Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit StrokeManager use to stroke tools #1814

Merged
merged 3 commits into from
Mar 9, 2024

Conversation

J5lx
Copy link
Member

@J5lx J5lx commented Mar 8, 2024

While looking at the little glitch I discovered when reviewing #1806, I realised that there are quite a few components that indirectly rely on StrokeManager despite not even dealing with strokes and not requiring any StrokeManager functionality, in particular the non-stroke tools. In many of those cases, StrokeManager is used from somewhere within pointer event handling code to obtain the current cursor position even though that position is readily available from the event object.

This PR replaces those StrokeManager usages and moves StrokeManager instance from ScribbleArea to StrokeTool (where it is actually needed). This way:

  • Non-stroke tools are more self-contained with one less dependency to worry about
  • It is clearer where position data is coming from (e.g. event->canvasPos() vs getCurrentPoint()) as there is one less layer of indirection
  • ScribbleArea no longer has to concern itself with the concept of strokes as it’s left entirely to StrokeTool and its subclasses

Additional changes:

  • StrokeManager renamed to StrokeInterpolator to clearly distinguish it from BaseManager-derived classes and because SomethingManager is always a rather vague name
  • For convenience, PointerEvent now has canvasPos in addition to posF (now viewportPos), similar to how QMouseEvent has localPos, windowPos and globalPos
  • Fixed a bug where the camera tool showed the wrong cursor when dragging a path point after navigating away from a camera keyframe while hovering over one of the camera handles

Although the number of changes in this PR is relatively higher, many of them are fairly trivial. After submitting the PR, I’ll leave some comments on the few changes that might be less obvious.

@@ -591,8 +589,6 @@ void ScribbleArea::tabletEvent(QTabletEvent *e)
if (event.eventType() == PointerEvent::Press)
{
event.accept();
mStrokeManager->pointerPressEvent(&event);
mStrokeManager->setTabletInUse(true);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pointer events now passed to strokemanager from stroke tools, tabletinuse now managed implicitly by strokemanager

selectionTolerance);
mCamPathMoveMode = mode;
if (mode != CameraMoveType::NONE)
mCamMoveMode = getPathMoveMode(cam,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using a single move mode attribute for simplicity, since movemode values for camera handles and path handles are different this is not an issue

@@ -117,7 +118,7 @@ QCursor CameraTool::cursor()

QImage moveTypeImage;
QPoint offset = QPoint(6, 6);
switch(moveMode())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move mode now updated in response to pointer events

LayerCamera* layerCam = mEditor->layers()->getCameraLayerBelow(mEditor->currentLayerIndex());
Q_ASSERT(layerCam);
mode = mEditor->overlays()->getMoveModeForPoint(getCurrentPoint(), layerCam->getViewAtFrame(mEditor->currentFrame()));
mPerspMode = mode;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perspmode now updated in pointer event handlers

@@ -45,7 +45,6 @@ QCursor SelectTool::cursor()
// Don't update cursor while we're moving the selection
if (mScribbleArea->isPointerInUse()) { return QCursor(mCursorPixmap); }

mEditor->select()->setMoveModeForAnchorInRange(getCurrentPoint());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already called in pointer event handlers, no need to do it again here

@MrStevns MrStevns self-assigned this Mar 8, 2024
QPoint pos() const;
* Returns the QPointF of the device, in canvas coordinates
*/
QPointF canvasPos() const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
QPointF canvasPos() const;
const QPointF& canvasPos() const;

Copy link
Member

@MrStevns MrStevns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A much appreciated decoupling that I have thought about doing so many times.
Excellent that you got around doing it!

I've looked through the code and it looks good to me, well aside from some suggestions about reference access but that's minor stuff.

My reason for neither approving nor requesting changes is that I'd like to hear your thoughts about the PointerEvent part that I mentioned before concluding my review. Is it more important that we're decoupled from ViewManager but have higher potential for creating mapping bugs when initializing PointerEvent, than either introducing a interface that sets the expectation for how the points are mapped or depend on ViewManager explicitly? 🤔

Speaking of testing the changes myself, I've tried to use all the different tools with layer combinations and it works as expected, good job 👍

Copy link
Member Author

@J5lx J5lx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing 🙏

core_lib/src/tool/stroketool.h Show resolved Hide resolved
core_lib/src/util/pointerevent.cpp Show resolved Hide resolved
Copy link
Member

@MrStevns MrStevns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! If you're done, you may merge it

@J5lx J5lx added this to the v0.6.7 milestone Mar 9, 2024
@J5lx J5lx merged commit 4fb9b97 into pencil2d:master Mar 9, 2024
8 checks passed
@J5lx J5lx deleted the refactoring/strokemanager branch March 9, 2024 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

2 participants