Xonotic
colorpicker_string.qc
Go to the documentation of this file.
1 #include "colorpicker_string.qh"
2 
3 .bool disabled;
4 
5 entity makeXonoticColorpickerString(string theCvar, string theDefaultCvar)
6 {
7  entity me;
9  me.configureXonoticColorpickerString(me, theCvar, theDefaultCvar);
10  return me;
11 }
12 
13 void XonoticColorpickerString_configureXonoticColorpickerString(entity me, string theCvar, string theDefaultCvar)
14 {
15  me.configureImage(me, me.image);
16  me.controlledCvar = (theCvar) ? theCvar : string_null;
17  me.loadCvars(me);
18 }
19 
21 {
22  if (!me.controlledCvar)
23  return;
24 
25  if(substring(me.controlledCvar, -1, 1) == "_")
26  {
27  me.prevcoords = color_hslimage(
28  eX * cvar(strcat(me.controlledCvar, "red")) +
29  eY * cvar(strcat(me.controlledCvar, "green")) +
30  eZ * cvar(strcat(me.controlledCvar, "blue")),
31  me.imagemargin);
32  }
33  else
34  me.prevcoords = color_hslimage(stov(cvar_string(me.controlledCvar)), me.imagemargin);
35 }
36 
38 {
39  if (!me.controlledCvar)
40  return;
41 
42  if(substring(me.controlledCvar, -1, 1) == "_")
43  {
44  vector v = hslimage_color(me.prevcoords, me.imagemargin);
45  cvar_set(strcat(me.controlledCvar, "red"), ftos(v.x));
46  cvar_set(strcat(me.controlledCvar, "green"), ftos(v.y));
47  cvar_set(strcat(me.controlledCvar, "blue"), ftos(v.z));
48  }
49  else
50  cvar_set(me.controlledCvar, sprintf("%v", hslimage_color(me.prevcoords, me.imagemargin)));
51 }
52 
54 {
55  this.mouseDrag(this, pos);
56  return true;
57 }
58 
60 {
61  if(me.disabled)
62  return 0;
63  vector margin;
64  margin = me.imagemargin;
65  if(coords.x >= margin.x)
66  if(coords.y >= margin.y)
67  if(coords.x <= 1 - margin.x)
68  if(coords.y <= 1 - margin.y)
69  {
70  me.prevcoords = coords;
71  me.saveCvars(me);
72  }
73 
74  return 1;
75 }
76 
78 {
80  me.mouseDrag(me, coords);
81  return 1;
82 }
83 
85 {
86  float save;
87  save = draw_alpha;
88  if(me.disabled)
89  draw_alpha *= me.disabledAlpha;
90 
92 
93  vector sz;
94  sz = draw_PictureSize(strcat(me.src, "_selected"));
95  sz = globalToBoxSize(sz, draw_scale);
96 
97  if(!me.disabled)
98  draw_Picture(me.imgOrigin + me.prevcoords - 0.5 * sz, strcat(me.src, "_selected"), sz, '1 1 1', 1);
99 
100  draw_alpha = save;
101 }
string string_null
Definition: nil.qh:9
const vector eY
Definition: vector.qh:45
#define NEW(cname,...)
Definition: oo.qh:105
float XonoticColorpickerString_mouseDrag(entity me, vector coords)
entity() spawn
bool disabled
void XonoticColorpickerString_configureXonoticColorpickerString(entity me, string theCvar, string theDefaultCvar)
void XonoticColorpickerString_draw(entity me)
#define METHOD(cname, name, prototype)
Definition: oo.qh:257
#define SUPER(cname)
Definition: oo.qh:219
float XonoticColorpickerString_mouseRelease(entity me, vector coords)
void XonoticColorpickerString_loadCvars(entity me)
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
vector hslimage_color(vector v, vector margin)
Definition: colorpicker.qc:26
vector(float skel, float bonenum) _skel_get_boneabs_hidden
entity makeXonoticColorpickerString(string theCvar, string theDefaultCvar)
vector v
Definition: ent_cs.qc:116
const vector eX
Definition: vector.qh:44
const vector eZ
Definition: vector.qh:46
vector color_hslimage(vector v, vector margin)
Definition: colorpicker.qc:40
void XonoticColorpickerString_saveCvars(entity me)