mirror of https://github.com/GNOME/gimp.git
app: port GimpVectors drawing to cairo
This is just a rough proof of concept. More changes are about to follow.
This commit is contained in:
parent
81182d93f7
commit
4c57e3f19e
|
@ -268,8 +268,6 @@ gimp_display_shell_canvas_realize (GtkWidget *canvas,
|
|||
|
||||
/* allow shrinking */
|
||||
gtk_widget_set_size_request (GTK_WIDGET (shell), 0, 0);
|
||||
|
||||
gimp_display_shell_draw_vectors (shell);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -2308,6 +2306,11 @@ gimp_display_shell_canvas_expose_image (GimpDisplayShell *shell,
|
|||
gimp_display_shell_preview_transform (shell, cr);
|
||||
cairo_restore (cr);
|
||||
|
||||
/* draw the vectors */
|
||||
cairo_save (cr);
|
||||
gimp_display_shell_draw_vectors (shell, cr);
|
||||
cairo_restore (cr);
|
||||
|
||||
/* draw the grid */
|
||||
cairo_save (cr);
|
||||
gimp_display_shell_draw_grid (shell, cr);
|
||||
|
|
|
@ -583,47 +583,38 @@ gimp_display_shell_draw_selection_in (GimpDisplayShell *shell,
|
|||
cairo_mask (cr, mask);
|
||||
}
|
||||
|
||||
void
|
||||
gimp_display_shell_draw_vector (GimpDisplayShell *shell,
|
||||
GimpVectors *vectors)
|
||||
static void
|
||||
gimp_display_shell_draw_one_vectors (GimpDisplayShell *shell,
|
||||
cairo_t *cr,
|
||||
GimpVectors *vectors,
|
||||
gdouble width)
|
||||
{
|
||||
GimpStroke *stroke = NULL;
|
||||
|
||||
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;
|
||||
GimpBezierDesc *desc = gimp_vectors_make_bezier (vectors);
|
||||
|
||||
coords = gimp_stroke_interpolate (stroke, 1.0, &closed);
|
||||
|
||||
if (coords && coords->len > 0)
|
||||
if (desc)
|
||||
{
|
||||
GdkPoint *gdk_coords = g_new (GdkPoint, coords->len);
|
||||
cairo_append_path (cr, (cairo_path_t *) desc);
|
||||
|
||||
gimp_display_shell_transform_coords (shell,
|
||||
&g_array_index (coords,
|
||||
GimpCoords, 0),
|
||||
gdk_coords,
|
||||
coords->len,
|
||||
FALSE);
|
||||
cairo_set_line_width (cr, 1.6 * width);
|
||||
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
|
||||
cairo_stroke_preserve (cr);
|
||||
|
||||
gimp_canvas_draw_lines (GIMP_CANVAS (shell->canvas),
|
||||
GIMP_CANVAS_STYLE_XOR,
|
||||
gdk_coords, coords->len);
|
||||
cairo_set_line_width (cr, width);
|
||||
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
|
||||
cairo_stroke (cr);
|
||||
|
||||
g_free (gdk_coords);
|
||||
g_free (desc->data);
|
||||
g_free (desc);
|
||||
}
|
||||
|
||||
if (coords)
|
||||
g_array_free (coords, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gimp_display_shell_draw_vectors (GimpDisplayShell *shell)
|
||||
gimp_display_shell_draw_vectors (GimpDisplayShell *shell,
|
||||
cairo_t *cr)
|
||||
{
|
||||
GimpImage *image;
|
||||
|
||||
|
@ -633,17 +624,30 @@ gimp_display_shell_draw_vectors (GimpDisplayShell *shell)
|
|||
|
||||
if (image && TRUE /* gimp_display_shell_get_show_vectors (shell) */)
|
||||
{
|
||||
GList *all_vectors;
|
||||
GList *list;
|
||||
GList *all_vectors = gimp_image_get_vectors_list (image);
|
||||
const GList *list;
|
||||
gdouble xscale;
|
||||
gdouble yscale;
|
||||
gdouble width;
|
||||
|
||||
all_vectors = gimp_image_get_vectors_list (image);
|
||||
if (! all_vectors)
|
||||
return;
|
||||
|
||||
cairo_translate (cr, - shell->offset_x, - shell->offset_y);
|
||||
cairo_scale (cr, shell->scale_x, shell->scale_y);
|
||||
|
||||
/* determine a reasonable line width */
|
||||
xscale = yscale = 2.0;
|
||||
cairo_device_to_user_distance (cr, &xscale, &yscale);
|
||||
width = MAX (xscale, yscale);
|
||||
width = MIN (width, 2.0);
|
||||
|
||||
for (list = all_vectors; list; list = list->next)
|
||||
{
|
||||
GimpVectors *vectors = list->data;
|
||||
|
||||
if (gimp_item_get_visible (GIMP_ITEM (vectors)))
|
||||
gimp_display_shell_draw_vector (shell, vectors);
|
||||
gimp_display_shell_draw_one_vectors (shell, cr, vectors, width);
|
||||
}
|
||||
|
||||
g_list_free (all_vectors);
|
||||
|
|
|
@ -61,9 +61,8 @@ void gimp_display_shell_draw_selection_in (GimpDisplayShell *shell,
|
|||
cairo_t *cr,
|
||||
cairo_pattern_t *mask,
|
||||
gint index);
|
||||
void gimp_display_shell_draw_vector (GimpDisplayShell *shell,
|
||||
GimpVectors *vectors);
|
||||
void gimp_display_shell_draw_vectors (GimpDisplayShell *shell);
|
||||
void gimp_display_shell_draw_vectors (GimpDisplayShell *shell,
|
||||
cairo_t *cr);
|
||||
void gimp_display_shell_draw_cursor (GimpDisplayShell *shell,
|
||||
cairo_t *cr);
|
||||
void gimp_display_shell_draw_area (GimpDisplayShell *shell,
|
||||
|
|
|
@ -107,6 +107,17 @@ gimp_display_shell_expose_sample_point (GimpDisplayShell *shell,
|
|||
gimp_display_shell_expose_area (shell, x1, y1, x2 - x1 + 3, y2 - y1 + 3);
|
||||
}
|
||||
|
||||
void
|
||||
gimp_display_shell_expose_vectors (GimpDisplayShell *shell,
|
||||
GimpVectors *vectors)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
||||
g_return_if_fail (vectors != NULL);
|
||||
|
||||
// FIXME
|
||||
gimp_display_shell_expose_full (shell);
|
||||
}
|
||||
|
||||
void
|
||||
gimp_display_shell_expose_full (GimpDisplayShell *shell)
|
||||
{
|
||||
|
|
|
@ -28,6 +28,8 @@ void gimp_display_shell_expose_guide (GimpDisplayShell *shell,
|
|||
GimpGuide *guide);
|
||||
void gimp_display_shell_expose_sample_point (GimpDisplayShell *shell,
|
||||
GimpSamplePoint *sample_point);
|
||||
void gimp_display_shell_expose_vectors (GimpDisplayShell *shell,
|
||||
GimpVectors *vectors);
|
||||
void gimp_display_shell_expose_full (GimpDisplayShell *shell);
|
||||
|
||||
|
||||
|
|
|
@ -607,24 +607,22 @@ static void
|
|||
gimp_display_shell_vectors_freeze_handler (GimpVectors *vectors,
|
||||
GimpDisplayShell *shell)
|
||||
{
|
||||
if (shell->paused_count == 0 && gimp_item_get_visible (GIMP_ITEM (vectors)))
|
||||
gimp_display_shell_draw_vector (shell, vectors);
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_display_shell_vectors_thaw_handler (GimpVectors *vectors,
|
||||
GimpDisplayShell *shell)
|
||||
{
|
||||
if (shell->paused_count == 0 && gimp_item_get_visible (GIMP_ITEM (vectors)))
|
||||
gimp_display_shell_draw_vector (shell, vectors);
|
||||
if (gimp_item_get_visible (GIMP_ITEM (vectors)))
|
||||
gimp_display_shell_expose_vectors (shell, vectors);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_display_shell_vectors_visible_handler (GimpVectors *vectors,
|
||||
GimpDisplayShell *shell)
|
||||
{
|
||||
if (shell->paused_count == 0)
|
||||
gimp_display_shell_draw_vector (shell, vectors);
|
||||
gimp_display_shell_expose_vectors (shell, vectors);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -632,8 +630,8 @@ gimp_display_shell_vectors_add_handler (GimpContainer *container,
|
|||
GimpVectors *vectors,
|
||||
GimpDisplayShell *shell)
|
||||
{
|
||||
if (shell->paused_count == 0 && gimp_item_get_visible (GIMP_ITEM (vectors)))
|
||||
gimp_display_shell_draw_vector (shell, vectors);
|
||||
if (gimp_item_get_visible (GIMP_ITEM (vectors)))
|
||||
gimp_display_shell_expose_vectors (shell, vectors);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -641,8 +639,8 @@ gimp_display_shell_vectors_remove_handler (GimpContainer *container,
|
|||
GimpVectors *vectors,
|
||||
GimpDisplayShell *shell)
|
||||
{
|
||||
if (shell->paused_count == 0 && gimp_item_get_visible (GIMP_ITEM (vectors)))
|
||||
gimp_display_shell_draw_vector (shell, vectors);
|
||||
if (gimp_item_get_visible (GIMP_ITEM (vectors)))
|
||||
gimp_display_shell_expose_vectors (shell, vectors);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -1698,8 +1698,6 @@ gimp_display_shell_pause (GimpDisplayShell *shell)
|
|||
tool_manager_control_active (shell->display->gimp,
|
||||
GIMP_TOOL_ACTION_PAUSE,
|
||||
shell->display);
|
||||
|
||||
gimp_display_shell_draw_vectors (shell);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1722,8 +1720,6 @@ gimp_display_shell_resume (GimpDisplayShell *shell)
|
|||
|
||||
if (shell->paused_count == 0)
|
||||
{
|
||||
gimp_display_shell_draw_vectors (shell);
|
||||
|
||||
/* start the currently active tool */
|
||||
tool_manager_control_active (shell->display->gimp,
|
||||
GIMP_TOOL_ACTION_RESUME,
|
||||
|
|
Loading…
Reference in New Issue