[glade] gladeui/glade-app.c: glade_app_register_stock_icons() added fuction to register glade icons



commit 8beec9cd7d5ec72427ff5d101ae2b2c1158cbef6
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date:   Wed Apr 25 13:05:17 2012 -0300

    gladeui/glade-app.c: glade_app_register_stock_icons() added fuction to register glade icons
    
    gladeui/glade-project.[ch]: removed glade_project_pointer_mode_render_icon()
    
    gladeui/glade-utils.c: added glade_utils_pointer_mode_render_icon()

 gladeui/glade-app.c     |   42 +++++++++++
 gladeui/glade-project.c |  189 -----------------------------------------------
 gladeui/glade-project.h |    2 -
 gladeui/glade-utils.c   |  187 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 229 insertions(+), 191 deletions(-)
---
diff --git a/gladeui/glade-app.c b/gladeui/glade-app.c
index 3f906fb..78b5061 100644
--- a/gladeui/glade-app.c
+++ b/gladeui/glade-app.c
@@ -264,6 +264,45 @@ glade_init_check (void)
 }
 
 static void
+pointer_mode_register_icon (GtkIconFactory *factory,
+                            const gchar *icon_name,
+                            GladePointerMode mode,
+                            GtkIconSize size)
+{
+  GdkPixbuf *pixbuf;
+  GtkIconSet *icon_set;
+
+  pixbuf = glade_utils_pointer_mode_render_icon (mode, size);
+  if (pixbuf)
+    {
+      GtkIconSet *icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
+      gtk_icon_factory_add (factory, icon_name, icon_set);
+      g_object_unref (pixbuf);
+    }
+}
+
+/*
+ * glade_app_register_stock_icons:
+ * @size: icon size
+ *
+ * Register a new stock icon for most of GladePointerMode.
+ * After calling this function "glade-selector", "glade-drag-resize",
+ * "glade-margin-edit" and "glade-align-edit" stock icons will be available.
+ */ 
+static void
+glade_app_register_stock_icons (GtkIconSize size)
+{
+  GtkIconFactory *factory = gtk_icon_factory_new ();
+
+  pointer_mode_register_icon (factory, "glade-selector", GLADE_POINTER_SELECT, size);
+  pointer_mode_register_icon (factory, "glade-drag-resize", GLADE_POINTER_DRAG_RESIZE, size);
+  pointer_mode_register_icon (factory, "glade-margin-edit", GLADE_POINTER_MARGIN_EDIT, size);
+  pointer_mode_register_icon (factory, "glade-align-edit", GLADE_POINTER_ALIGN_EDIT, size);
+
+  gtk_icon_factory_add_default (factory);
+}
+
+static void
 glade_app_init (GladeApp * app)
 {
   static gboolean initialized = FALSE;
@@ -282,6 +321,9 @@ glade_app_init (GladeApp * app)
 
       glade_cursor_init ();
 
+      /* Register icons needed by the UI */
+      glade_app_register_stock_icons (GTK_ICON_SIZE_LARGE_TOOLBAR);
+
       initialized = TRUE;
     }
 
diff --git a/gladeui/glade-project.c b/gladeui/glade-project.c
index 9dea0a7..fff3595 100644
--- a/gladeui/glade-project.c
+++ b/gladeui/glade-project.c
@@ -2809,195 +2809,6 @@ glade_project_check_reordered (GladeProject *project,
   g_list_free (new_order);
 }
 
