]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/item/inputcontainer.qc
Merge branch 'BuddyFriendGuy/mapStringFilter' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / item / inputcontainer.qc
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))
12
13         METHOD(InputContainer, _changeFocusXY, float(entity, vector))
14         ATTRIB(InputContainer, mouseFocusedChild, entity, NULL)
15         ATTRIB(InputContainer, isTabRoot, float, 0)
16 ENDCLASS(InputContainer)
17 #endif
18
19 #ifdef IMPLEMENTATION
20 void InputContainer_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
21 {
22         SUPER(InputContainer).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
23         /*
24         if(me.parent.instanceOfInputContainer)
25                 me.isTabRoot = 0;
26         else
27                 me.isTabRoot = 1;
28         */
29 }
30
31 void InputContainer_focusLeave(entity me)
32 {
33         SUPER(InputContainer).focusLeave(me);
34         me.mouseFocusedChild = NULL;
35 }
36
37 float InputContainer_keyDown(entity me, float scan, float ascii, float shift)
38 {
39         entity f, ff;
40         if(SUPER(InputContainer).keyDown(me, scan, ascii, shift))
41                 return 1;
42         if(scan == K_ESCAPE)
43         {
44                 f = me.focusedChild;
45                 if(f)
46                 {
47                         me.setFocus(me, NULL);
48                         return 1;
49                 }
50                 return 0;
51         }
52         if(scan == K_TAB)
53         {
54                 f = me.focusedChild;
55                 if(shift & S_SHIFT)
56                 {
57                         if(f)
58                         {
59                                 for(ff = f.prevSibling; ff; ff = ff.prevSibling)
60                                 {
61                                         if (!ff.focusable)
62                                                 continue;
63                                         me.setFocus(me, ff);
64                                         return 1;
65                                 }
66                         }
67                         if(!f || me.isTabRoot)
68                         {
69                                 for(ff = me.lastChild; ff; ff = ff.prevSibling)
70                                 {
71                                         if (!ff.focusable)
72                                                 continue;
73                                         me.setFocus(me, ff);
74                                         return 1;
75                                 }
76                                 return 0; // AIIIIEEEEE!
77                         }
78                 }
79                 else
80                 {
81                         if(f)
82                         {
83                                 for(ff = f.nextSibling; ff; ff = ff.nextSibling)
84                                 {
85                                         if (!ff.focusable)
86                                                 continue;
87                                         me.setFocus(me, ff);
88                                         return 1;
89                                 }
90                         }
91                         if(!f || me.isTabRoot)
92                         {
93                                 for(ff = me.firstChild; ff; ff = ff.nextSibling)
94                                 {
95                                         if (!ff.focusable)
96                                                 continue;
97                                         me.setFocus(me, ff);
98                                         return 1;
99                                 }
100                                 return 0; // AIIIIEEEEE!
101                         }
102                 }
103         }
104         return 0;
105 }
106
107 float InputContainer__changeFocusXY(entity me, vector pos)
108 {
109         entity e, ne;
110         e = me.mouseFocusedChild;
111         ne = me.itemFromPoint(me, pos);
112         if(ne)
113                 if (!ne.focusable)
114                         ne = NULL;
115         me.mouseFocusedChild = ne;
116         if(ne)
117                 if(ne != e)
118                 {
119                         me.setFocus(me, ne);
120                         if(ne.instanceOfInputContainer)
121                         {
122                                 ne.focusedChild = NULL;
123                                 ne._changeFocusXY(e, globalToBox(pos, ne.Container_origin, ne.Container_size));
124                         }
125                 }
126         return (ne != NULL);
127 }
128
129 float InputContainer_mouseDrag(entity me, vector pos)
130 {
131         if(SUPER(InputContainer).mouseDrag(me, pos))
132                 return 1;
133         if(pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1)
134                 return 1;
135         return 0;
136 }
137 float InputContainer_mouseMove(entity me, vector pos)
138 {
139         if(me.mouseFocusedChild != me.focusedChild) // if the keyboard moved the focus away
140                 me.mouseFocusedChild = NULL; // force focusing
141         if(me._changeFocusXY(me, pos))
142                 if(SUPER(InputContainer).mouseMove(me, pos))
143                         return 1;
144         if(pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1)
145                 return 1;
146         return 0;
147 }
148 float InputContainer_mousePress(entity me, vector pos)
149 {
150         me.mouseFocusedChild = NULL; // force focusing
151         if(me._changeFocusXY(me, pos))
152                 if(SUPER(InputContainer).mousePress(me, pos))
153                         return 1;
154         if(pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1)
155                 return 1;
156         return 0;
157 }
158 float InputContainer_mouseRelease(entity me, vector pos)
159 {
160         SUPER(InputContainer).mouseRelease(me, pos); // return value?
161         if(me.focused) // am I still eligible for this? (UGLY HACK, but a mouse event could have changed focus away)
162                 if(me._changeFocusXY(me, pos))
163                         return 1;
164         if(pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1)
165                 return 1;
166         return 0;
167 }
168 #endif