Initial checkin of Pika from heckimp

This commit is contained in:
2023-09-25 15:35:21 -07:00
commit 891e999216
6761 changed files with 5240685 additions and 0 deletions

24
app/vectors/meson.build Normal file
View File

@ -0,0 +1,24 @@
libappvectors_sources = [
'pikaanchor.c',
'pikabezierstroke.c',
'pikastroke-new.c',
'pikastroke.c',
'pikavectors-compat.c',
'pikavectors-export.c',
'pikavectors-import.c',
'pikavectors-preview.c',
'pikavectors-warp.c',
'pikavectors.c',
'pikavectorsmodundo.c',
'pikavectorspropundo.c',
'pikavectorsundo.c',
]
libappvectors = static_library('appvectors',
libappvectors_sources,
include_directories: [ rootInclude, rootAppInclude, ],
c_args: '-DG_LOG_DOMAIN="Pika-Vectors"',
dependencies: [
cairo, gegl, gdk_pixbuf,
],
)

64
app/vectors/pikaanchor.c Normal file
View File

@ -0,0 +1,64 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* pikaanchor.c
* Copyright (C) 2002 Simon Budig <simon@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <glib-object.h>
#include "vectors-types.h"
#include "pikaanchor.h"
G_DEFINE_BOXED_TYPE (PikaAnchor, pika_anchor, pika_anchor_copy, pika_anchor_free)
PikaAnchor *
pika_anchor_new (PikaAnchorType type,
const PikaCoords *position)
{
PikaAnchor *anchor = g_slice_new0 (PikaAnchor);
anchor->type = type;
if (position)
anchor->position = *position;
return anchor;
}
PikaAnchor *
pika_anchor_copy (const PikaAnchor *anchor)
{
g_return_val_if_fail (anchor != NULL, NULL);
return g_slice_dup (PikaAnchor, anchor);
}
void
pika_anchor_free (PikaAnchor *anchor)
{
g_return_if_fail (anchor != NULL);
g_slice_free (PikaAnchor, anchor);
}

52
app/vectors/pikaanchor.h Normal file
View File

@ -0,0 +1,52 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* pikaanchor.h
* Copyright (C) 2002 Simon Budig <simon@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __PIKA_ANCHOR_H__
#define __PIKA_ANCHOR_H__
#define PIKA_ANCHOR(anchor) ((PikaAnchor *) (anchor))
#define PIKA_TYPE_ANCHOR (pika_anchor_get_type ())
#define PIKA_VALUE_HOLDS_ANCHOR(value) (G_TYPE_CHECK_VALUE_TYPE ((value), PIKA_TYPE_ANCHOR))
GType pika_anchor_get_type (void) G_GNUC_CONST;
struct _PikaAnchor
{
PikaCoords position;
PikaAnchorType type; /* Interpretation dependent on PikaStroke type */
gboolean selected;
};
PikaAnchor * pika_anchor_new (PikaAnchorType type,
const PikaCoords *position);
PikaAnchor * pika_anchor_copy (const PikaAnchor *anchor);
void pika_anchor_free (PikaAnchor *anchor);
#endif /* __PIKA_ANCHOR_H__ */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,88 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* pikabezierstroke.h
* Copyright (C) 2002 Simon Budig <simon@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __PIKA_BEZIER_STROKE_H__
#define __PIKA_BEZIER_STROKE_H__
#include "pikastroke.h"
#define PIKA_TYPE_BEZIER_STROKE (pika_bezier_stroke_get_type ())
#define PIKA_BEZIER_STROKE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PIKA_TYPE_BEZIER_STROKE, PikaBezierStroke))
#define PIKA_BEZIER_STROKE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PIKA_TYPE_BEZIER_STROKE, PikaBezierStrokeClass))
#define PIKA_IS_BEZIER_STROKE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PIKA_TYPE_BEZIER_STROKE))
#define PIKA_IS_BEZIER_STROKE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PIKA_TYPE_BEZIER_STROKE))
#define PIKA_BEZIER_STROKE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PIKA_TYPE_BEZIER_STROKE, PikaBezierStrokeClass))
typedef struct _PikaBezierStrokeClass PikaBezierStrokeClass;
struct _PikaBezierStroke
{
PikaStroke parent_instance;
};
struct _PikaBezierStrokeClass
{
PikaStrokeClass parent_class;
};
GType pika_bezier_stroke_get_type (void) G_GNUC_CONST;
PikaStroke * pika_bezier_stroke_new (void);
PikaStroke * pika_bezier_stroke_new_from_coords (const PikaCoords *coords,
gint n_coords,
gboolean closed);
PikaStroke * pika_bezier_stroke_new_moveto (const PikaCoords *start);
void pika_bezier_stroke_lineto (PikaStroke *bez_stroke,
const PikaCoords *end);
void pika_bezier_stroke_conicto (PikaStroke *bez_stroke,
const PikaCoords *control,
const PikaCoords *end);
void pika_bezier_stroke_cubicto (PikaStroke *bez_stroke,
const PikaCoords *control1,
const PikaCoords *control2,
const PikaCoords *end);
void pika_bezier_stroke_arcto (PikaStroke *bez_stroke,
gdouble radius_x,
gdouble radius_y,
gdouble angle_rad,
gboolean large_arc,
gboolean sweep,
const PikaCoords *end);
PikaStroke * pika_bezier_stroke_new_ellipse (const PikaCoords *center,
gdouble radius_x,
gdouble radius_y,
gdouble angle);
PikaAnchor * pika_bezier_stroke_extend (PikaStroke *stroke,
const PikaCoords *coords,
PikaAnchor *neighbor,
PikaVectorExtendMode extend_mode);
#endif /* __PIKA_BEZIER_STROKE_H__ */

View File

@ -0,0 +1,51 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* pikastroke-new.c
* Copyright (C) 2006 Simon Budig <simon@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <glib-object.h>
#include "vectors-types.h"
#include "pikastroke-new.h"
#include "pikabezierstroke.h"
PikaStroke *
pika_stroke_new_from_coords (PikaVectorsStrokeType type,
const PikaCoords *coords,
gint n_coords,
gboolean closed)
{
switch (type)
{
case PIKA_VECTORS_STROKE_TYPE_BEZIER:
return pika_bezier_stroke_new_from_coords (coords, n_coords, closed);
break;
default:
g_warning ("unknown type in pika_stroke_new_from_coords(): %d", type);
return NULL;
}
}

View File

@ -0,0 +1,35 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* pikastroke-new.c
* Copyright (C) 2006 Simon Budig <simon@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __PIKA_VECTORS_NEW_H__
#define __PIKA_VECTORS_NEW_H__
PikaStroke * pika_stroke_new_from_coords (PikaVectorsStrokeType type,
const PikaCoords *coords,
gint n_coords,
gboolean closed);
#endif /* __PIKA_VECTORS_NEW_H__ */

1497
app/vectors/pikastroke.c Normal file

File diff suppressed because it is too large Load Diff

355
app/vectors/pikastroke.h Normal file
View File

