1999-08-15 23:59:06 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
1999-08-19 02:48:35 +08:00
|
|
|
* Measure tool
|
|
|
|
* Copyright (C) 1999 Sven Neumann <sven@gimp.org>
|
|
|
|
*
|
1999-08-15 23:59:06 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
1999-08-22 13:56:27 +08:00
|
|
|
#include "config.h"
|
app/appenv.h New file. Includes <math.h>. Move G_PI, RINT(), ROUND() etc
1999-09-01 Tor Lillqvist <tml@iki.fi>
* app/appenv.h
* libgimp/gimpmath.h: New file. Includes <math.h>. Move G_PI,
RINT(), ROUND() etc from app/appenv.h here, so plug-ins can
use them, too. Remove some commented-out old stuff in appenv.h.
* libgimp/gimp.h: Include gimpmath.h.
* libgimp/gimp.c (gimp_main): Win32: Don't install signal
handlers, we can't do anything useful in the handler ourselves
anyway (it would be nice to print out a backtrace, but that seems
pretty hard to do, even if not impossible). Let Windows inform the
user about the crash. If the plug-in was compiled with MSVC, and
the user also has it, she is offered a chance to start the
debugger automatically anyway.
* app/*several*.c: Include gimpmath.h for G_PI etc. Don't include
<math.h>, as gimpmath.h includes it.
* plug-ins/*/*many*.c: Include config.h. Don't include <math.h>.
Remove all the duplicated definitions of G_PI and rint(). Use
RINT() instead of rint().
* app/app_procs.[ch]: app_exit() takes a gboolean.
* app/batch.c
* app/commands.c
* app/interface.c: Call app_exit() with FALSE or TRUE.
* app/main.c (on_error): Call gimp_fatal_error. (main): Don't
install any signal handler on Win32 here, either.
* app/errors.c (gimp_fatal_error, gimp_terminate): Win32: Format
the message and call MessageBox with it. g_on_error_query doesn't
do anything useful on Win32, and printf'ing a message to stdout or
stderr doesn't do anything, either, in a windowing application.
1999-09-02 04:30:56 +08:00
|
|
|
|
2001-02-04 12:51:17 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-01-24 07:56:18 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2001-05-21 21:58:46 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2001-01-24 07:56:18 +08:00
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "tools-types.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "gui/gui-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
2001-04-18 05:43:29 +08:00
|
|
|
#include "gui/info-dialog.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
|
|
|
|
#include "display/gimpdisplay.h"
|
2001-10-13 20:52:30 +08:00
|
|
|
#include "display/gimpdisplay-foreach.h"
|
2001-11-01 05:20:09 +08:00
|
|
|
#include "display/gimpdisplayshell.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
|
2001-04-18 05:43:29 +08:00
|
|
|
#include "gimpdrawtool.h"
|
2001-03-08 09:07:03 +08:00
|
|
|
#include "gimpmeasuretool.h"
|
2001-02-21 20:18:09 +08:00
|
|
|
#include "tool_manager.h"
|
|
|
|
#include "tool_options.h"
|
2001-02-18 03:49:44 +08:00
|
|
|
|
2001-04-18 05:43:29 +08:00
|
|
|
#include "undo.h"
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2001-02-24 05:32:47 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
2000-12-28 07:25:51 +08:00
|
|
|
|
1999-08-19 02:48:35 +08:00
|
|
|
/* definitions */
|
|
|
|
#define TARGET 8
|
|
|
|
#define ARC_RADIUS 30
|
|
|
|
#define ARC_RADIUS_2 1100
|
1999-08-15 23:59:06 +08:00
|
|
|
#define STATUSBAR_SIZE 128
|
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
/* maximum information buffer size */
|
|
|
|
#define MAX_INFO_BUF 16
|
|
|
|
|
1999-08-15 23:59:06 +08:00
|
|
|
/* the measure tool options */
|
1999-08-21 19:30:10 +08:00
|
|
|
typedef struct _MeasureOptions MeasureOptions;
|
2000-01-14 20:41:00 +08:00
|
|
|
|
1999-08-21 19:30:10 +08:00
|
|
|
struct _MeasureOptions
|
|
|
|
{
|
2001-07-18 04:50:01 +08:00
|
|
|
GimpToolOptions tool_options;
|
1999-08-21 19:30:10 +08:00
|
|
|
|
1999-12-18 00:37:50 +08:00
|
|
|
gboolean use_info_window;
|
|
|
|
gboolean use_info_window_d;
|
1999-08-21 19:30:10 +08:00
|
|
|
GtkWidget *use_info_window_w;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-02-21 20:18:09 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
static void gimp_measure_tool_class_init (GimpMeasureToolClass *klass);
|
|
|
|
static void gimp_measure_tool_init (GimpMeasureTool *tool);
|
2001-02-18 03:49:44 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
static void gimp_measure_tool_control (GimpTool *tool,
|
|
|
|
ToolAction action,
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpDisplay *gdisp);
|
2001-02-28 03:18:01 +08:00
|
|
|
static void gimp_measure_tool_button_press (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpDisplay *gdisp);
|
2001-02-28 03:18:01 +08:00
|
|
|
static void gimp_measure_tool_button_release (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpDisplay *gdisp);
|
2001-02-28 03:18:01 +08:00
|
|
|
static void gimp_measure_tool_motion (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpDisplay *gdisp);
|
2001-02-28 03:18:01 +08:00
|
|
|
static void gimp_measure_tool_cursor_update (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpDisplay *gdisp);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
static void gimp_measure_tool_draw (GimpDrawTool *draw_tool);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2001-04-01 04:41:39 +08:00
|
|
|
static gdouble measure_get_angle (gint dx,
|
|
|
|
gint dy,
|
|
|
|
gdouble xres,
|
|
|
|
gdouble yres);
|
2001-02-21 20:18:09 +08:00
|
|
|
static MeasureOptions * measure_tool_options_new (void);
|
2001-07-18 04:50:01 +08:00
|
|
|
static void measure_tool_options_reset (GimpToolOptions *tool_options);
|
2001-04-01 04:41:39 +08:00
|
|
|
static void measure_tool_info_window_close_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
2000-12-31 12:07:42 +08:00
|
|
|
static void measure_tool_info_update (void);
|
|
|
|
|
1999-08-21 19:30:10 +08:00
|
|
|
|
|
|
|
static MeasureOptions *measure_tool_options = NULL;
|
|
|
|
|
|
|
|
/* the measure tool info window */
|
2000-12-28 07:25:51 +08:00
|
|
|
static InfoDialog *measure_tool_info = NULL;
|
|
|
|
static gchar distance_buf[MAX_INFO_BUF];
|
|
|
|
static gchar angle_buf[MAX_INFO_BUF];
|
1999-08-21 19:30:10 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
static GimpDrawToolClass *parent_class = NULL;
|
2001-02-21 20:18:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2001-07-07 20:17:23 +08:00
|
|
|
gimp_measure_tool_register (Gimp *gimp)
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
2001-07-07 20:17:23 +08:00
|
|
|
tool_manager_register_tool (gimp,
|
|
|
|
GIMP_TYPE_MEASURE_TOOL,
|
2001-02-28 07:20:51 +08:00
|
|
|
FALSE,
|
2001-02-24 05:32:47 +08:00
|
|
|
"gimp:measure_tool",
|
|
|
|
_("Measure Tool"),
|
2001-06-15 00:28:06 +08:00
|
|
|
_("Measure angles and lengths"),
|
2001-02-21 20:18:09 +08:00
|
|
|
N_("/Tools/Measure"), NULL,
|
|
|
|
NULL, "tools/measure.html",
|
2001-08-06 00:08:19 +08:00
|
|
|
GIMP_STOCK_TOOL_MEASURE);
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
GType
|
2001-02-21 20:18:09 +08:00
|
|
|
gimp_measure_tool_get_type (void)
|
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static GType tool_type = 0;
|
2001-02-21 20:18:09 +08:00
|
|
|
|
|
|
|
if (! tool_type)
|
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static const GTypeInfo tool_info =
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
sizeof (GimpMeasureToolClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_measure_tool_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
2001-02-21 20:18:09 +08:00
|
|
|
sizeof (GimpMeasureTool),
|
2001-08-14 22:53:55 +08:00
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_measure_tool_init,
|
2001-02-21 20:18:09 +08:00
|
|
|
};
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
tool_type = g_type_register_static (GIMP_TYPE_DRAW_TOOL,
|
|
|
|
"GimpMeasureTool",
|
|
|
|
&tool_info, 0);
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return tool_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_measure_tool_class_init (GimpMeasureToolClass *klass)
|
|
|
|
{
|
2001-02-28 03:18:01 +08:00
|
|
|
GimpToolClass *tool_class;
|
|
|
|
GimpDrawToolClass *draw_tool_class;
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
tool_class->control = gimp_measure_tool_control;
|
|
|
|
tool_class->button_press = gimp_measure_tool_button_press;
|
|
|
|
tool_class->button_release = gimp_measure_tool_button_release;
|
|
|
|
tool_class->motion = gimp_measure_tool_motion;
|
|
|
|
tool_class->cursor_update = gimp_measure_tool_cursor_update;
|
|
|
|
|
|
|
|
draw_tool_class->draw = gimp_measure_tool_draw;
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_measure_tool_init (GimpMeasureTool *measure_tool)
|
|
|
|
{
|
|
|
|
GimpTool *tool;
|
|
|
|
|
|
|
|
tool = GIMP_TOOL (measure_tool);
|
|
|
|
|
|
|
|
/* The tool options */
|
|
|
|
if (! measure_tool_options)
|
|
|
|
{
|
|
|
|
measure_tool_options = measure_tool_options_new ();
|
|
|
|
|
2001-02-24 05:32:47 +08:00
|
|
|
tool_manager_register_tool_options (GIMP_TYPE_MEASURE_TOOL,
|
2001-07-18 04:50:01 +08:00
|
|
|
(GimpToolOptions *) measure_tool_options);
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
tool->preserve = TRUE; /* Preserve on drawable change */
|
|
|
|
}
|
|
|
|
|
1999-08-21 19:30:10 +08:00
|
|
|
static void
|
2001-10-29 19:47:11 +08:00
|
|
|
gimp_measure_tool_control (GimpTool *tool,
|
|
|
|
ToolAction action,
|
|
|
|
GimpDisplay *gdisp)
|
1999-08-21 19:30:10 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
GimpMeasureTool *measure_tool;
|
|
|
|
GimpDisplayShell *shell;
|
1999-08-21 19:30:10 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
measure_tool = GIMP_MEASURE_TOOL (tool);
|
1999-08-21 19:30:10 +08:00
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
|
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case PAUSE:
|
|
|
|
break;
|
1999-08-15 23:59:06 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
case RESUME:
|
|
|
|
break;
|
1999-08-19 02:48:35 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
case HALT:
|
2001-11-01 05:20:09 +08:00
|
|
|
gtk_statusbar_pop (GTK_STATUSBAR (shell->statusbar),
|
2001-02-28 03:18:01 +08:00
|
|
|
measure_tool->context_id);
|
|
|
|
tool->state = INACTIVE;
|
|
|
|
break;
|
2000-12-28 07:25:51 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
default:
|
|
|
|
break;
|
2000-12-28 07:25:51 +08:00
|
|
|
}
|
1999-08-19 02:48:35 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
if (GIMP_TOOL_CLASS (parent_class)->control)
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
|
1999-08-19 02:48:35 +08:00
|
|
|
}
|
1999-08-15 23:59:06 +08:00
|
|
|
|
|
|
|
static void
|
2001-02-28 03:18:01 +08:00
|
|
|
gimp_measure_tool_button_press (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpDisplay *gdisp)
|
1999-08-15 23:59:06 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
GimpMeasureTool *measure_tool;
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
gint x[3];
|
|
|
|
gint y[3];
|
|
|
|
gint i;
|
1999-08-21 19:30:10 +08:00
|
|
|
|
2001-02-21 20:18:09 +08:00
|
|
|
measure_tool = GIMP_MEASURE_TOOL (tool);
|
1999-08-15 23:59:06 +08:00
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
|
|
|
|
|
1999-08-19 02:48:35 +08:00
|
|
|
/* if we are changing displays, pop the statusbar of the old one */
|
2000-12-31 12:07:42 +08:00
|
|
|
if (tool->state == ACTIVE && gdisp != tool->gdisp)
|
1999-08-15 23:59:06 +08:00
|
|
|
{
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpDisplay *old_gdisp = tool->gdisp;
|
2000-12-28 07:25:51 +08:00
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
gtk_statusbar_pop (GTK_STATUSBAR (GIMP_DISPLAY_SHELL (old_gdisp->shell)->statusbar),
|
2000-01-14 20:41:00 +08:00
|
|
|
measure_tool->context_id);
|
2001-11-01 05:20:09 +08:00
|
|
|
|
|
|
|
gtk_statusbar_push (GTK_STATUSBAR (shell->statusbar),
|
1999-08-21 21:16:20 +08:00
|
|
|
measure_tool->context_id, (""));
|
|
|
|
}
|
|
|
|
|
1999-08-19 02:48:35 +08:00
|
|
|
measure_tool->function = CREATING;
|
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
if (tool->state == ACTIVE && gdisp == tool->gdisp)
|
1999-08-15 23:59:06 +08:00
|
|
|
{
|
2000-12-28 07:25:51 +08:00
|
|
|
/* if the cursor is in one of the handles,
|
|
|
|
* the new function will be moving or adding a new point or guide
|
|
|
|
*/
|
|
|
|
for (i = 0; i < measure_tool->num_points; i++)
|
1999-08-19 02:48:35 +08:00
|
|
|
{
|
2000-12-28 07:25:51 +08:00
|
|
|
gdisplay_transform_coords (gdisp,
|
|
|
|
measure_tool->x[i], measure_tool->y[i],
|
|
|
|
&x[i], &y[i], FALSE);
|
|
|
|
|
2000-01-14 20:41:00 +08:00
|
|
|
if (bevent->x == CLAMP (bevent->x, x[i] - TARGET, x[i] + TARGET) &&
|
|
|
|
bevent->y == CLAMP (bevent->y, y[i] - TARGET, y[i] + TARGET))
|
1999-08-19 02:48:35 +08:00
|
|
|
{
|
1999-08-20 00:26:47 +08:00
|
|
|
if (bevent->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK))
|
|
|
|
{
|
2001-05-16 03:10:57 +08:00
|
|
|
gboolean undo_group;
|
|
|
|
GimpGuide *guide;
|
2000-04-13 08:38:04 +08:00
|
|
|
|
|
|
|
undo_group = (bevent->state & GDK_CONTROL_MASK &&
|
|
|
|
bevent->state & GDK_MOD1_MASK &&
|
|
|
|
(measure_tool->y[i] ==
|
|
|
|
CLAMP (measure_tool->y[i],
|
|
|
|
0, gdisp->gimage->height)) &&
|
|
|
|
(measure_tool->x[i] ==
|
|
|
|
CLAMP (measure_tool->x[i],
|
|
|
|
0, gdisp->gimage->width)));
|
|
|
|
|
|
|
|
if (undo_group)
|
2000-04-13 08:23:10 +08:00
|
|
|
undo_push_group_start (gdisp->gimage, GUIDE_UNDO);
|
|
|
|
|
1999-08-21 21:16:20 +08:00
|
|
|
if (bevent->state & GDK_CONTROL_MASK &&
|
2000-04-13 08:38:04 +08:00
|
|
|
(measure_tool->y[i] ==
|
|
|
|
CLAMP (measure_tool->y[i], 0, gdisp->gimage->height)))
|
1999-08-20 00:26:47 +08:00
|
|
|
{
|
|
|
|
guide = gimp_image_add_hguide (gdisp->gimage);
|
1999-09-21 05:08:53 +08:00
|
|
|
undo_push_guide (gdisp->gimage, guide);
|
1999-08-21 19:30:10 +08:00
|
|
|
guide->position = measure_tool->y[i];
|
1999-08-20 00:26:47 +08:00
|
|
|
gdisplays_expose_guide (gdisp->gimage, guide);
|
2000-04-13 08:38:04 +08:00
|
|
|
}
|
|
|
|
|
1999-08-21 21:16:20 +08:00
|
|
|
if (bevent->state & GDK_MOD1_MASK &&
|
2000-04-13 08:38:04 +08:00
|
|
|
(measure_tool->x[i] ==
|
|
|
|
CLAMP (measure_tool->x[i], 0, gdisp->gimage->width)))
|
1999-08-20 00:26:47 +08:00
|
|
|
{
|
|
|
|
guide = gimp_image_add_vguide (gdisp->gimage);
|
1999-09-21 05:08:53 +08:00
|
|
|
undo_push_guide (gdisp->gimage, guide);
|
1999-08-21 19:30:10 +08:00
|
|
|
guide->position = measure_tool->x[i];
|
1999-08-20 00:26:47 +08:00
|
|
|
gdisplays_expose_guide (gdisp->gimage, guide);
|
|
|
|
}
|
2000-04-13 08:23:10 +08:00
|
|
|
|
2000-04-13 08:38:04 +08:00
|
|
|
if (undo_group)
|
2000-04-13 08:23:10 +08:00
|
|
|
undo_push_group_end (gdisp->gimage);
|
|
|
|
|
1999-08-20 00:26:47 +08:00
|
|
|
gdisplays_flush ();
|
|
|
|
measure_tool->function = GUIDING;
|
|
|
|
break;
|
|
|
|
}
|
1999-08-19 02:48:35 +08:00
|
|
|
measure_tool->function = (bevent->state & GDK_SHIFT_MASK) ? ADDING : MOVING;
|
|
|
|
measure_tool->point = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-12-28 07:25:51 +08:00
|
|
|
|
1999-08-19 02:48:35 +08:00
|
|
|
/* adding to the middle point makes no sense */
|
|
|
|
if (i == 0 && measure_tool->function == ADDING && measure_tool->num_points == 3)
|
|
|
|
measure_tool->function = MOVING;
|
2000-04-13 05:21:36 +08:00
|
|
|
|
|
|
|
/* if the function is still CREATING, we are outside the handles */
|
|
|
|
if (measure_tool->function == CREATING)
|
|
|
|
{
|
|
|
|
if (measure_tool->num_points > 1 && bevent->state & GDK_MOD1_MASK)
|
|
|
|
{
|
|
|
|
measure_tool->function = MOVING_ALL;
|
|
|
|
gdisplay_untransform_coords (gdisp, bevent->x, bevent->y,
|
|
|
|
&measure_tool->last_x, &measure_tool->last_y,
|
|
|
|
TRUE, FALSE);
|
|
|
|
}
|
|
|
|
}
|
1999-08-15 23:59:06 +08:00
|
|
|
}
|
1999-08-19 02:48:35 +08:00
|
|
|
|
1999-08-15 23:59:06 +08:00
|
|
|
if (measure_tool->function == CREATING)
|
|
|
|
{
|
|
|
|
if (tool->state == ACTIVE)
|
2000-03-02 08:03:28 +08:00
|
|
|
{
|
|
|
|
/* reset everything */
|
2001-02-28 03:18:01 +08:00
|
|
|
gimp_draw_tool_stop (GIMP_DRAW_TOOL (measure_tool));
|
2000-03-02 08:03:28 +08:00
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
gtk_statusbar_pop (GTK_STATUSBAR (shell->statusbar),
|
2000-12-28 07:25:51 +08:00
|
|
|
measure_tool->context_id);
|
2001-11-01 05:20:09 +08:00
|
|
|
gtk_statusbar_push (GTK_STATUSBAR (shell->statusbar),
|
2000-12-28 07:25:51 +08:00
|
|
|
measure_tool->context_id, "");
|
1999-08-21 21:16:20 +08:00
|
|
|
|
2000-03-02 08:03:28 +08:00
|
|
|
distance_buf[0] = '\0';
|
|
|
|
angle_buf[0] = '\0';
|
|
|
|
if (measure_tool_info)
|
|
|
|
measure_tool_info_update ();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* initialize the statusbar display */
|
2001-02-27 13:21:12 +08:00
|
|
|
measure_tool->context_id =
|
2001-11-01 05:20:09 +08:00
|
|
|
gtk_statusbar_get_context_id (GTK_STATUSBAR (shell->statusbar),
|
2000-12-28 07:25:51 +08:00
|
|
|
"measure");
|
2000-03-02 08:03:28 +08:00
|
|
|
}
|
2001-02-27 13:21:12 +08:00
|
|
|
|
1999-08-19 02:48:35 +08:00
|
|
|
/* set the first point and go into ADDING mode */
|
2001-02-27 13:21:12 +08:00
|
|
|
gdisplay_untransform_coords (gdisp, bevent->x, bevent->y,
|
2000-12-28 07:25:51 +08:00
|
|
|
&measure_tool->x[0], &measure_tool->y[0],
|
|
|
|
TRUE, FALSE);
|
|
|
|
measure_tool->point = 0;
|
1999-08-19 02:48:35 +08:00
|
|
|
measure_tool->num_points = 1;
|
2000-12-28 07:25:51 +08:00
|
|
|
measure_tool->function = ADDING;
|
1999-08-15 23:59:06 +08:00
|
|
|
|
|
|
|
/* set the gdisplay */
|
2000-12-31 12:07:42 +08:00
|
|
|
tool->gdisp = gdisp;
|
1999-08-15 23:59:06 +08:00
|
|
|
|
|
|
|
/* start drawing the measure tool */
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), shell->canvas->window);
|
1999-08-15 23:59:06 +08:00
|
|
|
}
|
1999-08-21 19:30:10 +08:00
|
|
|
|
|
|
|
/* create the info window if necessary */
|
2000-12-28 07:25:51 +08:00
|
|
|
if (! measure_tool_info &&
|
2000-04-13 05:21:36 +08:00
|
|
|
(measure_tool_options->use_info_window ||
|
2001-11-01 05:20:09 +08:00
|
|
|
! GTK_WIDGET_VISIBLE (shell->statusarea)))
|
2000-04-13 05:21:36 +08:00
|
|
|
{
|
|
|
|
measure_tool_info = info_dialog_new (_("Measure Tool"),
|
2001-02-22 05:56:39 +08:00
|
|
|
tool_manager_help_func, NULL);
|
2000-04-13 05:21:36 +08:00
|
|
|
info_dialog_add_label (measure_tool_info, _("Distance:"), distance_buf);
|
|
|
|
info_dialog_add_label (measure_tool_info, _("Angle:"), angle_buf);
|
2000-12-28 07:25:51 +08:00
|
|
|
|
2001-09-21 18:47:19 +08:00
|
|
|
gimp_dialog_create_action_area (GIMP_DIALOG (measure_tool_info->shell),
|
2000-12-28 07:25:51 +08:00
|
|
|
|
2001-08-04 03:43:19 +08:00
|
|
|
GTK_STOCK_CLOSE,
|
2000-12-28 07:25:51 +08:00
|
|
|
measure_tool_info_window_close_callback,
|
2000-04-13 05:21:36 +08:00
|
|
|
measure_tool_info, NULL, NULL, TRUE, FALSE,
|
2000-12-28 07:25:51 +08:00
|
|
|
|
2000-04-13 05:21:36 +08:00
|
|
|
NULL);
|
|
|
|
}
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
gdk_pointer_grab (shell->canvas->window, FALSE,
|
2000-01-14 20:41:00 +08:00
|
|
|
GDK_POINTER_MOTION_HINT_MASK |
|
|
|
|
GDK_BUTTON1_MOTION_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK,
|
1999-08-15 23:59:06 +08:00
|
|
|
NULL, NULL, bevent->time);
|
2001-11-01 05:20:09 +08:00
|
|
|
|
1999-08-15 23:59:06 +08:00
|
|
|
tool->state = ACTIVE;
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2000-01-14 20:41:00 +08:00
|
|
|
/* set the pointer to the crosshair,
|
|
|
|
* so one actually sees the cursor position
|
|
|
|
*/
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_shell_install_tool_cursor (shell,
|
|
|
|
GIMP_CROSSHAIR_SMALL_CURSOR,
|
|
|
|
GIMP_MEASURE_TOOL_CURSOR,
|
|
|
|
GIMP_CURSOR_MODIFIER_NONE);
|
1999-08-15 23:59:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-02-28 03:18:01 +08:00
|
|
|
gimp_measure_tool_button_release (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpDisplay *gdisp)
|
1999-08-15 23:59:06 +08:00
|
|
|
{
|
2001-02-18 03:49:44 +08:00
|
|
|
GimpMeasureTool *measure_tool;
|
1999-08-15 23:59:06 +08:00
|
|
|
|
2001-02-21 20:18:09 +08:00
|
|
|
measure_tool = GIMP_MEASURE_TOOL (tool);
|
2001-02-27 13:21:12 +08:00
|
|
|
|
1999-08-16 02:44:15 +08:00
|
|
|
measure_tool->function = FINISHED;
|
1999-08-15 23:59:06 +08:00
|
|
|
|
|
|
|
gdk_pointer_ungrab (bevent->time);
|
|
|
|
gdk_flush ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-02-28 03:18:01 +08:00
|
|
|
gimp_measure_tool_motion (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpDisplay *gdisp)
|
1999-08-15 23:59:06 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
GimpMeasureTool *measure_tool;
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
gint x, y;
|
|
|
|
gint ax, ay;
|
|
|
|
gint bx, by;
|
|
|
|
gint dx, dy;
|
|
|
|
gint i;
|
|
|
|
gint tmp;
|
|
|
|
gdouble angle;
|
|
|
|
gdouble distance;
|
|
|
|
gchar status_str[STATUSBAR_SIZE];
|
1999-08-15 23:59:06 +08:00
|
|
|
|
2001-02-21 20:18:09 +08:00
|
|
|
measure_tool = GIMP_MEASURE_TOOL (tool);
|
1999-08-15 23:59:06 +08:00
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
|
|
|
|
|
1999-08-15 23:59:06 +08:00
|
|
|
/* undraw the current tool */
|
2001-02-27 13:21:12 +08:00
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL(measure_tool));
|
1999-08-15 23:59:06 +08:00
|
|
|
|
1999-08-16 04:12:44 +08:00
|
|
|
/* get the coordinates */
|
1999-08-21 19:30:10 +08:00
|
|
|
gdisplay_untransform_coords (gdisp, mevent->x, mevent->y, &x, &y, TRUE, FALSE);
|
2000-12-28 07:25:51 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
/*
|
1999-08-19 02:48:35 +08:00
|
|
|
* A few comments here, because this routine looks quite weird at first ...
|
|
|
|
*
|
2001-02-27 13:21:12 +08:00
|
|
|
* The goal is to keep point 0, called the start point, to be always the one
|
1999-08-19 02:48:35 +08:00
|
|
|
* in the middle or, if there are only two points, the one that is fixed.
|
|
|
|
* The angle is then always measured at this point.
|
|
|
|
*/
|
|
|
|
|
1999-08-15 23:59:06 +08:00
|
|
|
switch (measure_tool->function)
|
|
|
|
{
|
1999-08-19 02:48:35 +08:00
|
|
|
case ADDING:
|
|
|
|
switch (measure_tool->point)
|
1999-08-15 23:59:06 +08:00
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
case 0: /* we are adding to the start point */
|
1999-08-19 02:48:35 +08:00
|
|
|
break;
|
|
|
|
case 1: /* we are adding to the end point, make it the new start point */
|
|
|
|
tmp = measure_tool->x[0];
|
|
|
|
measure_tool->x[0] = measure_tool->x[1];
|
|
|
|
measure_tool->x[1] = tmp;
|
|
|
|
tmp = measure_tool->y[0];
|
|
|
|
measure_tool->y[0] = measure_tool->y[1];
|
|
|
|
measure_tool->y[1] = tmp;
|
|
|
|
break;
|
|
|
|
case 2: /* we are adding to the third point, make it the new start point */
|
|
|
|
measure_tool->x[1] = measure_tool->x[0];
|
|
|
|
measure_tool->y[1] = measure_tool->y[0];
|
|
|
|
measure_tool->x[0] = measure_tool->x[2];
|
|
|
|
measure_tool->y[0] = measure_tool->y[2];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
1999-08-15 23:59:06 +08:00
|
|
|
}
|
1999-08-19 02:48:35 +08:00
|
|
|
measure_tool->num_points = MIN (measure_tool->num_points + 1, 3);
|
|
|
|
measure_tool->point = measure_tool->num_points - 1;
|
|
|
|
measure_tool->function = MOVING;
|
|
|
|
/* no, don't break here! */
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
|
|
case MOVING:
|
1999-08-19 02:48:35 +08:00
|
|
|
/* if we are moving the start point and only have two, make it the end point */
|
|
|
|
if (measure_tool->num_points == 2 && measure_tool->point == 0)
|
|
|
|
{
|
|
|
|
tmp = measure_tool->x[0];
|
|
|
|
measure_tool->x[0] = measure_tool->x[1];
|
|
|
|
measure_tool->x[1] = tmp;
|
|
|
|
tmp = measure_tool->y[0];
|
|
|
|
measure_tool->y[0] = measure_tool->y[1];
|
|
|
|
measure_tool->y[1] = tmp;
|
|
|
|
measure_tool->point = 1;
|
|
|
|
}
|
|
|
|
i = measure_tool->point;
|
1999-08-15 23:59:06 +08:00
|
|
|
|
1999-08-19 02:48:35 +08:00
|
|
|
measure_tool->x[i] = x;
|
|
|
|
measure_tool->y[i] = y;
|
1999-08-16 05:10:29 +08:00
|
|
|
|
|
|
|
/* restrict to horizontal/vertical movements, if modifiers are pressed */
|
1999-08-15 23:59:06 +08:00
|
|
|
if (mevent->state & GDK_MOD1_MASK)
|
|
|
|
{
|
|
|
|
if (mevent->state & GDK_CONTROL_MASK)
|
|
|
|
{
|
1999-08-19 02:48:35 +08:00
|
|
|
dx = measure_tool->x[i] - measure_tool->x[0];
|
|
|
|
dy = measure_tool->y[i] - measure_tool->y[0];
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
|
|
measure_tool->x[i] = measure_tool->x[0] +
|
1999-09-21 17:11:42 +08:00
|
|
|
(dx > 0 ? MAX (abs (dx), abs (dy)) : - MAX (abs (dx), abs (dy)));
|
2001-02-27 13:21:12 +08:00
|
|
|
measure_tool->y[i] = measure_tool->y[0] +
|
1999-09-21 17:11:42 +08:00
|
|
|
(dy > 0 ? MAX (abs (dx), abs (dy)) : - MAX (abs (dx), abs (dy)));
|
1999-08-15 23:59:06 +08:00
|
|
|
}
|
|
|
|
else
|
1999-08-19 02:48:35 +08:00
|
|
|
measure_tool->x[i] = measure_tool->x[0];
|
1999-08-15 23:59:06 +08:00
|
|
|
}
|
|
|
|
else if (mevent->state & GDK_CONTROL_MASK)
|
1999-08-19 02:48:35 +08:00
|
|
|
measure_tool->y[i] = measure_tool->y[0];
|
1999-08-15 23:59:06 +08:00
|
|
|
break;
|
|
|
|
|
2000-04-13 05:21:36 +08:00
|
|
|
case MOVING_ALL:
|
|
|
|
dx = x - measure_tool->last_x;
|
|
|
|
dy = y - measure_tool->last_y;
|
|
|
|
for (i = 0; i < measure_tool->num_points; i++)
|
|
|
|
{
|
|
|
|
measure_tool->x[i] += dx;
|
|
|
|
measure_tool->y[i] += dy;
|
|
|
|
}
|
|
|
|
measure_tool->last_x = x;
|
|
|
|
measure_tool->last_y = y;
|
|
|
|
break;
|
1999-08-19 02:48:35 +08:00
|
|
|
|
2000-04-13 05:21:36 +08:00
|
|
|
default:
|
|
|
|
break;
|
1999-08-19 02:48:35 +08:00
|
|
|
}
|
|
|
|
|
2000-04-13 05:21:36 +08:00
|
|
|
if (measure_tool->function == MOVING)
|
1999-08-15 23:59:06 +08:00
|
|
|
{
|
2000-04-13 05:21:36 +08:00
|
|
|
/* calculate distance and angle */
|
|
|
|
ax = measure_tool->x[1] - measure_tool->x[0];
|
|
|
|
ay = measure_tool->y[1] - measure_tool->y[0];
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2000-04-13 05:21:36 +08:00
|
|
|
if (measure_tool->num_points == 3)
|
1999-08-21 19:30:10 +08:00
|
|
|
{
|
2000-04-13 05:21:36 +08:00
|
|
|
bx = measure_tool->x[2] - measure_tool->x[0];
|
|
|
|
by = measure_tool->y[2] - measure_tool->y[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bx = 0;
|
|
|
|
by = 0;
|
1999-08-21 19:30:10 +08:00
|
|
|
}
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2000-04-13 05:21:36 +08:00
|
|
|
if (gdisp->dot_for_dot)
|
1999-08-21 19:30:10 +08:00
|
|
|
{
|
2000-04-13 05:21:36 +08:00
|
|
|
distance = sqrt (SQR (ax - bx) + SQR (ay - by));
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2000-04-13 05:21:36 +08:00
|
|
|
if (measure_tool->num_points != 3)
|
|
|
|
bx = ax > 0 ? 1 : -1;
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2000-04-13 05:21:36 +08:00
|
|
|
measure_tool->angle1 = measure_get_angle (ax, ay, 1.0, 1.0);
|
|
|
|
measure_tool->angle2 = measure_get_angle (bx, by, 1.0, 1.0);
|
|
|
|
angle = fabs (measure_tool->angle1 - measure_tool->angle2);
|
|
|
|
if (angle > 180.0)
|
|
|
|
angle = fabs (360.0 - angle);
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2000-04-13 05:21:36 +08:00
|
|
|
g_snprintf (status_str, STATUSBAR_SIZE, "%.1f %s, %.2f %s",
|
|
|
|
distance, _("pixels"), angle, _("degrees"));
|
2001-02-27 13:21:12 +08:00
|
|
|
|
2000-04-13 05:21:36 +08:00
|
|
|
if (measure_tool_options)
|
|
|
|
{
|
|
|
|
g_snprintf (distance_buf, MAX_INFO_BUF, "%.1f %s", distance, _("pixels"));
|
|
|
|
g_snprintf (angle_buf, MAX_INFO_BUF, "%.2f %s", angle, _("degrees"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* show real world units */
|
|
|
|
{
|
2000-12-28 07:25:51 +08:00
|
|
|
gchar *format_str =
|
|
|
|
g_strdup_printf ("%%.%df %s, %%.2f %s",
|
|
|
|
gimp_unit_get_digits (gdisp->gimage->unit),
|
|
|
|
gimp_unit_get_symbol (gdisp->gimage->unit),
|
|
|
|
_("degrees"));
|
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
distance = gimp_unit_get_factor (gdisp->gimage->unit) *
|
2000-04-13 05:21:36 +08:00
|
|
|
sqrt (SQR ((gdouble)(ax - bx) / gdisp->gimage->xresolution) +
|
|
|
|
SQR ((gdouble)(ay - by) / gdisp->gimage->yresolution));
|
2000-12-28 07:25:51 +08:00
|
|
|
|
2000-04-13 05:21:36 +08:00
|
|
|
if (measure_tool->num_points != 3)
|
|
|
|
bx = ax > 0 ? 1 : -1;
|
2000-12-28 07:25:51 +08:00
|
|
|
|
2001-02-27 13:21:12 +08:00
|
|
|
measure_tool->angle1 = measure_get_angle (ax, ay,
|
|
|
|
gdisp->gimage->xresolution,
|
|
|
|
gdisp->gimage->yresolution);
|
2000-04-13 05:21:36 +08:00
|
|
|
measure_tool->angle2 = measure_get_angle (bx, by,
|
2001-02-27 13:21:12 +08:00
|
|
|
gdisp->gimage->xresolution,
|
2000-04-13 05:21:36 +08:00
|
|
|
gdisp->gimage->yresolution);
|
2001-02-27 13:21:12 +08:00
|
|
|
angle = fabs (measure_tool->angle1 - measure_tool->angle2);
|
2000-04-13 05:21:36 +08:00
|
|
|
if (angle > 180.0)
|
|
|
|
angle = fabs (360.0 - angle);
|
2000-12-28 07:25:51 +08:00
|
|
|
|
2000-04-13 05:21:36 +08:00
|
|
|
g_snprintf (status_str, STATUSBAR_SIZE, format_str, distance , angle);
|
1999-08-21 19:30:10 +08:00
|
|
|
g_free (format_str);
|
2000-12-28 07:25:51 +08:00
|
|
|
|
2000-04-13 05:21:36 +08:00
|
|
|
if (measure_tool_options)
|
|
|
|
{
|
2000-12-28 07:25:51 +08:00
|
|
|
gchar *format_str =
|
|
|
|
g_strdup_printf ("%%.%df %s",
|
|
|
|
gimp_unit_get_digits (gdisp->gimage->unit),
|
|
|
|
gimp_unit_get_symbol (gdisp->gimage->unit));
|
2000-04-13 05:21:36 +08:00
|
|
|
g_snprintf (distance_buf, MAX_INFO_BUF, format_str, distance);
|
|
|
|
g_snprintf (angle_buf, MAX_INFO_BUF, "%.2f %s", angle, _("degrees"));
|
|
|
|
g_free (format_str);
|
|
|
|
}
|
1999-08-21 19:30:10 +08:00
|
|
|
}
|
2000-12-28 07:25:51 +08:00
|
|
|
|
2000-04-13 05:21:36 +08:00
|
|
|
/* show info in statusbar */
|
2001-11-01 05:20:09 +08:00
|
|
|
gtk_statusbar_pop (GTK_STATUSBAR (shell->statusbar),
|
2000-12-28 07:25:51 +08:00
|
|
|
measure_tool->context_id);
|
2001-11-01 05:20:09 +08:00
|
|
|
gtk_statusbar_push (GTK_STATUSBAR (shell->statusbar),
|
2000-12-28 07:25:51 +08:00
|
|
|
measure_tool->context_id,
|
2000-04-13 05:21:36 +08:00
|
|
|
status_str);
|
2000-12-28 07:25:51 +08:00
|
|
|
|
2000-04-13 05:21:36 +08:00
|
|
|
/* and in the info window */
|
|
|
|
if (measure_tool_info)
|
|
|
|
measure_tool_info_update ();
|
1999-08-15 23:59:06 +08:00
|
|
|
|
2000-04-13 05:21:36 +08:00
|
|
|
} /* measure_tool->function == MOVING */
|
2000-12-28 07:25:51 +08:00
|
|
|
|
1999-08-15 23:59:06 +08:00
|
|
|
/* redraw the current tool */
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (measure_tool));
|
1999-08-15 23:59:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-02-28 03:18:01 +08:00
|
|
|
gimp_measure_tool_cursor_update (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpDisplay *gdisp)
|
1999-08-15 23:59:06 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
GimpMeasureTool *measure_tool;
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
gint x[3];
|
|
|
|
gint y[3];
|
|
|
|
gint i;
|
|
|
|
gboolean in_handle = FALSE;
|
2001-02-25 03:29:47 +08:00
|
|
|
GdkCursorType ctype = GIMP_CROSSHAIR_SMALL_CURSOR;
|
|
|
|
GimpCursorModifier cmodifier = GIMP_CURSOR_MODIFIER_NONE;
|
2000-06-14 18:59:16 +08:00
|
|
|
|
2001-02-21 20:18:09 +08:00
|
|
|
measure_tool = GIMP_MEASURE_TOOL (tool);
|
1999-08-15 23:59:06 +08:00
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
|
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
if (tool->state == ACTIVE && tool->gdisp == gdisp)
|
1999-08-15 23:59:06 +08:00
|
|
|
{
|
2000-04-13 05:21:36 +08:00
|
|
|
for (i = 0; i < measure_tool->num_points; i++)
|
1999-08-19 02:48:35 +08:00
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
gdisplay_transform_coords (gdisp, measure_tool->x[i], measure_tool->y[i],
|
|
|
|
&x[i], &y[i], FALSE);
|
|
|
|
|
2000-01-26 07:06:12 +08:00
|
|
|
if (mevent->x == CLAMP (mevent->x, x[i] - TARGET, x[i] + TARGET) &&
|
|
|
|
mevent->y == CLAMP (mevent->y, y[i] - TARGET, y[i] + TARGET))
|
1999-08-20 00:26:47 +08:00
|
|
|
{
|
2000-04-13 05:21:36 +08:00
|
|
|
in_handle = TRUE;
|
2000-12-28 07:25:51 +08:00
|
|
|
|
1999-08-20 00:26:47 +08:00
|
|
|
if (mevent->state & GDK_CONTROL_MASK)
|
|
|
|
{
|
|
|
|
if (mevent->state & GDK_MOD1_MASK)
|
|
|
|
ctype = GDK_BOTTOM_RIGHT_CORNER;
|
|
|
|
else
|
|
|
|
ctype = GDK_BOTTOM_SIDE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (mevent->state & GDK_MOD1_MASK)
|
|
|
|
{
|
|
|
|
ctype = GDK_RIGHT_SIDE;
|
|
|
|
break;
|
|
|
|
}
|
2000-04-13 05:21:36 +08:00
|
|
|
|
2000-06-14 18:59:16 +08:00
|
|
|
if (mevent->state & GDK_SHIFT_MASK)
|
2001-02-25 03:29:47 +08:00
|
|
|
cmodifier = GIMP_CURSOR_MODIFIER_PLUS;
|
2000-06-14 18:59:16 +08:00
|
|
|
else
|
2001-02-25 03:29:47 +08:00
|
|
|
cmodifier = GIMP_CURSOR_MODIFIER_MOVE;
|
2000-04-13 05:21:36 +08:00
|
|
|
|
2000-06-14 18:59:16 +08:00
|
|
|
if (i == 0 && measure_tool->num_points == 3 &&
|
2001-02-25 03:29:47 +08:00
|
|
|
cmodifier == GIMP_CURSOR_MODIFIER_PLUS)
|
|
|
|
cmodifier = GIMP_CURSOR_MODIFIER_MOVE;
|
1999-08-20 00:26:47 +08:00
|
|
|
break;
|
|
|
|
}
|
1999-08-19 02:48:35 +08:00
|
|
|
}
|
2000-04-13 05:21:36 +08:00
|
|
|
|
2000-06-14 18:59:16 +08:00
|
|
|
if (!in_handle && measure_tool->num_points > 1 &&
|
|
|
|
mevent->state & GDK_MOD1_MASK)
|
2001-02-25 03:29:47 +08:00
|
|
|
cmodifier = GIMP_CURSOR_MODIFIER_MOVE;
|
1999-08-15 23:59:06 +08:00
|
|
|
}
|
2000-06-14 18:59:16 +08:00
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_shell_install_tool_cursor (shell,
|
|
|
|
ctype,
|
|
|
|
GIMP_MEASURE_TOOL_CURSOR,
|
|
|
|
cmodifier);
|
1999-08-15 23:59:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-02-28 03:18:01 +08:00
|
|
|
gimp_measure_tool_draw (GimpDrawTool *draw_tool)
|
1999-08-15 23:59:06 +08:00
|
|
|
{
|
2001-02-18 03:49:44 +08:00
|
|
|
GimpMeasureTool *measure_tool;
|
2001-02-28 03:18:01 +08:00
|
|
|
GimpTool *tool;
|
|
|
|
gint x[3];
|
|
|
|
gint y[3];
|
|
|
|
gint i;
|
|
|
|
gint angle1, angle2;
|
|
|
|
gint draw_arc = 0;
|
1999-08-15 23:59:06 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
measure_tool = GIMP_MEASURE_TOOL (draw_tool);
|
|
|
|
tool = GIMP_TOOL (draw_tool);
|
1999-08-15 23:59:06 +08:00
|
|
|
|
1999-08-19 02:48:35 +08:00
|
|
|
for (i = 0; i < measure_tool->num_points; i++)
|
1999-08-16 02:44:15 +08:00
|
|
|
{
|
2000-12-31 12:07:42 +08:00
|
|
|
gdisplay_transform_coords (tool->gdisp,
|
|
|
|
measure_tool->x[i], measure_tool->y[i],
|
1999-08-21 21:16:20 +08:00
|
|
|
&x[i], &y[i], FALSE);
|
1999-08-19 02:48:35 +08:00
|
|
|
if (i == 0 && measure_tool->num_points == 3)
|
1999-08-16 05:10:29 +08:00
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
gdk_draw_arc (draw_tool->win, draw_tool->gc, FALSE,
|
1999-08-19 02:48:35 +08:00
|
|
|
x[i] - (TARGET >> 1), y[i] - (TARGET >> 1),
|
|
|
|
TARGET, TARGET, 0, 23040);
|
1999-08-16 05:10:29 +08:00
|
|
|
}
|
1999-08-19 02:48:35 +08:00
|
|
|
else
|
1999-08-16 02:44:15 +08:00
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
gdk_draw_line (draw_tool->win, draw_tool->gc,
|
|
|
|
x[i] - TARGET, y[i],
|
1999-08-19 02:48:35 +08:00
|
|
|
x[i] + TARGET, y[i]);
|
2001-02-27 13:21:12 +08:00
|
|
|
gdk_draw_line (draw_tool->win, draw_tool->gc,
|
|
|
|
x[i], y[i] - TARGET,
|
1999-08-19 02:48:35 +08:00
|
|
|
x[i], y[i] + TARGET);
|
1999-08-16 02:44:15 +08:00
|
|
|
}
|
1999-08-19 02:48:35 +08:00
|
|
|
if (i > 0)
|
1999-08-16 02:44:15 +08:00
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
gdk_draw_line (draw_tool->win, draw_tool->gc,
|
1999-08-19 02:48:35 +08:00
|
|
|
x[0], y[0],
|
|
|
|
x[i], y[i]);
|
|
|
|
/* only draw the arc if the lines are long enough */
|
|
|
|
if ((SQR (x[i] - x[0]) + SQR (y[i] - y[0])) > ARC_RADIUS_2)
|
|
|
|
draw_arc++;
|
1999-08-16 02:44:15 +08:00
|
|
|
}
|
|
|
|
}
|
2001-02-27 13:21:12 +08:00
|
|
|
|
1999-08-19 02:48:35 +08:00
|
|
|
if (measure_tool->num_points > 1 && draw_arc == measure_tool->num_points - 1)
|
1999-08-16 02:44:15 +08:00
|
|
|
{
|
1999-08-19 02:48:35 +08:00
|
|
|
angle1 = measure_tool->angle2 * 64.0;
|
|
|
|
angle2 = (measure_tool->angle1 - measure_tool->angle2) * 64.0;
|
2001-02-27 13:21:12 +08:00
|
|
|
|
1999-08-19 02:48:35 +08:00
|
|
|
if (angle2 > 11520)
|
|
|
|
angle2 -= 23040;
|
|
|
|
if (angle2 < -11520)
|
|
|
|
angle2 += 23040;
|
2001-02-27 13:21:12 +08:00
|
|
|
|
1999-08-19 02:48:35 +08:00
|
|
|
if (angle2 != 0)
|
|
|
|
{
|
2001-02-27 13:21:12 +08:00
|
|
|
gdk_draw_arc (draw_tool->win, draw_tool->gc, FALSE,
|
1999-08-19 02:48:35 +08:00
|
|
|
x[0] - ARC_RADIUS, y[0] - ARC_RADIUS,
|
2001-02-27 13:21:12 +08:00
|
|
|
2 * ARC_RADIUS, 2 * ARC_RADIUS,
|
|
|
|
angle1, angle2);
|
2000-12-28 07:25:51 +08:00
|
|
|
|
1999-08-19 02:48:35 +08:00
|
|
|
if (measure_tool->num_points == 2)
|
2001-02-27 13:21:12 +08:00
|
|
|
gdk_draw_line (draw_tool->win, draw_tool->gc,
|
1999-08-19 02:48:35 +08:00
|
|
|
x[0], y[0],
|
2001-02-27 13:21:12 +08:00
|
|
|
x[1] - x[0] <= 0 ? x[0] - ARC_RADIUS - (TARGET >> 1) :
|
|
|
|
x[0] + ARC_RADIUS + (TARGET >> 1),
|
1999-08-19 02:48:35 +08:00
|
|
|
y[0]);
|
|
|
|
}
|
1999-08-16 02:44:15 +08:00
|
|
|
}
|
1999-08-15 23:59:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-07-18 04:50:01 +08:00
|
|
|
measure_tool_options_reset (GimpToolOptions *tool_options)
|
1999-08-15 23:59:06 +08:00
|
|
|
{
|
2001-04-01 04:41:39 +08:00
|
|
|
MeasureOptions *options;
|
|
|
|
|
|
|
|
options = (MeasureOptions *) tool_options;
|
1999-08-15 23:59:06 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->use_info_window_w),
|
|
|
|
options->use_info_window_d);
|
|
|
|
}
|
1999-08-15 23:59:06 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
static MeasureOptions *
|
|
|
|
measure_tool_options_new (void)
|
|
|
|
{
|
|
|
|
MeasureOptions *options;
|
|
|
|
GtkWidget *vbox;
|
1999-08-15 23:59:06 +08:00
|
|
|
|
2001-04-01 04:41:39 +08:00
|
|
|
options = g_new0 (MeasureOptions, 1);
|
2001-07-18 04:50:01 +08:00
|
|
|
tool_options_init ((GimpToolOptions *) options,
|
2001-02-28 03:18:01 +08:00
|
|
|
measure_tool_options_reset);
|
2001-04-01 04:41:39 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
options->use_info_window = options->use_info_window_d = FALSE;
|
1999-08-15 23:59:06 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
/* the main vbox */
|
|
|
|
vbox = options->tool_options.main_vbox;
|
1999-08-15 23:59:06 +08:00
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
/* the use_info_window toggle button */
|
|
|
|
options->use_info_window_w =
|
|
|
|
gtk_check_button_new_with_label (_("Use Info Window"));
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->use_info_window_w),
|
|
|
|
options->use_info_window_d);
|
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-25 05:27:11 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), options->use_info_window_w,
|
|
|
|
FALSE, FALSE, 0);
|
2001-07-30 08:46:09 +08:00
|
|
|
gtk_widget_show (options->use_info_window_w);
|
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-25 05:27:11 +08:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (options->use_info_window_w), "toggled",
|
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
|
|
|
&options->use_info_window);
|
2001-02-28 03:18:01 +08:00
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gdouble
|
|
|
|
measure_get_angle (gint dx,
|
|
|
|
gint dy,
|
|
|
|
gdouble xres,
|
|
|
|
gdouble yres)
|
|
|
|
{
|
|
|
|
gdouble angle;
|
|
|
|
|
|
|
|
if (dx)
|
|
|
|
angle = gimp_rad_to_deg (atan (((gdouble) (dy) / yres) /
|
|
|
|
((gdouble) (dx) / xres)));
|
|
|
|
else if (dy)
|
|
|
|
angle = dy > 0 ? 270.0 : 90.0;
|
|
|
|
else
|
|
|
|
angle = 180.0;
|
|
|
|
|
|
|
|
if (dx > 0)
|
|
|
|
{
|
|
|
|
if (dy > 0)
|
|
|
|
angle = 360.0 - angle;
|
|
|
|
else
|
|
|
|
angle = -angle;
|
1999-08-15 23:59:06 +08:00
|
|
|
}
|
2001-02-28 03:18:01 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
angle = 180.0 - angle;
|
|
|
|
}
|
|
|
|
|
|
|
|
return angle;
|
1999-08-15 23:59:06 +08:00
|
|
|
}
|
|
|
|
|
1999-08-21 19:30:10 +08:00
|
|
|
static void
|
|
|
|
measure_tool_info_update (void)
|
|
|
|
{
|
|
|
|
info_dialog_update (measure_tool_info);
|
|
|
|
info_dialog_popup (measure_tool_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
measure_tool_info_window_close_callback (GtkWidget *widget,
|
|
|
|
gpointer client_data)
|
|
|
|
{
|
|
|
|
info_dialog_free (measure_tool_info);
|
|
|
|
measure_tool_info = NULL;
|
|
|
|
}
|