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