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 ATTRIB(Container, focusable, float, 0)
23 ATTRIB(Container, firstChild, entity, NULL)
24 ATTRIB(Container, lastChild, entity, NULL)
25 ATTRIB(Container, focusedChild, entity, NULL)
26 ATTRIB(Container, shown, float, 0)
31 .vector Container_origin;
32 .vector Container_size;
33 .float Container_alpha;
37 void showNotifyContainer(entity me)
43 for(e = me.firstChild; e; e = e.nextSibling)
44 if(e.Container_alpha > 0)
48 void hideNotifyContainer(entity me)
54 for(e = me.firstChild; e; e = e.nextSibling)
55 if(e.Container_alpha > 0)
59 void setAlphaOfContainer(entity me, entity other, float theAlpha)
63 if(other.Container_alpha > 0)
64 other.hideNotify(other);
68 if(other.Container_alpha <= 0)
69 other.showNotify(other);
71 other.Container_alpha = theAlpha;
74 void resizeNotifyLieContainer(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize, .vector originField, .vector sizeField)
79 for(e = me.firstChild; e; e = e.nextSibling)
83 e.resizeNotify(e, o, s, boxToGlobal(o, absOrigin, absSize), boxToGlobalSize(s, absSize));
88 for(e = me.firstChild; e; e = e.nextSibling)
95 e.resizeNotify(e, o, s, boxToGlobal(o, absOrigin, absSize), boxToGlobalSize(s, absSize));
99 resizeNotifyItem(me, relOrigin, relSize, absOrigin, absSize);
102 void resizeNotifyContainer(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
104 me.resizeNotifyLie(me, relOrigin, relSize, absOrigin, absSize, Container_origin, Container_size);
107 entity itemFromPointContainer(entity me, vector pos)
111 for(e = me.lastChild; e; e = e.prevSibling)
113 o = e.Container_origin;
114 s = e.Container_size;
115 if(pos_x < o_x) continue;
116 if(pos_y < o_y) continue;
117 if(pos_x >= o_x + s_x) continue;
118 if(pos_y >= o_y + s_y) continue;
124 void drawContainer(entity me)
131 oldshift = draw_shift;
132 oldscale = draw_scale;
133 oldalpha = draw_alpha;
135 for(e = me.firstChild; e; e = e.nextSibling)
139 if(e.Container_alpha < 0.003) // can't change color values anyway
141 draw_shift = boxToGlobal(e.Container_origin, oldshift, oldscale);
142 draw_scale = boxToGlobalSize(e.Container_size, oldscale);
143 draw_alpha *= e.Container_alpha;
145 draw_shift = oldshift;
146 draw_scale = oldscale;
147 draw_alpha = oldalpha;
151 void focusLeaveContainer(entity me)
153 me.setFocus(me, NULL);
156 float keyUpContainer(entity me, float scan, float ascii, float shift)
161 return f.keyUp(f, scan, ascii, shift);
165 float keyDownContainer(entity me, float scan, float ascii, float shift)
170 return f.keyDown(f, scan, ascii, shift);
174 float mouseMoveContainer(entity me, vector pos)
179 return f.mouseMove(f, globalToBox(pos, f.Container_origin, f.Container_size));
182 float mousePressContainer(entity me, vector pos)
187 return f.mousePress(f, globalToBox(pos, f.Container_origin, f.Container_size));
190 float mouseDragContainer(entity me, vector pos)
195 return f.mouseDrag(f, globalToBox(pos, f.Container_origin, f.Container_size));
198 float mouseReleaseContainer(entity me, vector pos)
203 return f.mouseRelease(f, globalToBox(pos, f.Container_origin, f.Container_size));
207 void addItemCenteredContainer(entity me, entity other, vector theSize, float theAlpha)
209 me.addItem(me, other, '0.5 0.5 0' - 0.5 * theSize, theSize, theAlpha);
212 void addItemContainer(entity me, entity other, vector theOrigin, vector theSize, float theAlpha)
215 error("Can't add already added item!");
222 theOrigin_x -= 0.5 * (theSize_x - 1);
227 theOrigin_y -= 0.5 * (theSize_y - 1);
230 theOrigin_x = bound(0, theOrigin_x, 1 - theSize_x);
231 theOrigin_y = bound(0, theOrigin_y, 1 - theSize_y);
234 other.Container_origin = theOrigin;
235 other.Container_size = theSize;
236 me.setAlphaOf(me, other, theAlpha);
243 l.nextSibling = other;
245 me.firstChild = other;
247 other.prevSibling = l;
248 other.nextSibling = NULL;
249 me.lastChild = other;
251 draw_NeedResizeNotify = 1;
254 void removeItemContainer(entity me, entity other)
256 if(other.parent != me)
257 error("Can't remove from wrong container!");
267 n = other.nextSibling;
268 p = other.prevSibling;
281 void setFocusContainer(entity me, entity other)
285 error("Trying to set focus in a non-focused control!");
286 if(me.focusedChild == other)
288 //print(etos(me), ": focus changes from ", etos(me.focusedChild), " to ", etos(other), "\n");
291 me.focusedChild.focused = 0;
292 me.focusedChild.focusLeave(me.focusedChild);
297 other.focusEnter(other);
299 me.focusedChild = other;
302 void moveItemAfterContainer(entity me, entity other, entity dest)
304 // first: remove other from the chain
307 if(other.parent != me)
308 error("Can't move in wrong container!");
312 n = other.nextSibling;
313 p = other.prevSibling;
325 // now other got removed. Insert it behind dest now.
326 other.prevSibling = dest;
328 other.nextSibling = dest.nextSibling;
330 other.nextSibling = me.firstChild;
333 dest.nextSibling = other;
335 me.firstChild = other;
337 if(other.nextSibling)
338 other.nextSibling.prevSibling = other;
340 me.lastChild = other;