app: add support for show-all mode in GimpCanvasGrid
Don't crop the grid to the canvas size in show-all mode.
This commit is contained in:
@ -34,7 +34,9 @@
|
|||||||
|
|
||||||
#include "gimpcanvas-style.h"
|
#include "gimpcanvas-style.h"
|
||||||
#include "gimpcanvasgrid.h"
|
#include "gimpcanvasgrid.h"
|
||||||
|
#include "gimpcanvasitem-utils.h"
|
||||||
#include "gimpdisplayshell.h"
|
#include "gimpdisplayshell.h"
|
||||||
|
#include "gimpdisplayshell-scale.h"
|
||||||
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
@ -181,16 +183,13 @@ gimp_canvas_grid_draw (GimpCanvasItem *item,
|
|||||||
{
|
{
|
||||||
GimpCanvasGridPrivate *private = GET_PRIVATE (item);
|
GimpCanvasGridPrivate *private = GET_PRIVATE (item);
|
||||||
GimpDisplayShell *shell = gimp_canvas_item_get_shell (item);
|
GimpDisplayShell *shell = gimp_canvas_item_get_shell (item);
|
||||||
GimpImage *image = gimp_canvas_item_get_image (item);
|
|
||||||
gdouble xspacing, yspacing;
|
gdouble xspacing, yspacing;
|
||||||
gdouble xoffset, yoffset;
|
gdouble xoffset, yoffset;
|
||||||
gboolean vert, horz;
|
gboolean vert, horz;
|
||||||
gdouble x, y;
|
|
||||||
gdouble dx1, dy1, dx2, dy2;
|
gdouble dx1, dy1, dx2, dy2;
|
||||||
gint x0, x1, x2, x3;
|
gint x1, y1, x2, y2;
|
||||||
gint y0, y1, y2, y3;
|
gdouble dx, dy;
|
||||||
gint x_real, y_real;
|
gint x, y;
|
||||||
gint width, height;
|
|
||||||
|
|
||||||
#define CROSSHAIR 2
|
#define CROSSHAIR 2
|
||||||
|
|
||||||
@ -200,55 +199,90 @@ gimp_canvas_grid_draw (GimpCanvasItem *item,
|
|||||||
g_return_if_fail (xspacing >= 0.0 &&
|
g_return_if_fail (xspacing >= 0.0 &&
|
||||||
yspacing >= 0.0);
|
yspacing >= 0.0);
|
||||||
|
|
||||||
|
xspacing *= shell->scale_x;
|
||||||
|
yspacing *= shell->scale_y;
|
||||||
|
|
||||||
|
xoffset *= shell->scale_x;
|
||||||
|
yoffset *= shell->scale_y;
|
||||||
|
|
||||||
/* skip grid drawing when the space between grid lines starts
|
/* skip grid drawing when the space between grid lines starts
|
||||||
* disappearing, see bug #599267.
|
* disappearing, see bug #599267.
|
||||||
*/
|
*/
|
||||||
vert = (xspacing * shell->scale_x >= 2.0);
|
vert = (xspacing >= 2.0);
|
||||||
horz = (yspacing * shell->scale_y >= 2.0);
|
horz = (yspacing >= 2.0);
|
||||||
|
|
||||||
if (! vert && ! horz)
|
if (! vert && ! horz)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cairo_clip_extents (cr, &dx1, &dy1, &dx2, &dy2);
|
cairo_clip_extents (cr, &dx1, &dy1, &dx2, &dy2);
|
||||||
|
|
||||||
x1 = floor (dx1);
|
x1 = floor (dx1) - 1;
|
||||||
y1 = floor (dy1);
|
y1 = floor (dy1) - 1;
|
||||||
x2 = ceil (dx2);
|
x2 = ceil (dx2) + 1;
|
||||||
y2 = ceil (dy2);
|
y2 = ceil (dy2) + 1;
|
||||||
|
|
||||||
width = gimp_image_get_width (image);
|
if (! shell->show_all)
|
||||||
height = gimp_image_get_height (image);
|
{
|
||||||
|
GeglRectangle bounds;
|
||||||
|
|
||||||
xoffset = fmod (xoffset, xspacing);
|
gimp_display_shell_scale_get_image_unrotated_bounding_box (
|
||||||
yoffset = fmod (yoffset, yspacing);
|
shell,
|
||||||
|
&bounds.x, &bounds.y, &bounds.width, &bounds.height);
|
||||||
|
|
||||||
|
if (! gegl_rectangle_intersect (&bounds,
|
||||||
|
&bounds,
|
||||||
|
GEGL_RECTANGLE (x1, y1,
|
||||||
|
x2 - x1, y2 - y1)))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
x1 = bounds.x;
|
||||||
|
y1 = bounds.y;
|
||||||
|
x2 = bounds.x + bounds.width;
|
||||||
|
y2 = bounds.y + bounds.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (gimp_grid_get_style (private->grid))
|
||||||
|
{
|
||||||
|
case GIMP_GRID_INTERSECTIONS:
|
||||||
|
x1 -= CROSSHAIR;
|
||||||
|
y1 -= CROSSHAIR;
|
||||||
|
x2 += CROSSHAIR;
|
||||||
|
y2 += CROSSHAIR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GIMP_GRID_DOTS:
|
||||||
|
case GIMP_GRID_ON_OFF_DASH:
|
||||||
|
case GIMP_GRID_DOUBLE_DASH:
|
||||||
|
case GIMP_GRID_SOLID:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
xoffset = fmod (xoffset - shell->offset_x - x1, xspacing);
|
||||||
|
yoffset = fmod (yoffset - shell->offset_y - y1, yspacing);
|
||||||
|
|
||||||
|
if (xoffset < 0.0)
|
||||||
|
xoffset += xspacing;
|
||||||
|
|
||||||
|
if (yoffset < 0.0)
|
||||||
|
yoffset += yspacing;
|
||||||
|
|
||||||
switch (gimp_grid_get_style (private->grid))
|
switch (gimp_grid_get_style (private->grid))
|
||||||
{
|
{
|
||||||
case GIMP_GRID_DOTS:
|
case GIMP_GRID_DOTS:
|
||||||
if (vert && horz)
|
if (vert && horz)
|
||||||
{
|
{
|
||||||
for (x = xoffset; x <= width; x += xspacing)
|
for (dx = x1 + xoffset; dx <= x2; dx += xspacing)
|
||||||
{
|
{
|
||||||
if (x < 0)
|
x = RINT (dx);
|
||||||
continue;
|
|
||||||
|
|
||||||
gimp_canvas_item_transform_xy (item, x, 0, &x_real, &y_real);
|
for (dy = y1 + yoffset; dy <= y2; dy += yspacing)
|
||||||
|
|
||||||
if (x_real < x1 || x_real >= x2)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for (y = yoffset; y <= height; y += yspacing)
|
|
||||||
{
|
{
|
||||||
if (y < 0)
|
y = RINT (dy);
|
||||||
continue;
|
|
||||||
|
|
||||||
gimp_canvas_item_transform_xy (item, x, y, &x_real, &y_real);
|
cairo_move_to (cr, x, y + 0.5);
|
||||||
|
cairo_line_to (cr, x + 1.0, y + 0.5);
|
||||||
if (y_real >= y1 && y_real < y2)
|
|
||||||
{
|
|
||||||
cairo_move_to (cr, x_real, y_real + 0.5);
|
|
||||||
cairo_line_to (cr, x_real + 1, y_real + 0.5);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -257,49 +291,19 @@ gimp_canvas_grid_draw (GimpCanvasItem *item,
|
|||||||
case GIMP_GRID_INTERSECTIONS:
|
case GIMP_GRID_INTERSECTIONS:
|
||||||
if (vert && horz)
|
if (vert && horz)
|
||||||
{
|
{
|
||||||
for (x = xoffset; x <= width; x += xspacing)
|
for (dx = x1 + xoffset; dx <= x2; dx += xspacing)
|
||||||
{
|
{
|
||||||
if (x < 0)
|
x = RINT (dx);
|
||||||
continue;
|
|
||||||
|
|
||||||
gimp_canvas_item_transform_xy (item, x, 0, &x_real, &y_real);
|
for (dy = y1 + yoffset; dy <= y2; dy += yspacing)
|
||||||
|
|
||||||
if (x_real + CROSSHAIR < x1 || x_real - CROSSHAIR >= x2)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for (y = yoffset; y <= height; y += yspacing)
|
|
||||||
{
|
{
|
||||||
if (y < 0)
|
y = RINT (dy);
|
||||||
continue;
|
|
||||||
|
|
||||||
gimp_canvas_item_transform_xy (item, x, y, &x_real, &y_real);
|
cairo_move_to (cr, x + 0.5, y - CROSSHAIR);
|
||||||
|
cairo_line_to (cr, x + 0.5, y + CROSSHAIR + 1.0);
|
||||||
|
|
||||||
if (y_real + CROSSHAIR < y1 || y_real - CROSSHAIR >= y2)
|
cairo_move_to (cr, x - CROSSHAIR, y + 0.5);
|
||||||
continue;
|
cairo_line_to (cr, x + CROSSHAIR + 1.0, y + 0.5);
|
||||||
|
|
||||||
if (x_real >= x1 && x_real < x2)
|
|
||||||
{
|
|
||||||
cairo_move_to (cr,
|
|
||||||
x_real + 0.5,
|
|
||||||
CLAMP (y_real - CROSSHAIR,
|
|
||||||
y1, y2 - 1));
|
|
||||||
cairo_line_to (cr,
|
|
||||||
x_real + 0.5,
|
|
||||||
CLAMP (y_real + CROSSHAIR,
|
|
||||||
y1, y2 - 1) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (y_real >= y1 && y_real < y2)
|
|
||||||
{
|
|
||||||
cairo_move_to (cr,
|
|
||||||
CLAMP (x_real - CROSSHAIR,
|
|
||||||
x1, x2 - 1),
|
|
||||||
y_real + 0.5);
|
|
||||||
cairo_line_to (cr,
|
|
||||||
CLAMP (x_real + CROSSHAIR,
|
|
||||||
x1, x2 - 1) + 1,
|
|
||||||
y_real + 0.5);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -308,40 +312,25 @@ gimp_canvas_grid_draw (GimpCanvasItem *item,
|
|||||||
case GIMP_GRID_ON_OFF_DASH:
|
case GIMP_GRID_ON_OFF_DASH:
|
||||||
case GIMP_GRID_DOUBLE_DASH:
|
case GIMP_GRID_DOUBLE_DASH:
|
||||||
case GIMP_GRID_SOLID:
|
case GIMP_GRID_SOLID:
|
||||||
gimp_canvas_item_transform_xy (item, 0, 0, &x0, &y0);
|
|
||||||
gimp_canvas_item_transform_xy (item, width, height, &x3, &y3);
|
|
||||||
|
|
||||||
if (vert)
|
if (vert)
|
||||||
{
|
{
|
||||||
for (x = xoffset; x < width; x += xspacing)
|
for (dx = x1 + xoffset; dx < x2; dx += xspacing)
|
||||||
{
|
{
|
||||||
if (x < 0)
|
x = RINT (dx);
|
||||||
continue;
|
|
||||||
|
|
||||||
gimp_canvas_item_transform_xy (item, x, 0, &x_real, &y_real);
|
cairo_move_to (cr, x + 0.5, y1);
|
||||||
|
cairo_line_to (cr, x + 0.5, y2);
|
||||||
if (x_real >= x1 && x_real < x2)
|
|
||||||
{
|
|
||||||
cairo_move_to (cr, x_real + 0.5, y0);
|
|
||||||
cairo_line_to (cr, x_real + 0.5, y3 + 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (horz)
|
if (horz)
|
||||||
{
|
{
|
||||||
for (y = yoffset; y < height; y += yspacing)
|
for (dy = y1 + yoffset; dy < y2; dy += yspacing)
|
||||||
{
|
{
|
||||||
if (y < 0)
|
y = RINT (dy);
|
||||||
continue;
|
|
||||||
|
|
||||||
gimp_canvas_item_transform_xy (item, 0, y, &x_real, &y_real);
|
cairo_move_to (cr, x1, y + 0.5);
|
||||||
|
cairo_line_to (cr, x2, y + 0.5);
|
||||||
if (y_real >= y1 && y_real < y2)
|
|
||||||
{
|
|
||||||
cairo_move_to (cr, x0, y_real + 0.5);
|
|
||||||
cairo_line_to (cr, x3 + 1, y_real + 0.5);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -353,15 +342,20 @@ gimp_canvas_grid_draw (GimpCanvasItem *item,
|
|||||||
static cairo_region_t *
|
static cairo_region_t *
|
||||||
gimp_canvas_grid_get_extents (GimpCanvasItem *item)
|
gimp_canvas_grid_get_extents (GimpCanvasItem *item)
|
||||||
{
|
{
|
||||||
|
GimpDisplayShell *shell = gimp_canvas_item_get_shell (item);
|
||||||
GimpImage *image = gimp_canvas_item_get_image (item);
|
GimpImage *image = gimp_canvas_item_get_image (item);
|
||||||
cairo_rectangle_int_t rectangle;
|
cairo_rectangle_int_t rectangle;
|
||||||
gdouble x1, y1;
|
|
||||||
gdouble x2, y2;
|
|
||||||
gint w, h;
|
|
||||||
|
|
||||||
if (! image)
|
if (! image)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (! shell->show_all)
|
||||||
|
{
|
||||||
|
|
||||||
|
gdouble x1, y1;
|
||||||
|
gdouble x2, y2;
|
||||||
|
gint w, h;
|
||||||
|
|
||||||
w = gimp_image_get_width (image);
|
w = gimp_image_get_width (image);
|
||||||
h = gimp_image_get_height (image);
|
h = gimp_image_get_height (image);
|
||||||
|
|
||||||
@ -372,6 +366,15 @@ gimp_canvas_grid_get_extents (GimpCanvasItem *item)
|
|||||||
rectangle.y = floor (y1);
|
rectangle.y = floor (y1);
|
||||||
rectangle.width = ceil (x2) - rectangle.x;
|
rectangle.width = ceil (x2) - rectangle.x;
|
||||||
rectangle.height = ceil (y2) - rectangle.y;
|
rectangle.height = ceil (y2) - rectangle.y;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gimp_canvas_item_untransform_viewport (item,
|
||||||
|
&rectangle.x,
|
||||||
|
&rectangle.y,
|
||||||
|
&rectangle.width,
|
||||||
|
&rectangle.height);
|
||||||
|
}
|
||||||
|
|
||||||
return cairo_region_create_rectangle (&rectangle);
|
return cairo_region_create_rectangle (&rectangle);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user