summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2013-10-09 22:51:15 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2013-10-09 22:51:15 +0900
commitb0cca8b0dfac1776f0b226b4d3958c075a7365b9 (patch)
treef279d9d51cbad66aef2aa8468256589ba6eb92fa
parent0a53ff6cd1f4e6508e2960beeb5595d7c1eb3881 (diff)
theme selector - massively improve theme preview to actually preview
-rw-r--r--src/bin/Makefile.am1
-rw-r--r--src/bin/options_theme.c21
-rw-r--r--src/bin/options_themepv.c226
-rw-r--r--src/bin/options_themepv.h1
4 files changed, 240 insertions, 9 deletions
diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am
index b18e440..5516b82 100644
--- a/src/bin/Makefile.am
+++ b/src/bin/Makefile.am
@@ -25,6 +25,7 @@ options_font.c options_font.h \
25options_helpers.c options_helpers.h \ 25options_helpers.c options_helpers.h \
26options_video.c options_video.h \ 26options_video.c options_video.h \
27options_theme.c options_theme.h \ 27options_theme.c options_theme.h \
28options_themepv.c options_themepv.h \
28options_wallpaper.c options_wallpaper.h \ 29options_wallpaper.c options_wallpaper.h \
29sel.c sel.h \ 30sel.c sel.h \
30termio.c termio.h \ 31termio.c termio.h \
diff --git a/src/bin/options_theme.c b/src/bin/options_theme.c
index 8903d2b..81239df 100644
--- a/src/bin/options_theme.c
+++ b/src/bin/options_theme.c
@@ -5,6 +5,7 @@
5#include "termio.h" 5#include "termio.h"
6#include "options.h" 6#include "options.h"
7#include "options_theme.h" 7#include "options_theme.h"
8#include "options_themepv.h"
8#include "utils.h" 9#include "utils.h"
9#include "main.h" 10#include "main.h"
10 11
@@ -37,19 +38,21 @@ static Evas_Object *
37_cb_op_theme_content_get(void *data, Evas_Object *obj, const char *part) 38_cb_op_theme_content_get(void *data, Evas_Object *obj, const char *part)
38{ 39{
39 Theme *t = data; 40 Theme *t = data;
40 char buf[4096];
41 41
42 if (!strcmp(part, "elm.swallow.icon")) 42 if (!strcmp(part, "elm.swallow.icon"))
43 { 43 {
44 Evas_Object *o; 44 Evas_Object *o;
45 snprintf(buf, sizeof(buf), "%s/themes/%s", elm_app_data_dir_get(), t->name); 45 char buf[4096];
46 o = edje_object_add(evas_object_evas_get(obj)); 46 Config *config = termio_config_get(t->term);
47 if (!edje_object_file_set(o, buf, "terminology/background")) 47
48 return NULL; 48 if (config)
49 49 {
50 evas_object_size_hint_min_set(o, 50 snprintf(buf, sizeof(buf), "%s/themes/%s",
51 96 * elm_config_scale_get(), 51 elm_app_data_dir_get(), t->name);
52 40 * elm_config_scale_get()); 52 o = options_theme_preview_add(obj, config, buf,
53 128 * elm_config_scale_get(),
54 64 * elm_config_scale_get());
55 }
53 return o; 56 return o;
54 } 57 }
55 58
diff --git a/src/bin/options_themepv.c b/src/bin/options_themepv.c
new file mode 100644
index 0000000..d5e7c8a
--- /dev/null
+++ b/src/bin/options_themepv.c
@@ -0,0 +1,226 @@
1#include "private.h"
2
3#include <Elementary.h>
4#include "config.h"
5#include "termio.h"
6#include "termpty.h"
7#include "options.h"
8#include "options_themepv.h"
9#include "utils.h"
10#include "main.h"
11#include "col.h"
12
13static void
14_row_set(Evas_Object *o, int y, const char *txt)
15{
16 Evas_Textgrid_Cell *tc;
17 int x, tw, th;
18 const char *s;
19 int fg, bg;
20
21 evas_object_textgrid_size_get(o, &tw, &th);
22 if (y >= th) return;
23 tc = evas_object_textgrid_cellrow_get(o, y);
24 if (!tc) return;
25 fg = COL_DEF;
26 bg = COL_INVIS;
27 for (s = txt, x = 0; x < tw; x++)
28 {
29 unsigned int codepoint = ' ';
30
31 if ((s) && (*s == 0))
32 {
33 s = NULL;
34 codepoint = ' ';
35 }
36 else if (s)
37 {
38 while ((*s <= 0x02) && (*s != 0))
39 {
40 if (*s == 0x01)
41 {
42 s++;
43 if (((*s) >= 0x01) && (*s <= 0x0a)) fg = (*s - 0x01);
44 else if (((*s) >= 0x11) && (*s <= 0x1a)) fg = 12 + (*s - 0x11);
45 }
46 else if (*s == 0x02)
47 {
48 s++;
49 if (((*s) >= 0x01) && (*s <= 0x0a)) bg = (*s - 0x01);
50 else if (((*s) >= 0x11) && (*s <= 0x1a)) bg = 12 + (*s - 0x11);
51 }
52 s++;
53 }
54 if (*s != 0) codepoint = *s;
55 else s = NULL;
56 }
57
58 tc[x].fg_extended = 0;
59 tc[x].bg_extended = 0;
60 tc[x].underline = 0;
61 tc[x].strikethrough = 0;
62#if defined(SUPPORT_DBLWIDTH)
63 tc[x].double_width = 0;
64#endif
65 tc[x].fg_extended = 0;
66 tc[x].bg_extended = 0;
67
68 tc[x].fg = fg;
69 tc[x].bg = bg;
70 tc[x].codepoint = codepoint;
71 if (s) s++;
72 }
73 evas_object_textgrid_cellrow_set(o, y, tc);
74 evas_object_textgrid_update_add(o, 0, y, tw, 1);
75}
76
77static void
78_cb_resize(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void *info EINA_UNUSED)
79{
80 Evas_Object *grid = obj;
81 Evas_Object *textgrid = evas_object_data_get(grid, "textgrid");
82 Evas_Object *cursor = evas_object_data_get(grid, "cursor");
83 Evas_Object *selection = evas_object_data_get(grid, "selection");
84 Evas_Coord w, h, ww, hh;
85
86 evas_object_geometry_get(grid, NULL, NULL, &w, &h);
87 evas_object_textgrid_cell_size_get(textgrid, &ww, &hh);
88 elm_grid_size_set(grid, w, h);
89 elm_grid_pack(grid, textgrid, 0, 0, w, h);
90 elm_grid_pack(grid, cursor, 0, 0, ww, hh);
91 elm_grid_pack(grid, selection, ww * 5, hh * 1, ww * 8, hh * 1);
92}
93
94
95Evas_Object *
96options_theme_preview_add(Evas_Object *parent, Config *config, const char *file, Evas_Coord w, Evas_Coord h)
97{
98 Evas_Object *o, *oo, *obase, *oe, *obg;
99 Evas *evas;
100 int tw, th;
101 Evas_Coord ww, hh, y;
102
103 obase = elm_grid_add(parent);
104 evas = evas_object_evas_get(obase);
105 elm_grid_size_set(obase, w, h);
106
107 // make core frame
108 o = elm_layout_add(parent);
109 oe = elm_layout_edje_get(o);
110 obg = oe;
111 if (!edje_object_file_set(oe, file, "terminology/background"))
112 theme_apply(oe, config, "terminology/background");
113 if (config->translucent)
114 edje_object_signal_emit(oe, "translucent,on", "terminology");
115 else
116 edje_object_signal_emit(oe, "translucent,off", "terminology");
117 edje_object_signal_emit(oe, "focus,in", "terminology");
118 edje_object_signal_emit(oe, "tabcount,on", "terminology");
119 edje_object_signal_emit(oe, "tabmissed,on", "terminology");
120 edje_object_part_text_set(oe, "terminology.tabcount.label", "5/8");
121 edje_object_part_text_set(oe, "terminology.tabmissed.label", "2");
122 elm_grid_pack(obase, o, 0, 0, w, h);
123 evas_object_show(o);
124
125 oo = o;
126
127 // create a bg and swallow into core frame
128 o = elm_layout_add(parent);
129 oe = elm_layout_edje_get(o);
130 if (!edje_object_file_set(oe, file, "terminology/core"))
131 theme_apply(oe, config, "terminology/core");
132 if (config->translucent)
133 edje_object_signal_emit(oe, "translucent,on", "terminology");
134 else
135 edje_object_signal_emit(oe, "translucent,off", "terminology");
136 edje_object_signal_emit(oe, "focus,in", "terminology");
137 evas_object_show(o);
138 elm_layout_content_set(oo, "terminology.content", o);
139
140 oo = o;
141
142 // create a grid proportional layout to hold selection, textgrid and cursor
143 o = elm_grid_add(parent);
144 evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, _cb_resize, NULL);
145 elm_grid_size_set(o, 100, 100);
146 evas_object_show(o);
147 elm_layout_content_set(oo, "terminology.content", o);
148
149 oo = o;
150
151 // create a texgrid and swallow pack into grid
152 o = evas_object_textgrid_add(evas);
153 colors_term_init(o, obg);
154 evas_object_scale_set(o, elm_config_scale_get());
155 if (config->font.bitmap)
156 {
157 char buf[PATH_MAX];
158
159 snprintf(buf, sizeof(buf), "%s/fonts/%s",
160 elm_app_data_dir_get(), config->font.name);
161 evas_object_textgrid_font_set(o, buf, config->font.size);
162 }
163 else
164 evas_object_textgrid_font_set(o, config->font.name, config->font.size);
165 evas_object_textgrid_size_set(o, 80, 24);
166
167 evas_object_textgrid_cell_size_get(o, &ww, &hh);
168 if (ww < 1) ww = 1;
169 if (hh < 1) hh = 1;
170
171 // cmds:
172 // \x01 = set fg
173 // \x02 = set bg
174 //
175 // cols:
176 //
177 // \x01 = def
178 // \x02 = black
179 // \x03 = red
180 // ...
181 // \x09 = white
182 //
183 // \x11 = def BRIGHT
184 // \x12 = black BRIGHT
185 // \x13 = red BRIGHT
186 // ...
187 // \x19 = white BRIGHT
188
189#define F(_x) "\x01"_x
190#define B(_x) "\x01"_x
191#define R "\x01\x01\x02\x10"
192 _row_set(o, 0, " "F("\x04")"$"R" "F("\x19")">"R" test");
193 _row_set(o, 1, F("\x02")"black"R" "F("\x03")"red"R" "F("\x04")"green"R" "F("\x05")"yellow");
194 _row_set(o, 2, F("\x06")"blue"R" "F("\x07")"magenta"R" "F("\x08")"cyan"R" "F("\x09")"white");
195 _row_set(o, 3, F("\x12")"black"R" "F("\x13")"red"R" "F("\x14")"green"R" "F("\x15")"yellow");
196 _row_set(o, 4, F("\x16")"blue"R" "F("\x17")"magenta"R" "F("\x18")"cyan"R" "F("\x19")"white");
197 for (y = 5; y < 24; y++) _row_set(o, y, "");
198
199 evas_object_show(o);
200 evas_object_data_set(oo, "textgrid", o);
201 elm_grid_pack(oo, o, 0, 0, 100, 100);
202
203 // create a cursor and put it in the grid
204 o = elm_layout_add(parent);
205 oe = elm_layout_edje_get(o);
206 if (!edje_object_file_set(oe, file, "terminology/cursor"))
207 theme_apply(oe, config, "terminology/cursor");
208 edje_object_signal_emit(oe, "focus,in", "terminology");
209 evas_object_show(o);
210 evas_object_data_set(oo, "cursor", o);
211 elm_grid_pack(oo, o, 0, 0, 10, 10);
212
213 // create a selection and put it in the grid
214 o = edje_object_add(evas);
215 oe = o;
216 if (!edje_object_file_set(oe, file, "terminology/selection"))
217 theme_apply(oe, config, "terminology/selection");
218 edje_object_signal_emit(oe, "focus,in", "terminology");
219 edje_object_signal_emit(oe, "mode,oneline", "terminology");
220 evas_object_show(o);
221 evas_object_data_set(oo, "selection", o);
222 elm_grid_pack(oo, o, 0, 0, 10, 10);
223
224 evas_object_size_hint_min_set(obase, w, h);
225 return obase;
226}
diff --git a/src/bin/options_themepv.h b/src/bin/options_themepv.h
new file mode 100644
index 0000000..18d24e8
--- /dev/null
+++ b/src/bin/options_themepv.h
@@ -0,0 +1 @@
Evas_Object *options_theme_preview_add(Evas_Object *parent, Config *config, const char *file, Evas_Coord w, Evas_Coord h);