]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/item/inputcontainer.qc
Merge branch 'master' into Lyberta/StandaloneOverkillWeapons
[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 != prev)
93                 {
94                         this.setFocus(this, e);
95                         if (e && 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         METHOD(InputContainer, mousePress, bool(InputContainer this, vector pos))
120         {
121                 this.mouseFocusedChild = NULL;  // force focusing
122                 if (this._changeFocusXY(this, pos))
123                         if (SUPER(InputContainer).mousePress(this, pos)) return true;
124                 if (pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1) return true;
125                 return false;
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         }