gimp/app/tools/gimpdrawtool.c
Michael Natterer 02fde14c95 build display/ before tools/.
2001-11-08  Michael Natterer  <mitch@gimp.org>

	* app/Makefile.am: build display/ before tools/.

	* app/devices.c: devices_check_change(): added all events
	which have a GdkDevice pointer.

	* app/gimpprogress.c: include "display-types.h" instead of
	"core-types.h".

	* app/core/Makefile.am
	* app/core/gimpdrawable-bucket-fill.[ch]: new files: the bucket_fill
	stuff taken from tools/gimpbucketfilltool.[ch].

	* app/core/core-types.h: added "BucketFillMode".

	* app/core/gimpimage-mask-select.[ch]: cleanup.

	* app/core/gimpmarshal.list: added more marshallers for GimpTool's
	new signal signatures.

	* app/core/gimpmarshal.[ch]: regenerated.

	* app/display/Makefile.am
	* app/display/gimpdisplayshell-dnd.[ch]
	* app/display/gimpdisplayshell-layer-select.[ch]: new files: the
	canvas drop callbacks from gimpdisplayshell-callbacks.[ch] and
	the stuff formerly knows as gui/layer-select.[ch].

	* app/display/gimpdisplay.h: don't include "gui/gui-types.h".

	* app/display/gximage.c: include "display-types.h".

	* app/display/gimpdisplay-foreach.c
	* app/display/gimpdisplayshell.[ch]: call gdsplay_delete(), don't
	destroy the shell widget.

	* app/gui/Makefile.am
	* app/gui/layer-select.[ch]: removed.

	* app/gui/gradients-commands.c: fixed "Save as POV" fprintf()s.

	* app/gui/preferences-dialog.c: removed the layer_select stuff
	because it is useless with the new preview system.

	* app/gui/tool-options-dialog.c: send the correct data to the
	close_callback.

	* app/gui/tools-commands.c: changed to follow the new
	gimp_tool_initialize() semantics (see below).

	Tool & canvas event handling chainsawing:

	* app/tools/tools-types.h: new struct GimpCoords which contains
	x, y, pressure, tilt etc.

	* app/display/gimpdisplayshell-callbacks.[ch]: added utility
	functions which transparently retreive the current event's
	GimpCoords or take it from the device directly if the event has
	none. Pass GimpCoords _in_image_coordinates_ to all tool
	functions.

	Most important: don't pass GdkEvents and display coordinates to
	tools any more.

	* app/tools/gimptool.[ch]: changed virtual functions to take
	GimpCoords, time and state separately instead of GdkEvents.

	* app/tools/gimpbezierselecttool.c
	* app/tools/gimpblendtool.c
	* app/tools/gimpbucketfilltool.[ch]
	* app/tools/gimpbycolorselecttool.c
	* app/tools/gimpclonetool.c
	* app/tools/gimpcolorpickertool.c
	* app/tools/gimpconvolvetool.c
	* app/tools/gimpcroptool.[ch]
	* app/tools/gimpcurvestool.c
	* app/tools/gimpdodgeburntool.c
	* app/tools/gimpdrawtool.c
	* app/tools/gimpeditselectiontool.[ch]
	* app/tools/gimperasertool.c
	* app/tools/gimpfliptool.c
	* app/tools/gimpfreeselecttool.[ch]
	* app/tools/gimpfuzzyselecttool.c
	* app/tools/gimpinktool.c
	* app/tools/gimpiscissorstool.c
	* app/tools/gimpmagnifytool.c
	* app/tools/gimpmeasuretool.c
	* app/tools/gimpmovetool.c
	* app/tools/gimppainttool.c
	* app/tools/gimppathtool.[ch]
	* app/tools/gimprectselecttool.c
	* app/tools/gimprotatetool.c
	* app/tools/gimpselectiontool.[ch]
	* app/tools/gimpsmudgetool.c
	* app/tools/gimptexttool.c
	* app/tools/gimptransformtool.[ch]
	* app/tools/path_tool.[ch]
	* app/tools/selection_options.c: tons and tons of changes:

	- changed to use the new virtual function parameters.
	- removed zillions of gdisplay_untransform_coords().
	- get the active drawable's offsets manually in many cases.
	  (questionable, but IMHO ok because it's obvious and not simply a
	  "TRUE" passed to some function)
	- reordered some functions to be consistent across tools.
	- some tools had to be changed to work on image coords, not
	  display ones (esp. crop).
	- fixed strange rotate tool behaviour which should be backported
	  to stable.
	- some stuff i came across.
	- indentation and other paranoia.
	- rounding of coordinated may be broken in some tools.
	- new bugs guaranteed.

	* app/tools/tool_manager.[ch]: new semantic of
	tool_manager_initialize_active() (looked at the places where it
	was used from and put common code together). Should be a bit
	better now :)

	* app/tools/gimpblendtool.c
	* app/tools/transform_options.c: use the new GTK+ feature that a
	widget (toggle button) can be a frame's title for this tools' tool
	options.

	* app/widgets/widgets-types.h: stuff.

	* themes/Default/gtkrc: s/GtkDialog/GimpDialog/.

	* tools/pdbgen/Makefile.am: don't scan tools/gimpbucketfilltool.h
	any more.

	* tools/pdbgen/enums.pl: regenerated.

	* tools/pdbgen/pdb/tools.pdb: changed bucket_fill wrapper.

	* app/pdb/tools_cmds.c: regenerated.
