summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bin/options_colors.c157
1 files changed, 96 insertions, 61 deletions
diff --git a/src/bin/options_colors.c b/src/bin/options_colors.c
index 6353a92..f600f8e 100644
--- a/src/bin/options_colors.c
+++ b/src/bin/options_colors.c
@@ -1,6 +1,7 @@
1#include <Elementary.h>
2
3#include "private.h" 1#include "private.h"
2
3#include <Elementary.h>
4#include <assert.h>
4#include "config.h" 5#include "config.h"
5#include "termio.h" 6#include "termio.h"
6#include "options.h" 7#include "options.h"
@@ -23,49 +24,59 @@ static const char *mapping_names[] =
23 gettext_noop("Inverse Base") 24 gettext_noop("Inverse Base")
24 }; 25 };
25 26
26static Elm_Object_Item *colitem[4][11] = { { NULL } }; 27typedef struct _Colors_Ctx {
27static Evas_Object *colorsel = NULL; 28 Elm_Object_Item *colitem[4][11];
28static Elm_Object_Item *curitem = NULL; 29 Evas_Object *colorsel;
29static Evas_Object *colpal[4] = { NULL }; 30 Elm_Object_Item *curitem;
30static Evas_Object *label = NULL, *reset = NULL; 31 Evas_Object *colpal[4];
32 Evas_Object *label;
33 Evas_Object *reset;
34 Config *config;
35 Evas_Object *term;
36} Colors_Ctx;
31 37
32static void 38static void
33_cb_op_use_custom_chg(void *data, 39_cb_op_use_custom_chg(void *data,
34 Evas_Object *obj, 40 Evas_Object *obj,
35 void *_event EINA_UNUSED) 41 void *_event EINA_UNUSED)
36{ 42{
37 Evas_Object *term = data; 43 Colors_Ctx *ctx = data;
38 Config *config = termio_config_get(term); 44 Evas_Object *term = ctx->term;
45 Config *config = ctx->config;
39 Eina_Bool state = EINA_FALSE; 46 Eina_Bool state = EINA_FALSE;
40 int i; 47 int i;
41 48
42 state = elm_check_state_get(obj); 49 state = elm_check_state_get(obj);
43 elm_object_disabled_set(colorsel, !state); 50 elm_object_disabled_set(ctx->colorsel, !state);
44 for (i = 0; i < 4; i++) elm_object_disabled_set(colpal[i], !state); 51
45 elm_object_disabled_set(label, !state); 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);
46 config->colors_use = state; 56 config->colors_use = state;
47 termio_config_update(term); 57 termio_config_update(term);
48 config_save(config, NULL); 58 config_save(config, NULL);
49} 59}
50 60
51static void 61static void
52_cb_op_color_item_sel(void *_data EINA_UNUSED, 62_cb_op_color_item_sel(void *data,
53 Evas_Object *_obj EINA_UNUSED, 63 Evas_Object *_obj EINA_UNUSED,
54 void *event) 64 void *event)
55{ 65{
66 Colors_Ctx *ctx = data;
56 Elm_Object_Item *it = event; 67 Elm_Object_Item *it = event;
57 int r = 0, g = 0, b = 0, a = 0; 68 int r = 0, g = 0, b = 0, a = 0;
58 int i, j; 69 int i, j;
59 70
60 curitem = it; 71 ctx->curitem = it;
61 elm_colorselector_palette_item_color_get(it, &r, &g, &b, &a); 72 elm_colorselector_palette_item_color_get(it, &r, &g, &b, &a);
62 elm_colorselector_color_set(colorsel, r, g, b, a); 73 elm_colorselector_color_set(ctx->colorsel, r, g, b, a);
63 for (j = 0; j < 4; j++) 74 for (j = 0; j < 4; j++)
64 { 75 {
65 for (i = 0; i < 11; i++) 76 for (i = 0; i < 11; i++)
66 { 77 {
67 if (colitem[j][i] == it) 78 if (ctx->colitem[j][i] == it)
68 elm_object_text_set(label, 79 elm_object_text_set(ctx->label,
69#if HAVE_GETTEXT && ENABLE_NLS 80#if HAVE_GETTEXT && ENABLE_NLS
70 gettext(mapping_names[i]) 81 gettext(mapping_names[i])
71#else 82#else
@@ -81,29 +92,29 @@ _cb_op_color_chg(void *data,
81 Evas_Object *obj, 92 Evas_Object *obj,
82 void *_event EINA_UNUSED) 93 void *_event EINA_UNUSED)
83{ 94{
84 Evas_Object *term = data; 95 Colors_Ctx *ctx = data;
85 Config *config = termio_config_get(term); 96 Config *config = ctx->config;
86 int r = 0, g = 0, b = 0, a = 0, rr = 0, gg = 0, bb = 0, aa = 0; 97 int r = 0, g = 0, b = 0, a = 0, rr = 0, gg = 0, bb = 0, aa = 0;
87 int i, j; 98 int i, j;
88 99
89 elm_colorselector_palette_item_color_get(curitem, &rr, &gg, &bb, &aa); 100 elm_colorselector_palette_item_color_get(ctx->curitem, &rr, &gg, &bb, &aa);
90 elm_colorselector_color_get(obj, &r, &g, &b, &a); 101 elm_colorselector_color_get(obj, &r, &g, &b, &a);
91 if ((r != rr) || (g != gg) || (b != bb) || (a != aa)) 102 if ((r != rr) || (g != gg) || (b != bb) || (a != aa))
92 { 103 {
93 if (curitem) 104 if (ctx->curitem)
94 elm_colorselector_palette_item_color_set(curitem, r, g, b, a); 105 elm_colorselector_palette_item_color_set(ctx->curitem, r, g, b, a);
95 elm_object_disabled_set(reset, EINA_FALSE); 106 elm_object_disabled_set(ctx->reset, EINA_FALSE);
96 for (j = 0; j < 4; j++) 107 for (j = 0; j < 4; j++)
97 { 108 {
98 for (i = 0; i < 11; i++) 109 for (i = 0; i < 11; i++)
99 { 110 {
100 if (colitem[j][i] == curitem) 111 if (ctx->colitem[j][i] == ctx->curitem)
101 { 112 {
102 config->colors[(j * 12) + mapping[i]].r = r; 113 config->colors[(j * 12) + mapping[i]].r = r;
103 config->colors[(j * 12) + mapping[i]].g = g; 114 config->colors[(j * 12) + mapping[i]].g = g;
104 config->colors[(j * 12) + mapping[i]].b = b; 115 config->colors[(j * 12) + mapping[i]].b = b;
105 config->colors[(j * 12) + mapping[i]].a = a; 116 config->colors[(j * 12) + mapping[i]].a = a;
106 termio_config_update(term); 117 termio_config_update(ctx->term);
107 config_save(config, NULL); 118 config_save(config, NULL);
108 return; 119 return;
109 } 120 }
@@ -117,17 +128,18 @@ _cb_op_reset(void *data,
117 Evas_Object *_obj EINA_UNUSED, 128 Evas_Object *_obj EINA_UNUSED,
118 void *_event EINA_UNUSED) 129 void *_event EINA_UNUSED)
119{ 130{
120 Evas_Object *term = data; 131 Colors_Ctx *ctx = data;
121 Config *config = termio_config_get(term); 132 Evas_Object *term = ctx->term;
133 Config *config = ctx->config;
122 int r = 0, g = 0, b = 0, a = 0; 134 int r = 0, g = 0, b = 0, a = 0;
123 int i, j; 135 int i, j;
124 136
125 for (j = 0; j < 4; j++) 137 for (j = 0; j < 4; j++)
126 { 138 {
127 for (i = 0; i < 12; i++) 139 for (i = 0; i < 12; i++)
128 { 140 {
129 unsigned char rr = 0, gg = 0, bb = 0, aa = 0; 141 unsigned char rr = 0, gg = 0, bb = 0, aa = 0;
130 142
131 colors_standard_get(j, i, &rr, &gg, &bb, &aa); 143 colors_standard_get(j, i, &rr, &gg, &bb, &aa);
132 config->colors[(j * 12) + i].r = rr; 144 config->colors[(j * 12) + i].r = rr;
133 config->colors[(j * 12) + i].g = gg; 145 config->colors[(j * 12) + i].g = gg;
@@ -137,30 +149,43 @@ _cb_op_reset(void *data,
137 for (i = 0; i < 11; i++) 149 for (i = 0; i < 11; i++)
138 { 150 {
139 elm_colorselector_palette_item_color_set 151 elm_colorselector_palette_item_color_set
140 (colitem[j][i], 152 (ctx->colitem[j][i],
141 config->colors[(j * 12) + mapping[i]].r, 153 config->colors[(j * 12) + mapping[i]].r,
142 config->colors[(j * 12) + mapping[i]].g, 154 config->colors[(j * 12) + mapping[i]].g,
143 config->colors[(j * 12) + mapping[i]].b, 155 config->colors[(j * 12) + mapping[i]].b,
144 config->colors[(j * 12) + mapping[i]].a); 156 config->colors[(j * 12) + mapping[i]].a);
145 } 157 }
146 } 158 }
147 elm_object_disabled_set(reset, EINA_TRUE); 159 elm_object_disabled_set(ctx->reset, EINA_TRUE);
148 elm_colorselector_palette_item_color_get(curitem, &r, &g, &b, &a); 160 elm_colorselector_palette_item_color_get(ctx->curitem, &r, &g, &b, &a);
149 elm_colorselector_color_set(colorsel, r, g, b, a); 161 elm_colorselector_color_set(ctx->colorsel, r, g, b, a);
150 termio_config_update(term); 162 termio_config_update(term);
151 config_save(config, NULL); 163 config_save(config, NULL);
152} 164}
153 165
166/* make color palettes wrap back. :) works with elm git. */
154static void 167static void
155_cb_op_scroller_resize(void *_data EINA_UNUSED, 168_cb_op_scroller_resize(void *data,
156 Evas *_e EINA_UNUSED, 169 Evas *_e EINA_UNUSED,
157 Evas_Object *_obj EINA_UNUSED, 170 Evas_Object *_obj EINA_UNUSED,
158 void *_event EINA_UNUSED) 171 void *_event EINA_UNUSED)
159{ 172{
160 // make color palettes wrap back. :) works with elm git. 173 Colors_Ctx *ctx = data;
161 int i; 174 int i;
162 175
163 for (i = 0; i < 4; i++) evas_object_resize(colpal[i], 1, 1); 176 for (i = 0; i < 4; i++)
177 evas_object_resize(ctx->colpal[i], 1, 1);
178}
179
180static void
181_parent_del_cb(void *data,
182 Evas *_e EINA_UNUSED,
183 Evas_Object *_obj EINA_UNUSED,
184 void *_event_info EINA_UNUSED)
185{
186 Colors_Ctx *ctx = data;
187
188 free(ctx);
164} 189}
165 190
166void 191void
@@ -170,29 +195,39 @@ options_colors(Evas_Object *opbox, Evas_Object *term)
170 Evas_Object *o, *fr, *bx, *sc, *bx2, *bx3, *bx4; 195 Evas_Object *o, *fr, *bx, *sc, *bx2, *bx3, *bx4;
171 int i, j; 196 int i, j;
172 int r = 0, g = 0, b = 0, a = 0; 197 int r = 0, g = 0, b = 0, a = 0;
173 198 Colors_Ctx *ctx;
199
200 ctx = calloc(1, sizeof(*ctx));
201 assert(ctx);
202
203 ctx->config = config;
204 ctx->term = term;
205
174 fr = o = elm_frame_add(opbox); 206 fr = o = elm_frame_add(opbox);
175 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 207 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
176 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); 208 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
177 elm_object_text_set(o, _("Colors")); 209 elm_object_text_set(o, _("Colors"));
178 elm_box_pack_end(opbox, o); 210 elm_box_pack_end(opbox, o);
179 evas_object_show(o); 211 evas_object_show(o);
180 212
213 evas_object_event_callback_add(fr, EVAS_CALLBACK_DEL,
214 _parent_del_cb, ctx);
215
181 bx = o = elm_box_add(opbox); 216 bx = o = elm_box_add(opbox);
182 elm_box_horizontal_set(o, EINA_TRUE); 217 elm_box_horizontal_set(o, EINA_TRUE);
183 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); 218 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
184 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0); 219 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
185 elm_object_content_set(fr, o); 220 elm_object_content_set(fr, o);
186 evas_object_show(o); 221 evas_object_show(o);
187 222
188 sc = o = elm_scroller_add(opbox); 223 sc = o = elm_scroller_add(opbox);
189 evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, 224 evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE,
190 _cb_op_scroller_resize, NULL); 225 _cb_op_scroller_resize, ctx);
191 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 226 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
192 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); 227 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
193 elm_box_pack_end(bx, o); 228 elm_box_pack_end(bx, o);
194 evas_object_show(o); 229 evas_object_show(o);
195 230
196 bx3 = o = elm_box_add(opbox); 231 bx3 = o = elm_box_add(opbox);
197 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); 232 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
198 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0); 233 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
@@ -210,25 +245,25 @@ options_colors(Evas_Object *opbox, Evas_Object *term)
210 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); 245 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
211 elm_box_pack_end(bx3, o); 246 elm_box_pack_end(bx3, o);
212 evas_object_show(o); 247 evas_object_show(o);
213 248
214 colpal[j] = o = elm_colorselector_add(opbox); 249 ctx->colpal[j] = o = elm_colorselector_add(opbox);
215 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); 250 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
216 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); 251 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
217 elm_colorselector_mode_set(o, ELM_COLORSELECTOR_PALETTE); 252 elm_colorselector_mode_set(o, ELM_COLORSELECTOR_PALETTE);
218 for (i = 0; i < 11; i++) 253 for (i = 0; i < 11; i++)
219 { 254 {
220 Elm_Object_Item *it; 255 Elm_Object_Item *it;
221 256
222 it = elm_colorselector_palette_color_add 257 it = elm_colorselector_palette_color_add
223 (o, 258 (o,
224 config->colors[(j * 12) + mapping[i]].r, 259 config->colors[(j * 12) + mapping[i]].r,
225 config->colors[(j * 12) + mapping[i]].g, 260 config->colors[(j * 12) + mapping[i]].g,
226 config->colors[(j * 12) + mapping[i]].b, 261 config->colors[(j * 12) + mapping[i]].b,
227 config->colors[(j * 12) + mapping[i]].a); 262 config->colors[(j * 12) + mapping[i]].a);
228 colitem[j][i] = it; 263 ctx->colitem[j][i] = it;
229 } 264 }
230 evas_object_smart_callback_add(o, "color,item,selected", 265 evas_object_smart_callback_add(o, "color,item,selected",
231 _cb_op_color_item_sel, term); 266 _cb_op_color_item_sel, ctx);
232 elm_box_pack_end(bx3, o); 267 elm_box_pack_end(bx3, o);
233 evas_object_show(o); 268 evas_object_show(o);
234 if (j == 1) 269 if (j == 1)
@@ -242,15 +277,15 @@ options_colors(Evas_Object *opbox, Evas_Object *term)
242 } 277 }
243 } 278 }
244 279
245 curitem = colitem[0][0]; 280 ctx->curitem = ctx->colitem[0][0];
246 281
247 bx2 = o = elm_box_add(opbox); 282 bx2 = o = elm_box_add(opbox);
248 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); 283 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
249 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0); 284 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
250 elm_box_pack_end(bx, o); 285 elm_box_pack_end(bx, o);
251 evas_object_show(o); 286 evas_object_show(o);
252 287
253 label = o = elm_label_add(opbox); 288 ctx->label = o = elm_label_add(opbox);
254 elm_object_text_set(o, 289 elm_object_text_set(o,
255#if HAVE_GETTEXT && ENABLE_NLS 290#if HAVE_GETTEXT && ENABLE_NLS
256 gettext(mapping_names[0]) 291 gettext(mapping_names[0])
@@ -262,16 +297,16 @@ options_colors(Evas_Object *opbox, Evas_Object *term)
262 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); 297 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
263 elm_box_pack_end(bx2, o); 298 elm_box_pack_end(bx2, o);
264 evas_object_show(o); 299 evas_object_show(o);
265 300
266 colorsel = o = elm_colorselector_add(opbox); 301 ctx->colorsel = o = elm_colorselector_add(opbox);
267 elm_colorselector_palette_item_color_get(colitem[0][0], &r, &g, &b, &a); 302 elm_colorselector_palette_item_color_get(ctx->colitem[0][0], &r, &g, &b, &a);
268 elm_colorselector_color_set(o, r, g, b, a); 303 elm_colorselector_color_set(o, r, g, b, a);
269 elm_colorselector_mode_set(o, ELM_COLORSELECTOR_COMPONENTS); 304 elm_colorselector_mode_set(o, ELM_COLORSELECTOR_COMPONENTS);
270 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); 305 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
271 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); 306 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
272 elm_box_pack_end(bx2, o); 307 elm_box_pack_end(bx2, o);
273 evas_object_show(o); 308 evas_object_show(o);
274 evas_object_smart_callback_add(o, "changed", _cb_op_color_chg, term); 309 evas_object_smart_callback_add(o, "changed", _cb_op_color_chg, ctx);
275 310
276 bx4 = o = elm_box_add(opbox); 311 bx4 = o = elm_box_add(opbox);
277 elm_box_horizontal_set(o, EINA_TRUE); 312 elm_box_horizontal_set(o, EINA_TRUE);
@@ -279,7 +314,7 @@ options_colors(Evas_Object *opbox, Evas_Object *term)
279 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0); 314 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
280 elm_box_pack_end(bx2, o); 315 elm_box_pack_end(bx2, o);
281 evas_object_show(o); 316 evas_object_show(o);
282 317
283 o = elm_check_add(opbox); 318 o = elm_check_add(opbox);
284 evas_object_size_hint_weight_set(o, 1.0, 0.0); 319 evas_object_size_hint_weight_set(o, 1.0, 0.0);
285 evas_object_size_hint_align_set(o, 0.0, 0.5); 320 evas_object_size_hint_align_set(o, 0.0, 0.5);
@@ -287,14 +322,14 @@ options_colors(Evas_Object *opbox, Evas_Object *term)
287 elm_check_state_set(o, config->colors_use); 322 elm_check_state_set(o, config->colors_use);
288 elm_box_pack_end(bx4, o); 323 elm_box_pack_end(bx4, o);
289 evas_object_show(o); 324 evas_object_show(o);
290 evas_object_smart_callback_add(o, "changed", _cb_op_use_custom_chg, term); 325 evas_object_smart_callback_add(o, "changed", _cb_op_use_custom_chg, ctx);
291 326
292 reset = o = elm_button_add(opbox); 327 ctx->reset = o = elm_button_add(opbox);
293 elm_object_disabled_set(o, EINA_TRUE); 328 elm_object_disabled_set(o, EINA_TRUE);
294 evas_object_size_hint_weight_set(o, 1.0, 0.0); 329 evas_object_size_hint_weight_set(o, 1.0, 0.0);
295 evas_object_size_hint_align_set(o, 1.0, 0.5); 330 evas_object_size_hint_align_set(o, 1.0, 0.5);
296 elm_object_text_set(o, _("Reset")); 331 elm_object_text_set(o, _("Reset"));
297 elm_box_pack_end(bx4, o); 332 elm_box_pack_end(bx4, o);
298 evas_object_show(o); 333 evas_object_show(o);
299 evas_object_smart_callback_add(o, "clicked", _cb_op_reset, term); 334 evas_object_smart_callback_add(o, "clicked", _cb_op_reset, ctx);
300} 335}