2 CLASS(Container) EXTENDS(Item)
3 METHOD(Container, draw, void(entity))
4 METHOD(Container, keyUp, float(entity, float, float, float))
5 METHOD(Container, keyDown, float(entity, float, float, float))
6 METHOD(Container, mouseMove, float(entity, vector))
7 METHOD(Container, mousePress, float(entity, vector))
8 METHOD(Container, mouseDrag, float(entity, vector))
9 METHOD(Container, mouseRelease, float(entity, vector))
10 METHOD(Container, focusLeave, void(entity))
11 METHOD(Container, resizeNotify, void(entity, vector, vector, vector, vector))
12 METHOD(Container, resizeNotifyLie, void(entity, vector, vector, vector, vector, .vector, .vector))
13 METHOD(Container, addItem, void(entity, entity, vector, vector, float))
14 METHOD(Container, addItemCentered, void(entity, entity, vector, float))
15 METHOD(Container, moveItemAfter, void(entity, entity, entity))
16 METHOD(Container, removeItem, void(entity, entity))
17 METHOD(Container, setFocus, void(entity, entity))
18 METHOD(Container, setAlphaOf, void(entity, entity, float))
19 METHOD(Container, itemFromPoint, entity(entity, vector))
20 METHOD(Container, showNotify, void(entity))
21 METHOD(Container, hideNotify, void(entity))
22 METHOD(Container, preferredFocusedGrandChild, entity(entity))
23 ATTRIB(Container, focusable, float, 0)
24 ATTRIB(Container, firstChild, entity, NULL)
25 ATTRIB(Container, lastChild, entity, NULL)
26 ATTRIB(Container, focusedChild, entity, NULL)
27 ATTRIB(Container, shown, float, 0)
32 .vector Container_origin;
33 .vector Container_size;
34 .vector Container_fontscale;
35 .float Container_alpha;
39 void showNotifyContainer(entity me)
45 for(e = me.firstChild; e; e = e.nextSibling)
46 if(e.Container_alpha > 0)
50 void hideNotifyContainer(entity me)
56 for(e = me.firstChild; e; e = e.nextSibling)
57 if(e.Container_alpha > 0)
61 void setAlphaOfContainer(entity me, entity other, float theAlpha)
65 if(other.Container_alpha > 0)
66 other.hideNotify(other);
70 if(other.Container_alpha <= 0)
71 other.showNotify(other);
73 other.Container_alpha = theAlpha;
76 void resizeNotifyLieContainer(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize, .vector originField, .vector sizeField)
81 for(e = me.firstChild; e; e = e.nextSibling)
85 e.resizeNotify(e, o, s, boxToGlobal(o, absOrigin, absSize), boxToGlobalSize(s, absSize));
90 for(e = me.firstChild; e; e = e.nextSibling)
97 e.resizeNotify(e, o, s, boxToGlobal(o, absOrigin, absSize), boxToGlobalSize(s, absSize));
101 resizeNotifyItem(me, relOrigin, relSize, absOrigin, absSize);
104 void resizeNotifyContainer(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
106 me.resizeNotifyLie(me, relOrigin, relSize, absOrigin, absSize, Container_origin, Container_size);
109 entity itemFromPointContainer(entity me, vector pos)
113 for(e = me.lastChild; e; e = e.prevSibling)
115 o = e.Container_origin;
116 s = e.Container_size;
117 if(pos_x < o_x) continue;
118 if(pos_y < o_y) continue;
119 if(pos_x >= o_x + s_x) continue;
120 if(pos_y >= o_y + s_y) continue;
126 void drawContainer(entity me)
134 oldshift = draw_shift;
135 oldscale = draw_scale;
136 oldalpha = draw_alpha;
137 oldfontscale = draw_fontscale;
139 for(e = me.firstChild; e; e = e.nextSibling)
143 if(e.Container_alpha < 0.003) // can't change color values anyway
145 draw_shift = boxToGlobal(e.Container_origin, oldshift, oldscale);
146 draw_scale = boxToGlobalSize(e.Container_size, oldscale);
147 if(e.Container_fontscale != '0 0 0')
148 draw_fontscale = boxToGlobalSize(e.Container_fontscale, oldfontscale);
149 draw_alpha *= e.Container_alpha;
151 draw_shift = oldshift;
152 draw_scale = oldscale;
153 draw_fontscale = oldfontscale;
154 draw_alpha = oldalpha;
158 void focusLeaveContainer(entity me)
160 me.setFocus(me, NULL);
163 float keyUpContainer(entity me, float scan, float ascii, float shift)
168 return f.keyUp(f, scan, ascii, shift);
172 float keyDownContainer(entity me, float scan, float ascii, float shift)
177 return f.keyDown(f, scan, ascii, shift);
181 float mouseMoveContainer(entity me, vector pos)
186 return f.mouseMove(f, globalToBox(pos, f.Container_origin, f.Container_size));
189 float mousePressContainer(entity me, vector pos)
194 return f.mousePress(f, globalToBox(pos, f.Container_origin, f.Container_size));
197 float mouseDragContainer(entity me, vector pos)
202 return f.mouseDrag(f, globalToBox(pos, f.Container_origin, f.Container_size));
205 float mouseReleaseContainer(entity me, vector pos)
210 return f.mouseRelease(f, globalToBox(pos, f.Container_origin, f.Container_size));
214 void addItemCenteredContainer(entity me, entity other, vector theSize, float theAlpha)
216 me.addItem(me, other, '0.5 0.5 0' - 0.5 * theSize, theSize, theAlpha);
219 void addItemContainer(entity me, entity other, vector theOrigin, vector theSize, float theAlpha)
222 error("Can't add already added item!");
229 theOrigin_x -= 0.5 * (theSize_x - 1);
234 theOrigin_y -= 0.5 * (theSize_y - 1);
237 theOrigin_x = bound(0, theOrigin_x, 1 - theSize_x);
238 theOrigin_y = bound(0, theOrigin_y, 1 - theSize_y);
241 other.Container_origin = theOrigin;
242 other.Container_size = theSize;
243 me.setAlphaOf(me, other, theAlpha);
250 l.nextSibling = other;
252 me.firstChild = other;
254 other.prevSibling = l;
255 other.nextSibling = NULL;
256 me.lastChild = other;
258 draw_NeedResizeNotify = 1;
261 void removeItemContainer(entity me, entity other)
263 if(other.parent != me)
264 error("Can't remove from wrong container!");
274 n = other.nextSibling;
275 p = other.prevSibling;
288 void setFocusContainer(entity me, entity other)
292 error("Trying to set focus in a non-focused control!");
293 if(me.focusedChild == other)
295 //print(etos(me), ": focus changes from ", etos(me.focusedChild), " to ", etos(other), "\n");
298 me.focusedChild.focused = 0;
299 me.focusedChild.focusLeave(me.focusedChild);
304 other.focusEnter(other);
306 me.focusedChild = other;
309 void moveItemAfterContainer(entity me, entity other, entity dest)
311 // first: remove other from the chain
314 if(other.parent != me)
315 error("Can't move in wrong container!");
319 n = other.nextSibling;
320 p = other.prevSibling;
332 // now other got removed. Insert it behind dest now.
333 other.prevSibling = dest;
335 other.nextSibling = dest.nextSibling;
337 other.nextSibling = me.firstChild;
340 dest.nextSibling = other;
342 me.firstChild = other;
344 if(other.nextSibling)
345 other.nextSibling.prevSibling = other;
347 me.lastChild = other;
350 entity preferredFocusedGrandChildContainer(entity me)
357 for(e = me.firstChild; e; e = e.nextSibling)
359 if(e.instanceOfContainer)
361 e2 = e.preferredFocusedGrandChild(e);
363 if(!best || best.preferredFocusPriority < e2.preferredFocusPriority)
367 if(!best || best.preferredFocusPriority < e.preferredFocusPriority)