e - paledit - add palette editor tool

devs/bu5hm4n/pointer-fix
Carsten Haitzler 2 years ago
parent bc8a4f9a89
commit 24840b2f6b
  1. 1
      src/bin/meson.build
  2. 1
      src/bin/tools/meson.build
  3. 366
      src/bin/tools/paledit/colsel.c
  4. 8
      src/bin/tools/paledit/e_paledit.desktop
  5. BIN
      src/bin/tools/paledit/e_paledit.png
  6. 122
      src/bin/tools/paledit/main.c
  7. 20
      src/bin/tools/paledit/main.h
  8. 20
      src/bin/tools/paledit/meson.build
  9. 309
      src/bin/tools/paledit/palcols.c
  10. 66
      src/bin/tools/paledit/palimg.c
  11. 331
      src/bin/tools/paledit/palsel.c

@ -564,3 +564,4 @@ suid_exes += join_paths(dir_e_utils, 'enlightenment_ckpasswd')
subdir('e_fm')
subdir('system')
subdir('tools')

@ -0,0 +1 @@
subdir('paledit')

@ -0,0 +1,366 @@
#include "main.h"
static void
_spinner_to_rect(Evas_Object *win)
{
Elm_Object_Item *it;
int r, g, b, a;
elm_colorselector_color_get(evas_object_data_get(win, "pal_colorsel"), &r, &g, &b, &a);
it = elm_genlist_selected_item_get(evas_object_data_get(win, "pal_class_list"));
if (it)
{
Elm_Palette_Color *col = elm_object_item_data_get(it);
Elm_Palette *pal = evas_object_data_get(win, "pal");
col->r = r;
col->g = g;
col->b = b;
col->a = a;
elm_genlist_item_update(it);
pal_save(win);
palimg_update(evas_object_data_get(win, "pal_image"), pal);
}
evas_color_argb_premul(a, &r, &g, &b);
evas_object_color_set(evas_object_data_get(win, "pal_color_rect"), r, g, b, a);
}
static void
_spinner_to_colorsel_mirror(Evas_Object *win)
{
int r, g, b, a;
r = elm_spinner_value_get(evas_object_data_get(win, "pal_spin_int_r"));
g = elm_spinner_value_get(evas_object_data_get(win, "pal_spin_int_g"));
b = elm_spinner_value_get(evas_object_data_get(win, "pal_spin_int_b"));
a = elm_spinner_value_get(evas_object_data_get(win, "pal_spin_int_a"));
elm_colorselector_color_set(evas_object_data_get(win, "pal_colorsel"), r, g, b, a);
}
static void
_spinner_to_entry_mirror(Evas_Object *win)
{
int r, g, b, a;
char buf[256];
elm_colorselector_color_get(evas_object_data_get(win, "pal_colorsel"), &r, &g, &b, &a);
snprintf(buf, sizeof(buf),
"#<+ backing=on backing_color=#0004>"
"<+ color=#f54>%02x</>"
"<+ color=#5f4>%02x</>"
"<+ color=#45f>%02x</>"
"<+ color=#888>%02x</>"
"</>"
, r, g, b, a);
elm_object_text_set(evas_object_data_get(win, "pal_color_entry"), buf);
}
static void
_spinner_to_spinner_mirror(Evas_Object *win)
{
int r, g, b, a;
int pr, pg, pb, pa;
elm_colorselector_color_get(evas_object_data_get(win, "pal_colorsel"), &r, &g, &b, &a);
pr = (r * 100) / 255;
pg = (g * 100) / 255;
pb = (b * 100) / 255;
pa = (a * 100) / 255;
elm_spinner_value_set(evas_object_data_get(win, "pal_spin_int_r"), r);
elm_spinner_value_set(evas_object_data_get(win, "pal_spin_int_g"), g);
elm_spinner_value_set(evas_object_data_get(win, "pal_spin_int_b"), b);
elm_spinner_value_set(evas_object_data_get(win, "pal_spin_int_a"), a);
elm_spinner_value_set(evas_object_data_get(win, "pal_spin_perc_r"), pr);
elm_spinner_value_set(evas_object_data_get(win, "pal_spin_perc_g"), pg);
elm_spinner_value_set(evas_object_data_get(win, "pal_spin_perc_b"), pb);
elm_spinner_value_set(evas_object_data_get(win, "pal_spin_perc_a"), pa);
}
static void
_cb_spinner_perc_changed(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
Evas_Object *win = data;
double val;
int intval;
val = elm_spinner_value_get(obj);
intval = (val * 255.0) / 100.0;
if (obj == evas_object_data_get(win, "pal_spin_perc_r"))
elm_spinner_value_set(evas_object_data_get(win, "pal_spin_int_r"), intval);
else if (obj == evas_object_data_get(win, "pal_spin_perc_g"))
elm_spinner_value_set(evas_object_data_get(win, "pal_spin_int_g"), intval);
else if (obj == evas_object_data_get(win, "pal_spin_perc_b"))
elm_spinner_value_set(evas_object_data_get(win, "pal_spin_int_b"), intval);
else if (obj == evas_object_data_get(win, "pal_spin_perc_a"))
elm_spinner_value_set(evas_object_data_get(win, "pal_spin_int_a"), intval);
_spinner_to_colorsel_mirror(win);
_spinner_to_entry_mirror(win);
_spinner_to_rect(win);
}
static void
_cb_spinner_int_changed(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
Evas_Object *win = data;
double val;
int intval;
val = elm_spinner_value_get(obj);
intval = (val * 100.0) / 255.0;
if (obj == evas_object_data_get(win, "pal_spin_int_r"))
elm_spinner_value_set(evas_object_data_get(win, "pal_spin_perc_r"), intval);
else if (obj == evas_object_data_get(win, "pal_spin_int_g"))
elm_spinner_value_set(evas_object_data_get(win, "pal_spin_perc_g"), intval);
else if (obj == evas_object_data_get(win, "pal_spin_int_b"))
elm_spinner_value_set(evas_object_data_get(win, "pal_spin_perc_b"), intval);
else if (obj == evas_object_data_get(win, "pal_spin_int_a"))
elm_spinner_value_set(evas_object_data_get(win, "pal_spin_perc_a"), intval);
_spinner_to_colorsel_mirror(win);
_spinner_to_entry_mirror(win);
_spinner_to_rect(win);
}
static void
_cb_colorsel_changed(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Evas_Object *win = data;
_spinner_to_spinner_mirror(win);
_spinner_to_entry_mirror(win);
_spinner_to_rect(win);
}
static void
_colsel_entry_handle(Evas_Object *win, Evas_Object *entry, Eina_Bool activated)
{
const char *markup = elm_object_text_get(entry);
if (markup)
{
char *plain = elm_entry_markup_to_utf8(markup);
if (plain)
{
char *p = plain;
int r, g, b, a;
if (p[0] == '#') p++;
if (strlen(p) == 8)
{
if (sscanf(p, "%02x%02x%02x%02x", &r, &g, &b, &a) == 4)
{
elm_colorselector_color_set(evas_object_data_get(win, "pal_colorsel"), r, g, b, a);
goto ok;
}
}
else if (activated)
{
if (strlen(p) == 6)
{
if (sscanf(p, "%02x%02x%02x", &r, &g, &b) == 3)
{
a = 255;
elm_colorselector_color_set(evas_object_data_get(win, "pal_colorsel"), r, g, b, a);
goto ok;
}
}
else if (strlen(p) == 4)
{
if (sscanf(p, "%01x%01x%01x%01x", &r, &g, &b, &a) == 4)
{
r = (r << 4) | r;
g = (g << 4) | g;
b = (b << 4) | b;
a = (a << 4) | a;
elm_colorselector_color_set(evas_object_data_get(win, "pal_colorsel"), r, g, b, a);
goto ok;
}
}
else if (strlen(p) == 3)
{
if (sscanf(p, "%01x%01x%01x", &r, &g, &b) == 3)
{
r = (r << 4) | r;
g = (g << 4) | g;
b = (b << 4) | b;
a = 255;
elm_colorselector_color_set(evas_object_data_get(win, "pal_colorsel"), r, g, b, a);
goto ok;
}
}
}
free(plain);
}
}
return;
ok:
colsel_update(win);
}
static void
_cb_color_entry_changed(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
Evas_Object *win = data;
_colsel_entry_handle(win, obj, EINA_FALSE);
}
static void
_cb_color_entry_activated(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
Evas_Object *win = data;
_colsel_entry_handle(win, obj, EINA_TRUE);
}
static void
_colsel_row(Evas_Object *win, Evas_Object *tb,
int row,
int r, int g, int b, int a,
const char *label, const char *name_percent, const char *name_int)
{
Evas_Object *o, *sp;
o = elm_label_add(win);
elm_object_text_set(o, label);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0);
evas_object_size_hint_fill_set(o, 0.0, EVAS_HINT_FILL);
elm_table_pack(tb, o, 0, row, 1, 1);
evas_object_show(o);
o = evas_object_rectangle_add(evas_object_evas_get(win));
evas_object_color_set(o, r, g, b, a);
evas_object_size_hint_min_set(o, ELM_SCALE_SIZE(15), ELM_SCALE_SIZE(15));
elm_table_pack(tb, o, 1, row, 1, 1);
evas_object_show(o);
// invisible spinner for just spacing the 2 cells with real spinners for
// holding max possible vbalue and then some to avoid resizing due to font
// changes mwith some digits causing sizing to go up
sp = o = elm_spinner_add(win);
elm_spinner_editable_set(o, EINA_TRUE);
elm_spinner_label_format_set(o, "%1.0f%%");
elm_spinner_step_set(o, 1);
elm_spinner_min_max_set(o, 0, 99999);
elm_spinner_value_set(o, 99999);
elm_table_pack(tb, o, 2, row, 1, 1);
sp = o = elm_spinner_add(win);
elm_spinner_editable_set(o, EINA_TRUE);
elm_spinner_label_format_set(o, "%1.0f");
elm_spinner_step_set(o, 1);
elm_spinner_min_max_set(o, 0, 99999);
elm_spinner_value_set(o, 99999);
elm_table_pack(tb, o, 3, row, 1, 1);
sp = o = elm_spinner_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_spinner_editable_set(o, EINA_TRUE);
elm_spinner_label_format_set(o, "%1.0f%%");
elm_spinner_step_set(o, 1);
elm_spinner_min_max_set(sp, 0, 100);
evas_object_smart_callback_add(o, "changed", _cb_spinner_perc_changed, win);
elm_table_pack(tb, o, 2, row, 1, 1);
evas_object_show(o);
evas_object_data_set(win, name_percent, o);
sp = o = elm_spinner_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_spinner_editable_set(o, EINA_TRUE);
elm_spinner_label_format_set(o, "%1.0f");
elm_spinner_step_set(o, 1);
elm_spinner_min_max_set(sp, 0, 255);
evas_object_smart_callback_add(o, "changed", _cb_spinner_int_changed, win);
elm_table_pack(tb, o, 3, row, 1, 1);
evas_object_show(o);
evas_object_data_set(win, name_int, o);
}
void
colsel_update(Evas_Object *win)
{
_spinner_to_spinner_mirror(win);
_spinner_to_entry_mirror(win);
_spinner_to_rect(win);
}
Evas_Object *
colsel_add(Evas_Object *win)
{
Evas_Object *o, *bxr, *tb2, *fr2, *fr;
bxr = o = elm_box_add(win);
elm_box_padding_set(o, 0, ELM_SCALE_SIZE(10));
elm_box_align_set(o, 0.5, 0.0);
evas_object_size_hint_weight_set(o, 0.0, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
fr = o = elm_frame_add(win);
elm_object_style_set(o, "pad_small");
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(bxr, o);
evas_object_show(o);
fr2 = o = elm_frame_add(win);
elm_object_style_set(o, "outline");
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_content_set(fr, o);
evas_object_show(o);
tb2 = o = elm_table_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_content_set(fr2, o);
evas_object_show(o);
o = elm_bg_add(win);
elm_object_style_set(o, "checks_small");
evas_object_size_hint_min_set(o, ELM_SCALE_SIZE(80), ELM_SCALE_SIZE(60));
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_table_pack(tb2, o, 0, 0, 1, 1);
evas_object_show(o);
o = evas_object_rectangle_add(evas_object_evas_get(win));
evas_object_size_hint_min_set(o, ELM_SCALE_SIZE(60), ELM_SCALE_SIZE(40));
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_color_set(o, 128, 64, 0, 128);
elm_table_pack(tb2, o, 0, 0, 1, 1);
evas_object_data_set(win, "pal_color_rect", o);
evas_object_show(o);
o = elm_colorselector_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_smart_callback_add(o, "changed", _cb_colorsel_changed, win);
elm_box_pack_end(bxr, o);
evas_object_show(o);
evas_object_data_set(win, "pal_colorsel", o);
o = elm_entry_add(win);
elm_entry_single_line_set(o, EINA_TRUE);
elm_entry_scrollable_set(o, EINA_TRUE);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_smart_callback_add(o, "changed,user", _cb_color_entry_changed, win);
evas_object_smart_callback_add(o, "activated", _cb_color_entry_activated, win);
elm_box_pack_end(bxr, o);
evas_object_show(o);
evas_object_data_set(win, "pal_color_entry", o);
tb2 = o = elm_table_add(win);
elm_table_padding_set(o, ELM_SCALE_SIZE(10), ELM_SCALE_SIZE(10));
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, 0.0);
elm_box_pack_end(bxr, o);
evas_object_show(o);
_colsel_row(win, tb2, 0, 255, 0, 0, 255, "Red", "pal_spin_perc_r", "pal_spin_int_r");
_colsel_row(win, tb2, 1, 0, 255, 0, 255, "Green", "pal_spin_perc_g", "pal_spin_int_g");
_colsel_row(win, tb2, 2, 0, 0, 255, 255, "Blue", "pal_spin_perc_b", "pal_spin_int_b");
_colsel_row(win, tb2, 3, 64, 64, 64, 128, "Alpha", "pal_spin_perc_a", "pal_spin_int_a");
return bxr;
}

