2018-07-18 10:53:08 +08:00
|
|
|
// Aseprite
|
2025-01-07 07:21:51 +08:00
|
|
|
// Copyright (C) 2018-2025 Igara Studio S.A.
|
2018-07-18 10:53:08 +08:00
|
|
|
// Copyright (C) 2001-2018 David Capello
|
|
|
|
//
|
|
|
|
// This program is distributed under the terms of
|
|
|
|
// the End-User License Agreement for Aseprite.
|
|
|
|
|
|
|
|
#ifndef APP_UI_KEY_H_INCLUDED
|
|
|
|
#define APP_UI_KEY_H_INCLUDED
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "app/commands/params.h"
|
|
|
|
#include "app/ui/key_context.h"
|
|
|
|
#include "base/convert_to.h"
|
2022-03-09 07:40:11 +08:00
|
|
|
#include "base/vector2d.h"
|
2025-01-07 07:21:51 +08:00
|
|
|
#include "ui/shortcut.h"
|
2018-07-18 10:53:08 +08:00
|
|
|
|
|
|
|
#include <memory>
|
2022-04-14 09:46:48 +08:00
|
|
|
#include <utility>
|
2018-07-18 10:53:08 +08:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
class Message;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace app {
|
|
|
|
class Command;
|
2018-07-24 02:15:04 +08:00
|
|
|
class KeyboardShortcuts;
|
2024-12-16 21:10:34 +08:00
|
|
|
|
2018-07-18 10:53:08 +08:00
|
|
|
namespace tools {
|
|
|
|
class Tool;
|
|
|
|
}
|
2024-12-16 21:10:34 +08:00
|
|
|
|
2018-07-18 10:53:08 +08:00
|
|
|
enum class KeySource { Original, ExtensionDefined, UserDefined };
|
2024-12-16 21:10:34 +08:00
|
|
|
|
2018-07-18 10:53:08 +08:00
|
|
|
enum class KeyType {
|
|
|
|
Command,
|
|
|
|
Tool,
|
|
|
|
Quicktool,
|
|
|
|
Action,
|
2018-07-20 10:05:14 +08:00
|
|
|
WheelAction,
|
2022-03-09 07:40:11 +08:00
|
|
|
DragAction,
|
2018-07-18 10:53:08 +08:00
|
|
|
};
|
2024-12-16 21:10:34 +08:00
|
|
|
|
2018-07-18 10:53:08 +08:00
|
|
|
// TODO This should be called "KeyActionModifier" or something similar
|
|
|
|
enum class KeyAction {
|
|
|
|
None = 0x00000000,
|
|
|
|
CopySelection = 0x00000001,
|
|
|
|
SnapToGrid = 0x00000002,
|
|
|
|
AngleSnap = 0x00000004,
|
|
|
|
MaintainAspectRatio = 0x00000008,
|
|
|
|
LockAxis = 0x00000010,
|
|
|
|
AddSelection = 0x00000020,
|
|
|
|
SubtractSelection = 0x00000040,
|
2018-10-27 01:04:08 +08:00
|
|
|
IntersectSelection = 0x00000080,
|
|
|
|
AutoSelectLayer = 0x00000100,
|
|
|
|
LeftMouseButton = 0x00000200,
|
|
|
|
RightMouseButton = 0x00000400,
|
|
|
|
StraightLineFromLastPoint = 0x00000800,
|
|
|
|
MoveOrigin = 0x00001000,
|
|
|
|
SquareAspect = 0x00002000,
|
|
|
|
DrawFromCenter = 0x00004000,
|
|
|
|
ScaleFromCenter = 0x00008000,
|
|
|
|
AngleSnapFromLastPoint = 0x00010000,
|
|
|
|
RotateShape = 0x00020000,
|
2020-09-19 06:29:43 +08:00
|
|
|
FineControl = 0x00040000,
|
2018-07-18 10:53:08 +08:00
|
|
|
};
|
2024-12-16 21:10:34 +08:00
|
|
|
|
2018-07-20 10:05:14 +08:00
|
|
|
enum class WheelAction {
|
|
|
|
None,
|
|
|
|
Zoom,
|
|
|
|
VScroll,
|
|
|
|
HScroll,
|
|
|
|
FgColor,
|
|
|
|
BgColor,
|
2021-09-22 21:51:10 +08:00
|
|
|
FgTile,
|
|
|
|
BgTile,
|
2018-07-20 10:05:14 +08:00
|
|
|
Frame,
|
|
|
|
BrushSize,
|
|
|
|
BrushAngle,
|
|
|
|
ToolSameGroup,
|
|
|
|
ToolOtherGroup,
|
|
|
|
Layer,
|
2022-03-11 03:08:56 +08:00
|
|
|
InkType,
|
2018-07-20 10:05:14 +08:00
|
|
|
InkOpacity,
|
|
|
|
LayerOpacity,
|
|
|
|
CelOpacity,
|
|
|
|
Alpha,
|
|
|
|
HslHue,
|
|
|
|
HslSaturation,
|
|
|
|
HslLightness,
|
|
|
|
HsvHue,
|
|
|
|
HsvSaturation,
|
|
|
|
HsvValue,
|
2024-12-16 21:10:34 +08:00
|
|
|
|
2018-07-20 10:05:14 +08:00
|
|
|
// Range
|
|
|
|
First = Zoom,
|
|
|
|
Last = HsvValue,
|
|
|
|
};
|
2024-12-16 21:10:34 +08:00
|
|
|
|
2018-07-18 10:53:08 +08:00
|
|
|
inline KeyAction operator&(KeyAction a, KeyAction b)
|
|
|
|
{
|
|
|
|
return KeyAction(int(a) & int(b));
|
|
|
|
}
|
2024-12-16 21:10:34 +08:00
|
|
|
|
2022-03-09 07:40:11 +08:00
|
|
|
class Key;
|
|
|
|
using KeyPtr = std::shared_ptr<Key>;
|
|
|
|
using Keys = std::vector<KeyPtr>;
|
2025-01-07 07:21:51 +08:00
|
|
|
using KeySourceShortcutList = std::vector<std::pair<KeySource, ui::Shortcut>>;
|
2022-03-09 07:40:11 +08:00
|
|
|
using DragVector = base::Vector2d<double>;
|
2024-12-16 21:10:34 +08:00
|
|
|
|
2018-07-18 10:53:08 +08:00
|
|
|
class Key {
|
|
|
|
public:
|
2022-04-14 09:46:48 +08:00
|
|
|
Key(const Key& key);
|
2020-09-19 06:29:43 +08:00
|
|
|
Key(Command* command, const Params& params, const KeyContext keyContext);
|
|
|
|
Key(const KeyType type, tools::Tool* tool);
|
|
|
|
explicit Key(const KeyAction action, const KeyContext keyContext);
|
|
|
|
explicit Key(const WheelAction action);
|
2022-03-09 07:40:11 +08:00
|
|
|
static KeyPtr MakeDragAction(WheelAction dragAction);
|
2024-12-16 21:10:34 +08:00
|
|
|
|
2018-07-18 10:53:08 +08:00
|
|
|
KeyType type() const { return m_type; }
|
2025-01-07 07:21:51 +08:00
|
|
|
const ui::Shortcuts& shortcuts() const;
|
|
|
|
const KeySourceShortcutList& addsKeys() const { return m_adds; }
|
|
|
|
const KeySourceShortcutList& delsKeys() const { return m_dels; }
|
|
|
|
|
|
|
|
void add(const ui::Shortcut& shortcut, KeySource source, KeyboardShortcuts& globalKeys);
|
|
|
|
const ui::Shortcut* isPressed(const ui::Message* msg, KeyContext keyContext) const;
|
|
|
|
const ui::Shortcut* isPressed(const ui::Message* msg) const;
|
2018-07-18 10:53:08 +08:00
|
|
|
bool isPressed() const;
|
|
|
|
bool isLooselyPressed() const;
|
2024-12-24 04:01:43 +08:00
|
|
|
bool isCommandListed() const;
|
2024-12-16 21:10:34 +08:00
|
|
|
|
2025-01-07 07:21:51 +08:00
|
|
|
bool hasShortcut(const ui::Shortcut& shortcut) const;
|
|
|
|
bool hasUserDefinedShortcuts() const;
|
2024-12-16 21:10:34 +08:00
|
|
|
|
2022-04-14 09:46:48 +08:00
|
|
|
// The KeySource indicates from where the key was disabled
|
|
|
|
// (e.g. if it was removed from an extension-defined file, or from
|
|
|
|
// user-defined).
|
2025-01-07 07:21:51 +08:00
|
|
|
void disableShortcut(const ui::Shortcut& shortcut, KeySource source);
|
2024-12-16 21:10:34 +08:00
|
|
|
|
2025-01-07 07:21:51 +08:00
|
|
|
// Resets user shortcuts to the original & extension-defined ones.
|
2018-07-18 10:53:08 +08:00
|
|
|
void reset();
|
2024-12-16 21:10:34 +08:00
|
|
|
|
2018-07-20 10:05:14 +08:00
|
|
|
void copyOriginalToUser();
|
2024-12-16 21:10:34 +08:00
|
|
|
|
2018-07-18 10:53:08 +08:00
|
|
|
// for KeyType::Command
|
|
|
|
Command* command() const { return m_command; }
|
|
|
|
const Params& params() const { return m_params; }
|
|
|
|
KeyContext keycontext() const { return m_keycontext; }
|
|
|
|
// for KeyType::Tool or Quicktool
|
|
|
|
tools::Tool* tool() const { return m_tool; }
|
|
|
|
// for KeyType::Action
|
|
|
|
KeyAction action() const { return m_action; }
|
2022-03-09 07:40:11 +08:00
|
|
|
// for KeyType::WheelAction / KeyType::DragAction
|
2018-07-20 10:05:14 +08:00
|
|
|
WheelAction wheelAction() const { return m_wheelAction; }
|
2022-03-09 07:40:11 +08:00
|
|
|
// for KeyType::DragAction
|
|
|
|
DragVector dragVector() const { return m_dragVector; }
|
|
|
|
void setDragVector(const DragVector& v) { m_dragVector = v; }
|
2024-12-16 21:10:34 +08:00
|
|
|
|
2018-07-18 10:53:08 +08:00
|
|
|
std::string triggerString() const;
|
2024-12-16 21:10:34 +08:00
|
|
|
|
2018-07-18 10:53:08 +08:00
|
|
|
private:
|
|
|
|
KeyType m_type;
|
2025-01-07 07:21:51 +08:00
|
|
|
KeySourceShortcutList m_adds;
|
|
|
|
KeySourceShortcutList m_dels;
|
|
|
|
// Final list of shortcuts after processing the
|
2022-04-14 09:46:48 +08:00
|
|
|
// addition/deletion of extension-defined & user-defined keys.
|
2025-01-07 07:21:51 +08:00
|
|
|
mutable std::unique_ptr<ui::Shortcuts> m_shortcuts;
|
2018-07-18 10:53:08 +08:00
|
|
|
KeyContext m_keycontext;
|
2024-12-16 21:10:34 +08:00
|
|
|
|
2018-07-18 10:53:08 +08:00
|
|
|
// for KeyType::Command
|
|
|
|
Command* m_command;
|
|
|
|
Params m_params;
|
2024-12-16 21:10:34 +08:00
|
|
|
|
2022-03-09 07:40:11 +08:00
|
|
|
tools::Tool* m_tool; // for KeyType::Tool or Quicktool
|
|
|
|
KeyAction m_action; // for KeyType::Action
|
|
|
|
WheelAction m_wheelAction; // for KeyType::WheelAction / DragAction
|
|
|
|
DragVector m_dragVector; // for KeyType::DragAction
|
|
|
|
};
|
2024-12-16 21:10:34 +08:00
|
|
|
|
2018-07-18 10:53:08 +08:00
|
|
|
std::string convertKeyContextToUserFriendlyString(KeyContext keyContext);
|
|
|
|
|
|
|
|
} // namespace app
|
|
|
|
|
|
|
|
namespace base {
|
|
|
|
|
|
|
|
template<>
|
|
|
|
app::KeyAction convert_to(const std::string& from);
|
|
|
|
template<>
|
|
|
|
std::string convert_to(const app::KeyAction& from);
|
|
|
|
|
2018-07-20 10:05:14 +08:00
|
|
|
template<>
|
|
|
|
app::WheelAction convert_to(const std::string& from);
|
|
|
|
template<>
|
|
|
|
std::string convert_to(const app::WheelAction& from);
|
|
|
|
|
2018-07-18 10:53:08 +08:00
|
|
|
} // namespace base
|
|
|
|
|
|
|
|
#endif
|