[gimp] app: add gimp_cairo_add_segments()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: add gimp_cairo_add_segments()
- Date: Fri, 27 Aug 2010 13:03:49 +0000 (UTC)
commit f260cd766eef3b5318a13614ecc9f75f4f88faf8
Author: Michael Natterer <mitch gimp org>
Date: Fri Aug 27 14:58:43 2010 +0200
app: add gimp_cairo_add_segments()
which adds an array of GdkSegments to the current path, and use it in
gimpdisplayshell-draw.c instead of duplicating the code three times.
app/display/gimpdisplayshell-draw.c | 52 +++--------------------------------
app/widgets/gimpcairo.c | 25 +++++++++++++++++
app/widgets/gimpcairo.h | 4 +++
3 files changed, 33 insertions(+), 48 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-draw.c b/app/display/gimpdisplayshell-draw.c
index 6dd32aa..ee5240e 100644
--- a/app/display/gimpdisplayshell-draw.c
+++ b/app/display/gimpdisplayshell-draw.c
@@ -43,6 +43,7 @@
#include "vectors/gimpstroke.h"
#include "vectors/gimpvectors.h"
+#include "widgets/gimpcairo.h"
#include "widgets/gimpwidgets-utils.h"
#include "gimpcanvas.h"
@@ -540,8 +541,6 @@ gimp_display_shell_draw_layer_boundary (GimpDisplayShell *shell,
GdkSegment *segs,
gint n_segs)
{
- gint i;
-
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (cr != NULL);
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
@@ -549,20 +548,7 @@ gimp_display_shell_draw_layer_boundary (GimpDisplayShell *shell,
gimp_display_shell_set_layer_style (shell, cr, drawable);
- for (i = 0; i < n_segs; i++)
- {
- if (segs[i].x1 == segs[i].x2)
- {
- cairo_move_to (cr, segs[i].x1 + 0.5, segs[i].y1);
- cairo_line_to (cr, segs[i].x2 + 0.5, segs[i].y2);
- }
- else
- {
- cairo_move_to (cr, segs[i].x1, segs[i].y1 + 0.5);
- cairo_line_to (cr, segs[i].x2, segs[i].y2 + 0.5);
- }
- }
-
+ gimp_cairo_add_segments (cr, segs, n_segs);
cairo_stroke (cr);
}
@@ -572,28 +558,13 @@ gimp_display_shell_draw_selection_out (GimpDisplayShell *shell,
GdkSegment *segs,
gint n_segs)
{
- gint i;
-
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (cr != NULL);
g_return_if_fail (segs != NULL && n_segs > 0);
gimp_display_shell_set_selection_out_style (shell, cr);
- for (i = 0; i < n_segs; i++)
- {
- if (segs[i].x1 == segs[i].x2)
- {
- cairo_move_to (cr, segs[i].x1 + 0.5, segs[i].y1);
- cairo_line_to (cr, segs[i].x2 + 0.5, segs[i].y2);
- }
- else
- {
- cairo_move_to (cr, segs[i].x1, segs[i].y1 + 0.5);
- cairo_line_to (cr, segs[i].x2, segs[i].y2 + 0.5);
- }
- }
-
+ gimp_cairo_add_segments (cr, segs, n_segs);
cairo_stroke (cr);
}
@@ -603,28 +574,13 @@ gimp_display_shell_draw_selection_segments (GimpDisplayShell *shell,
GdkSegment *segs,
gint n_segs)
{
- gint i;
-
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (cr != NULL);
g_return_if_fail (segs != NULL && n_segs > 0);
cairo_set_line_width (cr, 1.0);
- for (i = 0; i < n_segs; i++)
- {
- if (segs[i].x1 == segs[i].x2)
- {
- cairo_move_to (cr, segs[i].x1 + 0.5, segs[i].y1);
- cairo_line_to (cr, segs[i].x2 + 0.5, segs[i].y2);
- }
- else
- {
- cairo_move_to (cr, segs[i].x1, segs[i].y1 + 0.5);
- cairo_line_to (cr, segs[i].x2, segs[i].y2 + 0.5);
- }
- }
-
+ gimp_cairo_add_segments (cr, segs, n_segs);
cairo_stroke (cr);
}
diff --git a/app/widgets/gimpcairo.c b/app/widgets/gimpcairo.c
index e84bc6e..084b976 100644
--- a/app/widgets/gimpcairo.c
+++ b/app/widgets/gimpcairo.c
@@ -84,3 +84,28 @@ gimp_cairo_stipple_pattern_create (const GimpRGB *fg,
return pattern;
}
+
+void
+gimp_cairo_add_segments (cairo_t *cr,
+ GdkSegment *segs,
+ gint n_segs)
+{
+ gint i;
+
+ g_return_if_fail (cr != NULL);
+ g_return_if_fail (segs != NULL && n_segs > 0);
+
+ for (i = 0; i < n_segs; i++)
+ {
+ if (segs[i].x1 == segs[i].x2)
+ {
+ cairo_move_to (cr, segs[i].x1 + 0.5, segs[i].y1);
+ cairo_line_to (cr, segs[i].x2 + 0.5, segs[i].y2);
+ }
+ else
+ {
+ cairo_move_to (cr, segs[i].x1, segs[i].y1 + 0.5);
+ cairo_line_to (cr, segs[i].x2, segs[i].y2 + 0.5);
+ }
+ }
+}
diff --git a/app/widgets/gimpcairo.h b/app/widgets/gimpcairo.h
index 9e04305..15d907d 100644
--- a/app/widgets/gimpcairo.h
+++ b/app/widgets/gimpcairo.h
@@ -29,5 +29,9 @@ cairo_pattern_t * gimp_cairo_stipple_pattern_create (const GimpRGB *fg,
const GimpRGB *bg,
gint index);
+void gimp_cairo_add_segments (cairo_t *cr,
+ GdkSegment *segs,
+ gint n_segs);
+
#endif /* __GIMP_CAIRO_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]