-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d688c5
commit d08c201
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |