]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/item/inputcontainer.qc
Merge branch 'master' into Mario/showspecs
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / item / inputcontainer.qc
1 #include "inputcontainer.qh"
2
3         void InputContainer_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
4         {
5                 SUPER(InputContainer).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
6                 /*
7                 if(me.parent.instanceOfInputContainer)
8                     me.isTabRoot = 0;
9                 else
10                     me.isTabRoot = 1;
11                 */
12         }
13
14         void InputContainer_focusLeave(entity me)
15         {
16                 SUPER(InputContainer).focusLeave(me);
17                 me.mouseFocusedChild = NULL;
18         }
19
20         float InputContainer_keyDown(entity me, float scan, float ascii, float shift)
21         {
22                 entity f, ff;
23                 if (SUPER(InputContainer).keyDown(me, scan, ascii, shift))
24                         return 1;
25                 if (scan == K_ESCAPE)
26                 {
27                         f = me.focusedChild;
28                         if (f)
29                         {
30                                 me.setFocus(me, NULL);
31                                 return 1;
32                         }
33                         return 0;
34                 }
35                 if (scan == K_TAB)
36                 {
37                         f = me.focusedChild;
38                         if (shift & S_SHIFT)
39                         {
40                                 if (f)
41                                 {
42                                         for (ff = f.prevSibling; ff; ff = ff.prevSibling)
43                                         {
44                                                 if (!ff.focusable) continue;
45                                                 me.setFocus(me, ff);
46                                                 return 1;
47                                         }
48                                 }
49                                 if (!f || me.isTabRoot)
50                                 {
51                                         for (ff = me.lastChild; ff; ff = ff.prevSibling)
52                                         {
53                                                 if (!ff.focusable) continue;
54                                                 me.setFocus(me, ff);
55                                                 return 1;
56                                         }
57                                         return 0;  // AIIIIEEEEE!
58                                 }
59                         }
60                         else
61                         {
62                                 if (f)
63                                 {
64                                         for (ff = f.nextSibling; ff; ff = ff.nextSibling)
65                                         {
66                                                 if (!ff.focusable) continue;
67                                                 me.setFocus(me, ff);
68                                                 return 1;
69                                         }
70                                 }
71                                 if (!f || me.isTabRoot)
72                                 {
73                                         for (ff = me.firstChild; ff; ff = ff.nextSibling)
74                                         {
75                                                 if (!ff.focusable) continue;
76                                                 me.setFocus(me, ff);
77                                                 return 1;
78                                         }
79                                         return 0;  // AIIIIEEEEE!
80                                 }
81                         }
82                 }
83                 return 0;
84         }
85
86         bool InputContainer__changeFocusXY(entity this, vector pos)
87         {
88                 entity e = this.itemFromPoint(this, pos);
89                 if (e && !e.focusable) e = NULL;
90                 entity prev = this.mouseFocusedChild;
91                 this.mouseFocusedChild = e;
92                 if (!e) return false;  // keep focus when hovering over non-focusable elements
93                 if (e != prev)
94                 {
95                         this.setFocus(this, e);
96                         if (e.instanceOfInputContainer)
97                         {
98                                 e.focusedChild = NULL;
99                                 e._changeFocusXY(e, globalToBox(pos, e.Container_origin, e.Container_size));
100                         }
101                 }
102                 return true;  // have focus
103         }
104
105         float InputContainer_mouseDrag(entity me, vector pos)
106         {
107                 if (SUPER(InputContainer).mouseDrag(me, pos)) return 1;
108                 if (pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1) return 1;
109                 return 0;
110         }
111         float InputContainer_mouseMove(entity me, vector pos)
112         {
113                 if (me.mouseFocusedChild != me.focusedChild) // if the keyboard moved the focus away
114                         me.mouseFocusedChild = NULL;             // force focusing
115                 if (me._changeFocusXY(me, pos))
116                         if (SUPER(InputContainer).mouseMove(me, pos)) return 1;
117                 if (pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1) return 1;
118                 return 0;
119         }
120         float InputContainer_mousePress(entity me, vector pos)
121         {
122                 me.mouseFocusedChild = NULL;  // force focusing
123                 if (me._changeFocusXY(me, pos))
124                         if (SUPER(InputContainer).mousePress(me, pos)) return 1;
125                 if (pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1) return 1;
126                 return 0;
127         }
128         float InputContainer_mouseRelease(entity me, vector pos)
129         {
130                 SUPER(InputContainer).mouseRelease(me, pos); // return value?
131                 if (me.focused)                              // am I still eligible for this? (UGLY HACK, but a mouse event could have changed focus away)
132                         if (me._changeFocusXY(me, pos)) return 1;
133                 if (pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1) return 1;
134                 return 0;
135         }