[gimp] app: port GimpDisplayShell cursor drawing to cairo
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: port GimpDisplayShell cursor drawing to cairo
- Date: Mon, 23 Aug 2010 18:47:55 +0000 (UTC)
commit 3a1ba90507a6b16b0ad54c190ad3f3b8d9f7d42b
Author: Michael Natterer <mitch gimp org>
Date: Mon Aug 23 20:39:22 2010 +0200
app: port GimpDisplayShell cursor drawing to cairo
Also add code to invalidate the new cursor location in
gimp_display_shell_update_cursor(), which is needed with
the new manual double buffering code.
app/display/gimpcanvas.c | 35 ----------------------------
app/display/gimpcanvas.h | 3 --
app/display/gimpdisplayshell-callbacks.c | 4 ++-
app/display/gimpdisplayshell-cursor.c | 20 ++++++++++++----
app/display/gimpdisplayshell-draw.c | 37 +++++++++++++++++++++++++++--
app/display/gimpdisplayshell-draw.h | 3 +-
app/display/gimpdisplayshell-style.c | 12 +++++++++
app/display/gimpdisplayshell-style.h | 2 +
8 files changed, 68 insertions(+), 48 deletions(-)
---
diff --git a/app/display/gimpcanvas.c b/app/display/gimpcanvas.c
index 500395d..d252dd0 100644
--- a/app/display/gimpcanvas.c
+++ b/app/display/gimpcanvas.c
@@ -534,41 +534,6 @@ gimp_canvas_new (GimpDisplayConfig *config)
}
/**
- * gimp_canvas_draw_cursor:
- * @canvas: the #GimpCanvas widget to draw on.
- * @x: x coordinate
- * @y: y coordinate
- *
- * Draws a plus-shaped black and white cursor, centered at the point
- * @x, @y.
- **/
-void
-gimp_canvas_draw_cursor (GimpCanvas *canvas,
- gint x,
- gint y)
-{
- GtkWidget *widget = GTK_WIDGET (canvas);
- GdkWindow *window = gtk_widget_get_window (widget);
-
- if (! (gimp_canvas_ensure_style (canvas, GIMP_CANVAS_STYLE_BLACK) &&
- gimp_canvas_ensure_style (canvas, GIMP_CANVAS_STYLE_WHITE)) )
- return;
-
- gdk_draw_line (window, canvas->gc[GIMP_CANVAS_STYLE_WHITE],
- x - 7, y - 1, x + 7, y - 1);
- gdk_draw_line (window, canvas->gc[GIMP_CANVAS_STYLE_BLACK],
- x - 7, y, x + 7, y );
- gdk_draw_line (window, canvas->gc[GIMP_CANVAS_STYLE_WHITE],
- x - 7, y + 1, x + 7, y + 1);
- gdk_draw_line (window, canvas->gc[GIMP_CANVAS_STYLE_WHITE],
- x - 1, y - 7, x - 1, y + 7);
- gdk_draw_line (window, canvas->gc[GIMP_CANVAS_STYLE_BLACK],
- x, y - 7, x, y + 7);
- gdk_draw_line (window, canvas->gc[GIMP_CANVAS_STYLE_WHITE],
- x + 1, y - 7, x + 1, y + 7);
-}
-
-/**
* gimp_canvas_draw_point:
* @canvas: a #GimpCanvas widget
* @style: one of the enumerated #GimpCanvasStyle's.
diff --git a/app/display/gimpcanvas.h b/app/display/gimpcanvas.h
index 81a09c2..e085706 100644
--- a/app/display/gimpcanvas.h
+++ b/app/display/gimpcanvas.h
@@ -86,9 +86,6 @@ GType gimp_canvas_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_canvas_new (GimpDisplayConfig *config);
-void gimp_canvas_draw_cursor (GimpCanvas *canvas,
- gint x,
- gint y);
void gimp_canvas_draw_point (GimpCanvas *canvas,
GimpCanvasStyle style,
gint x,
diff --git a/app/display/gimpdisplayshell-callbacks.c b/app/display/gimpdisplayshell-callbacks.c
index db5e4b6..49e5e75 100644
--- a/app/display/gimpdisplayshell-callbacks.c
+++ b/app/display/gimpdisplayshell-callbacks.c
@@ -2307,7 +2307,9 @@ gimp_display_shell_canvas_expose_image (GimpDisplayShell *shell,
cairo_restore (cr);
/* and the cursor (if we have a software cursor) */
- gimp_display_shell_draw_cursor (shell);
+ cairo_save (cr);
+ gimp_display_shell_draw_cursor (shell, cr);
+ cairo_restore (cr);
/* restart (and recalculate) the selection boundaries */
gimp_display_shell_selection_control (shell, GIMP_SELECTION_ON);
diff --git a/app/display/gimpdisplayshell-cursor.c b/app/display/gimpdisplayshell-cursor.c
index 29be4cd..6acc305 100644
--- a/app/display/gimpdisplayshell-cursor.c
+++ b/app/display/gimpdisplayshell-cursor.c
@@ -141,22 +141,32 @@ gimp_display_shell_update_cursor (GimpDisplayShell *shell,
/* Erase old cursor, if necessary */
+#define CURSOR_SIZE 14
+
if (shell->have_cursor && (! new_cursor ||
display_x != shell->cursor_x ||
display_y != shell->cursor_y))
{
gimp_display_shell_expose_area (shell,
- shell->cursor_x - 7,
- shell->cursor_y - 7,
- 15, 15);
- if (! new_cursor)
- shell->have_cursor = FALSE;
+ shell->cursor_x - CURSOR_SIZE,
+ shell->cursor_y - CURSOR_SIZE,
+ 2 * CURSOR_SIZE + 1,
+ 2 * CURSOR_SIZE + 1);
}
shell->have_cursor = new_cursor;
shell->cursor_x = display_x;
shell->cursor_y = display_y;
+ if (shell->have_cursor)
+ {
+ gimp_display_shell_expose_area (shell,
+ shell->cursor_x - CURSOR_SIZE,
+ shell->cursor_y - CURSOR_SIZE,
+ 2 * CURSOR_SIZE + 1,
+ 2 * CURSOR_SIZE + 1);
+ }
+
/* use the passed image_coords for the statusbar because they are
* possibly snapped...
*/
diff --git a/app/display/gimpdisplayshell-draw.c b/app/display/gimpdisplayshell-draw.c
index a0bc9de..180cff3 100644
--- a/app/display/gimpdisplayshell-draw.c
+++ b/app/display/gimpdisplayshell-draw.c
@@ -605,13 +605,44 @@ gimp_display_shell_draw_vectors (GimpDisplayShell *shell)
}
void
-gimp_display_shell_draw_cursor (GimpDisplayShell *shell)
+gimp_display_shell_draw_cursor (GimpDisplayShell *shell,
+ cairo_t *cr)
{
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
+ g_return_if_fail (cr != NULL);
if (shell->have_cursor)
- gimp_canvas_draw_cursor (GIMP_CANVAS (shell->canvas),
- shell->cursor_x, shell->cursor_y);
+ {
+ gimp_display_shell_set_cursor_style (shell, cr);
+
+#define CURSOR_SIZE 14
+
+ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+
+ cairo_move_to (cr, shell->cursor_x - CURSOR_SIZE, shell->cursor_y - 1);
+ cairo_line_to (cr, shell->cursor_x + CURSOR_SIZE, shell->cursor_y - 1);
+
+ cairo_move_to (cr, shell->cursor_x - CURSOR_SIZE, shell->cursor_y + 1);
+ cairo_line_to (cr, shell->cursor_x + CURSOR_SIZE, shell->cursor_y + 1);
+
+ cairo_move_to (cr, shell->cursor_x - 1, shell->cursor_y - CURSOR_SIZE);
+ cairo_line_to (cr, shell->cursor_x - 1, shell->cursor_y + CURSOR_SIZE);
+
+ cairo_move_to (cr, shell->cursor_x + 1, shell->cursor_y - CURSOR_SIZE);
+ cairo_line_to (cr, shell->cursor_x + 1, shell->cursor_y + CURSOR_SIZE);
+
+ cairo_stroke (cr);
+
+ cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+
+ cairo_move_to (cr, shell->cursor_x - CURSOR_SIZE, shell->cursor_y);
+ cairo_line_to (cr, shell->cursor_x + CURSOR_SIZE, shell->cursor_y);
+
+ cairo_move_to (cr, shell->cursor_x, shell->cursor_y - CURSOR_SIZE);
+ cairo_line_to (cr, shell->cursor_x, shell->cursor_y + CURSOR_SIZE);
+
+ cairo_stroke (cr);
+ }
}
void
diff --git a/app/display/gimpdisplayshell-draw.h b/app/display/gimpdisplayshell-draw.h
index fe11b68..88e5fde 100644
--- a/app/display/gimpdisplayshell-draw.h
+++ b/app/display/gimpdisplayshell-draw.h
@@ -50,7 +50,8 @@ void gimp_display_shell_draw_sample_points (GimpDisplayShell *shell,
void gimp_display_shell_draw_vector (GimpDisplayShell *shell,
GimpVectors *vectors);
void gimp_display_shell_draw_vectors (GimpDisplayShell *shell);
-void gimp_display_shell_draw_cursor (GimpDisplayShell *shell);
+void gimp_display_shell_draw_cursor (GimpDisplayShell *shell,
+ cairo_t *cr);
void gimp_display_shell_draw_area (GimpDisplayShell *shell,
gint x,
gint y,
diff --git a/app/display/gimpdisplayshell-style.c b/app/display/gimpdisplayshell-style.c
index 97e7eb6..25bb49f 100644
--- a/app/display/gimpdisplayshell-style.c
+++ b/app/display/gimpdisplayshell-style.c
@@ -136,6 +136,18 @@ gimp_display_shell_set_grid_style (GimpDisplayShell *shell,
}
}
+void
+gimp_display_shell_set_cursor_style (GimpDisplayShell *shell,
+ cairo_t *cr)
+{
+ g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
+ g_return_if_fail (cr != NULL);
+
+ cairo_set_line_width (cr, 1.0);
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+ cairo_translate (cr, 0.5, 0.5);
+}
+
/* private functions */
diff --git a/app/display/gimpdisplayshell-style.h b/app/display/gimpdisplayshell-style.h
index 55959e9..83bc3c5 100644
--- a/app/display/gimpdisplayshell-style.h
+++ b/app/display/gimpdisplayshell-style.h
@@ -31,6 +31,8 @@ void gimp_display_shell_set_sample_point_style (GimpDisplayShell *shell,
void gimp_display_shell_set_grid_style (GimpDisplayShell *shell,
cairo_t *cr,
GimpGrid *grid);
+void gimp_display_shell_set_cursor_style (GimpDisplayShell *shell,
+ cairo_t *cr);
#endif /* __GIMP_DISPLAY_SHELL_STYLE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]