Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
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 41 of file colorpicker.qc.

42{
43 vector pos = '0 0 0';
44 v = rgb_to_hsl(v);
45 if (v.y)
46 {
47 pos.x = v.x / 6;
48 pos.y = v.z * 0.875;
49 }
50 else // grey scale
51 {
52 pos.x = v.z;
53 pos.y = 0.875 + 0.07;
54 }
55 pos.x = margin.x + pos.x * (1 - 2 * margin.x);
56 pos.y = margin.y + pos.y * (1 - 2 * margin.y);
57 return pos;
58}
ERASEABLE vector rgb_to_hsl(vector rgb)
Definition color.qh:147
vector
Definition self.qh:92

References rgb_to_hsl(), and vector.

Referenced by XonoticColorpicker::draw(), and XonoticColorpickerString_loadCvars().

◆ hslimage_color()

vector hslimage_color ( vector v,
vector margin )

Definition at line 25 of file colorpicker.qc.

26{
27 v.x = (v.x - margin.x) / (1 - 2 * margin.x);
28 v.y = (v.y - margin.y) / (1 - 2 * margin.y);
29
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
35 if(v.y > 0.875) // grey bar
36 return hsl_to_rgb(eZ * v.x);
37 else
38 return hsl_to_rgb(v.x * 6 * eX + eY + v.y / 0.875 * eZ);
39}
ERASEABLE vector hsl_to_rgb(vector hsl)
Definition color.qh:167
const vector eY
Definition vector.qh:45
const vector eZ
Definition vector.qh:46
const vector eX
Definition vector.qh:44

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

Referenced by XonoticColorpicker::draw(), XonoticColorpicker_mouseDrag(), and XonoticColorpickerString_saveCvars().

◆ makeXonoticColorpicker()

entity makeXonoticColorpicker ( entity theTextbox)

Definition at line 5 of file colorpicker.qc.

6{
7 entity me;
9 me.configureXonoticColorpicker(me, theTextbox);
10 return me;
11}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define NEW(cname,...)
Definition oo.qh:117

References entity(), and NEW.

Referenced by XonoticColorpicker::draw(), XonoticFirstRunDialog_fill(), and XonoticProfileTab_fill().

◆ XonoticColorpicker_configureXonoticColorpicker()

void XonoticColorpicker_configureXonoticColorpicker ( entity me,
entity theTextbox )

Definition at line 13 of file colorpicker.qc.

14{
15 me.controlledTextbox = theTextbox;
16 me.configureImage(me, me.image);
17}

References entity().

◆ XonoticColorpicker_draw()

void XonoticColorpicker_draw ( entity me)

Definition at line 110 of file colorpicker.qc.

111{
112 SUPER(XonoticColorpicker).draw(me);
113
114 float B, C, aC;
115 C = cvar("r_textcontrast");
116 B = cvar("r_textbrightness");
117
118 // for this to work, C/(1-B) must be in 0..1
119 // B must be < 1
120 // C must be < 1-B
121
122 B = bound(0, B, 1);
123 C = bound(0, C, 1-B);
124
125 aC = 1 - C / (1 - B);
126
127 draw_Picture(me.imgOrigin, strcat(me.src, "_m"), me.imgSize, '0 0 0', aC);
128 draw_Picture(me.imgOrigin, strcat(me.src, "_m"), me.imgSize, me.color, B);
129}
void draw_Picture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha)
Definition draw.qc:72
float bound(float min, float value, float max)
float cvar(string name)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define SUPER(cname)
Definition oo.qh:231

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

◆ XonoticColorpicker_focusLeave()

void XonoticColorpicker_focusLeave ( entity me)

Definition at line 102 of file colorpicker.qc.

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

References entity().

◆ XonoticColorpicker_keyDown()

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

Definition at line 106 of file colorpicker.qc.

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

References entity().

◆ XonoticColorpicker_mouseDrag()

float XonoticColorpicker_mouseDrag ( entity me,
vector coords )

Definition at line 60 of file colorpicker.qc.

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

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

◆ XonoticColorpicker_mouseRelease()

float XonoticColorpicker_mouseRelease ( entity me,
vector coords )

Definition at line 95 of file colorpicker.qc.

96{
98 me.mouseDrag(me, coords);
99 return 1;
100}
void m_play_click_sound(string soundfile)
Definition menu.qc:1106
const string MENU_SOUND_SLIDE
Definition menu.qh:55

References entity(), m_play_click_sound(), MENU_SOUND_SLIDE, and vector.