]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/nexuiz/inputbox.c
slightly cleaned up favorites list. Thanks for the idea, esteel :)
[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                 me.loadCvars(me);
43         }
44         me.cursorPos = strlen(me.text);
45 }
46 void focusLeaveNexuizInputBox(entity me)
47 {
48         if(me.cvarName)
49                 me.saveCvars(me);
50 }
51 void setTextNexuizInputBox(entity me, string new)
52 {
53         if(me.text != new)
54         {
55                 setTextInputBox(me, new);
56                 me.onChange(me, me.onChangeEntity);
57         }
58         else
59                 setTextInputBox(me, new);
60 }
61 void loadCvarsNexuizInputBox(entity me)
62 {
63         setTextInputBox(me, cvar_string(me.cvarName));
64 }
65 void saveCvarsNexuizInputBox(entity me)
66 {
67         cvar_set(me.cvarName, me.text);
68 }
69 float keyDownNexuizInputBox(entity me, float key, float ascii, float shift)
70 {
71         float r;
72         r = 0;
73         if(key == K_ENTER)
74         {
75                 if(me.cvarName)
76                 {
77                         me.saveCvars(me);
78                         r = 1;
79                 }
80                 me.onEnter(me, me.onEnterEntity);
81         }
82         if(keyDownInputBox(me, key, ascii, shift))
83                 r = 1;
84         return r;
85 }
86 #endif