]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/item.qc
Merge branch 'master' into terencehill/menu_gametype_tooltips_2
[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(entity));
6         METHOD(Item, keyDown, float(entity, float, float, float));
7         METHOD(Item, keyUp, float(entity, float, float, float));
8         METHOD(Item, mouseMove, float(entity, vector));
9         METHOD(Item, mousePress, float(entity, vector));
10         METHOD(Item, mouseDrag, float(entity, vector));
11         METHOD(Item, mouseRelease, float(entity, vector));
12         METHOD(Item, focusEnter, void(entity));
13         METHOD(Item, focusLeave, void(entity));
14         METHOD(Item, resizeNotify, void(entity, vector, vector, vector, vector));
15         METHOD(Item, relinquishFocus, void(entity));
16         METHOD(Item, showNotify, void(entity));
17         METHOD(Item, hideNotify, void(entity));
18         METHOD(Item, toString, string(entity));
19         METHOD(Item, destroy, void(entity));
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 void Item_destroy(entity me)
33 {
34         // free memory associated with me
35 }
36
37 void Item_relinquishFocus(entity me)
38 {
39         if(me.parent)
40                 if(me.parent.instanceOfContainer)
41                         me.parent.setFocus(me.parent, NULL);
42 }
43
44 void Item_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
45 {
46         me.origin = absOrigin;
47         me.size = absSize;
48 }
49
50 float autocvar_menu_showboxes;
51 void Item_draw(entity me)
52 {
53         if(autocvar_menu_showboxes)
54         {
55                 vector rgb = '1 0 1';
56                 float a = fabs(autocvar_menu_showboxes);
57
58                 // don't draw containers and border images
59                 if(me.instanceOfContainer || me.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)
69                         rgb = '1 0 0';
70                 else if(r >= 1)
71                         rgb = '0 1 0';
72                 else
73                         rgb = '0 0 1';
74 #endif
75                 if(autocvar_menu_showboxes < 0)
76                 {
77                         draw_Fill('0 0 0', '0.5 0.5 0', rgb, a);
78                         draw_Fill('0.5 0.5 0', '0.5 0.5 0', rgb, a);
79                 }
80                 if(autocvar_menu_showboxes > 0)
81                 {
82                         draw_Fill('0 0 0', '1 1 0', rgb, a);
83                 }
84         }
85 }
86
87 void Item_showNotify(entity me)
88 {
89 }
90
91 void Item_hideNotify(entity me)
92 {
93 }
94
95 float Item_keyDown(entity me, float scan, float ascii, float shift)
96 {
97         return 0; // unhandled
98 }
99
100 float Item_keyUp(entity me, float scan, float ascii, float shift)
101 {
102         return 0; // unhandled
103 }
104
105 float Item_mouseMove(entity me, vector pos)
106 {
107         return 0; // unhandled
108 }
109
110 float Item_mousePress(entity me, vector pos)
111 {
112         return 0; // unhandled
113 }
114
115 float Item_mouseDrag(entity me, vector pos)
116 {
117         return 0; // unhandled
118 }
119
120 float Item_mouseRelease(entity me, vector pos)
121 {
122         return 0; // unhandled
123 }
124
125 void Item_focusEnter(entity me)
126 {
127         if(me.allowFocusSound)
128                 m_play_focus_sound();
129 }
130
131 void Item_focusLeave(entity me)
132 {
133 }
134
135 string Item_toString(entity me)
136 {
137         return string_null;
138 }
139 #endif