2001-11-08 19:14:51 +00:00

318 lines
7.1 KiB
C

/* 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>
#include "libgimpmath/gimpmath.h"
#include "tools-types.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "gimpdrawtool.h"
enum
{
DRAW,
LAST_SIGNAL
};
static void gimp_draw_tool_class_init (GimpDrawToolClass *klass);
static void gimp_draw_tool_init (GimpDrawTool *draw_tool);
static void gimp_draw_tool_finalize (GObject *object);
static void gimp_draw_tool_control (GimpTool *tool,
ToolAction action,
GimpDisplay *gdisp);
static guint gimp_draw_tool_signals[LAST_SIGNAL] = { 0 };
static GimpToolClass *parent_class = NULL;
GType
gimp_draw_tool_get_type (void)
{
static GType tool_type = 0;
if (! tool_type)
{
static const GTypeInfo tool_info =
{
sizeof (GimpDrawToolClass),
(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,
};
tool_type = g_type_register_static (GIMP_TYPE_TOOL,
"GimpDrawTool",
&tool_info, 0);
}
return tool_type;
}
static void
gimp_draw_tool_class_init (GimpDrawToolClass *klass)
{
GObjectClass *object_class;
GimpToolClass *tool_class;
object_class = G_OBJECT_CLASS (klass);
tool_class = GIMP_TOOL_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
gimp_draw_tool_signals[DRAW] =
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);
object_class->finalize = gimp_draw_tool_finalize;
tool_class->control = gimp_draw_tool_control;
}
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;
}
static void
gimp_draw_tool_finalize (GObject *object)
{
GimpDrawTool *draw_tool;
draw_tool = GIMP_DRAW_TOOL (object);
if (draw_tool->gc)
{
g_object_unref (G_OBJECT (draw_tool->gc));
draw_tool->gc = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_draw_tool_control (GimpTool *tool,
ToolAction action,
GimpDisplay *gdisp)
{
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;
}
GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
}
void
gimp_draw_tool_start (GimpDrawTool *core,
GdkWindow *win)
{
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);
g_signal_emit (G_OBJECT (core), gimp_draw_tool_signals[DRAW], 0);
core->draw_state = VISIBLE;
}
void
gimp_draw_tool_stop (GimpDrawTool *core)
{
if (core->draw_state == INVISIBLE)
return;
g_signal_emit (G_OBJECT (core), gimp_draw_tool_signals[DRAW], 0);
core->draw_state = INVISIBLE;
}
void
gimp_draw_tool_resume (GimpDrawTool *core)
{
core->paused_count = (core->paused_count > 0) ? core->paused_count - 1 : 0;
if (core->paused_count == 0)
{
core->draw_state = VISIBLE;
g_signal_emit (G_OBJECT (core), gimp_draw_tool_signals[DRAW], 0);
}
}
void
gimp_draw_tool_pause (GimpDrawTool *core)
{
if (core->paused_count == 0)
{
core->draw_state = INVISIBLE;
g_signal_emit (G_OBJECT (core), gimp_draw_tool_signals[DRAW], 0);
}
core->paused_count++;
}
void
gimp_draw_tool_draw_handle (GimpDrawTool *draw_tool,
gdouble x,
gdouble y,
gint size,
gint type)
{
GimpTool *tool;
GimpDisplayShell *shell;
gdouble hx, hy;
gint filled;
tool = GIMP_TOOL (draw_tool);
shell = GIMP_DISPLAY_SHELL (tool->gdisp->shell);
gdisplay_transform_coords_f (tool->gdisp, x, y, &hx, &hy, TRUE);
hx = ROUND (hx);
hy = ROUND (hy);
filled = type % 2;
if (type < 2)
{
gdk_draw_rectangle (shell->canvas->window,
draw_tool->gc, filled,
hx - size / 2, hy - size / 2,
size, size);
}
else
{
gdk_draw_arc (shell->canvas->window,
draw_tool->gc, filled,
hx - size / 2, hy - size / 2,
size, size,
0, 360 * 64);
}
}
void
gimp_draw_tool_draw_lines (GimpDrawTool *draw_tool,
gdouble *points,
gint npoints,
gint filled)
{
GimpTool *tool;
GimpDisplayShell *shell;
GdkPoint *coords;
gint i;
gdouble sx, sy;
tool = GIMP_TOOL (draw_tool);
shell = GIMP_DISPLAY_SHELL (tool->gdisp->shell);
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);
}
if (filled)
{
gdk_draw_polygon (shell->canvas->window,
draw_tool->gc, TRUE,
coords, npoints);
}
else
{
gdk_draw_lines (shell->canvas->window,
draw_tool->gc,
coords, npoints);
}
g_free (coords);
}