-static void
-draw_tip (cairo_t *cr)
-{
-  cairo_line_to (cr, 2, 8);
-  cairo_line_to (cr, 2, 4);
-  cairo_line_to (cr, 0, 4);
-  cairo_line_to (cr, 0, 3);
-  cairo_line_to (cr, 3, 0);
-  cairo_line_to (cr, 6, 3);
-  cairo_line_to (cr, 6, 4);
-  cairo_line_to (cr, 4, 4);
-
-  cairo_translate (cr, 12, 6);
-  cairo_rotate (cr, G_PI_2);
-}
-
-static void
-draw_tips (cairo_t *cr)
-{
-  cairo_move_to (cr, 2, 8);
-  draw_tip (cr); draw_tip (cr); draw_tip (cr); draw_tip (cr);
-  cairo_close_path (cr);
-}
-
-static void
-draw_pointer (cairo_t *cr)
-{
-  cairo_line_to (cr, 8, 3);
-  cairo_line_to (cr, 19, 14);
-  cairo_line_to (cr, 13.75, 14);
-  cairo_line_to (cr, 16.5, 19);
-  cairo_line_to (cr, 14, 21);
-  cairo_line_to (cr, 11, 16);
-  cairo_line_to (cr, 7, 19);
-  cairo_line_to (cr, 7, 3);
-  cairo_line_to (cr, 8, 3);
-}
-
-/* Needed for private draw functions! */
-#include "glade-design-private.h"
-
-/**
- * glade_project_pointer_mode_render_icon:
- * @mode: the #GladePointerMode to render as icon
- * @size: icon size
- *
- * Render an icon representing the pointer mode.
- * Best view with sizes bigger than GTK_ICON_SIZE_LARGE_TOOLBAR.
- */ 
-GdkPixbuf *
-glade_project_pointer_mode_render_icon (GladePointerMode mode, GtkIconSize size)
-{
-  GtkStyleContext *ctx = gtk_style_context_new ();
-  GdkRGBA c1, c2, c3, fg, bg;
-  cairo_surface_t *surface;
-  GtkWidgetPath *path;
-  gint width, height;
-  GdkPixbuf *pix;
-  cairo_t *cr;
-
-  if (gtk_icon_size_lookup (size, &width, &height) == FALSE) return NULL;
-
-  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
-  cr = cairo_create (surface);
-  cairo_scale (cr, width/24.0, height/24.0);
-
-  /* Get Style context */
-  path = gtk_widget_path_new ();
-  gtk_widget_path_append_type (path, GTK_TYPE_WIDGET);
-  gtk_style_context_set_path (ctx, path);
-  gtk_widget_path_free (path);
-
-  /* Now get colors */
-  gtk_style_context_get_color (ctx, GTK_STATE_FLAG_NORMAL, &fg);
-  gtk_style_context_get_background_color (ctx, GTK_STATE_FLAG_NORMAL, &bg);
-  
-  gtk_style_context_add_class (ctx, GTK_STYLE_CLASS_VIEW);
-  gtk_style_context_get_background_color (ctx, GTK_STATE_FLAG_SELECTED | GTK_STATE_FLAG_FOCUSED, &c1);
-  gtk_style_context_get_color (ctx, GTK_STATE_FLAG_SELECTED | GTK_STATE_FLAG_FOCUSED, &c2);
-  gtk_style_context_get_background_color (ctx, GTK_STATE_FLAG_SELECTED, &c3);
-
-  g_object_unref (ctx);
-
-  /* Clear surface */
-  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
-  cairo_fill(cr);
-  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
-
-  switch (mode)
-    {
-      case GLADE_POINTER_SELECT:
-      case GLADE_POINTER_ADD_WIDGET:
-        cairo_set_line_width (cr, 1);
-        cairo_translate (cr, 1.5, 1.5);
-        draw_pointer (cr);
-        fg.alpha = .16;
-        gdk_cairo_set_source_rgba (cr, &fg);
-        cairo_stroke (cr);
-
-        cairo_translate (cr, -1, -1);
-        draw_pointer (cr);
-        gdk_cairo_set_source_rgba (cr, &c2);
-        cairo_fill_preserve (cr);
-      
-        fg.alpha = .64;
-        gdk_cairo_set_source_rgba (cr, &fg);
-        cairo_stroke (cr);
-      break;
-      case GLADE_POINTER_DRAG_RESIZE:
-        cairo_set_line_width (cr, 1);
-        cairo_translate (cr, 10.5, 3.5);
-        
-        draw_tips (cr);
-
-        fg.alpha = .16;
-        gdk_cairo_set_source_rgba (cr, &fg);
-        cairo_stroke (cr);
-
-        cairo_translate (cr, -1, -1);
-        draw_tips (cr);
-        
-        gdk_cairo_set_source_rgba (cr, &c2);
-        cairo_fill_preserve (cr);
-        
-        c1.red = MAX (0, c1.red - .1);
-        c1.green = MAX (0, c1.green - .1);
-        c1.blue = MAX (0, c1.blue - .1);
-        gdk_cairo_set_source_rgba (cr, &c1);
-        cairo_stroke (cr);
-      break;
-      case GLADE_POINTER_MARGIN_EDIT:
-        {
-          gdk_cairo_set_source_rgba (cr, &bg);
-          cairo_rectangle (cr, 4, 4, 18, 18);
-          cairo_fill (cr);
-
-          c1.alpha = .1;
-          gdk_cairo_set_source_rgba (cr, &c1);
-          cairo_rectangle (cr, 6, 6, 16, 16);
-          cairo_fill (cr);
-
-          cairo_set_line_width (cr, 1);
-          fg.alpha = .32;
-          gdk_cairo_set_source_rgba (cr, &fg);
-          cairo_move_to (cr, 16.5, 22);
-          cairo_line_to (cr, 16.5, 16.5);
-          cairo_line_to (cr, 22, 16.5);
-          cairo_stroke (cr);
-
-          c1.alpha = .16;
-          gdk_cairo_set_source_rgba (cr, &c1);
-          cairo_rectangle (cr, 16, 16, 6, 6);
-          cairo_fill (cr);
-
-          cairo_set_line_width (cr, 2);
-          c1.alpha = .75;
-          gdk_cairo_set_source_rgba (cr, &c1);
-          cairo_move_to (cr, 6, 22);
-          cairo_line_to (cr, 6, 6);
-          cairo_line_to (cr, 22, 6);
-          cairo_stroke (cr);
-
-          c1.alpha = 1;
-          cairo_scale (cr, .75, .75);
-          cairo_set_line_width (cr, 4);
-          _glade_design_layout_draw_node (cr, 16*1.25, 6*1.25, &c1, &c2);
-          _glade_design_layout_draw_node (cr, 6*1.25, 16*1.25, &c1, &c2);
-        }
-      break;
-      case GLADE_POINTER_ALIGN_EDIT:
-        cairo_scale (cr, 1.5, 1.5);
-        cairo_rotate (cr, 45*(G_PI/180));
-        cairo_translate (cr, 11, 2);
-        _glade_design_layout_draw_pushpin (cr, 2.5, &c1, &c2, &c2, &fg);
-      break;
-      default:
-      break;
-    }
-
-  pix = gdk_pixbuf_get_from_surface (surface, 0, 0,
-                                     cairo_image_surface_get_width (surface),
-                                     cairo_image_surface_get_height (surface));
-
-  cairo_surface_destroy (surface);
-  cairo_destroy (cr);
-
-  return pix;
-}
-
 static inline gboolean
 glade_project_has_gwidget (GladeProject *project, GladeWidget *gwidget)
 {
diff --git a/gladeui/glade-project.h b/gladeui/glade-project.h
index a838a36..10de7e1 100644
--- a/gladeui/glade-project.h
+++ b/gladeui/glade-project.h
@@ -140,8 +140,6 @@ void                glade_project_check_reordered      (GladeProject       *proj
                                                         GladeWidget        *parent,
                                                         GList              *old_order);
 
-GdkPixbuf          *glade_project_pointer_mode_render_icon (GladePointerMode mode,
-                                                            GtkIconSize size);
 /* Commands */
 void                glade_project_undo                 (GladeProject       *project);
 void                glade_project_redo                 (GladeProject       *project);
diff --git a/gladeui/glade-utils.c b/gladeui/glade-utils.c
index 140854d..f0f147f 100644
--- a/gladeui/glade-utils.c
+++ b/gladeui/glade-utils.c
@@ -1747,3 +1747,190 @@ glade_utils_replace_home_dir_with_tilde (const gchar * path)
   return g_strdup (path);
 #endif
 }
