diff --git a/src/DrawingProgram/DrawingProgramCache.cpp b/src/DrawingProgram/DrawingProgramCache.cpp index ca17de7..feb12f6 100644 --- a/src/DrawingProgram/DrawingProgramCache.cpp +++ b/src/DrawingProgram/DrawingProgramCache.cpp @@ -335,16 +335,28 @@ void DrawingProgramCache::refresh_draw_cache(const std::shared_ptrbounds.dim(); //std::cout << "\niMin: " << iBounds.min.x() << " " << iBounds.min.y() << "\niMax: " << iBounds.max.x() << " " << iBounds.max.y() << "\nbMin: " << bvhNode->bounds.min.x() << " " << bvhNode->bounds.min.y() << "\nbMax: " << bvhNode->bounds.max.x() << " " << bvhNode->bounds.max.y() << "\nbDim: " << bDim.x() << " " << bDim.y(); + Vector2f clipBoundMin{static_cast((iBounds.min.x() - bvhNode->bounds.min.x()) / bDim.x()) * bvhNode->resolution.x(), static_cast((iBounds.min.y() - bvhNode->bounds.min.y()) / bDim.y()) * bvhNode->resolution.y()}; Vector2f clipBoundMax{static_cast((iBounds.max.x() - bvhNode->bounds.min.x()) / bDim.x()) * bvhNode->resolution.x(), static_cast((iBounds.max.y() - bvhNode->bounds.min.y()) / bDim.y()) * bvhNode->resolution.y()}; - SkRect clipRect = SkRect::MakeLTRB(clipBoundMin.x(), clipBoundMin.y(), clipBoundMax.x(), clipBoundMax.y()); + + SkIRect clipRect = SkIRect::MakeLTRB(std::max(clipBoundMin.x() - 2, 0), + std::max(clipBoundMin.y() - 2, 0), + std::min(clipBoundMax.x() + 2, bvhNode->resolution.x() - 1), + std::min(clipBoundMax.y() + 2, bvhNode->resolution.y() - 1)); + + SCollision::AABB clipRectBoundAABB{clipBoundMin - Vector2f{4, 4}, clipBoundMax + Vector2f{4, 4}}; + SCollision::AABB clipRectBoundAABBWorld{ + bvhNode->coords.from_space(clipRectBoundAABB.min), + bvhNode->coords.from_space(clipRectBoundAABB.max) + }; + //std::cout << "\ncMin: " << clipBoundMin.x() << " " << clipBoundMin.y() << "\ncMax: " << clipBoundMax.x() << " " << clipBoundMax.y() << std::endl; cacheCanvas->save(); - cacheCanvas->clipRect(clipRect); + cacheCanvas->clipIRect(clipRect); cacheCanvas->clear(SkColor4f{0, 0, 0, 0}); - draw_components_to_canvas(cacheCanvas, cacheDrawData, &drawCache.lastDrawnComponentPlacement, drawCache.invalidBounds); + draw_components_to_canvas(cacheCanvas, cacheDrawData, &drawCache.lastDrawnComponentPlacement, clipRectBoundAABBWorld); cacheCanvas->restore(); drawCache.invalidBounds = std::nullopt; } diff --git a/src/DrawingProgram/EditTool.cpp b/src/DrawingProgram/EditTool.cpp index 2f9d41f..fd548a6 100644 --- a/src/DrawingProgram/EditTool.cpp +++ b/src/DrawingProgram/EditTool.cpp @@ -140,9 +140,9 @@ void EditTool::tool_update() { Vector2f newPos = a->coords.get_mouse_pos(drawP.world); if(newPos != *controls.pointDragging->p) { if(controls.pointDragging->min) - newPos = cwise_vec_max(*controls.pointDragging->min, newPos); + newPos = cwise_vec_max((*controls.pointDragging->min + Vector2f{controls.pointDragging->minimumDistanceBetweenBoundsAndPoint, controls.pointDragging->minimumDistanceBetweenBoundsAndPoint}).eval(), newPos); if(controls.pointDragging->max) - newPos = cwise_vec_min(*controls.pointDragging->max, newPos); + newPos = cwise_vec_min((*controls.pointDragging->max - Vector2f{controls.pointDragging->minimumDistanceBetweenBoundsAndPoint, controls.pointDragging->minimumDistanceBetweenBoundsAndPoint}).eval(), newPos); *controls.pointDragging->p = newPos; a->commit_update(drawP); a->client_send_update(drawP); diff --git a/src/DrawingProgram/EditTool.hpp b/src/DrawingProgram/EditTool.hpp index 710d49b..f14b27b 100644 --- a/src/DrawingProgram/EditTool.hpp +++ b/src/DrawingProgram/EditTool.hpp @@ -13,6 +13,7 @@ class EditTool : public DrawingProgramToolBase { Vector2f* p; Vector2f* min; Vector2f* max; + float minimumDistanceBetweenBoundsAndPoint = 1.0f; }; EditTool(DrawingProgram& initDrawP);