app: in GimpCanvasBufferPreview, add support for offset buffers

Ditto.

(cherry picked from commit 43f8a5199f)
This commit is contained in:
Ell
2020-02-03 20:03:57 +02:00
parent 21d6c8a8da
commit f4dc0fd147

View File

@ -25,9 +25,12 @@
#include <cairo/cairo.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpmath/gimpmath.h"
#include "display/display-types.h"
#include "core/gimpimage.h"
#include "gimpcanvas.h"
#include "gimpcanvasbufferpreview.h"
#include "gimpdisplayshell.h"
@ -150,17 +153,9 @@ gimp_canvas_buffer_preview_draw (GimpCanvasItem *item,
cairo_surface_t *area;
guchar *data;
cairo_rectangle_int_t rectangle;
gint viewport_offset_x, viewport_offset_y;
gint viewport_width, viewport_height;
g_return_if_fail (GEGL_IS_BUFFER (buffer));
gimp_display_shell_scroll_get_scaled_viewport (shell,
&viewport_offset_x,
&viewport_offset_y,
&viewport_width,
&viewport_height);
gimp_canvas_buffer_preview_compute_bounds (item, &rectangle);
area = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
@ -169,8 +164,8 @@ gimp_canvas_buffer_preview_draw (GimpCanvasItem *item,
data = cairo_image_surface_get_data (area);
gegl_buffer_get (buffer,
GEGL_RECTANGLE ((viewport_offset_x < 0 ? 0 : viewport_offset_x),
(viewport_offset_y < 0 ? 0 : viewport_offset_y),
GEGL_RECTANGLE (rectangle.x + shell->offset_x,
rectangle.y + shell->offset_y,
rectangle.width,
rectangle.height),
shell->scale_x,
@ -197,38 +192,39 @@ gimp_canvas_buffer_preview_compute_bounds (GimpCanvasItem *item,
{
GimpDisplayShell *shell = gimp_canvas_item_get_shell (item);
GeglBuffer *buffer = GET_PRIVATE (item)->buffer;
gint x_from, x_to;
gint y_from, y_to;
gint viewport_offset_x, viewport_offset_y;
gint viewport_width, viewport_height;
gint width, height;
GeglRectangle extent;
gdouble x1, y1;
gdouble x2, y2;
g_return_if_fail (GEGL_IS_BUFFER (buffer));
width = gegl_buffer_get_width (buffer);
height = gegl_buffer_get_height (buffer);
extent = *gegl_buffer_get_extent (buffer);
gimp_display_shell_scroll_get_scaled_viewport (shell,
&viewport_offset_x,
&viewport_offset_y,
&viewport_width,
&viewport_height);
gimp_canvas_item_transform_xy_f (item,
extent.x,
extent.y,
&x1, &y1);
gimp_canvas_item_transform_xy_f (item,
extent.x + extent.width,
extent.y + extent.height,
&x2, &y2);
x_from = (viewport_offset_x < 0 ? -viewport_offset_x : 0);
y_from = (viewport_offset_y < 0 ? -viewport_offset_y : 0);
extent.x = floor (x1);
extent.y = floor (y1);
extent.width = ceil (x2) - extent.x;
extent.height = ceil (y2) - extent.y;
x_to = width * shell->scale_x - viewport_offset_x;
if (x_to > viewport_width)
x_to = viewport_width;
gegl_rectangle_intersect (&extent,
&extent,
GEGL_RECTANGLE (0,
0,
shell->disp_width,
shell->disp_height));
y_to = height * shell->scale_y - viewport_offset_y;
if (y_to > viewport_height)
y_to = viewport_height;
bounds->x = x_from;
bounds->y = y_from;
bounds->width = x_to - x_from;
bounds->height = y_to - y_from;
bounds->x = extent.x;
bounds->y = extent.y;
bounds->width = extent.width;
bounds->height = extent.height;
}
static cairo_region_t *