@ -0,0 +1,355 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* pikastroke.h
* Copyright (C) 2002 Simon Budig <simon@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __PIKA_STROKE_H__
#define __PIKA_STROKE_H__
#include "core/pikaobject.h"
#define PIKA_TYPE_STROKE (pika_stroke_get_type ())
#define PIKA_STROKE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PIKA_TYPE_STROKE, PikaStroke))
#define PIKA_STROKE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PIKA_TYPE_STROKE, PikaStrokeClass))
#define PIKA_IS_STROKE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PIKA_TYPE_STROKE))
#define PIKA_IS_STROKE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PIKA_TYPE_STROKE))
#define PIKA_STROKE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PIKA_TYPE_STROKE, PikaStrokeClass))
typedef struct _PikaStrokeClass PikaStrokeClass;
struct _PikaStroke
{
PikaObject parent_instance;
gint id;
GQueue *anchors;
gboolean closed;
};
struct _PikaStrokeClass
{
PikaObjectClass parent_class;
void (* changed) (PikaStroke *stroke);
void (* removed) (PikaStroke *stroke);
PikaAnchor * (* anchor_get) (PikaStroke *stroke,
const PikaCoords *coord);
gdouble (* nearest_point_get) (PikaStroke *stroke,
const PikaCoords *coord,
gdouble precision,
PikaCoords *ret_point,
PikaAnchor **ret_segment_start,
PikaAnchor **ret_segment_end,
gdouble *ret_pos);
gdouble (* nearest_tangent_get) (PikaStroke *stroke,
const PikaCoords *coord1,
const PikaCoords *coord2,
gdouble precision,
PikaCoords *nearest,
PikaAnchor **ret_segment_start,
PikaAnchor **ret_segment_end,
gdouble *ret_pos);
gdouble (* nearest_intersection_get)
(PikaStroke *stroke,
const PikaCoords *coord1,
const PikaCoords *direction,
gdouble precision,
PikaCoords *nearest,
PikaAnchor **ret_segment_start,
PikaAnchor **ret_segment_end,
gdouble *ret_pos);
PikaAnchor * (* anchor_get_next) (PikaStroke *stroke,
const PikaAnchor *prev);
void (* anchor_select) (PikaStroke *stroke,
PikaAnchor *anchor,
gboolean selected,
gboolean exclusive);
void (* anchor_move_relative) (PikaStroke *stroke,
PikaAnchor *anchor,
const PikaCoords *deltacoord,
PikaAnchorFeatureType feature);
void (* anchor_move_absolute) (PikaStroke *stroke,
PikaAnchor *anchor,
const PikaCoords *coord,
PikaAnchorFeatureType feature);
void (* anchor_convert) (PikaStroke *stroke,
PikaAnchor *anchor,
PikaAnchorFeatureType feature);
void (* anchor_delete) (PikaStroke *stroke,
PikaAnchor *anchor);
gboolean (* point_is_movable) (PikaStroke *stroke,
PikaAnchor *predec,
gdouble position);
void (* point_move_relative) (PikaStroke *stroke,
PikaAnchor *predec,
gdouble position,
const PikaCoords *deltacoord,
PikaAnchorFeatureType feature);
void (* point_move_absolute) (PikaStroke *stroke,
PikaAnchor *predec,
gdouble position,
const PikaCoords *coord,
PikaAnchorFeatureType feature);
void (* close) (PikaStroke *stroke);
PikaStroke * (* open) (PikaStroke *stroke,
PikaAnchor *end_anchor);
gboolean (* anchor_is_insertable) (PikaStroke *stroke,
PikaAnchor *predec,
gdouble position);
PikaAnchor * (* anchor_insert) (PikaStroke *stroke,
PikaAnchor *predec,
gdouble position);
gboolean (* is_extendable) (PikaStroke *stroke,
PikaAnchor *neighbor);
PikaAnchor * (* extend) (PikaStroke *stroke,
const PikaCoords *coords,
PikaAnchor *neighbor,
PikaVectorExtendMode extend_mode);
gboolean (* connect_stroke) (PikaStroke *stroke,
PikaAnchor *anchor,
PikaStroke *extension,
PikaAnchor *neighbor);
gboolean (* is_empty) (PikaStroke *stroke);
gboolean (* reverse) (PikaStroke *stroke);
gboolean (* shift_start) (PikaStroke *stroke,
PikaAnchor *new_start);
gdouble (* get_length) (PikaStroke *stroke,
gdouble precision);
gdouble (* get_distance) (PikaStroke *stroke,
const PikaCoords *coord);
gboolean (* get_point_at_dist) (PikaStroke *stroke,
gdouble dist,
gdouble precision,
PikaCoords *position,
gdouble *slope);
GArray * (* interpolate) (PikaStroke *stroke,
gdouble precision,
gboolean *ret_closed);
PikaStroke * (* duplicate) (PikaStroke *stroke);
PikaBezierDesc * (* make_bezier) (PikaStroke *stroke);
void (* translate) (PikaStroke *stroke,
gdouble offset_x,
gdouble offset_y);
void (* scale) (PikaStroke *stroke,
gdouble scale_x,
gdouble scale_y);
void (* rotate) (PikaStroke *stroke,
gdouble center_x,
gdouble center_y,
gdouble angle);
void (* flip) (PikaStroke *stroke,
PikaOrientationType flip_type,
gdouble axis);
void (* flip_free) (PikaStroke *stroke,
gdouble x1,
gdouble y1,
gdouble x2,
gdouble y2);
void (* transform) (PikaStroke *stroke,
const PikaMatrix3 *matrix,
GQueue *ret_strokes);
GList * (* get_draw_anchors) (PikaStroke *stroke);
GList * (* get_draw_controls) (PikaStroke *stroke);
GArray * (* get_draw_lines) (PikaStroke *stroke);
GArray * (* control_points_get) (PikaStroke *stroke,
gboolean *ret_closed);
};
GType pika_stroke_get_type (void) G_GNUC_CONST;
void pika_stroke_set_id (PikaStroke *stroke,
gint id);
gint pika_stroke_get_id (PikaStroke *stroke);
/* accessing / modifying the anchors */
GArray * pika_stroke_control_points_get (PikaStroke *stroke,
gboolean *closed);
PikaAnchor * pika_stroke_anchor_get (PikaStroke *stroke,
const PikaCoords *coord);
gdouble pika_stroke_nearest_point_get (PikaStroke *stroke,
const PikaCoords *coord,
gdouble precision,
PikaCoords *ret_point,
PikaAnchor **ret_segment_start,
PikaAnchor **ret_segment_end,
gdouble *ret_pos);
gdouble pika_stroke_nearest_tangent_get (PikaStroke *stroke,
const PikaCoords *coords1,
const PikaCoords *coords2,
gdouble precision,
PikaCoords *nearest,
PikaAnchor **ret_segment_start,
PikaAnchor **ret_segment_end,
gdouble *ret_pos);
gdouble pika_stroke_nearest_intersection_get (PikaStroke *stroke,
const PikaCoords *coords1,
const PikaCoords *direction,
gdouble precision,
PikaCoords *nearest,
PikaAnchor **ret_segment_start,
PikaAnchor **ret_segment_end,
gdouble *ret_pos);
/* prev == NULL: "first" anchor */
PikaAnchor * pika_stroke_anchor_get_next (PikaStroke *stroke,
const PikaAnchor *prev);
void pika_stroke_anchor_select (PikaStroke *stroke,
PikaAnchor *anchor,
gboolean selected,
gboolean exclusive);
/* type will be an xorable enum:
* VECTORS_NONE, VECTORS_FIX_ANGLE, VECTORS_FIX_RATIO, VECTORS_RESTRICT_ANGLE
* or so.
*/
void pika_stroke_anchor_move_relative (PikaStroke *stroke,
PikaAnchor *anchor,
const PikaCoords *delta,
PikaAnchorFeatureType feature);
void pika_stroke_anchor_move_absolute (PikaStroke *stroke,
PikaAnchor *anchor,
const PikaCoords *coord,
PikaAnchorFeatureType feature);
gboolean pika_stroke_point_is_movable (PikaStroke *stroke,
PikaAnchor *predec,
gdouble position);
void pika_stroke_point_move_relative (PikaStroke *stroke,
PikaAnchor *predec,
gdouble position,
const PikaCoords *deltacoord,
PikaAnchorFeatureType feature);
void pika_stroke_point_move_absolute (PikaStroke *stroke,
PikaAnchor *predec,
gdouble position,
const PikaCoords *coord,
PikaAnchorFeatureType feature);
void pika_stroke_close (PikaStroke *stroke);
void pika_stroke_anchor_convert (PikaStroke *stroke,
PikaAnchor *anchor,
PikaAnchorFeatureType feature);
void pika_stroke_anchor_delete (PikaStroke *stroke,
PikaAnchor *anchor);
PikaStroke * pika_stroke_open (PikaStroke *stroke,
PikaAnchor *end_anchor);
gboolean pika_stroke_anchor_is_insertable (PikaStroke *stroke,
PikaAnchor *predec,
gdouble position);
PikaAnchor * pika_stroke_anchor_insert (PikaStroke *stroke,
PikaAnchor *predec,
gdouble position);
gboolean pika_stroke_is_extendable (PikaStroke *stroke,
PikaAnchor *neighbor);
PikaAnchor * pika_stroke_extend (PikaStroke *stroke,
const PikaCoords *coords,
PikaAnchor *neighbor,
PikaVectorExtendMode extend_mode);
gboolean pika_stroke_connect_stroke (PikaStroke *stroke,
PikaAnchor *anchor,
PikaStroke *extension,
PikaAnchor *neighbor);
gboolean pika_stroke_is_empty (PikaStroke *stroke);
gboolean pika_stroke_reverse (PikaStroke *stroke);
gboolean pika_stroke_shift_start (PikaStroke *stroke,
PikaAnchor *new_start);
/* accessing the shape of the curve */
gdouble pika_stroke_get_length (PikaStroke *stroke,
gdouble precision);
gdouble pika_stroke_get_distance (PikaStroke *stroke,
const PikaCoords *coord);
gboolean pika_stroke_get_point_at_dist (PikaStroke *stroke,
gdouble dist,
gdouble precision,
PikaCoords *position,
gdouble *slope);
/* returns an array of valid coordinates */
GArray * pika_stroke_interpolate (PikaStroke *stroke,
const gdouble precision,
gboolean *closed);
PikaStroke * pika_stroke_duplicate (PikaStroke *stroke);
/* creates a bezier approximation. */
PikaBezierDesc * pika_stroke_make_bezier (PikaStroke *stroke);
void pika_stroke_translate (PikaStroke *stroke,
gdouble offset_x,
gdouble offset_y);
void pika_stroke_scale (PikaStroke *stroke,
gdouble scale_x,
gdouble scale_y);
void pika_stroke_rotate (PikaStroke *stroke,
gdouble center_x,
gdouble center_y,
gdouble angle);
void pika_stroke_flip (PikaStroke *stroke,
PikaOrientationType flip_type,
gdouble axis);
void pika_stroke_flip_free (PikaStroke *stroke,
gdouble x1,
gdouble y1,
gdouble x2,
gdouble y2);
void pika_stroke_transform (PikaStroke *stroke,
const PikaMatrix3 *matrix,
GQueue *ret_strokes);
GList * pika_stroke_get_draw_anchors (PikaStroke *stroke);
GList * pika_stroke_get_draw_controls (PikaStroke *stroke);
GArray * pika_stroke_get_draw_lines (PikaStroke *stroke);
#endif /* __PIKA_STROKE_H__ */

