Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
colorpicker.qc
Go to the documentation of this file.
1#include "colorpicker.qh"
2
3#include "inputbox.qh"
4
6{
8 me.configureXonoticColorpicker(me, theTextbox);
9 return me;
10}
11
13{
14 me.controlledTextbox = theTextbox;
15 me.configureImage(me, me.image);
16}
17
19{
20 this.mouseDrag(this, pos);
21 return true;
22}
23
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}
39
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}
58
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}
92
94{
96 me.mouseDrag(me, coords);
97 return 1;
98}
99
101{
102 me.controlledTextbox.saveCvars(me.controlledTextbox);
103}
104float XonoticColorpicker_keyDown(entity me, float key, float ascii, float shift)
105{
106 return me.controlledTextbox.keyDown(me.controlledTextbox, key, ascii, shift);
107}
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}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
virtual void mouseDrag()
virtual void mousePress()
ERASEABLE string rgb_to_hexcolor(vector rgb)
Definition color.qh:183
ERASEABLE vector rgb_to_hsl(vector rgb)
Definition color.qh:147
ERASEABLE vector hsl_to_rgb(vector hsl)
Definition color.qh:167
void XonoticColorpicker_configureXonoticColorpicker(entity me, entity theTextbox)
vector hslimage_color(vector v, vector margin)
entity makeXonoticColorpicker(entity theTextbox)
Definition colorpicker.qc:5
void XonoticColorpicker_draw(entity me)
float XonoticColorpicker_mouseDrag(entity me, vector coords)
float XonoticColorpicker_keyDown(entity me, float key, float ascii, float shift)
float XonoticColorpicker_mouseRelease(entity me, vector coords)
vector color_hslimage(vector v, vector margin)
void XonoticColorpicker_focusLeave(entity me)
#define strlen
void draw_Picture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha)
Definition draw.qc:72
void m_play_click_sound(string soundfile)
Definition menu.qc:1111
const string MENU_SOUND_SLIDE
Definition menu.qh:55
float bound(float min, float value, float max)
string substring(string s, float start, float length)
float cvar(string name)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define NEW(cname,...)
Definition oo.qh:117
#define SUPER(cname)
Definition oo.qh:231
#define METHOD(cname, name, prototype)
Definition oo.qh:269
vector
Definition self.qh:92
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
const vector eY
Definition vector.qh:45
const vector eZ
Definition vector.qh:46
const vector eX
Definition vector.qh:44