[gthumb: 3/129] rotate tool: added ability to set the background color



commit c6d46a03d3d2ad1bf978009db82015eccd401e92
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Wed Apr 13 17:06:45 2011 +0200

    rotate tool: added ability to set the background color

 extensions/file_tools/data/ui/rotate-options.ui |   22 ++-------
 extensions/file_tools/gth-file-tool-rotate.c    |   25 ++++++++-
 extensions/file_tools/gth-image-rotator.c       |   63 +++++++++++++++-------
 extensions/file_tools/gth-image-rotator.h       |   28 +++++-----
 4 files changed, 85 insertions(+), 53 deletions(-)
---
diff --git a/extensions/file_tools/data/ui/rotate-options.ui b/extensions/file_tools/data/ui/rotate-options.ui
index 152df48..58735c7 100644
--- a/extensions/file_tools/data/ui/rotate-options.ui
+++ b/extensions/file_tools/data/ui/rotate-options.ui
@@ -51,17 +51,6 @@
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkCheckButton" id="step_checkbutton">
-                            <property name="label" translatable="yes">5 degrees</property>
-                            <property name="can_focus">True</property>
-                            <property name="receives_default">False</property>
-                            <property name="draw_indicator">True</property>
-                          </object>
-                          <packing>
-                            <property name="position">2</property>
-                          </packing>
-                        </child>
-                        <child>
                           <object class="GtkHBox" id="small_angle_box">
                             <property name="visible">True</property>
                             <child>
@@ -69,7 +58,7 @@
                             </child>
                           </object>
                           <packing>
-                            <property name="position">3</property>
+                            <property name="position">2</property>
                           </packing>
                         </child>
                       </object>
@@ -262,6 +251,7 @@
                             <property name="row_spacing">6</property>
                             <child>
                               <object class="GtkLabel" id="label4">
+                                <property name="visible">True</property>
                                 <property name="xalign">0</property>
                                 <property name="label" translatable="yes">_Background:</property>
                                 <property name="use_underline">True</property>
@@ -300,11 +290,13 @@
                             </child>
                             <child>
                               <object class="GtkHBox" id="hbox3">
+                                <property name="visible">True</property>
                                 <child>
                                   <object class="GtkColorButton" id="background_colorbutton">
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
+                                    <property name="use_alpha">True</property>
                                     <property name="color">#000000000000</property>
                                   </object>
                                   <packing>
@@ -325,12 +317,6 @@
                             <property name="position">0</property>
                           </packing>
                         </child>
-                        <child>
-                          <placeholder/>
-                        </child>
-                        <child>
-                          <placeholder/>
-                        </child>
                       </object>
                     </child>
                   </object>
diff --git a/extensions/file_tools/gth-file-tool-rotate.c b/extensions/file_tools/gth-file-tool-rotate.c
index caa57ed..e923f73 100644
--- a/extensions/file_tools/gth-file-tool-rotate.c
+++ b/extensions/file_tools/gth-file-tool-rotate.c
@@ -277,6 +277,22 @@ size_combobox_changed_cb (GtkComboBox *combo_box,
 }
 
 
+static void
+background_colorbutton_notify_color_cb (GObject    *gobject,
+					GParamSpec *pspec,
+					gpointer    user_data)
+{
+	GthFileToolRotate *self = user_data;
+	GdkColor           gdk_color;
+	cairo_color_t      color;
+
+	gtk_color_button_get_color (GTK_COLOR_BUTTON (gobject), &gdk_color);
+	_gdk_color_to_cairo_color (&gdk_color, &color);
+	color.a = (double) gtk_color_button_get_alpha (GTK_COLOR_BUTTON (gobject)) / 255.0;
+	gth_image_rotator_set_background (self->priv->rotator, &color);
+}
+
+
 static GtkWidget *
 gth_file_tool_rotate_get_options (GthFileTool *base)
 {
@@ -375,10 +391,10 @@ gth_file_tool_rotate_get_options (GthFileTool *base)
 			  "value-changed",
 			  G_CALLBACK (small_angle_value_changed_cb),
 			  self);
