Skip to content

Commit

Permalink
Add tool interface skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Nov 18, 2023
1 parent 1d688c5 commit d08c201
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
28 changes: 28 additions & 0 deletions modules/core/inc/tactile/core/tool/mouse_event.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2023 Albin Johansson (GNU General Public License v3.0)

#pragma once

#include "tactile/core/api.hpp"
#include "tactile/core/math/vector.hpp"
#include "tactile/core/prelude.hpp"

namespace tactile {

/**
* \brief Simply represents different mouse buttons.
*/
enum class MouseButton : int8 {
kLeft,
kMiddle,
kRight
};

/**
* \brief Provides information about a mouse event, used by tool implementations.
*/
struct TACTILE_CORE_API MouseEvent final {
MouseButton button; ///< The active mouse button.
Float2 position; ///< The current mouse position.
};

} // namespace tactile
64 changes: 64 additions & 0 deletions modules/core/inc/tactile/core/tool/tool.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (C) 2023 Albin Johansson (GNU General Public License v3.0)

#pragma once

#include "tactile/core/api.hpp"
#include "tactile/core/prelude.hpp"
#include "tactile/core/tool/mouse_event.hpp"

namespace tactile {

/**
* \interface ITool
* \brief Interface for editor tool implementations.
*/
class TACTILE_CORE_API ITool {
public:
TACTILE_INTERFACE_CLASS(ITool);

/**
* \brief Called whenever the tool is enabled (activated).
*/
virtual void on_enable() = 0;

/**
* \brief Called whenever the tool is disabled (deactivated).
*
* \details This function is always called before a tool switch happens. The same is
* not guaranteed for other functions. For example, `on_mouse_pressed` is not
* necessarily followed by a `on_mouse_released` call. Therefore, tool
* implementations should reset any in-flight state in this function.
*/
virtual void on_disable() = 0;

/**
* \brief Called whenever the mouse is pressed in the document.
*
* \param event the mouse event information.
*/
virtual void on_mouse_pressed(const MouseEvent& event) = 0;

/**
* \brief Called whenever the mouse is dragged (while being pressed) in the document.
*
* \param event the mouse event information.
*/
virtual void on_mouse_dragged(const MouseEvent& event) = 0;

/**
* \brief Called whenever the mouse is released in the document.
*
* \param event the mouse event information.
*/
virtual void on_mouse_released(const MouseEvent& event) = 0;

/**
* \brief Indicates whether the tool is currently usable.
*
* \return true if the tool can be used; false otherwise.
*/
[[nodiscard]]
virtual auto is_usable() const -> bool = 0;
};

} // namespace tactile

0 comments on commit d08c201

Please sign in to comment.