summaryrefslogtreecommitdiff
path: root/src/bin/options_colors.c
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2013-12-16 23:51:35 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2013-12-16 23:53:01 +0900
commitf40eab09f26f4ee2c6008dbd0f6ca1a2da8516b1 (patch)
treed33ff9f196eec085da8ec907ffaad7a5b8b0f497 /src/bin/options_colors.c
parent6ea42c38ae74e28638dedd4c77988f5d373d562d (diff)
color options - fill in colors options panel.
this makes the colors config work and able to save/load a custom color palette. when enabled it overrides the theme provided palette for the "base" 48 colors (normal + bright with intense modes of each).
Diffstat (limited to 'src/bin/options_colors.c')
-rw-r--r--src/bin/options_colors.c269
1 files changed, 263 insertions, 6 deletions
diff --git a/src/bin/options_colors.c b/src/bin/options_colors.c
index 62bc69f..10f025d 100644
--- a/src/bin/options_colors.c
+++ b/src/bin/options_colors.c
@@ -6,15 +6,272 @@
6#include "options.h" 6#include "options.h"
7#include "options_colors.h" 7#include "options_colors.h"
8 8
9void 9static const char mapping[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11 };
10options_colors(Evas_Object *opbox, Evas_Object *term EINA_UNUSED) 10static const char *mapping_names[] =
11 {
12 "Default",
13 "Black",
14 "Red",
15 "Green",
16 "Yellow",
17 "Blue",
18 "Magenta",
19 "Cyan",
20 "White",
21 "Inverse",
22 "Inverse Base"
23 };
24
25static Elm_Object_Item *colitem[4][11] = { { NULL } };
26static Evas_Object *colorsel = NULL;
27static Elm_Object_Item *curitem = NULL;
28static Evas_Object *colpal[4] = { NULL };
29static Evas_Object *label = NULL, *reset = NULL;
30
31static void
32_cb_op_use_custom_chg(void *data EINA_UNUSED, Evas_Object *obj, void *event EINA_UNUSED)
33{
34 Evas_Object *term = data;
35 Config *config = termio_config_get(term);
36 Eina_Bool state = EINA_FALSE;
37 int i;
38
39 state = elm_check_state_get(obj);
40 elm_object_disabled_set(colorsel, !state);
41 for (i = 0; i < 4; i++) elm_object_disabled_set(colpal[i], !state);
42 elm_object_disabled_set(label, !state);
43 config->colors_use = state;
44 termio_config_update(term);
45 config_save(config, NULL);
46}
47
48static void
49_cb_op_color_item_sel(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event)
50{
51 Elm_Object_Item *it = event;
52 int r = 0, g = 0, b = 0, a = 0;
53 int i, j;
54
55 curitem = it;
56 elm_colorselector_palette_item_color_get(it, &r, &g, &b, &a);
57 elm_colorselector_color_set(colorsel, r, g, b, a);
58 for (j = 0; j < 4; j++)
59 {
60 for (i = 0; i < 11; i++)
61 {
62 if (colitem[j][i] == it)
63 elm_object_text_set(label, mapping_names[i]);
64 }
65 }
66}
67
68static void
69_cb_op_color_chg(void *data EINA_UNUSED, Evas_Object *obj, void *event EINA_UNUSED)
11{ 70{
12 Evas_Object *o; 71 Evas_Object *term = data;
72 Config *config = termio_config_get(term);
73 int r = 0, g = 0, b = 0, a = 0, rr = 0, gg = 0, bb = 0, aa = 0;
74 int i, j;
13 75
14 o = elm_label_add(opbox); 76 elm_colorselector_palette_item_color_get(curitem, &rr, &gg, &bb, &aa);
77 elm_colorselector_color_get(obj, &r, &g, &b, &a);
78 if ((r != rr) || (g != gg) || (b != bb) || (a != aa))
79 {
80 if (curitem)
81 elm_colorselector_palette_item_color_set(curitem, r, g, b, a);
82 elm_object_disabled_set(reset, EINA_FALSE);
83 for (j = 0; j < 4; j++)
84 {
85 for (i = 0; i < 11; i++)
86 {
87 if (colitem[j][i] == curitem)
88 {
89 config->colors[(j * 12) + mapping[i]].r = r;
90 config->colors[(j * 12) + mapping[i]].g = g;
91 config->colors[(j * 12) + mapping[i]].b = b;
92 config->colors[(j * 12) + mapping[i]].a = a;
93 termio_config_update(term);
94 config_save(config, NULL);
95 return;
96 }
97 }
98 }
99 }
100}
101
102static void
103_cb_op_reset(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
104{
105 Evas_Object *term = data;
106 Config *config = termio_config_get(term);
107 int r = 0, g = 0, b = 0, a = 0;
108 int i, j;
109
110 for (j = 0; j < 4; j++)
111 {
112 for (i = 0; i < 12; i++)
113 {
114 unsigned char rr = 0, gg = 0, bb = 0, aa = 0;
115
116 colors_standard_get(j, i, &rr, &gg, &bb, &aa);
117 config->colors[(j * 12) + i].r = rr;
118 config->colors[(j * 12) + i].g = gg;
119 config->colors[(j * 12) + i].b = bb;
120 config->colors[(j * 12) + i].a = aa;
121 }
122 for (i = 0; i < 11; i++)
123 {
124 elm_colorselector_palette_item_color_set
125 (colitem[j][i],
126 config->colors[(j * 12) + mapping[i]].r,
127 config->colors[(j * 12) + mapping[i]].g,
128 config->colors[(j * 12) + mapping[i]].b,
129 config->colors[(j * 12) + mapping[i]].a);
130 }
131 }
132 elm_object_disabled_set(reset, EINA_TRUE);
133 elm_colorselector_palette_item_color_get(curitem, &r, &g, &b, &a);
134 elm_colorselector_color_set(colorsel, r, g, b, a);
135 termio_config_update(term);
136 config_save(config, NULL);
137}
138
139static void
140_cb_op_scroller_resize(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
141{
142 // make color palettes wrap back. :) works with elm git.
143 int i;
144
145 for (i = 0; i < 4; i++) evas_object_resize(colpal[i], 1, 1);
146}
147
148void
149options_colors(Evas_Object *opbox, Evas_Object *term)
150{
151 Config *config = termio_config_get(term);
152 Evas_Object *o, *fr, *bx, *sc, *bx2, *bx3, *bx4;
153 int i, j;
154 int r = 0, g = 0, b = 0, a = 0;
155
156 fr = o = elm_frame_add(opbox);
15 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 157 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
16 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); 158 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
17 elm_object_text_set(o, "Not Implemented Yet."); 159 elm_object_text_set(o, "Colors");
18 evas_object_show(o);
19 elm_box_pack_end(opbox, o); 160 elm_box_pack_end(opbox, o);
161 evas_object_show(o);
162
163 bx = o = elm_box_add(opbox);
164 elm_box_horizontal_set(o, EINA_TRUE);
165 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
166 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
167 elm_object_content_set(fr, o);
168 evas_object_show(o);
169
170 sc = o = elm_scroller_add(opbox);
171 evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE,
172 _cb_op_scroller_resize, NULL);
173 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
174 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
175 elm_box_pack_end(bx, o);
176 evas_object_show(o);
177
178 bx3 = o = elm_box_add(opbox);
179 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
180 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
181 elm_object_content_set(sc, o);
182 evas_object_show(o);
183
184 for (j = 0; j < 4; j++)
185 {
186 o = elm_label_add(opbox);
187 if (j == 0) elm_object_text_set(o, "Normal");
188 else if (j == 1) elm_object_text_set(o, "Bright");
189 else if (j == 2) elm_object_text_set(o, "Normal 2");
190 else if (j == 3) elm_object_text_set(o, "Bright 2");
191 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
192 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
193 elm_box_pack_end(bx3, o);
194 evas_object_show(o);
195
196 colpal[j] = o = elm_colorselector_add(opbox);
197 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
198 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
199 elm_colorselector_mode_set(o, ELM_COLORSELECTOR_PALETTE);
200 for (i = 0; i < 11; i++)
201 {
202 Elm_Object_Item *it;
203
204 it = elm_colorselector_palette_color_add
205 (o,
206 config->colors[(j * 12) + mapping[i]].r,
207 config->colors[(j * 12) + mapping[i]].g,
208 config->colors[(j * 12) + mapping[i]].b,
209 config->colors[(j * 12) + mapping[i]].a);
210 colitem[j][i] = it;
211 }
212 evas_object_smart_callback_add(o, "color,item,selected",
213 _cb_op_color_item_sel, term);
214 elm_box_pack_end(bx3, o);
215 evas_object_show(o);
216 if (j == 1)
217 {
218 o = elm_separator_add(opbox);
219 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
220 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
221 elm_separator_horizontal_set(o, EINA_TRUE);
222 elm_box_pack_end(bx3, o);
223 evas_object_show(o);
224 }
225 }
226
227 curitem = colitem[0][0];
228
229 bx2 = o = elm_box_add(opbox);
230 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
231 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
232 elm_box_pack_end(bx, o);
233 evas_object_show(o);
234
235 label = o = elm_label_add(opbox);
236 elm_object_text_set(o, mapping_names[0]);
237 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
238 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
239 elm_box_pack_end(bx2, o);
240 evas_object_show(o);
241
242 colorsel = o = elm_colorselector_add(opbox);
243 elm_colorselector_palette_item_color_get(colitem[0][0], &r, &g, &b, &a);
244 elm_colorselector_color_set(o, r, g, b, a);
245 elm_colorselector_mode_set(o, ELM_COLORSELECTOR_COMPONENTS);
246 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
247 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
248 elm_box_pack_end(bx2, o);
249 evas_object_show(o);
250 evas_object_smart_callback_add(o, "changed", _cb_op_color_chg, term);
251
252 bx4 = o = elm_box_add(opbox);
253 elm_box_horizontal_set(o, EINA_TRUE);
254 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
255 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
256 elm_box_pack_end(bx2, o);
257 evas_object_show(o);
258
259 o = elm_check_add(opbox);
260 evas_object_size_hint_weight_set(o, 1.0, 0.0);
261 evas_object_size_hint_align_set(o, 0.0, 0.5);
262 elm_object_text_set(o, "Use");
263 elm_check_state_set(o, config->colors_use);
264 elm_box_pack_end(bx4, o);
265 evas_object_show(o);
266 evas_object_smart_callback_add(o, "changed", _cb_op_use_custom_chg, term);
267
268 reset = o = elm_button_add(opbox);
269 elm_object_disabled_set(o, EINA_TRUE);
270 evas_object_size_hint_weight_set(o, 1.0, 0.0);
271 evas_object_size_hint_align_set(o, 1.0, 0.5);
272 elm_object_text_set(o, "Reset");
273 elm_box_pack_end(bx4, o);
274 evas_object_show(o);
275 evas_object_smart_callback_add(o, "clicked", _cb_op_reset, term);
276
20} 277}