Skip to content

Commit

Permalink
Move any type of item
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip-Scott committed Oct 22, 2018
1 parent cd742bf commit 3f3c335
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class Phi.Application : Granite.Application {

canvas = new Phi.ResponsiveCanvas ();
canvas.set_size_request (600, 600);
canvas.set_scale (2.0);
canvas.set_scale (1.232412);
canvas.set_bounds (0, 0, 10000, 10000);

var root = canvas.get_root_item ();
Expand All @@ -70,6 +70,8 @@ public class Phi.Application : Granite.Application {
"stroke-color", "#9bdb4d",
"fill-color", "#68b723");

var text = Goo.CanvasText.create (root, "Add text here", 20, 20, 200, Goo.CanvasAnchorType.NW, "font", "Open Sans 18");

window.add (canvas);
window.show_all ();

Expand Down
18 changes: 7 additions & 11 deletions src/ResponsiveCanvas.vala
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public class Phi.ResponsiveCanvas : Goo.Canvas {
selected_item = get_item_at (event.x / current_scale, event.y / current_scale, true);

if (selected_item != null) {
if (selected_item is Goo.CanvasRect) {
start_x = (selected_item as Goo.CanvasRect).x;
start_y = (selected_item as Goo.CanvasRect).y;
if (selected_item is Goo.CanvasItemSimple) {
start_x = (selected_item as Goo.CanvasItemSimple).x;
start_y = (selected_item as Goo.CanvasItemSimple).y;
}

holding = true;
Expand Down Expand Up @@ -90,16 +90,12 @@ public class Phi.ResponsiveCanvas : Goo.Canvas {

public override bool motion_notify_event (Gdk.EventMotion event) {
if (holding) {
double x = (event.x - event_x_root) / current_scale;
double y = (event.y - event_y_root) / current_scale;
delta_x = (event.x - event_x_root) / current_scale;
delta_y = (event.y - event_y_root) / current_scale;
switch (holding_id) {
case 0: // Moving
delta_x = x;
delta_y = y;
((Goo.CanvasRect) selected_item).x = delta_x + start_x;
((Goo.CanvasRect) selected_item).y = delta_y + start_y;
print (@"$x $y\n");

((Goo.CanvasItemSimple) selected_item).x = delta_x + start_x;
((Goo.CanvasItemSimple) selected_item).y = delta_y + start_y;
break;
// case 1: // Top left
// delta_x = fix_position (x, real_width, start_w);
Expand Down
5 changes: 5 additions & 0 deletions vapi/goocanvas-2.0.vapi
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,11 @@ namespace Goo {
public Goo.CairoPattern stroke_pattern { owned get; set; }
[NoAccessorMethod]
public Gdk.Pixbuf stroke_pixbuf { set; }
[NoAccessorMethod]
public virtual double x { get; set; }
[NoAccessorMethod]
public virtual double y { get ; set; }

}
[CCode (cheader_filename = "goocanvas.h", ref_function = "goo_canvas_line_dash_ref", type_id = "GOO_TYPE_CANVAS_LINE_DASH", unref_function = "goo_canvas_line_dash_unref")]
[Compact]
Expand Down

0 comments on commit 3f3c335

Please sign in to comment.