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).
This commit is contained in:
Carsten Haitzler 2013-12-16 23:51:35 +09:00
parent 6ea42c38ae
commit f40eab09f2
8 changed files with 392 additions and 38 deletions

View File

@ -1,6 +1,7 @@
#include "private.h"
#include <Elementary.h>
#include "config.h"
#include "col.h"
#include <Edje.h>
typedef struct _Color Color;
@ -377,7 +378,7 @@ static const Color colors256[256] =
};
void
colors_term_init(Evas_Object *textgrid, Evas_Object *bg)
colors_term_init(Evas_Object *textgrid, Evas_Object *bg, Config *config)
{
int c, n;
int r, g, b, a;
@ -385,36 +386,56 @@ colors_term_init(Evas_Object *textgrid, Evas_Object *bg)
for (c = 0; c < 4 * 12; c++)
{
snprintf(buf, sizeof(buf) - 1, "c%i", c);
n = c + 24 * ( c / 24);
if (edje_object_color_class_get(bg, buf,
&r, &g, &b, &a,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL))
if (config->colors_use)
{
n = c + (24 * (c / 24));
r = config->colors[c].r;
g = config->colors[c].g;
b = config->colors[c].b;
a = config->colors[c].a;
/* normal */
evas_object_textgrid_palette_set(
textgrid, EVAS_TEXTGRID_PALETTE_STANDARD, n,
r, g, b, a);
evas_object_textgrid_palette_set
(textgrid, EVAS_TEXTGRID_PALETTE_STANDARD, n,
r, g, b, a);
/* faint */
evas_object_textgrid_palette_set(
textgrid, EVAS_TEXTGRID_PALETTE_STANDARD, n + 24,
r/2, g/2, b/2, a/2);
evas_object_textgrid_palette_set
(textgrid, EVAS_TEXTGRID_PALETTE_STANDARD, n + 24,
r / 2, g / 2, b / 2, a / 2);
}
else
{
Color color = colors[c/24][(c%24)/12][c%12];
/* normal */
evas_object_textgrid_palette_set(
textgrid, EVAS_TEXTGRID_PALETTE_STANDARD, n,
color.r, color.g, color.b, color.a);
/* faint */
evas_object_textgrid_palette_set(
textgrid, EVAS_TEXTGRID_PALETTE_STANDARD, n + 24,
color.r/2, color.g/2, color.b/2, color.a/2);
snprintf(buf, sizeof(buf) - 1, "c%i", c);
n = c + (24 * (c / 24));
if (edje_object_color_class_get(bg, buf,
&r, &g, &b, &a,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL))
{
/* normal */
evas_object_textgrid_palette_set
(textgrid, EVAS_TEXTGRID_PALETTE_STANDARD, n,
r, g, b, a);
/* faint */
evas_object_textgrid_palette_set
(textgrid, EVAS_TEXTGRID_PALETTE_STANDARD, n + 24,
r / 2, g / 2, b / 2, a / 2);
}
else
{
Color color = colors[c / 24][(c % 24) / 12][c % 12];
/* normal */
evas_object_textgrid_palette_set
(textgrid, EVAS_TEXTGRID_PALETTE_STANDARD, n,
color.r, color.g, color.b, color.a);
/* faint */
evas_object_textgrid_palette_set
(textgrid, EVAS_TEXTGRID_PALETTE_STANDARD, n + 24,
color.r / 2, color.g / 2, color.b / 2, color.a / 2);
}
}
}
for (c = 0; c < 256; c++)
@ -440,3 +461,24 @@ colors_term_init(Evas_Object *textgrid, Evas_Object *bg)
}
}
}
void
colors_standard_get(int set, int col, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a)
{
if ((set >= 0) && (set < 4))
{
int s1, s2;
s1 = set / 2;
s2 = set % 2;
*r = colors[s1][s2][col].r;
*g = colors[s1][s2][col].g;
*b = colors[s1][s2][col].b;
*a = colors[s1][s2][col].a;
return;
}
*r = 0;
*g = 0;
*b = 0;
*a = 0;
}

View File

@ -3,6 +3,7 @@
#include <Evas.h>
void colors_term_init(Evas_Object *textgrid, Evas_Object *bg);
void colors_term_init(Evas_Object *textgrid, Evas_Object *bg, Config *config);
void colors_standard_get(int set, int col, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a);
#endif

View File

