Xonotic
colorpicker.qc File Reference
#include "colorpicker.qh"
#include "inputbox.qh"
+ Include dependency graph for colorpicker.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

vector color_hslimage (vector v, vector margin)
 
vector hslimage_color (vector v, vector margin)
 
entity makeXonoticColorpicker (entity theTextbox)
 
void XonoticColorpicker_configureXonoticColorpicker (entity me, entity theTextbox)
 
void XonoticColorpicker_draw (entity me)
 
void XonoticColorpicker_focusLeave (entity me)
 
float XonoticColorpicker_keyDown (entity me, float key, float ascii, float shift)
 
float XonoticColorpicker_mouseDrag (entity me, vector coords)
 
float XonoticColorpicker_mouseRelease (entity me, vector coords)
 

Function Documentation

◆ color_hslimage()

vector color_hslimage ( vector  v,
vector  margin 
)

Definition at line 40 of file colorpicker.qc.

References rgb_to_hsl(), and vector().

Referenced by XonoticColorpickerString_loadCvars().

41 {
42  vector pos = '0 0 0';
43  v = rgb_to_hsl(v);
44  if (v.y)
45  {
46  pos_x = v.x / 6;
47  pos_y = v.z * 0.875;
48  }
49  else // grey scale
50  {
51  pos_x = v.z;
52  pos_y = 0.875 + 0.07;
53  }
54  pos_x = margin.x + pos.x * (1 - 2 * margin.x);
55  pos_y = margin.y + pos.y * (1 - 2 * margin.y);
56  return pos;
57 }
ERASEABLE vector rgb_to_hsl(vector rgb)
Definition: color.qh:147
vector(float skel, float bonenum) _skel_get_boneabs_hidden
vector v
Definition: ent_cs.qc:116
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hslimage_color()

vector hslimage_color ( vector  v,
vector  margin 
)

Definition at line 26 of file colorpicker.qc.

References eX, eY, eZ, and hsl_to_rgb().

Referenced by XonoticColorpicker_mouseDrag(), and XonoticColorpickerString_saveCvars().

27 {
28  v_x = (v.x - margin.x) / (1 - 2 * margin.x);
29  v_y = (v.y - margin.y) / (1 - 2 * margin.y);
30  if(v.x < 0) v_x = 0;
31  if(v.y < 0) v_y = 0;
32  if(v.x > 1) v_x = 1;
33  if(v.y > 1) v_y = 1;
34  if(v.y > 0.875) // grey bar
35  return hsl_to_rgb(eZ * v.x);
36  else
37  return hsl_to_rgb(v.x * 6 * eX + eY + v.y / 0.875 * eZ);
38 }
ERASEABLE vector hsl_to_rgb(vector hsl)
Definition: color.qh:167
const vector eY
Definition: vector.qh:45
vector v
Definition: ent_cs.qc:116
const vector eX
Definition: vector.qh:44
const vector eZ
Definition: vector.qh:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ makeXonoticColorpicker()

entity makeXonoticColorpicker ( entity  theTextbox)

Definition at line 5 of file colorpicker.qc.

References entity(), and NEW.

6 {
7  entity me;
9  me.configureXonoticColorpicker(me, theTextbox);
10  return me;
11 }
#define NEW(cname,...)
Definition: oo.qh:105
entity() spawn
+ Here is the call graph for this function:

◆ XonoticColorpicker_configureXonoticColorpicker()

void XonoticColorpicker_configureXonoticColorpicker ( entity  me,
entity  theTextbox 
)

Definition at line 13 of file colorpicker.qc.

References METHOD, and vector().

14 {
15  me.controlledTextbox = theTextbox;
16  me.configureImage(me, me.image);
17 }
+ Here is the call graph for this function:

◆ XonoticColorpicker_draw()

void XonoticColorpicker_draw ( entity  me)

Definition at line 109 of file colorpicker.qc.

References bound(), cvar(), draw_Picture(), strcat(), and SUPER.

110 {
111  SUPER(XonoticColorpicker).draw(me);
112 
113  float B, C, aC;
114  C = cvar("r_textcontrast");
115  B = cvar("r_textbrightness");
116 
117  // for this to work, C/(1-B) must be in 0..1
118  // B must be < 1
119  // C must be < 1-B
120 
121  B = bound(0, B, 1);
122  C = bound(0, C, 1-B);
123 
124  aC = 1 - C / (1 - B);
125 
126  draw_Picture(me.imgOrigin, strcat(me.src, "_m"), me.imgSize, '0 0 0', aC);
127  draw_Picture(me.imgOrigin, strcat(me.src, "_m"), me.imgSize, me.color, B);
128 }
#define SUPER(cname)
Definition: oo.qh:219
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"))
+ Here is the call graph for this function:

◆ XonoticColorpicker_focusLeave()

void XonoticColorpicker_focusLeave ( entity  me)

Definition at line 101 of file colorpicker.qc.

102 {
103  me.controlledTextbox.saveCvars(me.controlledTextbox);
104 }

◆ XonoticColorpicker_keyDown()

float XonoticColorpicker_keyDown ( entity  me,
float  key,
float  ascii,
float  shift 
)

Definition at line 105 of file colorpicker.qc.

106 {
107  return me.controlledTextbox.keyDown(me.controlledTextbox, key, ascii, shift);
108 }

◆ XonoticColorpicker_mouseDrag()

float XonoticColorpicker_mouseDrag ( entity  me,
vector  coords 
)

Definition at line 59 of file colorpicker.qc.

References checkColorCode(), hslimage_color(), isCaretEscaped(), rgb_to_hexcolor(), strcat(), strlen(), substring(), and vector().

60 {
61  int i;
62  for (;;)
63  {
64  i = me.controlledTextbox.cursorPos;
65  string theText = me.controlledTextbox.text;
66  vector res = checkColorCode(theText, strlen(theText), i, true);
67  if (!res.x)
68  break;
69 
70  int cc_len = res.x;
71  int new_pos = i - res.y;
72  theText = strcat(substring(theText, 0, new_pos), substring(theText, new_pos + cc_len, -1));
73  me.controlledTextbox.setText(me.controlledTextbox, theText);
74  me.controlledTextbox.cursorPos = new_pos;
75  }
76 
77  if(substring(me.controlledTextbox.text, i-1, 1) == "^")
78  {
79  if(!isCaretEscaped(me.controlledTextbox.text, i-1))
80  me.controlledTextbox.enterText(me.controlledTextbox, "^"); // escape previous caret
81  }
82 
83  vector margin;
84  margin = me.imagemargin;
85  if(coords.x >= margin.x)
86  if(coords.y >= margin.y)
87  if(coords.x <= 1 - margin.x)
88  if(coords.y <= 1 - margin.y)
89  me.controlledTextbox.enterText(me.controlledTextbox, rgb_to_hexcolor(hslimage_color(coords, margin)));
90 
91  return 1;
92 }
ERASEABLE bool isCaretEscaped(string theText, float pos)
Definition: string.qh:511
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
ERASEABLE vector checkColorCode(string theText, int text_len, int pos, bool check_at_the_end)
Definition: string.qh:540
ERASEABLE string rgb_to_hexcolor(vector rgb)
Definition: color.qh:183
+ Here is the call graph for this function:

◆ XonoticColorpicker_mouseRelease()

float XonoticColorpicker_mouseRelease ( entity  me,
vector  coords 
)

Definition at line 94 of file colorpicker.qc.

References m_play_click_sound(), and MENU_SOUND_SLIDE.

95 {
97  me.mouseDrag(me, coords);
98  return 1;
99 }
+ Here is the call graph for this function: