2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2005-04-03 15:48:03 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpcursorview.c
|
2016-10-18 22:48:04 +02:00
|
|
|
* Copyright (C) 2005-2016 Michael Natterer <mitch@gimp.org>
|
2005-04-03 15:48:03 +00:00
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2005-04-03 15:48:03 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2005-04-03 15:48:03 +00: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
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2005-04-03 15:48:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-10-09 20:24:04 +00:00
|
|
|
#include <gegl.h>
|
2005-04-03 15:48:03 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2005-04-03 17:15:45 +00:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2007-03-09 13:00:01 +00:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2005-04-03 15:48:03 +00:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2008-11-09 17:51:43 +00:00
|
|
|
#include "display-types.h"
|
2005-04-03 15:48:03 +00:00
|
|
|
|
2016-10-18 22:48:04 +02:00
|
|
|
#include "config/gimpcoreconfig.h"
|
|
|
|
|
|
|
|
#include "core/gimp.h"
|
2008-11-10 18:43:26 +00:00
|
|
|
#include "core/gimpcontext.h"
|
2005-04-03 15:48:03 +00:00
|
|
|
#include "core/gimpimage.h"
|
2005-07-09 11:07:36 +00:00
|
|
|
#include "core/gimpimage-pick-color.h"
|
2005-07-08 22:54:46 +00:00
|
|
|
#include "core/gimpitem.h"
|
2005-04-03 15:48:03 +00:00
|
|
|
|
2008-11-09 17:51:43 +00:00
|
|
|
#include "widgets/gimpcolorframe.h"
|
|
|
|
#include "widgets/gimpdocked.h"
|
|
|
|
#include "widgets/gimpmenufactory.h"
|
|
|
|
#include "widgets/gimpsessioninfo-aux.h"
|
|
|
|
|
2005-04-03 15:48:03 +00:00
|
|
|
#include "gimpcursorview.h"
|
2008-11-10 18:43:26 +00:00
|
|
|
#include "gimpdisplay.h"
|
|
|
|
#include "gimpdisplayshell.h"
|
2005-04-03 15:48:03 +00:00
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2005-07-08 22:54:46 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2022-03-03 03:15:44 +00:00
|
|
|
PROP_GIMP,
|
2005-07-08 22:54:46 +00:00
|
|
|
PROP_SAMPLE_MERGED
|
|
|
|
};
|
|
|
|
|
|
|
|
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-18 12:09:39 -04:00
|
|
|
struct _GimpCursorViewPrivate
|
2008-11-09 14:02:38 +00:00
|
|
|
{
|
2008-11-10 18:43:26 +00:00
|
|
|
GimpEditor parent_instance;
|
|
|
|
|
2022-03-03 03:15:44 +00:00
|
|
|
Gimp *gimp;
|
|
|
|
|
2008-11-10 18:43:26 +00:00
|
|
|
GtkWidget *coord_hbox;
|
|
|
|
GtkWidget *selection_hbox;
|
|
|
|
GtkWidget *color_hbox;
|
|
|
|
|
|
|
|
GtkWidget *pixel_x_label;
|
|
|
|
GtkWidget *pixel_y_label;
|
|
|
|
GtkWidget *unit_x_label;
|
|
|
|
GtkWidget *unit_y_label;
|
|
|
|
GtkWidget *selection_x_label;
|
|
|
|
GtkWidget *selection_y_label;
|
|
|
|
GtkWidget *selection_width_label;
|
|
|
|
GtkWidget *selection_height_label;
|
|
|
|
GtkWidget *color_frame_1;
|
|
|
|
GtkWidget *color_frame_2;
|
|
|
|
|
|
|
|
gboolean sample_merged;
|
|
|
|
|
|
|
|
GimpContext *context;
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
GimpImage *image;
|
2005-04-03 15:48:03 +00:00
|
|
|
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
GimpUnit *unit;
|
2017-09-08 11:14:49 -04:00
|
|
|
guint cursor_idle_id;
|
|
|
|
GimpImage *cursor_image;
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
GimpUnit *cursor_unit;
|
2024-11-16 14:08:44 +09:00
|
|
|
gboolean cursor_show_all;
|
2017-09-08 11:14:49 -04:00
|
|
|
gdouble cursor_x;
|
|
|
|
gdouble cursor_y;
|
|
|
|
};
|
2005-12-19 22:37:49 +00:00
|
|
|
|
|
|
|
|
2017-09-08 11:14:49 -04:00
|
|
|
static void gimp_cursor_view_docked_iface_init (GimpDockedInterface *iface);
|
|
|
|
|
|
|
|
static void gimp_cursor_view_dispose (GObject *object);
|
2022-03-03 03:15:44 +00:00
|
|
|
static void gimp_cursor_view_constructed (GObject *object);
|
2017-09-08 11:14:49 -04:00
|
|
|
static void gimp_cursor_view_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_cursor_view_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
2010-12-22 23:34:47 +01:00
|
|
|
static void gimp_cursor_view_style_updated (GtkWidget *widget);
|
2017-09-08 11:14:49 -04:00
|
|
|
|
|
|
|
static void gimp_cursor_view_set_aux_info (GimpDocked *docked,
|
|
|
|
GList *aux_info);
|
|
|
|
static GList * gimp_cursor_view_get_aux_info (GimpDocked *docked);
|
|
|
|
|
|
|
|
static void gimp_cursor_view_set_context (GimpDocked *docked,
|
|
|
|
GimpContext *context);
|
|
|
|
static void gimp_cursor_view_image_changed (GimpCursorView *view,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpContext *context);
|
|
|
|
static void gimp_cursor_view_mask_changed (GimpCursorView *view,
|
|
|
|
GimpImage *image);
|
2024-11-16 11:33:27 +09:00
|
|
|
static void gimp_cursor_view_display_changed (GimpCursorView *view,
|
2017-09-08 11:14:49 -04:00
|
|
|
GimpDisplay *display,
|
|
|
|
GimpContext *context);
|
|
|
|
static void gimp_cursor_view_shell_unit_changed (GimpCursorView *view,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GimpDisplayShell *shell);
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
static void gimp_cursor_view_format_as_unit (GimpUnit *unit,
|
2017-09-08 11:14:49 -04:00
|
|
|
gchar *output_buf,
|
|
|
|
gint output_buf_size,
|
|
|
|
gdouble pixel_value,
|
|
|
|
gdouble image_res);
|
|
|
|
static void gimp_cursor_view_set_label_italic (GtkWidget *label,
|
|
|
|
gboolean italic);
|
|
|
|
static void gimp_cursor_view_update_selection_info (GimpCursorView *view,
|
|
|
|
GimpImage *image,
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
GimpUnit *unit);
|
2017-09-08 11:14:49 -04:00
|
|
|
static gboolean gimp_cursor_view_cursor_idle (GimpCursorView *view);
|
2008-11-09 14:02:38 +00:00
|
|
|
|
2005-12-19 22:37:49 +00:00
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GimpCursorView, gimp_cursor_view, GIMP_TYPE_EDITOR,
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-18 12:09:39 -04:00
|
|
|
G_ADD_PRIVATE (GimpCursorView)
|
2005-12-19 22:37:49 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCKED,
|
2006-05-15 09:46:31 +00:00
|
|
|
gimp_cursor_view_docked_iface_init))
|
2005-12-19 22:37:49 +00:00
|
|
|
|
|
|
|
#define parent_class gimp_cursor_view_parent_class
|
|
|
|
|
|
|
|
static GimpDockedInterface *parent_docked_iface = NULL;
|
2005-04-03 15:48:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_cursor_view_class_init (GimpCursorViewClass* klass)
|
|
|
|
{
|
2005-07-08 22:54:46 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2005-04-03 15:48:03 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2022-03-03 03:15:44 +00:00
|
|
|
object_class->constructed = gimp_cursor_view_constructed;
|
2010-12-22 23:34:47 +01:00
|
|
|
object_class->dispose = gimp_cursor_view_dispose;
|
|
|
|
object_class->get_property = gimp_cursor_view_get_property;
|
|
|
|
object_class->set_property = gimp_cursor_view_set_property;
|
2005-07-08 22:54:46 +00:00
|
|
|
|
2010-12-22 23:34:47 +01:00
|
|
|
widget_class->style_updated = gimp_cursor_view_style_updated;
|
2005-07-08 22:54:46 +00:00
|
|
|
|
2022-03-03 03:15:44 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_GIMP,
|
|
|
|
g_param_spec_object ("gimp",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_TYPE_GIMP,
|
|
|
|
GIMP_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
2005-07-08 22:54:46 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_SAMPLE_MERGED,
|
|
|
|
g_param_spec_boolean ("sample-merged",
|
|
|
|
NULL, NULL,
|
|
|
|
TRUE,
|
2006-01-18 20:29:40 +00:00
|
|
|
GIMP_PARAM_READWRITE |
|
2005-07-08 22:54:46 +00:00
|
|
|
G_PARAM_CONSTRUCT));
|
2005-04-03 15:48:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_cursor_view_init (GimpCursorView *view)
|
|
|
|
{
|
2005-07-08 22:54:46 +00:00
|
|
|
GtkWidget *frame;
|
2018-05-02 16:34:42 +02:00
|
|
|
GtkWidget *grid;
|
2005-07-08 22:54:46 +00:00
|
|
|
GtkWidget *toggle;
|
|
|
|
gint content_spacing;
|
|
|
|
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-18 12:09:39 -04:00
|
|
|
view->priv = gimp_cursor_view_get_instance_private (view);
|
2008-11-13 20:12:49 +00:00
|
|
|
|
2017-09-08 11:14:49 -04:00
|
|
|
view->priv->sample_merged = TRUE;
|
|
|
|
view->priv->context = NULL;
|
|
|
|
view->priv->shell = NULL;
|
|
|
|
view->priv->image = NULL;
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
view->priv->unit = gimp_unit_pixel ();
|
2017-09-08 11:14:49 -04:00
|
|
|
view->priv->cursor_idle_id = 0;
|
2005-04-03 15:48:03 +00:00
|
|
|
|
|
|
|
gtk_widget_style_get (GTK_WIDGET (view),
|
2005-08-03 09:34:55 +00:00
|
|
|
"content-spacing", &content_spacing,
|
2006-04-12 12:49:29 +00:00
|
|
|
NULL);
|
2005-04-03 15:48:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* cursor information */
|
|
|
|
|
2011-09-30 11:29:11 +02:00
|
|
|
view->priv->coord_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
|
|
|
|
content_spacing);
|
|
|
|
gtk_box_set_homogeneous (GTK_BOX (view->priv->coord_hbox), TRUE);
|
|
|
|
gtk_box_pack_start (GTK_BOX (view), view->priv->coord_hbox,
|
|
|
|
FALSE, FALSE, 0);
|
2008-11-13 20:12:49 +00:00
|
|
|
gtk_widget_show (view->priv->coord_hbox);
|
2005-04-03 15:48:03 +00:00
|
|
|
|
2011-09-30 11:29:11 +02:00
|
|
|
view->priv->selection_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
|
|
|
|
content_spacing);
|
|
|
|
gtk_box_set_homogeneous (GTK_BOX (view->priv->selection_hbox), TRUE);
|
|
|
|
gtk_box_pack_start (GTK_BOX (view), view->priv->selection_hbox,
|
|
|
|
FALSE, FALSE, 0);
|
2008-11-13 20:12:49 +00:00
|
|
|
gtk_widget_show (view->priv->selection_hbox);
|
2008-11-10 18:43:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Pixels */
|
|
|
|
|
2005-04-03 15:48:03 +00:00
|
|
|
frame = gimp_frame_new (_("Pixels"));
|
2008-11-13 20:12:49 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (view->priv->coord_hbox), frame, TRUE, TRUE, 0);
|
2005-04-03 15:48:03 +00:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2018-05-02 16:34:42 +02:00
|
|
|
grid = gtk_grid_new ();
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
|
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (grid), 2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), grid);
|
|
|
|
gtk_widget_show (grid);
|
2005-04-03 15:48:03 +00:00
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
view->priv->pixel_x_label = gtk_label_new (_("n/a"));
|
2016-09-08 19:11:20 +02:00
|
|
|
gtk_label_set_xalign (GTK_LABEL (view->priv->pixel_x_label), 1.0);
|
2018-05-02 16:34:42 +02:00
|
|
|
gimp_grid_attach_aligned (GTK_GRID (grid), 0, 0,
|
|
|
|
_("X"), 0.5, 0.5,
|
|
|
|
view->priv->pixel_x_label, 1);
|
2005-04-03 15:48:03 +00:00
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
view->priv->pixel_y_label = gtk_label_new (_("n/a"));
|
2016-09-08 19:11:20 +02:00
|
|
|
gtk_label_set_xalign (GTK_LABEL (view->priv->pixel_y_label), 1.0);
|
2018-05-02 16:34:42 +02:00
|
|
|
gimp_grid_attach_aligned (GTK_GRID (grid), 0, 1,
|
|
|
|
_("Y"), 0.5, 0.5,
|
|
|
|
view->priv->pixel_y_label, 1);
|
2005-04-03 15:48:03 +00:00
|
|
|
|
2008-11-10 18:43:26 +00:00
|
|
|
|
|
|
|
/* Units */
|
|
|
|
|
2005-04-03 15:48:03 +00:00
|
|
|
frame = gimp_frame_new (_("Units"));
|
2008-11-13 20:12:49 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (view->priv->coord_hbox), frame, TRUE, TRUE, 0);
|
2005-04-03 15:48:03 +00:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2018-05-02 16:34:42 +02:00
|
|
|
grid = gtk_grid_new ();
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (grid), 4);
|
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (grid), 2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), grid);
|
|
|
|
gtk_widget_show (grid);
|
2005-04-03 15:48:03 +00:00
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
view->priv->unit_x_label = gtk_label_new (_("n/a"));
|
2016-09-08 19:11:20 +02:00
|
|
|
gtk_label_set_xalign (GTK_LABEL (view->priv->unit_x_label), 1.0);
|
2018-05-02 16:34:42 +02:00
|
|
|
gimp_grid_attach_aligned (GTK_GRID (grid), 0, 0,
|
|
|
|
_("X"), 0.5, 0.5,
|
|
|
|
view->priv->unit_x_label, 1);
|
2005-04-03 15:48:03 +00:00
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
view->priv->unit_y_label = gtk_label_new (_("n/a"));
|
2016-09-08 19:11:20 +02:00
|
|
|
gtk_label_set_xalign (GTK_LABEL (view->priv->unit_y_label), 1.0);
|
2018-05-02 16:34:42 +02:00
|
|
|
gimp_grid_attach_aligned (GTK_GRID (grid), 0, 1,
|
|
|
|
_("Y"), 0.5, 0.5,
|
|
|
|
view->priv->unit_y_label, 1);
|
2005-04-03 15:48:03 +00:00
|
|
|
|
|
|
|
|
2008-11-10 18:43:26 +00:00
|
|
|
/* Selection Bounding Box */
|
|
|
|
|
2018-06-14 12:32:40 +02:00
|
|
|
frame = gimp_frame_new (_("Selection"));
|
2008-11-13 20:12:49 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (view->priv->selection_hbox), frame, TRUE, TRUE, 0);
|
2008-11-10 18:43:26 +00:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2018-06-14 12:32:40 +02:00
|
|
|
gimp_help_set_help_data (frame, _("The selection's bounding box"), NULL);
|
|
|
|
|
2018-05-02 16:34:42 +02:00
|
|
|
grid = gtk_grid_new ();
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
|
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (grid), 2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), grid);
|
|
|
|
gtk_widget_show (grid);
|
2008-11-10 18:43:26 +00:00
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
view->priv->selection_x_label = gtk_label_new (_("n/a"));
|
2016-09-08 19:11:20 +02:00
|
|
|
gtk_label_set_xalign (GTK_LABEL (view->priv->selection_x_label), 1.0);
|
2018-05-02 16:34:42 +02:00
|
|
|
gimp_grid_attach_aligned (GTK_GRID (grid), 0, 0,
|
|
|
|
_("X"), 0.5, 0.5,
|
|
|
|
view->priv->selection_x_label, 1);
|
2008-11-10 18:43:26 +00:00
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
view->priv->selection_y_label = gtk_label_new (_("n/a"));
|
2016-09-08 19:11:20 +02:00
|
|
|
gtk_label_set_xalign (GTK_LABEL (view->priv->selection_y_label), 1.0);
|
2018-05-02 16:34:42 +02:00
|
|
|
gimp_grid_attach_aligned (GTK_GRID (grid), 0, 1,
|
|
|
|
_("Y"), 0.5, 0.5,
|
|
|
|
view->priv->selection_y_label, 1);
|
2008-11-10 18:43:26 +00:00
|
|
|
|
|
|
|
frame = gimp_frame_new ("");
|
2008-11-13 20:12:49 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (view->priv->selection_hbox), frame, TRUE, TRUE, 0);
|
2008-11-10 18:43:26 +00:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2018-05-02 16:34:42 +02:00
|
|
|
grid = gtk_grid_new ();
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (grid), 4);
|
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (grid), 2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), grid);
|
|
|
|
gtk_widget_show (grid);
|
2008-11-10 18:43:26 +00:00
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
view->priv->selection_width_label = gtk_label_new (_("n/a"));
|
2016-09-08 19:11:20 +02:00
|
|
|
gtk_label_set_xalign (GTK_LABEL (view->priv->selection_width_label), 1.0);
|
2018-05-02 16:34:42 +02:00
|
|
|
gimp_grid_attach_aligned (GTK_GRID (grid), 0, 0,
|
|
|
|
/* Width */
|
|
|
|
_("W"), 0.5, 0.5,
|
|
|
|
view->priv->selection_width_label, 1);
|
2008-11-10 18:43:26 +00:00
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
view->priv->selection_height_label = gtk_label_new (_("n/a"));
|
2016-09-08 19:11:20 +02:00
|
|
|
gtk_label_set_xalign (GTK_LABEL (view->priv->selection_height_label), 1.0);
|
2018-05-02 16:34:42 +02:00
|
|
|
gimp_grid_attach_aligned (GTK_GRID (grid), 0, 1,
|
|
|
|
/* Height */
|
|
|
|
_("H"), 0.5, 0.5,
|
|
|
|
view->priv->selection_height_label, 1);
|
2008-11-10 18:43:26 +00:00
|
|
|
|
2022-03-03 03:15:44 +00:00
|
|
|
/* sample merged toggle */
|
2008-11-10 18:43:26 +00:00
|
|
|
|
2022-03-03 03:15:44 +00:00
|
|
|
toggle = gimp_prop_check_button_new (G_OBJECT (view), "sample-merged",
|
|
|
|
_("_Sample Merged"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (view), toggle, FALSE, FALSE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_cursor_view_docked_iface_init (GimpDockedInterface *iface)
|
|
|
|
{
|
|
|
|
parent_docked_iface = g_type_interface_peek_parent (iface);
|
|
|
|
|
|
|
|
if (! parent_docked_iface)
|
|
|
|
parent_docked_iface = g_type_default_interface_peek (GIMP_TYPE_DOCKED);
|
|
|
|
|
|
|
|
iface->set_aux_info = gimp_cursor_view_set_aux_info;
|
|
|
|
iface->get_aux_info = gimp_cursor_view_get_aux_info;
|
|
|
|
iface->set_context = gimp_cursor_view_set_context;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_cursor_view_constructed (GObject *object)
|
|
|
|
{
|
|
|
|
GimpCursorView *view = GIMP_CURSOR_VIEW (object);
|
|
|
|
gint content_spacing;
|
|
|
|
|
|
|
|
gtk_widget_style_get (GTK_WIDGET (view),
|
|
|
|
"content-spacing", &content_spacing,
|
|
|
|
NULL);
|
2005-04-03 15:48:03 +00:00
|
|
|
|
2022-03-03 03:15:44 +00:00
|
|
|
/* color information */
|
2011-09-30 11:29:11 +02:00
|
|
|
view->priv->color_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
|
|
|
|
content_spacing);
|
|
|
|
gtk_box_set_homogeneous (GTK_BOX (view->priv->color_hbox), TRUE);
|
2008-11-13 20:12:49 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (view), view->priv->color_hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (view->priv->color_hbox);
|
2005-04-03 15:48:03 +00:00
|
|
|
|
2022-03-03 03:15:44 +00:00
|
|
|
view->priv->color_frame_1 = gimp_color_frame_new (view->priv->gimp);
|
2008-11-13 20:12:49 +00:00
|
|
|
gimp_color_frame_set_mode (GIMP_COLOR_FRAME (view->priv->color_frame_1),
|
2018-07-15 23:24:50 +02:00
|
|
|
GIMP_COLOR_PICK_MODE_PIXEL);
|
2018-04-03 01:45:27 +02:00
|
|
|
gimp_color_frame_set_ellipsize (GIMP_COLOR_FRAME (view->priv->color_frame_1),
|
|
|
|
PANGO_ELLIPSIZE_END);
|
2008-11-13 20:12:49 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (view->priv->color_hbox), view->priv->color_frame_1,
|
2005-04-03 17:15:45 +00:00
|
|
|
TRUE, TRUE, 0);
|
2008-11-13 20:12:49 +00:00
|
|
|
gtk_widget_show (view->priv->color_frame_1);
|
2005-04-03 15:48:03 +00:00
|
|
|
|
2022-03-03 03:15:44 +00:00
|
|
|
view->priv->color_frame_2 = gimp_color_frame_new (view->priv->gimp);
|
2008-11-13 20:12:49 +00:00
|
|
|
gimp_color_frame_set_mode (GIMP_COLOR_FRAME (view->priv->color_frame_2),
|
2018-07-15 23:24:50 +02:00
|
|
|
GIMP_COLOR_PICK_MODE_RGB_PERCENT);
|
2008-11-13 20:12:49 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (view->priv->color_hbox), view->priv->color_frame_2,
|
2005-04-03 17:15:45 +00:00
|
|
|
TRUE, TRUE, 0);
|
2008-11-13 20:12:49 +00:00
|
|
|
gtk_widget_show (view->priv->color_frame_2);
|
2005-07-08 22:54:46 +00:00
|
|
|
|
2005-04-03 15:48:03 +00:00
|
|
|
}
|
|
|
|
|
2015-11-07 21:14:40 +01:00
|
|
|
static void
|
|
|
|
gimp_cursor_view_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GimpCursorView *view = GIMP_CURSOR_VIEW (object);
|
|
|
|
|
|
|
|
if (view->priv->context)
|
|
|
|
gimp_docked_set_context (GIMP_DOCKED (view), NULL);
|
|
|
|
|
2017-09-08 11:14:49 -04:00
|
|
|
if (view->priv->cursor_idle_id)
|
|
|
|
{
|
|
|
|
g_source_remove (view->priv->cursor_idle_id);
|
|
|
|
view->priv->cursor_idle_id = 0;
|
|
|
|
}
|
|
|
|
|
2022-03-03 03:15:44 +00:00
|
|
|
view->priv->color_frame_1 = NULL;
|
|
|
|
view->priv->color_frame_2 = NULL;
|
|
|
|
|
2017-09-08 11:14:49 -04:00
|
|
|
g_clear_object (&view->priv->cursor_image);
|
|
|
|
|
2015-11-07 21:14:40 +01:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2005-07-08 22:54:46 +00:00
|
|
|
static void
|
|
|
|
gimp_cursor_view_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpCursorView *view = GIMP_CURSOR_VIEW (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2022-03-03 03:15:44 +00:00
|
|
|
case PROP_GIMP:
|
|
|
|
view->priv->gimp = g_value_get_object (value);
|
|
|
|
break;
|
|
|
|
|
2005-07-08 22:54:46 +00:00
|
|
|
case PROP_SAMPLE_MERGED:
|
2008-11-13 20:12:49 +00:00
|
|
|
view->priv->sample_merged = g_value_get_boolean (value);
|
2005-07-08 22:54:46 +00:00
|
|
|
break;
|
2016-10-18 22:48:04 +02:00
|
|
|
|
|
|
|
default:
|
2005-07-08 22:54:46 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_cursor_view_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpCursorView *view = GIMP_CURSOR_VIEW (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
2022-03-03 03:15:44 +00:00
|
|
|
case PROP_GIMP:
|
|
|
|
g_value_set_object (value, view->priv->gimp);
|
|
|
|
break;
|
|
|
|
|
2005-07-08 22:54:46 +00:00
|
|
|
case PROP_SAMPLE_MERGED:
|
2008-11-13 20:12:49 +00:00
|
|
|
g_value_set_boolean (value, view->priv->sample_merged);
|
2005-07-08 22:54:46 +00:00
|
|
|
break;
|
2016-10-18 22:48:04 +02:00
|
|
|
|
|
|
|
default:
|
2005-07-08 22:54:46 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-03 17:15:45 +00:00
|
|
|
#define AUX_INFO_FRAME_1_MODE "frame-1-mode"
|
|
|
|
#define AUX_INFO_FRAME_2_MODE "frame-2-mode"
|
2005-04-03 15:48:03 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_cursor_view_set_aux_info (GimpDocked *docked,
|
|
|
|
GList *aux_info)
|
|
|
|
{
|
|
|
|
GimpCursorView *view = GIMP_CURSOR_VIEW (docked);
|
|
|
|
GList *list;
|
|
|
|
|
2005-06-04 22:49:53 +00:00
|
|
|
parent_docked_iface->set_aux_info (docked, aux_info);
|
|
|
|
|
2005-04-03 15:48:03 +00:00
|
|
|
for (list = aux_info; list; list = g_list_next (list))
|
|
|
|
{
|
2005-04-03 17:15:45 +00:00
|
|
|
GimpSessionInfoAux *aux = list->data;
|
|
|
|
GtkWidget *frame = NULL;
|
2005-04-03 15:48:03 +00:00
|
|
|
|
2005-04-03 17:15:45 +00:00
|
|
|
if (! strcmp (aux->name, AUX_INFO_FRAME_1_MODE))
|
2008-11-13 20:12:49 +00:00
|
|
|
frame = view->priv->color_frame_1;
|
2005-04-03 17:15:45 +00:00
|
|
|
else if (! strcmp (aux->name, AUX_INFO_FRAME_2_MODE))
|
2008-11-13 20:12:49 +00:00
|
|
|
frame = view->priv->color_frame_2;
|
2005-04-03 17:15:45 +00:00
|
|
|
|
|
|
|
if (frame)
|
2005-04-03 15:48:03 +00:00
|
|
|
{
|
2005-04-03 17:15:45 +00:00
|
|
|
GEnumClass *enum_class;
|
|
|
|
GEnumValue *enum_value;
|
|
|
|
|
2018-07-15 23:24:50 +02:00
|
|
|
enum_class = g_type_class_peek (GIMP_TYPE_COLOR_PICK_MODE);
|
2005-04-03 17:15:45 +00:00
|
|
|
enum_value = g_enum_get_value_by_nick (enum_class, aux->value);
|
|
|
|
|
|
|
|
if (enum_value)
|
|
|
|
gimp_color_frame_set_mode (GIMP_COLOR_FRAME (frame),
|
|
|
|
enum_value->value);
|
2005-04-03 15:48:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GList *
|
|
|
|
gimp_cursor_view_get_aux_info (GimpDocked *docked)
|
|
|
|
{
|
2005-06-04 22:49:53 +00:00
|
|
|
GimpCursorView *view = GIMP_CURSOR_VIEW (docked);
|
|
|
|
GList *aux_info;
|
2005-04-03 17:15:45 +00:00
|
|
|
const gchar *nick;
|
|
|
|
GimpSessionInfoAux *aux;
|
|
|
|
|
2005-06-04 22:49:53 +00:00
|
|
|
aux_info = parent_docked_iface->get_aux_info (docked);
|
|
|
|
|
2018-07-15 23:24:50 +02:00
|
|
|
if (gimp_enum_get_value (GIMP_TYPE_COLOR_PICK_MODE,
|
|
|
|
GIMP_COLOR_FRAME (view->priv->color_frame_1)->pick_mode,
|
2005-04-03 17:15:45 +00:00
|
|
|
NULL, &nick, NULL, NULL))
|
2005-04-03 15:48:03 +00:00
|
|
|
{
|
2005-04-03 17:15:45 +00:00
|
|
|
aux = gimp_session_info_aux_new (AUX_INFO_FRAME_1_MODE, nick);
|
2005-04-03 15:48:03 +00:00
|
|
|
aux_info = g_list_append (aux_info, aux);
|
|
|
|
}
|
|
|
|
|
2018-07-15 23:24:50 +02:00
|
|
|
if (gimp_enum_get_value (GIMP_TYPE_COLOR_PICK_MODE,
|
|
|
|
GIMP_COLOR_FRAME (view->priv->color_frame_2)->pick_mode,
|
2005-04-03 17:15:45 +00:00
|
|
|
NULL, &nick, NULL, NULL))
|
2005-04-03 15:48:03 +00:00
|
|
|
{
|
2005-04-03 17:15:45 +00:00
|
|
|
aux = gimp_session_info_aux_new (AUX_INFO_FRAME_2_MODE, nick);
|
|
|
|
aux_info = g_list_append (aux_info, aux);
|
2005-04-03 15:48:03 +00:00
|
|
|
}
|
|
|
|
|
2005-04-03 17:15:45 +00:00
|
|
|
return aux_info;
|
2005-04-03 15:48:03 +00:00
|
|
|
}
|
|
|
|
|
2008-11-09 14:02:38 +00:00
|
|
|
static void
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
gimp_cursor_view_format_as_unit (GimpUnit *unit,
|
2008-11-09 14:02:38 +00:00
|
|
|
gchar *output_buf,
|
|
|
|
gint output_buf_size,
|
|
|
|
gdouble pixel_value,
|
|
|
|
gdouble image_res)
|
|
|
|
{
|
|
|
|
gchar format_buf[32];
|
2008-11-10 18:43:26 +00:00
|
|
|
gdouble value;
|
|
|
|
gint unit_digits = 0;
|
|
|
|
const gchar *unit_str = "";
|
2008-11-09 14:02:38 +00:00
|
|
|
|
2010-02-21 16:46:39 +01:00
|
|
|
value = gimp_pixels_to_units (pixel_value, unit, image_res);
|
2008-11-10 18:43:26 +00:00
|
|
|
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
if (unit != gimp_unit_pixel ())
|
2008-11-10 18:43:26 +00:00
|
|
|
{
|
2017-05-06 22:57:43 +02:00
|
|
|
unit_digits = gimp_unit_get_scaled_digits (unit, image_res);
|
2010-02-21 16:46:39 +01:00
|
|
|
unit_str = gimp_unit_get_abbreviation (unit);
|
2008-11-10 18:43:26 +00:00
|
|
|
}
|
2008-11-09 14:02:38 +00:00
|
|
|
|
2010-02-21 16:46:39 +01:00
|
|
|
g_snprintf (format_buf, sizeof (format_buf),
|
|
|
|
"%%.%df %s", unit_digits, unit_str);
|
2008-11-09 14:02:38 +00:00
|
|
|
|
2008-11-10 18:43:26 +00:00
|
|
|
g_snprintf (output_buf, output_buf_size, format_buf, value);
|
2008-11-09 14:02:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_cursor_view_set_label_italic (GtkWidget *label,
|
|
|
|
gboolean italic)
|
|
|
|
{
|
2016-02-12 22:48:59 +01:00
|
|
|
PangoStyle attribute = italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL;
|
2008-11-09 14:02:38 +00:00
|
|
|
|
|
|
|
gimp_label_set_attributes (GTK_LABEL (label),
|
|
|
|
PANGO_ATTR_STYLE, attribute,
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
|
2005-04-03 15:48:03 +00:00
|
|
|
static void
|
2010-12-22 23:34:47 +01:00
|
|
|
gimp_cursor_view_style_updated (GtkWidget *widget)
|
2005-04-03 15:48:03 +00:00
|
|
|
{
|
|
|
|
GimpCursorView *view = GIMP_CURSOR_VIEW (widget);
|
2005-04-03 17:15:45 +00:00
|
|
|
gint content_spacing;
|
2005-04-03 15:48:03 +00:00
|
|
|
|
2010-12-22 23:34:47 +01:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->style_updated (widget);
|
2005-04-03 17:15:45 +00:00
|
|
|
|
|
|
|
gtk_widget_style_get (GTK_WIDGET (view),
|
2005-08-03 09:34:55 +00:00
|
|
|
"content-spacing", &content_spacing,
|
2006-04-12 12:49:29 +00:00
|
|
|
NULL);
|
2005-04-03 17:15:45 +00:00
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
gtk_box_set_spacing (GTK_BOX (view->priv->coord_hbox), content_spacing);
|
|
|
|
gtk_box_set_spacing (GTK_BOX (view->priv->selection_hbox), content_spacing);
|
|
|
|
gtk_box_set_spacing (GTK_BOX (view->priv->color_hbox), content_spacing);
|
2008-11-10 18:43:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_cursor_view_set_context (GimpDocked *docked,
|
|
|
|
GimpContext *context)
|
|
|
|
{
|
2016-10-18 22:48:04 +02:00
|
|
|
GimpCursorView *view = GIMP_CURSOR_VIEW (docked);
|
|
|
|
GimpColorConfig *config = NULL;
|
|
|
|
GimpDisplay *display = NULL;
|
|
|
|
GimpImage *image = NULL;
|
2008-11-10 18:43:26 +00:00
|
|
|
|
2015-11-07 21:14:40 +01:00
|
|
|
if (context == view->priv->context)
|
|
|
|
return;
|
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
if (view->priv->context)
|
2008-11-10 18:43:26 +00:00
|
|
|
{
|
2008-11-13 20:12:49 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (view->priv->context,
|
2024-11-16 11:33:27 +09:00
|
|
|
gimp_cursor_view_display_changed,
|
2008-11-10 18:43:26 +00:00
|
|
|
view);
|
2008-11-13 20:12:49 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (view->priv->context,
|
2008-11-10 18:43:26 +00:00
|
|
|
gimp_cursor_view_image_changed,
|
|
|
|
view);
|
2015-11-07 21:14:40 +01:00
|
|
|
|
|
|
|
g_object_unref (view->priv->context);
|
2008-11-10 18:43:26 +00:00
|
|
|
}
|
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
view->priv->context = context;
|
2008-11-10 18:43:26 +00:00
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
if (view->priv->context)
|
2008-11-10 18:43:26 +00:00
|
|
|
{
|
2015-11-07 21:14:40 +01:00
|
|
|
g_object_ref (view->priv->context);
|
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
g_signal_connect_swapped (view->priv->context, "display-changed",
|
2024-11-16 11:33:27 +09:00
|
|
|
G_CALLBACK (gimp_cursor_view_display_changed),
|
2008-11-10 18:43:26 +00:00
|
|
|
view);
|
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
g_signal_connect_swapped (view->priv->context, "image-changed",
|
2008-11-10 18:43:26 +00:00
|
|
|
G_CALLBACK (gimp_cursor_view_image_changed),
|
|
|
|
view);
|
|
|
|
|
2016-10-18 22:48:04 +02:00
|
|
|
config = context->gimp->config->color_management;
|
2008-11-10 18:43:26 +00:00
|
|
|
display = gimp_context_get_display (context);
|
|
|
|
image = gimp_context_get_image (context);
|
|
|
|
}
|
|
|
|
|
2016-10-18 22:48:04 +02:00
|
|
|
gimp_color_frame_set_color_config (GIMP_COLOR_FRAME (view->priv->color_frame_1),
|
|
|
|
config);
|
|
|
|
gimp_color_frame_set_color_config (GIMP_COLOR_FRAME (view->priv->color_frame_2),
|
|
|
|
config);
|
|
|
|
|
2024-11-16 11:33:27 +09:00
|
|
|
gimp_cursor_view_display_changed (view, display, view->priv->context);
|
2015-11-07 21:14:40 +01:00
|
|
|
gimp_cursor_view_image_changed (view, image, view->priv->context);
|
2008-11-10 18:43:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_cursor_view_image_changed (GimpCursorView *view,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpContext *context)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CURSOR_VIEW (view));
|
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
if (image == view->priv->image)
|
2008-11-10 18:43:26 +00:00
|
|
|
return;
|
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
if (view->priv->image)
|
2008-11-10 18:43:26 +00:00
|
|
|
{
|
2008-11-13 20:12:49 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (view->priv->image,
|
2008-11-10 18:43:26 +00:00
|
|
|
gimp_cursor_view_mask_changed,
|
|
|
|
view);
|
|
|
|
}
|
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
view->priv->image = image;
|
2008-11-10 18:43:26 +00:00
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
if (view->priv->image)
|
2008-11-10 18:43:26 +00:00
|
|
|
{
|
2008-11-13 20:12:49 +00:00
|
|
|
g_signal_connect_swapped (view->priv->image, "mask-changed",
|
2008-11-10 18:43:26 +00:00
|
|
|
G_CALLBACK (gimp_cursor_view_mask_changed),
|
|
|
|
view);
|
|
|
|
}
|
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
gimp_cursor_view_mask_changed (view, view->priv->image);
|
2008-11-10 18:43:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_cursor_view_mask_changed (GimpCursorView *view,
|
|
|
|
GimpImage *image)
|
|
|
|
{
|
2010-02-21 16:46:39 +01:00
|
|
|
gimp_cursor_view_update_selection_info (view,
|
|
|
|
view->priv->image,
|
|
|
|
view->priv->unit);
|
2008-11-10 18:43:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2024-11-16 11:33:27 +09:00
|
|
|
gimp_cursor_view_display_changed (GimpCursorView *view,
|
|
|
|
GimpDisplay *display,
|
|
|
|
GimpContext *context)
|
2008-11-10 18:43:26 +00:00
|
|
|
{
|
|
|
|
GimpDisplayShell *shell = NULL;
|
|
|
|
|
|
|
|
if (display)
|
2009-10-04 19:56:39 +02:00
|
|
|
shell = gimp_display_get_shell (display);
|
2008-11-10 18:43:26 +00:00
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
if (view->priv->shell)
|
2008-11-10 18:43:26 +00:00
|
|
|
{
|
2008-11-13 20:12:49 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (view->priv->shell,
|
2008-11-10 18:43:26 +00:00
|
|
|
gimp_cursor_view_shell_unit_changed,
|
|
|
|
view);
|
|
|
|
}
|
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
view->priv->shell = shell;
|
2008-11-10 18:43:26 +00:00
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
if (view->priv->shell)
|
2008-11-10 18:43:26 +00:00
|
|
|
{
|
2008-11-13 20:12:49 +00:00
|
|
|
g_signal_connect_swapped (view->priv->shell, "notify::unit",
|
2008-11-10 18:43:26 +00:00
|
|
|
G_CALLBACK (gimp_cursor_view_shell_unit_changed),
|
|
|
|
view);
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_cursor_view_shell_unit_changed (view,
|
|
|
|
NULL,
|
2008-11-13 20:12:49 +00:00
|
|
|
view->priv->shell);
|
2008-11-10 18:43:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_cursor_view_shell_unit_changed (GimpCursorView *view,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GimpDisplayShell *shell)
|
|
|
|
{
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
GimpUnit *new_unit = gimp_unit_pixel ();
|
2008-11-10 18:43:26 +00:00
|
|
|
|
|
|
|
if (shell)
|
|
|
|
{
|
|
|
|
new_unit = gimp_display_shell_get_unit (shell);
|
|
|
|
}
|
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
if (view->priv->unit != new_unit)
|
2008-11-10 18:43:26 +00:00
|
|
|
{
|
2008-11-13 20:12:49 +00:00
|
|
|
gimp_cursor_view_update_selection_info (view, view->priv->image, new_unit);
|
|
|
|
view->priv->unit = new_unit;
|
2008-11-10 18:43:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-02 02:43:40 +02:00
|
|
|
static void
|
|
|
|
gimp_cursor_view_update_selection_info (GimpCursorView *view,
|
|
|
|
GimpImage *image,
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
GimpUnit *unit)
|
2008-11-10 18:43:26 +00:00
|
|
|
{
|
2015-07-02 02:43:40 +02:00
|
|
|
gint x, y, width, height;
|
2008-11-10 18:43:26 +00:00
|
|
|
|
2015-07-02 02:43:40 +02:00
|
|
|
if (image &&
|
|
|
|
gimp_item_bounds (GIMP_ITEM (gimp_image_get_mask (image)),
|
|
|
|
&x, &y, &width, &height))
|
2008-11-10 18:43:26 +00:00
|
|
|
{
|
2010-02-21 16:46:39 +01:00
|
|
|
gdouble xres, yres;
|
|
|
|
gchar buf[32];
|
2008-11-10 18:43:26 +00:00
|
|
|
|
|
|
|
gimp_image_get_resolution (image, &xres, &yres);
|
|
|
|
|
2015-07-02 02:43:40 +02:00
|
|
|
gimp_cursor_view_format_as_unit (unit, buf, sizeof (buf), x, xres);
|
2008-11-13 20:12:49 +00:00
|
|
|
gtk_label_set_text (GTK_LABEL (view->priv->selection_x_label), buf);
|
2008-11-10 18:43:26 +00:00
|
|
|
|
2015-07-02 02:43:40 +02:00
|
|
|
gimp_cursor_view_format_as_unit (unit, buf, sizeof (buf), y, yres);
|
2008-11-13 20:12:49 +00:00
|
|
|
gtk_label_set_text (GTK_LABEL (view->priv->selection_y_label), buf);
|
2008-11-10 18:43:26 +00:00
|
|
|
|
2010-02-21 16:46:39 +01:00
|
|
|
gimp_cursor_view_format_as_unit (unit, buf, sizeof (buf), width, xres);
|
2008-11-13 20:12:49 +00:00
|
|
|
gtk_label_set_text (GTK_LABEL (view->priv->selection_width_label), buf);
|
2008-11-10 18:43:26 +00:00
|
|
|
|
2010-02-21 16:46:39 +01:00
|
|
|
gimp_cursor_view_format_as_unit (unit, buf, sizeof (buf), height, yres);
|
2008-11-13 20:12:49 +00:00
|
|
|
gtk_label_set_text (GTK_LABEL (view->priv->selection_height_label), buf);
|
2008-11-10 18:43:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-02 02:43:40 +02:00
|
|
|
gtk_label_set_text (GTK_LABEL (view->priv->selection_x_label),
|
|
|
|
_("n/a"));
|
|
|
|
gtk_label_set_text (GTK_LABEL (view->priv->selection_y_label),
|
|
|
|
_("n/a"));
|
|
|
|
gtk_label_set_text (GTK_LABEL (view->priv->selection_width_label),
|
|
|
|
_("n/a"));
|
|
|
|
gtk_label_set_text (GTK_LABEL (view->priv->selection_height_label),
|
|
|
|
_("n/a"));
|
2008-11-10 18:43:26 +00:00
|
|
|
}
|
2005-04-03 15:48:03 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 11:14:49 -04:00
|
|
|
static gboolean
|
|
|
|
gimp_cursor_view_cursor_idle (GimpCursorView *view)
|
|
|
|
{
|
|
|
|
if (view->priv->cursor_image)
|
|
|
|
{
|
2024-11-16 14:08:44 +09:00
|
|
|
GimpImage *image = view->priv->cursor_image;
|
|
|
|
GimpUnit *unit = view->priv->cursor_unit;
|
|
|
|
gboolean show_all = view->priv->cursor_show_all;
|
|
|
|
gdouble x = view->priv->cursor_x;
|
|
|
|
gdouble y = view->priv->cursor_y;
|
2017-09-08 11:14:49 -04:00
|
|
|
gboolean in_image;
|
|
|
|
gchar buf[32];
|
|
|
|
const Babl *sample_format;
|
2020-05-20 08:49:42 +03:00
|
|
|
gdouble pixel[4];
|
2023-11-12 17:56:32 +01:00
|
|
|
GeglColor *color;
|
2017-09-08 11:14:49 -04:00
|
|
|
gdouble xres;
|
|
|
|
gdouble yres;
|
|
|
|
gint int_x;
|
|
|
|
gint int_y;
|
|
|
|
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
if (unit == gimp_unit_pixel ())
|
2017-09-08 11:14:49 -04:00
|
|
|
unit = gimp_image_get_unit (image);
|
|
|
|
|
|
|
|
gimp_image_get_resolution (image, &xres, &yres);
|
|
|
|
|
|
|
|
in_image = (x >= 0.0 && x < gimp_image_get_width (image) &&
|
|
|
|
y >= 0.0 && y < gimp_image_get_height (image));
|
|
|
|
|
|
|
|
g_snprintf (buf, sizeof (buf), "%d", (gint) floor (x));
|
|
|
|
gtk_label_set_text (GTK_LABEL (view->priv->pixel_x_label), buf);
|
|
|
|
gimp_cursor_view_set_label_italic (view->priv->pixel_x_label, ! in_image);
|
|
|
|
|
|
|
|
g_snprintf (buf, sizeof (buf), "%d", (gint) floor (y));
|
|
|
|
gtk_label_set_text (GTK_LABEL (view->priv->pixel_y_label), buf);
|
|
|
|
gimp_cursor_view_set_label_italic (view->priv->pixel_y_label, ! in_image);
|
|
|
|
|
|
|
|
gimp_cursor_view_format_as_unit (unit, buf, sizeof (buf), x, xres);
|
|
|
|
gtk_label_set_text (GTK_LABEL (view->priv->unit_x_label), buf);
|
|
|
|
gimp_cursor_view_set_label_italic (view->priv->unit_x_label, ! in_image);
|
|
|
|
|
|
|
|
gimp_cursor_view_format_as_unit (unit, buf, sizeof (buf), y, yres);
|
|
|
|
gtk_label_set_text (GTK_LABEL (view->priv->unit_y_label), buf);
|
|
|
|
gimp_cursor_view_set_label_italic (view->priv->unit_y_label, ! in_image);
|
|
|
|
|
|
|
|
int_x = (gint) floor (x);
|
|
|
|
int_y = (gint) floor (y);
|
|
|
|
|
2023-11-12 17:56:32 +01:00
|
|
|
color = gegl_color_new ("black");
|
2017-09-08 11:14:49 -04:00
|
|
|
if (gimp_image_pick_color (image, NULL,
|
|
|
|
int_x, int_y,
|
2024-11-16 14:08:44 +09:00
|
|
|
show_all,
|
2017-09-08 11:14:49 -04:00
|
|
|
view->priv->sample_merged,
|
|
|
|
FALSE, 0.0,
|
|
|
|
&sample_format, pixel, &color))
|
|
|
|
{
|
|
|
|
gimp_color_frame_set_color (GIMP_COLOR_FRAME (view->priv->color_frame_1),
|
2023-11-23 16:20:36 +01:00
|
|
|
FALSE, color, int_x, int_y);
|
2017-09-08 11:14:49 -04:00
|
|
|
gimp_color_frame_set_color (GIMP_COLOR_FRAME (view->priv->color_frame_2),
|
2023-11-23 16:20:36 +01:00
|
|
|
FALSE, color, int_x, int_y);
|
2017-09-08 11:14:49 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_color_frame_set_invalid (GIMP_COLOR_FRAME (view->priv->color_frame_1));
|
|
|
|
gimp_color_frame_set_invalid (GIMP_COLOR_FRAME (view->priv->color_frame_2));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Show the selection info from the image under the cursor if any */
|
|
|
|
gimp_cursor_view_update_selection_info (view,
|
|
|
|
image,
|
|
|
|
view->priv->cursor_unit);
|
|
|
|
|
|
|
|
g_clear_object (&view->priv->cursor_image);
|
2023-11-12 17:56:32 +01:00
|
|
|
g_object_unref (color);
|
2017-09-08 11:14:49 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_label_set_text (GTK_LABEL (view->priv->pixel_x_label), _("n/a"));
|
|
|
|
gtk_label_set_text (GTK_LABEL (view->priv->pixel_y_label), _("n/a"));
|
|
|
|
gtk_label_set_text (GTK_LABEL (view->priv->unit_x_label), _("n/a"));
|
|
|
|
gtk_label_set_text (GTK_LABEL (view->priv->unit_y_label), _("n/a"));
|
|
|
|
|
|
|
|
gimp_color_frame_set_invalid (GIMP_COLOR_FRAME (view->priv->color_frame_1));
|
|
|
|
gimp_color_frame_set_invalid (GIMP_COLOR_FRAME (view->priv->color_frame_2));
|
|
|
|
|
|
|
|
/* Start showing selection info from the active image again */
|
|
|
|
gimp_cursor_view_update_selection_info (view,
|
|
|
|
view->priv->image,
|
|
|
|
view->priv->unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
view->priv->cursor_idle_id = 0;
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
2005-04-03 15:48:03 +00:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
GtkWidget *
|
2022-03-03 03:15:44 +00:00
|
|
|
gimp_cursor_view_new (Gimp *gimp,
|
|
|
|
GimpMenuFactory *menu_factory)
|
2005-04-03 15:48:03 +00:00
|
|
|
{
|
2005-07-08 22:54:46 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_MENU_FACTORY (menu_factory), NULL);
|
|
|
|
|
|
|
|
return g_object_new (GIMP_TYPE_CURSOR_VIEW,
|
2022-03-03 03:15:44 +00:00
|
|
|
"gimp", gimp,
|
2005-07-08 22:54:46 +00:00
|
|
|
"menu-factory", menu_factory,
|
|
|
|
"menu-identifier", "<CursorInfo>",
|
|
|
|
"ui-path", "/cursor-info-popup",
|
|
|
|
NULL);
|
2005-04-03 15:48:03 +00:00
|
|
|
}
|
|
|
|
|
2005-07-08 22:54:46 +00:00
|
|
|
void
|
|
|
|
gimp_cursor_view_set_sample_merged (GimpCursorView *view,
|
|
|
|
gboolean sample_merged)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CURSOR_VIEW (view));
|
|
|
|
|
|
|
|
sample_merged = sample_merged ? TRUE : FALSE;
|
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
if (view->priv->sample_merged != sample_merged)
|
2005-07-08 22:54:46 +00:00
|
|
|
{
|
2008-11-13 20:12:49 +00:00
|
|
|
view->priv->sample_merged = sample_merged;
|
2005-07-08 22:54:46 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (view), "sample-merged");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_cursor_view_get_sample_merged (GimpCursorView *view)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_CURSOR_VIEW (view), FALSE);
|
|
|
|
|
2008-11-13 20:12:49 +00:00
|
|
|
return view->priv->sample_merged;
|
2005-07-08 22:54:46 +00:00
|
|
|
}
|
|
|
|
|
2005-04-03 15:48:03 +00:00
|
|
|
void
|
|
|
|
gimp_cursor_view_update_cursor (GimpCursorView *view,
|
|
|
|
GimpImage *image,
|
Issue #8900 and #9923: reimplementing GimpUnit as a proper class.
This fixes all our GObject Introspection issues with GimpUnit which was
both an enum and an int-derived type of user-defined units *completing*
the enum values. GIR clearly didn't like this!
Now GimpUnit is a proper class and units are unique objects, allowing to
compare them with an identity test (i.e. `unit == gimp_unit_pixel ()`
tells us if unit is the pixel unit or not), which makes it easy to use,
just like with int, yet adding also methods, making for nicer
introspected API.
As an aside, this also fixes #10738, by having all the built-in units
retrievable even if libgimpbase had not been properly initialized with
gimp_base_init().
I haven't checked in details how GIR works to introspect, but it looks
like it loads the library to inspect and runs functions, hence
triggering some CRITICALS because virtual methods (supposed to be
initialized with gimp_base_init() run by libgimp) are not set. This new
code won't trigger any critical because the vtable method are now not
necessary, at least for all built-in units.
Note that GimpUnit is still in libgimpbase. It could have been moved to
libgimp in order to avoid any virtual method table (since we need to
keep core and libgimp side's units in sync, PDB is required), but too
many libgimpwidgets widgets were already using GimpUnit. And technically
most of GimpUnit logic doesn't require PDB (only the creation/sync
part). This is one of the reasons why user-created GimpUnit list is
handled and stored differently from other types of objects.
Globally this simplifies the code a lot too and we don't need separate
implementations of various utils for core and libgimp, which means less
prone to errors.
2024-07-25 20:55:21 +02:00
|
|
|
GimpUnit *shell_unit,
|
2024-11-16 14:08:44 +09:00
|
|
|
gboolean shell_show_all,
|
2005-04-03 15:48:03 +00:00
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CURSOR_VIEW (view));
|
2007-03-20 19:03:34 +00:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (image));
|
2005-04-03 15:48:03 +00:00
|
|
|
|
2017-09-08 11:14:49 -04:00
|
|
|
g_clear_object (&view->priv->cursor_image);
|
2005-04-03 15:48:03 +00:00
|
|
|
|
2024-11-16 14:08:44 +09:00
|
|
|
view->priv->cursor_image = g_object_ref (image);
|
|
|
|
view->priv->cursor_unit = shell_unit;
|
|
|
|
view->priv->cursor_show_all = shell_show_all;
|
|
|
|
view->priv->cursor_x = x;
|
|
|
|
view->priv->cursor_y = y;
|
2005-04-03 15:48:03 +00:00
|
|
|
|
2017-09-08 11:14:49 -04:00
|
|
|
if (view->priv->cursor_idle_id == 0)
|
2005-04-03 15:48:03 +00:00
|
|
|
{
|
2017-09-08 11:14:49 -04:00
|
|
|
view->priv->cursor_idle_id =
|
|
|
|
g_idle_add ((GSourceFunc) gimp_cursor_view_cursor_idle, view);
|
2005-04-03 15:48:03 +00:00
|
|
|
}
|
|
|
|
}
|
2007-03-20 19:03:34 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gimp_cursor_view_clear_cursor (GimpCursorView *view)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CURSOR_VIEW (view));
|
|
|
|
|
2017-09-08 11:14:49 -04:00
|
|
|
g_clear_object (&view->priv->cursor_image);
|
2008-11-10 22:18:33 +00:00
|
|
|
|
2017-09-08 11:14:49 -04:00
|
|
|
if (view->priv->cursor_idle_id == 0)
|
|
|
|
{
|
|
|
|
view->priv->cursor_idle_id =
|
|
|
|
g_idle_add ((GSourceFunc) gimp_cursor_view_cursor_idle, view);
|
|
|
|
}
|
2007-03-20 19:03:34 +00:00
|
|
|
}
|