Commit 77c400e7 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

port to Cairo drawing.

2007-11-14  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimppaletteview.[ch]: port to Cairo drawing.


svn path=/trunk/; revision=24154
parent d06ff70d
2007-11-14 Michael Natterer <mitch@gimp.org>
* app/widgets/gimppaletteview.[ch]: port to Cairo drawing.
2007-11-13 Martin Nordholts <martinn@svn.gnome.org>
* app/tools/gimprectangletool.c: Avoid GimpRectangleTool internals
......
......@@ -21,6 +21,8 @@
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
......@@ -47,8 +49,6 @@ enum
};
static void gimp_palette_view_realize (GtkWidget *widget);
static void gimp_palette_view_unrealize (GtkWidget *widget);
static gboolean gimp_palette_view_expose (GtkWidget *widget,
GdkEventExpose *eevent);
static gboolean gimp_palette_view_button_press (GtkWidget *widget,
......@@ -66,8 +66,6 @@ static GimpPaletteEntry *
gint y);
static void gimp_palette_view_expose_entry (GimpPaletteView *view,
GimpPaletteEntry *entry);
static void gimp_palette_view_draw_selected (GimpPaletteView *view,
GdkRectangle *area);
static void gimp_palette_view_invalidate (GimpPalette *palette,
GimpPaletteView *view);
static void gimp_palette_view_drag_color (GtkWidget *widget,
......@@ -145,8 +143,6 @@ gimp_palette_view_class_init (GimpPaletteViewClass *klass)
G_TYPE_POINTER,
GIMP_TYPE_RGB);
widget_class->realize = gimp_palette_view_realize;
widget_class->unrealize = gimp_palette_view_unrealize;
widget_class->expose_event = gimp_palette_view_expose;
widget_class->button_press_event = gimp_palette_view_button_press;
widget_class->key_press_event = gimp_palette_view_key_press;
......@@ -162,49 +158,74 @@ gimp_palette_view_init (GimpPaletteView *view)
view->selected = NULL;
view->dnd_entry = NULL;
view->gc = NULL;
}
static void
gimp_palette_view_realize (GtkWidget *widget)
static gboolean
gimp_palette_view_expose (GtkWidget *widget,
GdkEventExpose *eevent)
{
GimpPaletteView *view = GIMP_PALETTE_VIEW (widget);
GimpPaletteView *pal_view = GIMP_PALETTE_VIEW (widget);
GimpView *view = GIMP_VIEW (widget);
GTK_WIDGET_CLASS (parent_class)->realize (widget);
if (! GTK_WIDGET_DRAWABLE (widget))
return FALSE;
view->gc = gdk_gc_new (widget->window);
GTK_WIDGET_CLASS (parent_class)->expose_event (widget, eevent);
gdk_gc_set_function (view->gc, GDK_INVERT);
gdk_gc_set_line_attributes (view->gc, 1,
GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_ROUND);
}
if (view->renderer->viewable && pal_view->selected)
{
GimpViewRendererPalette *renderer;
cairo_t *cr;
gint8 *dash_list;
gint row, col;
static void
gimp_palette_view_unrealize (GtkWidget *widget)
{
GimpPaletteView *view = GIMP_PALETTE_VIEW (widget);
renderer = GIMP_VIEW_RENDERER_PALETTE (view->renderer);
if (view->gc)
{
g_object_unref (view->gc);
view->gc = NULL;
}
row = pal_view->selected->position / renderer->columns;
col = pal_view->selected->position % renderer->columns;
GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
}
cr = gdk_cairo_create (widget->window);
gdk_cairo_region (cr, eevent->region);
cairo_clip (cr);
static gboolean
gimp_palette_view_expose (GtkWidget *widget,
GdkEventExpose *eevent)
{
if (GTK_WIDGET_DRAWABLE (widget))
{
GimpPaletteView *view = GIMP_PALETTE_VIEW (widget);
cairo_set_line_width (cr, 1.0);
gdk_cairo_set_source_color (cr, &widget->style->base[GTK_STATE_NORMAL]);
cairo_rectangle (cr,
widget->allocation.x + col * renderer->cell_width + 0.5,
widget->allocation.y + row * renderer->cell_height + 0.5,
renderer->cell_width,
renderer->cell_height);
cairo_stroke_preserve (cr);
GTK_WIDGET_CLASS (parent_class)->expose_event (widget, eevent);
gtk_widget_style_get (widget,
"focus-line-pattern", (gchar *) &dash_list,
NULL);
if (dash_list[0])
{
/* Taken straight from gtk_default_draw_focus()
*/
gint n_dashes = strlen ((const gchar *) dash_list);
gdouble *dashes = g_new (gdouble, n_dashes);
gdouble total_length = 0;
gint i;
for (i = 0; i < n_dashes; i++)
{
dashes[i] = dash_list[i];
total_length += dash_list[i];
}
gdk_cairo_set_source_color (cr, &widget->style->text[GTK_STATE_NORMAL]);
cairo_set_dash (cr, dashes, n_dashes, 0.5);
cairo_stroke (cr);
g_free (dashes);
}
if (view->selected)
gimp_palette_view_draw_selected (view, &eevent->area);
g_free (dash_list);
cairo_destroy (cr);
}
return FALSE;
......@@ -465,38 +486,6 @@ gimp_palette_view_expose_entry (GimpPaletteView *view,
renderer->cell_height + 1);
}
static void
gimp_palette_view_draw_selected (GimpPaletteView *pal_view,
GdkRectangle *area)
{
GimpView *view = GIMP_VIEW (pal_view);
if (view->renderer->viewable && pal_view->selected)
{
GtkWidget *widget = GTK_WIDGET (view);
GimpViewRendererPalette *renderer;
gint row, col;
renderer = GIMP_VIEW_RENDERER_PALETTE (view->renderer);
row = pal_view->selected->position / renderer->columns;
col = pal_view->selected->position % renderer->columns;
if (area)
gdk_gc_set_clip_rectangle (pal_view->gc, area);
gdk_draw_rectangle (widget->window, pal_view->gc,
FALSE,
widget->allocation.x + col * renderer->cell_width,
widget->allocation.y + row * renderer->cell_height,
renderer->cell_width,
renderer->cell_height);
if (area)
gdk_gc_set_clip_rectangle (pal_view->gc, NULL);
}
}
static void
gimp_palette_view_invalidate (GimpPalette *palette,
GimpPaletteView *view)
......
......@@ -41,7 +41,6 @@ struct _GimpPaletteView
GimpPaletteEntry *selected;
GimpPaletteEntry *dnd_entry;
GdkGC *gc;
};
struct _GimpPaletteViewClass
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment