diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Canvas.cpp | 20 | ||||
-rw-r--r-- | src/canvas-base.c | 52 | ||||
-rw-r--r-- | src/ganv-private.h | 3 |
3 files changed, 24 insertions, 51 deletions
diff --git a/src/Canvas.cpp b/src/Canvas.cpp index 68d3ea3..45835e0 100644 --- a/src/Canvas.cpp +++ b/src/Canvas.cpp @@ -875,9 +875,11 @@ GanvCanvasImpl::layout_calculate(double dur, bool update) vec_mult(node->impl->force, dur)); node->impl->vel = vec_mult(node->impl->vel, damp); + static const double MAX_VEL = 2000.0; + static const double MIN_COORD = 4.0; + // Clamp velocity - const double vel_mag = vec_mag(node->impl->vel); - static const double MAX_VEL = 2000.0; + const double vel_mag = vec_mag(node->impl->vel); if (vel_mag > MAX_VEL) { node->impl->vel = vec_mult( vec_mult(node->impl->vel, 1.0 / vel_mag), @@ -885,8 +887,20 @@ GanvCanvasImpl::layout_calculate(double dur, bool update) } // Update position + GanvItem* item = GANV_ITEM(node); + const double x0 = item->x; + const double y0 = item->y; const Vector dpos = vec_mult(node->impl->vel, dur); - if (ganv_item_move_update(GANV_ITEM(node), dpos.x, dpos.y, update)) { + + item->x = std::max(MIN_COORD, item->x + dpos.x); + item->y = std::max(MIN_COORD, item->y + dpos.y); + + if (update) { + ganv_item_request_update(item); + item->canvas->need_repick = TRUE; + } + + if (lrint(x0) != lrint(item->x) || lrint(y0) != lrint(item->y)) { ++n_moved; } } diff --git a/src/canvas-base.c b/src/canvas-base.c index 662aab6..afd81b6 100644 --- a/src/canvas-base.c +++ b/src/canvas-base.c @@ -415,62 +415,24 @@ ganv_item_lower(GanvItem* item) --item->layer; } -gboolean -ganv_item_move_update(GanvItem* item, double dx, double dy, gboolean update) -{ - if (item == NULL || !GANV_IS_ITEM(item)) { - return FALSE; - } - - const double old_x = item->x; - const double old_y = item->y; - - item->x += dx; - item->y += dy; - - static const double MIN_COORD = 4.0; - if (item->x < MIN_COORD) { - item->x = MIN_COORD; - } - if (item->y < MIN_COORD) { - item->y = MIN_COORD; - } - - const gboolean moved = (lrint(old_x) != lrint(item->x) || - lrint(old_y) != lrint(item->y)); - - if (update) { - ganv_item_request_update(item); - item->canvas->need_repick = TRUE; - } - - return moved; -} - /** * ganv_item_move: * @item: A canvas item. * @dx: Horizontal offset. * @dy: Vertical offset. **/ -gboolean +void ganv_item_move(GanvItem* item, double dx, double dy) { - const double old_x = item->x; - const double old_y = item->y; - - if (!ganv_item_move_update(item, dx, dy, FALSE)) { - return FALSE; + if (!item || !GANV_IS_ITEM(item)) { + return; } - if (lrint(old_x) != lrint(item->x) || - lrint(old_y) != lrint(item->y)) { - ganv_item_request_update(item); - item->canvas->need_repick = TRUE; - return TRUE; - } + item->x += dx; + item->y += dy; - return FALSE; + ganv_item_request_update(item); + item->canvas->need_repick = TRUE; } /** diff --git a/src/ganv-private.h b/src/ganv-private.h index 5540898..1bbdddd 100644 --- a/src/ganv-private.h +++ b/src/ganv-private.h @@ -203,9 +203,6 @@ ganv_item_i2w_offset(GanvItem* item, double* px, double* py); void ganv_item_i2w_pair(GanvItem* item, double* x1, double* y1, double* x2, double* y2); -gboolean -ganv_item_move_update(GanvItem* item, double dx, double dy, gboolean update); - void ganv_item_invoke_update(GanvItem* item, int flags); |