]> git.sur5r.net Git - glabels/commitdiff
2008-04-07 Jim Evins <evins@snaught.com>
authorJim Evins <evins@snaught.com>
Tue, 8 Apr 2008 02:04:10 +0000 (02:04 +0000)
committerJim Evins <evins@snaught.com>
Tue, 8 Apr 2008 02:04:10 +0000 (02:04 +0000)
* 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

glabels2/ChangeLog
glabels2/data/glade/Makefile.am
glabels2/data/glade/wdgt-rotate-label.glade [deleted file]
glabels2/src/wdgt-rotate-label.c
glabels2/src/wdgt-rotate-label.h

index 2bf67cb0203949b6f55df3c48d6b123dc43850a2..8cfcdece43d0dca672ca5f2e6a093049ae4b70d8 100644 (file)
@@ -1,3 +1,15 @@
+2008-04-07  Jim Evins  <evins@snaught.com>
+
+       * 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  <evins@snaught.com>
 
        * data/templates/brother-other-templates.xml:
index 4747c88fb5602d7dc83ac52b2e1e9a991ca11685..fdccb1cb11bb659567ff915148bca94a77980576 100644 (file)
@@ -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 (file)
index 89e24a0..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
-<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
-
-<glade-interface>
-
-<widget class="GtkWindow" id="window1">
-  <property name="visible">True</property>
-  <property name="title" translatable="yes">window1</property>
-  <property name="type">GTK_WINDOW_TOPLEVEL</property>
-  <property name="window_position">GTK_WIN_POS_NONE</property>
-  <property name="modal">False</property>
-  <property name="resizable">True</property>
-  <property name="destroy_with_parent">False</property>
-  <property name="decorated">True</property>
-  <property name="skip_taskbar_hint">False</property>
-  <property name="skip_pager_hint">False</property>
-  <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
-  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
-  <property name="focus_on_map">True</property>
-  <property name="urgency_hint">False</property>
-
-  <child>
-    <widget class="GtkHBox" id="rotate_hbox">
-      <property name="border_width">12</property>
-      <property name="visible">True</property>
-      <property name="homogeneous">False</property>
-      <property name="spacing">6</property>
-
-      <child>
-       <widget class="GtkCheckButton" id="rotate_check">
-         <property name="visible">True</property>
-         <property name="can_focus">True</property>
-         <property name="label" translatable="yes">Rotate</property>
-         <property name="use_underline">True</property>
-         <property name="relief">GTK_RELIEF_NORMAL</property>
-         <property name="focus_on_click">True</property>
-         <property name="active">False</property>
-         <property name="inconsistent">False</property>
-         <property name="draw_indicator">True</property>
-       </widget>
-       <packing>
-         <property name="padding">0</property>
-         <property name="expand">False</property>
-         <property name="fill">False</property>
-       </packing>
-      </child>
-
-      <child>
-       <widget class="GtkDrawingArea" id="rotate_drawingarea">
-         <property name="visible">True</property>
-       </widget>
-       <packing>
-         <property name="padding">0</property>
-         <property name="expand">True</property>
-         <property name="fill">True</property>
-       </packing>
-      </child>
-    </widget>
-  </child>
-</widget>
-
-</glade-interface>
index 4edca601f1ef16182ec882462e12a6cfd6048f50..993eab20f780317f2add8001ea77a0eaa43a3e5c 100644 (file)
 #include "wdgt-rotate-label.h"
 
 #include <glib/gi18n.h>
-#include <glade/glade-xml.h>
-#include <gtk/gtktogglebutton.h>
-#include <gtk/gtkcheckbutton.h>
+#include <gtk/gtkradiobutton.h>
 #include <gtk/gtkdrawingarea.h>
 #include <math.h>
 
 #include "marshal.h"
 #include "color.h"
+#include "hig.h"
 #include <libglabels/db.h>
 #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
 
 
 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);
+
 }
 
index 3d8b412edba4514f956452686ab6195f781b5d2e..d3a0dacab605347a11fb26b135d660c682ffb93a 100644 (file)
@@ -25,7 +25,7 @@
 #ifndef __WDGT_ROTATE_LABEL_H__
 #define __WDGT_ROTATE_LABEL_H__
 
-#include <gtk/gtkvbox.h>
+#include <gtk/gtkhbox.h>
 
 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);