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
|
|
|
|
2002-05-03 20:45:22 +08:00
|
|
|
#include "tools-types.h"
|
|
|
|
|
2002-05-11 07:30:09 +08:00
|
|
|
#ifdef __GNUC__
|
2002-05-03 20:45:22 +08:00
|
|
|
#warning FIXME #include "gui/gui-types.h"
|
2002-05-11 07:30:09 +08:00
|
|
|
#endif
|
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"
|
include the new "paint-funcs/paint-funcs-types.h".
2001-11-28 Michael Natterer <mitch@gimp.org>
* app/base/base-types.h: include the new
"paint-funcs/paint-funcs-types.h".
* app/paint-funcs/Makefile.am
* app/paint-funcs/paint-funcs-types.h: new file. Includes
"base/base-types.h".
* app/paint-funcs/paint-funcs.[ch]: removed the enums here,
include "paint-funcs-types.h".
* app/widgets/widgets-types.h: include "display/display-types.h"
* app/display/display-types.h: include "widgets/widgets-types.h".
* app/tools/tools-types.h: include "display/display-types.h"
* app/gui/gui-types.h: include "tools/tools-types.h".
The order of namespaces/dependencies should be (but is not):
(base, paint-funcs) -> (core, file, xcf, pdb) ->
(widgets, display) -> tools -> gui
* app/path.c: include "tools/tools-types.h".
* app/core/Makefile.am
* app/core/gimpimage-guides.[ch]
* app/core/gimpimage-merge.[ch]
* app/core/gimpimage-resize.[ch]
* app/core/gimpimage-scale.[ch]: new files.
* app/core/gimpimage.[ch]: removed the stuff which is in the new
files. Reordered all functions in both the .h and .c files,
commented the groups of functions.
* app/core/gimpcontainer.c: create the handler_id using a counter,
not the address of a pointer, because the address *may* be the
same twice, added debugging output.
* app/core/gimpviewable.[ch]: added primitive support for getting
a preview GdkPixbuf.
* app/nav_window.c
* app/undo.c
* app/undo_history.c
* app/core/gimpimage-duplicate.c
* app/core/gimpimage-mask.[ch]
* app/display/gimpdisplay.c
* app/display/gimpdisplayshell-callbacks.c
* app/display/gimpdisplayshell-dnd.c
* app/display/gimpdisplayshell-render.c
* app/display/gimpdisplayshell-scale.c
* app/display/gimpdisplayshell-scroll.c
* app/gui/image-commands.c
* app/gui/info-window.c
* app/gui/layers-commands.c
* app/gui/palette-import-dialog.c
* app/tools/gimpbycolorselecttool.c
* app/tools/gimpeditselectiontool.c
* app/tools/gimpmeasuretool.c
* app/tools/gimpmovetool.c
* app/widgets/gimpcontainerview-utils.c
* app/xcf/xcf-load.c: changed accordingly, some cleanup.
* tools/pdbgen/pdb/guides.pdb
* tools/pdbgen/pdb/image.pdb: changed accordingly, reordered functions.
* app/plug_in.c: set the labels of the "Repeat" and "Re-Show" menu
items to the name of the last plug-in (Fixes #50986).
* app/display/gimpdisplayshell.[ch]: set the labels of "Undo" and
"Redo" to the resp. undo names. Much simplified the WM icon stuff
by removing most code and using gimp_viewable_get_new_preview_pixbuf().
* app/widgets/gimpbrushfactoryview.c: forgot to assign the GQuark
returned by gimp_container_add_handler().
* app/pdb/guides_cmds.c
* app/pdb/image_cmds.c
* libgimp/gimpimage_pdb.[ch]: regenerated.
2001-11-29 01:51:06 +08:00
|
|
|
#include "core/gimpimage-guides.h"
|
2001-11-20 21:53:21 +08:00
|
|
|
#include "core/gimptoolinfo.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
|
2002-08-31 05:00:42 +08:00
|
|
|
#include "widgets/gimpviewabledialog.h"
|
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
2001-11-01 05:20:09 +08:00
|
|
|
#include "display/gimpdisplayshell.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
|
2001-11-20 21:53:21 +08:00
|
|
|
#include "gui/info-dialog.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
|
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-11-09 03:14:51 +08:00
|
|
|
static void gimp_measure_tool_control (GimpTool *tool,
|
2002-02-19 01:00:09 +08:00
|
|
|
GimpToolAction action,
|
2001-11-09 03:14:51 +08:00
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void gimp_measure_tool_button_press (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void gimp_measure_tool_button_release (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void gimp_measure_tool_motion (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void gimp_measure_tool_cursor_update (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
|
|
|
|
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-11-21 07:00:47 +08:00
|
|
|
|
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);
|
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
static GimpToolOptions * measure_tool_options_new (GimpToolInfo *tool_info);
|
|
|
|
static void measure_tool_options_reset (GimpToolOptions *tool_options);
|
1999-08-21 19:30:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* 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
|
2002-03-29 11:50:29 +08:00
|
|
|
gimp_measure_tool_register (GimpToolRegisterCallback callback,
|
2002-05-03 19:31:08 +08:00
|
|
|
gpointer data)
|
2001-02-21 20:18:09 +08:00
|
|
|
{
|
2002-03-29 11:50:29 +08:00
|
|
|
(* callback) (GIMP_TYPE_MEASURE_TOOL,
|
2001-11-21 07:00:47 +08:00
|
|
|
measure_tool_options_new,
|
|
|
|
FALSE,
|
2002-03-21 20:17:17 +08:00
|
|
|
"gimp-measure-tool",
|
GimpViewableDialogs everywhere, cleanup:
2002-09-01 Michael Natterer <mitch@gimp.org>
GimpViewableDialogs everywhere, cleanup:
* libgimpwidgets/gimpstock.c: added texts for the RESIZE, SCALE
and CROP stock items.
* app/widgets/gimpviewabledialog.c: update the title when the
viewable's name changes.
* app/gui/color-notebook.[ch]: added color_notebook_viewable_new()
which creates a GimpViewableDialog.
* app/widgets/gimpgradienteditor.[ch]
* app/gui/colormap-editor-commands.c
* app/gui/file-new-dialog.c
* app/gui/gradient-editor-commands.c
* app/gui/palette-editor-commands.c
* app/undo_history.c: use GimpViewableDialogs and the new
color_notebook constructor.
* app/gui/convert-dialog.c: #include "widgets/gimpviewabledialog.h"
* app/gui/image-commands.c
* app/gui/info-dialog.c
* app/gui/resize-dialog.c: minor cleanups.
* app/gui/info-window.c: cleaned up the whole thing, esp. the
"Extended" page. Added HSV color display to the color picker
frame. Set the icons as frame titles, stuff...
* app/tools/gimpimagemaptool.[ch]: removed "shell_title",
"shell_name" and "stock_id" from the GimpImageMapTool struct
because they can be obtained from the tool's GimpToolInfo object.
* app/tools/gimpbrightnesscontrasttool.c
* app/tools/gimpcolorbalancetool.c
* app/tools/gimpcurvestool.c
* app/tools/gimphuesaturationtool.c
* app/tools/gimplevelstool.c
* app/tools/gimpposterizetool.c
* app/tools/gimpthresholdtool.c: changed accordingly.
* app/tools/gimphistogramtool.c: same here: take values from
tool->tool_info instead of hardcoding them.
* app/tools/gimpcroptool.[ch]: removed the static crop dialog
variables and added them to the GimpCropTool struct. Feels safer
and makes the callback code much simpler. Use stock items for the
dialog's "Resize" and "Crop" buttons.
* app/tools/gimpmeasuretool.c
* app/tools/gimprotatetool.c: for consistency don't name the tools
"Blah Tool", also the dialog titles need to match the menu
entries.
Unrelated:
* libgimpwidgets/gimpwidgets.c: the recently changed, gtk-doc
comment was correct, as gtk-doc takes the parameter names from
the header, not the .c file.
* app/tools/gimptransformtool.c: set the transform tool's state to
TRANSFORM_CREATING after changing displays, so the initial matrix
components are saved correctly for the "Reset" function.
2002-09-01 16:44:57 +08:00
|
|
|
_("Measure"),
|
2001-11-21 07:00:47 +08:00
|
|
|
_("Measure angles and lengths"),
|
|
|
|
N_("/Tools/Measure"), NULL,
|
|
|
|
NULL, "tools/measure.html",
|
2002-03-29 11:50:29 +08:00
|
|
|
GIMP_STOCK_TOOL_MEASURE,
|
2002-05-03 19:31:08 +08:00
|
|
|
data);
|
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);
|
|
|
|
|
2002-05-03 05:03:27 +08:00
|
|
|
gimp_tool_control_set_tool_cursor (tool->control, GIMP_MEASURE_TOOL_CURSOR);
|
2001-02-21 20:18:09 +08:00
|
|
|
}
|
|
|
|
|
1999-08-21 19:30:10 +08:00
|
|
|
static void
|
2002-02-19 01:00:09 +08:00
|
|
|
gimp_measure_tool_control (GimpTool *tool,
|
|
|
|
GimpToolAction action,
|
|
|
|
GimpDisplay *gdisp)
|
1999-08-21 19:30:10 +08:00
|
|
|
{
|
2002-02-03 20:10:23 +08:00
|
|
|
GimpMeasureTool *measure_tool;
|
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-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:
|
2002-02-03 20:10:23 +08:00
|
|
|
gimp_tool_pop_status (tool);
|
2003-01-03 21:59:23 +08:00
|
|
|
gimp_tool_control_halt (tool->control);
|
2001-02-28 03:18:01 +08:00
|
|
|
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-11-09 03:14:51 +08:00
|
|
|
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-11-09 03:14:51 +08:00
|
|
|
gimp_measure_tool_button_press (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
1999-08-15 23:59:06 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
GimpMeasureTool *measure_tool;
|
2001-11-20 21:53:21 +08:00
|
|
|
MeasureOptions *options;
|
2001-11-01 05:20:09 +08:00
|
|
|
GimpDisplayShell *shell;
|
|
|
|
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-20 21:53:21 +08:00
|
|
|
options = (MeasureOptions *) tool->tool_info->tool_options;
|
|
|
|
|
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 */
|
2002-05-03 19:31:08 +08:00
|
|
|
if (gimp_tool_control_is_active (tool->control) && gdisp != tool->gdisp)
|
1999-08-15 23:59:06 +08:00
|
|
|
{
|
2002-02-03 20:10:23 +08:00
|
|
|
gimp_tool_pop_status (tool);
|
2001-11-12 22:45:58 +08:00
|
|
|
}
|
1999-08-21 21:16:20 +08:00
|
|
|
|
1999-08-19 02:48:35 +08:00
|
|
|
measure_tool->function = CREATING;
|
|
|
|
|
2002-05-03 19:31:08 +08:00
|
|
|
if (gimp_tool_control_is_active (tool->control) && 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
|
|
|
{
|
2001-11-16 05:17:36 +08:00
|
|
|
if (gimp_draw_tool_on_handle (GIMP_DRAW_TOOL (tool), gdisp,
|
2001-11-12 22:45:58 +08:00
|
|
|
coords->x,
|
|
|
|
coords->y,
|
2001-11-16 05:17:36 +08:00
|
|
|
GIMP_HANDLE_CIRCLE,
|
|
|
|
measure_tool->x[i],
|
|
|
|
measure_tool->y[i],
|
|
|
|
TARGET, TARGET,
|
|
|
|
GTK_ANCHOR_CENTER,
|
|
|
|
FALSE))
|
1999-08-19 02:48:35 +08:00
|
|
|
{
|
2001-11-09 03:14:51 +08:00
|
|
|
if (state & (GDK_CONTROL_MASK | GDK_MOD1_MASK))
|
1999-08-20 00:26:47 +08:00
|
|
|
{
|
2001-11-09 03:14:51 +08:00
|
|
|
gboolean create_hguide;
|
|
|
|
gboolean create_vguide;
|
2001-05-16 03:10:57 +08:00
|
|
|
GimpGuide *guide;
|
2000-04-13 08:38:04 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
create_hguide = ((state & GDK_CONTROL_MASK) &&
|
|
|
|
(measure_tool->y[i] ==
|
|
|
|
CLAMP (measure_tool->y[i],
|
|
|
|
0,
|
|
|
|
gdisp->gimage->height)));
|
2000-04-13 08:38:04 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
create_vguide = ((state & GDK_MOD1_MASK) &&
|
|
|
|
(measure_tool->x[i] ==
|
|
|
|
CLAMP (measure_tool->x[i],
|
|
|
|
0,
|
|
|
|
gdisp->gimage->width)));
|
|
|
|
|
|
|
|
if (create_hguide && create_vguide)
|
2002-02-24 01:29:19 +08:00
|
|
|
undo_push_group_start (gdisp->gimage,
|
|
|
|
IMAGE_GUIDE_UNDO_GROUP);
|
2000-04-13 08:23:10 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
if (create_hguide)
|
1999-08-20 00:26:47 +08:00
|
|
|
{
|
|
|
|
guide = gimp_image_add_hguide (gdisp->gimage);
|
2002-02-24 01:29:19 +08:00
|
|
|
undo_push_image_guide (gdisp->gimage, guide);
|
1999-08-21 19:30:10 +08:00
|
|
|
guide->position = measure_tool->y[i];
|
2001-11-14 23:40:30 +08:00
|
|
|
|
|
|
|
gimp_image_update_guide (gdisp->gimage, guide);
|
2000-04-13 08:38:04 +08:00
|
|
|
}
|
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
if (create_vguide)
|
1999-08-20 00:26:47 +08:00
|
|
|
{
|
|
|
|
guide = gimp_image_add_vguide (gdisp->gimage);
|
2002-02-24 01:29:19 +08:00
|
|
|
undo_push_image_guide (gdisp->gimage, guide);
|
1999-08-21 19:30:10 +08:00
|
|
|
guide->position = measure_tool->x[i];
|
2001-11-14 23:40:30 +08:00
|
|
|
|
|
|
|
gimp_image_update_guide (gdisp->gimage, guide);
|
1999-08-20 00:26:47 +08:00
|
|
|
}
|
2000-04-13 08:23:10 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
if (create_hguide && create_vguide)
|
2000-04-13 08:23:10 +08:00
|
|
|
undo_push_group_end (gdisp->gimage);
|
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
if (create_hguide || create_vguide)
|
2002-05-09 01:48:24 +08:00
|
|
|
gimp_image_flush (gdisp->gimage);
|
2001-11-09 03:14:51 +08:00
|
|
|
|
1999-08-20 00:26:47 +08:00
|
|
|
measure_tool->function = GUIDING;
|
|
|
|
break;
|
|
|
|
}
|
2001-11-09 03:14:51 +08:00
|
|
|
|
|
|
|
measure_tool->function = (state & GDK_SHIFT_MASK) ? ADDING : MOVING;
|
1999-08-19 02:48:35 +08:00
|
|
|
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 */
|
2001-11-09 03:14:51 +08:00
|
|
|
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)
|
|
|
|
{
|
2001-11-09 03:14:51 +08:00
|
|
|
if (measure_tool->num_points > 1 && (state & GDK_MOD1_MASK))
|
2000-04-13 05:21:36 +08:00
|
|
|
{
|
|
|
|
measure_tool->function = MOVING_ALL;
|
2001-11-09 03:14:51 +08:00
|
|
|
|
|
|
|
measure_tool->last_x = coords->x;
|
|
|
|
measure_tool->last_y = coords->y;
|
2000-04-13 05:21:36 +08:00
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
{
|
2002-05-03 19:31:08 +08:00
|
|
|
if (gimp_tool_control_is_active (tool->control))
|
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
|
|
|
|
|
|
|
distance_buf[0] = '\0';
|
|
|
|
angle_buf[0] = '\0';
|
|
|
|
if (measure_tool_info)
|
|
|
|
measure_tool_info_update ();
|
|
|
|
}
|
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-11-09 03:14:51 +08:00
|
|
|
measure_tool->x[0] = coords->x;
|
|
|
|
measure_tool->y[0] = coords->y;
|
2000-12-28 07:25:51 +08:00
|
|
|
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
|
|
|
|
2002-05-03 19:31:08 +08:00
|
|
|
if (gimp_tool_control_is_active (tool->control))
|
2002-02-03 20:10:23 +08:00
|
|
|
{
|
|
|
|
gimp_tool_pop_status (tool);
|
2002-08-31 05:00:42 +08:00
|
|
|
gimp_tool_push_status (tool, " ");
|
2002-02-03 20:10:23 +08:00
|
|
|
}
|
|
|
|
|
1999-08-15 23:59:06 +08:00
|
|
|
/* start drawing the measure tool */
|
2002-02-03 20:10:23 +08:00
|
|
|
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), gdisp);
|
1999-08-15 23:59:06 +08:00
|
|
|
}
|
1999-08-21 19:30:10 +08:00
|
|
|
|
|
|
|
/* create the info window if necessary */
|
2001-11-20 21:53:21 +08:00
|
|
|
if (! measure_tool_info && (options->use_info_window ||
|
2002-02-03 20:10:23 +08:00
|
|
|
! GTK_WIDGET_VISIBLE (shell->statusbar)))
|
2000-04-13 05:21:36 +08:00
|
|
|
{
|
2002-08-31 05:00:42 +08:00
|
|
|
measure_tool_info = info_dialog_new (NULL,
|
GimpViewableDialogs everywhere, cleanup:
2002-09-01 Michael Natterer <mitch@gimp.org>
GimpViewableDialogs everywhere, cleanup:
* libgimpwidgets/gimpstock.c: added texts for the RESIZE, SCALE
and CROP stock items.
* app/widgets/gimpviewabledialog.c: update the title when the
viewable's name changes.
* app/gui/color-notebook.[ch]: added color_notebook_viewable_new()
which creates a GimpViewableDialog.
* app/widgets/gimpgradienteditor.[ch]
* app/gui/colormap-editor-commands.c
* app/gui/file-new-dialog.c
* app/gui/gradient-editor-commands.c
* app/gui/palette-editor-commands.c
* app/undo_history.c: use GimpViewableDialogs and the new
color_notebook constructor.
* app/gui/convert-dialog.c: #include "widgets/gimpviewabledialog.h"
* app/gui/image-commands.c
* app/gui/info-dialog.c
* app/gui/resize-dialog.c: minor cleanups.
* app/gui/info-window.c: cleaned up the whole thing, esp. the
"Extended" page. Added HSV color display to the color picker
frame. Set the icons as frame titles, stuff...
* app/tools/gimpimagemaptool.[ch]: removed "shell_title",
"shell_name" and "stock_id" from the GimpImageMapTool struct
because they can be obtained from the tool's GimpToolInfo object.
* app/tools/gimpbrightnesscontrasttool.c
* app/tools/gimpcolorbalancetool.c
* app/tools/gimpcurvestool.c
* app/tools/gimphuesaturationtool.c
* app/tools/gimplevelstool.c
* app/tools/gimpposterizetool.c
* app/tools/gimpthresholdtool.c: changed accordingly.
* app/tools/gimphistogramtool.c: same here: take values from
tool->tool_info instead of hardcoding them.
* app/tools/gimpcroptool.[ch]: removed the static crop dialog
variables and added them to the GimpCropTool struct. Feels safer
and makes the callback code much simpler. Use stock items for the
dialog's "Resize" and "Crop" buttons.
* app/tools/gimpmeasuretool.c
* app/tools/gimprotatetool.c: for consistency don't name the tools
"Blah Tool", also the dialog titles need to match the menu
entries.
Unrelated:
* libgimpwidgets/gimpwidgets.c: the recently changed, gtk-doc
comment was correct, as gtk-doc takes the parameter names from
the header, not the .c file.
* app/tools/gimptransformtool.c: set the transform tool's state to
TRANSFORM_CREATING after changing displays, so the initial matrix
components are saved correctly for the "Reset" function.
2002-09-01 16:44:57 +08:00
|
|
|
tool->tool_info->blurb,
|
|
|
|
GIMP_OBJECT (tool->tool_info)->name,
|
|
|
|
tool->tool_info->stock_id,
|
|
|
|
_("Measure Distances and Angles"),
|
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,
|
2002-11-14 19:54:57 +08:00
|
|
|
measure_tool_info, NULL, NULL, TRUE, TRUE,
|
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
|
|
|
|
2002-08-31 05:00:42 +08:00
|
|
|
if (measure_tool_info)
|
|
|
|
gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (measure_tool_info->shell),
|
|
|
|
GIMP_VIEWABLE (tool->gdisp->gimage));
|
|
|
|
|
2002-05-03 19:31:08 +08:00
|
|
|
gimp_tool_control_activate (tool->control);
|
1999-08-15 23:59:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-09 03:14:51 +08:00
|
|
|
gimp_measure_tool_button_release (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-09 03:14:51 +08:00
|
|
|
gimp_measure_tool_motion (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
1999-08-15 23:59:06 +08:00
|
|
|
{
|
2002-06-27 06:16:59 +08:00
|
|
|
GimpMeasureTool *measure_tool;
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
MeasureOptions *options;
|
|
|
|
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
|
|
|
|
2002-06-27 06:16:59 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
|
|
|
|
|
2001-11-20 21:53:21 +08:00
|
|
|
options = (MeasureOptions *) tool->tool_info->tool_options;
|
|
|
|
|
2002-02-03 20:10:23 +08:00
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (measure_tool));
|
1999-08-15 23:59:06 +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
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
measure_tool->x[i] = ROUND (coords->x);
|
|
|
|
measure_tool->y[i] = ROUND (coords->y);
|
1999-08-16 05:10:29 +08:00
|
|
|
|
|
|
|
/* restrict to horizontal/vertical movements, if modifiers are pressed */
|
2001-11-09 03:14:51 +08:00
|
|
|
if (state & GDK_MOD1_MASK)
|
1999-08-15 23:59:06 +08:00
|
|
|
{
|
2001-11-09 03:14:51 +08:00
|
|
|
if (state & GDK_CONTROL_MASK)
|
1999-08-15 23:59:06 +08:00
|
|
|
{
|
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
|
2001-11-09 03:14:51 +08:00
|
|
|
{
|
|
|
|
measure_tool->x[i] = measure_tool->x[0];
|
|
|
|
}
|
1999-08-15 23:59:06 +08:00
|
|
|
}
|
2001-11-09 03:14:51 +08:00
|
|
|
else if (state & GDK_CONTROL_MASK)
|
|
|
|
{
|
|
|
|
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:
|
2001-11-09 03:14:51 +08:00
|
|
|
dx = ROUND (coords->x) - measure_tool->last_x;
|
|
|
|
dy = ROUND (coords->y) - measure_tool->last_y;
|
|
|
|
|
2000-04-13 05:21:36 +08:00
|
|
|
for (i = 0; i < measure_tool->num_points; i++)
|
|
|
|
{
|
|
|
|
measure_tool->x[i] += dx;
|
|
|
|
measure_tool->y[i] += dy;
|
|
|
|
}
|
2001-11-09 03:14:51 +08:00
|
|
|
|
|
|
|
measure_tool->last_x = ROUND (coords->x);
|
|
|
|
measure_tool->last_y = ROUND (coords->y);
|
2000-04-13 05:21:36 +08:00
|
|
|
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
|
|
|
|
2002-06-27 06:16:59 +08:00
|
|
|
if (shell->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
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
g_snprintf (status_str, sizeof (status_str), "%.1f %s, %.2f %s",
|
2000-04-13 05:21:36 +08:00
|
|
|
distance, _("pixels"), angle, _("degrees"));
|
2001-11-20 21:53:21 +08:00
|
|
|
|
|
|
|
g_snprintf (distance_buf, sizeof (distance_buf), "%.1f %s",
|
|
|
|
distance, _("pixels"));
|
|
|
|
g_snprintf (angle_buf, sizeof (angle_buf), "%.2f %s",
|
|
|
|
angle, _("degrees"));
|
2000-04-13 05:21:36 +08:00
|
|
|
}
|
|
|
|
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
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
g_snprintf (status_str, sizeof (status_str), format_str,
|
|
|
|
distance, angle);
|
1999-08-21 19:30:10 +08:00
|
|
|
g_free (format_str);
|
2000-12-28 07:25:51 +08:00
|
|
|
|
2001-11-20 21:53:21 +08:00
|
|
|
format_str =
|
|
|
|
g_strdup_printf ("%%.%df %s",
|
|
|
|
gimp_unit_get_digits (gdisp->gimage->unit),
|
|
|
|
gimp_unit_get_symbol (gdisp->gimage->unit));
|
|
|
|
g_snprintf (distance_buf, sizeof (distance_buf), format_str,
|
|
|
|
distance);
|
|
|
|
g_snprintf (angle_buf, sizeof (angle_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 */
|
2002-02-03 20:10:23 +08:00
|
|
|
gimp_tool_pop_status (tool);
|
|
|
|
gimp_tool_push_status (tool, 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
|
|
|
|
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-11-09 03:14:51 +08:00
|
|
|
gimp_measure_tool_cursor_update (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
1999-08-15 23:59:06 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
GimpMeasureTool *measure_tool;
|
|
|
|
gboolean in_handle = FALSE;
|
2001-02-25 03:29:47 +08:00
|
|
|
GdkCursorType ctype = GIMP_CROSSHAIR_SMALL_CURSOR;
|
|
|
|
GimpCursorModifier cmodifier = GIMP_CURSOR_MODIFIER_NONE;
|
2001-11-09 03:14:51 +08:00
|
|
|
gint i;
|
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
|
|
|
|
2002-05-03 19:31:08 +08:00
|
|
|
if (gimp_tool_control_is_active (tool->control) && 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-11-16 05:17:36 +08:00
|
|
|
if (gimp_draw_tool_on_handle (GIMP_DRAW_TOOL (tool), gdisp,
|
2001-11-12 22:45:58 +08:00
|
|
|
coords->x,
|
|
|
|
coords->y,
|
2001-11-16 05:17:36 +08:00
|
|
|
GIMP_HANDLE_CIRCLE,
|
|
|
|
measure_tool->x[i],
|
|
|
|
measure_tool->y[i],
|
|
|
|
TARGET, TARGET,
|
|
|
|
GTK_ANCHOR_CENTER,
|
|
|
|
FALSE))
|
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
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
if (state & GDK_CONTROL_MASK)
|
1999-08-20 00:26:47 +08:00
|
|
|
{
|
2001-11-09 03:14:51 +08:00
|
|
|
if (state & GDK_MOD1_MASK)
|
1999-08-20 00:26:47 +08:00
|
|
|
ctype = GDK_BOTTOM_RIGHT_CORNER;
|
|
|
|
else
|
|
|
|
ctype = GDK_BOTTOM_SIDE;
|
|
|
|
break;
|
|
|
|
}
|
2001-11-09 03:14:51 +08:00
|
|
|
|
|
|
|
if (state & GDK_MOD1_MASK)
|
1999-08-20 00:26:47 +08:00
|
|
|
{
|
|
|
|
ctype = GDK_RIGHT_SIDE;
|
|
|
|
break;
|
|
|
|
}
|
2000-04-13 05:21:36 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
if (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
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
if (! in_handle && measure_tool->num_points > 1 && (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
|
|
|
|
2002-05-03 19:31:08 +08:00
|
|
|
gimp_tool_control_set_cursor (tool->control, ctype);
|
|
|
|
gimp_tool_control_set_cursor_modifier (tool->control, cmodifier);
|
2002-02-05 01:43:01 +08:00
|
|
|
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, gdisp);
|
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 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
|
|
|
{
|
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-11-16 05:17:36 +08:00
|
|
|
gimp_draw_tool_draw_handle (draw_tool,
|
|
|
|
GIMP_HANDLE_CIRCLE,
|
|
|
|
measure_tool->x[i],
|
|
|
|
measure_tool->y[i],
|
|
|
|
TARGET,
|
|
|
|
TARGET,
|
|
|
|
GTK_ANCHOR_CENTER,
|
|
|
|
FALSE);
|
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-11-16 05:17:36 +08:00
|
|
|
gimp_draw_tool_draw_handle (draw_tool,
|
|
|
|
GIMP_HANDLE_CROSS,
|
|
|
|
measure_tool->x[i],
|
|
|
|
measure_tool->y[i],
|
|
|
|
TARGET * 2,
|
|
|
|
TARGET * 2,
|
|
|
|
GTK_ANCHOR_CENTER,
|
|
|
|
FALSE);
|
1999-08-16 02:44:15 +08:00
|
|
|
}
|
2001-11-12 22:45:58 +08:00
|
|
|
|
1999-08-19 02:48:35 +08:00
|
|
|
if (i > 0)
|
1999-08-16 02:44:15 +08:00
|
|
|
{
|
2001-11-12 22:45:58 +08:00
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
|
|
|
measure_tool->x[0],
|
|
|
|
measure_tool->y[0],
|
|
|
|
measure_tool->x[i],
|
|
|
|
measure_tool->y[i],
|
|
|
|
FALSE);
|
|
|
|
|
1999-08-19 02:48:35 +08:00
|
|
|
/* only draw the arc if the lines are long enough */
|
2001-11-12 22:45:58 +08:00
|
|
|
if (gimp_draw_tool_calc_distance (draw_tool, tool->gdisp,
|
|
|
|
measure_tool->x[0],
|
|
|
|
measure_tool->y[0],
|
|
|
|
measure_tool->x[i],
|
|
|
|
measure_tool->y[i]) > ARC_RADIUS)
|
|
|
|
{
|
|
|
|
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-11-16 05:17:36 +08:00
|
|
|
gimp_draw_tool_draw_arc_by_anchor (draw_tool,
|
2001-11-12 22:45:58 +08:00
|
|
|
FALSE,
|
|
|
|
measure_tool->x[0],
|
|
|
|
measure_tool->y[0],
|
|
|
|
ARC_RADIUS,
|
2001-11-16 05:17:36 +08:00
|
|
|
ARC_RADIUS,
|
2001-11-12 22:45:58 +08:00
|
|
|
angle1, angle2,
|
2001-11-16 05:17:36 +08:00
|
|
|
GTK_ANCHOR_CENTER,
|
2001-11-12 22:45:58 +08:00
|
|
|
FALSE);
|
2000-12-28 07:25:51 +08:00
|
|
|
|
1999-08-19 02:48:35 +08:00
|
|
|
if (measure_tool->num_points == 2)
|
2001-11-12 22:45:58 +08:00
|
|
|
{
|
2002-06-27 06:16:59 +08:00
|
|
|
GimpDisplayShell *shell;
|
|
|
|
gdouble target;
|
|
|
|
gdouble arc_radius;
|
|
|
|
|
|
|
|
shell = GIMP_DISPLAY_SHELL (tool->gdisp->shell);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
2002-06-27 06:16:59 +08:00
|
|
|
target = FUNSCALEX (shell, (TARGET >> 1));
|
|
|
|
arc_radius = FUNSCALEX (shell, ARC_RADIUS);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
|
|
|
gimp_draw_tool_draw_line
|
|
|
|
(draw_tool,
|
|
|
|
measure_tool->x[0],
|
|
|
|
measure_tool->y[0],
|
|
|
|
(measure_tool->x[1] >= measure_tool->x[0] ?
|
|
|
|
measure_tool->x[0] + arc_radius + target :
|
|
|
|
measure_tool->x[0] - arc_radius - target),
|
|
|
|
measure_tool->y[0],
|
|
|
|
FALSE);
|
|
|
|
}
|
1999-08-19 02:48:35 +08:00
|
|
|
}
|
1999-08-16 02:44:15 +08:00
|
|
|
}
|
1999-08-15 23:59:06 +08:00
|
|
|
}
|
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
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;
|
|
|
|
}
|
2001-11-21 07:00:47 +08:00
|
|
|
|
|
|
|
static GimpToolOptions *
|
|
|
|
measure_tool_options_new (GimpToolInfo *tool_info)
|
|
|
|
{
|
|
|
|
MeasureOptions *options;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
|
|
|
|
options = g_new0 (MeasureOptions, 1);
|
|
|
|
|
|
|
|
tool_options_init ((GimpToolOptions *) options, tool_info);
|
|
|
|
|
|
|
|
((GimpToolOptions *) options)->reset_func = measure_tool_options_reset;
|
|
|
|
|
|
|
|
options->use_info_window = options->use_info_window_d = FALSE;
|
|
|
|
|
|
|
|
/* the main vbox */
|
|
|
|
vbox = options->tool_options.main_vbox;
|
|
|
|
|
|
|
|
/* 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),
|
2002-04-28 22:35:01 +08:00
|
|
|
options->use_info_window);
|
2001-11-21 07:00:47 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), options->use_info_window_w,
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (options->use_info_window_w);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (options->use_info_window_w, "toggled",
|
2001-11-21 07:00:47 +08:00
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
|
|
|
&options->use_info_window);
|
|
|
|
|
|
|
|
return (GimpToolOptions *) options;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
measure_tool_options_reset (GimpToolOptions *tool_options)
|
|
|
|
{
|
|
|
|
MeasureOptions *options;
|
|
|
|
|
|
|
|
options = (MeasureOptions *) tool_options;
|
|
|
|
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->use_info_window_w),
|
|
|
|
options->use_info_window_d);
|
|
|
|
}
|