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