summaryrefslogtreecommitdiff
path: root/src/bin/options_colors.c
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2018-01-15 22:51:16 +0100
committerBoris Faure <billiob@gmail.com>2018-01-15 22:51:16 +0100
commitf33e898e291e95d133358e5f79083fb374eaa1b4 (patch)
treed998d2dc8ba29f6ab66f122596c9f418342fb3ba /src/bin/options_colors.c
parent820a5440fe348fabe78fed3aeb87c6a53b5a4855 (diff)
options_colors: clean up a bit and have a global reset button
Diffstat (limited to 'src/bin/options_colors.c')
-rw-r--r--src/bin/options_colors.c161
1 files changed, 91 insertions, 70 deletions
diff --git a/src/bin/options_colors.c b/src/bin/options_colors.c
index 092ebbc..88bea6e 100644
--- a/src/bin/options_colors.c
+++ b/src/bin/options_colors.c
@@ -7,8 +7,6 @@
7#include "options.h" 7#include "options.h"
8#include "options_colors.h" 8#include "options_colors.h"
9 9
10
11static const char mapping[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11 };
12static const char *mapping_names[] = 10static const char *mapping_names[] =
13 { 11 {
14 gettext_noop("Default"), 12 gettext_noop("Default"),
@@ -20,12 +18,13 @@ static const char *mapping_names[] =
20 gettext_noop("Magenta"), 18 gettext_noop("Magenta"),
21 gettext_noop("Cyan"), 19 gettext_noop("Cyan"),
22 gettext_noop("White"), 20 gettext_noop("White"),
21 gettext_noop("Invisible"),
23 gettext_noop("Inverse"), 22 gettext_noop("Inverse"),
24 gettext_noop("Inverse Base") 23 gettext_noop("Inverse Background")
25 }; 24 };
26 25
27typedef struct _Colors_Ctx { 26typedef struct _Colors_Ctx {
28 Elm_Object_Item *colitem[4][11]; 27 Elm_Object_Item *colitem[4][12];
29 Evas_Object *colorsel; 28 Evas_Object *colorsel;
30 Elm_Object_Item *curitem; 29 Elm_Object_Item *curitem;
31 Evas_Object *colpal[4]; 30 Evas_Object *colpal[4];
@@ -33,32 +32,10 @@ typedef struct _Colors_Ctx {
33 Evas_Object *reset; 32 Evas_Object *reset;
34 Config *config; 33 Config *config;
35 Evas_Object *term; 34 Evas_Object *term;
35 Evas_Object *bg;
36} Colors_Ctx; 36} Colors_Ctx;
37 37
38static void 38static void
39_cb_op_use_custom_chg(void *data,
40 Evas_Object *obj,
41 void *_event EINA_UNUSED)
42{
43 Colors_Ctx *ctx = data;
44 Evas_Object *term = ctx->term;
45 Config *config = ctx->config;
46 Eina_Bool state = EINA_FALSE;
47 int i;
48
49 state = elm_check_state_get(obj);
50 elm_object_disabled_set(ctx->colorsel, !state);
51
52 for (i = 0; i < 4; i++)
53 elm_object_disabled_set(ctx->colpal[i], !state);
54
55 elm_object_disabled_set(ctx->label, !state);
56 config->colors_use = state;
57 termio_config_update(term);
58 config_save(config, NULL);
59}
60
61static void
62_cb_op_color_item_sel(void *data, 39_cb_op_color_item_sel(void *data,
63 Evas_Object *_obj EINA_UNUSED, 40 Evas_Object *_obj EINA_UNUSED,
64 void *event) 41 void *event)
@@ -73,8 +50,10 @@ _cb_op_color_item_sel(void *data,
73 elm_colorselector_color_set(ctx->colorsel, r, g, b, a); 50 elm_colorselector_color_set(ctx->colorsel, r, g, b, a);
74 for (j = 0; j < 4; j++) 51 for (j = 0; j < 4; j++)
75 { 52 {
76 for (i = 0; i < 11; i++) 53 for (i = 0; i < 12; i++)
77 { 54 {
55 if (i == COL_INVIS)
56 continue;
78 if (ctx->colitem[j][i] == it) 57 if (ctx->colitem[j][i] == it)
79 elm_object_text_set(ctx->label, 58 elm_object_text_set(ctx->label,
80#if HAVE_GETTEXT && ENABLE_NLS 59#if HAVE_GETTEXT && ENABLE_NLS
@@ -104,16 +83,19 @@ _cb_op_color_chg(void *data,
104 if (ctx->curitem) 83 if (ctx->curitem)
105 elm_colorselector_palette_item_color_set(ctx->curitem, r, g, b, a); 84 elm_colorselector_palette_item_color_set(ctx->curitem, r, g, b, a);
106 elm_object_disabled_set(ctx->reset, EINA_FALSE); 85 elm_object_disabled_set(ctx->reset, EINA_FALSE);
86 config->colors_use = EINA_TRUE;
107 for (j = 0; j < 4; j++) 87 for (j = 0; j < 4; j++)
108 { 88 {
109 for (i = 0; i < 11; i++) 89 for (i = 0; i < 12; i++)
110 { 90 {
91 if (i == COL_INVIS)
92 continue;
111 if (ctx->colitem[j][i] == ctx->curitem) 93 if (ctx->colitem[j][i] == ctx->curitem)
112 { 94 {
113 config->colors[(j * 12) + mapping[i]].r = r; 95 config->colors[(j * 12) + i].r = r;
114 config->colors[(j * 12) + mapping[i]].g = g; 96 config->colors[(j * 12) + i].g = g;
115 config->colors[(j * 12) + mapping[i]].b = b; 97 config->colors[(j * 12) + i].b = b;
116 config->colors[(j * 12) + mapping[i]].a = a; 98 config->colors[(j * 12) + i].a = a;
117 termio_config_update(ctx->term); 99 termio_config_update(ctx->term);
118 config_save(config, NULL); 100 config_save(config, NULL);
119 return; 101 return;
@@ -124,6 +106,48 @@ _cb_op_color_chg(void *data,
124} 106}
125 107
126static void 108static void
109_reset_config_colors(Colors_Ctx *ctx)
110{
111 int i, j;
112
113 for (j = 0; j < 4; j++)
114 {
115 for (i = 0; i < 12; i++)
116 {
117 int r, g, b, a;
118 unsigned char rr = 0, gg = 0, bb = 0, aa = 0;
119 char buf[32];
120
121 if (i == COL_INVIS)
122 continue;
123
124 snprintf(buf, sizeof(buf) - 1, "c%i", j * 12 + i);
125 if (!edje_object_color_class_get(ctx->bg, buf,
126 &r,
127 &g,
128 &b,
129 &a,
130 NULL, NULL, NULL, NULL,
131 NULL, NULL, NULL, NULL))
132 {
133 colors_standard_get(j, i, &rr, &gg, &bb, &aa);
134 }
135 else
136 {
137 rr = r;
138 gg = g;
139 bb = b;
140 aa = a;
141 }
142 ctx->config->colors[(j * 12) + i].r = rr;
143 ctx->config->colors[(j * 12) + i].g = gg;
144 ctx->config->colors[(j * 12) + i].b = bb;
145 ctx->config->colors[(j * 12) + i].a = aa;
146 }
147 }
148}
149
150static void
127_cb_op_reset(void *data, 151_cb_op_reset(void *data,
128 Evas_Object *_obj EINA_UNUSED, 152 Evas_Object *_obj EINA_UNUSED,
129 void *_event EINA_UNUSED) 153 void *_event EINA_UNUSED)
@@ -134,29 +158,24 @@ _cb_op_reset(void *data,
134 int r = 0, g = 0, b = 0, a = 0; 158 int r = 0, g = 0, b = 0, a = 0;
135 int i, j; 159 int i, j;
136 160
161 _reset_config_colors(ctx);
137 for (j = 0; j < 4; j++) 162 for (j = 0; j < 4; j++)
138 { 163 {
139 for (i = 0; i < 12; i++) 164 for (i = 0; i < 12; i++)
140 { 165 {
141 unsigned char rr = 0, gg = 0, bb = 0, aa = 0; 166 if (i == COL_INVIS)
167 continue;
142 168
143 colors_standard_get(j, i, &rr, &gg, &bb, &aa);
144 config->colors[(j * 12) + i].r = rr;
145 config->colors[(j * 12) + i].g = gg;
146 config->colors[(j * 12) + i].b = bb;
147 config->colors[(j * 12) + i].a = aa;
148 }
149 for (i = 0; i < 11; i++)
150 {
151 elm_colorselector_palette_item_color_set 169 elm_colorselector_palette_item_color_set
152 (ctx->colitem[j][i], 170 (ctx->colitem[j][i],
153 config->colors[(j * 12) + mapping[i]].r, 171 config->colors[(j * 12) + i].r,
154 config->colors[(j * 12) + mapping[i]].g, 172 config->colors[(j * 12) + i].g,
155 config->colors[(j * 12) + mapping[i]].b, 173 config->colors[(j * 12) + i].b,
156 config->colors[(j * 12) + mapping[i]].a); 174 config->colors[(j * 12) + i].a);
157 } 175 }
158 } 176 }
159 elm_object_disabled_set(ctx->reset, EINA_TRUE); 177 elm_object_disabled_set(ctx->reset, EINA_TRUE);
178 config->colors_use = EINA_FALSE;
160 elm_colorselector_palette_item_color_get(ctx->curitem, &r, &g, &b, &a); 179 elm_colorselector_palette_item_color_get(ctx->curitem, &r, &g, &b, &a);
161 elm_colorselector_color_set(ctx->colorsel, r, g, b, a); 180 elm_colorselector_color_set(ctx->colorsel, r, g, b, a);
162 termio_config_update(term); 181 termio_config_update(term);
@@ -222,12 +241,12 @@ options_colors(Evas_Object *opbox, Evas_Object *term, Evas_Object *bg)
222 evas_object_show(o); 241 evas_object_show(o);
223 242
224 sc = o = elm_scroller_add(opbox); 243 sc = o = elm_scroller_add(opbox);
225 evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE,
226 _cb_op_scroller_resize, ctx);
227 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 244 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
228 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); 245 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
229 elm_box_pack_end(bx, o); 246 elm_box_pack_end(bx, o);
230 evas_object_show(o); 247 evas_object_show(o);
248 evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE,
249 _cb_op_scroller_resize, ctx);
231 250
232 bx3 = o = elm_box_add(opbox); 251 bx3 = o = elm_box_add(opbox);
233 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); 252 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
@@ -235,13 +254,21 @@ options_colors(Evas_Object *opbox, Evas_Object *term, Evas_Object *bg)
235 elm_object_content_set(sc, o); 254 elm_object_content_set(sc, o);
236 evas_object_show(o); 255 evas_object_show(o);
237 256
257 if (!config->colors_use)
258 {
259 _reset_config_colors(ctx);
260 }
238 for (j = 0; j < 4; j++) 261 for (j = 0; j < 4; j++)
239 { 262 {
240 o = elm_label_add(opbox); 263 o = elm_label_add(opbox);
241 if (j == 0) elm_object_text_set(o, _("Normal")); 264 if (j == 0)
242 else if (j == 1) elm_object_text_set(o, _("Bright/Bold")); 265 elm_object_text_set(o, _("Normal"));
243 else if (j == 2) elm_object_text_set(o, _("Intense")); 266 else if (j == 1)
244 else if (j == 3) elm_object_text_set(o, _("Intense Bright/Bold")); 267 elm_object_text_set(o, _("Bright/Bold"));
268 else if (j == 2)
269 elm_object_text_set(o, _("Intense"));
270 else if (j == 3)
271 elm_object_text_set(o, _("Intense Bright/Bold"));
245 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); 272 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
246 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); 273 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
247 elm_box_pack_end(bx3, o); 274 elm_box_pack_end(bx3, o);
@@ -251,22 +278,25 @@ options_colors(Evas_Object *opbox, Evas_Object *term, Evas_Object *bg)
251 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); 278 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
252 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); 279 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
253 elm_colorselector_mode_set(o, ELM_COLORSELECTOR_PALETTE); 280 elm_colorselector_mode_set(o, ELM_COLORSELECTOR_PALETTE);
254 for (i = 0; i < 11; i++) 281 for (i = 0; i < 12; i++)
255 { 282 {
256 Elm_Object_Item *it; 283 Elm_Object_Item *it;
257 284
285 if (i == COL_INVIS)
286 continue;
287
258 it = elm_colorselector_palette_color_add 288 it = elm_colorselector_palette_color_add
259 (o, 289 (o,
260 config->colors[(j * 12) + mapping[i]].r, 290 config->colors[(j * 12) + i].r,
261 config->colors[(j * 12) + mapping[i]].g, 291 config->colors[(j * 12) + i].g,
262 config->colors[(j * 12) + mapping[i]].b, 292 config->colors[(j * 12) + i].b,
263 config->colors[(j * 12) + mapping[i]].a); 293 config->colors[(j * 12) + i].a);
264 ctx->colitem[j][i] = it; 294 ctx->colitem[j][i] = it;
265 } 295 }
266 evas_object_smart_callback_add(o, "color,item,selected",
267 _cb_op_color_item_sel, ctx);
268 elm_box_pack_end(bx3, o); 296 elm_box_pack_end(bx3, o);
269 evas_object_show(o); 297 evas_object_show(o);
298 evas_object_smart_callback_add(o, "color,item,selected",
299 _cb_op_color_item_sel, ctx);
270 if (j == 1) 300 if (j == 1)
271 { 301 {
272 o = elm_separator_add(opbox); 302 o = elm_separator_add(opbox);
@@ -316,20 +346,11 @@ options_colors(Evas_Object *opbox, Evas_Object *term, Evas_Object *bg)
316 elm_box_pack_end(bx2, o); 346 elm_box_pack_end(bx2, o);
317 evas_object_show(o); 347 evas_object_show(o);
318 348
319 o = elm_check_add(opbox);
320 evas_object_size_hint_weight_set(o, 1.0, 0.0);
321 evas_object_size_hint_align_set(o, 0.0, 0.5);
322 elm_object_text_set(o, _("Use"));
323 elm_check_state_set(o, config->colors_use);
324 elm_box_pack_end(bx4, o);
325 evas_object_show(o);
326 evas_object_smart_callback_add(o, "changed", _cb_op_use_custom_chg, ctx);
327
328 ctx->reset = o = elm_button_add(opbox); 349 ctx->reset = o = elm_button_add(opbox);
329 elm_object_disabled_set(o, EINA_TRUE); 350 elm_object_disabled_set(o, !config->colors_use);
330 evas_object_size_hint_weight_set(o, 1.0, 0.0); 351 evas_object_size_hint_weight_set(o, 1.0, 0.0);
331 evas_object_size_hint_align_set(o, 1.0, 0.5); 352 evas_object_size_hint_align_set(o, 1.0, 0.5);
332 elm_object_text_set(o, _("Reset")); 353 elm_object_text_set(o, _("Reset all the colors"));
333 elm_box_pack_end(bx4, o); 354 elm_box_pack_end(bx4, o);
334 evas_object_show(o); 355 evas_object_show(o);
335 evas_object_smart_callback_add(o, "clicked", _cb_op_reset, ctx); 356 evas_object_smart_callback_add(o, "clicked", _cb_op_reset, ctx);