@ -4,12 +4,14 @@
#include <Efreet.h>
#include "config.h"
#include "main.h"
#include "col.h"
#define CONF_VER 1
#define CONF_VER 2
#define LIM(v, min, max) {if (v >= max) v = max; else if (v <= min) v = min;}
static Eet_Data_Descriptor *edd_base = NULL;
static Eet_Data_Descriptor *edd_color = NULL;
static const char *
_config_home_get(void)
@ -28,6 +30,19 @@ config_init(void)
eet_eina_stream_data_descriptor_class_set
(&eddc, sizeof(eddc), "Config", sizeof(Config));
edd_base = eet_data_descriptor_stream_new(&eddc);
eet_eina_stream_data_descriptor_class_set
(&eddc, sizeof(eddc), "Config_Color", sizeof(Config_Color));
edd_color = eet_data_descriptor_stream_new(&eddc);
EET_DATA_DESCRIPTOR_ADD_BASIC
(edd_color, Config_Color, "r", r, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC
(edd_color, Config_Color, "g", g, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC
(edd_color, Config_Color, "b", b, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC
(edd_color, Config_Color, "a", a, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC
(edd_base, Config, "version", version, EET_T_INT);
@ -100,6 +115,10 @@ config_init(void)
EET_DATA_DESCRIPTOR_ADD_BASIC
(edd_base, Config, "application_server_restore_views",
application_server_restore_views, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC
(edd_base, Config, "colors_use", colors_use, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_ARRAY
(edd_base, Config, "colors", colors, edd_color);
}
void
@ -110,6 +129,11 @@ config_shutdown(void)
eet_data_descriptor_free(edd_base);
edd_base = NULL;
}
if (edd_color)
{
eet_data_descriptor_free(edd_color);
edd_color = NULL;
}
efreet_shutdown();
}
@ -186,6 +210,8 @@ config_sync(const Config *config_src, Config *config)
config->custom_geometry = config_src->custom_geometry;
config->cg_width = config_src->cg_width;
config->cg_height = config_src->cg_height;
config->colors_use = config_src->colors_use;
memcpy(config->colors, config_src->colors, sizeof(config->colors));
}
Config *
@ -406,6 +432,8 @@ config_load(const char *key)
config = calloc(1, sizeof(Config));
if (config)
{
int i, j;
config->version = CONF_VER;
config->font.bitmap = EINA_TRUE;
config->font.name = eina_stringshare_add("nexus.pcf");
@ -445,6 +473,20 @@ config_load(const char *key)
config->custom_geometry = EINA_FALSE;
config->cg_width = 80;
config->cg_height = 24;
config->colors_use = EINA_FALSE;
for (j = 0; j < 4; j++)
{
for (i = 0; i < 12; i++)
{
unsigned char rr = 0, gg = 0, bb = 0, aa = 0;
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;
}
}
}
}
@ -498,6 +540,8 @@ config_fork(Config *config)
CPY(custom_geometry);
CPY(cg_width);
CPY(cg_height);
CPY(colors_use);
memcpy(config2->colors, config->colors, sizeof(config->colors));
CPY(temporary);
SCPY(config_key);

View File

@ -2,9 +2,15 @@
#define _CONFIG_H__ 1
typedef struct _Config Config;
typedef struct _Config_Color Config_Color;
/* TODO: separate config per terminal (tab, window) and global. */
struct _Config_Color
{
unsigned char r, g, b, a;
};
struct _Config
{
int version;
@ -48,6 +54,8 @@ struct _Config
Eina_Bool drag_links;
int cg_width;
int cg_height;
Eina_Bool colors_use;
Config_Color colors[(4 * 12)];
Eina_Bool temporary; /* not in EET */
const char *config_key; /* not in EET, the key that config was loaded */

View File

@ -121,7 +121,7 @@ void change_theme(Evas_Object *win, Config *config)
if (!theme_apply(edje, config, "terminology/background"))
ERR("Couldn't find terminology theme!");
colors_term_init(termio_textgrid_get(term->term), edje);
colors_term_init(termio_textgrid_get(term->term), edje, config);
termio_config_set(term->term, config);
}
}
@ -2172,7 +2172,7 @@ main_term_new(Win *wn, Config *config, const char *cmd,
term->term = o = termio_add(wn->win, config, cmd, login_shell, cd,
size_w, size_h);
colors_term_init(termio_textgrid_get(term->term), term->bg);
colors_term_init(termio_textgrid_get(term->term), term->bg, config);
termio_win_set(o, wn->win);
termio_theme_set(o, term->bg);

View File

@ -6,15 +6,272 @@
#include "options.h"
#include "options_colors.h"
void
options_colors(Evas_Object *opbox, Evas_Object *term EINA_UNUSED)
{
Evas_Object *o;
static const char mapping[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11 };
static const char *mapping_names[] =
{
"Default",
"Black",
"Red",
"Green",
"Yellow",
"Blue",
"Magenta",
"Cyan",
"White",
"Inverse",
"Inverse Base"
};
o = elm_label_add(opbox);
static Elm_Object_Item *colitem[4][11] = { { NULL } };
static Evas_Object *colorsel = NULL;
static Elm_Object_Item *curitem = NULL;
static Evas_Object *colpal[4] = { NULL };
static Evas_Object *label = NULL, *reset = NULL;
static void
_cb_op_use_custom_chg(void *data EINA_UNUSED, Evas_Object *obj, void *event EINA_UNUSED)
{
Evas_Object *term = data;
Config *config = termio_config_get(term);
Eina_Bool state = EINA_FALSE;
int i;
state = elm_check_state_get(obj);
elm_object_disabled_set(colorsel, !state);
for (i = 0; i < 4; i++) elm_object_disabled_set(colpal[i], !state);
elm_object_disabled_set(label, !state);
config->colors_use = state;
termio_config_update(term);
config_save(config, NULL);
}
static void
_cb_op_color_item_sel(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event)
{
Elm_Object_Item *it = event;
int r = 0, g = 0, b = 0, a = 0;
int i, j;
curitem = it;
elm_colorselector_palette_item_color_get(it, &r, &g, &b, &a);
elm_colorselector_color_set(colorsel, r, g, b, a);
for (j = 0; j < 4; j++)
{
for (i = 0; i < 11; i++)
{
if (colitem[j][i] == it)
elm_object_text_set(label, mapping_names[i]);
}
}
}
static void
_cb_op_color_chg(void *data EINA_UNUSED, Evas_Object *obj, void *event EINA_UNUSED)
{
Evas_Object *term = data;
Config *config = termio_config_get(term);
int r = 0, g = 0, b = 0, a = 0, rr = 0, gg = 0, bb = 0, aa = 0;
int i, j;
elm_colorselector_palette_item_color_get(curitem, &rr, &gg, &bb, &aa);
elm_colorselector_color_get(obj, &r, &g, &b, &a);
if ((r != rr) || (g != gg) || (b != bb) || (a != aa))
{
if (curitem)
elm_colorselector_palette_item_color_set(curitem, r, g, b, a);
elm_object_disabled_set(reset, EINA_FALSE);
for (j = 0; j < 4; j++)
{
for (i = 0; i < 11; i++)
{
if (colitem[j][i] == curitem)
{
config->colors[(j * 12) + mapping[i]].r = r;
config->colors[(j * 12) + mapping[i]].g = g;
config->colors[(j * 12) + mapping[i]].b = b;
config->colors[(j * 12) + mapping[i]].a = a;
termio_config_update(term);
config_save(config, NULL);
return;
}
}
}
}
}
static void
_cb_op_reset(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
{
Evas_Object *term = data;
Config *config = termio_config_get(term);
int r = 0, g = 0, b = 0, a = 0;
int i, j;
for (j = 0; j < 4; j++)
{
for (i = 0; i < 12; i++)
{
unsigned char rr = 0, gg = 0, bb = 0, aa = 0;
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
(colitem[j][i],
config->colors[(j * 12) + mapping[i]].r,
config->colors[(j * 12) + mapping[i]].g,
config->colors[(j * 12) + mapping[i]].b,
config->colors[(j * 12) + mapping[i]].a);
}
}
elm_object_disabled_set(reset, EINA_TRUE);
elm_colorselector_palette_item_color_get(curitem, &r, &g, &b, &a);
elm_colorselector_color_set(colorsel, r, g, b, a);
termio_config_update(term);
config_save(config, NULL);
}
static void
_cb_op_scroller_resize(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
{
// make color palettes wrap back. :) works with elm git.
int i;
for (i = 0; i < 4; i++) evas_object_resize(colpal[i], 1, 1);
}
void
options_colors(Evas_Object *opbox, Evas_Object *term)
{
Config *config = termio_config_get(term);
Evas_Object *o, *fr, *bx, *sc, *bx2, *bx3, *bx4;
int i, j;
int r = 0, g = 0, b = 0, a = 0;
fr = o = elm_frame_add(opbox);
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);
elm_object_text_set(o, "Not Implemented Yet.");
evas_object_show(o);
elm_object_text_set(o, "Colors");
elm_box_pack_end(opbox, o);
evas_object_show(o);
bx = o = elm_box_add(opbox);
elm_box_horizontal_set(o, EINA_TRUE);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
elm_object_content_set(fr, o);
evas_object_show(o);
sc = o = elm_scroller_add(opbox);
evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE,
_cb_op_scroller_resize, NULL);
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);
elm_box_pack_end(bx, o);
evas_object_show(o);
bx3 = o = elm_box_add(opbox);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
elm_object_content_set(sc, o);
evas_object_show(o);
for (j = 0; j < 4; j++)
{
o = elm_label_add(opbox);
if (j == 0) elm_object_text_set(o, "Normal");
else if (j == 1) elm_object_text_set(o, "Bright");
else if (j == 2) elm_object_text_set(o, "Normal 2");
else if (j == 3) elm_object_text_set(o, "Bright 2");
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
elm_box_pack_end(bx3, o);
evas_object_show(o);
colpal[j] = o = elm_colorselector_add(opbox);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
elm_colorselector_mode_set(o, ELM_COLORSELECTOR_PALETTE);
for (i = 0; i < 11; i++)
{
Elm_Object_Item *it;
it = elm_colorselector_palette_color_add
(o,
config->colors[(j * 12) + mapping[i]].r,
config->colors[(j * 12) + mapping[i]].g,
config->colors[(j * 12) + mapping[i]].b,
config->colors[(j * 12) + mapping[i]].a);
colitem[j][i] = it;
}
evas_object_smart_callback_add(o, "color,item,selected",
_cb_op_color_item_sel, term);
elm_box_pack_end(bx3, o);
evas_object_show(o);
if (j == 1)
{
o = elm_separator_add(opbox);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
elm_separator_horizontal_set(o, EINA_TRUE);
elm_box_pack_end(bx3, o);
evas_object_show(o);
}
}
curitem = colitem[0][0];
bx2 = o = elm_box_add(opbox);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
elm_box_pack_end(bx, o);
evas_object_show(o);
label = o = elm_label_add(opbox);
elm_object_text_set(o, mapping_names[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);
elm_box_pack_end(bx2, o);
evas_object_show(o);
colorsel = o = elm_colorselector_add(opbox);
elm_colorselector_palette_item_color_get(colitem[0][0], &r, &g, &b, &a);
elm_colorselector_color_set(o, r, g, b, a);
elm_colorselector_mode_set(o, ELM_COLORSELECTOR_COMPONENTS);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
elm_box_pack_end(bx2, o);
evas_object_show(o);
evas_object_smart_callback_add(o, "changed", _cb_op_color_chg, term);
bx4 = o = elm_box_add(opbox);
elm_box_horizontal_set(o, EINA_TRUE);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.0);
elm_box_pack_end(bx2, 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, term);
reset = o = elm_button_add(opbox);
elm_object_disabled_set(o, EINA_TRUE);
evas_object_size_hint_weight_set(o, 1.0, 0.0);
evas_object_size_hint_align_set(o, 1.0, 0.5);
elm_object_text_set(o, "Reset");
elm_box_pack_end(bx4, o);
evas_object_show(o);
evas_object_smart_callback_add(o, "clicked", _cb_op_reset, term);
}

View File

@ -149,7 +149,7 @@ options_theme_preview_add(Evas_Object *parent, Config *config, const char *file,
// create a texgrid and swallow pack into grid
o = evas_object_textgrid_add(evas);
colors_term_init(o, obg);
colors_term_init(o, obg, config);
evas_object_scale_set(o, elm_config_scale_get());
if (config->font.bitmap)
{

View File

@ -4701,6 +4701,8 @@ termio_config_update(Evas_Object *obj)
edje_object_signal_emit(sd->cursor.obj, "focus,in", "terminology");
}
colors_term_init(sd->grid.obj, sd->theme, sd->config);
evas_object_scale_set(sd->grid.obj, elm_config_scale_get());
evas_object_textgrid_font_set(sd->grid.obj, sd->font.name, sd->font.size);
evas_object_textgrid_cell_size_get(sd->grid.obj, &w, &h);