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
|
|
|
|
|
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"
|
|
|
|
|
|
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"
|
2002-08-31 05:00:42 +08:00
|
|
|
|
|
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"
|
2017-06-12 05:44:55 +08:00
|
|
|
|
#include "display/gimptoolcompass.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
|
|
|
|
|
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);
|
|
|
|
|
|
2017-06-12 05:44:55 +08:00
|
|
|
|
static void gimp_measure_tool_compass_changed (GimpToolWidget *widget,
|
|
|
|
|
GimpMeasureTool *measure);
|
2017-06-28 02:30:31 +08:00
|
|
|
|
static void gimp_measure_tool_compass_response(GimpToolWidget *widget,
|
|
|
|
|
gint response_id,
|
|
|
|
|
GimpMeasureTool *measure);
|
2017-06-12 05:44:55 +08:00
|
|
|
|
static void gimp_measure_tool_compass_status (GimpToolWidget *widget,
|
|
|
|
|
const gchar *status,
|
|
|
|
|
GimpMeasureTool *measure);
|
|
|
|
|
static void gimp_measure_tool_compass_create_guides
|
|
|
|
|
(GimpToolWidget *widget,
|
|
|
|
|
gint x,
|
|
|
|
|
gint y,
|
|
|
|
|
gboolean horizontal,
|
|
|
|
|
gboolean vertical,
|
|
|
|
|
GimpMeasureTool *measure);
|
|
|
|
|
|
2017-06-28 02:30:31 +08:00
|
|
|
|
static void gimp_measure_tool_start (GimpMeasureTool *measure,
|
|
|
|
|
GimpDisplay *display,
|
|
|
|
|
const GimpCoords *coords);
|
|
|
|
|
static void gimp_measure_tool_halt (GimpMeasureTool *measure);
|
|
|
|
|
|
2007-02-28 02:55:12 +08:00
|
|
|
|
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,
|
2017-03-05 23:01:59 +08:00
|
|
|
|
GIMP_ICON_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)
|
|
|
|
|
{
|
2017-06-27 01:50:31 +08:00
|
|
|
|
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
2001-02-21 20:18:09 +08:00
|
|
|
|
|
2017-06-27 03:03:09 +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;
|
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);
|
2017-10-29 23:38:24 +08:00
|
|
|
|
gimp_tool_control_set_active_modifiers (tool->control,
|
|
|
|
|
GIMP_TOOL_ACTIVE_MODIFIERS_SEPARATE);
|
2009-02-21 00:57:26 +08:00
|
|
|
|
gimp_tool_control_set_precision (tool->control,
|
|
|
|
|
GIMP_CURSOR_PRECISION_PIXEL_BORDER);
|
2017-06-28 04:41:25 +08:00
|
|
|
|
gimp_tool_control_set_cursor (tool->control,
|
|
|
|
|
GIMP_CURSOR_CROSSHAIR_SMALL);
|
2005-11-24 03:14:05 +08:00
|
|
|
|
gimp_tool_control_set_tool_cursor (tool->control,
|
|
|
|
|
GIMP_TOOL_CURSOR_MEASURE);
|
2017-06-28 02:30:31 +08:00
|
|
|
|
|
|
|
|
|
gimp_draw_tool_set_default_status (GIMP_DRAW_TOOL (tool),
|
|
|
|
|
_("Click-Drag to create a line"));
|
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:
|
2017-06-28 02:30:31 +08:00
|
|
|
|
gimp_measure_tool_halt (measure);
|
2001-02-28 03:18:01 +08:00
|
|
|
|
break;
|
2014-04-05 04:34:26 +08:00
|
|
|
|
|
|
|
|
|
case GIMP_TOOL_ACTION_COMMIT:
|
|
|
|
|
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
|
|
|
|
|
2017-06-28 02:30:31 +08:00
|
|
|
|
if (tool->display && display != tool->display)
|
|
|
|
|
gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, tool->display);
|
2003-08-22 09:42:57 +08:00
|
|
|
|
|
2017-06-28 04:50:50 +08:00
|
|
|
|
if (! measure->widget)
|
1999-08-15 23:59:06 +08:00
|
|
|
|
{
|
2017-06-28 02:30:31 +08:00
|
|
|
|
gimp_measure_tool_start (measure, display, coords);
|
2017-06-27 03:03:09 +08:00
|
|
|
|
|
2017-06-28 04:50:50 +08:00
|
|
|
|
gimp_tool_widget_hover (measure->widget, coords, state, TRUE);
|
2017-06-12 05:44:55 +08:00
|
|
|
|
}
|
2002-02-03 20:10:23 +08:00
|
|
|
|
|
2017-06-28 04:50:50 +08:00
|
|
|
|
if (gimp_tool_widget_button_press (measure->widget, coords, time, state,
|
2017-06-12 05:44:55 +08:00
|
|
|
|
press_type))
|
|
|
|
|
{
|
2017-06-28 04:50:50 +08:00
|
|
|
|
measure->grab_widget = measure->widget;
|
1999-08-15 23:59:06 +08:00
|
|
|
|
}
|
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
|
|
|
|
}
|
2017-06-28 02:30:31 +08:00
|
|
|
|
|
|
|
|
|
gimp_tool_control_activate (tool->control);
|
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
|
|
|
|
|
2011-03-29 15:16:22 +08:00
|
|
|
|
gimp_tool_control_halt (tool->control);
|
2017-06-12 05:44:55 +08:00
|
|
|
|
|
|
|
|
|
if (measure->grab_widget)
|
|
|
|
|
{
|
|
|
|
|
gimp_tool_widget_button_release (measure->grab_widget,
|
|
|
|
|
coords, time, state, release_type);
|
|
|
|
|
measure->grab_widget = NULL;
|
|
|
|
|
}
|
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);
|
|
|
|
|
|
2017-06-12 05:44:55 +08:00
|
|
|
|
if (measure->grab_widget)
|
1999-08-15 23:59:06 +08:00
|
|
|
|
{
|
2017-06-12 05:44:55 +08:00
|
|
|
|
gimp_tool_widget_motion (measure->grab_widget, coords, time, state);
|
1999-08-19 02:48:35 +08:00
|
|
|
|
}
|
1999-08-15 23:59:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 05:44:55 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_measure_tool_compass_changed (GimpToolWidget *widget,
|
|
|
|
|
GimpMeasureTool *measure)
|
|
|
|
|
{
|
|
|
|
|
g_object_get (widget,
|
|
|
|
|
"n-points", &measure->n_points,
|
|
|
|
|
"x1", &measure->x[0],
|
|
|
|
|
"y1", &measure->y[0],
|
|
|
|
|
"x2", &measure->x[1],
|
|
|
|
|
"y2", &measure->y[1],
|
|
|
|
|
"x3", &measure->x[2],
|
|
|
|
|
"y3", &measure->y[2],
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
gimp_measure_tool_dialog_update (measure, GIMP_TOOL (measure)->display);
|
|
|
|
|
}
|
2001-02-27 13:21:12 +08:00
|
|
|
|
|
2017-06-28 02:30:31 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_measure_tool_compass_response (GimpToolWidget *widget,
|
|
|
|
|
gint response_id,
|
|
|
|
|
GimpMeasureTool *measure)
|
|
|
|
|
{
|
|
|
|
|
GimpTool *tool = GIMP_TOOL (measure);
|
|
|
|
|
|
|
|
|
|
if (response_id == GIMP_TOOL_WIDGET_RESPONSE_CANCEL)
|
|
|
|
|
gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, tool->display);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 05:44:55 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_measure_tool_compass_status (GimpToolWidget *widget,
|
|
|
|
|
const gchar *status,
|
|
|
|
|
GimpMeasureTool *measure)
|
|
|
|
|
{
|
|
|
|
|
GimpTool *tool = GIMP_TOOL (measure);
|
|
|
|
|
|
2017-06-28 02:30:31 +08:00
|
|
|
|
if (! status)
|
1999-08-16 02:44:15 +08:00
|
|
|
|
{
|
2017-06-12 05:44:55 +08:00
|
|
|
|
/* replace status bar hint by distance and angle */
|
|
|
|
|
gimp_measure_tool_dialog_update (measure, tool->display);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-10-04 20:03:37 +08:00
|
|
|
|
|
2017-06-12 05:44:55 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_measure_tool_compass_create_guides (GimpToolWidget *widget,
|
|
|
|
|
gint x,
|
|
|
|
|
gint y,
|
|
|
|
|
gboolean horizontal,
|
|
|
|
|
gboolean vertical,
|
|
|
|
|
GimpMeasureTool *measure)
|
|
|
|
|
{
|
|
|
|
|
GimpDisplay *display = GIMP_TOOL (measure)->display;
|
|
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
2010-10-04 20:03:37 +08:00
|
|
|
|
|
2017-06-12 05:44:55 +08:00
|
|
|
|
if (x < 0 || x > gimp_image_get_width (image))
|
|
|
|
|
vertical = FALSE;
|
2000-12-28 07:25:51 +08:00
|
|
|
|
|
2017-06-12 05:44:55 +08:00
|
|
|
|
if (y < 0 || y > gimp_image_get_height (image))
|
|
|
|
|
horizontal = FALSE;
|
2010-09-25 23:59:56 +08:00
|
|
|
|
|
2017-06-12 05:44:55 +08:00
|
|
|
|
if (horizontal || vertical)
|
|
|
|
|
{
|
|
|
|
|
if (horizontal && vertical)
|
|
|
|
|
gimp_image_undo_group_start (image,
|
|
|
|
|
GIMP_UNDO_GROUP_GUIDE,
|
|
|
|
|
_("Add Guides"));
|
2002-06-27 06:16:59 +08:00
|
|
|
|
|
2017-06-12 05:44:55 +08:00
|
|
|
|
if (horizontal)
|
|
|
|
|
gimp_image_add_hguide (image, y, TRUE);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
|
2017-06-12 05:44:55 +08:00
|
|
|
|
if (vertical)
|
|
|
|
|
gimp_image_add_vguide (image, x, TRUE);
|
2001-11-12 22:45:58 +08:00
|
|
|
|
|
2017-06-12 05:44:55 +08:00
|
|
|
|
if (horizontal && vertical)
|
|
|
|
|
gimp_image_undo_group_end (image);
|
2010-10-04 20:03:37 +08:00
|
|
|
|
|
2017-06-12 05:44:55 +08:00
|
|
|
|
gimp_image_flush (image);
|
1999-08-16 02:44:15 +08:00
|
|
|
|
}
|
1999-08-15 23:59:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-28 02:30:31 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_measure_tool_start (GimpMeasureTool *measure,
|
|
|
|
|
GimpDisplay *display,
|
|
|
|
|
const GimpCoords *coords)
|
|
|
|
|
{
|
|
|
|
|
GimpTool *tool = GIMP_TOOL (measure);
|
|
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (display);
|
|
|
|
|
|
|
|
|
|
measure->n_points = 1;
|
|
|
|
|
measure->x[0] = coords->x;
|
|
|
|
|
measure->y[0] = coords->y;
|
|
|
|
|
measure->x[1] = 0;
|
|
|
|
|
measure->y[1] = 0;
|
|
|
|
|
measure->x[2] = 0;
|
|
|
|
|
measure->y[2] = 0;
|
|
|
|
|
|
2017-06-28 04:50:50 +08:00
|
|
|
|
measure->widget = gimp_tool_compass_new (shell,
|
|
|
|
|
measure->n_points,
|
|
|
|
|
measure->x[0],
|
|
|
|
|
measure->y[0],
|
|
|
|
|
measure->x[1],
|
|
|
|
|
measure->y[1],
|
|
|
|
|
measure->x[2],
|
|
|
|
|
measure->y[2]);
|
2017-06-28 02:30:31 +08:00
|
|
|
|
|
2017-06-28 04:50:50 +08:00
|
|
|
|
gimp_draw_tool_set_widget (GIMP_DRAW_TOOL (tool), measure->widget);
|
2017-06-28 02:30:31 +08:00
|
|
|
|
|
2017-06-28 04:50:50 +08:00
|
|
|
|
g_signal_connect (measure->widget, "changed",
|
2017-06-28 02:30:31 +08:00
|
|
|
|
G_CALLBACK (gimp_measure_tool_compass_changed),
|
|
|
|
|
measure);
|
2017-06-28 04:50:50 +08:00
|
|
|
|
g_signal_connect (measure->widget, "response",
|
2017-06-28 02:30:31 +08:00
|
|
|
|
G_CALLBACK (gimp_measure_tool_compass_response),
|
|
|
|
|
measure);
|
2017-06-28 04:50:50 +08:00
|
|
|
|
g_signal_connect (measure->widget, "status",
|
2017-06-28 02:30:31 +08:00
|
|
|
|
G_CALLBACK (gimp_measure_tool_compass_status),
|
|
|
|
|
measure);
|
2017-06-28 04:50:50 +08:00
|
|
|
|
g_signal_connect (measure->widget, "create-guides",
|
2017-06-28 02:30:31 +08:00
|
|
|
|
G_CALLBACK (gimp_measure_tool_compass_create_guides),
|
|
|
|
|
measure);
|
|
|
|
|
|
|
|
|
|
tool->display = display;
|
|
|
|
|
|
|
|
|
|
gimp_draw_tool_start (GIMP_DRAW_TOOL (measure), display);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gimp_measure_tool_halt (GimpMeasureTool *measure)
|
|
|
|
|
{
|
|
|
|
|
GimpTool *tool = GIMP_TOOL (measure);
|
|
|
|
|
|
|
|
|
|
if (tool->display)
|
|
|
|
|
gimp_tool_pop_status (tool, tool->display);
|
|
|
|
|
|
2017-06-28 04:30:17 +08:00
|
|
|
|
if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (measure)))
|
|
|
|
|
gimp_draw_tool_stop (GIMP_DRAW_TOOL (measure));
|
|
|
|
|
|
|
|
|
|
gimp_draw_tool_set_widget (GIMP_DRAW_TOOL (tool), NULL);
|
2017-06-28 04:50:50 +08:00
|
|
|
|
g_clear_object (&measure->widget);
|
2017-06-28 04:30:17 +08:00
|
|
|
|
|
2017-06-28 02:30:31 +08:00
|
|
|
|
g_clear_object (&measure->gui);
|
|
|
|
|
|
|
|
|
|
tool->display = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2017-01-24 03:52:32 +08:00
|
|
|
|
gdouble inch_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];
|
2017-01-24 03:52:32 +08:00
|
|
|
|
gint unit_distance_digits = 0;
|
2017-01-19 22:42:00 +08:00
|
|
|
|
gint unit_width_digits;
|
|
|
|
|
gint unit_height_digits;
|
2003-10-21 01:36:18 +08:00
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
2017-06-12 05:44:55 +08:00
|
|
|
|
if (measure->n_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));
|
2017-01-24 03:52:32 +08:00
|
|
|
|
inch_distance = sqrt (SQR ((gdouble) (ax - bx) / xres) +
|
|
|
|
|
SQR ((gdouble) (ay - by) / yres));
|
|
|
|
|
unit_distance = gimp_unit_get_factor (shell->unit) * inch_distance;
|
2003-10-21 01:36:18 +08:00
|
|
|
|
|
2017-06-12 05:44:55 +08:00
|
|
|
|
if (measure->n_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
|
|
|
|
|
|
|
|
|
unit_angle = fabs (theta1 - theta2);
|
|
|
|
|
if (unit_angle > 180.0)
|
|
|
|
|
unit_angle = fabs (360.0 - unit_angle);
|
|
|
|
|
|
2017-01-19 22:42:00 +08:00
|
|
|
|
/* Compute minimum digits to display accurate values, so that
|
2017-06-12 05:44:55 +08:00
|
|
|
|
* every pixel shows a different value in unit.
|
|
|
|
|
*/
|
2017-01-24 03:52:32 +08:00
|
|
|
|
if (inch_distance)
|
|
|
|
|
unit_distance_digits = gimp_unit_get_scaled_digits (shell->unit,
|
2017-06-12 05:44:55 +08:00
|
|
|
|
pixel_distance /
|
|
|
|
|
inch_distance);
|
|
|
|
|
unit_width_digits = gimp_unit_get_scaled_digits (shell->unit, xres);
|
|
|
|
|
unit_height_digits = gimp_unit_get_scaled_digits (shell->unit, yres);
|
2017-01-19 22:42:00 +08:00
|
|
|
|
|
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,
|
2018-01-28 22:03:53 +08:00
|
|
|
|
"%.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
|
|
|
|
|
{
|
2018-01-28 22:03:53 +08:00
|
|
|
|
g_snprintf (format, sizeof (format),
|
|
|
|
|
"%%.%df %s, %%.2f\302\260 (%%.%df × %%.%df)",
|
|
|
|
|
unit_distance_digits,
|
|
|
|
|
gimp_unit_get_plural (shell->unit),
|
|
|
|
|
unit_width_digits,
|
|
|
|
|
unit_height_digits);
|
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,
|
2018-01-28 22:03:53 +08:00
|
|
|
|
unit_distance, unit_angle,
|
2006-09-28 19:07:55 +08:00
|
|
|
|
unit_width, unit_height);
|
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
|
|
|
|
/* 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)
|
|
|
|
|
{
|
2017-01-19 22:42:00 +08:00
|
|
|
|
g_snprintf (format, sizeof (format), "%%.%df",
|
|
|
|
|
unit_distance_digits);
|
2006-02-15 22:48:40 +08:00
|
|
|
|
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)
|
|
|
|
|
{
|
2017-01-19 22:42:00 +08:00
|
|
|
|
g_snprintf (format, sizeof (format), "%%.%df",
|
|
|
|
|
unit_width_digits);
|
2006-02-15 22:48:40 +08:00
|
|
|
|
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)
|
|
|
|
|
{
|
2017-01-19 22:42:00 +08:00
|
|
|
|
g_snprintf (format, sizeof (format), "%%.%df",
|
|
|
|
|
unit_height_digits);
|
2006-02-15 22:48:40 +08:00
|
|
|
|
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
|
|
|
|
{
|
2014-05-02 09:01:23 +08:00
|
|
|
|
GimpTool *tool = GIMP_TOOL (measure);
|
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
|
GimpToolGui *gui;
|
2018-04-30 00:40:43 +08:00
|
|
|
|
GtkWidget *grid;
|
2014-05-02 09:01:23 +08:00
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
2014-05-03 02:02:53 +08:00
|
|
|
|
g_return_val_if_fail (tool->display != NULL, NULL);
|
2014-05-02 09:01:23 +08:00
|
|
|
|
|
|
|
|
|
shell = gimp_display_get_shell (tool->display);
|
2013-06-07 18:03:39 +08:00
|
|
|
|
|
|
|
|
|
gui = gimp_tool_gui_new (tool->tool_info,
|
2016-01-23 06:41:45 +08:00
|
|
|
|
NULL,
|
2013-06-07 18:03:39 +08:00
|
|
|
|
_("Measure Distances and Angles"),
|
2016-01-23 06:41:45 +08:00
|
|
|
|
NULL, NULL,
|
2014-05-02 09:01:23 +08:00
|
|
|
|
gimp_widget_get_monitor (GTK_WIDGET (shell)),
|
2014-06-09 09:08:43 +08:00
|
|
|
|
TRUE,
|
2003-10-21 01:36:18 +08:00
|
|
|
|
|
2017-02-12 23:06:34 +08:00
|
|
|
|
_("_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
|
|
|
|
|
2014-06-09 09:08:43 +08:00
|
|
|
|
gimp_tool_gui_set_auto_overlay (gui, TRUE);
|
2013-06-08 21:34:23 +08:00
|
|
|
|
gimp_tool_gui_set_focus_on_map (gui, 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
|
|
|
|
|
2018-04-30 00:40:43 +08:00
|
|
|
|
grid = gtk_grid_new ();
|
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
|
|
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (gimp_tool_gui_get_vbox (gui)), grid,
|
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
|
gtk_widget_show (grid);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
label = gtk_label_new (_("Distance:"));
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
2018-04-30 00:40:43 +08:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
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);
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 1.0);
|
2018-04-30 00:40:43 +08:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 1, 0, 1, 1);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
|
|
label = gtk_label_new (_("pixels"));
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
2018-04-30 00:40:43 +08:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 2, 0, 1, 1);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
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);
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 1.0);
|
2018-04-30 00:40:43 +08:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 3, 0, 1, 1);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2007-03-01 00:46:55 +08:00
|
|
|
|
measure->unit_label[0] = label = gtk_label_new (NULL);
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
2018-04-30 00:40:43 +08:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 4, 0, 1, 1);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
label = gtk_label_new (_("Angle:"));
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
2018-04-30 00:40:43 +08:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
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);
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 1.0);
|
2018-04-30 00:40:43 +08:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 1, 1, 1, 1);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
|
|
label = gtk_label_new ("\302\260");
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
2018-04-30 00:40:43 +08:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 2, 1, 1, 1);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
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);
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 1.0);
|
2018-04-30 00:40:43 +08:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 3, 1, 1, 1);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2007-03-01 00:46:55 +08:00
|
|
|
|
measure->unit_label[1] = label = gtk_label_new (NULL);
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
2018-04-30 00:40:43 +08:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 4, 1, 1, 1);
|
2003-10-21 01:36:18 +08:00
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2005-03-21 18:27:36 +08:00
|
|
|
|
|
|
|
|
|
label = gtk_label_new (_("Width:"));
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
2018-04-30 00:40:43 +08:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 1, 1);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
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);
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 1.0);
|
2018-04-30 00:40:43 +08:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 1, 2, 1, 1);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
|
|
label = gtk_label_new (_("pixels"));
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
2018-04-30 00:40:43 +08:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 2, 2, 1, 1);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
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);
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 1.0);
|
2018-04-30 00:40:43 +08:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 3, 2, 1, 1);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2007-03-01 00:46:55 +08:00
|
|
|
|
measure->unit_label[2] = label = gtk_label_new (NULL);
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
2018-04-30 00:40:43 +08:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 4, 2, 1, 1);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
label = gtk_label_new (_("Height:"));
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
2018-04-30 00:40:43 +08:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 3, 1, 1);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
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);
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 1.0);
|
2018-04-30 00:40:43 +08:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 1, 3, 1, 1);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
|
|
label = gtk_label_new (_("pixels"));
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
2018-04-30 00:40:43 +08:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 2, 3, 1, 1);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
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);
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 1.0);
|
2018-04-30 00:40:43 +08:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 3, 3, 1, 1);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2007-03-01 00:46:55 +08:00
|
|
|
|
measure->unit_label[3] = label = gtk_label_new (NULL);
|
2016-09-09 01:11:20 +08:00
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
2018-04-30 00:40:43 +08:00
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 4, 3, 1, 1);
|
2005-03-21 18:27:36 +08:00
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
2013-06-07 18:03:39 +08:00
|
|
|
|
return gui;
|
1999-08-21 19:30:10 +08:00
|
|
|
|
}
|