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
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (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
|
|
|
|
* along with this program; if not, write to the Free Software
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
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"
|
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2006-08-29 22:46:32 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2007-03-09 21:00:01 +08:00
|
|
|
#include "libgimpmath/gimpmath.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
|
|
|
|
2007-06-07 05:40:31 +08:00
|
|
|
#include "base/tile-manager.h"
|
|
|
|
|
2005-08-06 19:18:26 +08:00
|
|
|
#include "core/gimpcontext.h"
|
2003-06-24 03:34:48 +08:00
|
|
|
#include "core/gimpgrid.h"
|
2006-06-07 06:48:57 +08:00
|
|
|
#include "core/gimpguide.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
2007-12-26 01:09:04 +08:00
|
|
|
#include "core/gimpimage-guides.h"
|
|
|
|
#include "core/gimpimage-sample-points.h"
|
2003-09-12 06:24:30 +08:00
|
|
|
#include "core/gimplist.h"
|
2007-06-06 21:45:44 +08:00
|
|
|
#include "core/gimpprojection.h"
|
2007-01-30 18:34:59 +08:00
|
|
|
#include "core/gimpsamplepoint.h"
|
2002-04-15 01:28:58 +08:00
|
|
|
|
2003-09-12 06:24:30 +08:00
|
|
|
#include "vectors/gimpstroke.h"
|
2004-02-07 08:16:52 +08:00
|
|
|
#include "vectors/gimpvectors.h"
|
2003-05-18 22:47:07 +08:00
|
|
|
|
2003-05-29 19:34:30 +08:00
|
|
|
#include "widgets/gimpwidgets-utils.h"
|
2001-05-09 03:29:15 +08:00
|
|
|
|
2003-11-10 07:24:40 +08:00
|
|
|
#include "gimpcanvas.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "gimpdisplay.h"
|
|
|
|
#include "gimpdisplayshell.h"
|
2003-03-20 19:31:33 +08:00
|
|
|
#include "gimpdisplayshell-appearance.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"
|
2008-07-12 05:26:14 +08:00
|
|
|
#include "gimpdisplayshell-scroll.h"
|
2003-01-04 02:01:30 +08:00
|
|
|
#include "gimpdisplayshell-transform.h"
|
2002-05-08 00:23:14 +08:00
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
|
|
|
|
/* local function prototypes */
|
2000-02-09 07:45:20 +08:00
|
|
|
|
2004-04-04 23:53:21 +08:00
|
|
|
static GdkGC * gimp_display_shell_get_grid_gc (GimpDisplayShell *shell,
|
|
|
|
GimpGrid *grid);
|
2005-08-06 19:18:26 +08:00
|
|
|
static GdkGC * gimp_display_shell_get_pen_gc (GimpDisplayShell *shell,
|
|
|
|
GimpContext *context,
|
2005-08-06 19:23:58 +08:00
|
|
|
GimpActiveColor active);
|
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
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
void
|
2008-08-10 18:09:03 +08:00
|
|
|
gimp_display_shell_draw_guide (const GimpDisplayShell *shell,
|
|
|
|
GimpGuide *guide,
|
|
|
|
gboolean active)
|
2001-11-01 05:20:09 +08:00
|
|
|
{
|
2006-06-07 23:49:59 +08:00
|
|
|
gint position;
|
2008-08-05 18:11:07 +08:00
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
gint x, y;
|
2001-11-01 05:20:09 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
2006-06-07 23:49:59 +08:00
|
|
|
g_return_if_fail (GIMP_IS_GUIDE (guide));
|
2001-11-01 05:20:09 +08:00
|
|
|
|
2006-06-07 23:49:59 +08:00
|
|
|
position = gimp_guide_get_position (guide);
|
|
|
|
|
|
|
|
if (position < 0)
|
2001-11-01 05:20:09 +08:00
|
|
|
return;
|
|
|
|
|
2008-08-05 18:11:07 +08:00
|
|
|
x1 = 0;
|
|
|
|
y1 = 0;
|
2003-11-11 03:35:56 +08:00
|
|
|
|
2008-08-05 18:11:07 +08:00
|
|
|
gdk_drawable_get_size (shell->canvas->window, &x2, &y2);
|
2001-11-01 05:20:09 +08:00
|
|
|
|
2006-06-07 23:49:59 +08:00
|
|
|
switch (gimp_guide_get_orientation (guide))
|
2001-11-01 05:20:09 +08:00
|
|
|
{
|
2003-11-11 03:35:56 +08:00
|
|
|
case GIMP_ORIENTATION_HORIZONTAL:
|
2006-06-07 23:49:59 +08:00
|
|
|
gimp_display_shell_transform_xy (shell, 0, position, &x, &y, FALSE);
|
2003-11-11 03:35:56 +08:00
|
|
|
y1 = y2 = y;
|
|
|
|
break;
|
2003-11-10 09:10:46 +08:00
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
case GIMP_ORIENTATION_VERTICAL:
|
2006-06-07 23:49:59 +08:00
|
|
|
gimp_display_shell_transform_xy (shell, position, 0, &x, &y, FALSE);
|
2003-11-11 03:35:56 +08:00
|
|
|
x1 = x2 = x;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ORIENTATION_UNKNOWN:
|
|
|
|
return;
|
2001-11-01 05:20:09 +08:00
|
|
|
}
|
2003-11-11 03:35:56 +08:00
|
|
|
|
2003-11-11 22:50:07 +08:00
|
|
|
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas),
|
|
|
|
(active ?
|
|
|
|
GIMP_CANVAS_STYLE_GUIDE_ACTIVE :
|
|
|
|
GIMP_CANVAS_STYLE_GUIDE_NORMAL), x1, y1, x2, y2);
|
2001-11-01 05:20:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-08-10 18:09:03 +08:00
|
|
|
gimp_display_shell_draw_guides (const GimpDisplayShell *shell)
|
2001-11-01 05:20:09 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
2008-03-19 05:22:21 +08:00
|
|
|
if (shell->display->image &&
|
|
|
|
gimp_display_shell_get_show_guides (shell))
|
2001-11-01 05:20:09 +08:00
|
|
|
{
|
2003-09-06 02:22:03 +08:00
|
|
|
GList *list;
|
2001-11-01 05:20:09 +08:00
|
|
|
|
2007-12-26 01:09:04 +08:00
|
|
|
for (list = gimp_image_get_guides (shell->display->image);
|
2004-02-07 08:16:52 +08:00
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
2008-08-05 18:11:07 +08:00
|
|
|
gimp_display_shell_draw_guide (shell, list->data, FALSE);
|
2006-04-12 20:49:29 +08:00
|
|
|
}
|
2001-11-01 05:20:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-24 03:34:48 +08:00
|
|
|
void
|
2004-04-05 01:17:40 +08:00
|
|
|
gimp_display_shell_draw_grid (GimpDisplayShell *shell,
|
|
|
|
const GdkRectangle *area)
|
2003-06-24 03:34:48 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
2004-04-05 01:17:40 +08:00
|
|
|
g_return_if_fail (area != NULL);
|
2003-06-24 03:34:48 +08:00
|
|
|
|
2008-03-19 05:22:21 +08:00
|
|
|
if (shell->display->image &&
|
|
|
|
gimp_display_shell_get_show_grid (shell))
|
2003-06-24 03:34:48 +08:00
|
|
|
{
|
2003-11-10 09:10:46 +08:00
|
|
|
GimpGrid *grid;
|
2003-11-11 03:35:56 +08:00
|
|
|
GimpCanvas *canvas;
|
2004-04-04 23:53:21 +08:00
|
|
|
gdouble x, y;
|
2004-04-05 01:17:40 +08:00
|
|
|
gint x0, x1, x2, x3;
|
|
|
|
gint y0, y1, y2, y3;
|
2003-11-10 09:10:46 +08:00
|
|
|
gint x_real, y_real;
|
2007-12-08 05:59:51 +08:00
|
|
|
gdouble x_offset, y_offset;
|
2003-11-10 09:10:46 +08:00
|
|
|
gint width, height;
|
2004-09-08 03:08:55 +08:00
|
|
|
|
|
|
|
#define CROSSHAIR 2
|
2003-06-24 03:34:48 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
grid = GIMP_GRID (shell->display->image->grid);
|
2004-04-05 01:17:40 +08:00
|
|
|
if (! grid)
|
2003-11-10 09:10:46 +08:00
|
|
|
return;
|
2003-06-24 03:34:48 +08:00
|
|
|
|
2004-05-27 22:51:44 +08:00
|
|
|
g_return_if_fail (grid->xspacing > 0 && grid->yspacing > 0);
|
|
|
|
|
2004-04-05 01:17:40 +08:00
|
|
|
x1 = area->x;
|
|
|
|
y1 = area->y;
|
|
|
|
x2 = area->x + area->width;
|
|
|
|
y2 = area->y + area->height;
|
2003-06-24 03:34:48 +08:00
|
|
|
|
2007-12-26 00:21:40 +08:00
|
|
|
width = gimp_image_get_width (shell->display->image);
|
|
|
|
height = gimp_image_get_height (shell->display->image);
|
2003-09-06 02:22:03 +08:00
|
|
|
|
2004-05-27 22:51:44 +08:00
|
|
|
x_offset = grid->xoffset;
|
|
|
|
while (x_offset > 0)
|
|
|
|
x_offset -= grid->xspacing;
|
|
|
|
|
|
|
|
y_offset = grid->yoffset;
|
|
|
|
while (y_offset > 0)
|
|
|
|
y_offset -= grid->yspacing;
|
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
canvas = GIMP_CANVAS (shell->canvas);
|
|
|
|
|
2004-04-04 23:53:21 +08:00
|
|
|
gimp_canvas_set_custom_gc (canvas,
|
|
|
|
gimp_display_shell_get_grid_gc (shell, grid));
|
2003-11-11 03:35:56 +08:00
|
|
|
|
2003-10-10 22:11:47 +08:00
|
|
|
switch (grid->style)
|
2003-06-24 03:34:48 +08:00
|
|
|
{
|
2003-09-21 18:45:19 +08:00
|
|
|
case GIMP_GRID_DOTS:
|
2004-05-27 22:51:44 +08:00
|
|
|
for (x = x_offset; x <= width; x += grid->xspacing)
|
2003-07-29 05:26:11 +08:00
|
|
|
{
|
2004-05-27 22:51:44 +08:00
|
|
|
if (x < 0)
|
|
|
|
continue;
|
|
|
|
|
2004-04-05 01:17:40 +08:00
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
x, 0, &x_real, &y_real,
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
if (x_real < x1 || x_real >= x2)
|
|
|
|
continue;
|
|
|
|
|
2004-05-27 22:51:44 +08:00
|
|
|
for (y = y_offset; y <= height; y += grid->yspacing)
|
2003-07-29 05:26:11 +08:00
|
|
|
{
|
2004-05-27 22:51:44 +08:00
|
|
|
if (y < 0)
|
|
|
|
continue;
|
|
|
|
|
2003-09-06 02:22:03 +08:00
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
x, y, &x_real, &y_real,
|
|
|
|
FALSE);
|
|
|
|
|
2004-04-05 01:17:40 +08:00
|
|
|
if (y_real >= y1 && y_real < y2)
|
|
|
|
gimp_canvas_draw_point (GIMP_CANVAS (shell->canvas),
|
|
|
|
GIMP_CANVAS_STYLE_CUSTOM,
|
|
|
|
x_real, y_real);
|
2003-07-29 05:26:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-09-21 18:45:19 +08:00
|
|
|
case GIMP_GRID_INTERSECTIONS:
|
2004-05-27 22:51:44 +08:00
|
|
|
for (x = x_offset; x <= width; x += grid->xspacing)
|
2003-06-24 03:34:48 +08:00
|
|
|
{
|
2004-05-27 22:51:44 +08:00
|
|
|
if (x < 0)
|
|
|
|
continue;
|
|
|
|
|
2004-04-05 01:17:40 +08:00
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
x, 0, &x_real, &y_real,
|
|
|
|
FALSE);
|
|
|
|
|
2004-09-08 03:08:55 +08:00
|
|
|
if (x_real + CROSSHAIR < x1 || x_real - CROSSHAIR >= x2)
|
2004-04-05 01:17:40 +08:00
|
|
|
continue;
|
|
|
|
|
2004-05-27 22:51:44 +08:00
|
|
|
for (y = y_offset; y <= height; y += grid->yspacing)
|
2003-06-24 03:34:48 +08:00
|
|
|
{
|
2004-05-27 22:51:44 +08:00
|
|
|
if (y < 0)
|
|
|
|
continue;
|
|
|
|
|
2003-09-06 02:22:03 +08:00
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
x, y, &x_real, &y_real,
|
|
|
|
FALSE);
|
|
|
|
|
2004-09-08 03:08:55 +08:00
|
|
|
if (y_real + CROSSHAIR < y1 || y_real - CROSSHAIR >= y2)
|
2004-04-05 01:17:40 +08:00
|
|
|
continue;
|
|
|
|
|
2003-06-24 03:34:48 +08:00
|
|
|
if (x_real >= x1 && x_real < x2)
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_CUSTOM,
|
|
|
|
x_real,
|
2004-09-08 03:08:55 +08:00
|
|
|
CLAMP (y_real - CROSSHAIR,
|
|
|
|
y1, y2 - 1),
|
2003-11-11 03:35:56 +08:00
|
|
|
x_real,
|
2004-09-08 03:08:55 +08:00
|
|
|
CLAMP (y_real + CROSSHAIR,
|
|
|
|
y1, y2 - 1));
|
2003-06-24 03:34:48 +08:00
|
|
|
if (y_real >= y1 && y_real < y2)
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_CUSTOM,
|
2004-09-08 03:08:55 +08:00
|
|
|
CLAMP (x_real - CROSSHAIR,
|
|
|
|
x1, x2 - 1),
|
2003-11-11 03:35:56 +08:00
|
|
|
y_real,
|
2004-09-08 03:08:55 +08:00
|
|
|
CLAMP (x_real + CROSSHAIR,
|
|
|
|
x1, x2 - 1),
|
2003-11-11 03:35:56 +08:00
|
|
|
y_real);
|
2003-06-24 03:34:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-09-21 18:45:19 +08:00
|
|
|
case GIMP_GRID_ON_OFF_DASH:
|
|
|
|
case GIMP_GRID_DOUBLE_DASH:
|
|
|
|
case GIMP_GRID_SOLID:
|
2004-04-05 01:17:40 +08:00
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
0, 0, &x0, &y0,
|
|
|
|
FALSE);
|
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
width, height, &x3, &y3,
|
|
|
|
FALSE);
|
|
|
|
|
2004-05-27 22:51:44 +08:00
|
|
|
for (x = x_offset; x < width; x += grid->xspacing)
|
2003-06-24 03:34:48 +08:00
|
|
|
{
|
2004-05-27 22:51:44 +08:00
|
|
|
if (x < 0)
|
|
|
|
continue;
|
|
|
|
|
2003-09-06 02:22:03 +08:00
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
x, 0, &x_real, &y_real,
|
|
|
|
FALSE);
|
|
|
|
|
2004-04-05 01:17:40 +08:00
|
|
|
if (x_real >= x1 && x_real < x2)
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_CUSTOM,
|
2004-04-05 01:17:40 +08:00
|
|
|
x_real, y0, x_real, y3 - 1);
|
2003-06-24 03:34:48 +08:00
|
|
|
}
|
|
|
|
|
2004-05-27 22:51:44 +08:00
|
|
|
for (y = y_offset; y < height; y += grid->yspacing)
|
2003-06-24 03:34:48 +08:00
|
|
|
{
|
2004-05-27 22:51:44 +08:00
|
|
|
if (y < 0)
|
|
|
|
continue;
|
|
|
|
|
2003-09-06 02:22:03 +08:00
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
0, y, &x_real, &y_real,
|
|
|
|
FALSE);
|
|
|
|
|
2004-04-05 01:17:40 +08:00
|
|
|
if (y_real >= y1 && y_real < y2)
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_line (canvas, GIMP_CANVAS_STYLE_CUSTOM,
|
2004-04-05 01:17:40 +08:00
|
|
|
x0, y_real, x3 - 1, y_real);
|
2003-06-24 03:34:48 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2003-09-06 02:22:03 +08:00
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_set_custom_gc (canvas, NULL);
|
2003-06-24 03:34:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-06 19:18:26 +08:00
|
|
|
void
|
|
|
|
gimp_display_shell_draw_pen (GimpDisplayShell *shell,
|
|
|
|
const GimpVector2 *points,
|
|
|
|
gint num_points,
|
|
|
|
GimpContext *context,
|
|
|
|
GimpActiveColor color,
|
|
|
|
gint width)
|
|
|
|
{
|
2005-08-06 19:23:58 +08:00
|
|
|
GimpCanvas *canvas;
|
|
|
|
GdkGC *gc;
|
|
|
|
GdkGCValues values;
|
|
|
|
GdkPoint *coords;
|
2005-08-06 19:18:26 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
g_return_if_fail (GIMP_IS_CONTEXT (context));
|
|
|
|
g_return_if_fail (num_points == 0 || points != NULL);
|
|
|
|
|
|
|
|
canvas = GIMP_CANVAS (shell->canvas);
|
|
|
|
|
2005-08-06 21:50:02 +08:00
|
|
|
coords = g_new (GdkPoint, MAX (2, num_points));
|
2005-08-06 19:18:26 +08:00
|
|
|
|
2006-08-09 21:40:21 +08:00
|
|
|
gimp_display_shell_transform_points (shell,
|
2008-02-27 01:30:33 +08:00
|
|
|
points, coords, num_points, FALSE);
|
2005-08-06 19:18:26 +08:00
|
|
|
|
2005-08-06 21:50:02 +08:00
|
|
|
if (num_points == 1)
|
|
|
|
{
|
|
|
|
coords[1] = coords[0];
|
|
|
|
num_points = 2;
|
|
|
|
}
|
|
|
|
|
2005-08-06 19:23:58 +08:00
|
|
|
gc = gimp_display_shell_get_pen_gc (shell, context, color);
|
|
|
|
|
|
|
|
values.line_width = MAX (1, width);
|
|
|
|
gdk_gc_set_values (gc, &values, GDK_GC_LINE_WIDTH);
|
2005-08-06 19:18:26 +08:00
|
|
|
|
|
|
|
gimp_canvas_set_custom_gc (canvas, gc);
|
2005-08-06 21:50:02 +08:00
|
|
|
|
2005-08-06 19:18:26 +08:00
|
|
|
gimp_canvas_draw_lines (canvas, GIMP_CANVAS_STYLE_CUSTOM, coords, num_points);
|
2005-08-06 21:50:02 +08:00
|
|
|
|
2005-08-06 19:18:26 +08:00
|
|
|
gimp_canvas_set_custom_gc (canvas, NULL);
|
|
|
|
|
|
|
|
g_free (coords);
|
|
|
|
}
|
|
|
|
|
2005-03-05 08:10:40 +08:00
|
|
|
void
|
2008-08-10 18:09:03 +08:00
|
|
|
gimp_display_shell_draw_sample_point (const GimpDisplayShell *shell,
|
|
|
|
GimpSamplePoint *sample_point,
|
|
|
|
gboolean active)
|
2005-03-05 08:10:40 +08:00
|
|
|
{
|
2005-03-09 08:23:19 +08:00
|
|
|
GimpCanvasStyle style;
|
2005-03-20 06:04:31 +08:00
|
|
|
gdouble x, y;
|
2005-03-09 08:23:19 +08:00
|
|
|
gint x1, x2;
|
|
|
|
gint y1, y2;
|
|
|
|
gint w, h;
|
2005-03-05 08:10:40 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
g_return_if_fail (sample_point != NULL);
|
|
|
|
|
|
|
|
if (sample_point->x < 0)
|
|
|
|
return;
|
|
|
|
|
2005-03-20 06:04:31 +08:00
|
|
|
gimp_display_shell_transform_xy_f (shell,
|
|
|
|
sample_point->x + 0.5,
|
|
|
|
sample_point->y + 0.5,
|
|
|
|
&x, &y, FALSE);
|
2005-03-05 08:10:40 +08:00
|
|
|
|
2005-03-20 06:04:31 +08:00
|
|
|
x1 = floor (x - GIMP_SAMPLE_POINT_DRAW_SIZE);
|
|
|
|
x2 = ceil (x + GIMP_SAMPLE_POINT_DRAW_SIZE);
|
|
|
|
y1 = floor (y - GIMP_SAMPLE_POINT_DRAW_SIZE);
|
|
|
|
y2 = ceil (y + GIMP_SAMPLE_POINT_DRAW_SIZE);
|
2005-03-05 08:10:40 +08:00
|
|
|
|
|
|
|
gdk_drawable_get_size (shell->canvas->window, &w, &h);
|
|
|
|
|
2005-03-20 06:04:31 +08:00
|
|
|
if (x < - GIMP_SAMPLE_POINT_DRAW_SIZE ||
|
|
|
|
y < - GIMP_SAMPLE_POINT_DRAW_SIZE ||
|
|
|
|
x > w + GIMP_SAMPLE_POINT_DRAW_SIZE ||
|
|
|
|
y > h + GIMP_SAMPLE_POINT_DRAW_SIZE)
|
2005-03-05 08:10:40 +08:00
|
|
|
return;
|
|
|
|
|
2005-03-09 08:23:19 +08:00
|
|
|
if (active)
|
|
|
|
style = GIMP_CANVAS_STYLE_SAMPLE_POINT_ACTIVE;
|
|
|
|
else
|
|
|
|
style = GIMP_CANVAS_STYLE_SAMPLE_POINT_NORMAL;
|
|
|
|
|
|
|
|
#define HALF_SIZE (GIMP_SAMPLE_POINT_DRAW_SIZE / 2)
|
|
|
|
|
|
|
|
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), style,
|
|
|
|
x, y1, x, y1 + HALF_SIZE);
|
|
|
|
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), style,
|
|
|
|
x, y2 - HALF_SIZE, x, y2);
|
|
|
|
|
|
|
|
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), style,
|
|
|
|
x1, y, x1 + HALF_SIZE, y);
|
|
|
|
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), style,
|
|
|
|
x2 - HALF_SIZE, y, x2, y);
|
|
|
|
|
|
|
|
gimp_canvas_draw_arc (GIMP_CANVAS (shell->canvas), style,
|
|
|
|
FALSE,
|
|
|
|
x - HALF_SIZE, y - HALF_SIZE,
|
|
|
|
GIMP_SAMPLE_POINT_DRAW_SIZE,
|
|
|
|
GIMP_SAMPLE_POINT_DRAW_SIZE,
|
|
|
|
0, 64 * 270);
|
|
|
|
|
|
|
|
gimp_canvas_draw_text (GIMP_CANVAS (shell->canvas), style,
|
|
|
|
x + 2, y + 2,
|
|
|
|
"%d",
|
2007-12-26 01:09:04 +08:00
|
|
|
g_list_index (gimp_image_get_sample_points (shell->display->image),
|
2005-03-09 08:23:19 +08:00
|
|
|
sample_point) + 1);
|
2005-03-05 08:10:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-08-10 18:09:03 +08:00
|
|
|
gimp_display_shell_draw_sample_points (const GimpDisplayShell *shell)
|
2005-03-05 08:10:40 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
2008-03-19 05:22:21 +08:00
|
|
|
if (shell->display->image &&
|
|
|
|
gimp_display_shell_get_show_sample_points (shell))
|
2005-03-05 08:10:40 +08:00
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
|
2007-12-26 01:09:04 +08:00
|
|
|
for (list = gimp_image_get_sample_points (shell->display->image);
|
2005-03-05 08:10:40 +08:00
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
gimp_display_shell_draw_sample_point (shell, list->data, FALSE);
|
|
|
|
}
|
2005-03-05 08:10:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-12 06:24:30 +08:00
|
|
|
void
|
2008-08-10 18:09:03 +08:00
|
|
|
gimp_display_shell_draw_vector (const GimpDisplayShell *shell,
|
|
|
|
GimpVectors *vectors)
|
2003-09-12 06:24:30 +08:00
|
|
|
{
|
2003-11-10 09:10:46 +08:00
|
|
|
GimpStroke *stroke = NULL;
|
2003-09-12 06:24:30 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
g_return_if_fail (GIMP_IS_VECTORS (vectors));
|
|
|
|
|
|
|
|
while ((stroke = gimp_vectors_stroke_get_next (vectors, stroke)))
|
|
|
|
{
|
|
|
|
GArray *coords;
|
|
|
|
gboolean closed;
|
|
|
|
|
|
|
|
coords = gimp_stroke_interpolate (stroke, 1.0, &closed);
|
|
|
|
|
2006-08-09 21:40:21 +08:00
|
|
|
if (coords && coords->len > 0)
|
2003-09-12 06:24:30 +08:00
|
|
|
{
|
2006-08-09 21:40:21 +08:00
|
|
|
GdkPoint *gdk_coords = g_new (GdkPoint, coords->len);
|
2003-09-12 06:24:30 +08:00
|
|
|
|
2006-08-09 21:40:21 +08:00
|
|
|
gimp_display_shell_transform_coords (shell,
|
|
|
|
&g_array_index (coords,
|
|
|
|
GimpCoords, 0),
|
|
|
|
gdk_coords,
|
|
|
|
coords->len,
|
2004-03-21 05:59:41 +08:00
|
|
|
FALSE);
|
2003-09-12 06:24:30 +08:00
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
gimp_canvas_draw_lines (GIMP_CANVAS (shell->canvas),
|
|
|
|
GIMP_CANVAS_STYLE_XOR,
|
|
|
|
gdk_coords, coords->len);
|
2003-09-12 06:24:30 +08:00
|
|
|
|
|
|
|
g_free (gdk_coords);
|
|
|
|
}
|
|
|
|
|
2003-09-12 18:04:37 +08:00
|
|
|
if (coords)
|
|
|
|
g_array_free (coords, TRUE);
|
2003-09-12 06:24:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-08-10 18:09:03 +08:00
|
|
|
gimp_display_shell_draw_vectors (const GimpDisplayShell *shell)
|
2003-09-12 06:24:30 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
2008-03-19 05:22:21 +08:00
|
|
|
if (shell->display->image &&
|
|
|
|
TRUE /* gimp_display_shell_get_show_vectors (shell) */)
|
2003-09-12 06:24:30 +08:00
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
for (list = GIMP_LIST (shell->display->image->vectors)->list;
|
2003-09-12 06:24:30 +08:00
|
|
|
list;
|
|
|
|
list = list->next)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
2003-09-12 06:24:30 +08:00
|
|
|
GimpVectors *vectors = list->data;
|
|
|
|
|
|
|
|
if (gimp_item_get_visible (GIMP_ITEM (vectors)))
|
|
|
|
gimp_display_shell_draw_vector (shell, vectors);
|
2006-04-12 20:49:29 +08:00
|
|
|
}
|
2003-09-12 06:24:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-07 08:16:52 +08:00
|
|
|
void
|
2008-08-10 18:09:03 +08:00
|
|
|
gimp_display_shell_draw_cursor (const GimpDisplayShell *shell)
|
2004-02-07 08:16:52 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
|
|
|
if (shell->have_cursor)
|
|
|
|
gimp_canvas_draw_cursor (GIMP_CANVAS (shell->canvas),
|
|
|
|
shell->cursor_x, shell->cursor_y);
|
|
|
|
}
|
|
|
|
|
2003-02-21 20:16:43 +08:00
|
|
|
void
|
2008-08-10 18:09:03 +08:00
|
|
|
gimp_display_shell_draw_area (const GimpDisplayShell *shell,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
2001-11-01 05:20:09 +08:00
|
|
|
{
|
2008-07-13 15:40:11 +08:00
|
|
|
gint sx, sy;
|
|
|
|
gint sw, sh;
|
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));
|
|
|
|
|
|
|
|
if (! shell->display->image)
|
|
|
|
return;
|
|
|
|
|
2008-08-10 17:08:11 +08:00
|
|
|
gimp_display_shell_scroll_get_scaled_viewport_offset (shell, &sx, &sy);
|
2008-07-13 15:40:11 +08:00
|
|
|
gimp_display_shell_get_scaled_image_size (shell, &sw, &sh);
|
2004-02-07 09:41:30 +08:00
|
|
|
|
|
|
|
/* check if the passed in area intersects with
|
|
|
|
* both the display and the image
|
|
|
|
*/
|
|
|
|
if (gimp_rectangle_intersect (x, y, w, h,
|
|
|
|
0, 0, shell->disp_width, shell->disp_height,
|
2006-10-19 16:25:04 +08:00
|
|
|
&x, &y, &w, &h)
|
|
|
|
&&
|
2004-02-07 09:41:30 +08:00
|
|
|
gimp_rectangle_intersect (x, y, w, h,
|
|
|
|
sx, sy, sw, sh,
|
|
|
|
&x, &y, &w, &h))
|
|
|
|
{
|
2004-10-01 17:50:04 +08:00
|
|
|
GdkRectangle rect;
|
|
|
|
gint x2, y2;
|
|
|
|
gint i, j;
|
2001-11-01 05:20:09 +08:00
|
|
|
|
2004-02-07 09:41:30 +08:00
|
|
|
x2 = x + w;
|
|
|
|
y2 = y + h;
|
2001-11-01 05:20:09 +08:00
|
|
|
|
2004-10-01 17:50:04 +08:00
|
|
|
if (shell->highlight)
|
|
|
|
{
|
2007-08-25 00:56:13 +08:00
|
|
|
rect.x = ceil (shell->scale_x * shell->highlight->x);
|
|
|
|
rect.y = ceil (shell->scale_y * shell->highlight->y);
|
|
|
|
rect.width = floor (shell->scale_x * shell->highlight->width);
|
|
|
|
rect.height = floor (shell->scale_y * shell->highlight->height);
|
2004-10-01 17:50:04 +08:00
|
|
|
}
|
|
|
|
|
2004-02-07 09:41:30 +08:00
|
|
|
/* display the image in RENDER_BUF_WIDTH x RENDER_BUF_HEIGHT
|
|
|
|
* sized chunks
|
|
|
|
*/
|
2007-12-29 06:12:17 +08:00
|
|
|
for (i = y; i < y2; i += GIMP_DISPLAY_RENDER_BUF_HEIGHT)
|
2001-11-01 05:20:09 +08:00
|
|
|
{
|
2007-12-29 06:12:17 +08:00
|
|
|
for (j = x; j < x2; j += GIMP_DISPLAY_RENDER_BUF_WIDTH)
|
2004-02-07 09:41:30 +08:00
|
|
|
{
|
2008-07-12 15:00:46 +08:00
|
|
|
gint disp_xoffset, disp_yoffset;
|
2004-02-07 09:41:30 +08:00
|
|
|
gint dx, dy;
|
|
|
|
|
2007-12-29 06:12:17 +08:00
|
|
|
dx = MIN (x2 - j, GIMP_DISPLAY_RENDER_BUF_WIDTH);
|
|
|
|
dy = MIN (y2 - i, GIMP_DISPLAY_RENDER_BUF_HEIGHT);
|
2001-11-01 05:20:09 +08:00
|
|
|
|
2008-08-10 17:08:11 +08:00
|
|
|
gimp_display_shell_scroll_get_disp_offset (shell,
|
|
|
|
&disp_xoffset,
|
|
|
|
&disp_yoffset);
|
2008-07-12 15:00:46 +08:00
|
|
|
|
2004-02-07 09:41:30 +08:00
|
|
|
gimp_display_shell_render (shell,
|
2008-07-12 15:00:46 +08:00
|
|
|
j - disp_xoffset,
|
|
|
|
i - disp_yoffset,
|
2004-10-01 17:50:04 +08:00
|
|
|
dx, dy,
|
|
|
|
shell->highlight ? &rect : NULL);
|
2004-02-07 09:41:30 +08:00
|
|
|
}
|
2001-11-01 05:20:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-21 20:16:43 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
static GdkGC *
|
2004-04-04 23:53:21 +08:00
|
|
|
gimp_display_shell_get_grid_gc (GimpDisplayShell *shell,
|
|
|
|
GimpGrid *grid)
|
2003-11-11 03:35:56 +08:00
|
|
|
{
|
|
|
|
GdkGCValues values;
|
|
|
|
GdkColor fg, bg;
|
|
|
|
|
2004-04-04 23:53:21 +08:00
|
|
|
if (shell->grid_gc)
|
|
|
|
return shell->grid_gc;
|
|
|
|
|
2003-11-11 03:35:56 +08:00
|
|
|
switch (grid->style)
|
|
|
|
{
|
|
|
|
case GIMP_GRID_ON_OFF_DASH:
|
|
|
|
values.line_style = GDK_LINE_ON_OFF_DASH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_GRID_DOUBLE_DASH:
|
|
|
|
values.line_style = GDK_LINE_DOUBLE_DASH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_GRID_DOTS:
|
|
|
|
case GIMP_GRID_INTERSECTIONS:
|
|
|
|
case GIMP_GRID_SOLID:
|
|
|
|
values.line_style = GDK_LINE_SOLID;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
values.join_style = GDK_JOIN_MITER;
|
|
|
|
|
2004-04-04 23:53:21 +08:00
|
|
|
shell->grid_gc = gdk_gc_new_with_values (shell->canvas->window,
|
|
|
|
&values, (GDK_GC_LINE_STYLE |
|
|
|
|
GDK_GC_JOIN_STYLE));
|
2003-11-11 03:35:56 +08:00
|
|
|
|
|
|
|
gimp_rgb_get_gdk_color (&grid->fgcolor, &fg);
|
2004-04-04 23:53:21 +08:00
|
|
|
gdk_gc_set_rgb_fg_color (shell->grid_gc, &fg);
|
2005-08-06 19:18:26 +08:00
|
|
|
|
|
|
|
gimp_rgb_get_gdk_color (&grid->bgcolor, &bg);
|
2004-04-04 23:53:21 +08:00
|
|
|
gdk_gc_set_rgb_bg_color (shell->grid_gc, &bg);
|
2003-11-11 03:35:56 +08:00
|
|
|
|
2004-04-04 23:53:21 +08:00
|
|
|
return shell->grid_gc;
|
2003-11-11 03:35:56 +08:00
|
|
|
}
|
2005-08-06 19:18:26 +08:00
|
|
|
|
|
|
|
static GdkGC *
|
|
|
|
gimp_display_shell_get_pen_gc (GimpDisplayShell *shell,
|
|
|
|
GimpContext *context,
|
2005-08-06 19:23:58 +08:00
|
|
|
GimpActiveColor active)
|
2005-08-06 19:18:26 +08:00
|
|
|
{
|
|
|
|
GdkGCValues values;
|
|
|
|
GimpRGB rgb;
|
|
|
|
GdkColor color;
|
|
|
|
|
|
|
|
if (shell->pen_gc)
|
|
|
|
return shell->pen_gc;
|
|
|
|
|
|
|
|
values.line_style = GDK_LINE_SOLID;
|
|
|
|
values.cap_style = GDK_CAP_ROUND;
|
2005-08-08 08:33:51 +08:00
|
|
|
values.join_style = GDK_JOIN_ROUND;
|
2005-08-06 19:18:26 +08:00
|
|
|
|
|
|
|
shell->pen_gc = gdk_gc_new_with_values (shell->canvas->window,
|
2005-08-06 19:23:58 +08:00
|
|
|
&values, (GDK_GC_LINE_STYLE |
|
2005-08-06 19:18:26 +08:00
|
|
|
GDK_GC_CAP_STYLE |
|
|
|
|
GDK_GC_JOIN_STYLE));
|
|
|
|
|
|
|
|
switch (active)
|
|
|
|
{
|
|
|
|
case GIMP_ACTIVE_COLOR_FOREGROUND:
|
|
|
|
gimp_context_get_foreground (context, &rgb);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ACTIVE_COLOR_BACKGROUND:
|
|
|
|
gimp_context_get_background (context, &rgb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_rgb_get_gdk_color (&rgb, &color);
|
|
|
|
gdk_gc_set_rgb_fg_color (shell->pen_gc, &color);
|
|
|
|
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (shell->pen_gc),
|
2006-06-20 01:50:40 +08:00
|
|
|
(gpointer) &shell->pen_gc);
|
2005-08-06 19:18:26 +08:00
|
|
|
|
|
|
|
g_signal_connect_object (context, "notify",
|
|
|
|
G_CALLBACK (g_object_unref),
|
|
|
|
shell->pen_gc, G_CONNECT_SWAPPED);
|
|
|
|
|
|
|
|
return shell->pen_gc;
|
|
|
|
}
|