Skip to content

Commit

Permalink
Android Editor: Add Undo/Redo Buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
syntaxerror247 committed Dec 13, 2024
1 parent ba2c5c1 commit b1fc02d
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 0 deletions.
9 changes: 9 additions & 0 deletions editor/gui/editor_bottom_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#include "editor/editor_string_names.h"
#include "editor/gui/editor_toaster.h"
#include "editor/gui/editor_version_button.h"
#ifdef ANDROID_ENABLED
#include "editor/gui/touch_actions_panel.h"
#endif
#include "editor/themes/editor_scale.h"
#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
Expand Down Expand Up @@ -263,6 +266,12 @@ EditorBottomPanel::EditorBottomPanel() {
button_hbox->set_h_size_flags(Control::SIZE_EXPAND_FILL);
bottom_hbox->add_child(button_hbox);

#ifdef ANDROID_ENABLED
TouchActionsPanel *touch_actions_panel = memnew(TouchActionsPanel);
touch_actions_panel->set_h_size_flags(Control::SIZE_EXPAND_FILL);
bottom_hbox->add_child(touch_actions_panel);
#endif

editor_toaster = memnew(EditorToaster);
bottom_hbox->add_child(editor_toaster);

Expand Down
64 changes: 64 additions & 0 deletions editor/gui/touch_actions_panel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**************************************************************************/
/* touch_actions_panel.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#include "touch_actions_panel.h"
#include "core/input/input.h"
#include "editor/editor_settings.h"

void TouchActionsPanel::_simulate_action(const String &action_name) {
Ref<Shortcut> shortcut = ED_GET_SHORTCUT(action_name);

if (shortcut.is_valid() && !shortcut->get_events().is_empty()) {
Ref<InputEventKey> event = shortcut->get_events()[0];
if (event.is_valid()) {
event->set_pressed(true);
Input::get_singleton()->parse_input_event(event);
}
}
}

TouchActionsPanel::TouchActionsPanel() {
hbox = memnew(HBoxContainer);
hbox->set_alignment(BoxContainer::ALIGNMENT_CENTER);
hbox->add_theme_constant_override("separation", 30);
add_child(hbox);

undo_button = memnew(Button);
undo_button->set_text(TTR("Undo"));
undo_button->set_focus_mode(Control::FOCUS_NONE);
undo_button->connect(SceneStringName(pressed), callable_mp(this, &TouchActionsPanel::_simulate_action).bind("ui_undo"));
hbox->add_child(undo_button);

redo_button = memnew(Button);
redo_button->set_text(TTR("Redo"));
redo_button->set_focus_mode(Control::FOCUS_NONE);
redo_button->connect(SceneStringName(pressed), callable_mp(this, &TouchActionsPanel::_simulate_action).bind("ui_redo"));
hbox->add_child(redo_button);
}
52 changes: 52 additions & 0 deletions editor/gui/touch_actions_panel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**************************************************************************/
/* touch_actions_panel.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef TOUCH_ACTIONS_PANEL_H
#define TOUCH_ACTIONS_PANEL_H

#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
#include "scene/gui/panel_container.h"

class TouchActionsPanel : public PanelContainer {
GDCLASS(TouchActionsPanel, PanelContainer);

private:
HBoxContainer *hbox;
Button *undo_button;
Button *redo_button;

void _simulate_action(const String &action_name);

public:
TouchActionsPanel();
};

#endif // TOUCH_ACTIONS_PANEL_H

0 comments on commit b1fc02d

Please sign in to comment.