@ -0,0 +1,8 @@
[Desktop Entry]
Type=Application
Name=Palette Editor
Icon=e_paledit
Exec=e_paledit
Comment=A tool for editing color schemes and paletted for Enlightenment
Categories=Settings;DesktopSettings;
StartupWMClass=e_paledit

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

@ -0,0 +1,122 @@
#include "main.h"
void
pal_save(Evas_Object *win)
{
char *palname = evas_object_data_get(win, "pal_selected_palette");
if (!palname) return;
Elm_Palette *pal = evas_object_data_get(win, "pal");
elm_config_palette_save(pal, palname);
elm_config_palette_set(palname);
elm_config_all_flush();
elm_config_reload();
}
void
pal_load(Evas_Object *win)
{
char *palname = evas_object_data_get(win, "pal_selected_palette");
if (!palname) return;
Elm_Palette *pal = elm_config_palette_load(palname);
if (!pal) return;
evas_object_data_set(win, "pal", pal);
palcols_fill(win);
palimg_update(evas_object_data_get(win, "pal_image"), pal);
elm_object_text_set(evas_object_data_get(win, "pal_name"), palname);
pal_save(win);
}
static void
_cb_close_click(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
evas_object_del(data);
}
EAPI_MAIN int
elm_main(int argc, char **argv)
{
Evas_Object *o, *win, *bx, *bxh, *fr, *tb;
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
win = elm_win_util_standard_add("e_paledit", "Palette Editor");
elm_win_autodel_set(win, EINA_TRUE);
fr = o = elm_frame_add(win);
elm_object_style_set(o, "pad_medium");
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, o);
evas_object_show(o);
bx = o = elm_box_add(win);
elm_box_padding_set(o, 0, ELM_SCALE_SIZE(10));
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_content_set(fr, o);
evas_object_show(o);
bxh = o = elm_box_add(win);
elm_box_padding_set(o, ELM_SCALE_SIZE(10), 0);
elm_box_horizontal_set(o, EINA_TRUE);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(bx, o);
evas_object_show(o);
o = palcols_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(bxh, o);
evas_object_show(o);
o = elm_separator_add(win);
evas_object_size_hint_weight_set(o, 0.0, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, 0.5, EVAS_HINT_FILL);
elm_box_pack_end(bxh, o);
evas_object_show(o);
o = colsel_add(win);
evas_object_size_hint_weight_set(o, 0.0, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(bxh, o);
evas_object_show(o);
tb = o = elm_table_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_fill_set(o, 1.0, EVAS_HINT_FILL);
elm_box_pack_end(bx, o);
evas_object_show(o);
o = evas_object_rectangle_add(evas_object_evas_get(win));
evas_object_size_hint_min_set(o, ELM_SCALE_SIZE(120), 0);
elm_table_pack(tb, o, 0, 0, 1, 1);
o = elm_button_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_smart_callback_add(o, "clicked", _cb_close_click, win);
elm_object_text_set(o, "Close");
elm_table_pack(tb, o, 0, 0, 1, 1);
evas_object_show(o);
colsel_update(win);
if (argc > 1)
{
evas_object_data_set(win, "pal_selected_palette", strdup(argv[1]));
}
else
{
const char *palconf = elm_config_palette_get();
if (!palconf) palconf = "default";
evas_object_data_set(win, "pal_selected_palette", strdup(palconf));
}
pal_load(win);
evas_object_show(win);
elm_run();
return 0;
}
ELM_MAIN()

