The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Move objects

These changes was commited to the Birdfont repository Sat, 16 Jul 2016 13:45:51 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Sat, 16 Jul 2016 13:45:51 +0000 (15:45 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Sat, 16 Jul 2016 13:45:51 +0000 (15:45 +0200)
commit 7fa95796872f1b8f72df2c2b85eb1aa7a2e8a723
tree 2e346c6b4eb1940710681f34fa46109d4bad8f3c
parent 64507ad23ab34eb30b9193da267ca4f16e03458c
Move objects

12 files changed:
libsvgbird/Circle.vala
libsvgbird/Ellipse.vala
libsvgbird/EmptyObject.vala
libsvgbird/Layer.vala
libsvgbird/Line.vala
libsvgbird/Object.vala
libsvgbird/Polygon.vala
libsvgbird/Polyline.vala
libsvgbird/Rectangle.vala
libsvgbird/SvgDrawing.vala
libsvgbird/SvgPath.vala
--- a/libsvgbird/Circle.vala +++ b/libsvgbird/Circle.vala @@ -35,9 +35,6 @@ public override void draw_outline (Context cr) { cr.move_to (cx + r, cy); cr.arc (cx, cy, r, 0, 2 * Math.PI); - } - - public override void move (double dx, double dy) { } public override bool is_empty () {
--- a/libsvgbird/Ellipse.vala +++ b/libsvgbird/Ellipse.vala @@ -41,9 +41,6 @@ cr.move_to (1, 0); cr.arc (0, 0, 1, 0, 2 * PI); cr.restore (); - } - - public override void move (double dx, double dy) { } public override bool is_empty () {
--- a/libsvgbird/EmptyObject.vala +++ b/libsvgbird/EmptyObject.vala @@ -26,9 +26,6 @@ } public override void draw_outline (Context cr) { - } - - public override void move (double dx, double dy) { } public override bool is_empty () {
--- a/libsvgbird/Layer.vala +++ b/libsvgbird/Layer.vala @@ -51,10 +51,12 @@ if (object is Layer) { Layer sublayer = (Layer) object; + object.parent_matrix = cr.get_matrix (); sublayer.apply_transform (cr); object.view_matrix = cr.get_matrix (); has_size = sublayer.update_boundaries (cr); } else { + object.parent_matrix = cr.get_matrix (); object.apply_transform (cr); object.view_matrix = cr.get_matrix (); has_size = object.update_boundaries (cr); @@ -221,9 +223,6 @@ public override bool is_over (double x, double y) { return false; - } - - public override void move (double dx, double dy) { } public override bool is_empty () {
--- a/libsvgbird/Line.vala +++ b/libsvgbird/Line.vala @@ -42,9 +42,6 @@ cr.move_to (x1, y1); cr.line_to (x1, y1); cr.line_to (x2, y2); - } - - public override void move (double dx, double dy) { } public override bool is_empty () {
--- a/libsvgbird/Object.vala +++ b/libsvgbird/Object.vala @@ -87,6 +87,9 @@ public const double CANVAS_MAX = 100000; public const double CANVAS_MIN = -100000; + public Matrix view_matrix = Matrix.identity (); + public Matrix parent_matrix = Matrix.identity (); + public Object () { } @@ -101,15 +104,43 @@ Matrix m = view_matrix; m.invert (); m.transform_point (ref x, ref y); + } + + public void to_object_distance (ref double x, ref double y) { + Matrix m = view_matrix; + m.invert (); + m.transform_distance (ref x, ref y); } public abstract void draw_outline (Context cr); public abstract Object copy (); public abstract bool is_empty (); - public abstract void move (double dx, double dy); - public Matrix view_matrix = Matrix.identity (); + public virtual void move (double dx, double dy) { + left += dx; + right += dx; + top += dy; + bottom += dy; + to_object_distance (ref dx, ref dy); + transforms.translate (dx, dy); + update_view_matrix (); + } + + public void update_view_matrix () { + Matrix v = parent_matrix; + Matrix m = transforms.get_matrix (); + m.multiply (m, v); + view_matrix = m; + } + + public Matrix get_parent_matrix () { + Matrix matrix = view_matrix; + Matrix object_matrix = transforms.get_matrix (); + object_matrix.invert (); + matrix.multiply (matrix, object_matrix); + return matrix; + } public virtual void move_bounding_box (double dx, double dy) { top += dy;
--- a/libsvgbird/Polygon.vala +++ b/libsvgbird/Polygon.vala @@ -50,9 +50,6 @@ return inside; } - public override void move (double dx, double dy) { - } - public override bool is_empty () { return false; }
--- a/libsvgbird/Polyline.vala +++ b/libsvgbird/Polyline.vala @@ -38,9 +38,6 @@ cr.line_to (points.data[i].value, points.data[i + 1].value); } } - } - - public override void move (double dx, double dy) { } public override bool is_empty () {
--- a/libsvgbird/Rectangle.vala +++ b/libsvgbird/Rectangle.vala @@ -62,11 +62,6 @@ cr.scale (rx, ry); cr.arc (0, 0, 1, angle_start, angle_stop); cr.restore (); - } - - public override void move (double dx, double dy) { - x += dx; - y += dy; } public override bool is_empty () {
--- a/libsvgbird/SvgDrawing.vala +++ b/libsvgbird/SvgDrawing.vala @@ -83,9 +83,6 @@ } return drawing; - } - - public override void move (double dx, double dy) { } public override bool is_empty () {
--- a/libsvgbird/SvgPath.vala +++ b/libsvgbird/SvgPath.vala @@ -281,9 +281,6 @@ } cr.restore (); - } - - public override void move (double dx, double dy) { } public override bool is_empty () {