Skip to content

Commit

Permalink
Revert "Improve artboard item selection (akiraux#400)"
Browse files Browse the repository at this point in the history
This reverts commit abd76a9.
  • Loading branch information
guillotjulien committed Aug 14, 2020
1 parent 6fe3c08 commit ba081f0
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 65 deletions.
3 changes: 1 addition & 2 deletions data/com.github.akiraux.akira.appdata.xml.in.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@
<releases>
<release version="0.0.12" date="2020-08-11">
<description>
<p>Bug fixes and Artboards improvements</p>
<p>Bug fixes and improvements</p>
<ul>
<li>Items inside Artboards are masked when extending outside the edges of the Artboard.</li>
<li>Fix items reordering with the layers panel drag and drop</li>
<li>Fix random segfault at startup while setting accelerators</li>
<li>Updated goocanvas vapi</li>
Expand Down
1 change: 0 additions & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
com.github.akiraux.akira (0.0.12) xenial; urgency=medium

* Items inside Artboards are masked when extending outside the edges of the Artboard.
* Fix items reordering with the layers panel drag and drop.
* Fix random segfault at startup while setting accelerators.
* Updated goocanvas vapi.
Expand Down
2 changes: 1 addition & 1 deletion src/Lib/Canvas.vala
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public class Akira.Lib.Canvas : Goo.Canvas {

switch (uppercase_keyval) {
case Gdk.Key.Escape:
edit_mode = EditMode.MODE_SELECTION;
edit_mode = Akira.Lib.Canvas.EditMode.MODE_SELECTION;
// Clear the selected export area to be sure to not leave anything behind.
export_manager.clear ();
break;
Expand Down
108 changes: 58 additions & 50 deletions src/Lib/Models/CanvasArtboard.vala
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,28 @@ public class Akira.Lib.Models.CanvasArtboard : Goo.CanvasItemSimple, Goo.CanvasI
&& y <= bounds.y2;
}

public bool is_outside (Models.CanvasItem item) {
var x1 = item.get_global_coord ("x");
var x2 = x1 + item.get_coords ("width");
var y1 = item.get_global_coord ("y");
var y2 = y1 + item.get_coords ("height");

return x1 < bounds.x1
|| x2 > bounds.x2
|| y1 < bounds.y1
|| y2 > bounds.y2;
}

public bool dropped_inside (Models.CanvasItem item) {
return item.bounds_manager.x1 < bounds.x2
&& item.bounds_manager.x2 > bounds.x1
&& item.bounds_manager.y1 < bounds.y2
&& item.bounds_manager.y2 > bounds.y1;
var x1 = item.get_global_coord ("x");
var x2 = x1 + item.get_coords ("width");
var y1 = item.get_global_coord ("y");
var y2 = y1 + item.get_coords ("height");

return x1 < bounds.x2
&& x2 > bounds.x1
&& y1 < bounds.y2
&& y2 > bounds.y1;
}

public void add_child (Goo.CanvasItem item, int position = -1) {
Expand All @@ -178,19 +195,26 @@ public class Akira.Lib.Models.CanvasArtboard : Goo.CanvasItemSimple, Goo.CanvasI
Cairo.ImageSurface surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, 290, 256);
Cairo.Context cr = new Cairo.Context (surface);

cr.select_font_face ("Sans", Cairo.FontSlant.NORMAL, Cairo.FontWeight.NORMAL);
cr.select_font_face (
"Sans",
Cairo.FontSlant.NORMAL,
Cairo.FontWeight.NORMAL
);

cr.set_font_size (LABEL_FONT_SIZE / (canvas as Lib.Canvas).current_scale);

cr.text_extents (id, out label_extents);
}

public override void simple_update (Cairo.Context cr) {
bounds.x1 = x;
bounds.y1 = y - get_label_height ();
bounds.y1 = y - label_extents.height - LABEL_BOTTOM_PADDING;
bounds.x2 = x + width;
bounds.y2 = y + height;
}