@ -0,0 +1,20 @@
#ifndef _MAIN_H
#define _MAIN_H
#include <Elementary.h>
void palimg_update(Evas_Object *img, Elm_Palette *pal);
Evas_Object *palimg_add(Evas_Object *win);
Evas_Object *palsel_add(Evas_Object *win);
void palcols_fill(Evas_Object *win);
Evas_Object *palcols_add(Evas_Object *win);
void colsel_update(Evas_Object *win);
Evas_Object *colsel_add(Evas_Object *win);
void pal_load(Evas_Object *win);
void pal_save(Evas_Object *win);
#endif

@ -0,0 +1,20 @@
executable('e_paledit',
[ 'main.c',
'main.h',
'colsel.c',
'palcols.c',
'palimg.c',
'palsel.c'
],
include_directories: include_directories('.'),
dependencies : [ dep_elementary, deps ],
install_dir : dir_bin,
install : true
)
install_data('e_paledit.desktop',
install_dir: join_paths(dir_data, 'applications')
)
install_data('e_paledit.png',
install_dir: join_paths(dir_data, 'icons/hicolor/128x128/apps')
)

@ -0,0 +1,309 @@
#include "main.h"
static void _pal_color_add(Evas_Object *win);
static void _pal_color_del(Evas_Object *win);
static char *
_cb_class_gl_label_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
{
Elm_Palette_Color *col = data;
if (col->name) return strdup(col->name);
else return strdup("");
}
static Evas_Object *
_cb_class_gl_content_get(void *data, Evas_Object *obj, const char *part)
{
Elm_Palette_Color *col = data;
Evas_Object *o, *tb;
int r, g, b, a;
if (!!strcmp(part, "elm.swallow.icon")) return NULL;
tb = o = elm_table_add(obj);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
o = elm_bg_add(obj);
elm_object_style_set(o, "checks_small");
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_table_pack(tb, o, 0, 0, 1, 1);
evas_object_show(o);
o = evas_object_rectangle_add(evas_object_evas_get(obj));
r = col->r;
g = col->g;
b = col->b;
a = col->a;
evas_color_argb_premul(a, &r, &g, &b);
evas_object_color_set(o, r, g, b, a);
evas_object_size_hint_min_set(o, ELM_SCALE_SIZE(30), ELM_SCALE_SIZE(15));
elm_table_pack(tb, o, 0, 0, 1, 1);
evas_object_show(o);
return tb;
}
static void
_cb_class_gl_sel(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
{
Evas_Object *win = data;
Elm_Object_Item *it = event_info;
Elm_Palette_Color *col = elm_object_item_data_get(it);
elm_colorselector_color_set(evas_object_data_get(win, "pal_colorsel"),
col->r, col->g, col->b, col->a);
colsel_update(win);
elm_object_text_set(evas_object_data_get(win, "pal_class_entry"), col->name);
}
static int
_cb_class_insert_cmp(const void *pa, const void *pb)
{
Elm_Palette_Color *col1 = elm_object_item_data_get(pa);
Elm_Palette_Color *col2 = elm_object_item_data_get(pb);
const char *n1, *n2;
if (!col1) return -1;
if (!col2) return 1;
n1 = col1->name;
if (!n1) n1 = "";
n2 = col2->name;
if (!n2) n2 = "";
return strcmp(n1, n2);
}
static void
_cb_select_click(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Evas_Object *win = data;
Evas_Object *o = palsel_add(win);
evas_object_show(o);
}
static void
_cb_add_click(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
_pal_color_add(data);
}
static void
_cb_del_click(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
_pal_color_del(data);
}
static void
_pal_color_add(Evas_Object *win)
{
const char *markup = elm_object_text_get(evas_object_data_get(win, "pal_class_entry"));
if (markup)
{
char *plain = elm_entry_markup_to_utf8(markup);
if (plain)
{
Elm_Genlist_Item_Class *itc = evas_object_data_get(win, "pal_class_itc");
if (itc)
{
Elm_Palette *pal = evas_object_data_get(win, "pal");
Evas_Object *list = evas_object_data_get(win, "pal_class_list");
Eina_List *l;
Elm_Palette_Color *col;
int r, g, b, a;
EINA_LIST_FOREACH(pal->colors, l, col)
{
if (!col->name) continue;
if (!strcmp(col->name, plain)) goto exists;
}
elm_colorselector_color_get(evas_object_data_get(win, "pal_colorsel"), &r, &g, &b, &a);
elm_config_palette_color_set(pal, plain, r, g, b, a);
EINA_LIST_FOREACH(pal->colors, l, col)
{
if (!col->name) continue;
if (!strcmp(col->name, plain))
{
Elm_Object_Item *it;
it = elm_genlist_item_sorted_insert(list, itc, col,
NULL, ELM_GENLIST_ITEM_NONE,
_cb_class_insert_cmp,
_cb_class_gl_sel, win);
elm_genlist_item_show(it, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
elm_genlist_item_selected_set(it, EINA_TRUE);
break;
}
}
palimg_update(evas_object_data_get(win, "pal_image"), pal);
}
exists:
free(plain);
}
}
pal_save(win);
}
static void
_pal_color_del(Evas_Object *win)
{
Elm_Object_Item *it, *it_sel;
it = elm_genlist_selected_item_get(evas_object_data_get(win, "pal_class_list"));
if (it)
{
Elm_Palette *pal = evas_object_data_get(win, "pal");
Elm_Palette_Color *col = elm_object_item_data_get(it);
if (col->name) elm_config_palette_color_unset(pal, col->name);
it_sel = elm_genlist_item_next_get(it);
if (!it_sel) it_sel = elm_genlist_item_prev_get(it);
elm_object_item_del(it);
if (it_sel)
{
elm_genlist_item_show(it_sel, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
elm_genlist_item_selected_set(it_sel, EINA_TRUE);
}
palimg_update(evas_object_data_get(win, "pal_image"), pal);
}
pal_save(win);
}
void
palcols_fill(Evas_Object *win)
{
Elm_Object_Item *sel_it = NULL;
Elm_Palette *pal = evas_object_data_get(win, "pal");
Elm_Palette_Color *col;
Evas_Object *list = evas_object_data_get(win, "pal_class_list");
Eina_List *l;
Elm_Genlist_Item_Class *itc = evas_object_data_get(win, "pal_class_itc");
Elm_Object_Item *it;
elm_genlist_clear(list);
if (!itc)
{
itc = elm_genlist_item_class_new();
evas_object_data_set(win, "pal_class_itc", itc);
itc->item_style = "default";
itc->func.text_get = _cb_class_gl_label_get;
itc->func.content_get = _cb_class_gl_content_get;
}
EINA_LIST_FOREACH(pal->colors, l, col)
{
it = elm_genlist_item_sorted_insert(list, itc, col,
NULL, ELM_GENLIST_ITEM_NONE,
_cb_class_insert_cmp,
_cb_class_gl_sel, win);
if (!sel_it) sel_it = it;
}
if (sel_it)
{
elm_genlist_item_show(sel_it, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
elm_genlist_item_selected_set(sel_it, EINA_TRUE);
}
}
Evas_Object *
palcols_add(Evas_Object *win)
{
Evas_Object *o, *bxl, *btn, *bxh2;
bxl = o = elm_box_add(win);
elm_box_padding_set(o, 0, ELM_SCALE_SIZE(10));
elm_box_align_set(o, 0.5, 0.0);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(o);
btn = o = elm_button_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_smart_callback_add(o, "clicked", _cb_select_click, win);
elm_object_text_set(o, "Select palette");
elm_box_pack_end(bxl, o);
evas_object_show(o);
o = evas_object_rectangle_add(evas_object_evas_get(win));
evas_object_size_hint_min_set(o, ELM_SCALE_SIZE(240), 0);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
elm_box_pack_end(bxl, o);
bxh2 = o = elm_box_add(win);
elm_box_padding_set(o, ELM_SCALE_SIZE(10), 0);
elm_box_horizontal_set(o, EINA_TRUE);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(bxl, o);
evas_object_show(o);
o = elm_entry_add(win);
elm_entry_single_line_set(o, EINA_TRUE);
elm_entry_scrollable_set(o, EINA_TRUE);
elm_entry_editable_set(o, EINA_FALSE);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(bxh2, o);
evas_object_show(o);
evas_object_data_set(win, "pal_name", o);
o = palimg_add(win);
elm_box_pack_end(bxh2, o);
evas_object_show(o);
evas_object_data_set(win, "pal_image", o);
o = elm_genlist_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(bxl, o);
evas_object_show(o);
evas_object_data_set(win, "pal_class_list", o);
bxh2 = o = elm_box_add(win);
elm_box_padding_set(o, ELM_SCALE_SIZE(10), 0);
elm_box_horizontal_set(o, EINA_TRUE);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(bxl, o);
evas_object_show(o);
o = elm_entry_add(win);
elm_entry_single_line_set(o, EINA_TRUE);
elm_entry_scrollable_set(o, EINA_TRUE);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(bxh2, o);
evas_object_show(o);
evas_object_data_set(win, "pal_class_entry", o);
btn = o = elm_button_add(win);
evas_object_size_hint_weight_set(o, 0.0, 0.0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_smart_callback_add(o, "clicked", _cb_add_click, win);
elm_box_pack_end(bxh2, o);
evas_object_show(o);
o = elm_icon_add(win);
elm_icon_standard_set(o, "add");
elm_object_content_set(btn, o);
evas_object_show(o);
btn = o = elm_button_add(win);
evas_object_size_hint_weight_set(o, 0.0, 0.0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_smart_callback_add(o, "clicked", _cb_del_click, win);
elm_box_pack_end(bxh2, o);
evas_object_show(o);
o = elm_icon_add(win);
elm_icon_standard_set(o, "sub");
elm_object_content_set(btn, o);
evas_object_show(o);
return bxl;
}

@ -0,0 +1,66 @@
#include "main.h"
void
palimg_update(Evas_Object *img, Elm_Palette *pal)
{
unsigned char *pix, *p, *lin;
int w, h, stride;
Eina_List *l;
Elm_Palette_Color *col;
int x = 0, pixn = 0;
if (!pal) return;
evas_object_image_size_get(img, &w, &h);
stride = evas_object_image_stride_get(img);
pix = evas_object_image_data_get(img, EINA_TRUE);
lin = p = pix;
while (pixn < 256)
{
#define PIX_WRITE(r, g, b, a) \
*((int *)p) = (a << 24) | (r << 16) | (g << 8) | (b); \
p += sizeof(int); \
pixn++; \
x++; \
if (x == w) \
{ \
lin += stride; \
p = lin; \
x = 0; \
} \
if (pixn >= 256) break
if (!pal->colors)
{
PIX_WRITE(0, 0, 0, 0);
}
else
{
EINA_LIST_FOREACH(pal->colors, l, col)
{
int r, g, b, a;
r = col->r;
g = col->g;
b = col->b;
a = col->a;
evas_color_argb_premul(a, &r, &g, &b);
PIX_WRITE(r, g, b, a);
}
}
}
evas_object_image_data_set(img, pix);
evas_object_image_data_update_add(img, 0, 0, w, h);
}
Evas_Object *
palimg_add(Evas_Object *win)
{
const int zoom = 2;
Evas_Object *o = evas_object_image_filled_add(evas_object_evas_get(win));
evas_object_image_smooth_scale_set(o, EINA_FALSE);
evas_object_image_alpha_set(o, EINA_TRUE);
evas_object_image_size_set(o, 16, 16);
evas_object_size_hint_min_set(o,
ELM_SCALE_SIZE(zoom * 16),
ELM_SCALE_SIZE(zoom * 16));
return o;
}

@ -0,0 +1,331 @@
#include "main.h"
static void
_name_dismiss(Evas_Object *win)
{
evas_object_del(evas_object_data_get(win, "name_entry"));
evas_object_del(evas_object_data_get(win, "name_ok"));
evas_object_del(evas_object_data_get(win, "name_cancel"));
}
static void
_cb_name_ok_click(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
const char *markup = elm_object_text_get(evas_object_data_get(data, "name_entry"));
if (markup)
{
char *plain = elm_entry_markup_to_utf8(markup);
if (plain)
{
const char *op = evas_object_data_get(data, "name_op");
if (op)
{
if (!strcmp(op, "new"))
{
Elm_Palette *pal = elm_config_palette_load(plain);
if (pal)
{
free(evas_object_data_get(data, "pal_selected_palette"));
evas_object_data_set(data, "pal_selected_palette",
strdup(plain));
elm_config_palette_free(pal);
}
}
else if (!strcmp(op, "copy"))
{
char *palname = evas_object_data_get(data, "pal_selected_palette");
if (palname)
{
Elm_Palette *pal = elm_config_palette_load(palname);
if (pal)
{
free(evas_object_data_get(data, "pal_selected_palette"));
evas_object_data_set(data, "pal_selected_palette",
strdup(plain));
elm_config_palette_free(pal);
}
}
}
pal_load(data);
elm_popup_dismiss(evas_object_data_get(data, "pal_popup"));
}
free(plain);
}
}
_name_dismiss(data);
}
static void
_cb_name_activate(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
_cb_name_ok_click(data, NULL, NULL);
}
static void
_cb_name_cancel_click(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
_name_dismiss(data);
}
static void
_palsel_name_request(Evas_Object *win, const char *name, const char *op)
{
Evas_Object *o, *tb;
tb = evas_object_data_get(win, "pal_popup_table");
evas_object_data_set(win, "name_op", op);
o = elm_entry_add(win);
elm_entry_single_line_set(o, EINA_TRUE);
elm_entry_scrollable_set(o, EINA_TRUE);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_text_set(o, name);
evas_object_smart_callback_add(o, "activated", _cb_name_activate, win);
elm_table_pack(tb, o, 0, 1, 2, 1);
evas_object_show(o);
evas_object_data_set(win, "name_entry", o);
elm_entry_select_all(o);
elm_object_focus_set(o, EINA_TRUE);
o = elm_button_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_text_set(o, "OK");
evas_object_smart_callback_add(o, "clicked", _cb_name_ok_click, win);
elm_table_pack(tb, o, 0, 2, 1, 1);
evas_object_show(o);
evas_object_data_set(win, "name_ok", o);
o = elm_button_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_text_set(o, "Cancel");
evas_object_smart_callback_add(o, "clicked", _cb_name_cancel_click, win);
elm_table_pack(tb, o, 1, 2, 1, 1);
evas_object_show(o);
evas_object_data_set(win, "name_cancel", o);
}
static void
_cb_select_new_click(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
_palsel_name_request(data, "new", "new");
}
static void
_cb_select_del_click(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
char *palname = evas_object_data_get(data, "pal_selected_palette");
if (palname)
{
Elm_Object_Item *it_sel, *it = NULL;
it_sel = elm_genlist_selected_item_get(evas_object_data_get(data, "pal_popup_list"));
if (it_sel)
{
it = elm_genlist_item_next_get(it_sel);
if (!it) it = elm_genlist_item_prev_get(it_sel);
}
elm_object_item_del(it_sel);
elm_config_palette_delete(palname);
evas_object_data_del(data, "pal_selected_palette");
free(palname);
if (it)
{
elm_genlist_item_show(it, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
elm_genlist_item_selected_set(it, EINA_TRUE);
}
}
}
static void
_cb_select_copy_click(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
_palsel_name_request(data, "copy", "copy");
}
static void
_cb_select_select_click(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
pal_load(data);
elm_popup_dismiss(evas_object_data_get(data, "pal_popup"));
}
static void
_cb_select_cancel_click(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
elm_popup_dismiss(evas_object_data_get(data, "pal_popup"));
}
static void
_cb_select_dismissed(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
evas_object_del(evas_object_data_get(data, "pal_popup"));
evas_object_data_del(data, "pal_popup");
}
static char *
_cb_palette_gl_label_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
{
return strdup(data);
}
static Evas_Object *
_cb_palette_gl_content_get(void *data, Evas_Object *obj, const char *part)
{
Elm_Palette *pal;
Evas_Object *o;
if (!!strcmp(part, "elm.swallow.icon")) return NULL;
pal = elm_config_palette_load(data);
if (!pal) return NULL;
o = palimg_add(obj);
palimg_update(o, pal);
elm_config_palette_free(pal);
return o;
}
static void
_cb_palette_gl_del(void *data, Evas_Object *obj EINA_UNUSED)
{
free(data);
}
static void
_cb_palette_gl_sel(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
{
Evas_Object *win = data;
Elm_Object_Item *it = event_info;
free(evas_object_data_get(win, "pal_selected_palette"));
evas_object_data_set(win, "pal_selected_palette",
strdup(elm_object_item_data_get(it)));
}
static void
_palette_list_fill(Evas_Object *win, Evas_Object *list)
{
Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
Eina_List *palettes, *l;
const char *pal, *palconf;
Elm_Object_Item *sel_it = NULL;
itc->item_style = "default";
itc->func.text_get = _cb_palette_gl_label_get;
itc->func.content_get = _cb_palette_gl_content_get;
itc->func.del = _cb_palette_gl_del;
palconf = elm_config_palette_get();
palettes = elm_config_palette_list();
EINA_LIST_FOREACH(palettes, l, pal)
{
char *dat = strdup(pal);
Elm_Object_Item *it;
it = elm_genlist_item_append(list, itc, dat,
NULL, ELM_GENLIST_ITEM_NONE,
_cb_palette_gl_sel, win);
if ((palconf) && (!strcmp(pal, palconf)))
{
sel_it = it;
}
}
elm_config_palette_list_free(palettes);
elm_genlist_item_class_free(itc);
if (sel_it)
{
elm_genlist_item_show(sel_it, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
elm_genlist_item_selected_set(sel_it, EINA_TRUE);
}
}
Evas_Object *
palsel_add(Evas_Object *win)
{
Evas_Object *o, *pop, *tb, *li, *bx;
pop = o = elm_popup_add(win);
elm_popup_scrollable_set(o, EINA_FALSE);
elm_object_part_text_set(o, "title,text", "Select a palette");
evas_object_smart_callback_add(o, "dismissed", _cb_select_dismissed, win);
evas_object_data_set(win, "pal_popup", o);
tb = o = elm_table_add(win);
elm_table_padding_set(o, ELM_SCALE_SIZE(10), ELM_SCALE_SIZE(10));
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_content_set(pop, o);
evas_object_show(o);
evas_object_data_set(win, "pal_popup_table", o);
o = evas_object_rectangle_add(evas_object_evas_get(win));
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_min_set(o, ELM_SCALE_SIZE(220), ELM_SCALE_SIZE(300));
elm_table_pack(tb, o, 0, 0, 2, 1);
li = o = elm_genlist_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_smart_callback_add(o, "activated", _cb_select_select_click, win);
elm_table_pack(tb, o, 0, 0, 2, 1);
evas_object_show(o);
evas_object_data_set(win, "pal_popup_list", o);
_palette_list_fill(win, li);
bx = o = elm_box_add(win);
elm_box_homogeneous_set(o, EINA_TRUE);
elm_box_padding_set(o, ELM_SCALE_SIZE(5), 0);
elm_box_horizontal_set(o, EINA_TRUE);
elm_object_part_content_set(pop, "button1", o);
evas_object_show(o);
o = elm_button_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_text_set(o, "New");
evas_object_smart_callback_add(o, "clicked", _cb_select_new_click, win);
elm_box_pack_end(bx, o);
evas_object_show(o);
o = elm_button_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_text_set(o, "Del");
evas_object_smart_callback_add(o, "clicked", _cb_select_del_click, win);
elm_box_pack_end(bx, o);
evas_object_show(o);
o = elm_button_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_text_set(o, "Copy");
evas_object_smart_callback_add(o, "clicked", _cb_select_copy_click, win);
elm_box_pack_end(bx, o);
evas_object_show(o);
o = evas_object_rectangle_add(evas_object_evas_get(win));
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_box_pack_end(bx, o);
o = elm_button_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_text_set(o, "Select");
evas_object_smart_callback_add(o, "clicked", _cb_select_select_click, win);
elm_box_pack_end(bx, o);
evas_object_show(o);
o = elm_button_add(win);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0);
evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_text_set(o, "Cancel");
evas_object_smart_callback_add(o, "clicked", _cb_select_cancel_click, win);
elm_box_pack_end(bx, o);
evas_object_show(o);
return pop;
}
Loading…
Cancel
Save