2006-12-10 05:33:38 +08:00
|
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1999-08-15 23:59:06 +08:00
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
|
*
|
1999-08-19 02:48:35 +08:00
|
|
|
|
* Measure tool
|
2003-10-21 01:36:18 +08:00
|
|
|
|
* Copyright (C) 1999-2003 Sven Neumann <sven@gimp.org>
|
1999-08-19 02:48:35 +08:00
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1999-08-15 23:59:06 +08:00
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1999-08-15 23:59:06 +08:00
|
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1999-08-15 23:59:06 +08:00
|
|
|
|
*/
|
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>
|
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
|
#include <gegl.h>
|
2000-12-29 23:22:01 +08:00
|
|
|
|
#include <gtk/gtk.h>
|
2004-10-08 23:32:30 +08:00
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
|
2010-02-21 23:46:39 +08:00
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
2007-03-09 21:00:01 +08:00
|
|
|
|
#include "libgimpmath/gimpmath.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"
|
|
|
|
|
|
2009-04-23 03:08:42 +08:00
|
|
|
|
#include "core/gimp-utils.h"
|
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"
|
2003-02-13 19:23:50 +08:00
|
|
|
|
#include "core/gimpimage-undo.h"
|
2003-02-14 22:14:29 +08:00
|
|
|
|
#include "core/gimpimage-undo-push.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
|
|
2003-08-22 09:42:57 +08:00
|
|
|
|
#include "widgets/gimphelp-ids.h"
|
2007-03-01 06:35:37 +08:00
|
|
|
|
#include "widgets/gimpwidgets-utils.h"
|
2002-08-31 05:00:42 +08:00
|
|
|
|
|
2010-09-26 21:49:10 +08:00
|
|
|
|
#include "display/gimpcanvasgroup.h"
|
2010-09-25 23:59:56 +08:00
|
|
|
|
#include "display/gimpcanvashandle.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"
|
2009-10-04 21:31:38 +08:00
|
|
|
|
#include "display/gimpdisplayshell-appearance.h"
|
2013-06-07 18:03:39 +08:00
|
|
|
|
#include "display/gimptoolgui.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
|
|
2003-02-05 22:39:40 +08:00
|
|
|
|
#include "gimpmeasureoptions.h"
|
2001-03-08 09:07:03 +08:00
|
|
|
|
#include "gimpmeasuretool.h"
|
2003-04-16 00:05:52 +08:00
|
|
|
|
#include "gimptoolcontrol.h"
|
2001-02-18 03:49:44 +08:00
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
|
#include "gimp-intl.h"
|
2001-02-24 05:32:47 +08:00
|
|
|
|
|
2000-12-28 07:25:51 +08:00
|
|
|
|
|
2010-11-09 05:37:00 +08:00
|
|
|
|
#define ARC_RADIUS 30
|
2000-12-31 12:07:42 +08:00
|
|
|
|
|
1999-08-21 19:30:10 +08:00
|
|
|
|
|
2001-02-21 20:18:09 +08:00
|
|
|
|
/* local function prototypes */
|
2003-02-05 22:39:40 +08:00
|
|
|
|
|
2007-02-28 02:55:12 +08:00
|
|
|
|
static void gimp_measure_tool_control (GimpTool *tool,
|
|
|
|
|
GimpToolAction action,
|
|
|
|
|
GimpDisplay *display);
|
|
|
|
|
static void gimp_measure_tool_button_press (GimpTool *tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
|
const GimpCoords *coords,
|
2007-02-28 02:55:12 +08:00
|
|
|
|
guint32 time,
|
|
|
|
|
GdkModifierType state,
|
2009-06-20 23:37:31 +08:00
|
|
|
|
GimpButtonPressType press_type,
|
2007-02-28 02:55:12 +08:00
|
|
|
|
GimpDisplay *display);
|
|
|
|
|
static void gimp_measure_tool_button_release (GimpTool *tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
|
const GimpCoords *coords,
|
2007-02-28 02:55:12 +08:00
|
|
|
|
guint32 time,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpButtonReleaseType release_type,
|
|
|
|
|
GimpDisplay *display);
|
|
|
|
|
static void gimp_measure_tool_motion (GimpTool *tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
|
const GimpCoords *coords,
|
2007-02-28 02:55:12 +08:00
|
|
|
|
guint32 time,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpDisplay *display);
|
|
|
|
|
static gboolean gimp_measure_tool_key_press (GimpTool *tool,
|
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
|
GimpDisplay *display);
|
|
|
|
|
static void gimp_measure_tool_active_modifier_key (GimpTool *tool,
|
|
|
|
|
GdkModifierType key,
|
|
|
|
|
gboolean press,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpDisplay *display);
|
2011-03-29 02:44:30 +08:00
|
|
|
|
static void gimp_measure_tool_oper_update (GimpTool *tool,
|
|
|
|
|
const GimpCoords *coords,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
gboolean proximity,
|
|
|
|
|
GimpDisplay *display);
|
2007-02-28 02:55:12 +08:00
|
|
|
|
static void gimp_measure_tool_cursor_update (GimpTool *tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
|
const GimpCoords *coords,
|
2007-02-28 02:55:12 +08:00
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpDisplay *display);
|
|
|
|
|
|
|
|
|
|
static void gimp_measure_tool_draw (GimpDrawTool *draw_tool);
|
|
|
|
|
|
|
|
|
|
static gdouble gimp_measure_tool_get_angle (gint dx,
|
|
|
|
|
gint dy,
|
|
|
|
|
gdouble xres,
|
|
|
|
|
gdouble yres);
|
|
|
|
|
|
2013-06-07 18:03:39 +08:00
|
|
|
|
static GimpToolGui * gimp_measure_tool_dialog_new (GimpMeasureTool *measure);
|
2007-02-28 02:55:12 +08:00
|
|
|
|
static void gimp_measure_tool_dialog_update (GimpMeasureTool *measure,
|
|
|
|
|
GimpDisplay *display);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
|
1999-08-21 19:30:10 +08:00
|
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
|
G_DEFINE_TYPE (GimpMeasureTool, gimp_measure_tool, GIMP_TYPE_DRAW_TOOL)
|
2005-12-13 17:13:50 +08:00
|
|
|
|
|
|
|
|
|
#define parent_class gimp_measure_tool_parent_class
|
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,
|
2003-02-05 22:39:40 +08:00
|
|
|
|
GIMP_TYPE_MEASURE_OPTIONS,
|
|
|
|
|
gimp_measure_options_gui,
|
2003-06-28 19:20:37 +08:00
|
|
|
|
0,
|
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"),
|
2006-09-19 02:00:22 +08:00
|
|
|
|
_("Measure Tool: Measure distances and angles"),
|
2006-02-14 19:43:54 +08:00
|
|
|
|
N_("_Measure"), "<shift>M",
|
2003-08-22 09:42:57 +08:00
|
|
|
|
NULL, GIMP_HELP_TOOL_MEASURE,
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gimp_measure_tool_class_init (GimpMeasureToolClass *klass)
|
|
|
|
|
{
|
2004-06-05 07:08:29 +08:00
|
|
|
|
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
|
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +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->key_press = gimp_measure_tool_key_press;
|
|
|
|
|
tool_class->active_modifier_key = gimp_measure_tool_active_modifier_key;
|
2011-03-29 02:44:30 +08:00
|
|
|
|
tool_class->oper_update = gimp_measure_tool_oper_update;
|
2006-09-13 04:24:50 +08:00
|
|
|
|
tool_class->cursor_update = gimp_measure_tool_cursor_update;
|
2001-02-28 03:18:01 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
draw_tool_class->draw = gimp_measure_tool_draw;
|
2001-02-21 20:18:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-03-29 14:52:09 +08:00
|
|
|
|
gimp_measure_tool_init (GimpMeasureTool *measure)
|
2001-02-21 20:18:09 +08:00
|
|
|
|
{
|
2011-03-29 14:52:09 +08:00
|
|
|
|
GimpTool *tool = GIMP_TOOL (measure);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
|
2005-11-24 03:14:05 +08:00
|
|
|
|
gimp_tool_control_set_handle_empty_image (tool->control, TRUE);
|
2009-02-21 00:57:26 +08:00
|
|
|
|
gimp_tool_control_set_precision (tool->control,
|
|
|
|
|
GIMP_CURSOR_PRECISION_PIXEL_BORDER);
|
2005-11-24 03:14:05 +08:00
|
|
|
|
gimp_tool_control_set_tool_cursor (tool->control,
|
|
|
|
|
GIMP_TOOL_CURSOR_MEASURE);
|
2009-02-21 00:57:26 +08:00
|
|
|
|
|
2011-03-29 14:52:09 +08:00
|
|
|
|
measure->function = CREATING;
|
|
|
|
|
measure->point = -1;
|
|
|
|
|
measure->status_help = TRUE;
|
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,
|
2006-03-29 01:55:52 +08:00
|
|
|
|
GimpDisplay *display)
|
1999-08-21 19:30:10 +08:00
|
|
|
|
{
|
2011-04-01 20:49:25 +08:00
|
|
|
|
GimpMeasureTool *measure = GIMP_MEASURE_TOOL (tool);
|
|
|
|
|
|
2001-02-28 03:18:01 +08:00
|
|
|
|
switch (action)
|
|
|
|
|
{
|
2006-05-22 05:12:01 +08:00
|
|
|
|
case GIMP_TOOL_ACTION_PAUSE:
|
|
|
|
|
case GIMP_TOOL_ACTION_RESUME:
|
2001-02-28 03:18:01 +08:00
|
|
|
|
break;
|
1999-08-19 02:48:35 +08:00
|
|
|
|
|
2006-05-22 05:12:01 +08:00
|
|
|
|
case GIMP_TOOL_ACTION_HALT:
|
2013-06-07 18:03:39 +08:00
|
|
|
|
if (measure->gui)
|
|
|
|
|
g_object_unref (measure->gui);
|
2001-02-28 03:18:01 +08:00
|
|
|
|
break;
|
2000-12-28 07:25:51 +08:00
|
|
|
|
}
|
1999-08-19 02:48:35 +08:00
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
|
1999-08-19 02:48:35 +08:00
|
|
|
|
}
|
1999-08-15 23:59:06 +08:00
|
|
|
|
|
|
|
|
|
static void
|
2009-06-20 23:37:31 +08:00
|
|
|
|
gimp_measure_tool_button_press (GimpTool *tool,
|
|
|
|
|
const GimpCoords *coords,
|
|
|
|
|
guint32 time,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpButtonPressType press_type,
|
|
|
|
|
GimpDisplay *display)
|
1999-08-15 23:59:06 +08:00
|
|
|
|
{
|
2006-09-13 04:24:50 +08:00
|
|
|
|
GimpMeasureTool *measure = GIMP_MEASURE_TOOL (tool);
|
2006-09-06 02:25:31 +08:00
|
|
|
|
GimpMeasureOptions *options = GIMP_MEASURE_TOOL_GET_OPTIONS (tool);
|
2009-10-05 01:56:39 +08:00
|
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (display);
|
2009-10-08 01:00:42 +08:00
|
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
1999-08-21 19:30:10 +08:00
|
|
|
|
|
2003-08-22 09:42:57 +08:00
|
|
|
|
/* if we are changing displays, pop the statusbar of the old one */
|
2011-03-29 15:16:22 +08:00
|
|
|
|
if (display != tool->display)
|
1999-08-15 23:59:06 +08:00
|
|
|
|
{
|
2011-03-29 15:16:22 +08:00
|
|
|
|
if (tool->display)
|
2011-04-04 14:19:12 +08:00
|
|
|
|
gimp_tool_pop_status (tool, tool->display);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
}
|
2003-08-22 09:42:57 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
measure->function = CREATING;
|
|
|
|
|
|
|
|
|
|
measure->mouse_x = coords->x;
|
|
|
|
|
measure->mouse_y = coords->y;
|
1999-08-19 02:48:35 +08:00
|
|
|
|
|
2011-03-29 15:16:22 +08:00
|
|
|
|
if (display == tool->display)
|
1999-08-15 23:59:06 +08:00
|
|
|
|
{
|
2011-03-29 14:52:09 +08:00
|
|
|
|
/* if the cursor is in one of the handles, the new function
|
|
|
|
|
* will be moving or adding a new point or guide
|
2000-12-28 07:25:51 +08:00
|
|
|
|
*/
|
2011-03-29 14:52:09 +08:00
|
|
|
|
if (measure->point != -1)
|
2006-04-12 20:49:29 +08:00
|
|
|
|
{
|
2011-10-07 03:59:07 +08:00
|
|
|
|
GdkModifierType toggle_mask = gimp_get_toggle_behavior_mask ();
|
|
|
|
|
|
|
|
|
|
if (state & (toggle_mask | GDK_MOD1_MASK))
|
2006-04-12 20:49:29 +08:00
|
|
|
|
{
|
2011-03-29 14:52:09 +08:00
|
|
|
|
gboolean create_hguide;
|
|
|
|
|
gboolean create_vguide;
|
|
|
|
|
|
2011-10-07 03:59:07 +08:00
|
|
|
|
create_hguide = ((state & toggle_mask) &&
|
2011-03-29 14:52:09 +08:00
|
|
|
|
(measure->y[measure->point] ==
|
|
|
|
|
CLAMP (measure->y[measure->point],
|
|
|
|
|
0,
|
|
|
|
|
gimp_image_get_height (image))));
|
|
|
|
|
|
|
|
|
|
create_vguide = ((state & GDK_MOD1_MASK) &&
|
|
|
|
|
(measure->x[measure->point] ==
|
|
|
|
|
CLAMP (measure->x[measure->point],
|
|
|
|
|
0,
|
|
|
|
|
gimp_image_get_width (image))));
|
|
|
|
|
|
|
|
|
|
if (create_hguide || create_vguide)
|
2006-04-12 20:49:29 +08:00
|
|
|
|
{
|
2011-03-29 14:52:09 +08:00
|
|
|
|
if (create_hguide && create_vguide)
|
|
|
|
|
gimp_image_undo_group_start (image,
|
|
|
|
|
GIMP_UNDO_GROUP_GUIDE,
|
|
|
|
|
_("Add Guides"));
|
2000-04-13 08:23:10 +08:00
|
|
|
|
|
2011-03-29 14:52:09 +08:00
|
|
|
|
if (create_hguide)
|
|
|
|
|
gimp_image_add_hguide (image, measure->y[measure->point],
|
|
|
|
|
TRUE);
|
2000-04-13 08:23:10 +08:00
|
|
|
|
|
2011-03-29 14:52:09 +08:00
|
|
|
|
if (create_vguide)
|
|
|
|
|
gimp_image_add_vguide (image, measure->x[measure->point],
|
|
|
|
|
TRUE);
|
2010-10-01 16:34:15 +08:00
|
|
|
|
|
2011-03-29 14:52:09 +08:00
|
|
|
|
if (create_hguide && create_vguide)
|
|
|
|
|
gimp_image_undo_group_end (image);
|
2001-11-09 03:14:51 +08:00
|
|
|
|
|
2011-03-29 14:52:09 +08:00
|
|
|
|
gimp_image_flush (image);
|
2006-04-12 20:49:29 +08:00
|
|
|
|
}
|
2001-11-09 03:14:51 +08:00
|
|
|
|
|
2011-03-29 14:52:09 +08:00
|
|
|
|
measure->function = GUIDING;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (state & GDK_SHIFT_MASK)
|
|
|
|
|
measure->function = ADDING;
|
|
|
|
|
else
|
|
|
|
|
measure->function = MOVING;
|
2006-04-12 20:49:29 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2000-12-28 07:25:51 +08:00
|
|
|
|
|
1999-08-19 02:48:35 +08:00
|
|
|
|
/* adding to the middle point makes no sense */
|
2011-03-29 14:52:09 +08:00
|
|
|
|
if (measure->point == 0 &&
|
|
|
|
|
measure->function == ADDING &&
|
2006-09-13 04:24:50 +08:00
|
|
|
|
measure->num_points == 3)
|
2001-11-09 03:14:51 +08:00
|
|
|
|
{
|
2006-09-13 04:24:50 +08:00
|
|
|
|
measure->function = MOVING;
|
2001-11-09 03:14:51 +08:00
|
|
|
|
}
|
2000-04-13 05:21:36 +08:00
|
|
|
|
|
|
|
|
|
/* if the function is still CREATING, we are outside the handles */
|
2006-09-13 04:24:50 +08:00
|
|
|
|
if (measure->function == CREATING)
|
2006-04-12 20:49:29 +08:00
|
|
|
|
{
|
2006-09-13 04:24:50 +08:00
|
|
|
|
if (measure->num_points > 1 && (state & GDK_MOD1_MASK))
|
2006-04-12 20:49:29 +08:00
|
|
|
|
{
|
2006-09-13 04:24:50 +08:00
|
|
|
|
measure->function = MOVING_ALL;
|
2001-11-09 03:14:51 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
measure->last_x = coords->x;
|
|
|
|
|
measure->last_y = coords->y;
|
2006-04-12 20:49:29 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
1999-08-15 23:59:06 +08:00
|
|
|
|
}
|
2003-08-22 09:42:57 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
if (measure->function == CREATING)
|
1999-08-15 23:59:06 +08:00
|
|
|
|
{
|
2011-03-29 15:16:22 +08:00
|
|
|
|
if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (measure)))
|
|
|
|
|
gimp_draw_tool_stop (GIMP_DRAW_TOOL (measure));
|
2003-10-21 01:36:18 +08:00
|
|
|
|
|
2011-03-29 15:16:22 +08:00
|
|
|
|
measure->x[0] = measure->x[1] = measure->x[2] = 0.0;
|
|
|
|
|
measure->y[0] = measure->y[1] = measure->y[2] = 0.0;
|
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 */
|
2006-09-13 04:24:50 +08:00
|
|
|
|
measure->x[0] = coords->x + 0.5;
|
|
|
|
|
measure->y[0] = coords->y + 0.5;
|
|
|
|
|
measure->point = 0;
|
|
|
|
|
measure->num_points = 1;
|
|
|
|
|
measure->function = ADDING;
|
1999-08-15 23:59:06 +08:00
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
|
/* set the displaylay */
|
|
|
|
|
tool->display = display;
|
1999-08-15 23:59:06 +08:00
|
|
|
|
|
2011-03-29 15:16:22 +08:00
|
|
|
|
gimp_tool_replace_status (tool, display, _("Drag to create a line"));
|
2002-02-03 20:10:23 +08:00
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
|
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
|
1999-08-15 23:59:06 +08:00
|
|
|
|
}
|
1999-08-21 19:30:10 +08:00
|
|
|
|
|
2011-03-29 15:16:22 +08:00
|
|
|
|
gimp_tool_control_activate (tool->control);
|
|
|
|
|
|
1999-08-21 19:30:10 +08:00
|
|
|
|
/* create the info window if necessary */
|
2013-06-07 18:03:39 +08:00
|
|
|
|
if (! measure->gui)
|
2000-04-13 05:21:36 +08:00
|
|
|
|
{
|
2009-09-24 16:30:47 +08:00
|
|
|
|
if (options->use_info_window ||
|
2009-10-04 21:31:38 +08:00
|
|
|
|
! gimp_display_shell_get_show_statusbar (shell))
|
2009-09-24 16:30:47 +08:00
|
|
|
|
{
|
2013-06-07 18:03:39 +08:00
|
|
|
|
measure->gui = gimp_measure_tool_dialog_new (measure);
|
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (measure->gui),
|
|
|
|
|
(gpointer) &measure->gui);
|
2009-09-24 16:30:47 +08:00
|
|
|
|
}
|
2000-04-13 05:21:36 +08:00
|
|
|
|
}
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
2013-06-07 18:03:39 +08:00
|
|
|
|
if (measure->gui)
|
2011-03-21 01:15:42 +08:00
|
|
|
|
{
|
2013-06-07 18:03:39 +08:00
|
|
|
|
gimp_tool_gui_set_shell (measure->gui, shell);
|
|
|
|
|
gimp_tool_gui_set_viewable (measure->gui, GIMP_VIEWABLE (image));
|
2011-03-29 15:16:22 +08:00
|
|
|
|
|
|
|
|
|
gimp_measure_tool_dialog_update (measure, display);
|
2011-03-21 01:15:42 +08:00
|
|
|
|
}
|
1999-08-15 23:59:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2007-02-28 02:55:12 +08:00
|
|
|
|
gimp_measure_tool_button_release (GimpTool *tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
|
const GimpCoords *coords,
|
2007-02-28 02:55:12 +08:00
|
|
|
|
guint32 time,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpButtonReleaseType release_type,
|
|
|
|
|
GimpDisplay *display)
|
1999-08-15 23:59:06 +08:00
|
|
|
|
{
|
2006-09-13 04:24:50 +08:00
|
|
|
|
GimpMeasureTool *measure = GIMP_MEASURE_TOOL (tool);
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
measure->function = FINISHED;
|
2011-03-29 15:16:22 +08:00
|
|
|
|
|
|
|
|
|
gimp_tool_control_halt (tool->control);
|
1999-08-15 23:59:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2008-11-01 23:17:36 +08:00
|
|
|
|
gimp_measure_tool_motion (GimpTool *tool,
|
|
|
|
|
const GimpCoords *coords,
|
|
|
|
|
guint32 time,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpDisplay *display)
|
1999-08-15 23:59:06 +08:00
|
|
|
|
{
|
2006-09-13 04:24:50 +08:00
|
|
|
|
GimpMeasureTool *measure = GIMP_MEASURE_TOOL (tool);
|
|
|
|
|
gint dx, dy;
|
|
|
|
|
gint i;
|
|
|
|
|
gint tmp;
|
1999-08-15 23:59:06 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (measure));
|
|
|
|
|
|
|
|
|
|
measure->mouse_x = coords->x;
|
|
|
|
|
measure->mouse_y = coords->y;
|
1999-08-15 23:59:06 +08:00
|
|
|
|
|
2011-03-29 15:16:22 +08:00
|
|
|
|
/* A few comments here, because this routine looks quite weird at first ...
|
1999-08-19 02:48:35 +08:00
|
|
|
|
*
|
2003-10-21 01:36:18 +08:00
|
|
|
|
* The goal is to keep point 0, called the start point, to be
|
|
|
|
|
* always the one 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-19 02:48:35 +08:00
|
|
|
|
*/
|
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
switch (measure->function)
|
1999-08-15 23:59:06 +08:00
|
|
|
|
{
|
1999-08-19 02:48:35 +08:00
|
|
|
|
case ADDING:
|
2006-09-13 04:24:50 +08:00
|
|
|
|
switch (measure->point)
|
2006-04-12 20:49:29 +08:00
|
|
|
|
{
|
2011-03-29 15:16:22 +08:00
|
|
|
|
case 0:
|
|
|
|
|
/* we are adding to the start point */
|
2006-04-12 20:49:29 +08:00
|
|
|
|
break;
|
2011-03-29 15:16:22 +08:00
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
/* we are adding to the end point, make it the new start point */
|
2006-09-13 04:24:50 +08:00
|
|
|
|
tmp = measure->x[0];
|
|
|
|
|
measure->x[0] = measure->x[1];
|
|
|
|
|
measure->x[1] = tmp;
|
2011-03-29 15:16:22 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
tmp = measure->y[0];
|
|
|
|
|
measure->y[0] = measure->y[1];
|
|
|
|
|
measure->y[1] = tmp;
|
2006-04-12 20:49:29 +08:00
|
|
|
|
break;
|
2011-03-29 15:16:22 +08:00
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
/* we are adding to the third point, make it the new start point */
|
2006-09-13 04:24:50 +08:00
|
|
|
|
measure->x[1] = measure->x[0];
|
|
|
|
|
measure->y[1] = measure->y[0];
|
|
|
|
|
measure->x[0] = measure->x[2];
|
|
|
|
|
measure->y[0] = measure->y[2];
|
2006-04-12 20:49:29 +08:00
|
|
|
|
break;
|
2011-03-29 15:16:22 +08:00
|
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-09-13 04:24:50 +08:00
|
|
|
|
|
|
|
|
|
measure->num_points = MIN (measure->num_points + 1, 3);
|
|
|
|
|
measure->point = measure->num_points - 1;
|
|
|
|
|
measure->function = MOVING;
|
2011-03-29 15:16:22 +08:00
|
|
|
|
/* don't break here! */
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
|
|
|
|
case MOVING:
|
2011-03-29 15:16:22 +08:00
|
|
|
|
/* if we are moving the start point and only have two, make it
|
|
|
|
|
* the end point
|
|
|
|
|
*/
|
2006-09-13 04:24:50 +08:00
|
|
|
|
if (measure->num_points == 2 && measure->point == 0)
|
2006-04-12 20:49:29 +08:00
|
|
|
|
{
|
2006-09-13 04:24:50 +08:00
|
|
|
|
tmp = measure->x[0];
|
|
|
|
|
measure->x[0] = measure->x[1];
|
|
|
|
|
measure->x[1] = tmp;
|
2011-03-29 15:16:22 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
tmp = measure->y[0];
|
|
|
|
|
measure->y[0] = measure->y[1];
|
|
|
|
|
measure->y[1] = tmp;
|
2011-03-29 15:16:22 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
measure->point = 1;
|
2006-04-12 20:49:29 +08:00
|
|
|
|
}
|
1999-08-15 23:59:06 +08:00
|
|
|
|
|
2011-03-29 15:16:22 +08:00
|
|
|
|
measure->x[measure->point] = ROUND (coords->x);
|
|
|
|
|
measure->y[measure->point] = ROUND (coords->y);
|
1999-08-16 05:10:29 +08:00
|
|
|
|
|
2011-10-07 03:59:07 +08:00
|
|
|
|
if (state & gimp_get_constrain_behavior_mask ())
|
2006-04-12 20:49:29 +08:00
|
|
|
|
{
|
2011-03-29 15:16:22 +08:00
|
|
|
|
gdouble x = measure->x[measure->point];
|
|
|
|
|
gdouble y = measure->y[measure->point];
|
2004-08-23 05:48:50 +08:00
|
|
|
|
|
2009-04-23 03:08:42 +08:00
|
|
|
|
gimp_constrain_line (measure->x[0], measure->y[0],
|
|
|
|
|
&x, &y,
|
|
|
|
|
GIMP_CONSTRAIN_LINE_15_DEGREES);
|
2004-08-23 05:48:50 +08:00
|
|
|
|
|
2011-03-29 15:16:22 +08:00
|
|
|
|
measure->x[measure->point] = ROUND (x);
|
|
|
|
|
measure->y[measure->point] = ROUND (y);
|
2001-11-09 03:14:51 +08:00
|
|
|
|
}
|
1999-08-15 23:59:06 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2000-04-13 05:21:36 +08:00
|
|
|
|
case MOVING_ALL:
|
2006-09-13 04:24:50 +08:00
|
|
|
|
dx = ROUND (coords->x) - measure->last_x;
|
|
|
|
|
dy = ROUND (coords->y) - measure->last_y;
|
2001-11-09 03:14:51 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
for (i = 0; i < measure->num_points; i++)
|
2006-04-12 20:49:29 +08:00
|
|
|
|
{
|
2006-09-13 04:24:50 +08:00
|
|
|
|
measure->x[i] += dx;
|
|
|
|
|
measure->y[i] += dy;
|
2006-04-12 20:49:29 +08:00
|
|
|
|
}
|
2001-11-09 03:14:51 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
measure->last_x = ROUND (coords->x);
|
|
|
|
|
measure->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
|
|
|
|
}
|
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
if (measure->function == MOVING)
|
|
|
|
|
gimp_measure_tool_dialog_update (measure, display);
|
2003-08-22 09:42:57 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (measure));
|
1999-08-15 23:59:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2004-10-08 23:32:30 +08:00
|
|
|
|
static gboolean
|
|
|
|
|
gimp_measure_tool_key_press (GimpTool *tool,
|
|
|
|
|
GdkEventKey *kevent,
|
2006-03-29 01:55:52 +08:00
|
|
|
|
GimpDisplay *display)
|
2004-10-08 23:32:30 +08:00
|
|
|
|
{
|
2006-03-29 01:55:52 +08:00
|
|
|
|
if (display == tool->display)
|
2004-10-08 23:32:30 +08:00
|
|
|
|
{
|
|
|
|
|
switch (kevent->keyval)
|
|
|
|
|
{
|
2011-03-29 21:27:25 +08:00
|
|
|
|
case GDK_KEY_Escape:
|
2011-04-01 20:49:25 +08:00
|
|
|
|
gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display);
|
2004-10-08 23:32:30 +08:00
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_measure_tool_active_modifier_key (GimpTool *tool,
|
|
|
|
|
GdkModifierType key,
|
|
|
|
|
gboolean press,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpDisplay *display)
|
|
|
|
|
{
|
|
|
|
|
GimpMeasureTool *measure = GIMP_MEASURE_TOOL (tool);
|
|
|
|
|
|
2011-10-07 03:59:07 +08:00
|
|
|
|
if (key == gimp_get_constrain_behavior_mask () &&
|
|
|
|
|
measure->function == MOVING)
|
2006-09-13 04:24:50 +08:00
|
|
|
|
{
|
|
|
|
|
gdouble x, y;
|
|
|
|
|
|
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
|
|
|
|
|
|
|
|
|
x = measure->mouse_x;
|
|
|
|
|
y = measure->mouse_y;
|
|
|
|
|
|
|
|
|
|
if (press)
|
2009-04-23 03:08:42 +08:00
|
|
|
|
gimp_constrain_line (measure->x[0], measure->y[0],
|
|
|
|
|
&x, &y,
|
|
|
|
|
GIMP_CONSTRAIN_LINE_15_DEGREES);
|
2006-09-13 04:24:50 +08:00
|
|
|
|
|
|
|
|
|
measure->x[measure->point] = ROUND (x);
|
|
|
|
|
measure->y[measure->point] = ROUND (y);
|
|
|
|
|
|
2006-09-13 14:49:20 +08:00
|
|
|
|
gimp_measure_tool_dialog_update (measure, display);
|
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-08-15 23:59:06 +08:00
|
|
|
|
static void
|
2011-03-29 02:44:30 +08:00
|
|
|
|
gimp_measure_tool_oper_update (GimpTool *tool,
|
|
|
|
|
const GimpCoords *coords,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
gboolean proximity,
|
|
|
|
|
GimpDisplay *display)
|
1999-08-15 23:59:06 +08:00
|
|
|
|
{
|
2011-03-29 02:44:30 +08:00
|
|
|
|
GimpMeasureTool *measure = GIMP_MEASURE_TOOL (tool);
|
|
|
|
|
gchar *status = NULL;
|
|
|
|
|
gint i;
|
2000-06-14 18:59:16 +08:00
|
|
|
|
|
2011-03-29 15:16:22 +08:00
|
|
|
|
if (tool->display == display)
|
1999-08-15 23:59:06 +08:00
|
|
|
|
{
|
2011-03-29 14:52:09 +08:00
|
|
|
|
gint point = -1;
|
2011-03-29 02:44:30 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
for (i = 0; i < measure->num_points; i++)
|
2006-04-12 20:49:29 +08:00
|
|
|
|
{
|
2011-03-29 02:13:18 +08:00
|
|
|
|
if (gimp_canvas_item_hit (measure->handles[i],
|
|
|
|
|
coords->x, coords->y))
|
2006-04-12 20:49:29 +08:00
|
|
|
|
{
|
2011-10-07 03:59:07 +08:00
|
|
|
|
GdkModifierType toggle_mask = gimp_get_toggle_behavior_mask ();
|
|
|
|
|
|
2011-03-29 14:52:09 +08:00
|
|
|
|
point = i;
|
2006-04-12 20:49:29 +08:00
|
|
|
|
|
2011-10-07 03:59:07 +08:00
|
|
|
|
if (state & toggle_mask)
|
2006-04-12 20:49:29 +08:00
|
|
|
|
{
|
|
|
|
|
if (state & GDK_MOD1_MASK)
|
2007-03-01 06:35:37 +08:00
|
|
|
|
{
|
|
|
|
|
status = gimp_suggest_modifiers (_("Click to place "
|
|
|
|
|
"vertical and "
|
|
|
|
|
"horizontal guides"),
|
|
|
|
|
0,
|
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
|
}
|
2006-04-12 20:49:29 +08:00
|
|
|
|
else
|
2007-03-01 06:35:37 +08:00
|
|
|
|
{
|
|
|
|
|
status = gimp_suggest_modifiers (_("Click to place a "
|
|
|
|
|
"horizontal guide"),
|
|
|
|
|
GDK_MOD1_MASK & ~state,
|
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
|
}
|
2008-11-04 20:33:09 +08:00
|
|
|
|
|
|
|
|
|
gimp_tool_replace_status (tool, display, "%s", status);
|
2007-03-01 06:35:37 +08:00
|
|
|
|
g_free (status);
|
|
|
|
|
measure->status_help = TRUE;
|
2006-04-12 20:49:29 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state & GDK_MOD1_MASK)
|
|
|
|
|
{
|
2007-03-01 06:35:37 +08:00
|
|
|
|
status = gimp_suggest_modifiers (_("Click to place a "
|
|
|
|
|
"vertical guide"),
|
2011-10-07 03:59:07 +08:00
|
|
|
|
toggle_mask & ~state,
|
2007-03-01 06:35:37 +08:00
|
|
|
|
NULL, NULL, NULL);
|
2008-11-04 20:33:09 +08:00
|
|
|
|
gimp_tool_replace_status (tool, display, "%s", status);
|
2007-03-01 06:35:37 +08:00
|
|
|
|
g_free (status);
|
|
|
|
|
measure->status_help = TRUE;
|
2006-04-12 20:49:29 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-01 06:35:37 +08:00
|
|
|
|
if ((state & GDK_SHIFT_MASK)
|
|
|
|
|
&& ! ((i == 0) && (measure->num_points == 3)))
|
|
|
|
|
{
|
|
|
|
|
status = gimp_suggest_modifiers (_("Click-Drag to add a "
|
|
|
|
|
"new point"),
|
2011-10-07 03:59:07 +08:00
|
|
|
|
(toggle_mask |
|
|
|
|
|
GDK_MOD1_MASK) & ~state,
|
2007-03-01 06:35:37 +08:00
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
|
}
|
2006-04-12 20:49:29 +08:00
|
|
|
|
else
|
2007-03-01 06:35:37 +08:00
|
|
|
|
{
|
2007-03-01 16:52:37 +08:00
|
|
|
|
if ((i == 0) && (measure->num_points == 3))
|
|
|
|
|
state |= GDK_SHIFT_MASK;
|
2007-03-01 06:35:37 +08:00
|
|
|
|
status = gimp_suggest_modifiers (_("Click-Drag to move this "
|
|
|
|
|
"point"),
|
2011-10-07 03:59:07 +08:00
|
|
|
|
(GDK_SHIFT_MASK |
|
|
|
|
|
toggle_mask |
|
|
|
|
|
GDK_MOD1_MASK) & ~state,
|
2007-03-01 06:35:37 +08:00
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
|
}
|
2008-11-04 20:33:09 +08:00
|
|
|
|
|
|
|
|
|
gimp_tool_replace_status (tool, display, "%s", status);
|
2007-03-01 06:35:37 +08:00
|
|
|
|
g_free (status);
|
|
|
|
|
measure->status_help = TRUE;
|
2006-04-12 20:49:29 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-04-13 05:21:36 +08:00
|
|
|
|
|
2011-03-29 14:52:09 +08:00
|
|
|
|
if (point == -1)
|
2007-03-01 06:35:37 +08:00
|
|
|
|
{
|
|
|
|
|
if ((measure->num_points > 1) && (state & GDK_MOD1_MASK))
|
|
|
|
|
{
|
|
|
|
|
gimp_tool_replace_status (tool, display, _("Click-Drag to move "
|
|
|
|
|
"all points"));
|
|
|
|
|
measure->status_help = TRUE;
|
|
|
|
|
}
|
|
|
|
|
else if (measure->status_help)
|
|
|
|
|
{
|
|
|
|
|
if (measure->num_points > 1)
|
|
|
|
|
{
|
|
|
|
|
/* replace status bar hint by distance and angle */
|
|
|
|
|
gimp_measure_tool_dialog_update (measure, display);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gimp_tool_replace_status (tool, display, " ");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-29 02:44:30 +08:00
|
|
|
|
|
2011-03-29 14:52:09 +08:00
|
|
|
|
if (point != measure->point)
|
2011-03-29 02:44:30 +08:00
|
|
|
|
{
|
2011-03-29 14:52:09 +08:00
|
|
|
|
if (measure->point != -1 && measure->handles[measure->point])
|
2011-03-29 02:44:30 +08:00
|
|
|
|
{
|
2011-03-29 14:52:09 +08:00
|
|
|
|
gimp_canvas_item_set_highlight (measure->handles[measure->point],
|
2011-03-29 02:44:30 +08:00
|
|
|
|
FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-29 14:52:09 +08:00
|
|
|
|
measure->point = point;
|
2011-03-29 02:44:30 +08:00
|
|
|
|
|
2011-03-29 14:52:09 +08:00
|
|
|
|
if (measure->point != -1 && measure->handles[measure->point])
|
2011-03-29 02:44:30 +08:00
|
|
|
|
{
|
2011-03-29 14:52:09 +08:00
|
|
|
|
gimp_canvas_item_set_highlight (measure->handles[measure->point],
|
2011-03-29 02:44:30 +08:00
|
|
|
|
TRUE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gimp_measure_tool_cursor_update (GimpTool *tool,
|
|
|
|
|
const GimpCoords *coords,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpDisplay *display)
|
|
|
|
|
{
|
|
|
|
|
GimpMeasureTool *measure = GIMP_MEASURE_TOOL (tool);
|
|
|
|
|
GimpCursorType cursor = GIMP_CURSOR_CROSSHAIR_SMALL;
|
|
|
|
|
GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_NONE;
|
|
|
|
|
|
2011-03-29 15:16:22 +08:00
|
|
|
|
if (tool->display == display)
|
2011-03-29 02:44:30 +08:00
|
|
|
|
{
|
2011-03-29 14:52:09 +08:00
|
|
|
|
if (measure->point != -1)
|
2011-03-29 02:44:30 +08:00
|
|
|
|
{
|
2011-10-07 03:59:07 +08:00
|
|
|
|
GdkModifierType toggle_mask = gimp_get_toggle_behavior_mask ();
|
|
|
|
|
|
|
|
|
|
if (state & toggle_mask)
|
2011-03-29 02:44:30 +08:00
|
|
|
|
{
|
|
|
|
|
if (state & GDK_MOD1_MASK)
|
|
|
|
|
cursor = GIMP_CURSOR_CORNER_BOTTOM_RIGHT;
|
|
|
|
|
else
|
|
|
|
|
cursor = GIMP_CURSOR_SIDE_BOTTOM;
|
|
|
|
|
}
|
|
|
|
|
else if (state & GDK_MOD1_MASK)
|
|
|
|
|
{
|
|
|
|
|
cursor = GIMP_CURSOR_SIDE_RIGHT;
|
|
|
|
|
}
|
|
|
|
|
else if ((state & GDK_SHIFT_MASK) &&
|
2011-03-29 14:52:09 +08:00
|
|
|
|
! ((measure->point == 0) &&
|
2011-03-29 02:44:30 +08:00
|
|
|
|
(measure->num_points == 3)))
|
|
|
|
|
{
|
|
|
|
|
modifier = GIMP_CURSOR_MODIFIER_PLUS;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
modifier = GIMP_CURSOR_MODIFIER_MOVE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ((measure->num_points > 1) && (state & GDK_MOD1_MASK))
|
|
|
|
|
{
|
|
|
|
|
modifier = GIMP_CURSOR_MODIFIER_MOVE;
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-08-15 23:59:06 +08:00
|
|
|
|
}
|
2000-06-14 18:59:16 +08:00
|
|
|
|
|
2004-06-14 18:19:39 +08:00
|
|
|
|
gimp_tool_control_set_cursor (tool->control, cursor);
|
|
|
|
|
gimp_tool_control_set_cursor_modifier (tool->control, modifier);
|
2002-02-05 01:43:01 +08:00
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
|
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
|
|
|
|
{
|
2006-09-13 04:24:50 +08:00
|
|
|
|
GimpMeasureTool *measure = GIMP_MEASURE_TOOL (draw_tool);
|
|
|
|
|
GimpTool *tool = GIMP_TOOL (draw_tool);
|
2010-10-04 20:03:37 +08:00
|
|
|
|
GimpCanvasGroup *stroke_group;
|
2001-02-28 03:18:01 +08:00
|
|
|
|
gint i;
|
|
|
|
|
gint draw_arc = 0;
|
1999-08-15 23:59:06 +08:00
|
|
|
|
|
2011-03-29 02:13:18 +08:00
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
|
measure->handles[i] = 0;
|
|
|
|
|
|
2010-10-01 20:24:46 +08:00
|
|
|
|
stroke_group = gimp_draw_tool_add_stroke_group (draw_tool);
|
2010-09-26 21:49:10 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
for (i = 0; i < measure->num_points; i++)
|
1999-08-16 02:44:15 +08:00
|
|
|
|
{
|
2006-09-13 04:24:50 +08:00
|
|
|
|
if (i == 0 && measure->num_points == 3)
|
2006-04-12 20:49:29 +08:00
|
|
|
|
{
|
2011-03-29 02:13:18 +08:00
|
|
|
|
measure->handles[i] =
|
|
|
|
|
gimp_draw_tool_add_handle (draw_tool,
|
|
|
|
|
GIMP_HANDLE_CIRCLE,
|
|
|
|
|
measure->x[i],
|
|
|
|
|
measure->y[i],
|
|
|
|
|
GIMP_TOOL_HANDLE_SIZE_CROSS,
|
|
|
|
|
GIMP_TOOL_HANDLE_SIZE_CROSS,
|
|
|
|
|
GIMP_HANDLE_ANCHOR_CENTER);
|
2006-04-12 20:49:29 +08:00
|
|
|
|
}
|
1999-08-19 02:48:35 +08:00
|
|
|
|
else
|
2006-04-12 20:49:29 +08:00
|
|
|
|
{
|
2011-03-29 02:13:18 +08:00
|
|
|
|
measure->handles[i] =
|
|
|
|
|
gimp_draw_tool_add_handle (draw_tool,
|
|
|
|
|
GIMP_HANDLE_CROSS,
|
|
|
|
|
measure->x[i],
|
|
|
|
|
measure->y[i],
|
|
|
|
|
GIMP_TOOL_HANDLE_SIZE_CROSS,
|
|
|
|
|
GIMP_TOOL_HANDLE_SIZE_CROSS,
|
|
|
|
|
GIMP_HANDLE_ANCHOR_CENTER);
|
2006-04-12 20:49:29 +08:00
|
|
|
|
}
|
2001-11-12 22:45:58 +08:00
|
|
|
|
|
1999-08-19 02:48:35 +08:00
|
|
|
|
if (i > 0)
|
2006-04-12 20:49:29 +08:00
|
|
|
|
{
|
2010-10-04 20:03:37 +08:00
|
|
|
|
gimp_draw_tool_push_group (draw_tool, stroke_group);
|
2010-09-26 21:49:10 +08:00
|
|
|
|
|
2010-10-04 20:03:37 +08:00
|
|
|
|
gimp_draw_tool_add_line (draw_tool,
|
|
|
|
|
measure->x[0],
|
|
|
|
|
measure->y[0],
|
|
|
|
|
measure->x[i],
|
|
|
|
|
measure->y[i]);
|
|
|
|
|
|
|
|
|
|
gimp_draw_tool_pop_group (draw_tool);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
|
/* only draw the arc if the lines are long enough */
|
2006-03-29 01:55:52 +08:00
|
|
|
|
if (gimp_draw_tool_calc_distance (draw_tool, tool->display,
|
2006-09-13 04:24:50 +08:00
|
|
|
|
measure->x[0],
|
|
|
|
|
measure->y[0],
|
|
|
|
|
measure->x[i],
|
|
|
|
|
measure->y[i]) > ARC_RADIUS)
|
2001-11-12 22:45:58 +08:00
|
|
|
|
{
|
|
|
|
|
draw_arc++;
|
|
|
|
|
}
|
2006-04-12 20:49:29 +08:00
|
|
|
|
}
|
1999-08-16 02:44:15 +08:00
|
|
|
|
}
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
2011-03-29 15:16:22 +08:00
|
|
|
|
if (measure->point != -1 && measure->handles[measure->point])
|
|
|
|
|
{
|
|
|
|
|
gimp_canvas_item_set_highlight (measure->handles[measure->point],
|
|
|
|
|
TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
if (measure->num_points > 1 && draw_arc == measure->num_points - 1)
|
1999-08-16 02:44:15 +08:00
|
|
|
|
{
|
2010-09-25 23:35:40 +08:00
|
|
|
|
gdouble angle1 = measure->angle2 / 180.0 * G_PI;
|
|
|
|
|
gdouble angle2 = (measure->angle1 - measure->angle2) / 180.0 * G_PI;
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
2010-09-25 23:35:40 +08:00
|
|
|
|
if (angle2 > G_PI)
|
|
|
|
|
angle2 -= 2.0 * G_PI;
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
2010-09-25 23:35:40 +08:00
|
|
|
|
if (angle2 < -G_PI)
|
|
|
|
|
angle2 += 2.0 * G_PI;
|
|
|
|
|
|
|
|
|
|
if (angle2 != 0.0)
|
2006-04-12 20:49:29 +08:00
|
|
|
|
{
|
2010-10-04 20:03:37 +08:00
|
|
|
|
GimpCanvasItem *item;
|
|
|
|
|
|
|
|
|
|
gimp_draw_tool_push_group (draw_tool, stroke_group);
|
|
|
|
|
|
2010-09-26 01:02:22 +08:00
|
|
|
|
item = gimp_draw_tool_add_handle (draw_tool,
|
|
|
|
|
GIMP_HANDLE_CIRCLE,
|
|
|
|
|
measure->x[0],
|
|
|
|
|
measure->y[0],
|
|
|
|
|
ARC_RADIUS * 2 + 1,
|
|
|
|
|
ARC_RADIUS * 2 + 1,
|
2010-10-19 02:13:09 +08:00
|
|
|
|
GIMP_HANDLE_ANCHOR_CENTER);
|
2000-12-28 07:25:51 +08:00
|
|
|
|
|
2011-03-28 18:20:36 +08:00
|
|
|
|
gimp_canvas_handle_set_angles (item, angle1, angle2);
|
2010-09-25 23:59:56 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
if (measure->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;
|
|
|
|
|
|
2009-10-05 01:56:39 +08:00
|
|
|
|
shell = gimp_display_get_shell (tool->display);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
|
2010-11-09 05:37:00 +08:00
|
|
|
|
target = FUNSCALEX (shell, (GIMP_TOOL_HANDLE_SIZE_CROSS >> 1));
|
2002-06-27 06:16:59 +08:00
|
|
|
|
arc_radius = FUNSCALEX (shell, ARC_RADIUS);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
|
2010-10-04 20:03:37 +08:00
|
|
|
|
gimp_draw_tool_add_line (draw_tool,
|
|
|
|
|
measure->x[0],
|
|
|
|
|
measure->y[0],
|
|
|
|
|
(measure->x[1] >= measure->x[0] ?
|
|
|
|
|
measure->x[0] + arc_radius + target :
|
|
|
|
|
measure->x[0] - arc_radius - target),
|
|
|
|
|
measure->y[0]);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
}
|
2010-10-04 20:03:37 +08:00
|
|
|
|
|
|
|
|
|
gimp_draw_tool_pop_group (draw_tool);
|
2006-04-12 20:49:29 +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
|
2004-10-08 23:32:30 +08:00
|
|
|
|
gimp_measure_tool_get_angle (gint dx,
|
|
|
|
|
gint dy,
|
|
|
|
|
gdouble xres,
|
|
|
|
|
gdouble yres)
|
2001-02-28 03:18:01 +08:00
|
|
|
|
{
|
|
|
|
|
gdouble angle;
|
|
|
|
|
|
|
|
|
|
if (dx)
|
|
|
|
|
angle = gimp_rad_to_deg (atan (((gdouble) (dy) / yres) /
|
2006-04-12 20:49:29 +08:00
|
|
|
|
((gdouble) (dx) / xres)));
|
2001-02-28 03:18:01 +08:00
|
|
|
|
else if (dy)
|
|
|
|
|
angle = dy > 0 ? 270.0 : 90.0;
|
|
|
|
|
else
|
|
|
|
|
angle = 180.0;
|
|
|
|
|
|
|
|
|
|
if (dx > 0)
|
|
|
|
|
{
|
|
|
|
|
if (dy > 0)
|
2006-04-12 20:49:29 +08:00
|
|
|
|
angle = 360.0 - angle;
|
2001-02-28 03:18:01 +08:00
|
|
|
|
else
|
2006-04-12 20:49:29 +08:00
|
|
|
|
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
|
2006-09-13 04:24:50 +08:00
|
|
|
|
gimp_measure_tool_dialog_update (GimpMeasureTool *measure,
|
2006-03-29 01:55:52 +08:00
|
|
|
|
GimpDisplay *display)
|
1999-08-21 19:30:10 +08:00
|
|
|
|
{
|
2009-10-05 01:56:39 +08:00
|
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (display);
|
2009-10-08 01:00:42 +08:00
|
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
gint ax, ay;
|
|
|
|
|
gint bx, by;
|
2005-03-21 18:27:36 +08:00
|
|
|
|
gint pixel_width;
|
|
|
|
|
gint pixel_height;
|
|
|
|
|
gdouble unit_width;
|
|
|
|
|
gdouble unit_height;
|
2003-10-21 01:36:18 +08:00
|
|
|
|
gdouble pixel_distance;
|
|
|
|
|
gdouble unit_distance;
|
2005-03-21 18:27:36 +08:00
|
|
|
|
gdouble theta1, theta2;
|
|
|
|
|
gdouble pixel_angle;
|
2003-10-21 01:36:18 +08:00
|
|
|
|
gdouble unit_angle;
|
2007-12-27 01:33:41 +08:00
|
|
|
|
gdouble xres;
|
|
|
|
|
gdouble yres;
|
2003-10-21 01:36:18 +08:00
|
|
|
|
gchar format[128];
|
|
|
|
|
|
|
|
|
|
/* calculate distance and angle */
|
2006-09-13 04:24:50 +08:00
|
|
|
|
ax = measure->x[1] - measure->x[0];
|
|
|
|
|
ay = measure->y[1] - measure->y[0];
|
2003-10-21 01:36:18 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
if (measure->num_points == 3)
|
2003-10-21 01:36:18 +08:00
|
|
|
|
{
|
2006-09-13 04:24:50 +08:00
|
|
|
|
bx = measure->x[2] - measure->x[0];
|
|
|
|
|
by = measure->y[2] - measure->y[0];
|
2003-10-21 01:36:18 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bx = 0;
|
|
|
|
|
by = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-21 18:27:36 +08:00
|
|
|
|
pixel_width = ABS (ax - bx);
|
|
|
|
|
pixel_height = ABS (ay - by);
|
|
|
|
|
|
2007-12-27 01:33:41 +08:00
|
|
|
|
gimp_image_get_resolution (image, &xres, &yres);
|
|
|
|
|
|
2010-02-21 23:46:39 +08:00
|
|
|
|
unit_width = gimp_pixels_to_units (pixel_width, shell->unit, xres);
|
|
|
|
|
unit_height = gimp_pixels_to_units (pixel_height, shell->unit, yres);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
|
2003-10-21 01:36:18 +08:00
|
|
|
|
pixel_distance = sqrt (SQR (ax - bx) + SQR (ay - by));
|
2010-02-21 23:46:39 +08:00
|
|
|
|
unit_distance = (gimp_unit_get_factor (shell->unit) *
|
|
|
|
|
sqrt (SQR ((gdouble) (ax - bx) / xres) +
|
|
|
|
|
SQR ((gdouble) (ay - by) / yres)));
|
2003-10-21 01:36:18 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
if (measure->num_points != 3)
|
2003-10-21 01:36:18 +08:00
|
|
|
|
bx = ax > 0 ? 1 : -1;
|
|
|
|
|
|
2004-10-08 23:32:30 +08:00
|
|
|
|
theta1 = gimp_measure_tool_get_angle (ax, ay, 1.0, 1.0);
|
|
|
|
|
theta2 = gimp_measure_tool_get_angle (bx, by, 1.0, 1.0);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
|
|
|
|
|
pixel_angle = fabs (theta1 - theta2);
|
|
|
|
|
if (pixel_angle > 180.0)
|
|
|
|
|
pixel_angle = fabs (360.0 - pixel_angle);
|
|
|
|
|
|
2007-12-27 01:33:41 +08:00
|
|
|
|
theta1 = gimp_measure_tool_get_angle (ax, ay, xres, yres);
|
|
|
|
|
theta2 = gimp_measure_tool_get_angle (bx, by, xres, yres);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
measure->angle1 = theta1;
|
|
|
|
|
measure->angle2 = theta2;
|
2003-10-21 01:36:18 +08:00
|
|
|
|
|
|
|
|
|
unit_angle = fabs (theta1 - theta2);
|
|
|
|
|
if (unit_angle > 180.0)
|
|
|
|
|
unit_angle = fabs (360.0 - unit_angle);
|
|
|
|
|
|
2004-06-02 06:04:20 +08:00
|
|
|
|
if (shell->unit == GIMP_UNIT_PIXEL)
|
2003-10-21 01:36:18 +08:00
|
|
|
|
{
|
2006-09-28 19:07:55 +08:00
|
|
|
|
gimp_tool_replace_status (GIMP_TOOL (measure), display,
|
|
|
|
|
"%.1f %s, %.2f\302\260 (%d × %d)",
|
|
|
|
|
pixel_distance, _("pixels"), pixel_angle,
|
|
|
|
|
pixel_width, pixel_height);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2005-03-21 18:27:36 +08:00
|
|
|
|
g_snprintf (format, sizeof (format),
|
2006-09-13 14:49:20 +08:00
|
|
|
|
"%%.%df %s, %%.2f\302\260 (%%.%df × %%.%df)",
|
2010-02-21 23:46:39 +08:00
|
|
|
|
gimp_unit_get_digits (shell->unit),
|
|
|
|
|
gimp_unit_get_plural (shell->unit),
|
|
|
|
|
gimp_unit_get_digits (shell->unit),
|
|
|
|
|
gimp_unit_get_digits (shell->unit));
|
2003-10-21 01:36:18 +08:00
|
|
|
|
|
2006-09-28 19:07:55 +08:00
|
|
|
|
gimp_tool_replace_status (GIMP_TOOL (measure), display, format,
|
|
|
|
|
unit_distance, unit_angle,
|
|
|
|
|
unit_width, unit_height);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
}
|
2007-03-01 06:35:37 +08:00
|
|
|
|
measure->status_help = FALSE;
|
2003-10-21 01:36:18 +08:00
|
|
|
|
|
2013-06-07 18:03:39 +08:00
|
|
|
|
if (measure->gui)
|
2003-10-21 01:36:18 +08:00
|
|
|
|
{
|
2006-09-28 19:07:55 +08:00
|
|
|
|
gchar buf[128];
|
|
|
|
|
|
2005-03-21 18:27:36 +08:00
|
|
|
|
g_snprintf (format, sizeof (format), "%%.%df",
|
2010-02-21 23:46:39 +08:00
|
|
|
|
gimp_unit_get_digits (shell->unit));
|
|
|
|
|
|
2005-03-21 18:27:36 +08:00
|
|
|
|
/* Distance */
|
2003-10-21 01:36:18 +08:00
|
|
|
|
g_snprintf (buf, sizeof (buf), "%.1f", pixel_distance);
|
2006-09-13 04:24:50 +08:00
|
|
|
|
gtk_label_set_text (GTK_LABEL (measure->distance_label[0]), buf);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
|
2006-02-15 22:48:40 +08:00
|
|
|
|
if (shell->unit != GIMP_UNIT_PIXEL)
|
|
|
|
|
{
|
|
|
|
|
g_snprintf (buf, sizeof (buf), format, unit_distance);
|
2006-09-13 04:24:50 +08:00
|
|
|
|
gtk_label_set_text (GTK_LABEL (measure->distance_label[1]), buf);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
gtk_label_set_text (GTK_LABEL (measure->unit_label[0]),
|
2010-02-21 23:46:39 +08:00
|
|
|
|
gimp_unit_get_plural (shell->unit));
|
2006-02-15 22:48:40 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-03-01 00:46:55 +08:00
|
|
|
|
gtk_label_set_text (GTK_LABEL (measure->distance_label[1]), NULL);
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (measure->unit_label[0]), NULL);
|
2006-02-15 22:48:40 +08:00
|
|
|
|
}
|
2003-10-21 01:36:18 +08:00
|
|
|
|
|
2005-03-21 18:27:36 +08:00
|
|
|
|
/* Angle */
|
|
|
|
|
g_snprintf (buf, sizeof (buf), "%.2f", pixel_angle);
|
2006-09-13 04:24:50 +08:00
|
|
|
|
gtk_label_set_text (GTK_LABEL (measure->angle_label[0]), buf);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
|
2003-10-21 01:36:18 +08:00
|
|
|
|
if (fabs (unit_angle - pixel_angle) > 0.01)
|
|
|
|
|
{
|
|
|
|
|
g_snprintf (buf, sizeof (buf), "%.2f", unit_angle);
|
2006-09-13 04:24:50 +08:00
|
|
|
|
gtk_label_set_text (GTK_LABEL (measure->angle_label[1]), buf);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
gtk_label_set_text (GTK_LABEL (measure->unit_label[1]), "\302\260");
|
2003-10-21 01:36:18 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-03-01 00:46:55 +08:00
|
|
|
|
gtk_label_set_text (GTK_LABEL (measure->angle_label[1]), NULL);
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (measure->unit_label[1]), NULL);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-21 18:27:36 +08:00
|
|
|
|
/* Width */
|
|
|
|
|
g_snprintf (buf, sizeof (buf), "%d", pixel_width);
|
2006-09-13 04:24:50 +08:00
|
|
|
|
gtk_label_set_text (GTK_LABEL (measure->width_label[0]), buf);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
|
2006-02-15 22:48:40 +08:00
|
|
|
|
if (shell->unit != GIMP_UNIT_PIXEL)
|
|
|
|
|
{
|
|
|
|
|
g_snprintf (buf, sizeof (buf), format, unit_width);
|
2006-09-13 04:24:50 +08:00
|
|
|
|
gtk_label_set_text (GTK_LABEL (measure->width_label[1]), buf);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
gtk_label_set_text (GTK_LABEL (measure->unit_label[2]),
|
2010-02-21 23:46:39 +08:00
|
|
|
|
gimp_unit_get_plural (shell->unit));
|
2006-02-15 22:48:40 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-03-01 00:46:55 +08:00
|
|
|
|
gtk_label_set_text (GTK_LABEL (measure->width_label[1]), NULL);
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (measure->unit_label[2]), NULL);
|
2006-02-15 22:48:40 +08:00
|
|
|
|
}
|
2005-03-21 18:27:36 +08:00
|
|
|
|
|
|
|
|
|
g_snprintf (buf, sizeof (buf), "%d", pixel_height);
|
2006-09-13 04:24:50 +08:00
|
|
|
|
gtk_label_set_text (GTK_LABEL (measure->height_label[0]), buf);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
|
2006-02-15 22:48:40 +08:00
|
|
|
|
/* Height */
|
|
|
|
|
if (shell->unit != GIMP_UNIT_PIXEL)
|
|
|
|
|
{
|
|
|
|
|
g_snprintf (buf, sizeof (buf), format, unit_height);
|
2006-09-13 04:24:50 +08:00
|
|
|
|
gtk_label_set_text (GTK_LABEL (measure->height_label[1]), buf);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
gtk_label_set_text (GTK_LABEL (measure->unit_label[3]),
|
2010-02-21 23:46:39 +08:00
|
|
|
|
gimp_unit_get_plural (shell->unit));
|
2006-02-15 22:48:40 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-03-01 00:46:55 +08:00
|
|
|
|
gtk_label_set_text (GTK_LABEL (measure->height_label[1]), NULL);
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (measure->unit_label[3]), NULL);
|
2006-02-15 22:48:40 +08:00
|
|
|
|
}
|
2005-03-21 18:27:36 +08:00
|
|
|
|
|
2013-06-07 18:03:39 +08:00
|
|
|
|
gimp_tool_gui_show (measure->gui);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
}
|
1999-08-21 19:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 18:03:39 +08:00
|
|
|
|
static GimpToolGui *
|
2006-09-13 04:24:50 +08:00
|
|
|
|
gimp_measure_tool_dialog_new (GimpMeasureTool *measure)
|
1999-08-21 19:30:10 +08:00
|
|
|
|
{
|
2013-06-07 18:03:39 +08:00
|
|
|
|
GimpTool *tool = GIMP_TOOL (measure);
|
|
|
|
|
GimpToolGui *gui;
|
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
GtkWidget *vbox;
|
|
|
|
|
GtkWidget *table;
|
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
|
|
gui = gimp_tool_gui_new (tool->tool_info,
|
|
|
|
|
_("Measure Distances and Angles"),
|
|
|
|
|
FALSE,
|
2003-10-21 01:36:18 +08:00
|
|
|
|
|
2013-06-07 18:03:39 +08:00
|
|
|
|
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
|
2003-10-21 01:36:18 +08:00
|
|
|
|
|
2013-06-07 18:03:39 +08:00
|
|
|
|
NULL);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
|
2013-06-07 18:03:39 +08:00
|
|
|
|
dialog = gimp_tool_gui_get_dialog (gui);
|
|
|
|
|
vbox = gimp_tool_gui_get_vbox (gui);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
|
2013-06-07 18:03:39 +08:00
|
|
|
|
if (GTK_IS_DIALOG (dialog))
|
|
|
|
|
gtk_window_set_focus_on_map (GTK_WINDOW (dialog), FALSE);
|
2006-02-15 22:48:40 +08:00
|
|
|
|
|
2013-06-08 05:45:11 +08:00
|
|
|
|
g_signal_connect (gui, "response",
|
|
|
|
|
G_CALLBACK (g_object_unref),
|
|
|
|
|
NULL);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
|
2005-03-21 18:27:36 +08:00
|
|
|
|
table = gtk_table_new (4, 5, TRUE);
|
2004-05-26 21:39:23 +08:00
|
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
|
|
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
|
2013-06-07 18:03:39 +08:00
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
gtk_widget_show (table);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
label = gtk_label_new (_("Distance:"));
|
2004-05-12 19:37:21 +08:00
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 0, 1);
|
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
measure->distance_label[0] = label = gtk_label_new ("0.0");
|
2007-03-01 00:46:55 +08:00
|
|
|
|
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 1, 2, 0, 1);
|
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
|
|
label = gtk_label_new (_("pixels"));
|
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 2, 3, 0, 1);
|
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
measure->distance_label[1] = label = gtk_label_new ("0.0");
|
2007-03-01 00:46:55 +08:00
|
|
|
|
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 3, 4, 0, 1);
|
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2007-03-01 00:46:55 +08:00
|
|
|
|
measure->unit_label[0] = label = gtk_label_new (NULL);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 4, 5, 0, 1);
|
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
label = gtk_label_new (_("Angle:"));
|
2004-05-12 19:37:21 +08:00
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 1, 2);
|
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
measure->angle_label[0] = label = gtk_label_new ("0.0");
|
2007-03-01 00:46:55 +08:00
|
|
|
|
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 1, 2, 1, 2);
|
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
|
|
label = gtk_label_new ("\302\260");
|
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 2, 3, 1, 2);
|
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2007-03-01 00:46:55 +08:00
|
|
|
|
measure->angle_label[1] = label = gtk_label_new (NULL);
|
|
|
|
|
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 3, 4, 1, 2);
|
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2007-03-01 00:46:55 +08:00
|
|
|
|
measure->unit_label[1] = label = gtk_label_new (NULL);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 4, 5, 1, 2);
|
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2005-03-21 18:27:36 +08:00
|
|
|
|
|
|
|
|
|
label = gtk_label_new (_("Width:"));
|
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 2, 3);
|
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
measure->width_label[0] = label = gtk_label_new ("0.0");
|
2007-03-01 00:46:55 +08:00
|
|
|
|
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 1, 2, 2, 3);
|
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
|
|
label = gtk_label_new (_("pixels"));
|
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 2, 3, 2, 3);
|
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
measure->width_label[1] = label = gtk_label_new ("0.0");
|
2007-03-01 00:46:55 +08:00
|
|
|
|
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 3, 4, 2, 3);
|
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2007-03-01 00:46:55 +08:00
|
|
|
|
measure->unit_label[2] = label = gtk_label_new (NULL);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 4, 5, 2, 3);
|
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
label = gtk_label_new (_("Height:"));
|
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 3, 4);
|
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
measure->height_label[0] = label = gtk_label_new ("0.0");
|
2007-03-01 00:46:55 +08:00
|
|
|
|
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 1, 2, 3, 4);
|
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
|
|
label = gtk_label_new (_("pixels"));
|
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 2, 3, 3, 4);
|
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2006-09-13 04:24:50 +08:00
|
|
|
|
measure->height_label[1] = label = gtk_label_new ("0.0");
|
2007-03-01 00:46:55 +08:00
|
|
|
|
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 3, 4, 3, 4);
|
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2007-03-01 00:46:55 +08:00
|
|
|
|
measure->unit_label[3] = label = gtk_label_new (NULL);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
|
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), label, 4, 5, 3, 4);
|
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2013-06-07 18:03:39 +08:00
|
|
|
|
return gui;
|
1999-08-21 19:30:10 +08:00
|
|
|
|
}
|