2001-02-27 05:21:12 +00:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995-2001 Spencer Kimball, Peter Mattis, and others
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-05-09 22:34:59 +00:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
|
|
|
#include "tools-types.h"
|
2001-02-27 05:21:12 +00:00
|
|
|
|
2001-09-25 23:23:09 +00:00
|
|
|
#include "display/gimpdisplay.h"
|
2001-10-31 21:20:09 +00:00
|
|
|
#include "display/gimpdisplayshell.h"
|
2001-05-09 22:34:59 +00:00
|
|
|
|
2001-09-25 23:23:09 +00:00
|
|
|
#include "gimpdrawtool.h"
|
2001-02-27 05:21:12 +00:00
|
|
|
|
|
|
|
|
2001-02-27 19:18:01 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
DRAW,
|
|
|
|
LAST_SIGNAL
|
2001-02-27 05:21:12 +00:00
|
|
|
};
|
|
|
|
|
2001-02-27 14:14:13 +00:00
|
|
|
static void gimp_draw_tool_class_init (GimpDrawToolClass *klass);
|
|
|
|
static void gimp_draw_tool_init (GimpDrawTool *draw_tool);
|
|
|
|
|
2001-08-14 14:53:55 +00:00
|
|
|
static void gimp_draw_tool_finalize (GObject *object);
|
2001-02-27 19:18:01 +00:00
|
|
|
|
|
|
|
static void gimp_draw_tool_control (GimpTool *tool,
|
|
|
|
ToolAction action,
|
2001-10-29 11:47:11 +00:00
|
|
|
GimpDisplay *gdisp);
|
2001-02-27 14:14:13 +00:00
|
|
|
|
|
|
|
|
2001-02-27 05:21:12 +00:00
|
|
|
static guint gimp_draw_tool_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2001-02-27 19:18:01 +00:00
|
|
|
static GimpToolClass *parent_class = NULL;
|
|
|
|
|
2001-02-27 05:21:12 +00:00
|
|
|
|
|
|
|
|
2001-08-14 14:53:55 +00:00
|
|
|
GType
|
2001-02-27 05:21:12 +00:00
|
|
|
gimp_draw_tool_get_type (void)
|
|
|
|
{
|
2001-08-14 14:53:55 +00:00
|
|
|
static GType tool_type = 0;
|
2001-02-27 05:21:12 +00:00
|
|
|
|
|
|
|
if (! tool_type)
|
|
|
|
{
|
2001-08-14 14:53:55 +00:00
|
|
|
static const GTypeInfo tool_info =
|
2001-02-27 05:21:12 +00:00
|
|
|
{
|
|
|
|
sizeof (GimpDrawToolClass),
|
2001-08-14 14:53:55 +00:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_draw_tool_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpDrawTool),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_draw_tool_init,
|
2001-02-27 05:21:12 +00:00
|
|
|
};
|
|
|
|
|
2001-08-14 14:53:55 +00:00
|
|
|
tool_type = g_type_register_static (GIMP_TYPE_TOOL,
|
|
|
|
"GimpDrawTool",
|
|
|
|
&tool_info, 0);
|
2001-02-27 05:21:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return tool_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_draw_tool_class_init (GimpDrawToolClass *klass)
|
|
|
|
{
|
2001-08-14 14:53:55 +00:00
|
|
|
GObjectClass *object_class;
|
|
|
|
GimpToolClass *tool_class;
|
2001-02-27 19:18:01 +00:00
|
|
|
|
2001-08-14 14:53:55 +00:00
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
|
|
tool_class = GIMP_TOOL_CLASS (klass);
|
2001-02-27 19:18:01 +00:00
|
|
|
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-24 21:27:11 +00:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-02-27 05:21:12 +00:00
|
|
|
|
|
|
|
gimp_draw_tool_signals[DRAW] =
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-24 21:27:11 +00:00
|
|
|
g_signal_new ("draw",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpDrawToolClass, draw),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2001-02-27 05:21:12 +00:00
|
|
|
|
2001-08-14 14:53:55 +00:00
|
|
|
object_class->finalize = gimp_draw_tool_finalize;
|
2001-02-27 19:18:01 +00:00
|
|
|
|
2001-08-14 14:53:55 +00:00
|
|
|
tool_class->control = gimp_draw_tool_control;
|
2001-02-27 05:21:12 +00:00
|
|
|
}
|
|
|
|
|
2001-02-27 14:14:13 +00:00
|
|
|
static void
|
|
|
|
gimp_draw_tool_init (GimpDrawTool *tool)
|
|
|
|
{
|
|
|
|
tool->draw_state = INVISIBLE;
|
|
|
|
tool->gc = NULL;
|
|
|
|
tool->paused_count = 0;
|
|
|
|
tool->line_width = 0;
|
|
|
|
tool->line_style = GDK_LINE_SOLID;
|
|
|
|
tool->cap_style = GDK_CAP_NOT_LAST;
|
|
|
|
tool->join_style = GDK_JOIN_MITER;
|
|
|
|
}
|
2001-02-27 05:21:12 +00:00
|
|
|
|
2001-02-27 19:18:01 +00:00
|
|
|
static void
|
2001-08-14 14:53:55 +00:00
|
|
|
gimp_draw_tool_finalize (GObject *object)
|
2001-02-27 19:18:01 +00:00
|
|
|
{
|
|
|
|
GimpDrawTool *draw_tool;
|
|
|
|
|
|
|
|
draw_tool = GIMP_DRAW_TOOL (object);
|
|
|
|
|
|
|
|
if (draw_tool->gc)
|
2001-08-14 14:53:55 +00:00
|
|
|
{
|
2001-08-30 01:09:58 +00:00
|
|
|
g_object_unref (G_OBJECT (draw_tool->gc));
|
2001-08-14 14:53:55 +00:00
|
|
|
draw_tool->gc = NULL;
|
|
|
|
}
|
2001-02-27 19:18:01 +00:00
|
|
|
|
2001-08-14 14:53:55 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-02-27 19:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-10-29 11:47:11 +00:00
|
|
|
gimp_draw_tool_control (GimpTool *tool,
|
|
|
|
ToolAction action,
|
|
|
|
GimpDisplay *gdisp)
|
2001-02-27 19:18:01 +00:00
|
|
|
{
|
|
|
|
GimpDrawTool *draw_tool;
|
|
|
|
|
|
|
|
draw_tool = GIMP_DRAW_TOOL (tool);
|
|
|
|
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case PAUSE:
|
|
|
|
gimp_draw_tool_pause (draw_tool);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RESUME:
|
|
|
|
gimp_draw_tool_resume (draw_tool);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HALT:
|
|
|
|
gimp_draw_tool_stop (draw_tool);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2001-08-14 14:53:55 +00:00
|
|
|
|
|
|
|
if (GIMP_TOOL_CLASS (parent_class)->control)
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
|
2001-02-27 19:18:01 +00:00
|
|
|
}
|
|
|
|
|
2001-02-27 05:21:12 +00:00
|
|
|
void
|
2001-02-27 14:14:13 +00:00
|
|
|
gimp_draw_tool_start (GimpDrawTool *core,
|
|
|
|
GdkWindow *win)
|
2001-02-27 05:21:12 +00:00
|
|
|
{
|
|
|
|
GdkColor fg, bg;
|
|
|
|
|
|
|
|
if (core->draw_state != INVISIBLE)
|
|
|
|
gimp_draw_tool_stop (core); /* this seems backwards ;) */
|
|
|
|
|
|
|
|
core->win = win;
|
|
|
|
core->paused_count = 0; /* reset pause counter to 0 */
|
|
|
|
|
|
|
|
/* create a new graphics context */
|
|
|
|
if (! core->gc)
|
|
|
|
core->gc = gdk_gc_new (win);
|
|
|
|
|
|
|
|
gdk_gc_set_function (core->gc, GDK_INVERT);
|
|
|
|
fg.pixel = 0xFFFFFFFF;
|
|
|
|
bg.pixel = 0x00000000;
|
|
|
|
gdk_gc_set_foreground (core->gc, &fg);
|
|
|
|
gdk_gc_set_background (core->gc, &bg);
|
|
|
|
gdk_gc_set_line_attributes (core->gc, core->line_width, core->line_style,
|
|
|
|
core->cap_style, core->join_style);
|
|
|
|
|
2001-07-25 00:27:41 +00:00
|
|
|
g_signal_emit (G_OBJECT(core), gimp_draw_tool_signals[DRAW], 0);
|
2001-02-27 05:21:12 +00:00
|
|
|
|
|
|
|
core->draw_state = VISIBLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_draw_tool_stop (GimpDrawTool *core)
|
|
|
|
{
|
|
|
|
if (core->draw_state == INVISIBLE)
|
|
|
|
return;
|
|
|
|
|
2001-07-25 00:27:41 +00:00
|
|
|
g_signal_emit (G_OBJECT(core), gimp_draw_tool_signals[DRAW], 0);
|
2001-02-27 05:21:12 +00:00
|
|
|
|
|
|
|
core->draw_state = INVISIBLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_draw_tool_resume (GimpDrawTool *core)
|
|
|
|
{
|
|
|
|
core->paused_count = (core->paused_count > 0) ? core->paused_count - 1 : 0;
|
2001-02-27 19:18:01 +00:00
|
|
|
|
2001-02-27 05:21:12 +00:00
|
|
|
if (core->paused_count == 0)
|
|
|
|
{
|
|
|
|
core->draw_state = VISIBLE;
|
2001-02-27 19:18:01 +00:00
|
|
|
|
2001-07-25 00:27:41 +00:00
|
|
|
g_signal_emit(G_OBJECT(core), gimp_draw_tool_signals[DRAW], 0);
|
2001-02-27 05:21:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_draw_tool_pause (GimpDrawTool *core)
|
|
|
|
{
|
|
|
|
if (core->paused_count == 0)
|
|
|
|
{
|
|
|
|
core->draw_state = INVISIBLE;
|
|
|
|
|
2001-07-25 00:27:41 +00:00
|
|
|
g_signal_emit (G_OBJECT(core), gimp_draw_tool_signals[DRAW], 0);
|
2001-02-27 05:21:12 +00:00
|
|
|
}
|
|
|
|
|
2001-02-27 19:18:01 +00:00
|
|
|
core->paused_count++;
|
2001-02-27 14:14:13 +00:00
|
|
|
}
|
2001-04-07 14:55:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_draw_tool_draw_handle (GimpDrawTool *draw_tool,
|
2001-10-31 21:20:09 +00:00
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gint size,
|
|
|
|
gint type)
|
2001-04-07 14:55:39 +00:00
|
|
|
{
|
2001-10-31 21:20:09 +00:00
|
|
|
GimpTool *tool;
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
gdouble hx, hy;
|
|
|
|
gint filled;
|
|
|
|
|
|
|
|
tool = GIMP_TOOL (draw_tool);
|
|
|
|
|
|
|
|
shell = GIMP_DISPLAY_SHELL (tool->gdisp->shell);
|
2001-04-07 14:55:39 +00:00
|
|
|
|
|
|
|
gdisplay_transform_coords_f (tool->gdisp, x, y, &hx, &hy, TRUE);
|
|
|
|
|
|
|
|
hx = ROUND (hx);
|
|
|
|
hy = ROUND (hy);
|
|
|
|
|
|
|
|
filled = type % 2;
|
|
|
|
|
|
|
|
if (type < 2)
|
2001-10-31 21:20:09 +00:00
|
|
|
{
|
|
|
|
gdk_draw_rectangle (shell->canvas->window,
|
|
|
|
draw_tool->gc, filled,
|
|
|
|
hx - size / 2, hy - size / 2,
|
|
|
|
size, size);
|
|
|
|
}
|
2001-04-07 14:55:39 +00:00
|
|
|
else
|
2001-10-31 21:20:09 +00:00
|
|
|
{
|
|
|
|
gdk_draw_arc (shell->canvas->window,
|
|
|
|
draw_tool->gc, filled,
|
|
|
|
hx - size / 2, hy - size / 2,
|
|
|
|
size, size,
|
|
|
|
0, 360 * 64);
|
|
|
|
}
|
2001-04-07 14:55:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_draw_tool_draw_lines (GimpDrawTool *draw_tool,
|
2001-10-31 21:20:09 +00:00
|
|
|
gdouble *points,
|
|
|
|
gint npoints,
|
|
|
|
gint filled)
|
2001-04-07 14:55:39 +00:00
|
|
|
{
|
2001-10-31 21:20:09 +00:00
|
|
|
GimpTool *tool;
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
GdkPoint *coords;
|
|
|
|
gint i;
|
|
|
|
gdouble sx, sy;
|
2001-04-07 14:55:39 +00:00
|
|
|
|
2001-10-31 21:20:09 +00:00
|
|
|
tool = GIMP_TOOL (draw_tool);
|
2001-04-07 14:55:39 +00:00
|
|
|
|
2001-10-31 21:20:09 +00:00
|
|
|
shell = GIMP_DISPLAY_SHELL (tool->gdisp->shell);
|
2001-04-07 14:55:39 +00:00
|
|
|
|
2001-10-31 21:20:09 +00:00
|
|
|
coords = g_new (GdkPoint, npoints);
|
|
|
|
|
|
|
|
for (i = 0; i < npoints ; i++)
|
|
|
|
{
|
|
|
|
gdisplay_transform_coords_f (tool->gdisp, points[i*2], points[i*2+1],
|
|
|
|
&sx, &sy, TRUE);
|
|
|
|
coords[i].x = ROUND (sx);
|
|
|
|
coords[i].y = ROUND (sy);
|
|
|
|
}
|
2001-04-07 14:55:39 +00:00
|
|
|
|
|
|
|
if (filled)
|
2001-10-31 21:20:09 +00:00
|
|
|
{
|
|
|
|
gdk_draw_polygon (shell->canvas->window,
|
|
|
|
draw_tool->gc, TRUE,
|
|
|
|
coords, npoints);
|
|
|
|
}
|
2001-04-07 14:55:39 +00:00
|
|
|
else
|
2001-10-31 21:20:09 +00:00
|
|
|
{
|
|
|
|
gdk_draw_lines (shell->canvas->window,
|
|
|
|
draw_tool->gc,
|
|
|
|
coords, npoints);
|
|
|
|
}
|
2001-04-07 14:55:39 +00:00
|
|
|
|
|
|
|
g_free (coords);
|
|
|
|
}
|