21
21
#include <gtk/gtk.h>
23
#include "libgimpbase/gimpbase.h"
24
#include "libgimpmath/gimpmath.h"
23
26
#include "display-types.h"
25
#include "core/gimp-utils.h"
28
#include "core/gimpcontext.h"
26
29
#include "core/gimpgrid.h"
30
#include "core/gimpguide.h"
27
31
#include "core/gimpimage.h"
28
#include "core/gimpimage-guides.h"
29
32
#include "core/gimplist.h"
33
#include "core/gimpsamplepoint.h"
31
35
#include "vectors/gimpstroke.h"
32
36
#include "vectors/gimpvectors.h"
38
#include "widgets/gimprender.h"
34
39
#include "widgets/gimpwidgets-utils.h"
36
41
#include "gimpcanvas.h"
63
70
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
64
g_return_if_fail (guide != NULL);
66
if (guide->position < 0)
71
g_return_if_fail (GIMP_IS_GUIDE (guide));
73
position = gimp_guide_get_position (guide);
69
78
gimp_display_shell_transform_xy (shell, 0, 0, &x1, &y1, FALSE);
70
79
gimp_display_shell_transform_xy (shell,
71
shell->gdisp->gimage->width,
72
shell->gdisp->gimage->height,
80
shell->display->image->width,
81
shell->display->image->height,
75
84
gdk_drawable_get_size (shell->canvas->window, &w, &h);
82
switch (guide->orientation)
91
switch (gimp_guide_get_orientation (guide))
84
93
case GIMP_ORIENTATION_HORIZONTAL:
85
gimp_display_shell_transform_xy (shell,
86
0, guide->position, &x, &y, FALSE);
94
gimp_display_shell_transform_xy (shell, 0, position, &x, &y, FALSE);
90
98
case GIMP_ORIENTATION_VERTICAL:
91
gimp_display_shell_transform_xy (shell,
92
guide->position, 0, &x, &y, FALSE);
99
gimp_display_shell_transform_xy (shell, position, 0, &x, &y, FALSE);
302
gimp_display_shell_draw_pen (GimpDisplayShell *shell,
303
const GimpVector2 *points,
305
GimpContext *context,
306
GimpActiveColor color,
314
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
315
g_return_if_fail (GIMP_IS_CONTEXT (context));
316
g_return_if_fail (num_points == 0 || points != NULL);
318
canvas = GIMP_CANVAS (shell->canvas);
320
coords = g_new (GdkPoint, MAX (2, num_points));
322
gimp_display_shell_transform_points (shell,
323
(const gdouble *) points, coords,
328
coords[1] = coords[0];
332
gc = gimp_display_shell_get_pen_gc (shell, context, color);
334
values.line_width = MAX (1, width);
335
gdk_gc_set_values (gc, &values, GDK_GC_LINE_WIDTH);
337
gimp_canvas_set_custom_gc (canvas, gc);
339
gimp_canvas_draw_lines (canvas, GIMP_CANVAS_STYLE_CUSTOM, coords, num_points);
341
gimp_canvas_set_custom_gc (canvas, NULL);
347
gimp_display_shell_draw_sample_point (GimpDisplayShell *shell,
348
GimpSamplePoint *sample_point,
351
GimpCanvasStyle style;
357
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
358
g_return_if_fail (sample_point != NULL);
360
if (sample_point->x < 0)
363
gimp_display_shell_transform_xy_f (shell,
364
sample_point->x + 0.5,
365
sample_point->y + 0.5,
368
x1 = floor (x - GIMP_SAMPLE_POINT_DRAW_SIZE);
369
x2 = ceil (x + GIMP_SAMPLE_POINT_DRAW_SIZE);
370
y1 = floor (y - GIMP_SAMPLE_POINT_DRAW_SIZE);
371
y2 = ceil (y + GIMP_SAMPLE_POINT_DRAW_SIZE);
373
gdk_drawable_get_size (shell->canvas->window, &w, &h);
375
if (x < - GIMP_SAMPLE_POINT_DRAW_SIZE ||
376
y < - GIMP_SAMPLE_POINT_DRAW_SIZE ||
377
x > w + GIMP_SAMPLE_POINT_DRAW_SIZE ||
378
y > h + GIMP_SAMPLE_POINT_DRAW_SIZE)
382
style = GIMP_CANVAS_STYLE_SAMPLE_POINT_ACTIVE;
384
style = GIMP_CANVAS_STYLE_SAMPLE_POINT_NORMAL;
386
#define HALF_SIZE (GIMP_SAMPLE_POINT_DRAW_SIZE / 2)
388
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), style,
389
x, y1, x, y1 + HALF_SIZE);
390
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), style,
391
x, y2 - HALF_SIZE, x, y2);
393
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), style,
394
x1, y, x1 + HALF_SIZE, y);
395
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), style,
396
x2 - HALF_SIZE, y, x2, y);
398
gimp_canvas_draw_arc (GIMP_CANVAS (shell->canvas), style,
400
x - HALF_SIZE, y - HALF_SIZE,
401
GIMP_SAMPLE_POINT_DRAW_SIZE,
402
GIMP_SAMPLE_POINT_DRAW_SIZE,
405
gimp_canvas_draw_text (GIMP_CANVAS (shell->canvas), style,
408
g_list_index (shell->display->image->sample_points,
413
gimp_display_shell_draw_sample_points (GimpDisplayShell *shell)
415
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
417
if (gimp_display_shell_get_show_sample_points (shell))
421
for (list = shell->display->image->sample_points;
423
list = g_list_next (list))
425
gimp_display_shell_draw_sample_point (shell, list->data, FALSE);
295
431
gimp_display_shell_draw_vector (GimpDisplayShell *shell,
296
432
GimpVectors *vectors)
308
444
coords = gimp_stroke_interpolate (stroke, 1.0, &closed);
310
if (coords && coords->len)
446
if (coords && coords->len > 0)
313
GdkPoint *gdk_coords;
317
gdk_coords = g_new (GdkPoint, coords->len);
319
for (i = 0; i < coords->len; i++)
321
coord = &g_array_index (coords, GimpCoords, i);
323
gimp_display_shell_transform_xy (shell,
448
GdkPoint *gdk_coords = g_new (GdkPoint, coords->len);
450
gimp_display_shell_transform_coords (shell,
451
&g_array_index (coords,
327
gdk_coords[i].x = sx;
328
gdk_coords[i].y = sy;
331
457
gimp_canvas_draw_lines (GIMP_CANVAS (shell->canvas),
332
458
GIMP_CANVAS_STYLE_XOR,
384
510
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
386
512
/* the image's size in display coordinates */
387
sx = shell->disp_xoffset > 0 ? shell->disp_xoffset : - shell->offset_x;
388
sy = shell->disp_yoffset > 0 ? shell->disp_yoffset : - shell->offset_y;
389
sw = SCALEX (shell, shell->gdisp->gimage->width);
390
sh = SCALEY (shell, shell->gdisp->gimage->height);
513
sx = shell->disp_xoffset - shell->offset_x;
514
sy = shell->disp_yoffset - shell->offset_y;
515
sw = SCALEX (shell, shell->display->image->width);
516
sh = SCALEY (shell, shell->display->image->height);
392
518
/* check if the passed in area intersects with
393
519
* both the display and the image
395
521
if (gimp_rectangle_intersect (x, y, w, h,
396
522
0, 0, shell->disp_width, shell->disp_height,
398
525
gimp_rectangle_intersect (x, y, w, h,
417
544
/* display the image in RENDER_BUF_WIDTH x RENDER_BUF_HEIGHT
420
for (i = y; i < y2; i += GIMP_DISPLAY_SHELL_RENDER_BUF_HEIGHT)
547
for (i = y; i < y2; i += GIMP_RENDER_BUF_HEIGHT)
422
for (j = x; j < x2; j += GIMP_DISPLAY_SHELL_RENDER_BUF_WIDTH)
549
for (j = x; j < x2; j += GIMP_RENDER_BUF_WIDTH)
426
dx = MIN (x2 - j, GIMP_DISPLAY_SHELL_RENDER_BUF_WIDTH);
427
dy = MIN (y2 - i, GIMP_DISPLAY_SHELL_RENDER_BUF_HEIGHT);
553
dx = MIN (x2 - j, GIMP_RENDER_BUF_WIDTH);
554
dy = MIN (y2 - i, GIMP_RENDER_BUF_HEIGHT);
429
556
gimp_display_shell_render (shell,
430
557
j - shell->disp_xoffset,
482
609
GDK_GC_JOIN_STYLE));
484
611
gimp_rgb_get_gdk_color (&grid->fgcolor, &fg);
612
gdk_gc_set_rgb_fg_color (shell->grid_gc, &fg);
485
614
gimp_rgb_get_gdk_color (&grid->bgcolor, &bg);
487
gdk_gc_set_rgb_fg_color (shell->grid_gc, &fg);
488
615
gdk_gc_set_rgb_bg_color (shell->grid_gc, &bg);
490
617
return shell->grid_gc;
621
gimp_display_shell_get_pen_gc (GimpDisplayShell *shell,
622
GimpContext *context,
623
GimpActiveColor active)
630
return shell->pen_gc;
632
values.line_style = GDK_LINE_SOLID;
633
values.cap_style = GDK_CAP_ROUND;
634
values.join_style = GDK_JOIN_ROUND;
636
shell->pen_gc = gdk_gc_new_with_values (shell->canvas->window,
637
&values, (GDK_GC_LINE_STYLE |
643
case GIMP_ACTIVE_COLOR_FOREGROUND:
644
gimp_context_get_foreground (context, &rgb);
647
case GIMP_ACTIVE_COLOR_BACKGROUND:
648
gimp_context_get_background (context, &rgb);
652
gimp_rgb_get_gdk_color (&rgb, &color);
653
gdk_gc_set_rgb_fg_color (shell->pen_gc, &color);
655
g_object_add_weak_pointer (G_OBJECT (shell->pen_gc),
656
(gpointer) &shell->pen_gc);
658
g_signal_connect_object (context, "notify",
659
G_CALLBACK (g_object_unref),
660
shell->pen_gc, G_CONNECT_SWAPPED);
662
return shell->pen_gc;