public override void simple_paint (Cairo.Context cr, Goo.CanvasBounds bounds) {
bool force_redraw = false;
cr.set_source_rgba (0, 0, 0, 0.6);

if (settings.dark_theme) {
Expand All @@ -204,59 +228,51 @@ public class Akira.Lib.Models.CanvasArtboard : Goo.CanvasItemSimple, Goo.CanvasI
cr.move_to (x, y - LABEL_BOTTOM_PADDING);
cr.show_text (name != null ? name : id);

// Mask items outside Artboard.
cr.rectangle (x, y, width, height);
cr.clip ();

cr.rectangle (x, y, width, height);
cr.set_source_rgba (1, 1, 1, 1);
cr.rectangle (x, y, width, height);
cr.fill ();

if (items.get_n_items () > 0) {
var items_length = items.get_n_items ();

// Painting items in reversed order in order to
// print last item inserted (top of the stack) on top
// of the items inserted before.
// of the items inserted before
for (var i = 0; i < items_length; i++) {
var item = items[items_length - 1 - i];

var canvas_item = item as Goo.CanvasItemSimple;
if (canvas_item == null || item.visibility != Goo.CanvasItemVisibility.VISIBLE) {
continue;
// Check if the item is partially outside.
if (is_outside (item)) {
force_redraw = true;
}

cr.save ();

cr.transform (item.compute_transform (Cairo.Matrix.identity ()));
item.bounds_manager.update ();

var canvas_item = item as Goo.CanvasItemSimple;

if (canvas_item != null && item.visibility == Goo.CanvasItemVisibility.VISIBLE) {
canvas_item.simple_paint (cr, bounds);
}

// TEMPORARILY REMOVED.
// This won't work until the official goocanvas PPA gets the fixed VAPI.
// Clip the item if it comes with a path mask.
// if (canvas_item.simple_data.clip_path_commands != null) {
// Goo.Canvas.create_path (canvas_item.simple_data.clip_path_commands, cr);
// Cairo.FillRule fill_rule =
// canvas_item.simple_data.clip_fill_rule == 0
// ? Cairo.FillRule.EVEN_ODD
// : Cairo.FillRule.WINDING;

// cr.set_fill_rule (fill_rule);
// cr.clip ();
// }

canvas_item.simple_paint (cr, bounds);
cr.restore ();
}

item.bounds_manager.update ();
if (force_redraw) {
canvas.queue_draw ();
}
}
}

public override bool simple_is_item_at (double x, double y, Cairo.Context cr, bool is_pointer_event) {
// To select an Artboard you should put the arrow over the Artboard label.
// To select an Artboard you should put the arrow
// over the Artboard label
return y < 0
&& y > - get_label_height ()
&& y > - (label_extents.height + LABEL_BOTTOM_PADDING)
&& x > 0
&& x < label_extents.width;
&& x < (label_extents.width);
}

public double get_label_height () {
Expand All @@ -271,21 +287,6 @@ public class Akira.Lib.Models.CanvasArtboard : Goo.CanvasItemSimple, Goo.CanvasI
bool parent_is_visible,
GLib.List<Goo.CanvasItem> found_items
) {
// Check if the item needs a paint update.
if (need_update == 1) {
ensure_updated ();
}

// Skip the item if the point isn't in the item's bounds.
if (bounds.x1 > x || bounds.x2 < x || bounds.y1 > y || bounds.y2 < y) {
return found_items;
}

// Skip the item if is not visible or locked.
if (visibility != Goo.CanvasItemVisibility.VISIBLE || locked == true) {
return found_items;
}

var artboard_x = x;
var artboard_y = y;

Expand All @@ -296,7 +297,14 @@ public class Akira.Lib.Models.CanvasArtboard : Goo.CanvasItemSimple, Goo.CanvasI
}

foreach (Lib.Models.CanvasItem item in items) {
if (item.simple_is_item_at (x, y, cr, is_pointer_event)) {
var item_x = x;
var item_y = y;

canvas.convert_to_item_space (item, ref item_x, ref item_y);

var item_is_inside = item.simple_is_item_at (x, y, cr, is_pointer_event);

if (item_is_inside) {
found_items.append (item);
}
}
Expand Down
41 changes: 32 additions & 9 deletions src/Lib/Models/CanvasItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,17 @@ public interface Akira.Lib.Models.CanvasItem : Goo.CanvasItemSimple, Goo.CanvasI
return transform;
}

public virtual double get_global_coord (string coord_id) {
switch (coord_id) {
case "x":
return bounds_manager.x1;
case "y":
return bounds_manager.y1;
default:
return 0.0;
}
}

public virtual void reset_colors () {
reset_fill ();
reset_border ();
Expand Down Expand Up @@ -358,16 +369,28 @@ public interface Akira.Lib.Models.CanvasItem : Goo.CanvasItemSimple, Goo.CanvasI
border_color = rgba_stroke;
}

/*
* TODO: This method needs to account for the actual path of the item and not
* just the bounding box. I don't know if this is possible directly with goocanvas
* or it needs some cairo trickery to make it work.
*/
public bool simple_is_item_at (double x, double y, Cairo.Context cr, bool is_pointer_event) {
return x >= bounds_manager.x1
&& x <= bounds_manager.x2
&& y >= bounds_manager.y1
&& y <= bounds_manager.y2;
var width = get_coords ("width");
var height = get_coords ("height");

var item_x = relative_x;
var item_y = relative_y;

canvas.convert_from_item_space (
artboard,
ref item_x,
ref item_y);

if (
x >= item_x
&& x <= item_x + width
&& y >= item_y
&& y <= item_y + height
) {
return true;
}

return false;
}

// Update the size ratio to respect the updated size.
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/AffineTransform.vala
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ public class Akira.Utils.AffineTransform : Object {

double item_width = item.get_coords ("width");
double item_height = item.get_coords ("height");
double item_x = item.bounds_manager.x1;
double item_y = item.bounds_manager.y1;
double item_x = item.get_global_coord ("x");
double item_y = item.get_global_coord ("y");

double new_width = 0;
double new_height = 0;
Expand Down

0 comments on commit ba081f0

Please sign in to comment.