]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/item.qc
Merge branch 'master' into TimePath/csqc_viewmodels
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / item.qc
1 #ifndef ITEM_H
2 #define ITEM_H
3 #include "skin.qh"
4 CLASS(Item, Object)
5         METHOD(Item, draw, void(Item));
6         METHOD(Item, keyDown, float(Item, float, float, float));
7         METHOD(Item, keyUp, float(Item, float, float, float));
8         METHOD(Item, mouseMove, float(Item, vector));
9         METHOD(Item, mousePress, float(Item, vector));
10         METHOD(Item, mouseDrag, float(Item, vector));
11         METHOD(Item, mouseRelease, float(Item, vector));
12         METHOD(Item, focusEnter, void(Item));
13         METHOD(Item, focusLeave, void(Item));
14         METHOD(Item, resizeNotify, void(Item, vector, vector, vector, vector));
15         METHOD(Item, relinquishFocus, void(Item));
16         METHOD(Item, showNotify, void(Item));
17         METHOD(Item, hideNotify, void(Item));
18         METHOD(Item, toString, string(Item));
19         METHOD(Item, destroy, void(Item));
20         ATTRIB(Item, focused, float, 0)
21         ATTRIB(Item, focusable, float, 0)
22         ATTRIB(Item, allowFocusSound, float, 0)
23         ATTRIB(Item, parent, entity, NULL)
24         ATTRIB(Item, preferredFocusPriority, float, 0)
25         ATTRIB(Item, origin, vector, '0 0 0')
26         ATTRIB(Item, size, vector, '0 0 0')
27         ATTRIB(Item, tooltip, string, string_null)
28 ENDCLASS(Item)
29 #endif
30
31 #ifdef IMPLEMENTATION
32         METHOD(Item, destroy, void(Item this))
33         {
34                 // free memory associated with this
35         }
36
37         METHOD(Item, relinquishFocus, void(Item this))
38         {
39                 entity par = this.parent;
40                 if (!par) return;
41                 if (par.instanceOfContainer) par.setFocus(par, NULL);
42         }
43
44         METHOD(Item, resizeNotify, void(Item this, vector relOrigin, vector relSize, vector absOrigin, vector absSize))
45         {
46                 this.origin = absOrigin;
47                 this.size = absSize;
48         }
49
50         int autocvar_menu_showboxes;
51         METHOD(Item, draw, void(Item this))
52         {
53                 if (!autocvar_menu_showboxes) return;
54                 vector rgb = '1 0 1';
55                 float a = fabs(autocvar_menu_showboxes);
56
57                 // don't draw containers and border images
58                 if (this.instanceOfContainer || this.instanceOfBorderImage)
59                 {
60                         rgb = '0 0 0';
61                         a = 0;
62                 }
63
64                 #if 0
65                         // hack to detect multi drawing
66                         float r = random() * 3;
67                         if (r >= 2) rgb = '1 0 0';
68                         else if (r >= 1) rgb = '0 1 0';
69                         else rgb = '0 0 1';
70                 #endif
71                 if (autocvar_menu_showboxes < 0)
72                 {
73                         draw_Fill('0 0 0', '0.5 0.5 0', rgb, a);
74                         draw_Fill('0.5 0.5 0', '0.5 0.5 0', rgb, a);
75                 }
76                 else if (autocvar_menu_showboxes > 0)
77                 {
78                         draw_Fill('0 0 0', '1 1 0', rgb, a);
79                 }
80         }
81
82         METHOD(Item, showNotify, void(Item this))
83         {}
84
85         METHOD(Item, hideNotify, void(Item this))
86         {}
87
88         METHOD(Item, keyDown, float(Item this, float scan, float ascii, float shift))
89         {
90                 return 0;  // unhandled
91         }
92
93         METHOD(Item, keyUp, float(Item this, float scan, float ascii, float shift))
94         {
95                 return 0;  // unhandled
96         }
97
98         METHOD(Item, mouseMove, float(Item this, vector pos))
99         {
100                 return 0;  // unhandled
101         }
102
103         METHOD(Item, mousePress, float(Item this, vector pos))
104         {
105                 return 0;  // unhandled
106         }
107
108         METHOD(Item, mouseDrag, float(Item this, vector pos))
109         {
110                 return 0;  // unhandled
111         }
112
113         METHOD(Item, mouseRelease, float(Item this, vector pos))
114         {
115                 return 0;  // unhandled
116         }
117
118         METHOD(Item, focusEnter, void(Item this))
119         {
120                 if (this.allowFocusSound) m_play_focus_sound();
121         }
122
123         METHOD(Item, focusLeave, void(Item this))
124         {}
125
126         METHOD(Item, toString, string(Item this))
127         {
128                 return string_null;
129         }
130 #endif