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