billiob pushed a commit to branch master.

http://git.enlightenment.org/apps/terminology.git/commit/?id=ac1bc022934fdf91d9102bacf1449980fcf7eb4c

commit ac1bc022934fdf91d9102bacf1449980fcf7eb4c
Author: Boris Faure <[email protected]>
Date:   Tue Nov 3 23:33:01 2020 +0100

    options_themepv: add color mode
---
 src/bin/options_theme.c   |   3 +-
 src/bin/options_themepv.c | 154 +++++++++++++++++++++++++++++++++++++++++++---
 src/bin/options_themepv.h |   6 +-
 3 files changed, 151 insertions(+), 12 deletions(-)

diff --git a/src/bin/options_theme.c b/src/bin/options_theme.c
index 693ffd3..5cdd77e 100644
--- a/src/bin/options_theme.c
+++ b/src/bin/options_theme.c
@@ -61,7 +61,8 @@ _cb_op_theme_content_get(void *data, Evas_Object *obj, const 
char *part)
                                            theme_path_get(t->name),
                                            NULL,
                                            128 * elm_config_scale_get(),
-                                           64 * elm_config_scale_get());
+                                           64 * elm_config_scale_get(),
+                                           EINA_FALSE);
              return o;
           }
      }
diff --git a/src/bin/options_themepv.c b/src/bin/options_themepv.c
index 09d7a7e..ed72131 100644
--- a/src/bin/options_themepv.c
+++ b/src/bin/options_themepv.c
@@ -72,6 +72,135 @@ _row_set(Evas_Object *o, int y, const char *txt)
    evas_object_textgrid_update_add(o, 0, y, tw, 1);
 }
 