View File

@ -0,0 +1,289 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* pikavectors-compat.c
* Copyright (C) 2003 Michael Natterer <mitch@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "vectors-types.h"
#include "core/pikaimage.h"
#include "pikaanchor.h"
#include "pikabezierstroke.h"
#include "pikavectors.h"
#include "pikavectors-compat.h"
enum
{
PIKA_VECTORS_COMPAT_ANCHOR = 1,
PIKA_VECTORS_COMPAT_CONTROL = 2,
PIKA_VECTORS_COMPAT_NEW_STROKE = 3
};
static const PikaCoords default_coords = PIKA_COORDS_DEFAULT_VALUES;
PikaVectors *
pika_vectors_compat_new (PikaImage *image,
const gchar *name,
PikaVectorsCompatPoint *points,
gint n_points,
gboolean closed)
{
PikaVectors *vectors;
PikaStroke *stroke;
PikaCoords *coords;
PikaCoords *curr_stroke;
PikaCoords *curr_coord;
gint i;
g_return_val_if_fail (PIKA_IS_IMAGE (image), NULL);
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (points != NULL || n_points == 0, NULL);
g_return_val_if_fail (n_points >= 0, NULL);
vectors = pika_vectors_new (image, name);
coords = g_new0 (PikaCoords, n_points + 1);
curr_stroke = curr_coord = coords;
/* skip the first control point, will set it later */
curr_coord++;
for (i = 0; i < n_points; i++)
{
*curr_coord = default_coords;
curr_coord->x = points[i].x;
curr_coord->y = points[i].y;
/* copy the first anchor to be the first control point */
if (curr_coord == curr_stroke + 1)
*curr_stroke = *curr_coord;
/* found new stroke start */
if (points[i].type == PIKA_VECTORS_COMPAT_NEW_STROKE)
{
/* copy the last control point to the beginning of the stroke */
*curr_stroke = *(curr_coord - 1);
stroke =
pika_bezier_stroke_new_from_coords (curr_stroke,
curr_coord - curr_stroke - 1,
TRUE);
pika_vectors_stroke_add (vectors, stroke);
g_object_unref (stroke);
/* start a new stroke */
curr_stroke = curr_coord - 1;
/* copy the first anchor to be the first control point */
*curr_stroke = *curr_coord;
}
curr_coord++;
}
if (closed)
{
/* copy the last control point to the beginning of the stroke */
curr_coord--;
*curr_stroke = *curr_coord;
}
stroke = pika_bezier_stroke_new_from_coords (curr_stroke,
curr_coord - curr_stroke,
closed);
pika_vectors_stroke_add (vectors, stroke);
g_object_unref (stroke);
g_free (coords);
return vectors;
}
gboolean
pika_vectors_compat_is_compatible (PikaImage *image)
{
GList *list;
g_return_val_if_fail (PIKA_IS_IMAGE (image), FALSE);
for (list = pika_image_get_vectors_iter (image);
list;
list = g_list_next (list))
{
PikaVectors *vectors = PIKA_VECTORS (list->data);
GList *strokes;
gint open_count = 0;
if (pika_item_get_visible (PIKA_ITEM (vectors)))
return FALSE;
for (strokes = vectors->strokes->head;
strokes;
strokes = g_list_next (strokes))
{
PikaStroke *stroke = PIKA_STROKE (strokes->data);
if (! PIKA_IS_BEZIER_STROKE (stroke))
return FALSE;
if (!stroke->closed)
open_count++;
}
if (open_count >= 2)
return FALSE;
}
return TRUE;
}
PikaVectorsCompatPoint *
pika_vectors_compat_get_points (PikaVectors *vectors,
gint32 *n_points,
gint32 *closed)
{
PikaVectorsCompatPoint *points;
GList *strokes;
gint i;
GList *postponed = NULL; /* for the one open stroke... */
gint open_count;
gboolean first_stroke = TRUE;
g_return_val_if_fail (PIKA_IS_VECTORS (vectors), NULL);
g_return_val_if_fail (n_points != NULL, NULL);
g_return_val_if_fail (closed != NULL, NULL);
*n_points = 0;
*closed = TRUE;
open_count = 0;
for (strokes = vectors->strokes->head;
strokes;
strokes = g_list_next (strokes))
{
PikaStroke *stroke = strokes->data;
gint n_anchors;
if (! stroke->closed)
{
open_count++;
postponed = strokes;
*closed = FALSE;
if (open_count >= 2)
{
g_warning ("pika_vectors_compat_get_points(): convert failed");
*n_points = 0;
return NULL;
}
}
n_anchors = g_queue_get_length (stroke->anchors);
if (! stroke->closed)
n_anchors--;
*n_points += n_anchors;
}
points = g_new0 (PikaVectorsCompatPoint, *n_points);
i = 0;
for (strokes = vectors->strokes->head;
strokes || postponed;
strokes = g_list_next (strokes))
{
PikaStroke *stroke;
GList *anchors;
if (strokes)
{
if (postponed && strokes == postponed)
/* we need to visit the open stroke last... */
continue;
else
stroke = PIKA_STROKE (strokes->data);
}
else
{
stroke = PIKA_STROKE (postponed->data);
postponed = NULL;
}
for (anchors = stroke->anchors->head;
anchors;
anchors = g_list_next (anchors))
{
PikaAnchor *anchor = anchors->data;
/* skip the first anchor, will add it at the end if needed */
if (! anchors->prev)
continue;
switch (anchor->type)
{
case PIKA_ANCHOR_ANCHOR:
if (anchors->prev == stroke->anchors->head && ! first_stroke)
points[i].type = PIKA_VECTORS_COMPAT_NEW_STROKE;
else
points[i].type = PIKA_VECTORS_COMPAT_ANCHOR;
break;
case PIKA_ANCHOR_CONTROL:
points[i].type = PIKA_VECTORS_COMPAT_CONTROL;
break;
}
points[i].x = anchor->position.x;
points[i].y = anchor->position.y;
i++;
/* write the skipped control point */
if (! anchors->next && stroke->closed)
{
anchor = g_queue_peek_head (stroke->anchors);
points[i].type = PIKA_VECTORS_COMPAT_CONTROL;
points[i].x = anchor->position.x;
points[i].y = anchor->position.y;
i++;
}
}
first_stroke = FALSE;
}
return points;
}

