Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/settings/input_event_configuration_dialog.h
9913 views
1
/**************************************************************************/
2
/* input_event_configuration_dialog.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "scene/gui/dialogs.h"
34
35
class OptionButton;
36
class Tree;
37
class EventListenerLineEdit;
38
class CheckBox;
39
40
// Confirmation Dialog used when configuring an input event.
41
// Separate from ActionMapEditor for code cleanliness and separation of responsibilities.
42
class InputEventConfigurationDialog : public ConfirmationDialog {
43
GDCLASS(InputEventConfigurationDialog, ConfirmationDialog)
44
private:
45
struct IconCache {
46
Ref<Texture2D> keyboard;
47
Ref<Texture2D> mouse;
48
Ref<Texture2D> joypad_button;
49
Ref<Texture2D> joypad_axis;
50
} icon_cache;
51
52
Ref<InputEvent> event;
53
Ref<InputEvent> original_event;
54
55
bool in_tree_update = false;
56
57
// Listening for input
58
EventListenerLineEdit *event_listener = nullptr;
59
Label *event_as_text = nullptr;
60
61
// List of All Key/Mouse/Joypad input options.
62
int allowed_input_types;
63
Tree *input_list_tree = nullptr;
64
LineEdit *input_list_search = nullptr;
65
66
// Additional Options, shown depending on event selected
67
VBoxContainer *additional_options_container = nullptr;
68
69
HBoxContainer *device_container = nullptr;
70
OptionButton *device_id_option = nullptr;
71
72
HBoxContainer *mod_container = nullptr; // Contains the subcontainer and the store command checkbox.
73
74
enum ModCheckbox {
75
MOD_ALT,
76
MOD_SHIFT,
77
MOD_CTRL,
78
MOD_META,
79
MOD_MAX
80
};
81
#if defined(MACOS_ENABLED)
82
String mods[MOD_MAX] = { "Option", "Shift", "Ctrl", "Command" };
83
#elif defined(WINDOWS_ENABLED)
84
String mods[MOD_MAX] = { "Alt", "Shift", "Ctrl", "Windows" };
85
#else
86
String mods[MOD_MAX] = { "Alt", "Shift", "Ctrl", "Meta" };
87
#endif
88
String mods_tip[MOD_MAX] = {
89
TTRC("Alt or Option key"),
90
TTRC("Shift key"),
91
TTRC("Control key"),
92
TTRC("Meta/Windows or Command key"),
93
};
94
95
CheckBox *mod_checkboxes[MOD_MAX];
96
CheckBox *autoremap_command_or_control_checkbox = nullptr;
97
98
enum KeyMode {
99
KEYMODE_KEYCODE,
100
KEYMODE_PHY_KEYCODE,
101
KEYMODE_UNICODE,
102
};
103
104
OptionButton *key_mode = nullptr;
105
106
HBoxContainer *location_container = nullptr;
107
OptionButton *key_location = nullptr;
108
109
void _set_event(const Ref<InputEvent> &p_event, const Ref<InputEvent> &p_original_event, bool p_update_input_list_selection = true);
110
void _on_listen_input_changed(const Ref<InputEvent> &p_event);
111
112
void _search_term_updated(const String &p_term);
113
void _update_input_list();
114
void _input_list_item_activated();
115
void _input_list_item_selected();
116
117
void _mod_toggled(bool p_checked, int p_index);
118
void _autoremap_command_or_control_toggled(bool p_checked);
119
void _key_mode_selected(int p_mode);
120
void _key_location_selected(int p_location);
121
122
void _device_selection_changed(int p_option_button_index);
123
void _set_current_device(int p_device);
124
int _get_current_device() const;
125
126
protected:
127
void _notification(int p_what);
128
129
public:
130
// Pass an existing event to configure it. Alternatively, pass no event to start with a blank configuration.
131
// An action name can be passed for descriptive purposes.
132
void popup_and_configure(const Ref<InputEvent> &p_event = Ref<InputEvent>(), const String &p_current_action_name = "");
133
Ref<InputEvent> get_event() const;
134
135
void set_allowed_input_types(int p_type_masks);
136
137
InputEventConfigurationDialog();
138
};
139
140