-	g_signal_connect (GET_WIDGET ("step_checkbutton"),
+	/*g_signal_connect (GET_WIDGET ("step_checkbutton"),
 			  "toggled",
 			  G_CALLBACK (step_checkbutton_toggled_cb),
-			  self);
+			  self);*/
 	g_signal_connect (G_OBJECT (self->priv->grid_adj),
 			  "value-changed",
 			  G_CALLBACK (grid_value_changed_cb),
@@ -391,6 +407,11 @@ gth_file_tool_rotate_get_options (GthFileTool *base)
 			  "changed",
 			  G_CALLBACK (size_combobox_changed_cb),
 			  self);
+	g_signal_connect (GET_WIDGET ("background_colorbutton"),
+			  "notify::color",
+			  G_CALLBACK (background_colorbutton_notify_color_cb),
+			  self);
+
 
 	self->priv->rotator = (GthImageRotator *) gth_image_rotator_new (GTH_IMAGE_VIEWER (viewer));
 	gth_image_rotator_set_grid (self->priv->rotator, FALSE, DEFAULT_GRID);
diff --git a/extensions/file_tools/gth-image-rotator.c b/extensions/file_tools/gth-image-rotator.c
index 95667e1..af1d66b 100644
--- a/extensions/file_tools/gth-image-rotator.c
+++ b/extensions/file_tools/gth-image-rotator.c
@@ -37,18 +37,24 @@ static gpointer parent_class = NULL;
 
 struct _GthImageRotatorPrivate {
 	GthImageViewer     *viewer;
+
+	/* options */
+
+	GdkPoint            center;
+	double              angle;
+	gboolean            paint_grid;
+	int                 grid_lines;
+	GthTransformResize  resize;
+	cairo_color_t       background_color;
+
+	/* utility variables */
+
 	int                 original_width;
 	int                 original_height;
 	cairo_surface_t    *image;
 	GdkRectangle        image_area;
 	GdkRectangle        clip_area;
-	GdkRectangle        inner_area;
-	GdkPoint            center;
-	double              angle;
 	gboolean            paint_image;
-	gboolean            paint_grid;
-	int                 grid_lines;
-	GthTransformResize  resize;
 	cairo_matrix_t      matrix;
 };
 
@@ -56,16 +62,14 @@ struct _GthImageRotatorPrivate {
 static void
 gth_image_rotator_realize (GthImageViewerTool *base)
 {
-	/* GthImageRotator *self = GTH_IMAGE_ROTATOR (base);
-	FIXME */
+	/* void */
 }
 
 
 static void
 gth_image_rotator_unrealize (GthImageViewerTool *base)
 {
-	/* GthImageRotator *self = GTH_IMAGE_ROTATOR (base);
-	FIXME */
+	/* void */
 }
 
 
@@ -293,11 +297,7 @@ gth_image_rotator_expose (GthImageViewerTool *base,
 	style = gtk_widget_get_style (GTK_WIDGET (self->priv->viewer));
 	gtk_widget_get_allocation (GTK_WIDGET (self->priv->viewer), &allocation);
 	gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]);
-	cairo_rectangle (cr,
-			 0,
-			 0,
-			 allocation.width,
-			 allocation.height);
+	cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
 	cairo_fill (cr);
 
 	/* clip box */
@@ -308,7 +308,11 @@ gth_image_rotator_expose (GthImageViewerTool *base,
   			 self->priv->clip_area.width,
   			 self->priv->clip_area.height);
   	cairo_clip_preserve (cr);
-  	cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+  	cairo_set_source_rgba (cr,
+  			       self->priv->background_color.r,
+  			       self->priv->background_color.g,
+  			       self->priv->background_color.b,
+  			       self->priv->background_color.a);
   	cairo_fill (cr);
 
   	/* image */
@@ -327,7 +331,7 @@ gth_image_rotator_expose (GthImageViewerTool *base,
 	if (self->priv->paint_grid)
 		paint_grid (self, event, cr);
 
-	paint_center (self, event, cr);
+	/* paint_center (self, event, cr); FIXME */
 
 	cairo_restore (cr);
 }
@@ -386,6 +390,10 @@ gth_image_rotator_instance_init (GthImageRotator *self)
 	self->priv->paint_grid = FALSE;
 	self->priv->grid_lines = 0;
 	self->priv->resize = GTH_TRANSFORM_RESIZE_CLIP;
+	self->priv->background_color.r = 0.0;
+	self->priv->background_color.g = 0.0;
+	self->priv->background_color.b = 0.0;
+	self->priv->background_color.a = 1.0;
 }
 
 