View File

@ -0,0 +1,52 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* pikavectors-compat.h
* Copyright (C) 2003 Michael Natterer <mitch@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __PIKA_VECTORS_COMPAT_H__
#define __PIKA_VECTORS_COMPAT_H__
typedef struct _PikaVectorsCompatPoint PikaVectorsCompatPoint;
struct _PikaVectorsCompatPoint
{
guint32 type;
gdouble x;
gdouble y;
};
PikaVectors * pika_vectors_compat_new (PikaImage *image,
const gchar *name,
PikaVectorsCompatPoint *points,
gint n_points,
gboolean closed);
gboolean pika_vectors_compat_is_compatible (PikaImage *image);
PikaVectorsCompatPoint * pika_vectors_compat_get_points (PikaVectors *vectors,
gint32 *n_points,
gint32 *closed);
#endif /* __PIKA_VECTORS_COMPAT_H__ */

View File

@ -0,0 +1,326 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "libpikabase/pikabase.h"
#include "vectors-types.h"
#include "core/pikaimage.h"
#include "core/pikaitem.h"
#include "pikaanchor.h"
#include "pikastroke.h"
#include "pikabezierstroke.h"
#include "pikavectors.h"
#include "pikavectors-export.h"
#include "pika-intl.h"
static GString * pika_vectors_export (PikaImage *image,
GList *vectors);
static void pika_vectors_export_image_size (PikaImage *image,
GString *str);
static void pika_vectors_export_path (PikaVectors *vectors,
GString *str);
static gchar * pika_vectors_export_path_data (PikaVectors *vectors);
/**
* pika_vectors_export_file:
* @image: the #PikaImage from which to export vectors
* @vectors: a #GList of #PikaVectors objects or %NULL to export all vectors in @image
* @file: the file to write
* @error: return location for errors
*
* Exports one or more vectors to a SVG file.
*
* Returns: %TRUE on success,
* %FALSE if there was an error writing the file
**/
gboolean
pika_vectors_export_file (PikaImage *image,
GList *vectors,
GFile *file,
GError **error)
{
GOutputStream *output;
GString *string;
GError *my_error = NULL;
g_return_val_if_fail (PIKA_IS_IMAGE (image), FALSE);
g_return_val_if_fail (G_IS_FILE (file), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
output = G_OUTPUT_STREAM (g_file_replace (file,
NULL, FALSE, G_FILE_CREATE_NONE,
NULL, error));
if (! output)
return FALSE;
string = pika_vectors_export (image, vectors);
if (! g_output_stream_write_all (output, string->str, string->len,
NULL, NULL, &my_error))
{
GCancellable *cancellable = g_cancellable_new ();
g_set_error (error, my_error->domain, my_error->code,
_("Writing SVG file '%s' failed: %s"),
pika_file_get_utf8_name (file), my_error->message);
g_clear_error (&my_error);
g_string_free (string, TRUE);
/* Cancel the overwrite initiated by g_file_replace(). */
g_cancellable_cancel (cancellable);
g_output_stream_close (output, cancellable, NULL);
g_object_unref (cancellable);
g_object_unref (output);
return FALSE;
}
g_string_free (string, TRUE);
g_object_unref (output);
return TRUE;
}
/**
* pika_vectors_export_string:
* @image: the #PikaImage from which to export vectors
* @vectors: a #PikaVectors object or %NULL to export all vectors in @image
*
* Exports one or more vectors to a SVG string.
*
* Returns: a %NUL-terminated string that holds a complete XML document
**/
gchar *
pika_vectors_export_string (PikaImage *image,
GList *vectors)
{
g_return_val_if_fail (PIKA_IS_IMAGE (image), NULL);
return g_string_free (pika_vectors_export (image, vectors), FALSE);
}
static GString *
pika_vectors_export (PikaImage *image,
GList *vectors)
{
GString *str = g_string_new (NULL);
GList *list;
g_string_append_printf (str,
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\"\n"
" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n"
"\n"
"<svg xmlns=\"http://www.w3.org/2000/svg\"\n");
g_string_append (str, " ");
pika_vectors_export_image_size (image, str);
g_string_append_c (str, '\n');
g_string_append_printf (str,
" viewBox=\"0 0 %d %d\">\n",
pika_image_get_width (image),
pika_image_get_height (image));
if (! vectors)
vectors = pika_image_get_vectors_iter (image);
for (list = vectors; list; list = list->next)
pika_vectors_export_path (PIKA_VECTORS (list->data), str);
g_string_append (str, "</svg>\n");
return str;
}
static void
pika_vectors_export_image_size (PikaImage *image,
GString *str)
{
PikaUnit unit;
const gchar *abbrev;
gchar wbuf[G_ASCII_DTOSTR_BUF_SIZE];
gchar hbuf[G_ASCII_DTOSTR_BUF_SIZE];
gdouble xres;
gdouble yres;
gdouble w, h;
pika_image_get_resolution (image, &xres, &yres);
w = (gdouble) pika_image_get_width (image) / xres;
h = (gdouble) pika_image_get_height (image) / yres;
/* FIXME: should probably use the display unit here */
unit = pika_image_get_unit (image);
switch (unit)
{
case PIKA_UNIT_INCH: abbrev = "in"; break;
case PIKA_UNIT_MM: abbrev = "mm"; break;
case PIKA_UNIT_POINT: abbrev = "pt"; break;
case PIKA_UNIT_PICA: abbrev = "pc"; break;
default: abbrev = "cm";
unit = PIKA_UNIT_MM;
w /= 10.0;
h /= 10.0;
break;
}
g_ascii_formatd (wbuf, sizeof (wbuf), "%g", w * pika_unit_get_factor (unit));
g_ascii_formatd (hbuf, sizeof (hbuf), "%g", h * pika_unit_get_factor (unit));
g_string_append_printf (str,
"width=\"%s%s\" height=\"%s%s\"",
wbuf, abbrev, hbuf, abbrev);
}
static void
pika_vectors_export_path (PikaVectors *vectors,
GString *str)
{
const gchar *name = pika_object_get_name (vectors);
gchar *data = pika_vectors_export_path_data (vectors);
gchar *esc_name;
esc_name = g_markup_escape_text (name, strlen (name));
g_string_append_printf (str,
" <path id=\"%s\"\n"
" fill=\"none\" stroke=\"black\" stroke-width=\"1\"\n"
" d=\"%s\" />\n",
esc_name, data);
g_free (esc_name);
g_free (data);
}
#define NEWLINE "\n "
static gchar *
pika_vectors_export_path_data (PikaVectors *vectors)
{
GString *str;
GList *strokes;
gchar x_string[G_ASCII_DTOSTR_BUF_SIZE];
gchar y_string[G_ASCII_DTOSTR_BUF_SIZE];
gboolean closed = FALSE;
str = g_string_new (NULL);
for (strokes = vectors->strokes->head;
strokes;
strokes = strokes->next)
{
PikaStroke *stroke = strokes->data;
GArray *control_points;
PikaAnchor *anchor;
gint i;
if (closed)
g_string_append_printf (str, NEWLINE);
control_points = pika_stroke_control_points_get (stroke, &closed);
if (PIKA_IS_BEZIER_STROKE (stroke))
{
if (control_points->len >= 3)
{
anchor = &g_array_index (control_points, PikaAnchor, 1);
g_ascii_formatd (x_string, G_ASCII_DTOSTR_BUF_SIZE,
"%.2f", anchor->position.x);
g_ascii_formatd (y_string, G_ASCII_DTOSTR_BUF_SIZE,
"%.2f", anchor->position.y);
g_string_append_printf (str, "M %s,%s", x_string, y_string);
}
if (control_points->len > 3)
{
g_string_append_printf (str, NEWLINE "C");
}
for (i = 2; i < (control_points->len + (closed ? 2 : - 1)); i++)
{
if (i > 2 && i % 3 == 2)
g_string_append_printf (str, NEWLINE " ");
anchor = &g_array_index (control_points, PikaAnchor,
i % control_points->len);
g_ascii_formatd (x_string, G_ASCII_DTOSTR_BUF_SIZE,
"%.2f", anchor->position.x);
g_ascii_formatd (y_string, G_ASCII_DTOSTR_BUF_SIZE,
"%.2f", anchor->position.y);
g_string_append_printf (str, " %s,%s", x_string, y_string);
}
if (closed && control_points->len > 3)
g_string_append_printf (str, " Z");
}
else
{
g_printerr ("Unknown stroke type\n");
if (control_points->len >= 1)
{
anchor = &g_array_index (control_points, PikaAnchor, 0);
g_ascii_formatd (x_string, G_ASCII_DTOSTR_BUF_SIZE,
".2f", anchor->position.x);
g_ascii_formatd (y_string, G_ASCII_DTOSTR_BUF_SIZE,
".2f", anchor->position.y);
g_string_append_printf (str, "M %s,%s", x_string, y_string);
}
if (control_points->len > 1)
{
g_string_append_printf (str, NEWLINE "L");
}
for (i = 1; i < control_points->len; i++)
{
if (i > 1 && i % 3 == 1)
g_string_append_printf (str, NEWLINE " ");
anchor = &g_array_index (control_points, PikaAnchor, i);
g_ascii_formatd (x_string, G_ASCII_DTOSTR_BUF_SIZE,
"%.2f", anchor->position.x);
g_ascii_formatd (y_string, G_ASCII_DTOSTR_BUF_SIZE,
"%.2f", anchor->position.y);
g_string_append_printf (str, " %s,%s", x_string, y_string);
}
if (closed && control_points->len > 1)
g_string_append_printf (str, " Z");
}
g_array_free (control_points, TRUE);
}
return g_strchomp (g_string_free (str, FALSE));
}

View File

@ -0,0 +1,34 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __PIKA_VECTORS_EXPORT_H__
#define __PIKA_VECTORS_EXPORT_H__
gboolean pika_vectors_export_file (PikaImage *image,
GList *vectors,
GFile *file,
GError **error);
gchar * pika_vectors_export_string (PikaImage *image,
GList *vectors);
#endif /* __PIKA_VECTORS_IMPORT_H__ */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,48 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* PikaVectors Import
* Copyright (C) 2003 Sven Neumann <sven@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __PIKA_VECTORS_IMPORT_H__
#define __PIKA_VECTORS_IMPORT_H__
gboolean pika_vectors_import_file (PikaImage *image,
GFile *file,
gboolean merge,
gboolean scale,
PikaVectors *parent,
gint position,
GList **ret_vectors,
GError **error);
gboolean pika_vectors_import_buffer (PikaImage *image,
const gchar *buffer,
gsize len,
gboolean merge,
gboolean scale,
PikaVectors *parent,
gint position,
GList **ret_vectors,
GError **error);
#endif /* __PIKA_VECTORS_IMPORT_H__ */

View File

@ -0,0 +1,97 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <string.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "vectors-types.h"
#include "libpikamath/pikamath.h"
#include "core/pikaimage.h"
#include "core/pikatempbuf.h"
#include "pikastroke.h"
#include "pikavectors.h"
#include "pikavectors-preview.h"
/* public functions */
PikaTempBuf *
pika_vectors_get_new_preview (PikaViewable *viewable,
PikaContext *context,
gint width,
gint height)
{
PikaVectors *vectors;
PikaItem *item;
PikaStroke *cur_stroke;
gdouble xscale, yscale;
guchar *data;
PikaTempBuf *temp_buf;
vectors = PIKA_VECTORS (viewable);
item = PIKA_ITEM (viewable);
xscale = ((gdouble) width) / pika_image_get_width (pika_item_get_image (item));
yscale = ((gdouble) height) / pika_image_get_height (pika_item_get_image (item));
temp_buf = pika_temp_buf_new (width, height, babl_format ("Y' u8"));
data = pika_temp_buf_get_data (temp_buf);
memset (data, 255, width * height);
for (cur_stroke = pika_vectors_stroke_get_next (vectors, NULL);
cur_stroke;
cur_stroke = pika_vectors_stroke_get_next (vectors, cur_stroke))
{
GArray *coords;
gboolean closed;
gint i;
coords = pika_stroke_interpolate (cur_stroke, 0.5, &closed);
if (coords)
{
for (i = 0; i < coords->len; i++)
{
PikaCoords point;
gint x, y;
point = g_array_index (coords, PikaCoords, i);
x = ROUND (point.x * xscale);
y = ROUND (point.y * yscale);
if (x >= 0 && y >= 0 && x < width && y < height)
data[y * width + x] = 0;
}
g_array_free (coords, TRUE);
}
}
return temp_buf;
}

View File

@ -0,0 +1,36 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __PIKA_VECTORS_PREVIEW_H__
#define __PIKA_VECTORS_PREVIEW_H__
/*
* virtual function of PikaVectors -- don't call directly
*/
PikaTempBuf * pika_vectors_get_new_preview (PikaViewable *viewable,
PikaContext *context,
gint width,
gint height);
#endif /* __PIKA_VECTORS_PREVIEW_H__ */

View File

@ -0,0 +1,214 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* pikavectors-warp.c
* Copyright (C) 2005 Bill Skaggs <weskaggs@primate.ucdavis.edu>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "vectors-types.h"
#include "libpikamath/pikamath.h"
#include "core/pika-utils.h"
#include "core/pikacoords.h"
#include "pikaanchor.h"
#include "pikastroke.h"
#include "pikavectors.h"
#include "pikavectors-warp.h"
#define EPSILON 0.2
#define DX 2.0
static void pika_stroke_warp_point (PikaStroke *stroke,
gdouble x,
gdouble y,
PikaCoords *point_warped,
gdouble y_offset,
gdouble x_len);
static void pika_vectors_warp_stroke (PikaVectors *vectors,
PikaStroke *stroke,
gdouble y_offset);
void
pika_vectors_warp_point (PikaVectors *vectors,
PikaCoords *point,
PikaCoords *point_warped,
gdouble y_offset)
{
gdouble x = point->x;
gdouble y = point->y;
gdouble len;
GList *list;
PikaStroke *stroke;
for (list = vectors->strokes->head;
list;
list = g_list_next (list))
{
stroke = list->data;
len = pika_vectors_stroke_get_length (vectors, stroke);
if (x < len || ! list->next)
break;
x -= len;
}
if (! list)
{
point_warped->x = 0;
point_warped->y = 0;
return;
}
pika_stroke_warp_point (stroke, x, y, point_warped, y_offset, len);
}
static void
pika_stroke_warp_point (PikaStroke *stroke,
gdouble x,
gdouble y,
PikaCoords *point_warped,
gdouble y_offset,
gdouble x_len)
{
PikaCoords point_zero = { 0, };
PikaCoords point_minus = { 0, };
PikaCoords point_plus = { 0, };
gdouble slope;
gdouble dx, dy, nx, ny, len;
if (x + DX >= x_len)
{
gdouble tx, ty;
if (! pika_stroke_get_point_at_dist (stroke, x_len, EPSILON,
&point_zero, &slope))
{
point_warped->x = 0;
point_warped->y = 0;
return;
}
point_warped->x = point_zero.x;
point_warped->y = point_zero.y;
if (! pika_stroke_get_point_at_dist (stroke, x_len - DX, EPSILON,
&point_minus, &slope))
return;
dx = point_zero.x - point_minus.x;
dy = point_zero.y - point_minus.y;
len = hypot (dx, dy);
if (len < 0.01)
return;
tx = dx / len;
ty = dy / len;
nx = - dy / len;
ny = dx / len;
point_warped->x += tx * (x - x_len) + nx * (y - y_offset);
point_warped->y += ty * (x - x_len) + ny * (y - y_offset);
return;
}
if (! pika_stroke_get_point_at_dist (stroke, x, EPSILON,
&point_zero, &slope))
{
point_warped->x = 0;
point_warped->y = 0;
return;
}
point_warped->x = point_zero.x;
point_warped->y = point_zero.y;
if (! pika_stroke_get_point_at_dist (stroke, x - DX, EPSILON,
&point_minus, &slope))
return;
if (! pika_stroke_get_point_at_dist (stroke, x + DX, EPSILON,
&point_plus, &slope))
return;
dx = point_plus.x - point_minus.x;
dy = point_plus.y - point_minus.y;
len = hypot (dx, dy);
if (len < 0.01)
return;
nx = - dy / len;
ny = dx / len;
point_warped->x = point_zero.x + nx * (y - y_offset);
point_warped->y = point_zero.y + ny * (y - y_offset);
}
static void
pika_vectors_warp_stroke (PikaVectors *vectors,
PikaStroke *stroke,
gdouble y_offset)
{
GList *list;
for (list = stroke->anchors->head; list; list = g_list_next (list))
{
PikaAnchor *anchor = list->data;
pika_vectors_warp_point (vectors,
&anchor->position, &anchor->position,
y_offset);
}
}
void
pika_vectors_warp_vectors (PikaVectors *vectors,
PikaVectors *vectors_in,
gdouble y_offset)
{
GList *list;
for (list = vectors_in->strokes->head;
list;
list = g_list_next (list))
{
PikaStroke *stroke = list->data;
pika_vectors_warp_stroke (vectors, stroke, y_offset);
}
}

View File

@ -0,0 +1,40 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* pikavectors-warp.h
* Copyright (C) 2005 Bill Skaggs <weskaggs@primate.ucdavis.edu>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __PIKA_VECTORS_WARP_H__
#define __PIKA_VECTORS_WARP_H__
void pika_vectors_warp_point (PikaVectors *vectors,
PikaCoords *point,
PikaCoords *point_warped,
gdouble y_offset);
void pika_vectors_warp_vectors (PikaVectors *vectors,
PikaVectors *vectors_in,
gdouble yoffset);
#endif /* __PIKA_VECTORS_WARP_H__ */

1256
app/vectors/pikavectors.c Normal file

File diff suppressed because it is too large Load Diff

188
app/vectors/pikavectors.h Normal file
View File

@ -0,0 +1,188 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* pikavectors.h
* Copyright (C) 2002 Simon Budig <simon@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __PIKA_VECTORS_H__
#define __PIKA_VECTORS_H__
#include "core/pikaitem.h"
#define PIKA_TYPE_VECTORS (pika_vectors_get_type ())
#define PIKA_VECTORS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PIKA_TYPE_VECTORS, PikaVectors))
#define PIKA_VECTORS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PIKA_TYPE_VECTORS, PikaVectorsClass))
#define PIKA_IS_VECTORS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PIKA_TYPE_VECTORS))
#define PIKA_IS_VECTORS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PIKA_TYPE_VECTORS))
#define PIKA_VECTORS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PIKA_TYPE_VECTORS, PikaVectorsClass))
typedef struct _PikaVectorsClass PikaVectorsClass;
struct _PikaVectors
{
PikaItem parent_instance;
GQueue *strokes; /* Queue of PikaStrokes */
GHashTable *stroke_to_list; /* Map from PikaStroke to strokes listnode */
gint last_stroke_id;
gint freeze_count;
gdouble precision;
PikaBezierDesc *bezier_desc; /* Cached bezier representation */
gboolean bounds_valid; /* Cached bounding box */
gboolean bounds_empty;
gdouble bounds_x1;
gdouble bounds_y1;
gdouble bounds_x2;
gdouble bounds_y2;
};
struct _PikaVectorsClass
{
PikaItemClass parent_class;
/* signals */
void (* freeze) (PikaVectors *vectors);
void (* thaw) (PikaVectors *vectors);
/* virtual functions */
void (* stroke_add) (PikaVectors *vectors,
PikaStroke *stroke);
void (* stroke_remove) (PikaVectors *vectors,
PikaStroke *stroke);
PikaStroke * (* stroke_get) (PikaVectors *vectors,
const PikaCoords *coord);
PikaStroke * (* stroke_get_next) (PikaVectors *vectors,
PikaStroke *prev);
gdouble (* stroke_get_length) (PikaVectors *vectors,
PikaStroke *stroke);
PikaAnchor * (* anchor_get) (PikaVectors *vectors,
const PikaCoords *coord,
PikaStroke **ret_stroke);
void (* anchor_delete) (PikaVectors *vectors,
PikaAnchor *anchor);
gdouble (* get_length) (PikaVectors *vectors,
const PikaAnchor *start);
gdouble (* get_distance) (PikaVectors *vectors,
const PikaCoords *coord);
gint (* interpolate) (PikaVectors *vectors,
PikaStroke *stroke,
gdouble precision,
gint max_points,
PikaCoords *ret_coords);
PikaBezierDesc * (* make_bezier) (PikaVectors *vectors);
};
/* vectors utility functions */
GType pika_vectors_get_type (void) G_GNUC_CONST;
PikaVectors * pika_vectors_new (PikaImage *image,
const gchar *name);
PikaVectors * pika_vectors_get_parent (PikaVectors *vectors);
void pika_vectors_freeze (PikaVectors *vectors);
void pika_vectors_thaw (PikaVectors *vectors);
void pika_vectors_copy_strokes (PikaVectors *src_vectors,
PikaVectors *dest_vectors);
void pika_vectors_add_strokes (PikaVectors *src_vectors,
PikaVectors *dest_vectors);
/* accessing / modifying the anchors */
PikaAnchor * pika_vectors_anchor_get (PikaVectors *vectors,
const PikaCoords *coord,
PikaStroke **ret_stroke);
/* prev == NULL: "first" anchor */
PikaAnchor * pika_vectors_anchor_get_next (PikaVectors *vectors,
const PikaAnchor *prev);
/* type will be an xorable enum:
* VECTORS_NONE, VECTORS_FIX_ANGLE, VECTORS_FIX_RATIO, VECTORS_RESTRICT_ANGLE
* or so.
*/
void pika_vectors_anchor_move_relative (PikaVectors *vectors,
PikaAnchor *anchor,
const PikaCoords *deltacoord,
gint type);
void pika_vectors_anchor_move_absolute (PikaVectors *vectors,
PikaAnchor *anchor,
const PikaCoords *coord,
gint type);
void pika_vectors_anchor_delete (PikaVectors *vectors,
PikaAnchor *anchor);
void pika_vectors_anchor_select (PikaVectors *vectors,
PikaStroke *target_stroke,
PikaAnchor *anchor,
gboolean selected,
gboolean exclusive);
/* PikaStroke is a connected component of a PikaVectors object */
void pika_vectors_stroke_add (PikaVectors *vectors,
PikaStroke *stroke);
void pika_vectors_stroke_remove (PikaVectors *vectors,
PikaStroke *stroke);
gint pika_vectors_get_n_strokes (PikaVectors *vectors);
PikaStroke * pika_vectors_stroke_get (PikaVectors *vectors,
const PikaCoords *coord);
PikaStroke * pika_vectors_stroke_get_by_id (PikaVectors *vectors,
gint id);
/* prev == NULL: "first" stroke */
PikaStroke * pika_vectors_stroke_get_next (PikaVectors *vectors,
PikaStroke *prev);
gdouble pika_vectors_stroke_get_length (PikaVectors *vectors,
PikaStroke *stroke);
/* accessing the shape of the curve */
gdouble pika_vectors_get_length (PikaVectors *vectors,
const PikaAnchor *start);
gdouble pika_vectors_get_distance (PikaVectors *vectors,
const PikaCoords *coord);
/* returns the number of valid coordinates */
gint pika_vectors_interpolate (PikaVectors *vectors,
PikaStroke *stroke,
gdouble precision,
gint max_points,
PikaCoords *ret_coords);
/* usually overloaded */
/* returns a bezier representation */
const PikaBezierDesc * pika_vectors_get_bezier (PikaVectors *vectors);
#endif /* __PIKA_VECTORS_H__ */

View File

@ -0,0 +1,145 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "vectors-types.h"
#include "pikavectors.h"
#include "pikavectorsmodundo.h"
static void pika_vectors_mod_undo_constructed (GObject *object);
static gint64 pika_vectors_mod_undo_get_memsize (PikaObject *object,
gint64 *gui_size);
static void pika_vectors_mod_undo_pop (PikaUndo *undo,
PikaUndoMode undo_mode,
PikaUndoAccumulator *accum);
static void pika_vectors_mod_undo_free (PikaUndo *undo,
PikaUndoMode undo_mode);
G_DEFINE_TYPE (PikaVectorsModUndo, pika_vectors_mod_undo, PIKA_TYPE_ITEM_UNDO)
#define parent_class pika_vectors_mod_undo_parent_class
static void
pika_vectors_mod_undo_class_init (PikaVectorsModUndoClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
PikaObjectClass *pika_object_class = PIKA_OBJECT_CLASS (klass);
PikaUndoClass *undo_class = PIKA_UNDO_CLASS (klass);
object_class->constructed = pika_vectors_mod_undo_constructed;
pika_object_class->get_memsize = pika_vectors_mod_undo_get_memsize;
undo_class->pop = pika_vectors_mod_undo_pop;
undo_class->free = pika_vectors_mod_undo_free;
}
static void
pika_vectors_mod_undo_init (PikaVectorsModUndo *undo)
{
}
static void
pika_vectors_mod_undo_constructed (GObject *object)
{
PikaVectorsModUndo *vectors_mod_undo = PIKA_VECTORS_MOD_UNDO (object);
PikaVectors *vectors;
G_OBJECT_CLASS (parent_class)->constructed (object);
pika_assert (PIKA_IS_VECTORS (PIKA_ITEM_UNDO (object)->item));
vectors = PIKA_VECTORS (PIKA_ITEM_UNDO (object)->item);
vectors_mod_undo->vectors =
PIKA_VECTORS (pika_item_duplicate (PIKA_ITEM (vectors),
G_TYPE_FROM_INSTANCE (vectors)));
}
static gint64
pika_vectors_mod_undo_get_memsize (PikaObject *object,
gint64 *gui_size)
{
PikaVectorsModUndo *vectors_mod_undo = PIKA_VECTORS_MOD_UNDO (object);
gint64 memsize = 0;
memsize += pika_object_get_memsize (PIKA_OBJECT (vectors_mod_undo->vectors),
gui_size);
return memsize + PIKA_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
}
static void
pika_vectors_mod_undo_pop (PikaUndo *undo,
PikaUndoMode undo_mode,
PikaUndoAccumulator *accum)
{
PikaVectorsModUndo *vectors_mod_undo = PIKA_VECTORS_MOD_UNDO (undo);
PikaVectors *vectors = PIKA_VECTORS (PIKA_ITEM_UNDO (undo)->item);
PikaVectors *temp;
gint offset_x;
gint offset_y;
PIKA_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
temp = vectors_mod_undo->vectors;
vectors_mod_undo->vectors =
PIKA_VECTORS (pika_item_duplicate (PIKA_ITEM (vectors),
G_TYPE_FROM_INSTANCE (vectors)));
pika_vectors_freeze (vectors);
pika_vectors_copy_strokes (temp, vectors);
pika_item_get_offset (PIKA_ITEM (temp), &offset_x, &offset_y);
pika_item_set_offset (PIKA_ITEM (vectors), offset_x, offset_y);
pika_item_set_size (PIKA_ITEM (vectors),
pika_item_get_width (PIKA_ITEM (temp)),
pika_item_get_height (PIKA_ITEM (temp)));
g_object_unref (temp);
pika_vectors_thaw (vectors);
}
static void
pika_vectors_mod_undo_free (PikaUndo *undo,
PikaUndoMode undo_mode)
{
PikaVectorsModUndo *vectors_mod_undo = PIKA_VECTORS_MOD_UNDO (undo);
g_clear_object (&vectors_mod_undo->vectors);
PIKA_UNDO_CLASS (parent_class)->free (undo, undo_mode);
}

View File

@ -0,0 +1,56 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __PIKA_VECTORS_MOD_UNDO_H__
#define __PIKA_VECTORS_MOD_UNDO_H__
#include "core/pikaitemundo.h"
#define PIKA_TYPE_VECTORS_MOD_UNDO (pika_vectors_mod_undo_get_type ())
#define PIKA_VECTORS_MOD_UNDO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PIKA_TYPE_VECTORS_MOD_UNDO, PikaVectorsModUndo))
#define PIKA_VECTORS_MOD_UNDO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PIKA_TYPE_VECTORS_MOD_UNDO, PikaVectorsModUndoClass))
#define PIKA_IS_VECTORS_MOD_UNDO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PIKA_TYPE_VECTORS_MOD_UNDO))
#define PIKA_IS_VECTORS_MOD_UNDO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PIKA_TYPE_VECTORS_MOD_UNDO))
#define PIKA_VECTORS_MOD_UNDO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PIKA_TYPE_VECTORS_MOD_UNDO, PikaVectorsModUndoClass))
typedef struct _PikaVectorsModUndo PikaVectorsModUndo;
typedef struct _PikaVectorsModUndoClass PikaVectorsModUndoClass;
struct _PikaVectorsModUndo
{
PikaItemUndo parent_instance;
PikaVectors *vectors;
};
struct _PikaVectorsModUndoClass
{
PikaItemUndoClass parent_class;
};
GType pika_vectors_mod_undo_get_type (void) G_GNUC_CONST;
#endif /* __PIKA_VECTORS_MOD_UNDO_H__ */

View File

@ -0,0 +1,94 @@
/* Pika - Photo and Image Kooker Application
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "vectors-types.h"
#include "core/pikaimage.h"
#include "pikavectors.h"
#include "pikavectorspropundo.h"
static void pika_vectors_prop_undo_constructed (GObject *object);
static void pika_vectors_prop_undo_pop (PikaUndo *undo,
PikaUndoMode undo_mode,
PikaUndoAccumulator *accum);
G_DEFINE_TYPE (PikaVectorsPropUndo, pika_vectors_prop_undo, PIKA_TYPE_ITEM_UNDO)
#define parent_class pika_vectors_prop_undo_parent_class
static void
pika_vectors_prop_undo_class_init (PikaVectorsPropUndoClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
PikaUndoClass *undo_class = PIKA_UNDO_CLASS (klass);
object_class->constructed = pika_vectors_prop_undo_constructed;
undo_class->pop = pika_vectors_prop_undo_pop;
}
static void
pika_vectors_prop_undo_init (PikaVectorsPropUndo *undo)
{
}
static void
pika_vectors_prop_undo_constructed (GObject *object)
{
/* PikaVectors *vectors; */
G_OBJECT_CLASS (parent_class)->constructed (object);
pika_assert (PIKA_IS_VECTORS (PIKA_ITEM_UNDO (object)->item));
/* vectors = PIKA_VECTORS (PIKA_ITEM_UNDO (object)->item); */
switch (PIKA_UNDO (object)->undo_type)
{
default:
pika_assert_not_reached ();
}
}
static void
pika_vectors_prop_undo_pop (PikaUndo *undo,
PikaUndoMode undo_mode,
PikaUndoAccumulator *accum)
{
#if 0
PikaVectorsPropUndo *vectors_prop_undo = PIKA_VECTORS_PROP_UNDO (undo);
PikaVectors *vectors = PIKA_VECTORS (PIKA_ITEM_UNDO (undo)->item);
#endif
PIKA_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
switch (undo->undo_type)
{
default:
pika_assert_not_reached ();
}
}

