1 #ifndef CROSSHAIRBUTTON_H
2 #define CROSSHAIRBUTTON_H
3 #include "../item/radiobutton.qc"
4 CLASS(XonoticCrosshairButton, RadioButton)
5 METHOD(XonoticCrosshairButton, configureXonoticCrosshairButton, void(entity, float, float))
6 METHOD(XonoticCrosshairButton, setChecked, void(entity, float))
7 METHOD(XonoticCrosshairButton, draw, void(entity))
8 ATTRIB(XonoticCrosshairButton, fontSize, float, SKINFONTSIZE_NORMAL)
9 ATTRIB(XonoticCrosshairButton, image, string, SKINGFX_CROSSHAIRBUTTON)
11 ATTRIB(XonoticCrosshairButton, useDownAsChecked, float, 1)
12 ATTRIB(XonoticCrosshairButton, src3, string, string_null)
13 ATTRIB(XonoticCrosshairButton, src4, string, string_null)
15 ATTRIB(XonoticCrosshairButton, cvarName, string, string_null)
16 ATTRIB(XonoticCrosshairButton, cvarValueFloat, float, 0)
17 METHOD(XonoticCrosshairButton, loadCvars, void(entity))
18 METHOD(XonoticCrosshairButton, saveCvars, void(entity))
19 ENDCLASS(XonoticCrosshairButton)
20 entity makeXonoticCrosshairButton(float, float);
24 entity makeXonoticCrosshairButton(float theGroup, float theCrosshair)
27 me = NEW(XonoticCrosshairButton);
28 me.configureXonoticCrosshairButton(me, theGroup, theCrosshair);
31 void XonoticCrosshairButton_configureXonoticCrosshairButton(entity me, float theGroup, float theCrosshair)
33 me.cvarName = "crosshair";
34 me.cvarValueFloat = theCrosshair;
36 me.configureRadioButton(me, string_null, me.fontSize, me.image, theGroup, 0);
38 if(me.cvarValueFloat == -1)
39 me.src3 = strzone(strcat("/gfx/crosshair", cvar_string("crosshair")));
41 me.src3 = strzone(strcat("/gfx/crosshair", ftos(me.cvarValueFloat)));
42 me.src4 = "/gfx/crosshairdot";
44 void XonoticCrosshairButton_setChecked(entity me, float val)
46 if(me.cvarValueFloat != -1) // preview shouldn't work as a button
53 void XonoticCrosshairButton_loadCvars(entity me)
58 me.checked = (cvar(me.cvarName) == me.cvarValueFloat);
60 void XonoticCrosshairButton_saveCvars(entity me)
66 cvar_set(me.cvarName, ftos(me.cvarValueFloat));
67 // TODO on an apply button, read _cl_color and execute the color command for it
69 void XonoticCrosshairButton_draw(entity me)
75 if(me.cvarValueFloat == -1)
77 rgb = stov(cvar_string("crosshair_color"));
78 a = cvar("crosshair_alpha");
80 else if(me.checked || me.focused)
91 if(me.cvarValueFloat == -1) // update the preview if this is the preview button
95 me.src3 = strzone(strcat("/gfx/crosshair", cvar_string("crosshair")));
100 SUPER(XonoticCrosshairButton).draw(me);
102 sz = draw_PictureSize(me.src3);
103 sz = globalToBoxSize(sz, me.size);
104 if(me.cvarValueFloat == -1)
106 sz = sz * cvar("crosshair_size"); // (6 * '1 1 0' + ...) * 0.08 here to make visible size changes happen also at bigger sizes
109 sz = sz * (0.95 / sz_x);
111 sz = sz * (0.95 / sz_y);
114 else // show the crosshair picker at full size
116 sz = sz * (0.95 / sz.x);
118 sz = sz * (0.95 / sz.y);
121 draw_Picture('0.5 0.5 0' - 0.5 * sz, me.src3, sz, rgb, a);
122 if(cvar("crosshair_dot"))
124 if(cvar("crosshair_dot_color_custom") && (cvar_string("crosshair_dot_color") != "0"))
125 rgb = stov(cvar_string("crosshair_dot_color"));
127 draw_Picture('0.5 0.5 0' - 0.5 * sz * cvar("crosshair_dot_size"), me.src4, sz * cvar("crosshair_dot_size"), rgb, a * cvar("crosshair_dot_alpha"));