]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/nexuiz/inputbox.c
menu-div0test -> menu
[divverent/nexuiz.git] / data / qcsrc / menu / nexuiz / inputbox.c
1 #ifdef INTERFACE
2 CLASS(NexuizInputBox) EXTENDS(InputBox)
3         METHOD(NexuizInputBox, configureNexuizInputBox, void(entity, float, string))
4         METHOD(NexuizInputBox, focusLeave, void(entity))
5         METHOD(NexuizInputBox, setText, void(entity, string))
6         ATTRIB(NexuizInputBox, fontSize, float, SKINFONTSIZE_NORMAL)
7         ATTRIB(NexuizInputBox, image, string, SKINGFX_INPUTBOX)
8         ATTRIB(NexuizInputBox, onChange, void(entity, entity), SUB_Null)
9         ATTRIB(NexuizInputBox, onChangeEntity, entity, NULL)
10         ATTRIB(NexuizInputBox, keepspaceLeft, float, SKINMARGIN_INPUTBOX)
11         ATTRIB(NexuizInputBox, keepspaceRight, float, SKINMARGIN_INPUTBOX)
12         ATTRIB(NexuizInputBox, color, vector, SKINCOLOR_INPUTBOX_N)
13         ATTRIB(NexuizInputBox, colorF, vector, SKINCOLOR_INPUTBOX_F)
14
15         ATTRIB(NexuizInputBox, cvarName, string, string_null)
16         METHOD(NexuizInputBox, loadCvars, void(entity))
17         METHOD(NexuizInputBox, saveCvars, void(entity))
18 ENDCLASS(NexuizInputBox)
19 entity makeNexuizInputBox(float, string);
20 #endif
21
22 #ifdef IMPLEMENTATION
23 entity makeNexuizInputBox(float doEditColorCodes, string theCvar)
24 {
25         entity me;
26         me = spawnNexuizInputBox();
27         me.configureNexuizInputBox(me, doEditColorCodes, theCvar);
28         return me;
29 }
30 void configureNexuizInputBoxNexuizInputBox(entity me, float doEditColorCodes, string theCvar)
31 {
32         me.configureInputBox(me, "", 0, me.fontSize, me.image);
33         me.editColorCodes = doEditColorCodes;
34         if(theCvar)
35         {
36                 me.cvarName = theCvar;
37                 me.loadCvars(me);
38         }
39         me.cursorPos = strlen(me.text);
40 }
41 void focusLeaveNexuizInputBox(entity me)
42 {
43         if(me.cvarName)
44                 me.saveCvars(me);
45 }
46 void setTextNexuizInputBox(entity me, string new)
47 {
48         if(me.text != new)
49         {
50                 setTextInputBox(me, new);
51                 me.onChange(me, me.onChangeEntity);
52         }
53         else
54                 setTextInputBox(me, new);
55 }
56 void loadCvarsNexuizInputBox(entity me)
57 {
58         setTextInputBox(me, cvar_string(me.cvarName));
59 }
60 void saveCvarsNexuizInputBox(entity me)
61 {
62         cvar_set(me.cvarName, me.text);
63 }
64 #endif