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)) return 1;
46 me.setFocus(me, NULL);
58 for (ff = f.prevSibling; ff; ff = ff.prevSibling)
60 if (!ff.focusable) continue;
65 if (!f || me.isTabRoot)
67 for (ff = me.lastChild; ff; ff = ff.prevSibling)
69 if (!ff.focusable) continue;
73 return 0; // AIIIIEEEEE!
80 for (ff = f.nextSibling; ff; ff = ff.nextSibling)
82 if (!ff.focusable) continue;
87 if (!f || me.isTabRoot)
89 for (ff = me.firstChild; ff; ff = ff.nextSibling)
91 if (!ff.focusable) continue;
95 return 0; // AIIIIEEEEE!
102 bool InputContainer__changeFocusXY(entity this, vector pos)
104 entity e = this.itemFromPoint(this, pos);
105 if (e && !e.focusable) e = NULL;
106 entity prev = this.mouseFocusedChild;
107 this.mouseFocusedChild = e;
108 if (!e) return false; // keep focus when hovering over non-focusable elements
111 this.setFocus(this, e);
112 if (e.instanceOfInputContainer)
114 e.focusedChild = NULL;
115 e._changeFocusXY(e, globalToBox(pos, e.Container_origin, e.Container_size));
118 return true; // have focus
121 float InputContainer_mouseDrag(entity me, vector pos)
123 if (SUPER(InputContainer).mouseDrag(me, pos)) return 1;
124 if (pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1) return 1;
127 float InputContainer_mouseMove(entity me, vector pos)
129 if (me.mouseFocusedChild != me.focusedChild) // if the keyboard moved the focus away
130 me.mouseFocusedChild = NULL; // force focusing
131 if (me._changeFocusXY(me, pos))
132 if (SUPER(InputContainer).mouseMove(me, pos)) return 1;
133 if (pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1) return 1;
136 float InputContainer_mousePress(entity me, vector pos)
138 me.mouseFocusedChild = NULL; // force focusing
139 if (me._changeFocusXY(me, pos))
140 if (SUPER(InputContainer).mousePress(me, pos)) return 1;
141 if (pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1) return 1;
144 float InputContainer_mouseRelease(entity me, vector pos)
146 SUPER(InputContainer).mouseRelease(me, pos); // return value?
147 if (me.focused) // am I still eligible for this? (UGLY HACK, but a mouse event could have changed focus away)
148 if (me._changeFocusXY(me, pos)) return 1;
149 if (pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1) return 1;