View File

@ -0,0 +1,54 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __PIKA_VECTORS_PROP_UNDO_H__
#define __PIKA_VECTORS_PROP_UNDO_H__
#include "core/pikaitemundo.h"
#define PIKA_TYPE_VECTORS_PROP_UNDO (pika_vectors_prop_undo_get_type ())
#define PIKA_VECTORS_PROP_UNDO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PIKA_TYPE_VECTORS_PROP_UNDO, PikaVectorsPropUndo))
#define PIKA_VECTORS_PROP_UNDO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PIKA_TYPE_VECTORS_PROP_UNDO, PikaVectorsPropUndoClass))
#define PIKA_IS_VECTORS_PROP_UNDO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PIKA_TYPE_VECTORS_PROP_UNDO))
#define PIKA_IS_VECTORS_PROP_UNDO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PIKA_TYPE_VECTORS_PROP_UNDO))
#define PIKA_VECTORS_PROP_UNDO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PIKA_TYPE_VECTORS_PROP_UNDO, PikaVectorsPropUndoClass))
typedef struct _PikaVectorsPropUndo PikaVectorsPropUndo;
typedef struct _PikaVectorsPropUndoClass PikaVectorsPropUndoClass;
struct _PikaVectorsPropUndo
{
PikaItemUndo parent_instance;
};
struct _PikaVectorsPropUndoClass
{
PikaItemUndoClass parent_class;
};
GType pika_vectors_prop_undo_get_type (void) G_GNUC_CONST;
#endif /* __PIKA_VECTORS_PROP_UNDO_H__ */

