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 40 of file colorpicker.qc.

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
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 24 of file colorpicker.qc.

25{
26 v.x = (v.x - margin.x) / (1 - 2 * margin.x);
27 v.y = (v.y - margin.y) / (1 - 2 * margin.y);
28
29 if(v.x < 0) v.x = 0;
30 if(v.y < 0) v.y = 0;
31 if(v.x > 1) v.x = 1;
32 if(v.y > 1) v.y = 1;
33
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
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{
8 me.configureXonoticColorpicker(me, theTextbox);
9 return me;
10}
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 12 of file colorpicker.qc.

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

References entity().

◆ XonoticColorpicker_draw()

void XonoticColorpicker_draw ( entity me)

Definition at line 108 of file colorpicker.qc.

109{
110 SUPER(XonoticColorpicker).draw(me);
111
112 float B, C, aC;
113 C = cvar("r_textcontrast");
114 B = cvar("r_textbrightness");
115
116 // for this to work, C/(1-B) must be in 0..1
117 // B must be < 1
118 // C must be < 1-B
119
120 B = bound(0, B, 1);
121 C = bound(0, C, 1-B);
122
123 aC = 1 - C / (1 - B);
124
125 draw_Picture(me.imgOrigin, strcat(me.src, "_m"), me.imgSize, '0 0 0', aC);
126 draw_Picture(me.imgOrigin, strcat(me.src, "_m"), me.imgSize, me.color, B);
127}
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 100 of file colorpicker.qc.

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

References entity().

◆ XonoticColorpicker_keyDown()

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

Definition at line 104 of file colorpicker.qc.

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

References entity().

◆ XonoticColorpicker_mouseDrag()

float XonoticColorpicker_mouseDrag ( entity me,
vector coords )

Definition at line 59 of file colorpicker.qc.

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 = me.imagemargin;
84 if(coords.x >= margin.x)
85 if(coords.y >= margin.y)
86 if(coords.x <= 1 - margin.x)
87 if(coords.y <= 1 - margin.y)
88 me.controlledTextbox.enterText(me.controlledTextbox, rgb_to_hexcolor(hslimage_color(coords, margin)));
89
90 return 1;
91}
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:579
ERASEABLE vector checkColorCode(string theText, int text_len, int pos, bool check_at_the_end)
Definition string.qh:608

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 93 of file colorpicker.qc.

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

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