]> git.xonotic.org Git - voretournament/voretournament.git/blob - data/qcsrc/menu/voret/inputbox.c
Get VoreTournament code to compile with gmqcc. To be compiled with the same parameter...
[voretournament/voretournament.git] / data / qcsrc / menu / voret / inputbox.c
1 #ifdef INTERFACE\r
2 CLASS(VoretInputBox) EXTENDS(InputBox)\r
3         METHOD(VoretInputBox, configureVoretInputBox, void(entity, float, string))\r
4         METHOD(VoretInputBox, focusLeave, void(entity))\r
5         METHOD(VoretInputBox, setText, void(entity, string))\r
6         ATTRIB(VoretInputBox, fontSize, float, SKINFONTSIZE_NORMAL)\r
7         ATTRIB(VoretInputBox, image, string, SKINGFX_INPUTBOX)\r
8         ATTRIB(VoretInputBox, onChange, void(entity, entity), func_null)\r
9         ATTRIB(VoretInputBox, onChangeEntity, entity, NULL)\r
10         ATTRIB(VoretInputBox, onEnter, void(entity, entity), func_null)\r
11         ATTRIB(VoretInputBox, onEnterEntity, entity, NULL)\r
12         ATTRIB(VoretInputBox, marginLeft, float, SKINMARGIN_INPUTBOX_CHARS)\r
13         ATTRIB(VoretInputBox, marginRight, float, SKINMARGIN_INPUTBOX_CHARS)\r
14         ATTRIB(VoretInputBox, color, vector, SKINCOLOR_INPUTBOX_N)\r
15         ATTRIB(VoretInputBox, colorF, vector, SKINCOLOR_INPUTBOX_F)\r
16 \r
17         ATTRIB(VoretInputBox, alpha, float, SKINALPHA_TEXT)\r
18 \r
19         ATTRIB(VoretInputBox, cvarName, string, string_null)\r
20         METHOD(VoretInputBox, loadCvars, void(entity))\r
21         METHOD(VoretInputBox, saveCvars, void(entity))\r
22         METHOD(VoretInputBox, keyDown, float(entity, float, float, float))\r
23 ENDCLASS(VoretInputBox)\r
24 entity makeVoretInputBox(float, string);\r
25 #endif\r
26 \r
27 #ifdef IMPLEMENTATION\r
28 entity makeVoretInputBox(float doEditColorCodes, string theCvar)\r
29 {\r
30         entity me;\r
31         me = spawnVoretInputBox();\r
32         me.configureVoretInputBox(me, doEditColorCodes, theCvar);\r
33         return me;\r
34 }\r
35 void configureVoretInputBoxVoretInputBox(entity me, float doEditColorCodes, string theCvar)\r
36 {\r
37         me.configureInputBox(me, "", 0, me.fontSize, me.image);\r
38         me.editColorCodes = doEditColorCodes;\r
39         if(theCvar)\r
40         {\r
41                 me.cvarName = theCvar;\r
42                 me.tooltip = getZonedTooltipForIdentifier(theCvar);\r
43                 me.loadCvars(me);\r
44         }\r
45         me.cursorPos = strlen(me.text);\r
46 }\r
47 void focusLeaveVoretInputBox(entity me)\r
48 {\r
49         me.saveCvars(me);\r
50 }\r
51 void setTextVoretInputBox(entity me, string new)\r
52 {\r
53         if(me.text != new)\r
54         {\r
55                 setTextInputBox(me, new);\r
56                 if(me.onChange)\r
57                         me.onChange(me, me.onChangeEntity);\r
58         }\r
59         else\r
60                 setTextInputBox(me, new);\r
61 }\r
62 void loadCvarsVoretInputBox(entity me)\r
63 {\r
64         if not(me.cvarName)\r
65                 return;\r
66         setTextInputBox(me, cvar_string(me.cvarName));\r
67 }\r
68 void saveCvarsVoretInputBox(entity me)\r
69 {\r
70         if not(me.cvarName)\r
71                 return;\r
72         cvar_set(me.cvarName, me.text);\r
73 }\r
74 float keyDownVoretInputBox(entity me, float key, float ascii, float shift)\r
75 {\r
76         float r;\r
77         r = 0;\r
78         if(key == K_ENTER)\r
79         {\r
80                 if(me.cvarName)\r
81                 {\r
82                         me.saveCvars(me);\r
83                         r = 1;\r
84                 }\r
85                 me.onEnter(me, me.onEnterEntity);\r
86         }\r
87         if(keyDownInputBox(me, key, ascii, shift))\r
88                 r = 1;\r
89         return r;\r
90 }\r
91 #endif\r