]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/nexuiz/inputbox.c
only show tooltips for not engine owned cvars
[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 not(cvar_type(theCvar) & CVAR_TYPEFLAG_ENGINE)
43                         if(cvar_description(theCvar) != "custom cvar")
44                                 me.tooltip = strzone(cvar_description(theCvar));
45                 me.loadCvars(me);
46         }
47         me.cursorPos = strlen(me.text);
48 }
49 void focusLeaveNexuizInputBox(entity me)
50 {
51         me.saveCvars(me);
52 }
53 void setTextNexuizInputBox(entity me, string new)
54 {
55         if(me.text != new)
56         {
57                 setTextInputBox(me, new);
58                 me.onChange(me, me.onChangeEntity);
59         }
60         else
61                 setTextInputBox(me, new);
62 }
63 void loadCvarsNexuizInputBox(entity me)
64 {
65         if not(me.cvarName)
66                 return;
67         setTextInputBox(me, cvar_string(me.cvarName));
68 }
69 void saveCvarsNexuizInputBox(entity me)
70 {
71         if not(me.cvarName)
72                 return;
73         cvar_set(me.cvarName, me.text);
74 }
75 float keyDownNexuizInputBox(entity me, float key, float ascii, float shift)
76 {
77         float r;
78         r = 0;
79         if(key == K_ENTER)
80         {
81                 if(me.cvarName)
82                 {
83                         me.saveCvars(me);
84                         r = 1;
85                 }
86                 me.onEnter(me, me.onEnterEntity);
87         }
88         if(keyDownInputBox(me, key, ascii, shift))
89                 r = 1;
90         return r;
91 }
92 #endif