From a7eb68799c1018e78f549a3f45e736f6effaf8dd Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Sun, 20 Jan 2013 16:48:18 +0000 Subject: [PATCH] terminology: read colors from theme SVN revision: 83019 --- src/bin/col.c | 73 +++++++++++++++++++++++++++++++++++++++-- src/bin/col.h | 13 ++++---- src/bin/main.c | 2 ++ src/bin/options_theme.c | 1 + src/bin/termio.c | 33 +++++-------------- src/bin/termio.h | 2 ++ 6 files changed, 91 insertions(+), 33 deletions(-) diff --git a/src/bin/col.c b/src/bin/col.c index a08e1b94..8c0bb699 100644 --- a/src/bin/col.c +++ b/src/bin/col.c @@ -1,6 +1,16 @@ +#include "private.h" #include "col.h" +#include -const Color colors[2][2][12] = +typedef struct _Color Color; + +struct _Color +{ + unsigned char r, g, b, a; +}; + + +static const Color colors[2][2][12] = { { // normal { // normal @@ -64,7 +74,7 @@ const Color colors[2][2][12] = } }; -const Color colors256[256] = +static const Color colors256[256] = { // basic 16 repeated /* @@ -383,3 +393,62 @@ const Color colors256[256] = { 0xe4, 0xe4, 0xe4, 0xff }, { 0xee, 0xee, 0xee, 0xff }, }; + +void colors_term_init(Evas_Object *textgrid, Evas_Object *bg) +{ + int c, n, l, k, j, i; + int r, g, b, a; + char buf[32]; + + for (c = 0; c < 4 * 12; c++) + { + snprintf(buf, sizeof(buf) - 1, "color-%d", 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)) + { + evas_object_textgrid_palette_set( + textgrid, EVAS_TEXTGRID_PALETTE_STANDARD, c, + r, g, b, a); + } + 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, + r/2, g/2, b/2, a/2); + } + } + for (c = 0; c < 256; c++) + { + snprintf(buf, sizeof(buf) - 1, "256color-%d", c); + + if (edje_object_color_class_get(bg, buf, + &r, &g, &b, &a, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL)) + { + evas_object_textgrid_palette_set( + textgrid, EVAS_TEXTGRID_PALETTE_EXTENDED, c, + r, g, b, a); + } + else + { + Color color = colors256[c]; + + evas_object_textgrid_palette_set( + textgrid, EVAS_TEXTGRID_PALETTE_EXTENDED, c, + color.r, color.g, color.b, color.a); + } + } +} diff --git a/src/bin/col.h b/src/bin/col.h index ddffb744..ecae5d7f 100644 --- a/src/bin/col.h +++ b/src/bin/col.h @@ -1,9 +1,8 @@ -typedef struct _Color Color; +#ifndef _COL_H__ +#define _COL_H__ 1 -struct _Color -{ - unsigned char r, g, b, a; -}; +#include -extern const Color colors[2][2][12]; -extern const Color colors256[256]; +void colors_term_init(Evas_Object *textgrid, Evas_Object *bg); + +#endif diff --git a/src/bin/main.c b/src/bin/main.c index d6539e32..58d86643 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -697,6 +697,8 @@ 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); + termio_win_set(o, wn->win); termio_theme_set(o, term->bg); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); diff --git a/src/bin/options_theme.c b/src/bin/options_theme.c index 9f2f0345..cc06be3f 100644 --- a/src/bin/options_theme.c +++ b/src/bin/options_theme.c @@ -69,6 +69,7 @@ _cb_op_theme_sel(void *data, Evas_Object *obj __UNUSED__, void *event __UNUSED__ config_save(config, NULL); if (!theme_apply(edje, config, "terminology/background")) ERR("Couldn't find terminology theme!"); + colors_term_init(termio_textgrid_get(t->term), edje); } static int diff --git a/src/bin/termio.c b/src/bin/termio.c index 02186652..5089bfea 100644 --- a/src/bin/termio.c +++ b/src/bin/termio.c @@ -2167,30 +2167,6 @@ _smart_add(Evas_Object *obj) evas_object_show(o); sd->grid.obj = o; - for (n = 0, l = 0; l < 2; l++) // normal/intense - { - for (k = 0; k < 2; k++) // normal/faint - { - for (j = 0; j < 2; j++) // normal/bright - { - for (i = 0; i < 12; i++, n++) //colors - evas_object_textgrid_palette_set - (o, EVAS_TEXTGRID_PALETTE_STANDARD, n, - colors[l][j][i].r / (k + 1), - colors[l][j][i].g / (k + 1), - colors[l][j][i].b / (k + 1), - colors[l][j][i].a / (k + 1)); - } - } - } - for (n = 0; n < 256; n++) - { - evas_object_textgrid_palette_set - (o, EVAS_TEXTGRID_PALETTE_EXTENDED, n, - colors256[n].r, colors256[n].g, - colors256[n].b, colors256[n].a); - } - /* Setup cursor */ o = edje_object_add(evas_object_evas_get(obj)); evas_object_pass_events_set(o, EINA_TRUE); @@ -2873,3 +2849,12 @@ termio_cwd_get(const Evas_Object *obj, char *buf, size_t size) return EINA_TRUE; } + +Evas_Object * +termio_textgrid_get(Evas_Object *obj) +{ + Termio *sd = evas_object_smart_data_get(obj); + if (!sd) return NULL; + + return sd->grid.obj; +} diff --git a/src/bin/termio.h b/src/bin/termio.h index fb60b051..fe27b5f4 100644 --- a/src/bin/termio.h +++ b/src/bin/termio.h @@ -2,6 +2,7 @@ #define _TERMIO_H__ 1 #include "config.h" +#include "col.h" Evas_Object *termio_add(Evas_Object *parent, Config *config, const char *cmd, Eina_Bool login_shell, const char *cd, int w, int h); void termio_win_set(Evas_Object *obj, Evas_Object *win); @@ -20,5 +21,6 @@ void termio_font_size_set(Evas_Object *obj, int size); void termio_grid_size_set(Evas_Object *obj, int w, int h); pid_t termio_pid_get(const Evas_Object *obj); Eina_Bool termio_cwd_get(const Evas_Object *obj, char *buf, size_t size); +Evas_Object *termio_textgrid_get(Evas_Object *obj); #endif