[gimp] app: fix GimpNavigationView and GimpNavigationEditor for rotated canvases
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: fix GimpNavigationView and GimpNavigationEditor for rotated canvases
- Date: Tue, 5 Jan 2016 14:16:21 +0000 (UTC)
commit 51d41b2d616547e2446a6a9dd0c84490aea98a75
Author: Michael Natterer <mitch gimp org>
Date: Tue Jan 5 15:14:08 2016 +0100
app: fix GimpNavigationView and GimpNavigationEditor for rotated canvases
by changing it to always deal with the center of the viewport instead of
its upper-left corner.
Fix gimp_display_shell_scroll_center_image_coordinate() to use the
proper transform functions like in the last commit.
app/display/gimpdisplayshell-scroll.c | 19 +++---
app/display/gimpnavigationeditor.c | 32 +++++-----
app/widgets/gimpnavigationview.c | 110 +++++++++++++++++++--------------
app/widgets/gimpnavigationview.h | 14 +++--
4 files changed, 95 insertions(+), 80 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-scroll.c b/app/display/gimpdisplayshell-scroll.c
index 553f5d3..4a37e8a 100644
--- a/app/display/gimpdisplayshell-scroll.c
+++ b/app/display/gimpdisplayshell-scroll.c
@@ -38,6 +38,7 @@
#include "gimpdisplayshell-rotate.h"
#include "gimpdisplayshell-scale.h"
#include "gimpdisplayshell-scroll.h"
+#include "gimpdisplayshell-transform.h"
#define OVERPAN_FACTOR 0.5
@@ -66,20 +67,16 @@ gimp_display_shell_scroll_center_image_coordinate (GimpDisplayShell *shell,
gdouble image_x,
gdouble image_y)
{
- gint scaled_image_x;
- gint scaled_image_y;
- gint offset_to_apply_x;
- gint offset_to_apply_y;
+ gint viewport_x;
+ gint viewport_y;
- scaled_image_x = RINT (image_x * shell->scale_x);
- scaled_image_y = RINT (image_y * shell->scale_y);
-
- offset_to_apply_x = scaled_image_x - shell->disp_width / 2 - shell->offset_x;
- offset_to_apply_y = scaled_image_y - shell->disp_height / 2 - shell->offset_y;
+ gimp_display_shell_transform_xy (shell,
+ image_x, image_y,
+ &viewport_x, &viewport_y);
gimp_display_shell_scroll (shell,
- offset_to_apply_x,
- offset_to_apply_y);
+ viewport_x - shell->disp_width / 2,
+ viewport_y - shell->disp_height / 2);
}
void
diff --git a/app/display/gimpnavigationeditor.c b/app/display/gimpnavigationeditor.c
index 65f729e..4493355 100644
--- a/app/display/gimpnavigationeditor.c
+++ b/app/display/gimpnavigationeditor.c
@@ -48,6 +48,7 @@
#include "gimpdisplayshell.h"
#include "gimpdisplayshell-scale.h"
#include "gimpdisplayshell-scroll.h"
+#include "gimpdisplayshell-transform.h"
#include "gimpnavigationeditor.h"
#include "gimp-intl.h"
@@ -72,8 +73,8 @@ static gboolean gimp_navigation_editor_button_release (GtkWidget
GdkEventButton *bevent,
GimpDisplayShell *shell);
static void gimp_navigation_editor_marker_changed (GimpNavigationView *view,
- gdouble x,
- gdouble y,
+ gdouble center_x,
+ gdouble center_y,
gdouble width,
gdouble height,
GimpNavigationEditor *editor);
@@ -235,7 +236,7 @@ gimp_navigation_editor_popup (GimpDisplayShell *shell,
GimpNavigationView *view;
GdkScreen *screen;
gint x, y;
- gint view_marker_x, view_marker_y;
+ gint view_marker_center_x, view_marker_center_y;
gint view_marker_width, view_marker_height;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
@@ -276,8 +277,8 @@ gimp_navigation_editor_popup (GimpDisplayShell *shell,
gtk_window_set_screen (GTK_WINDOW (shell->nav_popup), screen);
gimp_navigation_view_get_local_marker (view,
- &view_marker_x,
- &view_marker_y,
+ &view_marker_center_x,
+ &view_marker_center_y,
&view_marker_width,
&view_marker_height);
/* Position the popup */
@@ -299,13 +300,11 @@ gimp_navigation_editor_popup (GimpDisplayShell *shell,
x = screen_click_x -
border_width -
- view_marker_x -
- view_marker_width / 2;
+ view_marker_center_x;
y = screen_click_y -
border_height -
- view_marker_y -
- view_marker_height / 2;
+ view_marker_center_y;
/* When the image is zoomed out and overscrolled, the above
* calculation risks positioning the popup far far away from the
@@ -333,9 +332,7 @@ gimp_navigation_editor_popup (GimpDisplayShell *shell,
gdk_flush ();
/* fill in then grab pointer */
- gimp_navigation_view_set_motion_offset (view,
- view_marker_width / 2,
- view_marker_height / 2);
+ gimp_navigation_view_set_motion_offset (view, 0, 0);
gimp_navigation_view_grab_pointer (view);
}
@@ -520,8 +517,8 @@ gimp_navigation_editor_button_release (GtkWidget *widget,
static void
gimp_navigation_editor_marker_changed (GimpNavigationView *view,
- gdouble x,
- gdouble y,
+ gdouble center_x,
+ gdouble center_y,
gdouble width,
gdouble height,
GimpNavigationEditor *editor)
@@ -530,8 +527,7 @@ gimp_navigation_editor_marker_changed (GimpNavigationView *view,
{
if (gimp_display_get_image (editor->shell->display))
gimp_display_shell_scroll_center_image_coordinate (editor->shell,
- x + width / 2,
- y + height / 2);
+ center_x, center_y);
}
}
@@ -711,6 +707,10 @@ gimp_navigation_editor_update_marker (GimpNavigationEditor *editor)
gdouble w, h;
gimp_display_shell_scroll_get_viewport (shell, &x, &y, &w, &h);
+ gimp_display_shell_untransform_xy_f (shell,
+ shell->disp_width / 2,
+ shell->disp_height / 2,
+ &x, &y);
gimp_navigation_view_set_marker (view, x, y, w, h);
}
diff --git a/app/widgets/gimpnavigationview.c b/app/widgets/gimpnavigationview.c
index 3a29810..b449052 100644
--- a/app/widgets/gimpnavigationview.c
+++ b/app/widgets/gimpnavigationview.c
@@ -56,14 +56,14 @@ struct _GimpNavigationView
GimpView parent_instance;
/* values in image coordinates */
- gdouble x;
- gdouble y;
+ gdouble center_x;
+ gdouble center_y;
gdouble width;
gdouble height;
/* values in view coordinates */
- gint p_x;
- gint p_y;
+ gint p_center_x;
+ gint p_center_y;
gint p_width;
gint p_height;
@@ -161,13 +161,13 @@ gimp_navigation_view_init (GimpNavigationView *view)
GDK_POINTER_MOTION_MASK |
GDK_KEY_PRESS_MASK);
- view->x = 0.0;
- view->y = 0.0;
+ view->center_x = 0.0;
+ view->center_y = 0.0;
view->width = 0.0;
view->height = 0.0;
- view->p_x = 0;
- view->p_y = 0;
+ view->p_center_x = 0;
+ view->p_center_y = 0;
view->p_width = 0;
view->p_height = 0;
@@ -242,25 +242,27 @@ gimp_navigation_view_button_press (GtkWidget *widget,
{
GimpNavigationView *nav_view = GIMP_NAVIGATION_VIEW (widget);
gint tx, ty;
+ gint p_width_2;
+ gint p_height_2;
GdkDisplay *display;
tx = bevent->x;
ty = bevent->y;
+ p_width_2 = nav_view->p_width / 2;
+ p_height_2 = nav_view->p_height / 2;
+
if (bevent->type == GDK_BUTTON_PRESS && bevent->button == 1)
{
- if (! (tx > nav_view->p_x &&
- tx < (nav_view->p_x + nav_view->p_width) &&
- ty > nav_view->p_y &&
- ty < (nav_view->p_y + nav_view->p_height)))
+ if (! (tx >= (nav_view->p_center_x - p_width_2) &&
+ tx < (nav_view->p_center_x + p_width_2) &&
+ ty >= (nav_view->p_center_y - p_height_2) &&
+ ty < (nav_view->p_center_y + p_height_2)))
{
GdkCursor *cursor;
- nav_view->motion_offset_x = nav_view->p_width / 2;
- nav_view->motion_offset_y = nav_view->p_height / 2;
-
- tx -= nav_view->motion_offset_x;
- ty -= nav_view->motion_offset_y;
+ nav_view->motion_offset_x = 0;
+ nav_view->motion_offset_y = 0;
gimp_navigation_view_move_to (nav_view, tx, ty);
@@ -271,8 +273,8 @@ gimp_navigation_view_button_press (GtkWidget *widget,
}
else
{
- nav_view->motion_offset_x = tx - nav_view->p_x;
- nav_view->motion_offset_y = ty - nav_view->p_y;
+ nav_view->motion_offset_x = tx - nav_view->p_center_x;
+ nav_view->motion_offset_y = ty - nav_view->p_center_y;
}
gimp_navigation_view_grab_pointer (nav_view);
@@ -349,19 +351,24 @@ gimp_navigation_view_motion_notify (GtkWidget *widget,
{
GdkDisplay *display = gtk_widget_get_display (widget);
GdkCursor *cursor;
+ gint p_width_2;
+ gint p_height_2;
- if (nav_view->p_x == 0 &&
- nav_view->p_y == 0 &&
- nav_view->p_width == view->renderer->width &&
- nav_view->p_height == view->renderer->height)
+ p_width_2 = nav_view->p_width / 2;
+ p_height_2 = nav_view->p_height / 2;
+
+ if (nav_view->p_center_x == view->renderer->width / 2 &&
+ nav_view->p_center_y == view->renderer->height / 2 &&
+ nav_view->p_width == view->renderer->width &&
+ nav_view->p_height == view->renderer->height)
{
gdk_window_set_cursor (view->event_window, NULL);
return FALSE;
}
- else if (mevent->x >= nav_view->p_x &&
- mevent->y >= nav_view->p_y &&
- mevent->x < nav_view->p_x + nav_view->p_width &&
- mevent->y < nav_view->p_y + nav_view->p_height)
+ else if (mevent->x >= nav_view->p_center_x - p_width_2 &&
+ mevent->y >= nav_view->p_center_y - p_height_2 &&
+ mevent->x < nav_view->p_center_x + p_width_2 &&
+ mevent->y < nav_view->p_center_y + p_height_2)
{
cursor = gdk_cursor_new_for_display (display, GDK_FLEUR);
}
@@ -418,8 +425,8 @@ gimp_navigation_view_key_press (GtkWidget *widget,
if (scroll_x || scroll_y)
{
gimp_navigation_view_move_to (nav_view,
- nav_view->p_x + scroll_x,
- nav_view->p_y + scroll_y);
+ nav_view->p_center_x + scroll_x,
+ nav_view->p_center_y + scroll_y);
return TRUE;
}
@@ -431,8 +438,8 @@ gimp_navigation_view_key_press (GtkWidget *widget,
void
gimp_navigation_view_set_marker (GimpNavigationView *nav_view,
- gdouble x,
- gdouble y,
+ gdouble center_x,
+ gdouble center_y,
gdouble width,
gdouble height)
{
@@ -444,10 +451,10 @@ gimp_navigation_view_set_marker (GimpNavigationView *nav_view,
g_return_if_fail (view->renderer->viewable);
- nav_view->x = x;
- nav_view->y = y;
- nav_view->width = MAX (1.0, width);
- nav_view->height = MAX (1.0, height);
+ nav_view->center_x = center_x;
+ nav_view->center_y = center_y;
+ nav_view->width = MAX (1.0, width);
+ nav_view->height = MAX (1.0, height);
gimp_navigation_view_transform (nav_view);
@@ -468,17 +475,17 @@ gimp_navigation_view_set_motion_offset (GimpNavigationView *view,
void
gimp_navigation_view_get_local_marker (GimpNavigationView *view,
- gint *x,
- gint *y,
+ gint *center_x,
+ gint *center_y,
gint *width,
gint *height)
{
g_return_if_fail (GIMP_IS_NAVIGATION_VIEW (view));
- if (x) *x = view->p_x;
- if (y) *y = view->p_y;
- if (width) *width = view->p_width;
- if (height) *height = view->p_height;
+ if (center_x) *center_x = view->p_center_x;
+ if (center_y) *center_y = view->p_center_y;
+ if (width) *width = view->p_width;
+ if (height) *height = view->p_height;
}
@@ -491,8 +498,8 @@ gimp_navigation_view_transform (GimpNavigationView *nav_view)
gimp_navigation_view_get_ratio (nav_view, &ratiox, &ratioy);
- nav_view->p_x = RINT (nav_view->x * ratiox);
- nav_view->p_y = RINT (nav_view->y * ratioy);
+ nav_view->p_center_x = RINT (nav_view->center_x * ratiox);
+ nav_view->p_center_y = RINT (nav_view->center_y * ratioy);
nav_view->p_width = ceil (nav_view->width * ratiox);
nav_view->p_height = ceil (nav_view->height * ratioy);
@@ -508,6 +515,11 @@ gimp_navigation_view_draw_marker (GimpNavigationView *nav_view,
{
GtkWidget *widget = GTK_WIDGET (view);
GtkAllocation allocation;
+ gint p_width_2;
+ gint p_height_2;
+
+ p_width_2 = nav_view->p_width / 2;
+ p_height_2 = nav_view->p_height / 2;
gtk_widget_get_allocation (widget, &allocation);
@@ -516,16 +528,20 @@ gimp_navigation_view_draw_marker (GimpNavigationView *nav_view,
0, 0,
allocation.width, allocation.height);
cairo_rectangle (cr,
- nav_view->p_x, nav_view->p_y,
- nav_view->p_width, nav_view->p_height);
+ nav_view->p_center_x - p_width_2,
+ nav_view->p_center_y - p_height_2,
+ nav_view->p_width,
+ nav_view->p_height);
cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
cairo_fill (cr);
cairo_rectangle (cr,
- nav_view->p_x, nav_view->p_y,
- nav_view->p_width, nav_view->p_height);
+ nav_view->p_center_x - p_width_2,
+ nav_view->p_center_y - p_height_2,
+ nav_view->p_width,
+ nav_view->p_height);
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_set_line_width (cr, BORDER_WIDTH);
diff --git a/app/widgets/gimpnavigationview.h b/app/widgets/gimpnavigationview.h
index 09928b5..a5498aa 100644
--- a/app/widgets/gimpnavigationview.h
+++ b/app/widgets/gimpnavigationview.h
@@ -42,8 +42,10 @@ struct _GimpNavigationViewClass
GimpViewClass parent_class;
void (* marker_changed) (GimpNavigationView *view,
- gdouble x,
- gdouble y);
+ gdouble center_x,
+ gdouble center_y,
+ gdouble width,
+ gdouble height);
void (* zoom) (GimpNavigationView *view,
GimpZoomType direction);
void (* scroll) (GimpNavigationView *view,
@@ -54,8 +56,8 @@ struct _GimpNavigationViewClass
GType gimp_navigation_view_get_type (void) G_GNUC_CONST;
void gimp_navigation_view_set_marker (GimpNavigationView *view,
- gdouble x,
- gdouble y,
+ gdouble center_x,
+ gdouble center_y,
gdouble width,
gdouble height);
void gimp_navigation_view_set_motion_offset
@@ -64,8 +66,8 @@ void gimp_navigation_view_set_motion_offset
gint motion_offset_y);
void gimp_navigation_view_get_local_marker
(GimpNavigationView *view,
- gint *x,
- gint *y,
+ gint *center_x,
+ gint *center_y,
gint *width,
gint *height);
void gimp_navigation_view_grab_pointer (GimpNavigationView *view);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]