+
+static void
+draw_tip (cairo_t *cr)
+{
+  cairo_line_to (cr, 2, 8);
+  cairo_line_to (cr, 2, 4);
+  cairo_line_to (cr, 0, 4);
+  cairo_line_to (cr, 0, 3);
+  cairo_line_to (cr, 3, 0);
+  cairo_line_to (cr, 6, 3);
+  cairo_line_to (cr, 6, 4);
+  cairo_line_to (cr, 4, 4);
+
+  cairo_translate (cr, 12, 6);
+  cairo_rotate (cr, G_PI_2);
+}
+
+static void
+draw_tips (cairo_t *cr)
+{
+  cairo_move_to (cr, 2, 8);
+  draw_tip (cr); draw_tip (cr); draw_tip (cr); draw_tip (cr);
+  cairo_close_path (cr);
+}
+
+static void
+draw_pointer (cairo_t *cr)
+{
+  cairo_line_to (cr, 8, 3);
+  cairo_line_to (cr, 19, 14);
+  cairo_line_to (cr, 13.75, 14);
+  cairo_line_to (cr, 16.5, 19);
+  cairo_line_to (cr, 14, 21);
+  cairo_line_to (cr, 11, 16);
+  cairo_line_to (cr, 7, 19);
+  cairo_line_to (cr, 7, 3);
+  cairo_line_to (cr, 8, 3);
+}
+
+/* Needed for private draw functions! */
+#include "glade-design-private.h"
+
+/**
+ * glade_utils_pointer_mode_render_icon:
+ * @mode: the #GladePointerMode to render as icon
+ * @size: icon size
+ *
+ * Render an icon representing the pointer mode.
+ * Best view with sizes bigger than GTK_ICON_SIZE_LARGE_TOOLBAR.
+ */ 
+GdkPixbuf *
+glade_utils_pointer_mode_render_icon (GladePointerMode mode, GtkIconSize size)
+{
+  GtkStyleContext *ctx = gtk_style_context_new ();
+  GdkRGBA c1, c2, c3, fg, bg;
+  cairo_surface_t *surface;
+  GtkWidgetPath *path;
+  gint width, height;
+  GdkPixbuf *pix;
+  cairo_t *cr;
+
+  if (gtk_icon_size_lookup (size, &width, &height) == FALSE) return NULL;
+
+  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
+  cr = cairo_create (surface);
+  cairo_scale (cr, width/24.0, height/24.0);
+
+  /* Get Style context */
+  path = gtk_widget_path_new ();
+  gtk_widget_path_append_type (path, GTK_TYPE_WIDGET);
+  gtk_style_context_set_path (ctx, path);
+  gtk_widget_path_free (path);
+
+  /* Now get colors */
+  gtk_style_context_lookup_color (ctx, "fg_color", &fg);
+  gtk_style_context_lookup_color (ctx, "bg_color", &bg);
+  gtk_style_context_lookup_color (ctx, "selected_bg_color", &c1);
+  gtk_style_context_lookup_color (ctx, "selected_fg_color", &c2);
+  gtk_style_context_lookup_color (ctx, "base_color", &c3);
+  
+  g_object_unref (ctx);
+
+  /* Clear surface */
+  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
+  cairo_fill(cr);
+  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+
+  switch (mode)
+    {
+      case GLADE_POINTER_SELECT:
+      case GLADE_POINTER_ADD_WIDGET:
+        cairo_set_line_width (cr, 1);
+        cairo_translate (cr, 1.5, 1.5);
+        draw_pointer (cr);
+        fg.alpha = .16;
+        gdk_cairo_set_source_rgba (cr, &fg);
+        cairo_stroke (cr);
+
+        cairo_translate (cr, -1, -1);
+        draw_pointer (cr);
+        gdk_cairo_set_source_rgba (cr, &c2);
+        cairo_fill_preserve (cr);
+      
+        fg.alpha = .64;
+        gdk_cairo_set_source_rgba (cr, &fg);
+        cairo_stroke (cr);
+      break;
+      case GLADE_POINTER_DRAG_RESIZE:
+        cairo_set_line_width (cr, 1);
+        cairo_translate (cr, 10.5, 3.5);
+        
+        draw_tips (cr);
+
+        fg.alpha = .16;
+        gdk_cairo_set_source_rgba (cr, &fg);
+        cairo_stroke (cr);
+
+        cairo_translate (cr, -1, -1);
+        draw_tips (cr);
+        
+        gdk_cairo_set_source_rgba (cr, &c2);
+        cairo_fill_preserve (cr);
+        
+        c1.red = MAX (0, c1.red - .1);
+        c1.green = MAX (0, c1.green - .1);
+        c1.blue = MAX (0, c1.blue - .1);
+        gdk_cairo_set_source_rgba (cr, &c1);
+        cairo_stroke (cr);
+      break;
+      case GLADE_POINTER_MARGIN_EDIT:
+        {
+          gdk_cairo_set_source_rgba (cr, &bg);
+          cairo_rectangle (cr, 4, 4, 18, 18);
+          cairo_fill (cr);
+
+          c1.alpha = .1;
+          gdk_cairo_set_source_rgba (cr, &c1);
+          cairo_rectangle (cr, 6, 6, 16, 16);
+          cairo_fill (cr);
+
+          cairo_set_line_width (cr, 1);
+          fg.alpha = .32;
+          gdk_cairo_set_source_rgba (cr, &fg);
+          cairo_move_to (cr, 16.5, 22);
+          cairo_line_to (cr, 16.5, 16.5);
+          cairo_line_to (cr, 22, 16.5);
+          cairo_stroke (cr);
+
+          c1.alpha = .16;
+          gdk_cairo_set_source_rgba (cr, &c1);
+          cairo_rectangle (cr, 16, 16, 6, 6);
+          cairo_fill (cr);
+
+          cairo_set_line_width (cr, 2);
+          c1.alpha = .75;
+          gdk_cairo_set_source_rgba (cr, &c1);
+          cairo_move_to (cr, 6, 22);
+          cairo_line_to (cr, 6, 6);
+          cairo_line_to (cr, 22, 6);
+          cairo_stroke (cr);
+
+          c1.alpha = 1;
+          cairo_scale (cr, .75, .75);
+          cairo_set_line_width (cr, 4);
+          _glade_design_layout_draw_node (cr, 16*1.25, 6*1.25, &c1, &c2);
+          _glade_design_layout_draw_node (cr, 6*1.25, 16*1.25, &c1, &c2);
+        }
+      break;
+      case GLADE_POINTER_ALIGN_EDIT:
+        cairo_scale (cr, 1.5, 1.5);
+        cairo_rotate (cr, 45*(G_PI/180));
+        cairo_translate (cr, 11, 2);
+        _glade_design_layout_draw_pushpin (cr, 2.5, &c1, &c2, &c2, &fg);
+      break;
+      default:
+      break;
+    }
+
+  pix = gdk_pixbuf_get_from_surface (surface, 0, 0,
+                                     cairo_image_surface_get_width (surface),
+                                     cairo_image_surface_get_height (surface));
+
+  cairo_surface_destroy (surface);
+  cairo_destroy (cr);
+
+  return pix;
+}



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