[glide] Add basic theme preview rendering



commit fda163b38f80af9de4fdedb9ba1016bdc97724d3
Author: Robert Carr <racarr Valentine localdomain>
Date:   Tue May 25 15:23:58 2010 -0400

    Add basic theme preview rendering

 libglide/glide-theme-chooser-priv.h |    2 ++
 libglide/glide-theme-chooser.c      |   32 ++++++++++++++++++++++++++++++++
 libglide/glide-theme-preview.c      |    6 ++++++
 libglide/glide-theme.c              |   23 +++++++++++++++++++++++
 libglide/glide-theme.h              |    3 +++
 5 files changed, 66 insertions(+), 0 deletions(-)
---
diff --git a/libglide/glide-theme-chooser-priv.h b/libglide/glide-theme-chooser-priv.h
index 391fc90..c7b1164 100644
--- a/libglide/glide-theme-chooser-priv.h
+++ b/libglide/glide-theme-chooser-priv.h
@@ -27,6 +27,8 @@ G_BEGIN_DECLS
 struct _GlideThemeChooserPrivate
 {
   GList *themes;
+  
+  GtkWidget *preview;
 };
 
 G_END_DECLS
diff --git a/libglide/glide-theme-chooser.c b/libglide/glide-theme-chooser.c
index 91179a4..cf93828 100644
--- a/libglide/glide-theme-chooser.c
+++ b/libglide/glide-theme-chooser.c
@@ -76,6 +76,34 @@ glide_theme_chooser_set_property (GObject *object,
     }
 }
 
+static void
+glide_theme_chooser_cursor_changed (GtkTreeView *tree_view, 
+				    gpointer user_data)
+{
+  GlideThemeChooser *chooser = (GlideThemeChooser *)user_data;
+  GtkTreePath *path;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  
+  gtk_tree_view_get_cursor (tree_view, &path, NULL);
+  model = gtk_tree_view_get_model (tree_view);
+  
+  if (gtk_tree_model_get_iter (model, &iter, path))
+    {
+      GlideTheme *theme;
+      gchar *name;
+      
+      gtk_tree_model_get (model, &iter, 0, &name, -1);
+      
+      theme = glide_theme_manager_get_theme (name);
+      glide_theme_preview_set_theme (GLIDE_THEME_PREVIEW (chooser->priv->preview), theme);
+      g_free (name);
+
+      GLIDE_NOTE(THEME_CHOOSER, "Theme selected: %s", name);
+    }
+  
+}
+
 static GtkListStore *
 glide_theme_chooser_get_list_store (GlideThemeChooser *chooser)
 {
@@ -110,6 +138,8 @@ glide_theme_chooser_make_treeview (GlideThemeChooser *chooser)
   
   gtk_tree_view_set_model (GTK_TREE_VIEW (ret), GTK_TREE_MODEL (glide_theme_chooser_get_list_store (chooser)));
   
+  g_signal_connect (ret, "cursor-changed", G_CALLBACK (glide_theme_chooser_cursor_changed), chooser);
+  
   return ret;
 }
 
@@ -122,6 +152,8 @@ glide_theme_chooser_make_main_hbox (GlideThemeChooser *chooser)
   tree_view = glide_theme_chooser_make_treeview (chooser);
   preview = glide_theme_preview_new ();
   
+  chooser->priv->preview = preview;
+  
   gtk_widget_set_size_request (preview, 200, 200);
   
   gtk_box_pack_start (GTK_BOX (ret), tree_view, FALSE, 0, 0);
diff --git a/libglide/glide-theme-preview.c b/libglide/glide-theme-preview.c
index 8c78745..b44e32e 100644
--- a/libglide/glide-theme-preview.c
+++ b/libglide/glide-theme-preview.c
@@ -42,11 +42,17 @@ static gboolean
 glide_theme_preview_expose_event (GtkWidget *widget,
 				  GdkEventExpose *event)
 {
+  GlideThemePreview *preview = (GlideThemePreview *)widget;
+  GtkAllocation alloc;
   cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget));
   
   cairo_set_source_rgba (cr, 0, 0, 0, 1);
   cairo_paint (cr);
   
+  gtk_widget_get_allocation (widget, &alloc);
+
+  glide_theme_preview (preview->priv->theme, cr, alloc.width, alloc.height);
+  
   cairo_destroy (cr);
   
   return FALSE;
diff --git a/libglide/glide-theme.c b/libglide/glide-theme.c
index 43ac832..d6ba8e4 100644
--- a/libglide/glide-theme.c
+++ b/libglide/glide-theme.c
@@ -350,4 +350,27 @@ glide_theme_get_default_color (GlideTheme *theme, ClutterColor *color)
   *color = theme->priv->default_color;
 }
 
+static void
+glide_theme_preview_background (GlideTheme *theme, cairo_t *cr,
+				gint width, gint height)
+{
+  GdkPixbuf *p, *s;
+  
+  // TODO: Error
+  p = gdk_pixbuf_new_from_file (theme->priv->default_background, NULL);
+  s = gdk_pixbuf_scale_simple (p, width, height, GDK_INTERP_HYPER);
+  
+  gdk_cairo_set_source_pixbuf (cr, s, 0, 0);
+  
+  cairo_rectangle (cr, 0, 0, width, height);
+  cairo_fill (cr);
+  
+  g_object_unref (G_OBJECT(p));
+  g_object_unref (G_OBJECT(s));
+}
 
+void
+glide_theme_preview (GlideTheme *theme, cairo_t *cr, gint width, gint height)
+{
+  glide_theme_preview_background (theme, cr, width, height);
+}
diff --git a/libglide/glide-theme.h b/libglide/glide-theme.h
index 72bdae6..a7532f8 100644
--- a/libglide/glide-theme.h
+++ b/libglide/glide-theme.h
@@ -23,6 +23,7 @@
 #include <clutter/clutter.h>
 
 #include <json-glib/json-glib.h>
+#include <cairo.h>
 
 #include "glide-types.h"
 
@@ -76,6 +77,8 @@ const gchar     *glide_theme_get_default_background (GlideTheme *theme);
 const gchar     *glide_theme_get_default_fontname (GlideTheme *theme);
 void             glide_theme_get_default_color (GlideTheme *theme, ClutterColor *c);
 
+void glide_theme_preview (GlideTheme *theme, cairo_t *cr, gint width, gint height);
+
 G_END_DECLS
 
 #endif  /* __GLIDE_THEME_H__  */



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