options_colors: clean up a bit and have a global reset button

This commit is contained in:
Boris Faure 2018-01-15 22:51:16 +01:00
parent 820a5440fe
commit f33e898e29
1 changed files with 91 additions and 70 deletions

View File

@ -7,8 +7,6 @@
#include "options.h" #include "options.h"
#include "options_colors.h" #include "options_colors.h"
static const char mapping[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11 };
static const char *mapping_names[] = static const char *mapping_names[] =
{ {
gettext_noop("Default"), gettext_noop("Default"),
@ -20,12 +18,13 @@ static const char *mapping_names[] =
gettext_noop("Magenta"), gettext_noop("Magenta"),
gettext_noop("Cyan"), gettext_noop("Cyan"),
gettext_noop("White"), gettext_noop("White"),
gettext_noop("Invisible"),
gettext_noop("Inverse"), gettext_noop("Inverse"),
gettext_noop("Inverse Base") gettext_noop("Inverse Background")
}; };
typedef struct _Colors_Ctx { typedef struct _Colors_Ctx {
Elm_Object_Item *colitem[4][11]; Elm_Object_Item *colitem[4][12];
Evas_Object *colorsel; Evas_Object *colorsel;
Elm_Object_Item *curitem; Elm_Object_Item *curitem;
Evas_Object *colpal[4]; Evas_Object *colpal[4];
@ -33,31 +32,9 @@ typedef struct _Colors_Ctx {
Evas_Object *reset; Evas_Object *reset;
Config *config; Config *config;
Evas_Object *term; Evas_Object *term;
Evas_Object *bg;
} Colors_Ctx; } Colors_Ctx;
static void
_cb_op_use_custom_chg(void *data,
Evas_Object *obj,
void *_event EINA_UNUSED)
{
Colors_Ctx *ctx = data;
Evas_Object *term = ctx->term;
Config *config = ctx->config;
Eina_Bool state = EINA_FALSE;
int i;
state = elm_check_state_get(obj);
elm_object_disabled_set(ctx->colorsel, !state);
for (i = 0; i < 4; i++)
elm_object_disabled_set(ctx->colpal[i], !state);
elm_object_disabled_set(ctx->label, !state);
config->colors_use = state;
termio_config_update(term);
config_save(config, NULL);
}
static void static void
_cb_op_color_item_sel(void *data, _cb_op_color_item_sel(void *data,
Evas_Object *_obj EINA_UNUSED, Evas_Object *_obj EINA_UNUSED,
@ -73,8 +50,10 @@ _cb_op_color_item_sel(void *data,
elm_colorselector_color_set(ctx->colorsel, r, g, b, a); elm_colorselector_color_set(ctx->colorsel, r, g, b, a);
for (j = 0; j < 4; j++) for (j = 0; j < 4; j++)
{ {
for (i = 0; i < 11; i++) for (i = 0; i < 12; i++)
{ {
if (i == COL_INVIS)
continue;
if (ctx->colitem[j][i] == it) if (ctx->colitem[j][i] == it)
elm_object_text_set(ctx->label, elm_object_text_set(ctx->label,
#if HAVE_GETTEXT && ENABLE_NLS #if HAVE_GETTEXT && ENABLE_NLS
@ -104,16 +83,19 @@ _cb_op_color_chg(void *data,
if (ctx->curitem) if (ctx->curitem)
elm_colorselector_palette_item_color_set(ctx->curitem, r, g, b, a); elm_colorselector_palette_item_color_set(ctx->curitem, r, g, b, a);
elm_object_disabled_set(ctx->reset, EINA_FALSE); elm_object_disabled_set(ctx->reset, EINA_FALSE);
config->colors_use = EINA_TRUE;
for (j = 0; j < 4; j++) for (j = 0; j < 4; j++)
{ {
for (i = 0; i < 11; i++) for (i = 0; i < 12; i++)
{ {
if (i == COL_INVIS)
continue;
if (ctx->colitem[j][i] == ctx->curitem) if (ctx->colitem[j][i] == ctx->curitem)
{ {
config->colors[(j * 12) + mapping[i]].r = r; config->colors[(j * 12) + i].r = r;
config->colors[(j * 12) + mapping[i]].g = g; config->colors[(j * 12) + i].g = g;
config->colors[(j * 12) + mapping[i]].b = b; config->colors[(j * 12) + i].b = b;
config->colors[(j * 12) + mapping[i]].a = a; config->colors[(j * 12) + i].a = a;
termio_config_update(ctx->term); termio_config_update(ctx->term);
config_save(config, NULL); config_save(config, NULL);
return; return;
@ -123,6 +105,48 @@ _cb_op_color_chg(void *data,
} }
} }
static void
_reset_config_colors(Colors_Ctx *ctx)
{
int i, j;
for (j = 0; j < 4; j++)
{
for (i = 0; i < 12; i++)
{
int r, g, b, a;
unsigned char rr = 0, gg = 0, bb = 0, aa = 0;
char buf[32];
if (i == COL_INVIS)
continue;
snprintf(buf, sizeof(buf) - 1, "c%i", j * 12 + i);
if (!edje_object_color_class_get(ctx->bg, buf,
&r,
&g,
&b,
&a,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL))
{
colors_standard_get(j, i, &rr, &gg, &bb, &aa);
}
else
{
rr = r;
gg = g;
bb = b;
aa = a;
}
ctx->config->colors[(j * 12) + i].r = rr;
ctx->config->colors[(j * 12) + i].g = gg;
ctx->config->colors[(j * 12) + i].b = bb;
ctx->config->colors[(j * 12) + i].a = aa;
}
}
}
static void static void
_cb_op_reset(void *data, _cb_op_reset(void *data,
Evas_Object *_obj EINA_UNUSED, Evas_Object *_obj EINA_UNUSED,
@ -134,29 +158,24 @@ _cb_op_reset(void *data,
int r = 0, g = 0, b = 0, a = 0; int r = 0, g = 0, b = 0, a = 0;
int i, j; int i, j;
_reset_config_colors(ctx);
for (j = 0; j < 4; j++) for (j = 0; j < 4; j++)
{ {
for (i = 0; i < 12; i++) for (i = 0; i < 12; i++)
{ {
unsigned char rr = 0, gg = 0, bb = 0, aa = 0; if (i == COL_INVIS)
continue;
colors_standard_get(j, i, &rr, &gg, &bb, &aa);
config->colors[(j * 12) + i].r = rr;
config->colors[(j * 12) + i].g = gg;
config->colors[(j * 12) + i].b = bb;
config->colors[(j * 12) + i].a = aa;
}
for (i = 0; i < 11; i++)
{
elm_colorselector_palette_item_color_set elm_colorselector_palette_item_color_set
(ctx->colitem[j][i], (ctx->colitem[j][i],
config->colors[(j * 12) + mapping[i]].r, config->colors[(j * 12) + i].r,
config->colors[(j * 12) + mapping[i]].g, config->colors[(j * 12) + i].g,
config->colors[(j * 12) + mapping[i]].b, config->colors[(j * 12) + i].b,
config->colors[(j * 12) + mapping[i]].a); config->colors[(j * 12) + i].a);
} }
} }
elm_object_disabled_set(ctx->reset, EINA_TRUE); elm_object_disabled_set(ctx->reset, EINA_TRUE);
config->colors_use = EINA_FALSE;
elm_colorselector_palette_item_color_get(ctx->curitem, &r, &g, &b, &a); elm_colorselector_palette_item_color_get(ctx->curitem, &r, &g, &b, &a);
elm_colorselector_color_set(ctx->colorsel, r, g, b, a); elm_colorselector_color_set(ctx->colorsel, r, g, b, a);
termio_config_update(term); termio_config_update(term);
@ -222,12 +241,12 @@ options_colors(Evas_Object *opbox, Evas_Object *term, Evas_Object *bg)
evas_object_show(o); evas_object_show(o);
sc = o = elm_scroller_add(opbox); sc = o = elm_scroller_add(opbox);
evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE,
_cb_op_scroller_resize, ctx);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(bx, o); elm_box_pack_end(bx, o);
evas_object_show(o); evas_object_show(o);
evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE,
_cb_op_scroller_resize, ctx);
bx3 = o = elm_box_add(opbox); bx3 = o = elm_box_add(opbox);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); 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)
elm_object_content_set(sc, o); elm_object_content_set(sc, o);
evas_object_show(o); evas_object_show(o);
if (!config->colors_use)
{
_reset_config_colors(ctx);
}
for (j = 0; j < 4; j++) for (j = 0; j < 4; j++)
{ {
o = elm_label_add(opbox); o = elm_label_add(opbox);
if (j == 0) elm_object_text_set(o, _("Normal")); if (j == 0)
else if (j == 1) elm_object_text_set(o, _("Bright/Bold")); elm_object_text_set(o, _("Normal"));
else if (j == 2) elm_object_text_set(o, _("Intense")); else if (j == 1)
else if (j == 3) elm_object_text_set(o, _("Intense Bright/Bold")); elm_object_text_set(o, _("Bright/Bold"));
else if (j == 2)
elm_object_text_set(o, _("Intense"));
else if (j == 3)
elm_object_text_set(o, _("Intense Bright/Bold"));
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
elm_box_pack_end(bx3, o); elm_box_pack_end(bx3, o);
@ -251,22 +278,25 @@ options_colors(Evas_Object *opbox, Evas_Object *term, Evas_Object *bg)
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
elm_colorselector_mode_set(o, ELM_COLORSELECTOR_PALETTE); elm_colorselector_mode_set(o, ELM_COLORSELECTOR_PALETTE);
for (i = 0; i < 11; i++) for (i = 0; i < 12; i++)
{ {
Elm_Object_Item *it; Elm_Object_Item *it;
if (i == COL_INVIS)
continue;
it = elm_colorselector_palette_color_add it = elm_colorselector_palette_color_add
(o, (o,
config->colors[(j * 12) + mapping[i]].r, config->colors[(j * 12) + i].r,
config->colors[(j * 12) + mapping[i]].g, config->colors[(j * 12) + i].g,
config->colors[(j * 12) + mapping[i]].b, config->colors[(j * 12) + i].b,
config->colors[(j * 12) + mapping[i]].a); config->colors[(j * 12) + i].a);
ctx->colitem[j][i] = it; ctx->colitem[j][i] = it;
} }
evas_object_smart_callback_add(o, "color,item,selected",
_cb_op_color_item_sel, ctx);
elm_box_pack_end(bx3, o); elm_box_pack_end(bx3, o);
evas_object_show(o); evas_object_show(o);
evas_object_smart_callback_add(o, "color,item,selected",
_cb_op_color_item_sel, ctx);
if (j == 1) if (j == 1)
{ {
o = elm_separator_add(opbox); o = elm_separator_add(opbox);
@ -316,20 +346,11 @@ options_colors(Evas_Object *opbox, Evas_Object *term, Evas_Object *bg)
elm_box_pack_end(bx2, o); elm_box_pack_end(bx2, o);
evas_object_show(o); evas_object_show(o);
o = elm_check_add(opbox);
evas_object_size_hint_weight_set(o, 1.0, 0.0);
evas_object_size_hint_align_set(o, 0.0, 0.5);
elm_object_text_set(o, _("Use"));
elm_check_state_set(o, config->colors_use);
elm_box_pack_end(bx4, o);
evas_object_show(o);
evas_object_smart_callback_add(o, "changed", _cb_op_use_custom_chg, ctx);
ctx->reset = o = elm_button_add(opbox); ctx->reset = o = elm_button_add(opbox);
elm_object_disabled_set(o, EINA_TRUE); elm_object_disabled_set(o, !config->colors_use);
evas_object_size_hint_weight_set(o, 1.0, 0.0); evas_object_size_hint_weight_set(o, 1.0, 0.0);
evas_object_size_hint_align_set(o, 1.0, 0.5); evas_object_size_hint_align_set(o, 1.0, 0.5);
elm_object_text_set(o, _("Reset")); elm_object_text_set(o, _("Reset all the colors"));
elm_box_pack_end(bx4, o); elm_box_pack_end(bx4, o);
evas_object_show(o); evas_object_show(o);
evas_object_smart_callback_add(o, "clicked", _cb_op_reset, ctx); evas_object_smart_callback_add(o, "clicked", _cb_op_reset, ctx);