@@ -548,6 +556,17 @@ gth_image_rotator_set_resize (GthImageRotator    *self,
 }
 
 
+void
+gth_image_rotator_set_background (GthImageRotator *self,
+			          cairo_color_t   *color)
+{
+	self->priv->background_color = *color;
+	gtk_widget_queue_draw (GTK_WIDGET (self->priv->viewer));
+
+	g_signal_emit (self, signals[CHANGED], 0);
+}
+
+
 GdkPixbuf *
 gth_image_rotator_get_result (GthImageRotator *self)
 {
@@ -564,8 +583,8 @@ gth_image_rotator_get_result (GthImageRotator *self)
 
 	/* compute the transformation matrix and the clip area */
 
-	tx = self->priv->original_width / 2.0; /* FIXME */
-	ty = self->priv->original_height / 2.0;
+	tx = self->priv->original_width * 0.5;
+	ty = self->priv->original_height * 0.5;
 	cairo_matrix_init_identity (&matrix);
 	cairo_matrix_translate (&matrix, tx, ty);
 	cairo_matrix_rotate (&matrix, self->priv->angle);
@@ -593,7 +612,11 @@ gth_image_rotator_get_result (GthImageRotator *self)
 
   	cairo_rectangle (cr, clip_area.x, clip_area.y, clip_area.width, clip_area.height);
   	cairo_clip_preserve (cr);
-  	cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* FIXME: use the background color */
+  	cairo_set_source_rgba (cr,
+  			       self->priv->background_color.r,
+  			       self->priv->background_color.g,
+  			       self->priv->background_color.b,
+  			       self->priv->background_color.a);
   	cairo_fill (cr);
 
   	/* paint the rotated image */
diff --git a/extensions/file_tools/gth-image-rotator.h b/extensions/file_tools/gth-image-rotator.h
index 34bd40d..25c7a7e 100644
--- a/extensions/file_tools/gth-image-rotator.h
+++ b/extensions/file_tools/gth-image-rotator.h
@@ -55,19 +55,21 @@ struct _GthImageRotatorClass
 	void (* changed) (GthImageRotator *rotator);
 };
 
-GType                 gth_image_rotator_get_type    (void);
-GthImageViewerTool *  gth_image_rotator_new         (GthImageViewer     *viewer);
-void                  gth_image_rotator_set_center  (GthImageRotator    *rotator,
-						     int                 x,
-						     int                 y);
-void                  gth_image_rotator_set_angle   (GthImageRotator    *rotator,
-						     double              angle);
-void                  gth_image_rotator_set_grid    (GthImageRotator    *self,
-						     gboolean            use_grid,
-						     int                 lines);
-void                  gth_image_rotator_set_resize  (GthImageRotator    *self,
-						     GthTransformResize  resize);
-GdkPixbuf *           gth_image_rotator_get_result  (GthImageRotator    *self);
+GType                 gth_image_rotator_get_type        (void);
+GthImageViewerTool *  gth_image_rotator_new             (GthImageViewer     *viewer);
+void                  gth_image_rotator_set_center      (GthImageRotator    *rotator,
+						         int                 x,
+						         int                 y);
+void                  gth_image_rotator_set_angle       (GthImageRotator    *rotator,
+						         double              angle);
+void                  gth_image_rotator_set_grid        (GthImageRotator    *self,
+						         gboolean            use_grid,
+						         int                 lines);
+void                  gth_image_rotator_set_resize      (GthImageRotator    *self,
+						         GthTransformResize  resize);
+void                  gth_image_rotator_set_background  (GthImageRotator    *self,
+							 cairo_color_t      *color);
+GdkPixbuf *           gth_image_rotator_get_result      (GthImageRotator    *self);
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]