From: Jim Evins Date: Tue, 8 Apr 2008 02:04:10 +0000 (+0000) Subject: 2008-04-07 Jim Evins X-Git-Tag: glabels-2_3_0~263 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=85c07ac71aaff4903c38f816ae77c5932754512b;p=glabels 2008-04-07 Jim Evins * src/wdgt-rotate-label.h: * src/wdgt-rotate-label.c: (gl_wdgt_rotate_label_init), (gl_wdgt_rotate_label_new), (toggled_cb), (create_pixbuf), (gl_wdgt_rotate_label_get_state), (gl_wdgt_rotate_label_set_state), (gl_wdgt_rotate_label_set_template_name): Modified wdgt-rotate-label to better indicate the rotation choices. * data/glade/Makefile.am: * data/glade/wdgt-rotate-label.glade: Deleted wdgt-rotate-label.glade. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@768 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 2bf67cb0..8cfcdece 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,15 @@ +2008-04-07 Jim Evins + + * src/wdgt-rotate-label.h: + * src/wdgt-rotate-label.c: (gl_wdgt_rotate_label_init), + (gl_wdgt_rotate_label_new), (toggled_cb), (create_pixbuf), + (gl_wdgt_rotate_label_get_state), (gl_wdgt_rotate_label_set_state), + (gl_wdgt_rotate_label_set_template_name): + Modified wdgt-rotate-label to better indicate the rotation choices. + * data/glade/Makefile.am: + * data/glade/wdgt-rotate-label.glade: + Deleted wdgt-rotate-label.glade. + 2008-04-04 Jim Evins * data/templates/brother-other-templates.xml: diff --git a/glabels2/data/glade/Makefile.am b/glabels2/data/glade/Makefile.am index 4747c88f..fdccb1cb 100644 --- a/glabels2/data/glade/Makefile.am +++ b/glabels2/data/glade/Makefile.am @@ -10,7 +10,6 @@ glade_DATA = \ property-bar.glade \ print-custom-widget.glade \ wdgt-media-select.glade \ - wdgt-rotate-label.glade \ new-label-dialog.glade EXTRA_DIST = $(glade_DATA) diff --git a/glabels2/data/glade/wdgt-rotate-label.glade b/glabels2/data/glade/wdgt-rotate-label.glade deleted file mode 100644 index 89e24a03..00000000 --- a/glabels2/data/glade/wdgt-rotate-label.glade +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - True - window1 - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - True - False - True - False - False - GDK_WINDOW_TYPE_HINT_NORMAL - GDK_GRAVITY_NORTH_WEST - True - False - - - - 12 - True - False - 6 - - - - True - True - Rotate - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - - True - - - 0 - True - True - - - - - - - diff --git a/glabels2/src/wdgt-rotate-label.c b/glabels2/src/wdgt-rotate-label.c index 4edca601..993eab20 100644 --- a/glabels2/src/wdgt-rotate-label.c +++ b/glabels2/src/wdgt-rotate-label.c @@ -27,14 +27,13 @@ #include "wdgt-rotate-label.h" #include -#include -#include -#include +#include #include #include #include "marshal.h" #include "color.h" +#include "hig.h" #include #include "cairo-label-path.h" @@ -48,6 +47,7 @@ #define LINE_COLOR GL_COLOR(0,0,0) #define FILL_COLOR GL_COLOR(255,255,255) +#define SHADOW_COLOR GL_COLOR_A(192,192,192,128) #define LINE_WIDTH_PIXELS 1.0 @@ -61,8 +61,10 @@ struct _glWdgtRotateLabelPrivate { - GtkWidget *rotate_check; - GtkWidget *rotate_drawingarea; + GtkWidget *no_rotate_radio; + GtkWidget *rotate_radio; + GtkWidget *no_rotate_image; + GtkWidget *rotate_image; lglTemplate *template; }; @@ -84,24 +86,17 @@ static gint wdgt_rotate_label_signals[LAST_SIGNAL] = { 0 }; static void gl_wdgt_rotate_label_finalize (GObject *object); -static void gl_wdgt_rotate_label_construct (glWdgtRotateLabel *rotate_label); - -static void entry_changed_cb (GtkToggleButton *toggle, +static void toggled_cb (GtkToggleButton *toggle, gpointer user_data); -static void drawingarea_update (GtkDrawingArea *drawing_area, - lglTemplate *template, +static GdkPixbuf *create_pixbuf (lglTemplate *template, gboolean rotate_flag); -static gboolean expose_cb (GtkWidget *drawingarea, - GdkEventExpose *event, - gpointer user_data); - /****************************************************************************/ /* Boilerplate Object stuff. */ /****************************************************************************/ -G_DEFINE_TYPE (glWdgtRotateLabel, gl_wdgt_rotate_label, GTK_TYPE_VBOX); +G_DEFINE_TYPE (glWdgtRotateLabel, gl_wdgt_rotate_label, GTK_TYPE_HBOX); static void @@ -128,6 +123,44 @@ static void gl_wdgt_rotate_label_init (glWdgtRotateLabel *rotate_label) { rotate_label->priv = g_new0 (glWdgtRotateLabelPrivate, 1); + + gtk_container_set_border_width (GTK_CONTAINER (rotate_label), GL_HIG_PAD2); + + rotate_label->priv->no_rotate_radio = gtk_radio_button_new_with_label (NULL, _("Normal")); + rotate_label->priv->rotate_radio = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rotate_label->priv->no_rotate_radio), _("Rotated")); + + gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (rotate_label->priv->no_rotate_radio), + FALSE); + gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (rotate_label->priv->rotate_radio), + FALSE); + + gtk_button_set_image_position (GTK_BUTTON (rotate_label->priv->no_rotate_radio), + GTK_POS_TOP); + gtk_button_set_image_position (GTK_BUTTON (rotate_label->priv->rotate_radio), + GTK_POS_TOP); + + rotate_label->priv->no_rotate_image = gtk_image_new (); + rotate_label->priv->rotate_image = gtk_image_new (); + + gtk_button_set_image (GTK_BUTTON (rotate_label->priv->no_rotate_radio), + rotate_label->priv->no_rotate_image); + gtk_button_set_image (GTK_BUTTON (rotate_label->priv->rotate_radio), + rotate_label->priv->rotate_image); + + gtk_box_pack_start (GTK_BOX (rotate_label), + rotate_label->priv->no_rotate_radio, + FALSE, FALSE, GL_HIG_PAD1); + gtk_box_pack_start (GTK_BOX (rotate_label), + rotate_label->priv->rotate_radio, + FALSE, FALSE, GL_HIG_PAD1); + + /* Connect signals to controls */ + g_signal_connect (G_OBJECT (rotate_label->priv->no_rotate_radio), + "toggled", + G_CALLBACK (toggled_cb), rotate_label); + g_signal_connect (G_OBJECT (rotate_label->priv->rotate_radio), + "toggled", + G_CALLBACK (toggled_cb), rotate_label); } static void @@ -154,68 +187,16 @@ gl_wdgt_rotate_label_new (void) rotate_label = g_object_new (gl_wdgt_rotate_label_get_type (), NULL); - gl_wdgt_rotate_label_construct (rotate_label); - return GTK_WIDGET (rotate_label); } -/*--------------------------------------------------------------------------*/ -/* Construct composite widget. */ -/*--------------------------------------------------------------------------*/ -static void -gl_wdgt_rotate_label_construct (glWdgtRotateLabel *rotate_label) -{ - GladeXML *gui; - GtkWidget *hbox; - - g_return_if_fail (GL_IS_WDGT_ROTATE_LABEL (rotate_label)); - g_return_if_fail (rotate_label->priv != NULL); - - gui = glade_xml_new (GLABELS_GLADE_DIR "wdgt-rotate-label.glade", - "rotate_hbox", NULL); - - if (!gui) { - g_critical ("Could not open wdgt-media-select.glade. gLabels may not be installed correctly!"); - return; - } - - hbox = glade_xml_get_widget (gui, "rotate_hbox"); - gtk_container_add (GTK_CONTAINER (rotate_label), hbox); - - rotate_label->priv->rotate_check = glade_xml_get_widget (gui, "rotate_check"); - rotate_label->priv->rotate_drawingarea = glade_xml_get_widget (gui, "rotate_drawingarea"); - - g_object_unref (gui); - - - gtk_widget_set_size_request (rotate_label->priv->rotate_drawingarea, - MINI_PREVIEW_CANVAS_PIXELS, - MINI_PREVIEW_CANVAS_PIXELS); - - /* Connect signals to controls */ - g_signal_connect (G_OBJECT (rotate_label->priv->rotate_check), - "toggled", - G_CALLBACK (entry_changed_cb), rotate_label); - g_signal_connect (G_OBJECT (rotate_label->priv->rotate_drawingarea), - "expose_event", - G_CALLBACK (expose_cb), rotate_label); -} - /*--------------------------------------------------------------------------*/ /* PRIVATE. modify widget due to change of check button */ /*--------------------------------------------------------------------------*/ static void -entry_changed_cb (GtkToggleButton *toggle, - gpointer user_data) +toggled_cb (GtkToggleButton *toggle, + gpointer user_data) { - glWdgtRotateLabel *rotate_label = GL_WDGT_ROTATE_LABEL (user_data); - - if (rotate_label->priv->template != NULL) { - /* Update mini_preview canvas & details with template */ - drawingarea_update (GTK_DRAWING_AREA (rotate_label->priv->rotate_drawingarea), - rotate_label->priv->template, - gtk_toggle_button_get_active (toggle)); - } /* Emit our "changed" signal */ g_signal_emit (G_OBJECT (user_data), @@ -226,28 +207,29 @@ entry_changed_cb (GtkToggleButton *toggle, /*--------------------------------------------------------------------------*/ /* PRIVATE. Update mini-preview from template . */ /*--------------------------------------------------------------------------*/ -static void -drawingarea_update (GtkDrawingArea *drawing_area, - lglTemplate *template, - gboolean rotate_flag) +static GdkPixbuf * +create_pixbuf (lglTemplate *template, + gboolean rotate_flag) { + GdkPixbuf *pixbuf; + cairo_surface_t *surface; const lglTemplateFrame *frame; gdouble m, m_canvas, w, h, scale; GtkStyle *style; - guint line_color, fill_color, shadow_color; cairo_t *cr; - if (!GTK_WIDGET_DRAWABLE (GTK_WIDGET (drawing_area))) - { - return; - } + /* Create pixbuf and cairo context. */ + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, MINI_PREVIEW_CANVAS_PIXELS, MINI_PREVIEW_CANVAS_PIXELS); + surface = cairo_image_surface_create_for_data (gdk_pixbuf_get_pixels (pixbuf), + CAIRO_FORMAT_RGB24, + gdk_pixbuf_get_width (pixbuf), + gdk_pixbuf_get_height (pixbuf), + gdk_pixbuf_get_rowstride (pixbuf)); - /* Clear surface */ - gdk_window_clear (GTK_WIDGET (drawing_area)->window); if (template == NULL) { - return; + return pixbuf; } frame = (lglTemplateFrame *)template->frames->data; @@ -264,21 +246,16 @@ drawingarea_update (GtkDrawingArea *drawing_area, scale = MINI_PREVIEW_MAX_PIXELS / m; m_canvas = MINI_PREVIEW_CANVAS_PIXELS / scale; - style = gtk_widget_get_style (GTK_WIDGET (drawing_area)); - - /* Adjust sensitivity (should the canvas be grayed?) */ - if (w != h) { - line_color = LINE_COLOR; - fill_color = FILL_COLOR; - } else { - line_color = gl_color_from_gdk_color (&style->text[GTK_STATE_INSENSITIVE]); - fill_color = gl_color_from_gdk_color (&style->base[GTK_STATE_INSENSITIVE]); - } - - shadow_color = gl_color_from_gdk_color (&style->bg[GTK_STATE_ACTIVE]); + cr = cairo_create (surface); + cairo_surface_destroy (surface); + /* Clear pixbuf */ + cairo_save (cr); + cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); + cairo_paint (cr); + cairo_restore (cr); - cr = gdk_cairo_create (GTK_WIDGET (drawing_area)->window); + cairo_set_antialias (cr, CAIRO_ANTIALIAS_GRAY); cairo_identity_matrix (cr); cairo_translate (cr, MINI_PREVIEW_CANVAS_PIXELS/2, MINI_PREVIEW_CANVAS_PIXELS/2); @@ -292,7 +269,7 @@ drawingarea_update (GtkDrawingArea *drawing_area, cairo_translate (cr, SHADOW_X_OFFSET/scale, SHADOW_Y_OFFSET/scale); gl_cairo_label_path (cr, template, rotate_flag, FALSE); - cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (shadow_color)); + cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (SHADOW_COLOR)); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_fill (cr); cairo_restore (cr); @@ -302,32 +279,18 @@ drawingarea_update (GtkDrawingArea *drawing_area, */ gl_cairo_label_path (cr, template, rotate_flag, FALSE); - cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (fill_color)); + cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (FILL_COLOR)); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_fill_preserve (cr); cairo_set_line_width (cr, LINE_WIDTH_PIXELS/scale); - cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (line_color)); + cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (LINE_COLOR)); cairo_stroke (cr); cairo_destroy (cr); -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. Expose handler. */ -/*--------------------------------------------------------------------------*/ -static gboolean -expose_cb (GtkWidget *drawingarea, GdkEventExpose *event, gpointer user_data) -{ - glWdgtRotateLabel *rotate_label = GL_WDGT_ROTATE_LABEL (user_data); - - drawingarea_update (GTK_DRAWING_AREA (drawingarea), - rotate_label->priv->template, - gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rotate_label->priv->rotate_check))); - - return FALSE; + return pixbuf; } /****************************************************************************/ @@ -338,7 +301,7 @@ gl_wdgt_rotate_label_get_state (glWdgtRotateLabel *rotate_label) { return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON - (rotate_label->priv->rotate_check)); + (rotate_label->priv->rotate_radio)); } /****************************************************************************/ @@ -349,7 +312,7 @@ gl_wdgt_rotate_label_set_state (glWdgtRotateLabel *rotate_label, gboolean state) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON - (rotate_label->priv->rotate_check), state); + (rotate_label->priv->rotate_radio), state); } /****************************************************************************/ @@ -367,12 +330,8 @@ gl_wdgt_rotate_label_set_template_name (glWdgtRotateLabel *rotate_label, { rotate_label->priv->template = NULL; - gtk_widget_set_sensitive (rotate_label->priv->rotate_check, - FALSE); - - drawingarea_update (GTK_DRAWING_AREA (rotate_label->priv->rotate_drawingarea), - NULL, - FALSE); + gtk_widget_set_sensitive (rotate_label->priv->no_rotate_radio, FALSE); + gtk_widget_set_sensitive (rotate_label->priv->rotate_radio, FALSE); } else { @@ -382,14 +341,22 @@ gl_wdgt_rotate_label_set_template_name (glWdgtRotateLabel *rotate_label, rotate_label->priv->template = template; lgl_template_frame_get_size (frame, &raw_w, &raw_h); - gtk_widget_set_sensitive (rotate_label->priv->rotate_check, + gtk_image_set_from_pixbuf (GTK_IMAGE (rotate_label->priv->no_rotate_image), + create_pixbuf (rotate_label->priv->template, FALSE)); + gtk_image_set_from_pixbuf (GTK_IMAGE (rotate_label->priv->rotate_image), + create_pixbuf (rotate_label->priv->template, TRUE)); + + gtk_widget_set_sensitive (rotate_label->priv->no_rotate_radio, + (raw_w != raw_h)); + gtk_widget_set_sensitive (rotate_label->priv->rotate_radio, (raw_w != raw_h)); - drawingarea_update (GTK_DRAWING_AREA (rotate_label->priv->rotate_drawingarea), - rotate_label->priv->template, - FALSE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (rotate_label->priv->no_rotate_radio), TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (rotate_label->priv->rotate_radio), FALSE); + } - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON - (rotate_label->priv->rotate_check), FALSE); + } diff --git a/glabels2/src/wdgt-rotate-label.h b/glabels2/src/wdgt-rotate-label.h index 3d8b412e..d3a0daca 100644 --- a/glabels2/src/wdgt-rotate-label.h +++ b/glabels2/src/wdgt-rotate-label.h @@ -25,7 +25,7 @@ #ifndef __WDGT_ROTATE_LABEL_H__ #define __WDGT_ROTATE_LABEL_H__ -#include +#include G_BEGIN_DECLS @@ -45,13 +45,13 @@ typedef struct _glWdgtRotateLabelClass glWdgtRotateLabelClass; typedef struct _glWdgtRotateLabelPrivate glWdgtRotateLabelPrivate; struct _glWdgtRotateLabel { - GtkVBox parent_widget; + GtkHBox parent_widget; glWdgtRotateLabelPrivate *priv; }; struct _glWdgtRotateLabelClass { - GtkVBoxClass parent_class; + GtkHBoxClass parent_class; void (*changed) (glWdgtRotateLabel *wdgt_rotate_label, gpointer user_data);