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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://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"
|
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"
|
2010-10-07 05:02:16 +08:00
|
|
|
#include "gimpcanvaspath.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"
|
2013-02-03 20:26:32 +08:00
|
|
|
#include "gimpdisplayxfer.h"
|
2002-05-08 00:23:14 +08:00
|
|
|
|
2001-11-01 05:20:09 +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);
|
|
|
|
|
2013-04-18 20:21:20 +08:00
|
|
|
gimp_canvas_set_selection_out_style (shell->canvas, cr);
|
2010-08-27 00:09:33 +08:00
|
|
|
|
2010-08-27 20:58:43 +08:00
|
|
|
gimp_cairo_add_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);
|
|
|
|
|
2013-04-18 20:21:20 +08:00
|
|
|
gimp_canvas_set_selection_in_style (shell->canvas, cr, index);
|
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)
|
|
|
|
{
|
|
|
|
GdkWindow *window;
|
|
|
|
cairo_pattern_t *bg_pattern;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
g_return_if_fail (cr != NULL);
|
|
|
|
|
|
|
|
window = gtk_widget_get_window (shell->canvas);
|
|
|
|
bg_pattern = gdk_window_get_background_pattern (window);
|
|
|
|
|
|
|
|
cairo_set_source (cr, bg_pattern);
|
|
|
|
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
|
|
|
{
|
2010-09-29 04:04:07 +08:00
|
|
|
gint x2, y2;
|
|
|
|
gint i, j;
|
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
|
|
|
x2 = x + w;
|
|
|
|
y2 = y + h;
|
2008-11-14 07:16:11 +08:00
|
|
|
|
2010-05-02 19:08:11 +08:00
|
|
|
/* display the image in RENDER_BUF_WIDTH x RENDER_BUF_HEIGHT
|
|
|
|
* sized chunks
|
2004-02-07 09:41:30 +08:00
|
|
|
*/
|
2010-05-02 19:08:11 +08:00
|
|
|
for (i = y; i < y2; i += GIMP_DISPLAY_RENDER_BUF_HEIGHT)
|
2004-02-07 09:41:30 +08:00
|
|
|
{
|
2010-05-02 19:08:11 +08:00
|
|
|
for (j = x; j < x2; j += GIMP_DISPLAY_RENDER_BUF_WIDTH)
|
2004-10-01 17:50:04 +08:00
|
|
|
{
|
2010-05-02 19:08:11 +08:00
|
|
|
gint dx, dy;
|
2004-10-01 17:50:04 +08:00
|
|
|
|
2010-05-02 19:08:11 +08:00
|
|
|
dx = MIN (x2 - j, GIMP_DISPLAY_RENDER_BUF_WIDTH);
|
|
|
|
dy = MIN (y2 - i, GIMP_DISPLAY_RENDER_BUF_HEIGHT);
|
2004-02-07 09:41:30 +08:00
|
|
|
|
2012-06-21 03:44:09 +08:00
|
|
|
gimp_display_shell_render (shell, cr, j, i, dx, dy);
|
2001-11-01 05:20:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-29 03:10:03 +08:00
|
|
|
|
|
|
|
static cairo_pattern_t *
|
|
|
|
gimp_display_shell_create_checkerboard (GimpDisplayShell *shell,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
return gimp_cairo_checkerboard_create (cr,
|
|
|
|
1 << (check_size + 2), &light, &dark);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_display_shell_draw_checkerboard (GimpDisplayShell *shell,
|
|
|
|
cairo_t *cr,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
g_return_if_fail (cr != NULL);
|
|
|
|
|
|
|
|
if (G_UNLIKELY (! shell->checkerboard))
|
|
|
|
shell->checkerboard = gimp_display_shell_create_checkerboard (shell, cr);
|
|
|
|
|
|
|
|
cairo_rectangle (cr, x, y, w, h);
|
|
|
|
cairo_clip (cr);
|
2010-09-29 04:04:07 +08:00
|
|
|
|
2010-09-29 03:10:03 +08:00
|
|
|
cairo_translate (cr, - shell->offset_x, - shell->offset_y);
|
|
|
|
cairo_set_source (cr, shell->checkerboard);
|
|
|
|
cairo_paint (cr);
|
|
|
|
}
|