2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +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
|
1997-11-25 06:05:25 +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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-07-05 03:31:35 +08:00
|
|
|
#include "widgets-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-14 05:51:20 +08:00
|
|
|
#include "gimpcursor.h"
|
2000-03-02 03:32:41 +08:00
|
|
|
|
2010-09-11 01:12:52 +08:00
|
|
|
|
2018-12-31 23:10:46 +08:00
|
|
|
#define cursor_default_hot_x 10
|
|
|
|
#define cursor_default_hot_y 10
|
2012-08-27 19:29:18 +08:00
|
|
|
|
2018-12-31 23:10:46 +08:00
|
|
|
#define cursor_mouse_hot_x 3
|
|
|
|
#define cursor_mouse_hot_y 2
|
|
|
|
#define cursor_crosshair_hot_x 15
|
|
|
|
#define cursor_crosshair_hot_y 15
|
|
|
|
#define cursor_zoom_hot_x 8
|
|
|
|
#define cursor_zoom_hot_y 8
|
|
|
|
#define cursor_color_picker_hot_x 1
|
|
|
|
#define cursor_color_picker_hot_y 30
|
2000-06-09 20:31:19 +08:00
|
|
|
|
2000-03-26 02:17:01 +08:00
|
|
|
|
2004-06-10 22:43:08 +08:00
|
|
|
typedef struct _GimpCursor GimpCursor;
|
2001-05-14 05:51:20 +08:00
|
|
|
|
2004-06-10 22:43:08 +08:00
|
|
|
struct _GimpCursor
|
2001-05-14 05:51:20 +08:00
|
|
|
{
|
2015-04-15 04:55:10 +08:00
|
|
|
const gchar *resource_name;
|
2018-12-31 23:10:46 +08:00
|
|
|
const gint hot_x;
|
|
|
|
const gint hot_y;
|
2004-06-10 22:43:08 +08:00
|
|
|
|
2015-04-15 04:55:10 +08:00
|
|
|
GdkPixbuf *pixbuf;
|
2018-12-31 23:10:46 +08:00
|
|
|
GdkPixbuf *pixbuf_x2;
|
2001-05-14 05:51:20 +08:00
|
|
|
};
|
2000-03-26 02:17:01 +08:00
|
|
|
|
2001-02-25 03:29:47 +08:00
|
|
|
|
2004-06-10 22:43:08 +08:00
|
|
|
static GimpCursor gimp_cursors[] =
|
1999-05-05 17:10:35 +08:00
|
|
|
{
|
2002-11-18 07:13:26 +08:00
|
|
|
/* these have to match up with enum GimpCursorType in widgets-enums.h */
|
|
|
|
|
2004-06-05 07:08:29 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-none",
|
|
|
|
cursor_default_hot_x, cursor_default_hot_y
|
2004-06-05 07:08:29 +08:00
|
|
|
},
|
2000-03-02 03:32:41 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-mouse",
|
|
|
|
cursor_mouse_hot_x, cursor_mouse_hot_y
|
2000-03-02 03:32:41 +08:00
|
|
|
},
|
2000-06-06 08:28:28 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-crosshair",
|
|
|
|
cursor_crosshair_hot_x, cursor_crosshair_hot_y
|
2000-06-06 08:28:28 +08:00
|
|
|
},
|
2000-06-09 20:31:19 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-crosshair-small",
|
|
|
|
cursor_default_hot_x, cursor_default_hot_y
|
2000-06-09 20:31:19 +08:00
|
|
|
},
|
2000-03-02 03:32:41 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-bad",
|
|
|
|
cursor_default_hot_x, cursor_default_hot_y
|
2000-03-02 03:32:41 +08:00
|
|
|
},
|
2006-11-16 06:43:24 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-move",
|
|
|
|
cursor_default_hot_x, cursor_default_hot_y
|
2006-11-16 06:43:24 +08:00
|
|
|
},
|
2000-06-14 18:59:16 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-zoom",
|
|
|
|
cursor_zoom_hot_x, cursor_zoom_hot_y
|
2000-06-14 18:59:16 +08:00
|
|
|
},
|
2000-03-02 03:32:41 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-color-picker",
|
|
|
|
cursor_color_picker_hot_x, cursor_color_picker_hot_y
|
2006-06-02 23:23:47 +08:00
|
|
|
},
|
2012-08-27 05:59:05 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-corner-top",
|
|
|
|
cursor_default_hot_x, cursor_default_hot_y
|
2012-08-27 05:59:05 +08:00
|
|
|
},
|
2006-06-02 23:23:47 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-corner-top-right",
|
|
|
|
cursor_default_hot_x, cursor_default_hot_y
|
2006-06-02 23:23:47 +08:00
|
|
|
},
|
2012-08-27 05:59:05 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-corner-right",
|
|
|
|
cursor_default_hot_x, cursor_default_hot_y
|
2012-08-27 05:59:05 +08:00
|
|
|
},
|
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-corner-bottom-right",
|
|
|
|
cursor_default_hot_x, cursor_default_hot_y
|
2012-08-27 05:59:05 +08:00
|
|
|
},
|
2006-06-02 23:23:47 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-corner-bottom",
|
|
|
|
cursor_default_hot_x, cursor_default_hot_y
|
2006-06-02 23:23:47 +08:00
|
|
|
},
|
2012-08-27 05:59:05 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-corner-bottom-left",
|
|
|
|
cursor_default_hot_x, cursor_default_hot_y
|
2012-08-27 05:59:05 +08:00
|
|
|
},
|
2006-06-02 23:23:47 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-corner-left",
|
|
|
|
cursor_default_hot_x, cursor_default_hot_y
|
2006-06-02 23:23:47 +08:00
|
|
|
},
|
2012-08-27 05:59:05 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-corner-top-left",
|
|
|
|
cursor_default_hot_x, cursor_default_hot_y
|
2012-08-27 05:59:05 +08:00
|
|
|
},
|
2006-06-02 23:23:47 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-side-top",
|
|
|
|
cursor_default_hot_x, cursor_default_hot_y
|
2006-06-02 23:23:47 +08:00
|
|
|
},
|
2012-08-27 05:59:05 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-side-top-right",
|
|
|
|
cursor_default_hot_x, cursor_default_hot_y
|
2012-08-27 05:59:05 +08:00
|
|
|
},
|
2006-06-02 23:23:47 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-side-right",
|
|
|
|
cursor_default_hot_x, cursor_default_hot_y
|
2006-06-02 23:23:47 +08:00
|
|
|
},
|
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-side-bottom-right",
|
|
|
|
cursor_default_hot_x, cursor_default_hot_y
|
2013-04-20 23:21:01 +08:00
|
|
|
},
|
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-side-bottom",
|
|
|
|
cursor_default_hot_x, cursor_default_hot_y
|
2006-06-02 23:23:47 +08:00
|
|
|
},
|
2012-08-27 05:59:05 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-side-bottom-left",
|
|
|
|
cursor_default_hot_x, cursor_default_hot_y
|
2012-08-27 05:59:05 +08:00
|
|
|
},
|
2006-06-02 23:23:47 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-side-left",
|
|
|
|
cursor_default_hot_x, cursor_default_hot_y
|
2012-08-27 05:59:05 +08:00
|
|
|
},
|
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
"cursor-side-top-left",
|
|
|
|
cursor_default_hot_x, cursor_default_hot_y
|
2000-06-09 20:31:19 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-06-10 22:43:08 +08:00
|
|
|
static GimpCursor gimp_tool_cursors[] =
|
2000-06-09 20:31:19 +08:00
|
|
|
{
|
2002-11-18 07:13:26 +08:00
|
|
|
/* these have to match up with enum GimpToolCursorType in widgets-enums.h */
|
|
|
|
|
2010-09-11 01:12:52 +08:00
|
|
|
{ NULL },
|
2018-12-31 23:10:46 +08:00
|
|
|
{ "tool-rect-select" },
|
|
|
|
{ "tool-ellipse-select" },
|
|
|
|
{ "tool-free-select" },
|
|
|
|
{ "tool-polygon-select" },
|
|
|
|
{ "tool-fuzzy-select" },
|
|
|
|
{ "tool-paths" },
|
|
|
|
{ "tool-paths-anchor" },
|
|
|
|
{ "tool-paths-control" },
|
|
|
|
{ "tool-paths-segment" },
|
|
|
|
{ "tool-iscissors" },
|
|
|
|
{ "tool-move" },
|
|
|
|
{ "tool-zoom" },
|
|
|
|
{ "tool-crop" },
|
|
|
|
{ "tool-resize" },
|
|
|
|
{ "tool-rotate" },
|
|
|
|
{ "tool-shear" },
|
|
|
|
{ "tool-perspective" },
|
2020-01-06 22:39:56 +08:00
|
|
|
{ "tool-transform-3d-camera" },
|
2018-12-31 23:10:46 +08:00
|
|
|
{ "tool-flip-horizontal" },
|
|
|
|
{ "tool-flip-vertical" },
|
|
|
|
{ "tool-text" },
|
|
|
|
{ "tool-color-picker" },
|
|
|
|
{ "tool-bucket-fill" },
|
|
|
|
{ "tool-gradient" },
|
|
|
|
{ "tool-pencil" },
|
|
|
|
{ "tool-paintbrush" },
|
|
|
|
{ "tool-airbrush" },
|
|
|
|
{ "tool-ink" },
|
|
|
|
{ "tool-clone" },
|
|
|
|
{ "tool-heal" },
|
|
|
|
{ "tool-eraser" },
|
|
|
|
{ "tool-smudge" },
|
|
|
|
{ "tool-blur" },
|
|
|
|
{ "tool-dodge" },
|
|
|
|
{ "tool-burn" },
|
|
|
|
{ "tool-measure" },
|
|
|
|
{ "tool-warp" },
|
|
|
|
{ "tool-hand" }
|
2000-06-09 20:31:19 +08:00
|
|
|
};
|
|
|
|
|
2004-06-10 22:43:08 +08:00
|
|
|
static GimpCursor gimp_cursor_modifiers[] =
|
2000-06-09 20:31:19 +08:00
|
|
|
{
|
2002-11-18 07:13:26 +08:00
|
|
|
/* these have to match up with enum GimpCursorModifier in widgets-enums.h */
|
|
|
|
|
2010-09-11 01:12:52 +08:00
|
|
|
{ NULL },
|
2018-12-31 23:10:46 +08:00
|
|
|
{ "modifier-bad" },
|
|
|
|
{ "modifier-plus" },
|
|
|
|
{ "modifier-minus" },
|
|
|
|
{ "modifier-intersect" },
|
|
|
|
{ "modifier-move" },
|
|
|
|
{ "modifier-resize" },
|
|
|
|
{ "modifier-rotate" },
|
|
|
|
{ "modifier-zoom" },
|
|
|
|
{ "modifier-control" },
|
|
|
|
{ "modifier-anchor" },
|
|
|
|
{ "modifier-foreground" },
|
|
|
|
{ "modifier-background" },
|
|
|
|
{ "modifier-pattern" },
|
|
|
|
{ "modifier-join" },
|
|
|
|
{ "modifier-select" }
|
1999-05-05 17:10:35 +08:00
|
|
|
};
|
|
|
|
|
2012-08-27 19:29:18 +08:00
|
|
|
|
2010-09-11 01:12:52 +08:00
|
|
|
static const GdkPixbuf *
|
2018-12-31 23:10:46 +08:00
|
|
|
get_cursor_pixbuf (GimpCursor *cursor,
|
|
|
|
gint scale_factor)
|
1999-05-05 17:10:35 +08:00
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
gchar *resource_path;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-08-27 04:53:04 +08:00
|
|
|
if (! cursor->pixbuf)
|
2015-04-15 04:55:10 +08:00
|
|
|
{
|
|
|
|
resource_path = g_strconcat ("/org/gimp/tool-cursors/",
|
2018-12-31 23:10:46 +08:00
|
|
|
cursor->resource_name,
|
|
|
|
".png", NULL);
|
2015-04-15 04:55:10 +08:00
|
|
|
|
|
|
|
cursor->pixbuf = gdk_pixbuf_new_from_resource (resource_path, &error);
|
|
|
|
|
|
|
|
if (! cursor->pixbuf)
|
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
g_critical ("Failed to create cursor image '%s': %s",
|
|
|
|
resource_path, error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (resource_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scale_factor == 2 && ! cursor->pixbuf_x2)
|
|
|
|
{
|
|
|
|
resource_path = g_strconcat ("/org/gimp/tool-cursors/",
|
|
|
|
cursor->resource_name,
|
|
|
|
"-x2.png", NULL);
|
|
|
|
|
|
|
|
cursor->pixbuf_x2 = gdk_pixbuf_new_from_resource (resource_path, &error);
|
|
|
|
|
|
|
|
if (! cursor->pixbuf_x2)
|
|
|
|
{
|
|
|
|
/* no critical here until we actually have the cursor files */
|
|
|
|
g_printerr ("Failed to create scaled cursor image '%s' "
|
2019-01-01 02:11:22 +08:00
|
|
|
"falling back to upscaling default cursor: %s\n",
|
2018-12-31 23:10:46 +08:00
|
|
|
resource_path, error->message);
|
2015-04-15 04:55:10 +08:00
|
|
|
g_clear_error (&error);
|
2018-12-31 23:10:46 +08:00
|
|
|
|
|
|
|
if (cursor->pixbuf)
|
|
|
|
{
|
|
|
|
gint width = gdk_pixbuf_get_width (cursor->pixbuf);
|
|
|
|
gint height = gdk_pixbuf_get_height (cursor->pixbuf);
|
|
|
|
|
|
|
|
cursor->pixbuf_x2 = gdk_pixbuf_scale_simple (cursor->pixbuf,
|
|
|
|
width * 2,
|
|
|
|
height * 2,
|
|
|
|
GDK_INTERP_NEAREST);
|
|
|
|
}
|
2015-04-15 04:55:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (resource_path);
|
|
|
|
}
|
2004-06-05 03:03:49 +08:00
|
|
|
|
2018-12-31 23:10:46 +08:00
|
|
|
if (scale_factor == 2)
|
|
|
|
return cursor->pixbuf_x2;
|
|
|
|
else
|
|
|
|
return cursor->pixbuf;
|
2004-06-03 20:36:02 +08:00
|
|
|
}
|
|
|
|
|
2004-06-04 20:10:13 +08:00
|
|
|
GdkCursor *
|
2018-12-31 21:04:04 +08:00
|
|
|
gimp_cursor_new (GdkWindow *window,
|
2011-07-25 04:09:21 +08:00
|
|
|
GimpHandedness cursor_handedness,
|
2004-06-04 20:10:13 +08:00
|
|
|
GimpCursorType cursor_type,
|
|
|
|
GimpToolCursorType tool_cursor,
|
|
|
|
GimpCursorModifier modifier)
|
2004-06-03 20:36:02 +08:00
|
|
|
{
|
2018-12-31 21:04:04 +08:00
|
|
|
GdkDisplay *display;
|
2004-06-10 22:43:08 +08:00
|
|
|
GimpCursor *bmcursor = NULL;
|
|
|
|
GimpCursor *bmmodifier = NULL;
|
|
|
|
GimpCursor *bmtool = NULL;
|
2010-09-11 01:12:52 +08:00
|
|
|
GdkCursor *cursor;
|
|
|
|
GdkPixbuf *pixbuf;
|
2018-12-31 23:10:46 +08:00
|
|
|
gint scale_factor;
|
|
|
|
gint hot_x;
|
|
|
|
gint hot_y;
|
2004-06-03 20:36:02 +08:00
|
|
|
|
2018-12-31 21:04:04 +08:00
|
|
|
g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
|
2004-06-05 07:08:29 +08:00
|
|
|
g_return_val_if_fail (cursor_type < GIMP_CURSOR_LAST, NULL);
|
2004-06-03 20:36:02 +08:00
|
|
|
|
2018-12-31 21:04:04 +08:00
|
|
|
display = gdk_window_get_display (window);
|
|
|
|
|
2011-03-17 21:42:44 +08:00
|
|
|
if (cursor_type <= (GimpCursorType) GDK_LAST_CURSOR)
|
2015-01-10 06:47:57 +08:00
|
|
|
return gdk_cursor_new_for_display (display, (GdkCursorType) cursor_type);
|
2004-06-03 20:36:02 +08:00
|
|
|
|
2004-06-05 07:08:29 +08:00
|
|
|
g_return_val_if_fail (cursor_type >= GIMP_CURSOR_NONE, NULL);
|
2004-06-03 20:36:02 +08:00
|
|
|
|
2006-06-02 23:23:47 +08:00
|
|
|
/* disallow the small tool cursor with some cursors
|
2004-06-03 20:36:02 +08:00
|
|
|
*/
|
2006-06-02 23:23:47 +08:00
|
|
|
if (cursor_type <= GIMP_CURSOR_NONE ||
|
|
|
|
cursor_type == GIMP_CURSOR_CROSSHAIR ||
|
|
|
|
cursor_type == GIMP_CURSOR_ZOOM ||
|
|
|
|
cursor_type == GIMP_CURSOR_COLOR_PICKER ||
|
|
|
|
cursor_type >= GIMP_CURSOR_LAST)
|
2004-06-03 20:36:02 +08:00
|
|
|
{
|
|
|
|
tool_cursor = GIMP_TOOL_CURSOR_NONE;
|
|
|
|
}
|
|
|
|
|
2004-06-10 22:43:08 +08:00
|
|
|
/* don't allow anything with the empty cursor
|
|
|
|
*/
|
|
|
|
if (cursor_type == GIMP_CURSOR_NONE)
|
|
|
|
{
|
|
|
|
tool_cursor = GIMP_TOOL_CURSOR_NONE;
|
|
|
|
modifier = GIMP_CURSOR_MODIFIER_NONE;
|
|
|
|
}
|
|
|
|
|
2007-08-02 21:33:38 +08:00
|
|
|
/* some more sanity checks
|
|
|
|
*/
|
|
|
|
if (cursor_type == GIMP_CURSOR_MOVE &&
|
|
|
|
modifier == GIMP_CURSOR_MODIFIER_MOVE)
|
|
|
|
{
|
|
|
|
modifier = GIMP_CURSOR_MODIFIER_NONE;
|
|
|
|
}
|
|
|
|
|
2011-07-25 04:09:21 +08:00
|
|
|
/* when cursor is "corner" or "side" sides must be exchanged for
|
|
|
|
* left-hand-mice-flipping of pixbuf below
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (cursor_handedness == GIMP_HANDEDNESS_LEFT)
|
|
|
|
{
|
2012-08-27 19:29:18 +08:00
|
|
|
switch (cursor_type)
|
2011-07-25 04:09:21 +08:00
|
|
|
{
|
2012-08-27 19:29:18 +08:00
|
|
|
case GIMP_CURSOR_CORNER_TOP_LEFT:
|
|
|
|
cursor_type = GIMP_CURSOR_CORNER_TOP_RIGHT; break;
|
|
|
|
|
|
|
|
case GIMP_CURSOR_CORNER_TOP_RIGHT:
|
|
|
|
cursor_type = GIMP_CURSOR_CORNER_TOP_LEFT; break;
|
|
|
|
|
|
|
|
case GIMP_CURSOR_CORNER_LEFT:
|
|
|
|
cursor_type = GIMP_CURSOR_CORNER_RIGHT; break;
|
|
|
|
|
|
|
|
case GIMP_CURSOR_CORNER_RIGHT:
|
|
|
|
cursor_type = GIMP_CURSOR_CORNER_LEFT; break;
|
|
|
|
|
|
|
|
case GIMP_CURSOR_CORNER_BOTTOM_LEFT:
|
|
|
|
cursor_type = GIMP_CURSOR_CORNER_BOTTOM_RIGHT; break;
|
|
|
|
|
|
|
|
case GIMP_CURSOR_CORNER_BOTTOM_RIGHT:
|
|
|
|
cursor_type = GIMP_CURSOR_CORNER_BOTTOM_LEFT; break;
|
|
|
|
|
|
|
|
case GIMP_CURSOR_SIDE_TOP_LEFT:
|
|
|
|
cursor_type = GIMP_CURSOR_SIDE_TOP_RIGHT; break;
|
|
|
|
|
|
|
|
case GIMP_CURSOR_SIDE_TOP_RIGHT:
|
|
|
|
cursor_type = GIMP_CURSOR_SIDE_TOP_LEFT; break;
|
|
|
|
|
|
|
|
case GIMP_CURSOR_SIDE_LEFT:
|
|
|
|
cursor_type = GIMP_CURSOR_SIDE_RIGHT; break;
|
|
|
|
|
|
|
|
case GIMP_CURSOR_SIDE_RIGHT:
|
|
|
|
cursor_type = GIMP_CURSOR_SIDE_LEFT; break;
|
|
|
|
|
|
|
|
case GIMP_CURSOR_SIDE_BOTTOM_LEFT:
|
|
|
|
cursor_type = GIMP_CURSOR_SIDE_BOTTOM_RIGHT; break;
|
|
|
|
|
|
|
|
case GIMP_CURSOR_SIDE_BOTTOM_RIGHT:
|
|
|
|
cursor_type = GIMP_CURSOR_SIDE_BOTTOM_LEFT; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2012-08-27 05:59:05 +08:00
|
|
|
}
|
2011-07-25 04:09:21 +08:00
|
|
|
}
|
|
|
|
|
2004-06-03 20:36:02 +08:00
|
|
|
/* prepare the main cursor */
|
|
|
|
|
2004-06-05 07:08:29 +08:00
|
|
|
cursor_type -= GIMP_CURSOR_NONE;
|
2004-06-03 20:36:02 +08:00
|
|
|
bmcursor = &gimp_cursors[cursor_type];
|
|
|
|
|
|
|
|
/* prepare the tool cursor */
|
|
|
|
|
2007-08-02 21:33:38 +08:00
|
|
|
if (tool_cursor > GIMP_TOOL_CURSOR_NONE &&
|
|
|
|
tool_cursor < GIMP_TOOL_CURSOR_LAST)
|
|
|
|
{
|
|
|
|
bmtool = &gimp_tool_cursors[tool_cursor];
|
|
|
|
}
|
2004-06-03 20:36:02 +08:00
|
|
|
|
|
|
|
/* prepare the cursor modifier */
|
|
|
|
|
2007-08-02 21:33:38 +08:00
|
|
|
if (modifier > GIMP_CURSOR_MODIFIER_NONE &&
|
|
|
|
modifier < GIMP_CURSOR_MODIFIER_LAST)
|
|
|
|
{
|
|
|
|
bmmodifier = &gimp_cursor_modifiers[modifier];
|
|
|
|
}
|
2004-06-03 20:36:02 +08:00
|
|
|
|
2018-12-31 23:10:46 +08:00
|
|
|
scale_factor = gdk_window_get_scale_factor (window);
|
|
|
|
|
|
|
|
/* we only support x2 scaling right now */
|
|
|
|
scale_factor = CLAMP (scale_factor, 1, 2);
|
|
|
|
|
|
|
|
pixbuf = gdk_pixbuf_copy (get_cursor_pixbuf (bmcursor, scale_factor));
|
2004-06-04 20:10:13 +08:00
|
|
|
|
2010-09-11 01:12:52 +08:00
|
|
|
if (bmmodifier || bmtool)
|
|
|
|
{
|
|
|
|
gint width = gdk_pixbuf_get_width (pixbuf);
|
|
|
|
gint height = gdk_pixbuf_get_height (pixbuf);
|
2004-06-04 20:10:13 +08:00
|
|
|
|
|
|
|
if (bmmodifier)
|
2018-12-31 23:10:46 +08:00
|
|
|
gdk_pixbuf_composite (get_cursor_pixbuf (bmmodifier, scale_factor),
|
|
|
|
pixbuf,
|
2004-06-05 03:03:49 +08:00
|
|
|
0, 0, width, height,
|
|
|
|
0.0, 0.0, 1.0, 1.0,
|
2012-08-27 04:53:04 +08:00
|
|
|
GDK_INTERP_NEAREST, 200);
|
2004-06-04 20:10:13 +08:00
|
|
|
|
|
|
|
if (bmtool)
|
2018-12-31 23:10:46 +08:00
|
|
|
gdk_pixbuf_composite (get_cursor_pixbuf (bmtool, scale_factor),
|
|
|
|
pixbuf,
|
2004-06-05 03:03:49 +08:00
|
|
|
0, 0, width, height,
|
|
|
|
0.0, 0.0, 1.0, 1.0,
|
2012-08-27 04:53:04 +08:00
|
|
|
GDK_INTERP_NEAREST, 200);
|
2004-06-03 20:36:02 +08:00
|
|
|
}
|
|
|
|
|
2018-12-31 23:10:46 +08:00
|
|
|
hot_x = bmcursor->hot_x;
|
|
|
|
hot_y = bmcursor->hot_y;
|
|
|
|
|
2011-07-25 04:09:21 +08:00
|
|
|
/* flip the cursor if mouse setting is left-handed */
|
|
|
|
|
|
|
|
if (cursor_handedness == GIMP_HANDEDNESS_LEFT)
|
|
|
|
{
|
|
|
|
GdkPixbuf *flipped = gdk_pixbuf_flip (pixbuf, TRUE);
|
|
|
|
gint width = gdk_pixbuf_get_width (flipped);
|
|
|
|
|
2018-12-31 23:10:46 +08:00
|
|
|
g_object_unref (pixbuf);
|
|
|
|
pixbuf = flipped;
|
|
|
|
|
|
|
|
hot_x = (width - 1) - hot_x;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scale_factor > 1)
|
|
|
|
{
|
|
|
|
cairo_surface_t *surface =
|
|
|
|
gdk_cairo_surface_create_from_pixbuf (pixbuf, scale_factor, NULL);
|
|
|
|
|
|
|
|
cursor = gdk_cursor_new_from_surface (display, surface, hot_x, hot_y);
|
|
|
|
cairo_surface_destroy (surface);
|
2011-07-25 04:09:21 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-31 23:10:46 +08:00
|
|
|
cursor = gdk_cursor_new_from_pixbuf (display, pixbuf, hot_x, hot_y);
|
2011-07-25 04:09:21 +08:00
|
|
|
}
|
|
|
|
|
2010-09-11 01:12:52 +08:00
|
|
|
g_object_unref (pixbuf);
|
2004-06-03 20:36:02 +08:00
|
|
|
|
2004-06-04 20:10:13 +08:00
|
|
|
return cursor;
|
2004-06-03 20:36:02 +08:00
|
|
|
}
|
|
|
|
|
2003-11-02 04:53:18 +08:00
|
|
|
void
|
|
|
|
gimp_cursor_set (GtkWidget *widget,
|
2011-07-25 04:09:21 +08:00
|
|
|
GimpHandedness cursor_handedness,
|
2003-11-02 04:53:18 +08:00
|
|
|
GimpCursorType cursor_type,
|
|
|
|
GimpToolCursorType tool_cursor,
|
|
|
|
GimpCursorModifier modifier)
|
|
|
|
{
|
2018-12-31 21:04:04 +08:00
|
|
|
GdkWindow *window;
|
2003-11-02 04:53:18 +08:00
|
|
|
GdkCursor *cursor;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
2010-04-20 01:21:07 +08:00
|
|
|
g_return_if_fail (gtk_widget_get_realized (widget));
|
2003-11-02 04:53:18 +08:00
|
|
|
|
2018-12-31 21:04:04 +08:00
|
|
|
window = gtk_widget_get_window (widget);
|
|
|
|
|
|
|
|
cursor = gimp_cursor_new (window,
|
2011-07-25 04:09:21 +08:00
|
|
|
cursor_handedness,
|
2003-11-02 04:53:18 +08:00
|
|
|
cursor_type,
|
|
|
|
tool_cursor,
|
|
|
|
modifier);
|
2018-12-31 21:04:04 +08:00
|
|
|
gdk_window_set_cursor (window, cursor);
|
2010-12-29 22:30:20 +08:00
|
|
|
g_object_unref (cursor);
|
2014-06-03 02:16:04 +08:00
|
|
|
|
2018-12-31 21:04:04 +08:00
|
|
|
gdk_display_flush (gdk_window_get_display (window));
|
2003-11-02 04:53:18 +08:00
|
|
|
}
|
2013-04-20 23:21:01 +08:00
|
|
|
|
|
|
|
GimpCursorType
|
|
|
|
gimp_cursor_rotate (GimpCursorType cursor,
|
|
|
|
gdouble angle)
|
|
|
|
{
|
|
|
|
if (cursor >= GIMP_CURSOR_CORNER_TOP &&
|
|
|
|
cursor <= GIMP_CURSOR_SIDE_TOP_LEFT)
|
|
|
|
{
|
|
|
|
gint offset = (gint) (angle / 45 + 0.5);
|
|
|
|
|
|
|
|
if (cursor < GIMP_CURSOR_SIDE_TOP)
|
|
|
|
{
|
|
|
|
cursor += offset;
|
|
|
|
|
|
|
|
if (cursor > GIMP_CURSOR_CORNER_TOP_LEFT)
|
|
|
|
cursor -= 8;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cursor += offset;
|
|
|
|
|
|
|
|
if (cursor > GIMP_CURSOR_SIDE_TOP_LEFT)
|
|
|
|
cursor -= 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cursor;
|
|
|
|
}
|