Commit 058764f4 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

app/display/gimpcanvas.[ch] moved GC from the the draw tool to GimpCanvas.

2003-11-10  Sven Neumann  <sven@gimp.org>

	* app/display/gimpcanvas.[ch]
	* app/tools/gimpdrawtool.[ch]: moved GC from the the draw tool to
	GimpCanvas. Added wrappers around GDK drawing functions and do all
	canvas drawing by means of these new functions.

	* app/display/gimpdisplayshell-appearance.c
	* app/display/gimpdisplayshell-render.c
	* app/display/gimpdisplayshell.c
	* app/tools/gimpcroptool.c
	* app/tools/gimpfuzzyselecttool.c: draw using the new GimpCanvas
	functions.
parent efea5763
2003-11-10 Sven Neumann <sven@gimp.org>
* app/display/gimpcanvas.[ch]
* app/tools/gimpdrawtool.[ch]: moved GC from the the draw tool to
GimpCanvas. Added wrappers around GDK drawing functions and do all
canvas drawing by means of these new functions.
* app/display/gimpdisplayshell-appearance.c
* app/display/gimpdisplayshell-render.c
* app/display/gimpdisplayshell.c
* app/tools/gimpcroptool.c
* app/tools/gimpfuzzyselecttool.c: draw using the new GimpCanvas
functions.
2003-11-10 Dave Neary <bolsh@gimp.org>
 
