Merge branch 'main' into beta

This commit is contained in:
David Capello 2021-08-13 14:47:56 -03:00
commit 74e9a73f48
8 changed files with 60 additions and 10 deletions

2
laf

@ -1 +1 @@
Subproject commit d76cc1af5564ed510fb31270d06f36dc1e426f40
Subproject commit 67daddc2801975328f3665c49e1f03344ab85d22

View File

@ -1453,6 +1453,17 @@ gfx::Point Editor::screenToEditor(const gfx::Point& pt)
m_proj.removeY(pt.y - vp.y + scroll.y - m_padding.y));
}
gfx::Point Editor::screenToEditorCeiling(const gfx::Point& pt)
{
View* view = View::getView(this);
Rect vp = view->viewportBounds();
Point scroll = view->viewScroll();
return gfx::Point(
m_proj.removeXCeiling(pt.x - vp.x + scroll.x - m_padding.x),
m_proj.removeYCeiling(pt.y - vp.y + scroll.y - m_padding.y));
}
gfx::PointF Editor::screenToEditorF(const gfx::Point& pt)
{
View* view = View::getView(this);
@ -1487,7 +1498,7 @@ Rect Editor::screenToEditor(const Rect& rc)
{
return gfx::Rect(
screenToEditor(rc.origin()),
screenToEditor(rc.point2()));
screenToEditorCeiling(rc.point2()));
}
Rect Editor::editorToScreen(const Rect& rc)

View File

@ -179,6 +179,7 @@ namespace app {
//
// TODO we should rename these functions to displayToEditor() and editorToDisplay()
gfx::Point screenToEditor(const gfx::Point& pt);
gfx::Point screenToEditorCeiling(const gfx::Point& pt);
gfx::PointF screenToEditorF(const gfx::Point& pt);
gfx::Point editorToScreen(const gfx::Point& pt);
gfx::PointF editorToScreenF(const gfx::PointF& pt);

View File

@ -12,6 +12,8 @@
#include "app/ui/editor/moving_selection_state.h"
#include "app/cmd/set_mask_position.h"
#include "app/commands/command.h"
#include "app/commands/commands.h"
#include "app/context_access.h"
#include "app/tx.h"
#include "app/ui/editor/editor.h"
@ -31,6 +33,7 @@ MovingSelectionState::MovingSelectionState(Editor* editor, MouseMessage* msg)
: m_editor(editor)
, m_cursorStart(editor->screenToEditor(msg->position()))
, m_selOrigin(editor->document()->mask()->bounds().origin())
, m_selectionCanceled(false)
{
editor->captureMouse();
@ -42,6 +45,12 @@ MovingSelectionState::MovingSelectionState(Editor* editor, MouseMessage* msg)
void MovingSelectionState::onBeforeCommandExecution(CommandExecutionEvent& ev)
{
if (ev.command()->id() == CommandId::Cancel()) {
// We cancel the cancel command to avoid calling the inputChain()->cancel(), which
// deselects the selection.
ev.cancel();
m_selectionCanceled = true;
}
m_editor->backToPreviousState();
m_editor->releaseMouse();
}
@ -66,18 +75,29 @@ EditorState::LeaveAction MovingSelectionState::onLeaveState(Editor* editor, Edit
m_selOrigin.y);
mask->unfreeze();
{
ContextWriter writer(UIContext::instance(), 1000);
Tx tx(writer.context(), "Move Selection Edges", DoesntModifyDocument);
tx(new cmd::SetMaskPosition(doc, newOrigin));
tx.commit();
if (m_selectionCanceled) {
doc->resetTransformation();
doc->generateMaskBoundaries();
}
else {
{
ContextWriter writer(UIContext::instance(), 1000);
Tx tx(writer.context(), "Move Selection Edges", DoesntModifyDocument);
tx(new cmd::SetMaskPosition(doc, newOrigin));
tx.commit();
}
doc->resetTransformation();
}
doc->resetTransformation();
doc->notifyGeneralUpdate();
return StandbyState::onLeaveState(editor, newState);
}
void MovingSelectionState::onBeforePopState(Editor* editor)
{
m_ctxConn.disconnect();
StandbyState::onBeforePopState(editor);
}
bool MovingSelectionState::onMouseDown(Editor* editor, MouseMessage* msg)
{
// Do nothing

View File

@ -26,6 +26,7 @@ namespace app {
virtual bool onMouseMove(Editor* editor, ui::MouseMessage* msg) override;
virtual bool onSetCursor(Editor* editor, const gfx::Point& mouseScreenPos) override;
virtual bool onUpdateStatusBar(Editor* editor) override;
virtual void onBeforePopState(Editor* editor) override;
virtual bool requireBrushPreview() override { return false; }
private:
@ -37,6 +38,7 @@ namespace app {
gfx::Point m_selOrigin;
gfx::Point m_delta;
obs::scoped_connection m_ctxConn;
bool m_selectionCanceled;
};
} // namespace app

View File

@ -438,7 +438,7 @@ protected:
gfx::Region viewportRegion;
e->getDrawableRegion(viewportRegion, Widget::kCutTopWindows);
for (auto rc : viewportRegion) {
gfx::Region subrgn(e->screenToEditor(rc).inflate(1, 1));
gfx::Region subrgn(e->screenToEditor(rc));
e->collapseRegionByTiledMode(subrgn);
m_allVisibleRgn |= subrgn;
}

View File

@ -49,6 +49,12 @@ namespace render {
template<typename T>
T removeY(T y) const { return m_zoom.remove<T>(y) / T(m_pixelRatio.h); }
template<typename T>
T removeXCeiling(T x) const { return T(m_zoom.removeCeiling(x)) / T(m_pixelRatio.w); }
template<typename T>
T removeYCeiling(T y) const { return T(m_zoom.removeCeiling(y)) / T(m_pixelRatio.h); }
gfx::Rect apply(const gfx::Rect& r) const {
int u = applyX(r.x);
int v = applyY(r.y);

View File

@ -32,6 +32,8 @@ namespace render {
template<typename T>
T remove(T x) const { return (x * m_den / m_num); }
int removeCeiling(int x) const;
gfx::Rect apply(const gfx::Rect& r) const;
gfx::Rect remove(const gfx::Rect& r) const;
@ -78,6 +80,14 @@ namespace render {
return (x * m_den / m_num);
}
inline int Zoom::removeCeiling(int x) const {
int v = x * m_den;
if (x < 0)
return (v / m_num);
else
return (v / m_num) + (v % m_num != 0);
}
inline gfx::Rect Zoom::apply(const gfx::Rect& r) const {
return gfx::Rect(
apply(r.x), apply(r.y),