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