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, bool(entity this, vector pos));
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 bool InputContainer__changeFocusXY(entity this, vector pos)
109 entity e = this.itemFromPoint(this, pos);
110 if (e && !e.focusable) e = NULL;
111 entity prev = this.mouseFocusedChild;
112 this.mouseFocusedChild = e;
113 if (!e) return false; // keep focus when hovering over non-focusable elements
115 this.setFocus(this, e);
116 if (e.instanceOfInputContainer) {
117 e.focusedChild = NULL;
118 e._changeFocusXY(e, globalToBox(pos, e.Container_origin, e.Container_size));
121 return true; // have focus
124 float InputContainer_mouseDrag(entity me, vector pos)
126 if(SUPER(InputContainer).mouseDrag(me, pos))
128 if(pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1)
132 float InputContainer_mouseMove(entity me, vector pos)
134 if(me.mouseFocusedChild != me.focusedChild) // if the keyboard moved the focus away
135 me.mouseFocusedChild = NULL; // force focusing
136 if(me._changeFocusXY(me, pos))
137 if(SUPER(InputContainer).mouseMove(me, pos))
139 if(pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1)
143 float InputContainer_mousePress(entity me, vector pos)
145 me.mouseFocusedChild = NULL; // force focusing
146 if(me._changeFocusXY(me, pos))
147 if(SUPER(InputContainer).mousePress(me, pos))
149 if(pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1)
153 float InputContainer_mouseRelease(entity me, vector pos)
155 SUPER(InputContainer).mouseRelease(me, pos); // return value?
156 if(me.focused) // am I still eligible for this? (UGLY HACK, but a mouse event could have changed focus away)
157 if(me._changeFocusXY(me, pos))
159 if(pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1)