Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
container.qc File Reference
#include "container.qh"
Include dependency graph for container.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void Container_addItem (entity me, entity other, vector theOrigin, vector theSize, float theAlpha)
void Container_addItemCentered (entity me, entity other, vector theSize, float theAlpha)
void Container_addItemRightCentered (entity me, entity other, vector theSize, float theAlpha)
void Container_draw (entity me)
void Container_enterLieSubitem (entity me, vector o, vector s, vector f, float a)
void Container_enterSubitem (entity me, entity sub)
void Container_focusLeave (entity me)
void Container_hideNotify (entity me)
entity Container_itemFromPoint (entity me, vector pos)
float Container_keyDown (entity me, float scan, float ascii, float shift)
float Container_keyUp (entity me, float scan, float ascii, float shift)
void Container_leaveSubitem (entity me)
float Container_mouseDrag (entity me, vector pos)
float Container_mouseMove (entity me, vector pos)
float Container_mouseRelease (entity me, vector pos)
void Container_moveItemAfter (entity me, entity other, entity dest)
entity Container_preferredFocusedGrandChild (entity me)
void Container_removeItem (entity me, entity other)
void Container_resizeNotify (entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
void Container_resizeNotifyLie (entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize,.vector originField,.vector sizeField,.vector fontScaleField)
void Container_saveFocus (entity me)
void Container_setAlphaOf (entity me, entity other, float theAlpha)
void Container_setFocus (entity me, entity other)
void Container_showNotify (entity me)

Function Documentation

◆ Container_addItem()

void Container_addItem ( entity me,
entity other,
vector theOrigin,
vector theSize,
float theAlpha )

Definition at line 242 of file container.qc.

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 }
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
entity other
float bound(float min, float value, float max)
#define NULL
Definition post.qh:14
#define error
Definition pre.qh:6

References bound(), entity(), error, NULL, other, and vector.

◆ Container_addItemCentered()

void Container_addItemCentered ( entity me,
entity other,
vector theSize,
float theAlpha )

Definition at line 232 of file container.qc.

233 {
234 me.addItem(me, other, '0.5 0.5 0' - 0.5 * theSize, theSize, theAlpha);
235 }

References entity(), other, and vector.

◆ Container_addItemRightCentered()

void Container_addItemRightCentered ( entity me,
entity other,
vector theSize,
float theAlpha )

Definition at line 237 of file container.qc.

238 {
239 me.addItem(me, other, '1 0.5 0' - 0.5 * theSize, theSize, theAlpha);
240 }

References entity(), other, and vector.

◆ Container_draw()

void Container_draw ( entity me)

Definition at line 114 of file container.qc.

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 }
#define SUPER(cname)
Definition oo.qh:231

References entity(), and SUPER.

◆ Container_enterLieSubitem()

void Container_enterLieSubitem ( entity me,
vector o,
vector s,
vector f,
float a )

Definition at line 8 of file container.qc.

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 }
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

References boxToGlobal(), boxToGlobalSize(), draw_alpha, draw_fontscale, draw_scale, draw_shift, entity(), and vector.

◆ Container_enterSubitem()

void Container_enterSubitem ( entity me,
entity sub )

Definition at line 3 of file container.qc.

4 {
5 me.enterLieSubitem(me, sub.Container_origin, sub.Container_size, sub.Container_fontscale, sub.Container_alpha);
6 }

References entity().

◆ Container_focusLeave()

void Container_focusLeave ( entity me)

Definition at line 132 of file container.qc.

133 {
134 me.setFocus(me, NULL);
135 }

References entity(), and NULL.

◆ Container_hideNotify()

void Container_hideNotify ( entity me)

Definition at line 38 of file container.qc.

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 }

References entity().

◆ Container_itemFromPoint()

entity Container_itemFromPoint ( entity me,
vector pos )

Definition at line 97 of file container.qc.

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 }
vector
Definition self.qh:92

References entity(), NULL, and vector.

◆ Container_keyDown()

float Container_keyDown ( entity me,
float scan,
float ascii,
float shift )

Definition at line 152 of file container.qc.

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 }

References entity().

◆ Container_keyUp()

float Container_keyUp ( entity me,
float scan,
float ascii,
float shift )

Definition at line 137 of file container.qc.

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 }

References entity().

◆ Container_leaveSubitem()

void Container_leaveSubitem ( entity me)

Definition at line 21 of file container.qc.

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 }

References draw_alpha, draw_fontscale, draw_scale, draw_shift, and entity().

◆ Container_mouseDrag()

float Container_mouseDrag ( entity me,
vector pos )

Definition at line 203 of file container.qc.

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 }
vector globalToBox(vector v, vector theOrigin, vector theScale)
Definition draw.qc:30

References entity(), globalToBox(), and vector.

◆ Container_mouseMove()

float Container_mouseMove ( entity me,
vector pos )

Definition at line 167 of file container.qc.

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 }

References entity(), globalToBox(), and vector.

◆ Container_mouseRelease()

float Container_mouseRelease ( entity me,
vector pos )

Definition at line 217 of file container.qc.

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 }

References entity(), globalToBox(), and vector.

◆ Container_moveItemAfter()

void Container_moveItemAfter ( entity me,
entity other,
entity dest )

Definition at line 340 of file container.qc.

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 }
vector dest
Definition jumppads.qh:54

References dest, entity(), error, and other.

◆ Container_preferredFocusedGrandChild()

entity Container_preferredFocusedGrandChild ( entity me)

Definition at line 368 of file container.qc.

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 }
best
Definition all.qh:82

References best, entity(), and NULL.

◆ Container_removeItem()

void Container_removeItem ( entity me,
entity other )

Definition at line 280 of file container.qc.

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 }

References entity(), error, NULL, and other.

◆ Container_resizeNotify()

void Container_resizeNotify ( entity me,
vector relOrigin,
vector relSize,
vector absOrigin,
vector absSize )

Definition at line 92 of file container.qc.

93 {
94 me.resizeNotifyLie(me, relOrigin, relSize, absOrigin, absSize, Container_origin, Container_size, Container_fontscale);
95 }
vector Container_origin
Definition container.qh:43
vector Container_fontscale
Definition container.qh:45
vector Container_size
Definition container.qh:44

References Container_fontscale, Container_origin, Container_size, entity(), and vector.

◆ Container_resizeNotifyLie()

void Container_resizeNotifyLie ( entity me,
vector relOrigin,
vector relSize,
vector absOrigin,
vector absSize,
.vector originField,
.vector sizeField,
.vector fontScaleField )

Definition at line 60 of file container.qc.

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 }

References boxToGlobal(), boxToGlobalSize(), entity(), SUPER, and vector.

◆ Container_saveFocus()

void Container_saveFocus ( entity me)

Definition at line 333 of file container.qc.

334 {
335 me.savedFocus = me.focusedChild;
336
337 if (me.focusedChild.instanceOfContainer) me.focusedChild.saveFocus(me.focusedChild);
338 }

References entity().

◆ Container_setAlphaOf()

void Container_setAlphaOf ( entity me,
entity other,
float theAlpha )

Definition at line 47 of file container.qc.

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 }

References entity(), and other.

◆ Container_setFocus()

void Container_setFocus ( entity me,
entity other )

Definition at line 299 of file container.qc.

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 }

References entity(), error, NULL, and other.

Referenced by m_activate_window(), and XonoticScrollPanel::setFocus().

◆ Container_showNotify()

void Container_showNotify ( entity me)

Definition at line 29 of file container.qc.

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 }

References entity().