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