mirror of https://github.com/GNOME/gimp.git
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.
This commit is contained in:
parent
6411f5e327
commit
3a1ba90507
|
@ -533,41 +533,6 @@ gimp_canvas_new (GimpDisplayConfig *config)
|
|||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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...
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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__ */
|
||||
|
|
Loading…
Reference in New Issue