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 .float Container_alpha;
38 void showNotifyContainer(entity me)
44 for(e = me.firstChild; e; e = e.nextSibling)
45 if(e.Container_alpha > 0)
49 void hideNotifyContainer(entity me)
55 for(e = me.firstChild; e; e = e.nextSibling)
56 if(e.Container_alpha > 0)
60 void setAlphaOfContainer(entity me, entity other, float theAlpha)
64 if(other.Container_alpha > 0)
65 other.hideNotify(other);
69 if(other.Container_alpha <= 0)
70 other.showNotify(other);
72 other.Container_alpha = theAlpha;
75 void resizeNotifyLieContainer(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize, .vector originField, .vector sizeField)
80 for(e = me.firstChild; e; e = e.nextSibling)
84 e.resizeNotify(e, o, s, boxToGlobal(o, absOrigin, absSize), boxToGlobalSize(s, absSize));
89 for(e = me.firstChild; e; e = e.nextSibling)
96 e.resizeNotify(e, o, s, boxToGlobal(o, absOrigin, absSize), boxToGlobalSize(s, absSize));
100 resizeNotifyItem(me, relOrigin, relSize, absOrigin, absSize);
103 void resizeNotifyContainer(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
105 me.resizeNotifyLie(me, relOrigin, relSize, absOrigin, absSize, Container_origin, Container_size);
108 entity itemFromPointContainer(entity me, vector pos)
112 for(e = me.lastChild; e; e = e.prevSibling)
114 o = e.Container_origin;
115 s = e.Container_size;
116 if(pos_x < o_x) continue;
117 if(pos_y < o_y) continue;
118 if(pos_x >= o_x + s_x) continue;
119 if(pos_y >= o_y + s_y) continue;
125 void drawContainer(entity me)
132 oldshift = draw_shift;
133 oldscale = draw_scale;
134 oldalpha = draw_alpha;
136 for(e = me.firstChild; e; e = e.nextSibling)
140 if(e.Container_alpha < 0.003) // can't change color values anyway
142 draw_shift = boxToGlobal(e.Container_origin, oldshift, oldscale);
143 draw_scale = boxToGlobalSize(e.Container_size, oldscale);
144 draw_alpha *= e.Container_alpha;
146 draw_shift = oldshift;
147 draw_scale = oldscale;
148 draw_alpha = oldalpha;
152 void focusLeaveContainer(entity me)
154 me.setFocus(me, NULL);
157 float keyUpContainer(entity me, float scan, float ascii, float shift)
162 return f.keyUp(f, scan, ascii, shift);
166 float keyDownContainer(entity me, float scan, float ascii, float shift)
171 return f.keyDown(f, scan, ascii, shift);
175 float mouseMoveContainer(entity me, vector pos)
180 return f.mouseMove(f, globalToBox(pos, f.Container_origin, f.Container_size));
183 float mousePressContainer(entity me, vector pos)
188 return f.mousePress(f, globalToBox(pos, f.Container_origin, f.Container_size));
191 float mouseDragContainer(entity me, vector pos)
196 return f.mouseDrag(f, globalToBox(pos, f.Container_origin, f.Container_size));
199 float mouseReleaseContainer(entity me, vector pos)
204 return f.mouseRelease(f, globalToBox(pos, f.Container_origin, f.Container_size));
208 void addItemCenteredContainer(entity me, entity other, vector theSize, float theAlpha)
210 me.addItem(me, other, '0.5 0.5 0' - 0.5 * theSize, theSize, theAlpha);
213 void addItemContainer(entity me, entity other, vector theOrigin, vector theSize, float theAlpha)
216 error("Can't add already added item!");
223 theOrigin_x -= 0.5 * (theSize_x - 1);
228 theOrigin_y -= 0.5 * (theSize_y - 1);
231 theOrigin_x = bound(0, theOrigin_x, 1 - theSize_x);
232 theOrigin_y = bound(0, theOrigin_y, 1 - theSize_y);
235 other.Container_origin = theOrigin;
236 other.Container_size = theSize;
237 me.setAlphaOf(me, other, theAlpha);
244 l.nextSibling = other;
246 me.firstChild = other;
248 other.prevSibling = l;
249 other.nextSibling = NULL;
250 me.lastChild = other;
252 draw_NeedResizeNotify = 1;
255 void removeItemContainer(entity me, entity other)
257 if(other.parent != me)
258 error("Can't remove from wrong container!");
268 n = other.nextSibling;
269 p = other.prevSibling;
282 void setFocusContainer(entity me, entity other)
286 error("Trying to set focus in a non-focused control!");
287 if(me.focusedChild == other)
289 //print(etos(me), ": focus changes from ", etos(me.focusedChild), " to ", etos(other), "\n");
292 me.focusedChild.focused = 0;
293 me.focusedChild.focusLeave(me.focusedChild);
298 other.focusEnter(other);
300 me.focusedChild = other;
303 void moveItemAfterContainer(entity me, entity other, entity dest)
305 // first: remove other from the chain
308 if(other.parent != me)
309 error("Can't move in wrong container!");
313 n = other.nextSibling;
314 p = other.prevSibling;
326 // now other got removed. Insert it behind dest now.
327 other.prevSibling = dest;
329 other.nextSibling = dest.nextSibling;
331 other.nextSibling = me.firstChild;
334 dest.nextSibling = other;
336 me.firstChild = other;
338 if(other.nextSibling)
339 other.nextSibling.prevSibling = other;
341 me.lastChild = other;
344 entity preferredFocusedGrandChildContainer(entity me)
351 for(e = me.firstChild; e; e = e.nextSibling)
353 if(e.instanceOfContainer)
355 e2 = e.preferredFocusedGrandChild(e);
357 if(!best || best.preferredFocusPriority < e2.preferredFocusPriority)
361 if(!best || best.preferredFocusPriority < e.preferredFocusPriority)