Preview works.

Option for setting desktop icon fonts; still needs work...
This commit is contained in:
Sanel Zukan 2008-01-21 19:08:36 +00:00
parent 6b5cd7bf4c
commit b9440e66be
2 changed files with 170 additions and 149 deletions

View File

@ -20,6 +20,7 @@
#include <edelib/Config.h>
#include <edelib/Debug.h>
#include <edelib/Util.h>
#include <edelib/FontChooser.h>
#include <edelib/Directory.h>
#include <string.h>
@ -36,41 +37,51 @@
#include <FL/Fl_Color_Chooser.h>
#include <FL/Fl_File_Chooser.h>
#include <FL/Fl_Shared_Image.h>
#include <FL/Fl_Tiled_Image.h>
#include <FL/Fl_Menu_Button.h>
#include <FL/x.h>
#define EICOMAN_UID 0x10
#define EICOMAN_UID 0x10
#define EICOMAN_CONFIG "../eiconman/eiconman.conf"
Fl_Menu_Item mode_menu[] = {
{_("Center"), 0, 0},
{_("Stretch"), 0, 0},
{_("Stretch (aspect)"), 0, 0},
{_("Tiled"), 0, 0},
{_("Tile"), 0, 0},
{0}
};
// make sure this part matches array positions in mode_menu[]
#define IMG_CENTER 0
#define IMG_STRETCH 1
#define IMG_TILE 2
Fl_Button* browse;
Fl_Button* desk_background_color;
Fl_Input* desk_background;
Fl_Choice* desk_background_mode;
Fl_Check_Button* desk_use_wallpaper;
Fl_Box* wallpaper;
Fl_Box* wallpaper;
Fl_Box* wallpaper_img;
Fl_Button* icon_background_color;
Fl_Button* icon_label_color;
Fl_Check_Button* icon_show_background_color;
Fl_Check_Button* icon_show_label;
Fl_Value_Slider* icon_font_size;
int icon_font;
int icon_font_size;
Fl_Value_Slider* icon_label_width;
Fl_Input* icon_font_txt;
Fl_Check_Button* engage_with_one_click;
void set_wallpaper(const char* path) {
if(!path)
return;
// fill input if not given
const char* old = desk_background->value();
if(!old || strcmp(old, path) != 0)
desk_background->value(path);
@ -79,9 +90,80 @@ void set_wallpaper(const char* path) {
if(!img)
return;
Fl_Image* scaled = img->copy(wallpaper->w() - 2, wallpaper->h() - 2);
wallpaper->image(scaled);
wallpaper->redraw();
int area_x = wallpaper->x() + 2;
int area_y = wallpaper->y() + 2;
int area_w = wallpaper->w() - 4;
int area_h = wallpaper->h() - 4;
/*
* Before doing anything with the image, first scale it relative to wallpaper box,
* which is relative to the screen sizes.
*/
int display_w = DisplayWidth(fl_display, fl_screen);
int display_h = DisplayHeight(fl_display, fl_screen);
int scale_w_factor, scale_h_factor;
if(display_w > area_w)
scale_w_factor = display_w / area_w;
else
scale_w_factor = 1;
if(display_h > area_h)
scale_h_factor = display_h / area_h;
else
scale_h_factor = 1;
Fl_Image* rel_img = img->copy(img->w() / scale_w_factor, img->h() / scale_h_factor);
/*
* Now all transformations will be applied on relative image
*/
int img_w = rel_img->w();
int img_h = rel_img->h();
wallpaper_img->position(area_x, area_y);
switch(desk_background_mode->value()) {
case IMG_STRETCH: {
Fl_Image* transformed = rel_img->copy(area_w, area_h);
wallpaper_img->size(area_w, area_h);
wallpaper_img->image(transformed);
break;
}
case IMG_TILE: {
Fl_Tiled_Image* tiled = new Fl_Tiled_Image(rel_img, area_w, area_h);
wallpaper_img->size(area_w, area_h);
wallpaper_img->image(tiled);
break;
}
case IMG_CENTER:
default: // fallback
if(img_w > wallpaper->w() && img_h > wallpaper->h()) {
wallpaper_img->size(area_w, area_h);
wallpaper_img->image(rel_img);
} else {
int pos_x = wallpaper_img->x();
int pos_y = wallpaper_img->y();
if(rel_img->w() < area_w)
pos_x = pos_x + (area_w / 2) - (rel_img->w() / 2);
if(rel_img->h() < area_h)
pos_y = pos_y + (area_h / 2) - (rel_img->h() / 2);
wallpaper_img->position(pos_x, pos_y);
int sw = (rel_img->w() > area_w) ? area_w : rel_img->w();
int sh = (rel_img->h() > area_h) ? area_h : rel_img->h();
wallpaper_img->size(sw, sh);
wallpaper_img->image(rel_img);
}
break;
}
}
void disable_wallpaper(bool doit) {
@ -89,20 +171,22 @@ void disable_wallpaper(bool doit) {
desk_use_wallpaper->value(0);
desk_background_mode->deactivate();
desk_background->deactivate();
browse->deactivate();
wallpaper->color(desk_background_color->color());
if(wallpaper->image()) {
wallpaper->image(NULL);
wallpaper->redraw();
}
browse->deactivate();
// hide image
wallpaper_img->hide();
} else {
desk_use_wallpaper->value(1);
desk_background_mode->activate();
desk_background->activate();
browse->activate();
set_wallpaper(desk_background->value());
wallpaper_img->show();
if(!wallpaper_img->image())
set_wallpaper(desk_background->value());
}
wallpaper->redraw();
}
void set_rgb_color(Fl_Button* btn, unsigned char r, unsigned char g, unsigned char b) {
@ -135,6 +219,7 @@ void wallpaper_color_cb(Fl_Widget*, void* w) {
Fl_Color c = (Fl_Color)edelib::color_rgb_to_fltk(r, g, b);
desk_background_color->color(c);
wallpaper->color(c);
wallpaper_img->redraw();
wallpaper->redraw();
}
}
@ -145,6 +230,8 @@ void browse_cb(Fl_Widget*, void*) {
return;
set_wallpaper(ret);
wallpaper_img->redraw();
wallpaper->redraw();
}
void wallpaper_use_cb(Fl_Widget*, void*) {
@ -155,34 +242,13 @@ void wallpaper_use_cb(Fl_Widget*, void*) {
disable_wallpaper(true);
}
void choice_cb(Fl_Widget*, void*) {
set_wallpaper(desk_background->value());
wallpaper_img->redraw();
wallpaper->redraw();
}
void apply_cb(Fl_Widget*, void* w) {
#if 0
unsigned char r, g, b;
edelib::Window* win = (edelib::Window*)w;
win->xsettings()->set("EDE/Desktop/Background/Wallpaper", desk_background->value());
win->xsettings()->set("EDE/Desktop/Background/WallpaperMode", desk_background_mode->value());
win->xsettings()->set("EDE/Desktop/Background/WallpaperShow", desk_use_wallpaper->value());
edelib::color_fltk_to_rgb(desk_background_color->color(), r, g, b);
win->xsettings()->set("EDE/Desktop/Background/Color", r, g, b, 0);
edelib::color_fltk_to_rgb(icon_background_color->color(), r, g, b);
win->xsettings()->set("EDE/Desktop/Icons/BackgroundColor", r, g, b, 0);
edelib::color_fltk_to_rgb(icon_label_color->color(), r, g, b);
win->xsettings()->set("EDE/Desktop/Icons/LabelColor", r, g, b, 0);
win->xsettings()->set("EDE/Desktop/Icons/BackgroundColorShow", icon_show_background_color->value());
win->xsettings()->set("EDE/Desktop/Icons/LabelShow", icon_show_label->value());
win->xsettings()->set("EDE/Desktop/Icons/FontSize", (int)icon_font_size->value());
win->xsettings()->set("EDE/Desktop/Icons/LabelWidth", (int)icon_label_width->value());
win->pause_xsettings_callback();
win->xsettings()->manager_notify();
win->restore_xsettings_callback();
#endif
edelib::Config conf;
conf.set("Desktop", "Color", (int)desk_background_color->color());
conf.set("Desktop", "WallpaperUse", desk_use_wallpaper->value());
@ -193,7 +259,8 @@ void apply_cb(Fl_Widget*, void* w) {
conf.set("Icons", "Label Background", (int)icon_background_color->color());
conf.set("Icons", "Label Foreground", (int)icon_label_color->color());
conf.set("Icons", "Label Fontsize", icon_font_size->value());
conf.set("Icons", "Label Font", icon_font);
conf.set("Icons", "Label Fontsize", icon_font_size);
conf.set("Icons", "Label Maxwidth", icon_label_width->value());
conf.set("Icons", "Label Transparent", icon_show_background_color->value());
conf.set("Icons", "Label Visible", icon_show_label->value());
@ -209,93 +276,20 @@ void ok_cb(Fl_Widget*, void* w) {
win->hide();
}
/*
* XSETTINGS getter. Left commented for future
*/
#if 0
bool xsettings_cb(const char* name, edelib::XSettingsAction action, const edelib::XSettingsSetting* setting, void* data) {
if(strcmp(name, "EDE/Desktop/Background/Wallpaper") == 0) {
if(action == edelib::XSETTINGS_ACTION_DELETED || setting->type != edelib::XSETTINGS_TYPE_STRING)
disable_wallpaper(true);
else
set_wallpaper(setting->data.v_string);
void browse_fonts_cb(Fl_Widget*, void* w) {
Fl_Input* in = (Fl_Input*)w;
int retsz;
const char* font_name = Fl::get_font_name((Fl_Font)icon_font, 0);
int font = edelib::font_chooser(_("Choose font"), "iso8859-2", retsz, font_name, icon_font_size);
if(font == -1)
return;
} else if(strcmp(name, "EDE/Desktop/Background/Color") == 0) {
if(action == edelib::XSETTINGS_ACTION_DELETED || setting->type != edelib::XSETTINGS_TYPE_COLOR)
desk_background_color->color(FL_BLACK);
else set_rgb_color(icon_label_color,
setting->data.v_color.red,
setting->data.v_color.green,
setting->data.v_color.blue);
} else if(strcmp(name, "EDE/Desktop/Background/WallpaperMode") == 0) {
if(action == edelib::XSETTINGS_ACTION_DELETED || setting->type != edelib::XSETTINGS_TYPE_INT)
desk_background_mode->value(0);
else {
int m = setting->data.v_int;
if(m > 3) {
EWARNING(ESTRLOC ": Got wrong value from %s (%i), zeroing...\n", setting->name, setting->data.v_int);
m = 0;
}
desk_background_mode->value(m);
}
} else if(strcmp(name, "EDE/Desktop/Background/WallpaperShow") == 0) {
if(action == edelib::XSETTINGS_ACTION_DELETED || setting->type != edelib::XSETTINGS_TYPE_INT)
disable_wallpaper(true);
else {
if(setting->data.v_int)
disable_wallpaper(false);
else
disable_wallpaper(true);
}
} else if(strcmp(name, "EDE/Desktop/Icons/BackgroundColor") == 0) {
if(action == edelib::XSETTINGS_ACTION_DELETED || setting->type != edelib::XSETTINGS_TYPE_COLOR)
icon_background_color->color(FL_BLUE);
else
set_rgb_color(icon_background_color,
setting->data.v_color.red,
setting->data.v_color.green,
setting->data.v_color.blue);
} else if(strcmp(name, "EDE/Desktop/Icons/LabelColor") == 0) {
if(action == edelib::XSETTINGS_ACTION_DELETED || setting->type != edelib::XSETTINGS_TYPE_COLOR)
icon_label_color->color(FL_WHITE);
else
set_rgb_color(icon_label_color,
setting->data.v_color.red,
setting->data.v_color.green,
setting->data.v_color.blue);
} else if(strcmp(name, "EDE/Desktop/Icons/BackgroundColorShow") == 0) {
if(action == edelib::XSETTINGS_ACTION_DELETED || setting->type != edelib::XSETTINGS_TYPE_INT)
icon_show_background_color->value(0);
else {
if(setting->data.v_int)
icon_show_background_color->value(1);
else
icon_show_background_color->value(0);
}
} else if(strcmp(name, "EDE/Desktop/Icons/LabelShow") == 0) {
if(action == edelib::XSETTINGS_ACTION_DELETED || setting->type != edelib::XSETTINGS_TYPE_INT)
icon_show_label->value(0);
else {
if(setting->data.v_int)
icon_show_label->value(1);
else
icon_show_label->value(0);
}
} else if(strcmp(name, "EDE/Desktop/Icons/FontSize") == 0) {
if(action == edelib::XSETTINGS_ACTION_DELETED || setting->type != edelib::XSETTINGS_TYPE_INT)
icon_font_size->value(12);
else
icon_font_size->value(setting->data.v_int);
} else if(strcmp(name, "EDE/Desktop/Icons/LabelWidth") == 0) {
if(action == edelib::XSETTINGS_ACTION_DELETED || setting->type != edelib::XSETTINGS_TYPE_INT)
icon_label_width->value(55);
else
icon_label_width->value(setting->data.v_int);
}
font_name = Fl::get_font_name((Fl_Font)font, 0);
in->value(font_name);
return false;
icon_font = font;
icon_font_size = retsz;
}
#endif
void load_settings(void) {
int b_mode = 0;
@ -305,24 +299,27 @@ void load_settings(void) {
int i_label_color = FL_WHITE;
int i_show_background_color = 0;
int i_show_label = 1;
int i_font_size = 12;
int i_label_width = 55;
bool one_click = false;
edelib::Config conf;
char wpath[256];
bool wpath_found = false;
if(conf.load(EICOMAN_CONFIG)) {
conf.get("Desktop", "Color", d_background_color, d_background_color);
conf.get("Desktop", "WallpaperUse", d_wp_use, d_wp_use);
conf.get("Desktop", "WallpaperMode", b_mode, b_mode);
if(conf.get("Desktop", "Wallpaper", wpath, sizeof(wpath)))
set_wallpaper(wpath);
wpath_found = true;
else
disable_wallpaper(true);
wpath_found = false;
conf.get("Icons", "Label Background", i_background_color, i_background_color);
conf.get("Icons", "Label Foreground", i_label_color, i_label_color);
conf.get("Icons", "Label Fontsize", i_font_size, i_font_size);
conf.get("Icons", "Label Font", icon_font, 1);
conf.get("Icons", "Label Fontsize", icon_font_size, 12);
conf.get("Icons", "Label Maxwidth", i_label_width, i_label_width);
conf.get("Icons", "Label Transparent",i_show_background_color, i_show_background_color);
conf.get("Icons", "Label Visible", i_show_label, i_show_label);
@ -331,21 +328,31 @@ void load_settings(void) {
desk_background_color->color(d_background_color);
wallpaper->color(d_background_color);
desk_background_mode->value(b_mode);
desk_use_wallpaper->value(d_wp_use);
if(!d_wp_use)
if(d_wp_use && wpath_found)
set_wallpaper(wpath);
else
disable_wallpaper(true);
icon_background_color->color(i_background_color);
icon_label_color->color(i_label_color);
icon_show_background_color->value(i_show_background_color);
icon_show_label->value(i_show_label);
icon_font_size->value(i_font_size);
icon_label_width->value(i_label_width);
engage_with_one_click->value(one_click);
//printf("%i %s\n", icon_font, Fl::get_font_name((Fl_Font)icon_font, 0));
icon_font_txt->value(Fl::get_font_name((Fl_Font)icon_font, 0));
}
int main(int argc, char** argv) {
Fl::set_fonts("iso8859-2");
Fl::set_font(FL_HELVETICA, "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-iso8859-2");
int show_group = 1;
if(argc > 1) {
if(strcmp(argv[1], "--desktop") == 0)
@ -357,8 +364,6 @@ int main(int argc, char** argv) {
}
edelib::Window* win = new edelib::Window(550, 285, _("Desktop options"));
//win->xsettings_callback(xsettings_cb, NULL);
win->begin();
Fl_Tabs* tabs = new Fl_Tabs(10, 10, 530, 230);
tabs->begin();
@ -379,6 +384,14 @@ int main(int argc, char** argv) {
wallpaper->box(FL_DOWN_BOX);
wallpaper->color(FL_BLACK);
/*
* Real image, since box will be resized as image size, but not
* larger than wallpaper box. wallpaper_img will be resized in set_wallpaper()
*/
wallpaper_img = new Fl_Box(wallpaper->x(), wallpaper->y(), 0, 0);
wallpaper_img->box(FL_NO_BOX);
wallpaper_img->align(FL_ALIGN_CLIP);
Fl_Box* b4 = new Fl_Box(60, 206, 145, 14);
b4->box(FL_THIN_UP_BOX);
@ -390,6 +403,7 @@ int main(int argc, char** argv) {
desk_background_mode = new Fl_Choice(295, 116, 220, 24, _("Mode:"));
desk_background_mode->down_box(FL_BORDER_BOX);
desk_background_mode->menu(mode_menu);
desk_background_mode->callback(choice_cb);
desk_background_color = new Fl_Button(295, 161, 25, 24, _("Background color"));
desk_background_color->color(FL_BLACK);
@ -423,17 +437,18 @@ int main(int argc, char** argv) {
icon_show_label = new Fl_Check_Button(260, 90, 220, 25, _("Show label"));
icon_show_label->down_box(FL_DOWN_BOX);
icon_font_size = new Fl_Value_Slider(30, 155, 220, 20, _("Font size"));
icon_font_size->type(5);
icon_font_size->step(1);
icon_font_size->maximum(48);
icon_font_size->align(FL_ALIGN_TOP_LEFT);
icon_label_width = new Fl_Value_Slider(260, 155, 220, 20, _("Label width"));
icon_label_width = new Fl_Value_Slider(30, 155, 220, 25, _("Label width"));
icon_label_width->type(5);
icon_label_width->step(1);
icon_label_width->maximum(200);
icon_label_width->align(FL_ALIGN_TOP_LEFT);
icon_font_txt = new Fl_Input(260, 155, 190, 25, _("Label font"));
icon_font_txt->align(FL_ALIGN_TOP_LEFT);
Fl_Button* icon_font_browse_button = new Fl_Button(455, 155, 25, 25, "...");
icon_font_browse_button->callback(browse_fonts_cb, icon_font_txt);
g2->end();
Fl_Group* g3 = new Fl_Group(20, 30, 510, 195, _("Icons behaviour"));
@ -448,6 +463,8 @@ int main(int argc, char** argv) {
Fl_Button* ok = new Fl_Button(260, 250, 90, 25, _("&OK"));
ok->callback(ok_cb, win);
//ok->labelfont((Fl_Font)18);
//ok->labelsize(14);
Fl_Button* apply = new Fl_Button(355, 250, 90, 25, _("&Apply"));
apply->callback(apply_cb, win);
Fl_Button* cancel = new Fl_Button(450, 250, 90, 25, _("&Cancel"));

View File

@ -6,7 +6,7 @@ Function {} {open
} {
Fl_Window {} {
label {Desktop options} open
xywh {333 344 550 285} type Double visible
xywh {394 295 550 285} type Double visible
} {
Fl_Tabs {} {open
xywh {10 10 530 230} labelsize 14
@ -69,13 +69,17 @@ Function {} {open
label {Show label}
xywh {260 90 220 25} down_box DOWN_BOX
}
Fl_Value_Slider {} {
label {Font size}
xywh {30 155 220 20} type {Horz Knob} align 5 step 0.01 textsize 12
}
Fl_Value_Slider {} {
label {Label width}
xywh {260 155 220 20} type {Horz Knob} align 5 step 0.01 textsize 12
xywh {30 155 220 25} type {Horz Knob} align 5 step 0.01 textsize 12
}
Fl_Input {} {
label {Label font}
xywh {260 155 190 25} align 5
}
Fl_Button {} {
label {...}
xywh {455 155 25 25}
}
}
Fl_Group {} {