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, moveItemAfter, void(entity, entity, entity))
15 METHOD(Container, removeItem, void(entity, entity))
16 METHOD(Container, setFocus, void(entity, entity))
17 METHOD(Container, itemFromPoint, entity(entity, vector))
18 METHOD(Container, open, void(entity))
19 ATTRIB(Container, focusable, float, 0)
20 ATTRIB(Container, firstChild, entity, NULL)
21 ATTRIB(Container, lastChild, entity, NULL)
22 ATTRIB(Container, focusedChild, entity, NULL)
27 .vector Container_origin;
28 .vector Container_size;
29 .float Container_alpha;
33 void openContainer(entity me)
36 for(e = me.firstChild; e; e = e.nextSibling)
40 void resizeNotifyLieContainer(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize, .vector originField, .vector sizeField)
44 for(e = me.firstChild; e; e = e.nextSibling)
48 e.resizeNotify(e, o, s, boxToGlobal(o, absOrigin, absSize), boxToGlobalSize(s, absSize));
50 resizeNotifyItem(me, relOrigin, relSize, absOrigin, absSize);
53 void resizeNotifyContainer(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
55 me.resizeNotifyLie(me, relOrigin, relSize, absOrigin, absSize, Container_origin, Container_size);
58 entity itemFromPointContainer(entity me, vector pos)
62 for(e = me.lastChild; e; e = e.prevSibling)
64 o = e.Container_origin;
66 if(pos_x < o_x) continue;
67 if(pos_y < o_y) continue;
68 if(pos_x >= o_x + s_x) continue;
69 if(pos_y >= o_y + s_y) continue;
75 void drawContainer(entity me)
82 oldshift = draw_shift;
83 oldscale = draw_scale;
84 oldalpha = draw_alpha;
86 for(e = me.firstChild; e; e = e.nextSibling)
90 if(!e.Container_alpha)
92 draw_shift = boxToGlobal(e.Container_origin, oldshift, oldscale);
93 draw_scale = boxToGlobalSize(e.Container_size, oldscale);
94 draw_alpha *= e.Container_alpha;
96 draw_shift = oldshift;
97 draw_scale = oldscale;
98 draw_alpha = oldalpha;
102 void focusLeaveContainer(entity me)
104 me.setFocus(me, NULL);
107 float keyUpContainer(entity me, float scan, float ascii, float shift)
112 return f.keyUp(f, scan, ascii, shift);
116 float keyDownContainer(entity me, float scan, float ascii, float shift)
121 return f.keyDown(f, scan, ascii, shift);
125 float mouseMoveContainer(entity me, vector pos)
130 return f.mouseMove(f, globalToBox(pos, f.Container_origin, f.Container_size));
133 float mousePressContainer(entity me, vector pos)
138 return f.mousePress(f, globalToBox(pos, f.Container_origin, f.Container_size));
141 float mouseDragContainer(entity me, vector pos)
146 return f.mouseDrag(f, globalToBox(pos, f.Container_origin, f.Container_size));
149 float mouseReleaseContainer(entity me, vector pos)
154 return f.mouseRelease(f, globalToBox(pos, f.Container_origin, f.Container_size));
158 void addItemContainer(entity me, entity other, vector theOrigin, vector theSize, float theAlpha)
161 error("Can't add already added item!");
167 other.Container_origin = theOrigin;
168 other.Container_size = theSize;
169 other.Container_alpha = theAlpha;
176 l.nextSibling = other;
178 me.firstChild = other;
180 other.prevSibling = l;
181 other.nextSibling = NULL;
182 me.lastChild = other;
184 draw_NeedResizeNotify = 1;
187 void removeItemContainer(entity me, entity other)
189 if(other.parent != me)
190 error("Can't remove from wrong container!");
200 n = other.nextSibling;
201 p = other.prevSibling;
214 void setFocusContainer(entity me, entity other)
218 error("Trying to set focus in a non-focused control!");
219 if(me.focusedChild == other)
221 //print(etos(me), ": focus changes from ", etos(me.focusedChild), " to ", etos(other), "\n");
224 me.focusedChild.focused = 0;
225 me.focusedChild.focusLeave(me.focusedChild);
230 other.focusEnter(other);
232 me.focusedChild = other;
235 void moveItemAfterContainer(entity me, entity other, entity dest)
237 // first: remove other from the chain
240 if(other.parent != me)
241 error("Can't move in wrong container!");
245 n = other.nextSibling;
246 p = other.prevSibling;
258 // now other got removed. Insert it behind dest now.
259 other.prevSibling = dest;
261 other.nextSibling = dest.nextSibling;
263 other.nextSibling = me.firstChild;
266 dest.nextSibling = other;
268 me.firstChild = other;
270 if(other.nextSibling)
271 other.nextSibling.prevSibling = other;
273 me.lastChild = other;