diff --git a/src/app/ui/editor/moving_cel_state.cpp b/src/app/ui/editor/moving_cel_state.cpp index 12c489f8e..2142053c6 100644 --- a/src/app/ui/editor/moving_cel_state.cpp +++ b/src/app/ui/editor/moving_cel_state.cpp @@ -17,6 +17,7 @@ #include "app/context_access.h" #include "app/doc_api.h" #include "app/doc_range.h" +#include "app/snap_to_grid.h" #include "app/tx.h" #include "app/ui/editor/editor.h" #include "app/ui/editor/editor_customization_delegate.h" @@ -125,6 +126,7 @@ MovingCelState::MovingCelState(Editor* editor, &MovingCelState::onBeforeCommandExecution, this); m_cursorStart = editor->screenToEditorF(msg->position()); + calcPivot(); editor->captureMouse(); // Hide the mask (temporarily, until mouse-up event) @@ -156,6 +158,10 @@ bool MovingCelState::onMouseUp(Editor* editor, MouseMessage* msg) Tx tx(writer, "Cel Movement", ModifyDocument); DocApi api = document->getApi(tx); gfx::Point intOffset = intCelOffset(); + bool snapToGrid = (Preferences::instance().selection.snapToGrid() && + m_editor->docPref().grid.snap()); + if (snapToGrid) + snapOffsetToGrid(intOffset); // And now we move the cel (or all selected range) to the new position. for (Cel* cel : m_celList) { @@ -168,6 +174,9 @@ bool MovingCelState::onMouseUp(Editor* editor, MouseMessage* msg) celBounds.w *= m_celScale.w; celBounds.h *= m_celScale.h; } + if (snapToGrid) + snapBoundsToGrid(celBounds); + tx(new cmd::SetCelBoundsF(cel, celBounds)); } else { @@ -224,6 +233,17 @@ bool MovingCelState::onMouseMove(Editor* editor, MouseMessage* msg) return StandbyState::onMouseMove(editor, msg); } +void MovingCelState::calcPivot() +{ + // Get grid displacement from pivot point, for now hardcoded + // to be relative to initial position + m_fullBounds = calcFullBounds(); + m_pivot = gfx::PointF(0,0); + const gfx::RectF& gridBounds = m_editor->getSite().gridBounds(); + m_pivotOffset = gfx::PointF( + gridBounds.size()) - (m_pivot-m_fullBounds.origin()); +} + void MovingCelState::onCommitMouseMove(Editor* editor, const gfx::PointF& newCursorPos) { @@ -262,6 +282,10 @@ void MovingCelState::onCommitMouseMove(Editor* editor, } gfx::Point intOffset = intCelOffset(); + bool snapToGrid = (Preferences::instance().selection.snapToGrid() && + m_editor->docPref().grid.snap()); + if (snapToGrid) + snapOffsetToGrid(intOffset); for (size_t i=0; isetBoundsF(celBounds); } else { @@ -367,6 +394,45 @@ gfx::RectF MovingCelState::calcFullBounds() const return bounds; } +void MovingCelState::snapOffsetToGrid(gfx::Point& offset) const +{ + const gfx::RectF& gridBounds = m_editor->getSite().gridBounds(); + const gfx::RectF displaceGrid(gridBounds.origin() + m_pivotOffset, + gridBounds.size()); + offset = snap_to_grid( + displaceGrid, + gfx::Point(m_fullBounds.origin() + offset), + PreferSnapTo::ClosestGridVertex) - m_fullBounds.origin(); +} + +void MovingCelState::snapBoundsToGrid(gfx::RectF& celBounds) const +{ + const gfx::RectF& gridBounds = m_editor->getSite().gridBounds(); + const gfx::RectF displaceGrid(gridBounds.origin() + m_pivotOffset, + gridBounds.size()); + const gfx::PointF& origin = celBounds.origin(); + if (m_scaled) { + gfx::PointF gridOffset( + snap_to_grid( + displaceGrid, + gfx::Point(origin.x + celBounds.w, + origin.y + celBounds.h), + PreferSnapTo::ClosestGridVertex) - origin); + + celBounds.w = std::max(gridBounds.w, gridOffset.x); + celBounds.h = std::max(gridBounds.h, gridOffset.y); + } + else if (m_moved) { + gfx::PointF gridOffset( + snap_to_grid( + displaceGrid, + gfx::Point(origin), + PreferSnapTo::ClosestGridVertex)); + + celBounds.setOrigin(gridOffset); + } +} + bool MovingCelState::restoreCelStartPosition() const { bool modified = false; diff --git a/src/app/ui/editor/moving_cel_state.h b/src/app/ui/editor/moving_cel_state.h index 5bc98f58a..ddceacd0c 100644 --- a/src/app/ui/editor/moving_cel_state.h +++ b/src/app/ui/editor/moving_cel_state.h @@ -58,7 +58,10 @@ namespace app { private: gfx::Point intCelOffset() const; gfx::RectF calcFullBounds() const; + void calcPivot(); bool restoreCelStartPosition() const; + void snapOffsetToGrid(gfx::Point& offset) const; + void snapBoundsToGrid(gfx::RectF& celBounds) const; // ContextObserver void onBeforeCommandExecution(CommandExecutionEvent& ev); @@ -71,7 +74,10 @@ namespace app { Cel* m_cel; CelList m_celList; std::vector m_celStarts; + gfx::RectF m_fullBounds; gfx::PointF m_cursorStart; + gfx::PointF m_pivot; + gfx::PointF m_pivotOffset; gfx::PointF m_celOffset; gfx::SizeF m_celMainSize; gfx::SizeF m_celScale; diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index d628c4406..f5c013dad 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -57,6 +57,7 @@ endif() if(REQUIRE_CURL AND NOT USE_SHARED_CURL) set(BUILD_RELEASE_DEBUG_DIRS ON BOOL) set(BUILD_CURL_EXE OFF CACHE BOOL "Set to ON to build curl executable.") + set(CURL_DISABLE_TESTS ON CACHE BOOL "Disable Curl tests") add_subdirectory(curl) endif() @@ -200,17 +201,10 @@ if(ENABLE_SCRIPTING) target_compile_definitions(lua PUBLIC LUA_USE_LINUX=1) endif() - # Compile Lua as C++ to control errors with exceptions and have - # stack unwinding (i.e. calling destructors correctly). - if(MSVC) - target_compile_options(lua PRIVATE -TP) - target_compile_options(lualib PRIVATE -TP) - target_compile_options(lauxlib PRIVATE -TP) - else() - target_compile_options(lua PRIVATE -xc++) - target_compile_options(lualib PRIVATE -xc++) - target_compile_options(lauxlib PRIVATE -xc++) - endif() + # Compile Lua C files as C++ to control errors with exceptions and + # have stack unwinding (i.e. calling destructors correctly). + file(GLOB all_lua_source_files lua/*.c) + set_source_files_properties(${all_lua_source_files} PROPERTIES LANGUAGE CXX) target_compile_definitions(lua PUBLIC LUA_FLOORN2I=F2Ifloor) target_compile_definitions(lualib PRIVATE HAVE_SYSTEM)