* app/tools/gimpimagemaptool.c: Moved assignment of shell to
......@@ -22,10 +22,6 @@
#include "display-types.h"
#include "config/config-types.h"
#include "core/gimpgrid.h"
#include "widgets/gimpwidgets-utils.h"
#include "gimpcanvas.h"
......@@ -37,6 +33,9 @@ static void gimp_canvas_class_init (GimpCanvasClass *klass);
static void gimp_canvas_init (GimpCanvas *gdisp);
static void gimp_canvas_realize (GtkWidget *widget);
static void gimp_canvas_unrealize (GtkWidget *widget);
static GdkGC * gimp_canvas_gc_new (GtkWidget *widget,
GimpCanvasStyle style);
static GdkGC * gimp_canvas_guides_gc_new (GtkWidget *widget,
GimpOrientationType orientation,
GdkColor *fg,
......@@ -88,91 +87,125 @@ gimp_canvas_class_init (GimpCanvasClass *klass)
static void
gimp_canvas_init (GimpCanvas *canvas)
{
canvas->render_gc = NULL;
gint i;
canvas->guides.normal_hgc = NULL;
canvas->guides.active_hgc = NULL;
canvas->guides.normal_vgc = NULL;
canvas->guides.active_vgc = NULL;
canvas->grid_gc = NULL;
canvas->vectors_gc = NULL;
for (i = 0; i < GIMP_CANVAS_NUM_STYLES; i++)
canvas->gc[i] = NULL;
}
static void
gimp_canvas_realize (GtkWidget *widget)
{
GimpCanvas *canvas = GIMP_CANVAS (widget);
GdkColor fg;
GdkColor bg;
GTK_WIDGET_CLASS (parent_class)->realize (widget);
canvas->render_gc = gdk_gc_new (widget->window);
gdk_gc_set_exposures (canvas->render_gc, TRUE);
/* guides */
fg.red = 0x0;
fg.green = 0x0;
fg.blue = 0x0;
bg.red = 0x0;
bg.green = 0x7f7f;
bg.blue = 0xffff;
canvas->guides.normal_hgc =
gimp_canvas_guides_gc_new (widget,
GIMP_ORIENTATION_HORIZONTAL, &fg, &bg);
canvas->guides.normal_vgc =
gimp_canvas_guides_gc_new (widget,
GIMP_ORIENTATION_VERTICAL, &fg, &bg);
fg.red = 0x0;
fg.green = 0x0;
fg.blue = 0x0;
bg.red = 0xffff;
bg.green = 0x0;
bg.blue = 0x0;
canvas->guides.active_hgc =
gimp_canvas_guides_gc_new (widget,
GIMP_ORIENTATION_HORIZONTAL, &fg, &bg);
canvas->guides.active_vgc =
gimp_canvas_guides_gc_new (widget,
GIMP_ORIENTATION_VERTICAL, &fg, &bg);
canvas->grid_gc = NULL;
canvas->vectors_gc = gdk_gc_new (widget->window);
gdk_gc_set_function (canvas->vectors_gc, GDK_INVERT);
fg.pixel = 0xFFFFFFFF;
bg.pixel = 0x00000000;
gdk_gc_set_foreground (canvas->vectors_gc, &fg);
gdk_gc_set_background (canvas->vectors_gc, &bg);
gdk_gc_set_line_attributes (canvas->vectors_gc,
0,
GDK_LINE_SOLID,
GDK_CAP_NOT_LAST, GDK_JOIN_MITER);
canvas->gc[GIMP_CANVAS_STYLE_RENDER] =
gimp_canvas_gc_new (widget, GIMP_CANVAS_STYLE_RENDER);
}
static void
gimp_canvas_unrealize (GtkWidget *widget)
{
GimpCanvas *canvas = GIMP_CANVAS (widget);
gint i;
g_object_unref (canvas->render_gc);
for (i = 0; i < GIMP_CANVAS_NUM_STYLES; i++)
{
if (canvas->gc[i])
{
g_object_unref (canvas->gc[i]);
canvas->gc[i] = NULL;
}
}
g_object_unref (canvas->guides.normal_hgc);
g_object_unref (canvas->guides.normal_vgc);
g_object_unref (canvas->guides.active_hgc);
g_object_unref (canvas->guides.active_vgc);
GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
}
/* g_object_unref (canvas->grid_gc); */
static GdkGC *
gimp_canvas_gc_new (GtkWidget *widget,
GimpCanvasStyle style)
{
GdkGC *gc = NULL;
GdkColor fg;
GdkColor bg;
g_object_unref (canvas->vectors_gc);
switch (style)
{
case GIMP_CANVAS_STYLE_XOR:
case GIMP_CANVAS_STYLE_XOR_DASHED:
fg.pixel = 0xFFFFFFFF;
bg.pixel = 0x00000000;
break;
GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
case GIMP_CANVAS_STYLE_HGUIDE_NORMAL:
case GIMP_CANVAS_STYLE_VGUIDE_NORMAL:
fg.red = 0x0;
fg.green = 0x0;
fg.blue = 0x0;
bg.red = 0x0;
bg.green = 0x7f7f;
bg.blue = 0xffff;
break;
case GIMP_CANVAS_STYLE_HGUIDE_ACTIVE:
case GIMP_CANVAS_STYLE_VGUIDE_ACTIVE:
fg.red = 0x0;
fg.green = 0x0;
fg.blue = 0x0;
bg.red = 0xffff;
bg.green = 0x0;
bg.blue = 0x0;
break;
default:
break;
}
switch (style)
{
case GIMP_CANVAS_STYLE_RENDER:
gc = gdk_gc_new (widget->window);
gdk_gc_set_exposures (gc, TRUE);
break;
case GIMP_CANVAS_STYLE_XOR:
case GIMP_CANVAS_STYLE_XOR_DASHED:
gc = gdk_gc_new (widget->window);
gdk_gc_set_function (gc, GDK_INVERT);
gdk_gc_set_foreground (gc, &fg);
gdk_gc_set_background (gc, &bg);
gdk_gc_set_line_attributes (gc,
0,
(style == GIMP_CANVAS_STYLE_XOR ?
GDK_LINE_SOLID : GDK_LINE_ON_OFF_DASH),
GDK_CAP_NOT_LAST,
GDK_JOIN_MITER);
break;
case GIMP_CANVAS_STYLE_HGUIDE_NORMAL:
case GIMP_CANVAS_STYLE_HGUIDE_ACTIVE:
gc = gimp_canvas_guides_gc_new (widget,
GIMP_ORIENTATION_HORIZONTAL, &fg, &bg);
break;
case GIMP_CANVAS_STYLE_VGUIDE_NORMAL:
case GIMP_CANVAS_STYLE_VGUIDE_ACTIVE:
gc = gimp_canvas_guides_gc_new (widget,
GIMP_ORIENTATION_VERTICAL, &fg, &bg);
break;
case GIMP_CANVAS_STYLE_CUSTOM:
g_assert_not_reached ();
break;
default:
break;
}
return gc;
}
static GdkGC *
......@@ -212,54 +245,15 @@ gimp_canvas_guides_gc_new (GtkWidget *widget,
return gc;
}
/* public functions */
GtkWidget *
gimp_canvas_new (void)
{
return GTK_WIDGET (g_object_new (GIMP_TYPE_CANVAS,
"name", "gimp-canvas",
NULL));
}
GdkGC *
gimp_canvas_grid_gc_new (GimpCanvas *canvas,
GimpGrid *grid)
{
GdkGC *gc;
GdkGCValues values;
GdkColor fg, bg;
g_return_val_if_fail (GIMP_IS_CANVAS (canvas), NULL);
g_return_val_if_fail (GIMP_IS_GRID (grid), NULL);
switch (grid->style)
{
case GIMP_GRID_ON_OFF_DASH:
values.line_style = GDK_LINE_ON_OFF_DASH;
break;
case GIMP_GRID_DOUBLE_DASH:
values.line_style = GDK_LINE_DOUBLE_DASH;
break;
case GIMP_GRID_DOTS:
case GIMP_GRID_INTERSECTIONS:
case GIMP_GRID_SOLID:
values.line_style = GDK_LINE_SOLID;
break;
}
values.join_style = GDK_JOIN_MITER;
gc = gdk_gc_new_with_values (GTK_WIDGET (canvas)->window, &values,
GDK_GC_LINE_STYLE | GDK_GC_JOIN_STYLE);
gimp_rgb_get_gdk_color (&grid->fgcolor, &fg);
gimp_rgb_get_gdk_color (&grid->bgcolor, &bg);
gdk_gc_set_rgb_fg_color (gc, &fg);
gdk_gc_set_rgb_bg_color (gc, &bg);
return gc;
return g_object_new (GIMP_TYPE_CANVAS,
"name", "gimp-canvas",
NULL);
}
void
......@@ -272,7 +266,7 @@ gimp_canvas_draw_cursor (GimpCanvas *canvas,
gdk_draw_line (widget->window,
widget->style->white_gc, x - 7, y - 1, x + 7, y - 1);
gdk_draw_line (widget->window,
widget->style->black_gc, x - 7, y, x + 7, y);
widget->style->black_gc, x - 7, y, x + 7, y );
gdk_draw_line (widget->window,
widget->style->white_gc, x - 7, y + 1, x + 7, y + 1);
gdk_draw_line (widget->window,
......@@ -282,3 +276,172 @@ gimp_canvas_draw_cursor (GimpCanvas *canvas,
gdk_draw_line (widget->window,
widget->style->white_gc, x + 1, y - 7, x + 1, y + 7);
}
void
gimp_canvas_draw_point (GimpCanvas *canvas,
GimpCanvasStyle style,
gint x,
gint y)
{
GtkWidget *widget = GTK_WIDGET (canvas);
if (! canvas->gc[style])
canvas->gc[style] = gimp_canvas_gc_new (widget, style);
gdk_draw_point (widget->window, canvas->gc[style], x, y);
}
void
gimp_canvas_draw_line (GimpCanvas *canvas,
GimpCanvasStyle style,
gint x1,
gint y1,
gint x2,
gint y2)
{
GtkWidget *widget = GTK_WIDGET (canvas);
if (! canvas->gc[style])
canvas->gc[style] = gimp_canvas_gc_new (widget, style);
gdk_draw_line (widget->window, canvas->gc[style], x1, y1, x2, y2);
}
void
gimp_canvas_draw_lines (GimpCanvas *canvas,
GimpCanvasStyle style,
GdkPoint *points,
gint num_points)
{
GtkWidget *widget = GTK_WIDGET (canvas);
if (! canvas->gc[style])
canvas->gc[style] = gimp_canvas_gc_new (widget, style);
gdk_draw_lines (widget->window, canvas->gc[style], points, num_points);
}
void
gimp_canvas_draw_rectangle (GimpCanvas *canvas,
GimpCanvasStyle style,
gboolean filled,
gint x,
gint y,
gint width,
gint height)
{
GtkWidget *widget = GTK_WIDGET (canvas);
if (! canvas->gc[style])
canvas->gc[style] = gimp_canvas_gc_new (widget, style);
gdk_draw_rectangle (widget->window, canvas->gc[style],
filled, x, y, width, height);
}
void
gimp_canvas_draw_arc (GimpCanvas *canvas,
GimpCanvasStyle style,
gboolean filled,
gint x,
gint y,
gint width,
gint height,
gint angle1,
gint angle2)
{
GtkWidget *widget = GTK_WIDGET (canvas);
if (! canvas->gc[style])
canvas->gc[style] = gimp_canvas_gc_new (widget, style);
gdk_draw_arc (widget->window, canvas->gc[style],
filled, x, y, width, height, angle1, angle2);
}
void
gimp_canvas_draw_polygon (GimpCanvas *canvas,
GimpCanvasStyle style,
gboolean filled,
GdkPoint *points,
gint num_points)
{
GtkWidget *widget = GTK_WIDGET (canvas);
if (! canvas->gc[style])
canvas->gc[style] = gimp_canvas_gc_new (widget, style);
gdk_draw_polygon (widget->window, canvas->gc[style],
filled, points, num_points);
}
void
gimp_canvas_draw_segments (GimpCanvas *canvas,
GimpCanvasStyle style,
GdkSegment *segments,
gint num_segments)
{
GtkWidget *widget = GTK_WIDGET (canvas);
if (! canvas->gc[style])
canvas->gc[style] = gimp_canvas_gc_new (widget, style);
gdk_draw_segments (widget->window, canvas->gc[style],
segments, num_segments);
}
void
gimp_canvas_draw_rgb (GimpCanvas *canvas,
GimpCanvasStyle style,
gint x,
gint y,
gint width,
gint height,
guchar *rgb_buf,
gint rowstride,
gint xdith,
gint ydith)
{
GtkWidget *widget = GTK_WIDGET (canvas);
if (! canvas->gc[style])
canvas->gc[style] = gimp_canvas_gc_new (widget, style);
gdk_draw_rgb_image_dithalign (widget->window, canvas->gc[style],
x, y, width, height,
GDK_RGB_DITHER_MAX,
rgb_buf, rowstride, xdith, ydith);
}
void
gimp_canvas_set_bg_color (GimpCanvas *canvas,
GimpRGB *color)
{
GtkWidget *widget = GTK_WIDGET (canvas);
GdkColormap *colormap;
GdkColor gdk_color;
if (! GTK_WIDGET_REALIZED (widget))
return;
gimp_rgb_get_gdk_color (color, &gdk_color);
colormap = gdk_drawable_get_colormap (widget->window);
g_return_if_fail (colormap != NULL);
gdk_colormap_alloc_color (colormap, &gdk_color, FALSE, TRUE);
gdk_window_set_background (widget->window, &gdk_color);
}
void
gimp_canvas_set_custom_gc (GimpCanvas *canvas,
GdkGC *gc)
{
if (canvas->gc[GIMP_CANVAS_STYLE_CUSTOM])
g_object_unref (canvas->gc[GIMP_CANVAS_STYLE_CUSTOM]);
canvas->gc[GIMP_CANVAS_STYLE_CUSTOM] = gc;
if (gc)
g_object_ref (gc);
}
......@@ -23,6 +23,20 @@
#include <gtk/gtkdrawingarea.h>
typedef enum
{
GIMP_CANVAS_STYLE_RENDER,
GIMP_CANVAS_STYLE_XOR,
GIMP_CANVAS_STYLE_XOR_DASHED,
GIMP_CANVAS_STYLE_HGUIDE_NORMAL,
GIMP_CANVAS_STYLE_HGUIDE_ACTIVE,
GIMP_CANVAS_STYLE_VGUIDE_NORMAL,
GIMP_CANVAS_STYLE_VGUIDE_ACTIVE,
GIMP_CANVAS_STYLE_CUSTOM,
GIMP_CANVAS_NUM_STYLES
} GimpCanvasStyle;
#define GIMP_TYPE_CANVAS (gimp_canvas_get_type ())
#define GIMP_CANVAS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CANVAS, GimpCanvas))
#define GIMP_CANVAS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CANVAS, GimpCanvasClass))
......@@ -37,23 +51,7 @@ struct _GimpCanvas
{
GtkDrawingArea parent_instance;
/* GC for rendering the image */
GdkGC *render_gc;
/* GCs for rendering guides */
struct
{
GdkGC *normal_hgc;
GdkGC *active_hgc;
GdkGC *normal_vgc;
GdkGC *active_vgc;
} guides;
/* GC for the grid */
GdkGC *grid_gc;
/* GC for the vectors */
GdkGC *vectors_gc;
GdkGC *gc[GIMP_CANVAS_NUM_STYLES];
};
struct _GimpCanvasClass
......@@ -62,14 +60,68 @@ struct _GimpCanvasClass
};
GType gimp_canvas_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_canvas_new (void);
GdkGC * gimp_canvas_grid_gc_new (GimpCanvas *canvas,
GimpGrid *grid);
void gimp_canvas_draw_cursor (GimpCanvas *canvas,
gint x,
gint y);
GType gimp_canvas_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_canvas_new (void);
void gimp_canvas_draw_cursor (GimpCanvas *canvas,
gint x,
gint y);
void gimp_canvas_draw_point (GimpCanvas *canvas,
GimpCanvasStyle style,
gint x,
gint y);
void gimp_canvas_draw_line (GimpCanvas *canvas,
GimpCanvasStyle style,
gint x1,
gint y1,
gint x2,
gint y2);
void gimp_canvas_draw_lines (GimpCanvas *canvas,
GimpCanvasStyle style,
GdkPoint *points,
gint num_points);
void gimp_canvas_draw_rectangle (GimpCanvas *canvas,
GimpCanvasStyle style,
gboolean filled,
gint x,
gint y,
gint width,
gint height);
void gimp_canvas_draw_arc (GimpCanvas *canvas,
GimpCanvasStyle style,
gboolean filled,
gint x,
gint y,
gint width,
gint height,
gint angle1,
gint angle2);
void gimp_canvas_draw_polygon (GimpCanvas *canvas,
GimpCanvasStyle style,
gboolean filled,
GdkPoint *points,
gint num_points);
void gimp_canvas_draw_segments (GimpCanvas *canvas,
GimpCanvasStyle style,
GdkSegment *segments,
gint num_segments);
void gimp_canvas_draw_rgb (GimpCanvas *canvas,
GimpCanvasStyle style,
gint x,
gint y,
gint width,
gint height,
guchar *rgb_buf,
gint rowstride,
gint xdith,
gint ydith);
void gimp_canvas_set_bg_color (GimpCanvas *canvas,
GimpRGB *color);
void gimp_canvas_set_custom_gc (GimpCanvas *canvas,
GdkGC *gc);
#endif /* __GIMP_CANVAS_H__ */
......@@ -30,6 +30,7 @@
#include "widgets/gimpitemfactory.h"
#include "widgets/gimpwidgets-utils.h"
#include "gimpcanvas.h"
#include "gimpdisplay.h"
#include "gimpdisplayoptions.h"
#include "gimpdisplayshell.h"
......@@ -120,7 +121,7 @@ gimp_display_shell_set_show_rulers (GimpDisplayShell *shell,
g_object_set (options, "show-rulers", show, NULL);
table = GTK_TABLE (shell->canvas->parent);
table = GTK_TABLE (GTK_WIDGET (shell->canvas)->parent);
if (show)
{
......@@ -437,19 +438,7 @@ gimp_display_shell_set_padding (GimpDisplayShell *shell,
"padding-color", &color,
NULL);