Skip to content

Commit

Permalink
Split control/tools/StrokeHandler into view and controller
Browse files Browse the repository at this point in the history
  • Loading branch information
bhennion committed Sep 19, 2022
1 parent 96d5c2d commit 52fdd28
Show file tree
Hide file tree
Showing 13 changed files with 569 additions and 264 deletions.
5 changes: 5 additions & 0 deletions src/core/control/tools/BaseShapeHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ void BaseShapeHandler::modifyModifiersByDrawDir(double width, double height, dou

auto BaseShapeHandler::getShape() const -> const std::vector<Point>& { return this->shape; }

auto BaseShapeHandler::createView(const xoj::view::Repaintable* parent) const
-> std::unique_ptr<xoj::view::OverlayView> {
return std::make_unique<xoj::view::ShapeToolView>(this, parent);
}

auto BaseShapeHandler::getViewPool() const
-> const std::shared_ptr<xoj::util::DispatchPool<xoj::view::ShapeToolView>>& {
return viewPool;
Expand Down
4 changes: 4 additions & 0 deletions src/core/control/tools/BaseShapeHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class DispatchPool;
}

namespace xoj::view {
class OverlayView;
class Repaintable;
class ShapeToolView;
};

Expand All @@ -56,6 +58,8 @@ class BaseShapeHandler: public InputHandler {
void onButtonDoublePressEvent(const PositionInputData& pos, double zoom) override;
bool onKeyEvent(GdkEventKey* event) override;

std::unique_ptr<xoj::view::OverlayView> createView(const xoj::view::Repaintable* parent) const override;

const std::shared_ptr<xoj::util::DispatchPool<xoj::view::ShapeToolView>>& getViewPool() const;

/**
Expand Down
7 changes: 7 additions & 0 deletions src/core/control/tools/InputHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class Point;
class Stroke;
class PositionInputData;

namespace xoj::view {
class OverlayView;
class Repaintable;
}; // namespace xoj::view

/**
* @brief A base class to handle pointer input
*
Expand Down Expand Up @@ -89,6 +94,8 @@ class InputHandler: public OverlayBase {
*/
virtual void onSequenceCancelEvent() = 0;

virtual std::unique_ptr<xoj::view::OverlayView> createView(const xoj::view::Repaintable* parent) const = 0;

Stroke* getStroke() const;

/**
Expand Down
11 changes: 11 additions & 0 deletions src/core/control/tools/SplineHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#pragma once

#include <memory> // for unique_ptr
#include <optional> // for optional
#include <vector> // for vector

Expand All @@ -22,6 +23,7 @@
#include "model/Point.h" // for Point
#include "util/Rectangle.h" // for Rectangle
#include "view/StrokeView.h"
#include "view/overlays/OverlayView.h"

#include "InputHandler.h" // for InputHandler
#include "SnapToGridInputHandler.h" // for SnapToGridInputHandler
Expand All @@ -30,6 +32,11 @@ class PositionInputData;
class LegacyRedrawable;
class XournalView;

namespace xoj::view {
class OverlayView;
class Repaintable;
} // namespace xoj::view

/**
* @brief A class to handle splines
*
Expand All @@ -51,6 +58,10 @@ class SplineHandler: public InputHandler {

void draw(cairo_t* cr) override;

std::unique_ptr<xoj::view::OverlayView> createView(const xoj::view::Repaintable* parent) const override {
return nullptr;
}

void onSequenceCancelEvent() override;
bool onMotionNotifyEvent(const PositionInputData& pos, double zoom) override;
void onButtonReleaseEvent(const PositionInputData& pos, double zoom) override;
Expand Down

0 comments on commit 52fdd28

Please sign in to comment.