1 #ifndef ITEM_INPUTCONTAINER_H
2 #define ITEM_INPUTCONTAINER_H
3 #include "container.qc"
4 CLASS(InputContainer, Container)
5 METHOD(InputContainer, keyDown, float(entity, float, float, float))
6 METHOD(InputContainer, mouseMove, float(entity, vector))
7 METHOD(InputContainer, mousePress, float(entity, vector))
8 METHOD(InputContainer, mouseRelease, float(entity, vector))
9 METHOD(InputContainer, mouseDrag, float(entity, vector))
10 METHOD(InputContainer, focusLeave, void(entity))
11 METHOD(InputContainer, resizeNotify, void(entity, vector, vector, vector, vector))
13 METHOD(InputContainer, _changeFocusXY, float(entity, vector))
14 ATTRIB(InputContainer, mouseFocusedChild, entity, NULL)
15 ATTRIB(InputContainer, isTabRoot, float, 0)
16 ENDCLASS(InputContainer)
20 void InputContainer_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
22 SUPER(InputContainer).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
24 if(me.parent.instanceOfInputContainer)
31 void InputContainer_focusLeave(entity me)
33 SUPER(InputContainer).focusLeave(me);
34 me.mouseFocusedChild = NULL;
37 float InputContainer_keyDown(entity me, float scan, float ascii, float shift)
40 if(SUPER(InputContainer).keyDown(me, scan, ascii, shift))
47 me.setFocus(me, NULL);
59 for(ff = f.prevSibling; ff; ff = ff.prevSibling)
67 if(!f || me.isTabRoot)
69 for(ff = me.lastChild; ff; ff = ff.prevSibling)
76 return 0; // AIIIIEEEEE!
83 for(ff = f.nextSibling; ff; ff = ff.nextSibling)
91 if(!f || me.isTabRoot)
93 for(ff = me.firstChild; ff; ff = ff.nextSibling)
100 return 0; // AIIIIEEEEE!
107 float InputContainer__changeFocusXY(entity me, vector pos)
110 e = me.mouseFocusedChild;
111 ne = me.itemFromPoint(me, pos);
115 me.mouseFocusedChild = ne;
120 if(ne.instanceOfInputContainer)
122 ne.focusedChild = NULL;
123 ne._changeFocusXY(e, globalToBox(pos, ne.Container_origin, ne.Container_size));
129 float InputContainer_mouseDrag(entity me, vector pos)
131 if(SUPER(InputContainer).mouseDrag(me, pos))
133 if(pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1)
137 float InputContainer_mouseMove(entity me, vector pos)
139 if(me.mouseFocusedChild != me.focusedChild) // if the keyboard moved the focus away
140 me.mouseFocusedChild = NULL; // force focusing
141 if(me._changeFocusXY(me, pos))
142 if(SUPER(InputContainer).mouseMove(me, pos))
144 if(pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1)
148 float InputContainer_mousePress(entity me, vector pos)
150 me.mouseFocusedChild = NULL; // force focusing
151 if(me._changeFocusXY(me, pos))
152 if(SUPER(InputContainer).mousePress(me, pos))
154 if(pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1)
158 float InputContainer_mouseRelease(entity me, vector pos)
160 SUPER(InputContainer).mouseRelease(me, pos); // return value?
161 if(me.focused) // am I still eligible for this? (UGLY HACK, but a mouse event could have changed focus away)
162 if(me._changeFocusXY(me, pos))
164 if(pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1)