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