summaryrefslogtreecommitdiffstats
path: root/src/ui/tools/tool-base.cpp
diff options
context:
space:
mode:
authorMartin Owens <doctormo@gmail.com>2017-06-30 03:58:14 +0000
committerMartin Owens <doctormo@gmail.com>2017-06-30 03:58:14 +0000
commitf55448431e934bf29bb9a983711d204614db7cc7 (patch)
tree52358e8121babdf471b4cb86f1b704275e5865ac /src/ui/tools/tool-base.cpp
parentMerge branch 'master' of gitlab.com:inkscape/inkscape (diff)
downloadinkscape-f55448431e934bf29bb9a983711d204614db7cc7.tar.gz
inkscape-f55448431e934bf29bb9a983711d204614db7cc7.zip
Hackfest: Refactor cursors so the hot spot is inside the xpm
Diffstat (limited to 'src/ui/tools/tool-base.cpp')
-rw-r--r--src/ui/tools/tool-base.cpp55
1 files changed, 16 insertions, 39 deletions
diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp
index 9231db7c8..0467b984e 100644
--- a/src/ui/tools/tool-base.cpp
+++ b/src/ui/tools/tool-base.cpp
@@ -86,7 +86,7 @@ SPDesktop const& ToolBase::getDesktop() const {
return *desktop;
}
-ToolBase::ToolBase(gchar const *const *cursor_shape, gint hot_x, gint hot_y, bool uses_snap)
+ToolBase::ToolBase(gchar const *const *cursor_shape, bool uses_snap)
: pref_observer(NULL)
, cursor(NULL)
, xp(0)
@@ -104,8 +104,6 @@ ToolBase::ToolBase(gchar const *const *cursor_shape, gint hot_x, gint hot_y, boo
, desktop(NULL)
, _uses_snap(uses_snap)
, cursor_shape(cursor_shape)
- , hot_x(hot_x)
- , hot_y(hot_y)
{
}
@@ -154,44 +152,24 @@ void ToolBase::sp_event_context_set_cursor(GdkCursorType cursor_type) {
void ToolBase::sp_event_context_update_cursor() {
GtkWidget *w = GTK_WIDGET(this->desktop->getCanvas());
if (gtk_widget_get_window (w)) {
-
GtkStyle *style = gtk_widget_get_style(w);
- /* fixme: */
if (this->cursor_shape) {
- GdkDisplay *display = gdk_display_get_default();
- if (gdk_display_supports_cursor_alpha(display) && gdk_display_supports_cursor_color(display)) {
- bool fillHasColor=false, strokeHasColor=false;
- guint32 fillColor = sp_desktop_get_color_tool(this->desktop, this->getPrefsPath(), true, &fillHasColor);
- guint32 strokeColor = sp_desktop_get_color_tool(this->desktop, this->getPrefsPath(), false, &strokeHasColor);
- double fillOpacity = fillHasColor ? sp_desktop_get_opacity_tool(this->desktop, this->getPrefsPath(), true) : 0;
- double strokeOpacity = strokeHasColor ? sp_desktop_get_opacity_tool(this->desktop, this->getPrefsPath(), false) : 0;
-
- GdkPixbuf *pixbuf = sp_cursor_pixbuf_from_xpm(
- this->cursor_shape,
- style->black, style->white,
- SP_RGBA32_U_COMPOSE(SP_RGBA32_R_U(fillColor),SP_RGBA32_G_U(fillColor),SP_RGBA32_B_U(fillColor),SP_COLOR_F_TO_U(fillOpacity)),
- SP_RGBA32_U_COMPOSE(SP_RGBA32_R_U(strokeColor),SP_RGBA32_G_U(strokeColor),SP_RGBA32_B_U(strokeColor),SP_COLOR_F_TO_U(strokeOpacity))
- );
- if (pixbuf != NULL) {
- if (this->cursor) {
- g_object_unref(this->cursor);
- }
- this->cursor = gdk_cursor_new_from_pixbuf(display, pixbuf, this->hot_x, this->hot_y);
- g_object_unref(pixbuf);
- }
- } else {
- GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **)this->cursor_shape);
-
- if (pixbuf) {
- if (this->cursor) {
- g_object_unref(this->cursor);
- }
- this->cursor = gdk_cursor_new_from_pixbuf(display,
- pixbuf, this->hot_x, this->hot_y);
- g_object_unref(pixbuf);
- }
+ if(this->cursor) {
+ g_object_unref(this->cursor);
}
+
+ bool fillHasColor=false, strokeHasColor=false;
+ guint32 fillColor = sp_desktop_get_color_tool(this->desktop, this->getPrefsPath(), true, &fillHasColor);
+ guint32 strokeColor = sp_desktop_get_color_tool(this->desktop, this->getPrefsPath(), false, &strokeHasColor);
+ double fillOpacity = fillHasColor ? sp_desktop_get_opacity_tool(this->desktop, this->getPrefsPath(), true) : 0;
+ double strokeOpacity = strokeHasColor ? sp_desktop_get_opacity_tool(this->desktop, this->getPrefsPath(), false) : 0;
+
+ this->cursor = sp_cursor_from_xpm(
+ this->cursor_shape, &style->black, &style->white,
+ SP_RGBA32_C_COMPOSE(fillColor, fillOpacity),
+ SP_RGBA32_C_COMPOSE(strokeColor, strokeOpacity)
+ );
}
gdk_window_set_cursor(gtk_widget_get_window (w), this->cursor);
gdk_flush();
@@ -208,8 +186,7 @@ void ToolBase::sp_event_context_update_cursor() {
void ToolBase::setup() {
this->pref_observer = new ToolPrefObserver(this->getPrefsPath(), this);
Inkscape::Preferences::get()->addObserver(*(this->pref_observer));
-
- this->sp_event_context_update_cursor();
+ this->sp_event_context_update_cursor();
}
/**