-
Notifications
You must be signed in to change notification settings - Fork 28
feat: implement dynamic key buffer system #77
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
Open
quarterstar
wants to merge
8
commits into
Prayag2:master
Choose a base branch
from
quarterstar:keybind
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
537eafb
feat: implement dynamic key buffer system
quarterstar ad625dc
build: attempt to fix kanzi windows builds with conditional compilation
quarterstar f3e5cec
Revert "build: attempt to fix kanzi windows builds with conditional c…
quarterstar 6be36ca
docs: add new shortcuts to readme
quarterstar 6dd6ad4
chore: reformat code
quarterstar 507321d
feat: .clangd file
quarterstar 2c0dabb
docs: make license header more consistent
quarterstar 4935164
fix: allow multiple shortcut combinations for a single action
quarterstar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,23 +1,23 @@ | ||
| /* | ||
| * Drawy - A simple brainstorming tool with an infinite canvas | ||
| * Copyright (C) 2025 - Prayag Jain <[email protected]> | ||
| * | ||
| * Authors: | ||
| * 1. quarterstar - [email protected] | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| * Drawy - A simple brainstorming tool with an infinite canvas | ||
| * Copyright (C) 2025 - Prayag Jain <[email protected]> | ||
| * | ||
| * Authors: | ||
| * 1. quarterstar - [email protected] | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| // NOTE: qt headers MUST be placed before | ||
| // kansi otherwise there will be a macro conflict | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,23 +1,23 @@ | ||
| /* | ||
| * Drawy - A simple brainstorming tool with an infinite canvas | ||
| * Copyright (C) 2025 - Prayag Jain <[email protected]> | ||
| * | ||
| * Authors: | ||
| * 1. quarterstar - [email protected] | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| * Drawy - A simple brainstorming tool with an infinite canvas | ||
| * Copyright (C) 2025 - Prayag Jain <[email protected]> | ||
| * | ||
| * Authors: | ||
| * 1. quarterstar - [email protected] | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
|
|
||
This file contains hidden or 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,14 @@ | ||
| #include "qt.hpp" | ||
|
|
||
| namespace Common::Utils::QtUtil { | ||
| uint64_t keyToken(const std::variant<Qt::Key, Qt::MouseButton> &v) { | ||
| uint64_t type = static_cast<uint64_t>(v.index()); // 0 = Qt::Key, 1 = Qt::MouseButton | ||
| uint64_t val = 0; | ||
| if (std::holds_alternative<Qt::Key>(v)) { | ||
| val = static_cast<uint64_t>(std::get<Qt::Key>(v)); | ||
| } else { | ||
| val = static_cast<uint64_t>(std::get<Qt::MouseButton>(v)); | ||
| } | ||
| return (type << 32) | (val & 0xffffffffULL); | ||
| } | ||
| } // namespace Common::Utils::QtUtil |
This file contains hidden or 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,10 @@ | ||
| #pragma once | ||
|
|
||
| #include <QKeyEvent> | ||
| #include <QMouseEvent> | ||
| #include <cstdint> | ||
| #include <variant> | ||
|
|
||
| namespace Common::Utils::QtUtil { | ||
| uint64_t keyToken(const std::variant<Qt::Key, Qt::MouseButton> &v); | ||
| } |
This file contains hidden or 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,24 @@ | ||
| #include "action.hpp" | ||
|
|
||
| void ToolTask::start(const TaskContext &ctx, const ActionState &state) { | ||
| m_toolBar.curTool().cleanup(); | ||
| m_canvas.setCursor(m_toolBar.tool(m_tool).cursor()); | ||
| m_toolBar.tool(m_tool).mousePressed(ctx.m_appContext); | ||
|
|
||
| // This is needed so that the thing hovered | ||
| // over the first time a press is detected is immediately | ||
| // queued for deletion. | ||
| if (!state.m_prevHeld && m_tool == Tool::Eraser) { | ||
| m_toolBar.tool(m_tool).mouseMoved(ctx.m_appContext); | ||
| } | ||
| } | ||
|
|
||
| void ToolTask::execute(const TaskContext &ctx, const ActionState &state) { | ||
| m_toolBar.tool(m_tool).mouseMoved(ctx.m_appContext); | ||
| } | ||
|
|
||
| void ToolTask::stop(const TaskContext &ctx, const ActionState &state) { | ||
| m_toolBar.tool(m_tool).mouseReleased(ctx.m_appContext); | ||
| m_toolBar.tool(m_tool).cleanup(); | ||
| m_canvas.setCursor(m_toolBar.curTool().cursor()); | ||
| } |
This file contains hidden or 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,125 @@ | ||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
| #include <memory> | ||
| #include <variant> | ||
| #include <vector> | ||
|
|
||
| #include "../canvas/canvas.hpp" | ||
| #include "../common/utils/qt.hpp" | ||
| #include "../components/toolbar.hpp" | ||
| #include "../tools/tool.hpp" | ||
|
|
||
| using namespace Common::Utils::QtUtil; | ||
|
|
||
| struct ActionKey { | ||
| std::variant<Qt::Key, Qt::MouseButton> m_id; | ||
| bool m_mouse{false}; | ||
| size_t m_count{1}; | ||
| }; | ||
|
|
||
| inline ActionKey key(Qt::MouseButton key, size_t count = 1) { | ||
| return ActionKey{.m_id = std::variant<Qt::Key, Qt::MouseButton>{key}, | ||
| .m_mouse = true, | ||
| .m_count = count}; | ||
| } | ||
|
|
||
| inline ActionKey key(Qt::Key key, size_t count = 1) { | ||
| return ActionKey{.m_id = key, .m_mouse = false, .m_count = count}; | ||
| } | ||
|
|
||
| struct ActionData { | ||
| std::vector<ActionKey> m_keys; | ||
| bool m_holdRequired{false}; | ||
| int64_t m_maxGapMs{0}; | ||
| }; | ||
|
|
||
| struct TaskContext { | ||
| ApplicationContext *m_appContext; | ||
| }; | ||
|
|
||
| struct ActionState { | ||
| bool m_prevHeld{false}; | ||
| }; | ||
|
|
||
| class IActionTask { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use the |
||
| public: | ||
| virtual void start(const TaskContext &ctx, const ActionState &state) = 0; | ||
| virtual void execute(const TaskContext &ctx, const ActionState &state) = 0; | ||
| virtual void stop(const TaskContext &ctx, const ActionState &state) = 0; | ||
|
|
||
| virtual ~IActionTask() = default; | ||
| }; | ||
|
|
||
| class ToolTask : public IActionTask { | ||
| public: | ||
| ToolTask(ToolBar &toolBar, Canvas &canvas, Tool::Type tool) | ||
| : m_toolBar(toolBar), | ||
| m_canvas(canvas), | ||
| m_tool(tool) {} | ||
|
|
||
| ToolBar &m_toolBar; | ||
| Canvas &m_canvas; | ||
|
|
||
| Tool::Type m_tool; | ||
|
|
||
| void start(const TaskContext &ctx, const ActionState &state) override; | ||
| void execute(const TaskContext &ctx, const ActionState &state) override; | ||
| void stop(const TaskContext &ctx, const ActionState &state) override; | ||
| }; | ||
|
|
||
| struct ActionFacade { | ||
| ActionFacade(std::unique_ptr<IActionTask> task, ActionData data) | ||
| : m_task(std::move(task)), | ||
| m_data(std::move(data)) {} | ||
|
|
||
| std::unique_ptr<IActionTask> m_task; | ||
| ActionData m_data; | ||
| ActionState m_state{}; | ||
| bool m_enabled{false}; | ||
|
|
||
| inline void enable(const TaskContext &ctx) { | ||
| if (m_enabled) | ||
| return; | ||
|
|
||
| if (m_task) | ||
| m_task->start(ctx, m_state); | ||
|
|
||
| m_enabled = true; | ||
| } | ||
|
|
||
| inline void execute(const TaskContext &ctx) { | ||
| if (!m_enabled || !m_task) | ||
| return; | ||
|
|
||
| m_task->execute(ctx, m_state); | ||
| } | ||
|
|
||
| inline void disable(const TaskContext &ctx) { | ||
| if (!m_enabled) | ||
| return; | ||
|
|
||
| if (m_task) | ||
| m_task->stop(ctx, m_state); | ||
|
|
||
| m_enabled = false; | ||
| } | ||
|
|
||
| inline void toggle(TaskContext ctx) { m_enabled ? disable(ctx) : enable(ctx); } | ||
| }; | ||
|
|
||
| inline std::vector<ActionFacade> getDefaultActions(ToolBar &toolbar, Canvas &canvas) { | ||
| std::vector<ActionFacade> result; | ||
|
|
||
| result.push_back(ActionFacade{ | ||
| std::make_unique<ToolTask>(toolbar, canvas, Tool::Move), | ||
| ActionData{{key(Qt::Key_Space), key(Qt::LeftButton)}, true, -2}, | ||
| }); | ||
|
|
||
| result.push_back(ActionFacade{ | ||
| std::make_unique<ToolTask>(toolbar, canvas, Tool::Eraser), | ||
| ActionData{{key(Qt::RightButton)}, true, -2}, | ||
| }); | ||
|
|
||
| return result; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class
ApplicationContextwas recently made a singleton, which means only one instance of it exists in the app. You don't have to pass its pointers anymore. Just access it by usingApplicationContext::instance().