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
|
|
|
|
1999-03-07 20:56:03 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2006-08-29 22:46:32 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2010-09-29 03:10:03 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2007-03-09 21:00:01 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2008-10-23 17:42:55 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2006-08-29 22:46:32 +08:00
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display-types.h"
|
2002-05-03 20:45:22 +08:00
|
|
|
|
2012-04-10 18:09:37 +08:00
|
|
|
#include "core/gimp-cairo.h"
|
2013-04-19 22:22:19 +08:00
|
|
|
#include "core/gimp-utils.h"
|
2002-04-15 01:28:58 +08:00
|
|
|
|
2003-11-10 07:24:40 +08:00
|
|
|
#include "gimpcanvas.h"
|
2013-04-18 20:21:20 +08:00
|
|
|
#include "gimpcanvas-style.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "gimpdisplay.h"
|
|
|
|
#include "gimpdisplayshell.h"
|
2004-02-07 08:16:52 +08:00
|
|
|
#include "gimpdisplayshell-draw.h"
|
2001-11-02 17:31:21 +08:00
|
|
|
#include "gimpdisplayshell-render.h"
|
2017-12-09 17:25:35 +08:00
|
|
|
|
|
|
|
|
2004-02-07 08:16:52 +08:00
|
|
|
/* public functions */
|
2002-02-17 21:12:16 +08:00
|
|
|
|
2010-08-27 00:09:33 +08:00
|
|
|
void
|
|
|
|
gimp_display_shell_draw_selection_out (GimpDisplayShell *shell,
|
|
|
|
cairo_t *cr,
|
2010-10-15 18:37:36 +08:00
|
|
|
GimpSegment *segs,
|
2010-08-27 00:09:33 +08:00
|
|
|
gint n_segs)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
g_return_if_fail (cr != NULL);
|
|
|
|
g_return_if_fail (segs != NULL && n_segs > 0);
|
|
|
|
|
2016-03-27 05:50:10 +08:00
|
|
|
gimp_canvas_set_selection_out_style (shell->canvas, cr,
|
|
|
|
shell->offset_x, shell->offset_y);
|
2010-08-27 00:09:33 +08:00
|
|
|
|
2018-03-07 17:38:58 +08:00
|
|
|
gimp_cairo_segments (cr, segs, n_segs);
|
2010-08-27 00:09:33 +08:00
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-08-27 21:03:03 +08:00
|
|
|
gimp_display_shell_draw_selection_in (GimpDisplayShell *shell,
|
|
|
|
cairo_t *cr,
|
|
|
|
cairo_pattern_t *mask,
|
|
|
|
gint index)
|
2010-08-27 02:52:52 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
g_return_if_fail (cr != NULL);
|
|
|
|
g_return_if_fail (mask != NULL);
|
|
|
|
|
2016-03-27 05:50:10 +08:00
|
|
|
gimp_canvas_set_selection_in_style (shell->canvas, cr, index,
|
|
|
|
shell->offset_x, shell->offset_y);
|
2010-08-27 02:52:52 +08:00
|
|
|
|
|
|
|
cairo_mask (cr, mask);
|
|
|
|
}
|
|
|
|
|
2013-04-18 17:56:43 +08:00
|
|
|
void
|
|
|
|
gimp_display_shell_draw_background (GimpDisplayShell *shell,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
2018-05-24 04:46:54 +08:00
|
|
|
GimpCanvas *canvas;
|
2013-04-18 17:56:43 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
g_return_if_fail (cr != NULL);
|
|
|
|
|
2018-05-24 04:46:54 +08:00
|
|
|
canvas = GIMP_CANVAS (shell->canvas);
|
2013-04-18 17:56:43 +08:00
|
|
|
|
2018-05-24 04:46:54 +08:00
|
|
|
if (canvas->padding_mode != GIMP_CANVAS_PADDING_MODE_DEFAULT)
|
|
|
|
{
|
|
|
|
gimp_cairo_set_source_rgb (cr, &canvas->padding_color);
|
|
|
|
cairo_paint (cr);
|
|
|
|
}
|
2013-04-18 17:56:43 +08:00
|
|
|
}
|
|
|
|
|
2013-04-20 16:47:13 +08:00
|
|
|
void
|
|
|
|
gimp_display_shell_draw_checkerboard (GimpDisplayShell *shell,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
g_return_if_fail (cr != NULL);
|
|
|
|
|
|
|
|
if (G_UNLIKELY (! shell->checkerboard))
|
|
|
|
{
|
|
|
|
GimpCheckSize check_size;
|
|
|
|
GimpCheckType check_type;
|
|
|
|
guchar check_light;
|
|
|
|
guchar check_dark;
|
|
|
|
GimpRGB light;
|
|
|
|
GimpRGB dark;
|
|
|
|
|
|
|
|
g_object_get (shell->display->config,
|
|
|
|
"transparency-size", &check_size,
|
|
|
|
"transparency-type", &check_type,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gimp_checks_get_shades (check_type, &check_light, &check_dark);
|
|
|
|
gimp_rgb_set_uchar (&light, check_light, check_light, check_light);
|
|
|
|
gimp_rgb_set_uchar (&dark, check_dark, check_dark, check_dark);
|
|
|
|
|
|
|
|
shell->checkerboard =
|
|
|
|
gimp_cairo_checkerboard_create (cr,
|
|
|
|
1 << (check_size + 2), &light, &dark);
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_translate (cr, - shell->offset_x, - shell->offset_y);
|
|
|
|
cairo_set_source (cr, shell->checkerboard);
|
|
|
|
cairo_paint (cr);
|
|
|
|
}
|
|
|
|
|
2003-02-21 20:16:43 +08:00
|
|
|
void
|
2010-09-30 02:58:13 +08:00
|
|
|
gimp_display_shell_draw_image (GimpDisplayShell *shell,
|
|
|
|
cairo_t *cr,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
2001-11-01 05:20:09 +08:00
|
|
|
{
|
2017-12-09 17:25:35 +08:00
|
|
|
gdouble chunk_width;
|
|
|
|
gdouble chunk_height;
|
|
|
|
gdouble scale = 1.0;
|
|
|
|
gint n_rows;
|
|
|
|
gint n_cols;
|
|
|
|
gint r, c;
|
2007-06-06 21:45:44 +08:00
|
|
|
|
2008-03-19 05:22:21 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
2010-05-02 19:08:11 +08:00
|
|
|
g_return_if_fail (gimp_display_get_image (shell->display));
|
2010-08-28 01:32:16 +08:00
|
|
|
g_return_if_fail (cr != NULL);
|
2008-03-19 05:22:21 +08:00
|
|
|
|
2010-05-02 19:08:11 +08:00
|
|
|
/* display the image in RENDER_BUF_WIDTH x RENDER_BUF_HEIGHT
|
2017-12-09 17:25:35 +08:00
|
|
|
* maximally-sized image-space chunks. adjust the screen-space
|
|
|
|
* chunk size as necessary, to accommodate for the display
|
|
|
|
* transform and window scale factor.
|
2004-02-07 09:41:30 +08:00
|
|
|
*/
|
2019-07-16 05:24:35 +08:00
|
|
|
chunk_width = shell->render_buf_width;
|
|
|
|
chunk_height = shell->render_buf_height;
|
2014-04-21 00:06:52 +08:00
|
|
|
|
2017-12-09 17:25:35 +08:00
|
|
|
#ifdef GIMP_DISPLAY_RENDER_ENABLE_SCALING
|
2018-05-04 08:07:31 +08:00
|
|
|
/* multiply the image scale-factor by the window scale-factor, and divide
|
|
|
|
* the cairo scale-factor by the same amount (further down), so that we make
|
|
|
|
* full use of the screen resolution, even on hidpi displays.
|
|
|
|
*/
|
2017-12-09 17:25:35 +08:00
|
|
|
scale *=
|
|
|
|
gdk_window_get_scale_factor (
|
|
|
|
gtk_widget_get_window (gtk_widget_get_toplevel (GTK_WIDGET (shell))));
|
|
|
|
#endif
|
|
|
|
|
2017-12-20 03:42:28 +08:00
|
|
|
scale = MIN (scale, GIMP_DISPLAY_RENDER_MAX_SCALE);
|
|
|
|
scale *= MAX (shell->scale_x, shell->scale_y);
|
2017-12-09 17:25:35 +08:00
|
|
|
|
2017-12-20 03:42:28 +08:00
|
|
|
if (scale != shell->scale_x)
|
|
|
|
chunk_width = (chunk_width - 1.0) * (shell->scale_x / scale);
|
|
|
|
if (scale != shell->scale_y)
|
|
|
|
chunk_height = (chunk_height - 1.0) * (shell->scale_y / scale);
|
2017-12-09 17:25:35 +08:00
|
|
|
|
|
|
|
if (shell->rotate_untransform)
|
2014-04-21 00:06:52 +08:00
|
|
|
{
|
2017-12-09 17:25:35 +08:00
|
|
|
gdouble a = shell->rotate_angle * G_PI / 180.0;
|
|
|
|
|
2017-12-09 18:21:55 +08:00
|
|
|
chunk_width = chunk_height = (MIN (chunk_width, chunk_height) - 1.0) /
|
2017-12-09 17:25:35 +08:00
|
|
|
(fabs (sin (a)) + fabs (cos (a)));
|
2014-04-21 00:06:52 +08:00
|
|
|
}
|
|
|
|
|
2017-12-09 17:25:35 +08:00
|
|
|
/* divide the painted area to evenly-sized chunks */
|
2017-12-09 23:28:37 +08:00
|
|
|
n_rows = ceil (h / floor (chunk_height));
|
|
|
|
n_cols = ceil (w / floor (chunk_width));
|
2004-10-01 17:50:04 +08:00
|
|
|
|
2017-12-09 17:25:35 +08:00
|
|
|
for (r = 0; r < n_rows; r++)
|
|
|
|
{
|
|
|
|
gint y1 = y + (2 * r * h + n_rows) / (2 * n_rows);
|
|
|
|
gint y2 = y + (2 * (r + 1) * h + n_rows) / (2 * n_rows);
|
2004-02-07 09:41:30 +08:00
|
|
|
|
2017-12-09 17:25:35 +08:00
|
|
|
for (c = 0; c < n_cols; c++)
|
|
|
|
{
|
2019-07-16 05:24:35 +08:00
|
|
|
gint x1 = x + (2 * c * w + n_cols) / (2 * n_cols);
|
|
|
|
gint x2 = x + (2 * (c + 1) * w + n_cols) / (2 * n_cols);
|
2017-12-09 17:25:35 +08:00
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
|
|
|
/* clip to chunk bounds, in screen space */
|
|
|
|
cairo_rectangle (cr, x1, y1, x2 - x1, y2 - y1);
|
|
|
|
cairo_clip (cr);
|
|
|
|
|
2019-07-16 05:24:35 +08:00
|
|
|
if (! gimp_display_shell_render_is_valid (shell,
|
|
|
|
x1, y1, x2 - x1, y2 - y1))
|
|
|
|
{
|
|
|
|
/* render image to the render cache */
|
|
|
|
gimp_display_shell_render (shell, cr,
|
|
|
|
x1, y1, x2 - x1, y2 - y1,
|
|
|
|
scale);
|
|
|
|
|
|
|
|
gimp_display_shell_render_validate_area (shell,
|
|
|
|
x1, y1, x2 - x1, y2 - y1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* render from the render cache to screen */
|
|
|
|
cairo_set_source_surface (cr, shell->render_cache, 0, 0);
|
|
|
|
cairo_paint (cr);
|
2017-12-09 17:25:35 +08:00
|
|
|
|
|
|
|
cairo_restore (cr);
|
|
|
|
|
|
|
|
/* if the GIMP_BRICK_WALL environment variable is defined,
|
|
|
|
* show chunk bounds
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
static gint brick_wall = -1;
|
|
|
|
|
|
|
|
if (brick_wall < 0)
|
|
|
|
brick_wall = (g_getenv ("GIMP_BRICK_WALL") != NULL);
|
|
|
|
|
|
|
|
if (brick_wall)
|
|
|
|
{
|
|
|
|
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
|
|
|
|
cairo_rectangle (cr, x1, y1, x2 - x1, y2 - y1);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
|
|
|
}
|
2001-11-01 05:20:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|