Path: blob/master/editor/settings/input_event_configuration_dialog.h
9913 views
/**************************************************************************/1/* input_event_configuration_dialog.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "scene/gui/dialogs.h"3334class OptionButton;35class Tree;36class EventListenerLineEdit;37class CheckBox;3839// Confirmation Dialog used when configuring an input event.40// Separate from ActionMapEditor for code cleanliness and separation of responsibilities.41class InputEventConfigurationDialog : public ConfirmationDialog {42GDCLASS(InputEventConfigurationDialog, ConfirmationDialog)43private:44struct IconCache {45Ref<Texture2D> keyboard;46Ref<Texture2D> mouse;47Ref<Texture2D> joypad_button;48Ref<Texture2D> joypad_axis;49} icon_cache;5051Ref<InputEvent> event;52Ref<InputEvent> original_event;5354bool in_tree_update = false;5556// Listening for input57EventListenerLineEdit *event_listener = nullptr;58Label *event_as_text = nullptr;5960// List of All Key/Mouse/Joypad input options.61int allowed_input_types;62Tree *input_list_tree = nullptr;63LineEdit *input_list_search = nullptr;6465// Additional Options, shown depending on event selected66VBoxContainer *additional_options_container = nullptr;6768HBoxContainer *device_container = nullptr;69OptionButton *device_id_option = nullptr;7071HBoxContainer *mod_container = nullptr; // Contains the subcontainer and the store command checkbox.7273enum ModCheckbox {74MOD_ALT,75MOD_SHIFT,76MOD_CTRL,77MOD_META,78MOD_MAX79};80#if defined(MACOS_ENABLED)81String mods[MOD_MAX] = { "Option", "Shift", "Ctrl", "Command" };82#elif defined(WINDOWS_ENABLED)83String mods[MOD_MAX] = { "Alt", "Shift", "Ctrl", "Windows" };84#else85String mods[MOD_MAX] = { "Alt", "Shift", "Ctrl", "Meta" };86#endif87String mods_tip[MOD_MAX] = {88TTRC("Alt or Option key"),89TTRC("Shift key"),90TTRC("Control key"),91TTRC("Meta/Windows or Command key"),92};9394CheckBox *mod_checkboxes[MOD_MAX];95CheckBox *autoremap_command_or_control_checkbox = nullptr;9697enum KeyMode {98KEYMODE_KEYCODE,99KEYMODE_PHY_KEYCODE,100KEYMODE_UNICODE,101};102103OptionButton *key_mode = nullptr;104105HBoxContainer *location_container = nullptr;106OptionButton *key_location = nullptr;107108void _set_event(const Ref<InputEvent> &p_event, const Ref<InputEvent> &p_original_event, bool p_update_input_list_selection = true);109void _on_listen_input_changed(const Ref<InputEvent> &p_event);110111void _search_term_updated(const String &p_term);112void _update_input_list();113void _input_list_item_activated();114void _input_list_item_selected();115116void _mod_toggled(bool p_checked, int p_index);117void _autoremap_command_or_control_toggled(bool p_checked);118void _key_mode_selected(int p_mode);119void _key_location_selected(int p_location);120121void _device_selection_changed(int p_option_button_index);122void _set_current_device(int p_device);123int _get_current_device() const;124125protected:126void _notification(int p_what);127128public:129// Pass an existing event to configure it. Alternatively, pass no event to start with a blank configuration.130// An action name can be passed for descriptive purposes.131void popup_and_configure(const Ref<InputEvent> &p_event = Ref<InputEvent>(), const String &p_current_action_name = "");132Ref<InputEvent> get_event() const;133134void set_allowed_input_types(int p_type_masks);135136InputEventConfigurationDialog();137};138139140