Editor API
UnigineEditor public API
Controls.h
1 // Copyright (C), UNIGINE. All rights reserved.
2 #pragma once
3 
4 #include <editor/EditorGlobal.h>
5 
6 #include <UnigineCallback.h>
7 #include <UnigineString.h>
8 
9 
10 namespace Editor
11 {
12 
13 class EDITOR_API Controls final
14 {
15 public:
16  enum class Context
17  {
18  SHARED = 0,
19  EXCLUSIVE,
20  };
21 
23  {
24  MOUSE = 1 << 0,
25  KEYBOARD = 1 << 1,
26  WHEEL = 1 << 2,
27  MODIFIER = 1 << 3,
28  };
29 
30  enum class MouseWheel
31  {
32  NONE = 0,
33  UP,
34  DOWN,
35  RIGHT,
36  LEFT,
37  };
38 
40  {
41  NONE = 0,
42  SHIFT = 1 << 0,
43  CTRL = 1 << 1,
44  ALT = 1 << 2,
45  CMD = 1 << 3,
46  MOUSE_LEFT = 1 << 4,
47  MOUSE_RIGHT = 1 << 5,
48  MOUSE_MIDDLE = 1 << 6,
49  MOUSE_AUX_0 = 1 << 7,
50  MOUSE_AUX_1 = 1 << 8,
51  MOUSE_AUX_2 = 1 << 9,
52  MOUSE_AUX_3 = 1 << 10,
53  };
54 
55  enum class ModifierMatch
56  {
57  EXACT = 0,
58  PARTIAL,
59  };
60 
61 public:
62  // Context
63  using ContextActiveChecker = bool (*)(void *opaque);
64  static bool createContext(const char *context_id,
65  const char *title,
66  ContextActiveChecker checker,
67  void *opaque,
68  Context context_type = Context::SHARED,
69  int priority = 0);
70  // It also removes all the associated controls with it.
71  static bool removeContext(const char *context_id);
72  static bool hasContext(const char *context_id);
73 
74  // Control
75  static bool createControl(const char *control_id, const char *context_id = "global",
76  int control_flags = ControlFlag::MOUSE | ControlFlag::KEYBOARD | ControlFlag::WHEEL);
77  static bool removeControl(const char *control_id);
78  static bool hasControl(const char *control_id);
79 
80  static bool setControlTitle(const char *control_id, const char *title);
81  static bool setControlTooltip(const char *control_id, const char *tooltip);
82  // 'key' can be Unigine::App::KEY_<>, or e.g. 'x'.
83  static bool setControlKey(const char *control_id, int key);
84  // 'button' should be Unigine::App::BUTTON_<>
85  static bool setControlMouseButton(const char *control_id, int mouse_button);
86  static bool setControlMouseWheel(const char *control_id, MouseWheel wheel);
87  // 'modifier_flags' should be made from ModifierFlag::<>
88  static bool setControlModifierFlags(const char *control_id, int modifier_flags);
89  static bool setControlModifierMatch(const char *control_id, ModifierMatch modifier_match);
90 
91  static bool setControlActivatedCallback(const char *control_id, Unigine::CallbackBase *func);
92  static bool setControlPressedCallback(const char *control_id, Unigine::CallbackBase *func);
93  static bool setControlReleasedCallback(const char *control_id, Unigine::CallbackBase *func);
94 
95  static bool addControlFriend(const char *control_id, const char *friend_control_id);
96  static bool removeControlFriend(const char *control_id, const char *friend_control_id);
97 
98  static bool isControlPressed(const char *control_id);
99  static bool isControlDown(const char *control_id);
100  static bool isControlUp(const char *control_id);
101 
102  static Unigine::String getControlShortcutText(const char *control_id);
103 };
104 
105 } // namespace Editor
Context
Definition: Controls.h:16
Definition: Actions.h:11
Definition: Controls.h:13
ControlFlag
Definition: Controls.h:22
ModifierMatch
Definition: Controls.h:55
MouseWheel
Definition: Controls.h:30
bool(*)(void *opaque) ContextActiveChecker
Definition: Controls.h:63
ModifierFlag
Definition: Controls.h:39