]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/nexuiz/inputbox.c
automatic tooltips from cvar descriptions
[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, onEnter, void(entity, entity), SUB_Null)
11         ATTRIB(NexuizInputBox, onEnterEntity, entity, NULL)
12         ATTRIB(NexuizInputBox, marginLeft, float, SKINMARGIN_INPUTBOX_CHARS)
13         ATTRIB(NexuizInputBox, marginRight, float, SKINMARGIN_INPUTBOX_CHARS)
14         ATTRIB(NexuizInputBox, color, vector, SKINCOLOR_INPUTBOX_N)
15         ATTRIB(NexuizInputBox, colorF, vector, SKINCOLOR_INPUTBOX_F)
16
17         ATTRIB(NexuizInputBox, alpha, float, SKINALPHA_TEXT)
18
19         ATTRIB(NexuizInputBox, cvarName, string, string_null)
20         METHOD(NexuizInputBox, loadCvars, void(entity))
21         METHOD(NexuizInputBox, saveCvars, void(entity))
22         METHOD(NexuizInputBox, keyDown, float(entity, float, float, float))
23 ENDCLASS(NexuizInputBox)
24 entity makeNexuizInputBox(float, string);
25 #endif
26
27 #ifdef IMPLEMENTATION
28 entity makeNexuizInputBox(float doEditColorCodes, string theCvar)
29 {
30         entity me;
31         me = spawnNexuizInputBox();
32         me.configureNexuizInputBox(me, doEditColorCodes, theCvar);
33         return me;
34 }
35 void configureNexuizInputBoxNexuizInputBox(entity me, float doEditColorCodes, string theCvar)
36 {
37         me.configureInputBox(me, "", 0, me.fontSize, me.image);
38         me.editColorCodes = doEditColorCodes;
39         if(theCvar)
40         {
41                 me.cvarName = theCvar;
42                 if(cvar_description(theCvar) != "custom cvar")
43                         me.tooltip = strzone(cvar_description(theCvar));
44                 me.loadCvars(me);
45         }
46         me.cursorPos = strlen(me.text);
47 }
48 void focusLeaveNexuizInputBox(entity me)
49 {
50         me.saveCvars(me);
51 }
52 void setTextNexuizInputBox(entity me, string new)
53 {
54         if(me.text != new)
55         {
56                 setTextInputBox(me, new);
57                 me.onChange(me, me.onChangeEntity);
58         }
59         else
60                 setTextInputBox(me, new);
61 }
62 void loadCvarsNexuizInputBox(entity me)
63 {
64         if not(me.cvarName)
65                 return;
66         setTextInputBox(me, cvar_string(me.cvarName));
67 }
68 void saveCvarsNexuizInputBox(entity me)
69 {
70         if not(me.cvarName)
71                 return;
72         cvar_set(me.cvarName, me.text);
73 }
74 float keyDownNexuizInputBox(entity me, float key, float ascii, float shift)
75 {
76         float r;
77         r = 0;
78         if(key == K_ENTER)
79         {
80                 if(me.cvarName)
81                 {
82                         me.saveCvars(me);
83                         r = 1;
84                 }
85                 me.onEnter(me, me.onEnterEntity);
86         }
87         if(keyDownInputBox(me, key, ascii, shift))
88                 r = 1;
89         return r;
90 }
91 #endif