View File

@ -0,0 +1,232 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "vectors-types.h"
#include "libpikabase/pikabase.h"
#include "core/pikaimage.h"
#include "pikavectors.h"
#include "pikavectorsundo.h"
enum
{
PROP_0,
PROP_PREV_PARENT,
PROP_PREV_POSITION,
PROP_PREV_VECTORS
};
static void pika_vectors_undo_constructed (GObject *object);
static void pika_vectors_undo_finalize (GObject *object);
static void pika_vectors_undo_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void pika_vectors_undo_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static gint64 pika_vectors_undo_get_memsize (PikaObject *object,
gint64 *gui_size);
static void pika_vectors_undo_pop (PikaUndo *undo,
PikaUndoMode undo_mode,
PikaUndoAccumulator *accum);
G_DEFINE_TYPE (PikaVectorsUndo, pika_vectors_undo, PIKA_TYPE_ITEM_UNDO)
#define parent_class pika_vectors_undo_parent_class
static void
pika_vectors_undo_class_init (PikaVectorsUndoClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
PikaObjectClass *pika_object_class = PIKA_OBJECT_CLASS (klass);
PikaUndoClass *undo_class = PIKA_UNDO_CLASS (klass);
object_class->constructed = pika_vectors_undo_constructed;
object_class->finalize = pika_vectors_undo_finalize;
object_class->set_property = pika_vectors_undo_set_property;
object_class->get_property = pika_vectors_undo_get_property;
pika_object_class->get_memsize = pika_vectors_undo_get_memsize;
undo_class->pop = pika_vectors_undo_pop;
g_object_class_install_property (object_class, PROP_PREV_PARENT,
g_param_spec_object ("prev-parent",
NULL, NULL,
PIKA_TYPE_VECTORS,
PIKA_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_PREV_POSITION,
g_param_spec_int ("prev-position", NULL, NULL,
0, G_MAXINT, 0,
PIKA_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_PREV_VECTORS,
g_param_spec_pointer ("prev-vectors", NULL, NULL,
PIKA_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
}
static void
pika_vectors_undo_init (PikaVectorsUndo *undo)
{
undo->prev_vectors = NULL;
}
static void
pika_vectors_undo_constructed (GObject *object)
{
G_OBJECT_CLASS (parent_class)->constructed (object);
pika_assert (PIKA_IS_VECTORS (PIKA_ITEM_UNDO (object)->item));
}
static void
pika_vectors_undo_finalize (GObject *object)
{
PikaVectorsUndo *undo = PIKA_VECTORS_UNDO (object);
g_clear_pointer (&undo->prev_vectors, g_list_free);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
pika_vectors_undo_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
PikaVectorsUndo *vectors_undo = PIKA_VECTORS_UNDO (object);
switch (property_id)
{
case PROP_PREV_PARENT:
vectors_undo->prev_parent = g_value_get_object (value);
break;
case PROP_PREV_POSITION:
vectors_undo->prev_position = g_value_get_int (value);
break;
case PROP_PREV_VECTORS:
vectors_undo->prev_vectors = g_list_copy (g_value_get_pointer (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
pika_vectors_undo_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
PikaVectorsUndo *vectors_undo = PIKA_VECTORS_UNDO (object);
switch (property_id)
{
case PROP_PREV_PARENT:
g_value_set_object (value, vectors_undo->prev_parent);
break;
case PROP_PREV_POSITION:
g_value_set_int (value, vectors_undo->prev_position);
break;
case PROP_PREV_VECTORS:
g_value_set_pointer (value, vectors_undo->prev_vectors);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static gint64
pika_vectors_undo_get_memsize (PikaObject *object,
gint64 *gui_size)
{
PikaItemUndo *item_undo = PIKA_ITEM_UNDO (object);
gint64 memsize = 0;
if (! pika_item_is_attached (item_undo->item))
memsize += pika_object_get_memsize (PIKA_OBJECT (item_undo->item),
gui_size);
return memsize + PIKA_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
}
static void
pika_vectors_undo_pop (PikaUndo *undo,
PikaUndoMode undo_mode,
PikaUndoAccumulator *accum)
{
PikaVectorsUndo *vectors_undo = PIKA_VECTORS_UNDO (undo);
PikaVectors *vectors = PIKA_VECTORS (PIKA_ITEM_UNDO (undo)->item);
PIKA_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
if ((undo_mode == PIKA_UNDO_MODE_UNDO &&
undo->undo_type == PIKA_UNDO_VECTORS_ADD) ||
(undo_mode == PIKA_UNDO_MODE_REDO &&
undo->undo_type == PIKA_UNDO_VECTORS_REMOVE))
{
/* remove vectors */
/* record the current parent and position */
vectors_undo->prev_parent = pika_vectors_get_parent (vectors);
vectors_undo->prev_position = pika_item_get_index (PIKA_ITEM (vectors));
pika_image_remove_vectors (undo->image, vectors, FALSE,
vectors_undo->prev_vectors);
}
else
{
/* restore vectors */
/* record the active vectors */
g_clear_pointer (&vectors_undo->prev_vectors, g_list_free);
vectors_undo->prev_vectors = g_list_copy (pika_image_get_selected_vectors (undo->image));
pika_image_add_vectors (undo->image, vectors,
vectors_undo->prev_parent,
vectors_undo->prev_position, FALSE);
}
}

View File

@ -0,0 +1,58 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __PIKA_VECTORS_UNDO_H__
#define __PIKA_VECTORS_UNDO_H__
#include "core/pikaitemundo.h"
#define PIKA_TYPE_VECTORS_UNDO (pika_vectors_undo_get_type ())
#define PIKA_VECTORS_UNDO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PIKA_TYPE_VECTORS_UNDO, PikaVectorsUndo))
#define PIKA_VECTORS_UNDO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PIKA_TYPE_VECTORS_UNDO, PikaVectorsUndoClass))
#define PIKA_IS_VECTORS_UNDO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PIKA_TYPE_VECTORS_UNDO))
#define PIKA_IS_VECTORS_UNDO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PIKA_TYPE_VECTORS_UNDO))
#define PIKA_VECTORS_UNDO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PIKA_TYPE_VECTORS_UNDO, PikaVectorsUndoClass))
typedef struct _PikaVectorsUndo PikaVectorsUndo;
typedef struct _PikaVectorsUndoClass PikaVectorsUndoClass;
struct _PikaVectorsUndo
{
PikaItemUndo parent_instance;
PikaVectors *prev_parent;
gint prev_position; /* former position in list */
GList *prev_vectors; /* previous selected vectors */
};
struct _PikaVectorsUndoClass
{
PikaItemUndoClass parent_class;
};
GType pika_vectors_undo_get_type (void) G_GNUC_CONST;
#endif /* __PIKA_VECTORS_UNDO_H__ */

View File

@ -0,0 +1,50 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* vectors-enums.h
* Copyright (C) 2006 Simon Budig <simon@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __VECTORS_ENUMS_H__
#define __VECTORS_ENUMS_H__
typedef enum
{
PIKA_ANCHOR_ANCHOR,
PIKA_ANCHOR_CONTROL
} PikaAnchorType;
typedef enum
{
PIKA_ANCHOR_FEATURE_NONE,
PIKA_ANCHOR_FEATURE_EDGE,
PIKA_ANCHOR_FEATURE_ALIGNED,
PIKA_ANCHOR_FEATURE_SYMMETRIC
} PikaAnchorFeatureType;
typedef enum
{
EXTEND_SIMPLE,
EXTEND_EDITABLE
} PikaVectorExtendMode;
#endif /* __VECTORS_ENUMS_H__ */

View File

@ -0,0 +1,41 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* vectors-types.h
* Copyright (C) 2002 Simon Budig <simon@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __VECTORS_TYPES_H__
#define __VECTORS_TYPES_H__
#include "core/core-types.h"
#include "vectors/vectors-enums.h"
typedef struct _PikaAnchor PikaAnchor;
typedef struct _PikaVectors PikaVectors;
typedef struct _PikaStroke PikaStroke;
typedef struct _PikaBezierStroke PikaBezierStroke;
#endif /* __VECTORS_TYPES_H__ */