Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
container.qc
Go to the documentation of this file.
1#include "container.qh"
2
4 {
5 me.enterLieSubitem(me, sub.Container_origin, sub.Container_size, sub.Container_fontscale, sub.Container_alpha);
6 }
7
9 {
10 me.Container_save_shift = draw_shift;
11 me.Container_save_scale = draw_scale;
12 me.Container_save_alpha = draw_alpha;
13 me.Container_save_fontscale = draw_fontscale;
14
17 if (f != '0 0 0') draw_fontscale = boxToGlobalSize(f, draw_fontscale);
18 draw_alpha *= a;
19 }
20
22 {
23 draw_shift = me.Container_save_shift;
24 draw_scale = me.Container_save_scale;
25 draw_alpha = me.Container_save_alpha;
26 draw_fontscale = me.Container_save_fontscale;
27 }
28
30 {
31 entity e;
32 if (me.shown) return;
33 me.shown = true;
34 for (e = me.firstChild; e; e = e.nextSibling)
35 if (e.Container_alpha > 0) e.showNotify(e);
36 }
37
39 {
40 entity e;
41 if (!me.shown) return;
42 me.shown = false;
43 for (e = me.firstChild; e; e = e.nextSibling)
44 if (e.Container_alpha > 0) e.hideNotify(e);
45 }
46
47 void Container_setAlphaOf(entity me, entity other, float theAlpha)
48 {
49 if (theAlpha <= 0)
50 {
51 if (other.Container_alpha > 0) other.hideNotify(other);
52 }
53 else // value > 0
54 {
55 if (other.Container_alpha <= 0) other.showNotify(other);
56 }
57 other.Container_alpha = theAlpha;
58 }
59
60 void Container_resizeNotifyLie(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize, .vector originField, .vector sizeField, .vector fontScaleField)
61 {
62 entity e;
63 vector o, s;
64 float d;
65 for (e = me.firstChild; e; e = e.nextSibling)
66 {
67 o = e.(originField);
68 s = e.(sizeField);
69 me.enterLieSubitem(me, o, s, e.(fontScaleField), e.Container_alpha);
70 e.resizeNotify(e, o, s, boxToGlobal(o, absOrigin, absSize), boxToGlobalSize(s, absSize));
71 me.leaveSubitem(me);
72 }
73 do
74 {
75 d = 0;
76 for (e = me.firstChild; e; e = e.nextSibling)
77 if (e.resized)
78 {
79 e.resized = 0;
80 d = 1;
81 o = e.(originField);
82 s = e.(sizeField);
83 me.enterLieSubitem(me, o, s, e.(fontScaleField), e.Container_alpha);
84 e.resizeNotify(e, o, s, boxToGlobal(o, absOrigin, absSize), boxToGlobalSize(s, absSize));
85 me.leaveSubitem(me);
86 }
87 }
88 while (d);
89 SUPER(Container).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
90 }
91
92 void Container_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
93 {
94 me.resizeNotifyLie(me, relOrigin, relSize, absOrigin, absSize, Container_origin, Container_size, Container_fontscale);
95 }
96
98 {
99 entity e;
100 vector o, s;
101 for (e = me.lastChild; e; e = e.prevSibling)
102 {
103 o = e.Container_origin;
104 s = e.Container_size;
105 if (pos.x < o.x) continue;
106 if (pos.y < o.y) continue;
107 if (pos.x >= o.x + s.x) continue;
108 if (pos.y >= o.y + s.y) continue;
109 return e;
110 }
111 return NULL;
112 }
113
115 {
116 entity e;
117
118 me.focusable = false;
119 for (e = me.firstChild; e; e = e.nextSibling)
120 {
121 if (e.focusable) me.focusable = true;
122 if (e.Container_alpha < 0.003) // can't change color values anyway
123 continue;
124 me.enterSubitem(me, e);
125 e.draw(e);
126 me.leaveSubitem(me);
127 }
128
129 SUPER(Container).draw(me);
130 }
131
133 {
134 me.setFocus(me, NULL);
135 }
136
137 float Container_keyUp(entity me, float scan, float ascii, float shift)
138 {
139 entity f;
140 float r;
141 f = me.focusedChild;
142 if (f)
143 {
144 me.enterSubitem(me, f);
145 r = f.keyUp(f, scan, ascii, shift);
146 me.leaveSubitem(me);
147 return r;
148 }
149 return 0;
150 }
151
152 float Container_keyDown(entity me, float scan, float ascii, float shift)
153 {
154 entity f;
155 float r;
156 f = me.focusedChild;
157 if (f)
158 {
159 me.enterSubitem(me, f);
160 r = f.keyDown(f, scan, ascii, shift);
161 me.leaveSubitem(me);
162 return r;
163 }
164 return 0;
165 }
166
168 {
169 entity f;
170 float r;
171 f = me.focusedChild;
172 if (f)
173 {
174 me.enterSubitem(me, f);
175 r = f.mouseMove(f, globalToBox(pos, f.Container_origin, f.Container_size));
176 me.leaveSubitem(me);
177 return r;
178 }
179 return 0;
180 }
182 {
183 entity f = this.focusedChild;
184 if (f)
185 {
186 this.enterSubitem(this, f);
187 vector v = globalToBox(pos, f.Container_origin, f.Container_size);
188 // If something in this container is focused but somehow the cursor is outside of the container it then
189 // remove the focus on mouse press.
190 // This situation can happen after a stand-alone dialog like "Advanced Settings" is opened and then closed
191 // because the focused item of the current window is saved (by saveFocus) and then restored on close,
192 // regardless of mouse position.
193 // If the focus wasn't removed then clicking outside of the current window would do nothing instead of
194 // closing the current window and returning to the main menu.
195 if (v.x < 0 || v.x > 1 || v.y < 0 || v.y > 1)
196 this.setFocus(this, NULL);
197 bool r = f.mousePress(f, v);
198 this.leaveSubitem(this);
199 return r;
200 }
201 return false;
202 }
204 {
205 entity f;
206 float r;
207 f = me.focusedChild;
208 if (f)
209 {
210 me.enterSubitem(me, f);
211 r = f.mouseDrag(f, globalToBox(pos, f.Container_origin, f.Container_size));
212 me.leaveSubitem(me);
213 return r;
214 }
215 return 0;
216 }
218 {
219 entity f;
220 float r;
221 f = me.focusedChild;
222 if (f)
223 {
224 me.enterSubitem(me, f);
225 r = f.mouseRelease(f, globalToBox(pos, f.Container_origin, f.Container_size));
226 me.leaveSubitem(me);
227 return r;
228 }
229 return 0;
230 }
231
232 void Container_addItemCentered(entity me, entity other, vector theSize, float theAlpha)
233 {
234 me.addItem(me, other, '0.5 0.5 0' - 0.5 * theSize, theSize, theAlpha);
235 }
236
237 void Container_addItemRightCentered(entity me, entity other, vector theSize, float theAlpha)
238 {
239 me.addItem(me, other, '1 0.5 0' - 0.5 * theSize, theSize, theAlpha);
240 }
241
242 void Container_addItem(entity me, entity other, vector theOrigin, vector theSize, float theAlpha)
243 {
244 if (other.parent) error("Can't add already added item!");
245
246 if (other.focusable) me.focusable = true;
247
248 if (theSize.x > 1)
249 {
250 theOrigin.x -= 0.5 * (theSize.x - 1);
251 theSize.x = 1;
252 }
253 if (theSize.y > 1)
254 {
255 theOrigin.y -= 0.5 * (theSize.y - 1);
256 theSize.y = 1;
257 }
258 theOrigin.x = bound(0, theOrigin.x, 1 - theSize.x);
259 theOrigin.y = bound(0, theOrigin.y, 1 - theSize.y);
260
261 other.parent = me;
262 other.Container_origin = theOrigin;
263 other.Container_size = theSize;
264
265 // don't call setAlphaOf, it would uneccessarily trigger showNotify
266 //me.setAlphaOf(me, other, theAlpha);
267 other.Container_alpha = theAlpha;
268
269 entity l;
270 l = me.lastChild;
271
272 if (l) l.nextSibling = other;
273 else me.firstChild = other;
274
275 other.prevSibling = l;
276 other.nextSibling = NULL;
277 me.lastChild = other;
278 }
279
281 {
282 if (other.parent != me) error("Can't remove from wrong container!");
283
284 if (other.focusable) me.focusable = false;
285
286 other.parent = NULL;
287
288 entity n, p;
289 n = other.nextSibling;
290 p = other.prevSibling;
291
292 if (p) p.nextSibling = n;
293 else me.firstChild = n;
294
295 if (n) n.prevSibling = p;
296 else me.lastChild = p;
297 }
298
300 {
301 if (me.focusedChild == other) return;
302
303 if (me.focusedChild)
304 {
305 me.focusedChild.focused = false;
306 me.focusedChild.focusLeave(me.focusedChild);
307 me.focusedChild = NULL;
308 }
309
310 if (other)
311 {
312 if (!me.focused) error("Trying to set focus in a non-focused control!");
313
314 if (me.savedFocus)
315 {
316 me.focusedChild = me.savedFocus;
317 me.savedFocus = NULL;
318 me.focusedChild.focused = true;
319 me.focusedChild.focusEnter(me.focusedChild);
320
321 if (me.focusedChild.instanceOfContainer)
322 me.focusedChild.setFocus(me.focusedChild, me.focusedChild.savedFocus);
323 }
324 else
325 {
326 me.focusedChild = other;
327 me.focusedChild.focused = true;
328 me.focusedChild.focusEnter(me.focusedChild);
329 }
330 }
331 }
332
334 {
335 me.savedFocus = me.focusedChild;
336
337 if (me.focusedChild.instanceOfContainer) me.focusedChild.saveFocus(me.focusedChild);
338 }
339
341 {
342 // first: remove other from the chain
343 entity n, p;
344
345 if (other.parent != me) error("Can't move in wrong container!");
346
347 n = other.nextSibling;
348 p = other.prevSibling;
349
350 if (p) p.nextSibling = n;
351 else me.firstChild = n;
352
353 if (n) n.prevSibling = p;
354 else me.lastChild = p;
355
356 // now other got removed. Insert it behind dest now.
357 other.prevSibling = dest;
358 if (dest) other.nextSibling = dest.nextSibling;
359 else other.nextSibling = me.firstChild;
360
361 if (dest) dest.nextSibling = other;
362 else me.firstChild = other;
363
364 if (other.nextSibling) other.nextSibling.prevSibling = other;
365 else me.lastChild = other;
366 }
367
369 {
370 entity e, e2;
371 entity best;
372
373 best = NULL;
374
375 for (e = me.firstChild; e; e = e.nextSibling)
376 {
377 if (e.instanceOfContainer)
378 {
379 e2 = e.preferredFocusedGrandChild(e);
380 if (e2)
381 if (!best || best.preferredFocusPriority < e2.preferredFocusPriority) best = e2;
382 }
383 if (e)
384 if (!best || best.preferredFocusPriority < e.preferredFocusPriority) best = e;
385 }
386
387 return best;
388 }
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
virtual void leaveSubitem()
virtual void setFocus()
virtual void enterSubitem()
virtual void mousePress()
Definition container.qc:181
void Container_resizeNotifyLie(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize,.vector originField,.vector sizeField,.vector fontScaleField)
Definition container.qc:60
void Container_saveFocus(entity me)
Definition container.qc:333
void Container_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
Definition container.qc:92
float Container_mouseRelease(entity me, vector pos)
Definition container.qc:217
void Container_setFocus(entity me, entity other)
Definition container.qc:299
void Container_draw(entity me)
Definition container.qc:114
void Container_addItemRightCentered(entity me, entity other, vector theSize, float theAlpha)
Definition container.qc:237
void Container_hideNotify(entity me)
Definition container.qc:38
void Container_removeItem(entity me, entity other)
Definition container.qc:280
void Container_addItem(entity me, entity other, vector theOrigin, vector theSize, float theAlpha)
Definition container.qc:242
void Container_leaveSubitem(entity me)
Definition container.qc:21
void Container_setAlphaOf(entity me, entity other, float theAlpha)
Definition container.qc:47
float Container_keyUp(entity me, float scan, float ascii, float shift)
Definition container.qc:137
float Container_mouseDrag(entity me, vector pos)
Definition container.qc:203
entity Container_itemFromPoint(entity me, vector pos)
Definition container.qc:97
void Container_enterSubitem(entity me, entity sub)
Definition container.qc:3
void Container_showNotify(entity me)
Definition container.qc:29
float Container_keyDown(entity me, float scan, float ascii, float shift)
Definition container.qc:152
void Container_moveItemAfter(entity me, entity other, entity dest)
Definition container.qc:340
void Container_addItemCentered(entity me, entity other, vector theSize, float theAlpha)
Definition container.qc:232
entity Container_preferredFocusedGrandChild(entity me)
Definition container.qc:368
void Container_enterLieSubitem(entity me, vector o, vector s, vector f, float a)
Definition container.qc:8
float Container_mouseMove(entity me, vector pos)
Definition container.qc:167
void Container_focusLeave(entity me)
Definition container.qc:132
vector Container_origin
Definition container.qh:43
vector Container_fontscale
Definition container.qh:45
vector Container_size
Definition container.qh:44
entity other
best
Definition all.qh:82
vector dest
Definition jumppads.qh:54
vector globalToBox(vector v, vector theOrigin, vector theScale)
Definition draw.qc:30
vector boxToGlobalSize(vector v, vector theScale)
Definition draw.qc:53
vector boxToGlobal(vector v, vector theOrigin, vector theScale)
Definition draw.qc:45
vector draw_shift
Definition draw.qh:7
vector draw_scale
Definition draw.qh:8
#define draw_fontscale
Definition draw.qh:5
float draw_alpha
Definition draw.qh:9
float bound(float min, float value, float max)
#define SUPER(cname)
Definition oo.qh:231
#define METHOD(cname, name, prototype)
Definition oo.qh:269
#define NULL
Definition post.qh:14
#define error
Definition pre.qh:6
vector
Definition self.qh:92