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:
@ -268,8 +268,6 @@ gimp_display_shell_canvas_realize (GtkWidget *canvas,
|
|||||||
|
|
||||||
/* allow shrinking */
|
/* allow shrinking */
|
||||||
gtk_widget_set_size_request (GTK_WIDGET (shell), 0, 0);
|
gtk_widget_set_size_request (GTK_WIDGET (shell), 0, 0);
|
||||||
|
|
||||||
gimp_display_shell_draw_vectors (shell);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -2308,6 +2306,11 @@ gimp_display_shell_canvas_expose_image (GimpDisplayShell *shell,
|
|||||||
gimp_display_shell_preview_transform (shell, cr);
|
gimp_display_shell_preview_transform (shell, cr);
|
||||||
cairo_restore (cr);
|
cairo_restore (cr);
|
||||||
|
|
||||||
|
/* draw the vectors */
|
||||||
|
cairo_save (cr);
|
||||||
|
gimp_display_shell_draw_vectors (shell, cr);
|
||||||
|
cairo_restore (cr);
|
||||||
|
|
||||||
/* draw the grid */
|
/* draw the grid */
|
||||||
cairo_save (cr);
|
cairo_save (cr);
|
||||||
gimp_display_shell_draw_grid (shell, cr);
|
gimp_display_shell_draw_grid (shell, cr);
|
||||||
|
@ -583,47 +583,38 @@ gimp_display_shell_draw_selection_in (GimpDisplayShell *shell,
|
|||||||
cairo_mask (cr, mask);
|
cairo_mask (cr, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
gimp_display_shell_draw_vector (GimpDisplayShell *shell,
|
gimp_display_shell_draw_one_vectors (GimpDisplayShell *shell,
|
||||||
GimpVectors *vectors)
|
cairo_t *cr,
|
||||||
|
GimpVectors *vectors,
|
||||||
|
gdouble width)
|
||||||
{
|
{
|
||||||
GimpStroke *stroke = NULL;
|
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)))
|
while ((stroke = gimp_vectors_stroke_get_next (vectors, stroke)))
|
||||||
{
|
{
|
||||||
GArray *coords;
|
GimpBezierDesc *desc = gimp_vectors_make_bezier (vectors);
|
||||||
gboolean closed;
|
|
||||||
|
|
||||||
coords = gimp_stroke_interpolate (stroke, 1.0, &closed);
|
if (desc)
|
||||||
|
|
||||||
if (coords && coords->len > 0)
|
|
||||||
{
|
{
|
||||||
GdkPoint *gdk_coords = g_new (GdkPoint, coords->len);
|
cairo_append_path (cr, (cairo_path_t *) desc);
|
||||||
|
|
||||||
gimp_display_shell_transform_coords (shell,
|
cairo_set_line_width (cr, 1.6 * width);
|
||||||
&g_array_index (coords,
|
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
|
||||||
GimpCoords, 0),
|
cairo_stroke_preserve (cr);
|
||||||
gdk_coords,
|
|
||||||
coords->len,
|
|
||||||
FALSE);
|
|
||||||
|
|
||||||
gimp_canvas_draw_lines (GIMP_CANVAS (shell->canvas),
|
cairo_set_line_width (cr, width);
|
||||||
GIMP_CANVAS_STYLE_XOR,
|
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
|
||||||
gdk_coords, coords->len);
|
cairo_stroke (cr);
|
||||||
|
|
||||||
g_free (gdk_coords);
|
g_free (desc->data);
|
||||||
|
g_free (desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (coords)
|
|
||||||
g_array_free (coords, TRUE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gimp_display_shell_draw_vectors (GimpDisplayShell *shell)
|
gimp_display_shell_draw_vectors (GimpDisplayShell *shell,
|
||||||
|
cairo_t *cr)
|
||||||
{
|
{
|
||||||
GimpImage *image;
|
GimpImage *image;
|
||||||
|
|
||||||
@ -633,17 +624,30 @@ gimp_display_shell_draw_vectors (GimpDisplayShell *shell)
|
|||||||
|
|
||||||
if (image && TRUE /* gimp_display_shell_get_show_vectors (shell) */)
|
if (image && TRUE /* gimp_display_shell_get_show_vectors (shell) */)
|
||||||
{
|
{
|
||||||
GList *all_vectors;
|
GList *all_vectors = gimp_image_get_vectors_list (image);
|
||||||
GList *list;
|
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)
|
for (list = all_vectors; list; list = list->next)
|
||||||
{
|
{
|
||||||
GimpVectors *vectors = list->data;
|
GimpVectors *vectors = list->data;
|
||||||
|
|
||||||
if (gimp_item_get_visible (GIMP_ITEM (vectors)))
|
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);
|
g_list_free (all_vectors);
|
||||||
|
@ -61,9 +61,8 @@ void gimp_display_shell_draw_selection_in (GimpDisplayShell *shell,
|
|||||||
cairo_t *cr,
|
cairo_t *cr,
|
||||||
cairo_pattern_t *mask,
|
cairo_pattern_t *mask,
|
||||||
gint index);
|
gint index);
|
||||||
void gimp_display_shell_draw_vector (GimpDisplayShell *shell,
|
void gimp_display_shell_draw_vectors (GimpDisplayShell *shell,
|
||||||
GimpVectors *vectors);
|
cairo_t *cr);
|
||||||
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);
|
cairo_t *cr);
|
||||||
void gimp_display_shell_draw_area (GimpDisplayShell *shell,
|
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);
|
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
|
void
|
||||||
gimp_display_shell_expose_full (GimpDisplayShell *shell)
|
gimp_display_shell_expose_full (GimpDisplayShell *shell)
|
||||||
{
|
{
|
||||||
|
@ -28,6 +28,8 @@ void gimp_display_shell_expose_guide (GimpDisplayShell *shell,
|
|||||||
GimpGuide *guide);
|
GimpGuide *guide);
|
||||||
void gimp_display_shell_expose_sample_point (GimpDisplayShell *shell,
|
void gimp_display_shell_expose_sample_point (GimpDisplayShell *shell,
|
||||||
GimpSamplePoint *sample_point);
|
GimpSamplePoint *sample_point);
|
||||||
|
void gimp_display_shell_expose_vectors (GimpDisplayShell *shell,
|
||||||
|
GimpVectors *vectors);
|
||||||
void gimp_display_shell_expose_full (GimpDisplayShell *shell);
|
void gimp_display_shell_expose_full (GimpDisplayShell *shell);
|
||||||
|
|
||||||
|
|
||||||
|
@ -607,24 +607,22 @@ static void
|
|||||||
gimp_display_shell_vectors_freeze_handler (GimpVectors *vectors,
|
gimp_display_shell_vectors_freeze_handler (GimpVectors *vectors,
|
||||||
GimpDisplayShell *shell)
|
GimpDisplayShell *shell)
|
||||||
{
|
{
|
||||||
if (shell->paused_count == 0 && gimp_item_get_visible (GIMP_ITEM (vectors)))
|
/* do nothing */
|
||||||
gimp_display_shell_draw_vector (shell, vectors);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gimp_display_shell_vectors_thaw_handler (GimpVectors *vectors,
|
gimp_display_shell_vectors_thaw_handler (GimpVectors *vectors,
|
||||||
GimpDisplayShell *shell)
|
GimpDisplayShell *shell)
|
||||||
{
|
{
|
||||||
if (shell->paused_count == 0 && gimp_item_get_visible (GIMP_ITEM (vectors)))
|
if (gimp_item_get_visible (GIMP_ITEM (vectors)))
|
||||||
gimp_display_shell_draw_vector (shell, vectors);
|
gimp_display_shell_expose_vectors (shell, vectors);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gimp_display_shell_vectors_visible_handler (GimpVectors *vectors,
|
gimp_display_shell_vectors_visible_handler (GimpVectors *vectors,
|
||||||
GimpDisplayShell *shell)
|
GimpDisplayShell *shell)
|
||||||
{
|
{
|
||||||
if (shell->paused_count == 0)
|
gimp_display_shell_expose_vectors (shell, vectors);
|
||||||
gimp_display_shell_draw_vector (shell, vectors);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -632,8 +630,8 @@ gimp_display_shell_vectors_add_handler (GimpContainer *container,
|
|||||||
GimpVectors *vectors,
|
GimpVectors *vectors,
|
||||||
GimpDisplayShell *shell)
|
GimpDisplayShell *shell)
|
||||||
{
|
{
|
||||||
if (shell->paused_count == 0 && gimp_item_get_visible (GIMP_ITEM (vectors)))
|
if (gimp_item_get_visible (GIMP_ITEM (vectors)))
|
||||||
gimp_display_shell_draw_vector (shell, vectors);
|
gimp_display_shell_expose_vectors (shell, vectors);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -641,8 +639,8 @@ gimp_display_shell_vectors_remove_handler (GimpContainer *container,
|
|||||||
GimpVectors *vectors,
|
GimpVectors *vectors,
|
||||||
GimpDisplayShell *shell)
|
GimpDisplayShell *shell)
|
||||||
{
|
{
|
||||||
if (shell->paused_count == 0 && gimp_item_get_visible (GIMP_ITEM (vectors)))
|
if (gimp_item_get_visible (GIMP_ITEM (vectors)))
|
||||||
gimp_display_shell_draw_vector (shell, vectors);
|
gimp_display_shell_expose_vectors (shell, vectors);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1698,8 +1698,6 @@ gimp_display_shell_pause (GimpDisplayShell *shell)
|
|||||||
tool_manager_control_active (shell->display->gimp,
|
tool_manager_control_active (shell->display->gimp,
|
||||||
GIMP_TOOL_ACTION_PAUSE,
|
GIMP_TOOL_ACTION_PAUSE,
|
||||||
shell->display);
|
shell->display);
|
||||||
|
|
||||||
gimp_display_shell_draw_vectors (shell);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1722,8 +1720,6 @@ gimp_display_shell_resume (GimpDisplayShell *shell)
|
|||||||
|
|
||||||
if (shell->paused_count == 0)
|
if (shell->paused_count == 0)
|
||||||
{
|
{
|
||||||
gimp_display_shell_draw_vectors (shell);
|
|
||||||
|
|
||||||
/* start the currently active tool */
|
/* start the currently active tool */
|
||||||
tool_manager_control_active (shell->display->gimp,
|
tool_manager_control_active (shell->display->gimp,
|
||||||
GIMP_TOOL_ACTION_RESUME,
|
GIMP_TOOL_ACTION_RESUME,
|
||||||
|
Reference in New Issue
Block a user