gimp r24870 - in trunk: . app/widgets



Author: neo
Date: Tue Feb 12 08:26:04 2008
New Revision: 24870
URL: http://svn.gnome.org/viewvc/gimp?rev=24870&view=rev

Log:
2008-02-12  Sven Neumann  <sven gimp org>

	* app/widgets/gimpcolormapeditor.[ch]: show a hint on 
non-indexed
	images. Based on a patch from Olof Frahm. Closes bug #438217.



Modified:
   trunk/ChangeLog
   trunk/app/widgets/gimpcolormapeditor.c
   trunk/app/widgets/gimpcolormapeditor.h

Modified: trunk/app/widgets/gimpcolormapeditor.c
==============================================================================
--- trunk/app/widgets/gimpcolormapeditor.c	(original)
+++ trunk/app/widgets/gimpcolormapeditor.c	Tue Feb 12 08:26:04 2008
@@ -76,12 +76,16 @@
                                                     guint               n_params,
                                                     GObjectConstructParam *params);
 
+static void   gimp_colormap_editor_finalize        (GObject            *object);
 static void   gimp_colormap_editor_destroy         (GtkObject          *object);
 static void   gimp_colormap_editor_unmap           (GtkWidget          *widget);
 
 static void   gimp_colormap_editor_set_image       (GimpImageEditor    *editor,
                                                     GimpImage          *image);
 
+static PangoLayout *
+              gimp_colormap_editor_create_layout   (GtkWidget          *widget);
+
 static void   gimp_colormap_editor_draw            (GimpColormapEditor *editor);
 static void   gimp_colormap_editor_draw_cell       (GimpColormapEditor *editor,
                                                     gint                col);
@@ -92,6 +96,9 @@
 static void   gimp_colormap_preview_size_allocate  (GtkWidget          *widget,
                                                     GtkAllocation      *allocation,
                                                     GimpColormapEditor *editor);
+static void   gimp_colormap_preview_expose         (GtkWidget          *widget,
+                                                    GdkEventExpose     *event,
+                                                    GimpColormapEditor *editor);
 static gboolean
               gimp_colormap_preview_button_press   (GtkWidget          *widget,
                                                     GdkEventButton     *bevent,
@@ -144,6 +151,7 @@
                   GDK_TYPE_MODIFIER_TYPE);
 
   object_class->constructor     = gimp_colormap_editor_constructor;
+  object_class->finalize        = gimp_colormap_editor_finalize;
 
   gtk_object_class->destroy     = gimp_colormap_editor_destroy;
 
@@ -157,9 +165,11 @@
 static void
 gimp_colormap_editor_init (GimpColormapEditor *editor)
 {
-  GtkWidget *frame;
-  GtkWidget *table;
-  GtkObject *adj;
+  GtkWidget      *frame;
+  GtkWidget      *table;
+  GtkObject      *adj;
+  gint            width;
+  gint            height;
 
   editor->col_index     = 0;
   editor->dnd_col_index = 0;
@@ -174,16 +184,25 @@
   gtk_widget_show (frame);
 
   editor->preview = gtk_preview_new (GTK_PREVIEW_COLOR);
-  gtk_widget_set_size_request (editor->preview, -1, 60);
   gtk_preview_set_expand (GTK_PREVIEW (editor->preview), TRUE);
   gtk_widget_add_events (editor->preview, GDK_BUTTON_PRESS_MASK);
   gtk_container_add (GTK_CONTAINER (frame), editor->preview);
   gtk_widget_show (editor->preview);
 
+  editor->layout = gimp_colormap_editor_create_layout (editor->preview);
+
+  pango_layout_set_width (editor->layout, 180 * PANGO_SCALE);
+  pango_layout_get_pixel_size (editor->layout, &width, &height);
+  gtk_widget_set_size_request (editor->preview, width, height);
+
   g_signal_connect_after (editor->preview, "size-allocate",
                           G_CALLBACK (gimp_colormap_preview_size_allocate),
                           editor);
 
+  g_signal_connect_after (editor->preview, "expose-event",
+                          G_CALLBACK (gimp_colormap_preview_expose),
+                          editor);
+
   g_signal_connect (editor->preview, "button-press-event",
                     G_CALLBACK (gimp_colormap_preview_button_press),
                     editor);
@@ -250,6 +269,20 @@
 }
 
 static void
+gimp_colormap_editor_finalize (GObject *object)
+{
+  GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (object);
+
+  if (editor->layout)
+    {
+      g_object_unref (editor->layout);
+      editor->layout = NULL;
+    }
+
+  G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
 gimp_colormap_editor_destroy (GtkObject *object)
 {
   GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (object);
@@ -448,6 +481,32 @@
 
 /*  private functions  */
 
+
+static PangoLayout *
+gimp_colormap_editor_create_layout (GtkWidget *widget)
+{
+  PangoLayout    *layout;
+  PangoAttrList  *attrs;
+  PangoAttribute *attr;
+
+  layout = gtk_widget_create_pango_layout (widget,
+                                           _("Colormap is only useful with "
+                                             "indexed images."));
+  pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
+
+  attrs = pango_attr_list_new ();
+
+  attr = pango_attr_style_new (PANGO_STYLE_ITALIC);
+  attr->start_index = 0;
+  attr->end_index   = -1;
+  pango_attr_list_insert (attrs, attr);
+
+  pango_layout_set_attributes (layout, attrs);
+  pango_attr_list_unref (attrs);
+
+  return layout;
+}
+
 #define MIN_CELL_SIZE 4
 
 static void
@@ -592,6 +651,30 @@
 }
 
 static void
+gimp_colormap_preview_expose (GtkWidget          *widget,
+                              GdkEventExpose     *event,
+                              GimpColormapEditor *editor)
+{
+  GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
+  gint             x, y;
+  gint             width, height;
+
+  if (image_editor->image == NULL ||
+      gimp_image_base_type (image_editor->image) == GIMP_INDEXED)
+    return;
+
+  pango_layout_get_pixel_size (editor->layout, &width, &height);
+
+  x = (widget->allocation.width - width) / 2;
+  y = (widget->allocation.height - height) / 2;
+
+  gdk_draw_layout (editor->preview->window,
+                   editor->preview->style->fg_gc[widget->state],
+                   MAX (x, 0), MAX (y, 0),
+                   editor->layout);
+}
+
+static void
 gimp_colormap_editor_clear (GimpColormapEditor *editor,
                             gint                start_row)
 {

Modified: trunk/app/widgets/gimpcolormapeditor.h
==============================================================================
--- trunk/app/widgets/gimpcolormapeditor.h	(original)
+++ trunk/app/widgets/gimpcolormapeditor.h	Tue Feb 12 08:26:04 2008
@@ -37,13 +37,15 @@
 {
   GimpImageEditor  parent_instance;
 
+  GtkWidget       *preview;
   gint             col_index;
   gint             dnd_col_index;
-  GtkWidget       *preview;
   gint             xn;
   gint             yn;
   gint             cellsize;
 
+  PangoLayout     *layout;
+
   GtkWidget       *edit_button;
   GtkWidget       *add_button;
 



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