+static void
+_fill_gyw_textgrid(Evas_Object *o)
+{
+   int x = 0, y = 0;
+   int tw, th;
+   Evas_Textgrid_Cell *tc;
+   const char *FGs[] = {
+        "  ",
+        "  ",
+        " 0",
+        "b0",
+        " 1",
+        "b1",
+        " 2",
+        "b2",
+        " 3",
+        "b3",
+        " 4",
+        "b4",
+        " 5",
+        "b5",
+        " 6",
+        "b6",
+        " 7",
+        "b7",
+        NULL
+   };
+   const char *fg_string;
+   const char *title = "        0   1   2   3   4   5   6   7";
+   const char *s;
+
+   evas_object_textgrid_size_get(o, &tw, &th);
+
+   /* write title line */
+   s = title;
+   tc = evas_object_textgrid_cellrow_get(o, 0);
+   if (!tc)
+     return;
+   for (x = 0; x < tw && *s; x++, s++)
+     {
+        tc[x] = (Evas_Textgrid_Cell) {
+             .fg = COL_DEF,
+             .bg = COL_INVIS,
+             .codepoint = s[0],
+        };
+     }
+   for (; x < tw; x++)
+     {
+        tc[x] = (Evas_Textgrid_Cell) {
+             .fg = COL_DEF,
+             .bg = COL_INVIS,
+             .codepoint = ' ',
+        };
+     }
+
+   for (fg_string = FGs[0], y = 1;
+        fg_string && y < th;
+        fg_string = FGs[y], y++)
+     {
+        int fg, bg;
+        Eina_Bool bold = (y % 2) == 0;
+
+        fg = (y - 1) / 2;
+        if (bold)
+          fg += 12;
+        bg = COL_INVIS;
+        x = 0;
+
+        tc = evas_object_textgrid_cellrow_get(o, y);
+        if (!tc) return;
+
+        /* write color fg */
+        for (s = fg_string; x < tw && *s; x++, s++)
+          {
+             tc[x] = (Evas_Textgrid_Cell) {
+                  .fg = COL_DEF,
+                  .bg = COL_INVIS,
+                  .codepoint = s[0],
+             };
+          }
+
+        /* write colors */
+        for (bg = 0; bg <= 8; bg++)
+          {
+             if (x < tw)
+               {
+                  tc[x] = (Evas_Textgrid_Cell) {
+                       .fg = COL_DEF,
+                          .bg = COL_INVIS,
+                          .codepoint = ' ',
+                  };
+                  x++;
+               }
+             for (s = "gYw"; x < tw && *s; x++, s++)
+               {
+                  tc[x] = (Evas_Textgrid_Cell) {
+                       .fg = fg,
+                       .bg = (bg == 0) ? COL_INVIS : bg,
+                       .bold = bold,
+                       .codepoint = s[0],
+                  };
+               }
+          }
+        for (; x < tw; x++)
+          {
+             tc[x] = (Evas_Textgrid_Cell) {
+                  .fg = COL_DEF,
+                  .bg = COL_INVIS,
+                  .codepoint = ' ',
+             };
+          }
+     }
+   for (; y < th; ++y)
+     {
+        tc = evas_object_textgrid_cellrow_get(o, y);
+        if (!tc) return;
+
+        for (x = 0; x < tw; x++)
+          {
+             tc[x] = (Evas_Textgrid_Cell) {
+                  .fg = COL_DEF,
+                  .bg = COL_INVIS,
+                  .codepoint = ' ',
+             };
+          }
+     }
+   evas_object_textgrid_update_add(o, 0, 0, tw, y);
+}
+
 static void
 _cb_resize(void *_data EINA_UNUSED,
            Evas *_e EINA_UNUSED,
@@ -98,7 +227,8 @@ options_theme_preview_add(Evas_Object *parent,
                           const Config *config,
                           const char *file,
                           const Color_Scheme *cs,
-                          Evas_Coord w, Evas_Coord h)
+                          Evas_Coord w, Evas_Coord h,
+                          Eina_Bool colors_mode)
 {
    Evas_Object *o, *oo, *obase, *oe, *obg;
    Evas *evas;
@@ -157,7 +287,7 @@ options_theme_preview_add(Evas_Object *parent,
 
    // create a texgrid and swallow pack into grid
    o = evas_object_textgrid_add(evas);
-   colors_term_init(o, obg, config);
+   colors_term_init(o, obg);
    evas_object_scale_set(o, elm_config_scale_get());
    if (config->font.bitmap)
      {
@@ -169,12 +299,17 @@ options_theme_preview_add(Evas_Object *parent,
      }
    else
      evas_object_textgrid_font_set(o, config->font.name, config->font.size);
-   evas_object_textgrid_size_set(o, 80, 24);
+   evas_object_textgrid_size_set(o, COLOR_MODE_PREVIEW_WIDTH,
+                                 COLOR_MODE_PREVIEW_HEIGHT);
 
    evas_object_textgrid_cell_size_get(o, &ww, &hh);
    if (ww < 1) ww = 1;
    if (hh < 1) hh = 1;
 
+   if (colors_mode)
+     _fill_gyw_textgrid(o);
+   else
+     {
    // cmds:
    // \x01 = set fg
    // \x02 = set bg
@@ -195,12 +330,13 @@ options_theme_preview_add(Evas_Object *parent,
 
 #define F(_x) "\x01"_x
 #define X "\x01\x01\x02\x10"
-   _row_set(o, 0, " "F("\x04")"$"X" "F("\x19")">"X" test");
-   _row_set(o, 1, F("\x02")"black"X" "F("\x03")"red"X" "F("\x04")"green"X" 
"F("\x05")"yellow");
-   _row_set(o, 2, F("\x06")"blue"X" "F("\x07")"mag"X" "F("\x08")"cyan"X" 
"F("\x09")"white");
-   _row_set(o, 3, F("\x12")"black"X" "F("\x13")"red"X" "F("\x14")"green"X" 
"F("\x15")"yellow");
-   _row_set(o, 4, F("\x16")"blue"X" "F("\x17")"mag"X" "F("\x18")"cyan"X" 
"F("\x19")"white");
-   for (y = 5; y < 24; y++) _row_set(o, y, "");
+        _row_set(o, 0, " "F("\x04")"$"X" "F("\x19")">"X" test");
+        _row_set(o, 1, F("\x02")"black"X" "F("\x03")"red"X" 
"F("\x04")"green"X" "F("\x05")"yellow");
+        _row_set(o, 2, F("\x06")"blue"X" "F("\x07")"mag"X" "F("\x08")"cyan"X" 
"F("\x09")"white");
+        _row_set(o, 3, F("\x12")"black"X" "F("\x13")"red"X" 
"F("\x14")"green"X" "F("\x15")"yellow");
+        _row_set(o, 4, F("\x16")"blue"X" "F("\x17")"mag"X" "F("\x18")"cyan"X" 
"F("\x19")"white");
+        for (y = 5; y < 10; y++) _row_set(o, y, "");
+     }
 
    evas_object_show(o);
    evas_object_data_set(oo, "textgrid", o);
diff --git a/src/bin/options_themepv.h b/src/bin/options_themepv.h
index cff6008..f4f8a48 100644
--- a/src/bin/options_themepv.h
+++ b/src/bin/options_themepv.h
@@ -8,6 +8,8 @@ options_theme_preview_add(Evas_Object *parent,
                           const char *file,
                           const Color_Scheme *cs,
                           Evas_Coord w,
-                          Evas_Coord h);
-
+                          Evas_Coord h,
+                          Eina_Bool colors_mode);
+#define COLOR_MODE_PREVIEW_WIDTH   39
+#define COLOR_MODE_PREVIEW_HEIGHT  20
 #endif

-- 


Reply via email to