From 573b885421511220cf888fc9f2821b3adbbbb846 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pekka=20Geh=C3=B6r?= Date: Tue, 16 Dec 2008 15:48:34 +0200 Subject: [PATCH] Added the image size change --- irreco/src/core/irreco_button_creator_dlg.c | 199 +++++++++++++++++----------- 1 file changed, 120 insertions(+), 79 deletions(-) diff --git a/irreco/src/core/irreco_button_creator_dlg.c b/irreco/src/core/irreco_button_creator_dlg.c index 6dbd6262..927377fd 100644 --- a/irreco/src/core/irreco_button_creator_dlg.c +++ b/irreco/src/core/irreco_button_creator_dlg.c @@ -2,17 +2,17 @@ /* * irreco - Ir Remote Control * Copyright (C) 2008 Pekka Gehör (pegu6@msn.com) - * + * * irreco_button_creator_dlg.c is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * irreco_button_creator_dlg.c is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -36,7 +36,7 @@ * @ingroup Irreco * * - * @{ + * @{ */ /** @@ -89,13 +89,15 @@ _set_button_details(IrrecoButtonCreatorDlg *self, IrrecoTheme *irreco_theme, IrrecoThemeButton *button); void _unbutton_size_changed(GtkSpinButton *spinbutton, IrrecoButtonCreatorDlg*self); +void +_button_size_changed(GtkSpinButton *spinbutton, IrrecoButtonCreatorDlg*self); /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ /* Construction & Destruction */ /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ /** - * @name Construction & Destruction - * @{ + * @name Construction & Destruction + * @{ */ G_DEFINE_TYPE (IrrecoButtonCreatorDlg, irreco_button_creator_dlg, @@ -103,7 +105,7 @@ G_DEFINE_TYPE (IrrecoButtonCreatorDlg, irreco_button_creator_dlg, static void irreco_button_creator_dlg_constructed(GObject *object) { /* TODO: Add initialization code here */ - + IrrecoData *irreco_data; IrrecoButtonCreatorDlg *self; @@ -117,7 +119,7 @@ static void irreco_button_creator_dlg_constructed(GObject *object) GtkWidget *vbox_unpressed_preview; GtkWidget *vbox_pressed_preview; GtkWidget *label_size; - + /* Settings */ GtkWidget *table_settings; GtkWidget *label_allow_text; @@ -222,12 +224,12 @@ static void irreco_button_creator_dlg_constructed(GObject *object) irreco_gtk_align(GTK_WIDGET(table_settings), 0, 0, 1, 1, 8, 8, 8, 8), gtk_label_new("SETTINGS")); - + gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(self)->vbox), self->notebook); /* Set widgets on the table */ - + gtk_table_set_row_spacings(GTK_TABLE(table), 6); gtk_table_set_col_spacings(GTK_TABLE(table), 6); @@ -289,7 +291,7 @@ static void irreco_button_creator_dlg_constructed(GObject *object) self->preview_image_unpressed); gtk_container_add(GTK_CONTAINER(vbox_unpressed_preview), self->label_unpressed_size); - + gtk_container_add(GTK_CONTAINER(frame_pressed), self->event_box_pressed); gtk_container_add(GTK_CONTAINER(self->event_box_pressed), vbox_pressed_preview); @@ -297,10 +299,10 @@ static void irreco_button_creator_dlg_constructed(GObject *object) self->preview_image_pressed); gtk_container_add(GTK_CONTAINER(vbox_pressed_preview), self->label_pressed_size); - - - - + + + + /*Added button list on combobox*/ fill_buttons_combobox(self); @@ -312,7 +314,7 @@ static void irreco_button_creator_dlg_constructed(GObject *object) gtk_spin_button_set_value(GTK_SPIN_BUTTON(self->text_v_align), 0.5); gtk_spin_button_set_value(GTK_SPIN_BUTTON(self->unbutton_size), 10); gtk_spin_button_set_value(GTK_SPIN_BUTTON(self->button_size), 10); - + /* Set button name */ gtk_widget_set_name(self->text_format_up, "unpressed"); gtk_widget_set_name(self->text_format_down, "pressed"); @@ -339,7 +341,8 @@ static void irreco_button_creator_dlg_constructed(GObject *object) G_CALLBACK(_select_font_format), self); g_signal_connect(G_OBJECT(self->unbutton_size), "value-changed", G_CALLBACK(_unbutton_size_changed), self); - + g_signal_connect(G_OBJECT(self->button_size), "value-changed", + G_CALLBACK(_button_size_changed), self); gtk_widget_show_all(GTK_WIDGET(self)); IRRECO_RETURN @@ -396,7 +399,7 @@ GtkWidget /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ /** * @name Private Functions - * @{ + * @{ */ /** @@ -415,10 +418,10 @@ static void fill_buttons_combobox(IrrecoButtonCreatorDlg *self) button_list = g_key_file_new(); g_key_file_load_from_file(button_list, BUTTON_LIST_DIR, G_KEY_FILE_NONE, &error); - + keys = g_key_file_get_keys(button_list, "button-names", &length, &error); - + for(i=0; icombobox_name), g_key_file_get_string(button_list, @@ -434,16 +437,33 @@ static void fill_buttons_combobox(IrrecoButtonCreatorDlg *self) void _unbutton_size_changed(GtkSpinButton *spinbutton, IrrecoButtonCreatorDlg*self) { - + GString *image_path = g_string_new(self->unpressed_path->str); + IRRECO_ENTER IRRECO_PRINTF("PATH: %s\n", self->unpressed_path->str); + _draw_preview_image(GTK_BUTTON(self->text_format_up), self, - self->unpressed_path->str); - + image_path->str); + + g_string_free(image_path, TRUE); IRRECO_RETURN } +void +_button_size_changed(GtkSpinButton *spinbutton, IrrecoButtonCreatorDlg*self) +{ + GString *image_path = g_string_new(self->unpressed_path->str); + + IRRECO_ENTER + + IRRECO_PRINTF("PATH: %s\n", self->unpressed_path->str); + _draw_preview_image(GTK_BUTTON(self->text_format_down), self, + image_path->str); + + g_string_free(image_path, TRUE); + IRRECO_RETURN +} /** * Draw preview with current image. @@ -461,6 +481,10 @@ _draw_preview_image(GtkButton *button, IrrecoButtonCreatorDlg *self, g_assert(self != NULL); /* compared with whichever image */ if (g_str_equal("pressed", gtk_widget_get_name(GTK_WIDGET(button)))) { + gint button_width = 0; + gint button_height = 0; + GdkPixbuf *pixbuf_size = NULL; + if (image != NULL) { pixbuf = gdk_pixbuf_new_from_file_at_scale(image, IRRECO_BUTTON_PREVIEW_WIDHT, @@ -477,20 +501,34 @@ _draw_preview_image(GtkButton *button, IrrecoButtonCreatorDlg *self, g_string_printf(self->pressed_path, "%s", image); gtk_widget_realize(GTK_WIDGET(self->preview_image_pressed)); gtk_image_set_from_pixbuf(GTK_IMAGE(self->preview_image_pressed), - GDK_PIXBUF(pixbuf)); - + GDK_PIXBUF(pixbuf)); + /* Show image real size */ - g_string_printf(size, "%sx%s", g_strdup_printf("%d", - gdk_pixbuf_get_width( - gdk_pixbuf_new_from_file(image, &error))), - g_strdup_printf("%d", gdk_pixbuf_get_height( - gdk_pixbuf_new_from_file(image, &error)))); + pixbuf_size = gdk_pixbuf_new_from_file(image, &error); + button_width = atoi(g_strdup_printf("%.0f", + (gdk_pixbuf_get_width( + pixbuf_size))/ + (6-gtk_spin_button_get_value(GTK_SPIN_BUTTON( + self->button_size))))); + button_height = atoi(g_strdup_printf("%.0f", + (gdk_pixbuf_get_height( + pixbuf_size)/ + (6-gtk_spin_button_get_value(GTK_SPIN_BUTTON( + self->button_size)))))); + + if (pixbuf_size != NULL) g_object_unref(G_OBJECT(pixbuf_size)); + + g_string_printf(size, "%sx%s", g_strdup_printf("%d", button_width), + g_strdup_printf("%d", button_height)); + gtk_label_set_text(GTK_LABEL(self->label_pressed_size), size->str); } else { gint button_width = 0; gint button_height = 0; + GdkPixbuf *pixbuf_size = NULL; + if (image != NULL) { pixbuf = gdk_pixbuf_new_from_file_at_scale(image, IRRECO_BUTTON_PREVIEW_WIDHT, @@ -506,24 +544,26 @@ _draw_preview_image(GtkButton *button, IrrecoButtonCreatorDlg *self, GDK_PIXBUF(pixbuf)); /* Show image real size */ + pixbuf_size = gdk_pixbuf_new_from_file(image, &error); button_width = atoi(g_strdup_printf("%.0f", (gdk_pixbuf_get_width( - gdk_pixbuf_new_from_file(image, &error)))/ + pixbuf_size))/ (6-gtk_spin_button_get_value(GTK_SPIN_BUTTON( self->unbutton_size))))); button_height = atoi(g_strdup_printf("%.0f", (gdk_pixbuf_get_height( - gdk_pixbuf_new_from_file(image, &error))/ + pixbuf_size)/ (6-gtk_spin_button_get_value(GTK_SPIN_BUTTON( - self->unbutton_size)))))); + self->unbutton_size)))))); + if (pixbuf_size != NULL) g_object_unref(G_OBJECT(pixbuf_size)); g_string_printf(size, "%sx%s", g_strdup_printf("%d", button_width), g_strdup_printf("%d", button_height)); gtk_label_set_text(GTK_LABEL(self->label_unpressed_size), size->str); - g_string_printf(self->unpressed_path, "%s", image); + /* Set button sensitive */ gtk_widget_set_sensitive(self->add_button_pressed, TRUE); gtk_widget_set_sensitive(self->event_box_pressed, TRUE); @@ -559,11 +599,10 @@ static void _select_image(GtkButton *button, IrrecoButtonCreatorDlg *self) gchar *filename; filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file_dlg)); - + /* Attempt to display the image. */ if (_draw_preview_image(button, self, filename)) { - /*irreco_gstring_set_and_free(self->filename, filename);*/ - g_string_printf(self->filename, "%s",filename); + irreco_gstring_set_and_free(self->filename, filename); filename = NULL; break; @@ -599,11 +638,11 @@ gboolean irreco_button_creator_dlg_run(IrrecoData *irreco_data, IrrecoTheme * irreco_theme, GtkWindow *parent_window, IrrecoThemeButton *button) -{ +{ IrrecoButtonCreatorDlg *self; gint response; gboolean loop = TRUE; - gboolean rvalue = FALSE; + gboolean rvalue = FALSE; IRRECO_ENTER self = (IrrecoButtonCreatorDlg*)irreco_button_creator_dlg_new( @@ -612,18 +651,20 @@ gboolean irreco_button_creator_dlg_run(IrrecoData *irreco_data, self->theme = irreco_theme; IRRECO_PRINTF("Button: %s\n", button->name->str); - + /*if(irreco_theme != NULL) {*/ - if (g_utf8_strlen(button->name->str, 1) >0) { + if (g_utf8_strlen(button->name->str, 1) >0) { /* Sets the button details */ _set_button_details(self, irreco_theme, button); } - + do { response = gtk_dialog_run(GTK_DIALOG(self)); switch (response) { case GTK_RESPONSE_OK: + + irreco_theme_button_set(button, gtk_combo_box_get_active_text( GTK_COMBO_BOX( @@ -675,12 +716,12 @@ _set_button_details(IrrecoButtonCreatorDlg *self, IrrecoTheme *irreco_theme, IrrecoThemeButton *button) { IRRECO_ENTER - + /* Set button information on table */ gtk_combo_box_prepend_text(GTK_COMBO_BOX(self->combobox_name), button->name->str); gtk_combo_box_set_active(GTK_COMBO_BOX(self->combobox_name), - 0); + 0); _draw_preview_image(GTK_BUTTON(self->add_button_unpressed), self, button->image_up->str); @@ -688,9 +729,9 @@ _set_button_details(IrrecoButtonCreatorDlg *self, IrrecoTheme *irreco_theme, self, button->image_down->str); if (button->allow_text) { - gtk_button_clicked(GTK_BUTTON(self->allow_text)); + gtk_button_clicked(GTK_BUTTON(self->allow_text)); } - + gtk_spin_button_set_value(GTK_SPIN_BUTTON(self->text_padding), button->text_padding); @@ -698,7 +739,7 @@ _set_button_details(IrrecoButtonCreatorDlg *self, IrrecoTheme *irreco_theme, button->text_h_align); gtk_spin_button_set_value(GTK_SPIN_BUTTON(self->text_v_align), button->text_v_align); - /*set text format */ + /*set text format */ if (strlen(button->text_format_up->str) > 0) { _set_font_format(self, button->text_format_up->str, @@ -751,7 +792,7 @@ static void _pressed_event_signal_image_clicked(GtkWidget *widget, IrrecoButtonCreatorDlg *self) { IRRECO_ENTER - + gtk_button_clicked(GTK_BUTTON(self->add_button_pressed)); IRRECO_RETURN @@ -766,11 +807,11 @@ static void _toggle_button_toggled(GtkToggleButton *togglebutton, if (gtk_toggle_button_get_active(togglebutton)) { gtk_button_set_label(GTK_BUTTON(self->allow_text), "YES"); gtk_widget_set_sensitive(self->text_format_up, TRUE); - gtk_widget_set_sensitive(self->text_format_down, TRUE); + gtk_widget_set_sensitive(self->text_format_down, TRUE); } else { gtk_button_set_label(GTK_BUTTON(self->allow_text), "NO"); gtk_widget_set_sensitive(self->text_format_up, FALSE); - gtk_widget_set_sensitive(self->text_format_down, FALSE); + gtk_widget_set_sensitive(self->text_format_down, FALSE); } IRRECO_RETURN @@ -786,7 +827,7 @@ static void _select_font_format(GtkButton *button, IrrecoButtonCreatorDlg *self) GString *format = g_string_new(NULL); const gchar *span = ">%s"; - + IRRECO_ENTER dialog = gtk_font_selection_dialog_new("Button font"); @@ -800,8 +841,8 @@ static void _select_font_format(GtkButton *button, IrrecoButtonCreatorDlg *self) "red", font, span);*/ g_string_printf(format, "unpressed_format = format->str; @@ -860,7 +901,7 @@ static void _select_font_format(GtkButton *button, IrrecoButtonCreatorDlg *self) sprintf(&color_string[1], "%.2X", color->red /256); sprintf(&color_string[3], "%.2X", color->green/256); sprintf(&color_string[5], "%.2X", color->blue /256); - + pango_font_description_set_family(font, family); pango_font_description_set_size(font, size * PANGO_SCALE); @@ -903,20 +944,20 @@ static void _select_font_format(GtkButton *button, IrrecoButtonCreatorDlg *self) IRRECO_PRINTF("FONT: %s\n", markup); gtk_label_set_markup(GTK_LABEL(self->label_text_format_up), markup); - - value = g_strdup_printf ("%u,%u,%u", - color->red, - color->green, + + value = g_strdup_printf ("%u,%u,%u", + color->red, + color->green, color->blue); - + IRRECO_PRINTF("FONT: %s\n", color_string); - + IRRECO_PRINTF("FONT: %s\n", value); - - - + + + if(markup != NULL) g_free(markup); if(text != NULL) g_free(text); if(family != NULL) g_free(family); @@ -930,39 +971,39 @@ static void _select_font_format(GtkButton *button, IrrecoButtonCreatorDlg *self) } #endif /** -* Set button text format +* Set button text format */ static void _set_font_format(IrrecoButtonCreatorDlg *self, const gchar *button_format, const gchar *text) { - - + + gchar *markup; GString *format = g_string_new(NULL); - + IRRECO_ENTER - + g_string_printf(format, "%s", button_format); - + markup = g_markup_printf_escaped(format->str, text); - + IRRECO_PRINTF("TEXT: %s\n", markup); - + if (strcmp(text, gtk_label_get_text(GTK_LABEL( self->label_text_format_up))) == 0) { gtk_label_set_markup(GTK_LABEL(self->label_text_format_up), - markup); + markup); } else { - + gtk_label_set_markup(GTK_LABEL(self->label_text_format_down), - markup); + markup); } - + if(markup != NULL) g_free(markup); - g_string_free(format, TRUE); - + g_string_free(format, TRUE); + IRRECO_RETURN - - + + } /** @} */ -- 2.11.4.GIT