]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/inputbox.c
Merge remote-tracking branch 'origin/master' into samual/update_effects_tab
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / inputbox.c
1 #ifdef INTERFACE
2 CLASS(XonoticInputBox) EXTENDS(InputBox)
3         METHOD(XonoticInputBox, configureXonoticInputBox, void(entity, float, string))
4         METHOD(XonoticInputBox, focusLeave, void(entity))
5         METHOD(XonoticInputBox, setText, void(entity, string))
6         ATTRIB(XonoticInputBox, fontSize, float, SKINFONTSIZE_NORMAL)
7         ATTRIB(XonoticInputBox, image, string, SKINGFX_INPUTBOX)
8         ATTRIB(XonoticInputBox, onChange, void(entity, entity), func_null)
9         ATTRIB(XonoticInputBox, onChangeEntity, entity, NULL)
10         ATTRIB(XonoticInputBox, onEnter, void(entity, entity), func_null)
11         ATTRIB(XonoticInputBox, onEnterEntity, entity, NULL)
12         ATTRIB(XonoticInputBox, marginLeft, float, SKINMARGIN_INPUTBOX_CHARS)
13         ATTRIB(XonoticInputBox, marginRight, float, SKINMARGIN_INPUTBOX_CHARS)
14         ATTRIB(XonoticInputBox, color, vector, SKINCOLOR_INPUTBOX_N)
15         ATTRIB(XonoticInputBox, colorF, vector, SKINCOLOR_INPUTBOX_F)
16
17         ATTRIB(XonoticInputBox, alpha, float, SKINALPHA_TEXT)
18
19         // Clear button attributes
20         ATTRIB(XonoticInputBox, cb_offset, float, SKINOFFSET_CLEARBUTTON) // bound to range -1, 0
21         ATTRIB(XonoticInputBox, cb_src, string, SKINGFX_CLEARBUTTON)
22         ATTRIB(XonoticInputBox, cb_color, vector, SKINCOLOR_CLEARBUTTON_N)
23         ATTRIB(XonoticInputBox, cb_colorF, vector, SKINCOLOR_CLEARBUTTON_F)
24         ATTRIB(XonoticInputBox, cb_colorC, vector, SKINCOLOR_CLEARBUTTON_C)
25
26         ATTRIB(XonoticInputBox, cvarName, string, string_null)
27         METHOD(XonoticInputBox, loadCvars, void(entity))
28         METHOD(XonoticInputBox, saveCvars, void(entity))
29         METHOD(XonoticInputBox, keyDown, float(entity, float, float, float))
30
31         ATTRIB(XonoticInputBox, saveImmediately, float, 0)
32 ENDCLASS(XonoticInputBox)
33 entity makeXonoticInputBox(float, string);
34 #endif
35
36 #ifdef IMPLEMENTATION
37 entity makeXonoticInputBox(float doEditColorCodes, string theCvar)
38 {
39         entity me;
40         me = spawnXonoticInputBox();
41         me.configureXonoticInputBox(me, doEditColorCodes, theCvar);
42         return me;
43 }
44 void XonoticInputBox_configureXonoticInputBox(entity me, float doEditColorCodes, string theCvar)
45 {
46         me.configureInputBox(me, "", 0, me.fontSize, me.image);
47         me.editColorCodes = doEditColorCodes;
48         if(theCvar)
49         {
50                 me.cvarName = theCvar;
51                 me.tooltip = getZonedTooltipForIdentifier(theCvar);
52                 me.loadCvars(me);
53         }
54         me.cursorPos = strlen(me.text);
55 }
56 void XonoticInputBox_focusLeave(entity me)
57 {
58         me.saveCvars(me);
59 }
60 void XonoticInputBox_setText(entity me, string new)
61 {
62         if(me.text != new)
63         {
64                 SUPER(XonoticInputBox).setText(me, new);
65                 if(me.onChange)
66                         me.onChange(me, me.onChangeEntity);
67                 if(me.saveImmediately)
68                         me.saveCvars(me);
69         }
70         else
71                 SUPER(XonoticInputBox).setText(me, new);
72 }
73 void XonoticInputBox_loadCvars(entity me)
74 {
75         if not(me.cvarName)
76                 return;
77         SUPER(XonoticInputBox).setText(me, cvar_string(me.cvarName));
78 }
79 void XonoticInputBox_saveCvars(entity me)
80 {
81         if not(me.cvarName)
82                 return;
83         cvar_set(me.cvarName, me.text);
84 }
85 float XonoticInputBox_keyDown(entity me, float key, float ascii, float shift)
86 {
87         float r;
88         r = 0;
89         if(key == K_ENTER || key == K_KP_ENTER)
90         {
91                 if(me.cvarName)
92                 {
93                         me.saveCvars(me);
94                         r = 1;
95                 }
96                 if(me.onEnter)
97                         me.onEnter(me, me.onEnterEntity);
98         }
99         if(SUPER(XonoticInputBox).keyDown(me, key, ascii, shift))
100                 r = 1;
101         return r;
102 }
103 #endif