Skip to content

Commit

Permalink
Entirely removes BIND_VMETHOD in favor of GDVIRTUAL
Browse files Browse the repository at this point in the history
* `_gui_input`, `_input`, `_unhandled_input` and `_unhandled_key_input` are now regular C++ virutal functions.
* Everything else converted to GDVIRTUAL
* BIND_VMETHOD is gone, always use the new syntax from now on.

Creating `_gui_input` method and using the binder to register events will no longer work, simply override the virtual function now.
  • Loading branch information
reduz committed Aug 23, 2021
1 parent 2d44677 commit 5cecdfa
Show file tree
Hide file tree
Showing 134 changed files with 355 additions and 406 deletions.
9 changes: 8 additions & 1 deletion core/input/input_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#include "input_event.h"

#include "core/input/input_map.h"
#include "core/input/shortcut.h"
#include "core/os/keyboard.h"
#include "scene/gui/shortcut.h"

const int InputEvent::DEVICE_ID_TOUCH_MOUSE = -1;
const int InputEvent::DEVICE_ID_INTERNAL = -2;
Expand Down Expand Up @@ -1545,6 +1545,13 @@ Ref<Shortcut> InputEventShortcut::get_shortcut() {
return shortcut;
}

void InputEventShortcut::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_shortcut", "shortcut"), &InputEventShortcut::set_shortcut);
ClassDB::bind_method(D_METHOD("get_shortcut"), &InputEventShortcut::get_shortcut);

ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shortcut", PROPERTY_HINT_RESOURCE_TYPE, "Shortcut"), "set_shortcut", "get_shortcut");
}

bool InputEventShortcut::is_pressed() const {
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions core/input/input_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,9 @@ class InputEventShortcut : public InputEvent {

Ref<Shortcut> shortcut;

protected:
static void _bind_methods();

public:
void set_shortcut(Ref<Shortcut> p_shortcut);
Ref<Shortcut> get_shortcut();
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 0 additions & 11 deletions core/object/class_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,17 +425,6 @@ class ClassDB {

#endif

#ifdef TOOLS_ENABLED

#define BIND_VMETHOD(m_method) \
::ClassDB::add_virtual_method(get_class_static(), m_method);

#else

#define BIND_VMETHOD(m_method)

#endif

#define GDREGISTER_CLASS(m_class) \
if (!GD_IS_DEFINED(ClassDB_Disable_##m_class)) { \
::ClassDB::register_class<m_class>(); \
Expand Down
3 changes: 3 additions & 0 deletions core/register_core_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "core/extension/native_extension_manager.h"
#include "core/input/input.h"
#include "core/input/input_map.h"
#include "core/input/shortcut.h"
#include "core/io/config_file.h"
#include "core/io/dtls_server.h"
#include "core/io/http_client.h"
Expand Down Expand Up @@ -145,10 +146,12 @@ void register_core_types() {
GDREGISTER_CLASS(Resource);
GDREGISTER_CLASS(Image);

GDREGISTER_CLASS(Shortcut);
GDREGISTER_VIRTUAL_CLASS(InputEvent);
GDREGISTER_VIRTUAL_CLASS(InputEventWithModifiers);
GDREGISTER_VIRTUAL_CLASS(InputEventFromWindow);
GDREGISTER_CLASS(InputEventKey);
GDREGISTER_CLASS(InputEventShortcut);
GDREGISTER_VIRTUAL_CLASS(InputEventMouse);
GDREGISTER_CLASS(InputEventMouseButton);
GDREGISTER_CLASS(InputEventMouseMotion);
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/CollisionObject2D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<methods>
<method name="_input_event" qualifiers="virtual">
<return type="void" />
<argument index="0" name="viewport" type="Object" />
<argument index="0" name="viewport" type="Viewport" />
<argument index="1" name="event" type="InputEvent" />
<argument index="2" name="shape_idx" type="int" />
<description>
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/CollisionObject3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<methods>
<method name="_input_event" qualifiers="virtual">
<return type="void" />
<argument index="0" name="camera" type="Object" />
<argument index="0" name="camera" type="Camera3D" />
<argument index="1" name="event" type="InputEvent" />
<argument index="2" name="position" type="Vector3" />
<argument index="3" name="normal" type="Vector3" />
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/GraphEdit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<tutorials>
</tutorials>
<methods>
<method name="_get_connection_line" qualifiers="virtual">
<method name="_get_connection_line" qualifiers="virtual const">
<return type="PackedVector2Array" />
<argument index="0" name="from" type="Vector2" />
<argument index="1" name="to" type="Vector2" />
Expand Down
17 changes: 17 additions & 0 deletions doc/classes/InputEventShortcut.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="InputEventShortcut" inherits="InputEvent" version="4.0">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<methods>
</methods>
<members>
<member name="shortcut" type="Shortcut" setter="set_shortcut" getter="get_shortcut">
</member>
</members>
<constants>
</constants>
</class>
12 changes: 2 additions & 10 deletions doc/classes/Node.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@
Call [method update_configuration_warnings] when the warnings need to be updated for this node.
</description>
</method>
<method name="_get_configuration_warnings" qualifiers="virtual">
<return type="String[]" />
<description>
The elements in the array returned from this method are displayed as warnings in the Scene Dock if the script that overrides it is a [code]tool[/code] script.
Returning an empty array produces no warnings.
Call [method update_configuration_warnings] when the warnings need to be updated for this node.
</description>
</method>
<method name="_input" qualifiers="virtual">
<return type="void" />
<argument index="0" name="event" type="InputEvent" />
Expand Down Expand Up @@ -104,9 +96,9 @@
</method>
<method name="_unhandled_key_input" qualifiers="virtual">
<return type="void" />
<argument index="0" name="event" type="InputEventKey" />
<argument index="0" name="event" type="InputEvent" />
<description>
Called when an [InputEventKey] hasn't been consumed by [method _input] or any GUI. The input event propagates up through the node tree until a node consumes it.
Called when an [InputEventKey] or [InputEventShortcut] hasn't been consumed by [method _input] or any GUI. The input event propagates up through the node tree until a node consumes it.
It is only called if unhandled key input processing is enabled, which is done automatically if this method is overridden, and can be toggled with [method set_process_unhandled_key_input].
To consume the input event and stop it propagating further to other nodes, [method Viewport.set_input_as_handled] can be called.
For gameplay input, this and [method _unhandled_input] are usually a better fit than [method _input] as they allow the GUI to intercept the events first.
Expand Down
32 changes: 16 additions & 16 deletions doc/classes/Viewport.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,33 @@
Returns [code]true[/code] if the viewport is currently performing a drag operation.
</description>
</method>
<method name="input">
<method name="is_embedding_subwindows" qualifiers="const">
<return type="bool" />
<description>
</description>
</method>
<method name="is_input_handled" qualifiers="const">
<return type="bool" />
<description>
</description>
</method>
<method name="push_input">
<return type="void" />
<argument index="0" name="event" type="InputEvent" />
<argument index="1" name="in_local_coords" type="bool" default="false" />
<description>
</description>
</method>
<method name="input_text">
<method name="push_text_input">
<return type="void" />
<argument index="0" name="text" type="String" />
<description>
</description>
</method>
<method name="is_embedding_subwindows" qualifiers="const">
<return type="bool" />
<description>
</description>
</method>
<method name="is_input_handled" qualifiers="const">
<return type="bool" />
<method name="push_unhandled_input">
<return type="void" />
<argument index="0" name="event" type="InputEvent" />
<argument index="1" name="in_local_coords" type="bool" default="false" />
<description>
</description>
</method>
Expand All @@ -150,13 +157,6 @@
Sets the number of subdivisions to use in the specified quadrant. A higher number of subdivisions allows you to have more shadows in the scene at once, but reduces the quality of the shadows. A good practice is to have quadrants with a varying number of subdivisions and to have as few subdivisions as possible.
</description>
</method>
<method name="unhandled_input">
<return type="void" />
<argument index="0" name="event" type="InputEvent" />
<argument index="1" name="in_local_coords" type="bool" default="false" />
<description>
</description>
</method>
<method name="warp_mouse">
<return type="void" />
<argument index="0" name="to_position" type="Vector2" />
Expand Down
4 changes: 1 addition & 3 deletions editor/animation_bezier_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ void AnimationBezierTrackEdit::_select_at_anim(const Ref<Animation> &p_anim, int
update();
}

void AnimationBezierTrackEdit::_gui_input(const Ref<InputEvent> &p_event) {
void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());

if (p_event->is_pressed()) {
Expand Down Expand Up @@ -1131,8 +1131,6 @@ void AnimationBezierTrackEdit::set_block_animation_update_ptr(bool *p_block_ptr)
}

void AnimationBezierTrackEdit::_bind_methods() {
ClassDB::bind_method("_gui_input", &AnimationBezierTrackEdit::_gui_input);

ClassDB::bind_method("_clear_selection", &AnimationBezierTrackEdit::_clear_selection);
ClassDB::bind_method("_clear_selection_for_anim", &AnimationBezierTrackEdit::_clear_selection_for_anim);
ClassDB::bind_method("_select_at_anim", &AnimationBezierTrackEdit::_select_at_anim);
Expand Down
2 changes: 1 addition & 1 deletion editor/animation_bezier_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class AnimationBezierTrackEdit : public Control {

void _zoom_changed();

void _gui_input(const Ref<InputEvent> &p_event);
virtual void gui_input(const Ref<InputEvent> &p_event) override;
void _menu_selected(int p_index);

bool *block_animation_update_ptr; //used to block all tracks re-gen (speed up)
Expand Down
10 changes: 3 additions & 7 deletions editor/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ void AnimationTimelineEdit::_play_position_draw() {
}
}

void AnimationTimelineEdit::_gui_input(const Ref<InputEvent> &p_event) {
void AnimationTimelineEdit::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());

const Ref<InputEventMouseButton> mb = p_event;
Expand Down Expand Up @@ -1754,8 +1754,6 @@ void AnimationTimelineEdit::_track_added(int p_track) {
}

void AnimationTimelineEdit::_bind_methods() {
ClassDB::bind_method("_gui_input", &AnimationTimelineEdit::_gui_input);

ADD_SIGNAL(MethodInfo("zoom_changed"));
ADD_SIGNAL(MethodInfo("name_limit_changed"));
ADD_SIGNAL(MethodInfo("timeline_changed", PropertyInfo(Variant::FLOAT, "position"), PropertyInfo(Variant::BOOL, "drag")));
Expand Down Expand Up @@ -2551,7 +2549,7 @@ String AnimationTrackEdit::get_tooltip(const Point2 &p_pos) const {
return Control::get_tooltip(p_pos);
}

void AnimationTrackEdit::_gui_input(const Ref<InputEvent> &p_event) {
void AnimationTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());

if (p_event->is_pressed()) {
Expand Down Expand Up @@ -2965,8 +2963,6 @@ void AnimationTrackEdit::append_to_selection(const Rect2 &p_box, bool p_deselect
}

void AnimationTrackEdit::_bind_methods() {
ClassDB::bind_method("_gui_input", &AnimationTrackEdit::_gui_input);

ADD_SIGNAL(MethodInfo("timeline_changed", PropertyInfo(Variant::FLOAT, "position"), PropertyInfo(Variant::BOOL, "drag")));
ADD_SIGNAL(MethodInfo("remove_request", PropertyInfo(Variant::INT, "track")));
ADD_SIGNAL(MethodInfo("dropped", PropertyInfo(Variant::INT, "from_track"), PropertyInfo(Variant::INT, "to_track")));
Expand Down Expand Up @@ -5761,7 +5757,7 @@ void AnimationTrackEditor::_pick_track_filter_input(const Ref<InputEvent> &p_ie)
case KEY_DOWN:
case KEY_PAGEUP:
case KEY_PAGEDOWN: {
pick_track->get_scene_tree()->get_scene_tree()->call("_gui_input", k);
pick_track->get_scene_tree()->get_scene_tree()->gui_input(k);
pick_track->get_filter_line_edit()->accept_event();
} break;
default:
Expand Down
4 changes: 2 additions & 2 deletions editor/animation_track_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class AnimationTimelineEdit : public Range {
float dragging_hsize_from;
float dragging_hsize_at;

void _gui_input(const Ref<InputEvent> &p_event);
virtual void gui_input(const Ref<InputEvent> &p_event) override;
void _track_added(int p_track);

protected:
Expand Down Expand Up @@ -195,7 +195,7 @@ class AnimationTrackEdit : public Control {
static void _bind_methods();
void _notification(int p_what);

virtual void _gui_input(const Ref<InputEvent> &p_event);
virtual void gui_input(const Ref<InputEvent> &p_event) override;

public:
virtual Variant get_drag_data(const Point2 &p_point) override;
Expand Down
4 changes: 2 additions & 2 deletions editor/animation_track_editor_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ void AnimationTrackEditTypeAudio::drop_data(const Point2 &p_point, const Variant
AnimationTrackEdit::drop_data(p_point, p_data);
}

void AnimationTrackEditTypeAudio::_gui_input(const Ref<InputEvent> &p_event) {
void AnimationTrackEditTypeAudio::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());

Ref<InputEventMouseMotion> mm = p_event;
Expand Down Expand Up @@ -1132,7 +1132,7 @@ void AnimationTrackEditTypeAudio::_gui_input(const Ref<InputEvent> &p_event) {
return;
}

AnimationTrackEdit::_gui_input(p_event);
AnimationTrackEdit::gui_input(p_event);
}

////////////////////
Expand Down
2 changes: 1 addition & 1 deletion editor/animation_track_editor_plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class AnimationTrackEditTypeAudio : public AnimationTrackEdit {
static void _bind_methods();

public:
virtual void _gui_input(const Ref<InputEvent> &p_event) override;
virtual void gui_input(const Ref<InputEvent> &p_event) override;

virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const override;
virtual void drop_data(const Point2 &p_point, const Variant &p_data) override;
Expand Down
7 changes: 2 additions & 5 deletions editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void FindReplaceBar::_notification(int p_what) {
}
}

void FindReplaceBar::_unhandled_input(const Ref<InputEvent> &p_event) {
void FindReplaceBar::unhandled_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());

Ref<InputEventKey> k = p_event;
Expand Down Expand Up @@ -611,7 +611,6 @@ void FindReplaceBar::set_text_edit(CodeTextEditor *p_text_editor) {
}

void FindReplaceBar::_bind_methods() {
ClassDB::bind_method("_unhandled_input", &FindReplaceBar::_unhandled_input);
ClassDB::bind_method("_search_current", &FindReplaceBar::search_current);

ADD_SIGNAL(MethodInfo("search"));
Expand Down Expand Up @@ -712,7 +711,7 @@ FindReplaceBar::FindReplaceBar() {

// This function should be used to handle shortcuts that could otherwise
// be handled too late if they weren't handled here.
void CodeTextEditor::_input(const Ref<InputEvent> &event) {
void CodeTextEditor::input(const Ref<InputEvent> &event) {
ERR_FAIL_COND(event.is_null());

const Ref<InputEventKey> key_event = event;
Expand Down Expand Up @@ -1753,8 +1752,6 @@ void CodeTextEditor::remove_all_bookmarks() {
}

void CodeTextEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_input"), &CodeTextEditor::_input);

ADD_SIGNAL(MethodInfo("validate_script"));
ADD_SIGNAL(MethodInfo("load_theme_settings"));
ADD_SIGNAL(MethodInfo("show_errors_panel"));
Expand Down
4 changes: 2 additions & 2 deletions editor/code_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class FindReplaceBar : public HBoxContainer {

protected:
void _notification(int p_what);
void _unhandled_input(const Ref<InputEvent> &p_event);
virtual void unhandled_input(const Ref<InputEvent> &p_event) override;

bool _search(uint32_t p_flags, int p_from_line, int p_from_col);

Expand Down Expand Up @@ -173,7 +173,7 @@ class CodeTextEditor : public VBoxContainer {
void _font_resize_timeout();
bool _add_font_size(int p_delta);

void _input(const Ref<InputEvent> &event);
virtual void input(const Ref<InputEvent> &event) override;
void _text_editor_gui_input(const Ref<InputEvent> &p_event);
void _zoom_in();
void _zoom_out();
Expand Down
2 changes: 1 addition & 1 deletion editor/create_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ void CreateDialog::_sbox_input(const Ref<InputEvent> &p_ie) {
case KEY_DOWN:
case KEY_PAGEUP:
case KEY_PAGEDOWN: {
search_options->call("_gui_input", k);
search_options->gui_input(k);
search_box->accept_event();
} break;
default:
Expand Down
4 changes: 2 additions & 2 deletions editor/editor_audio_buses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ void EditorAudioBus::_effect_add(int p_which) {
ur->commit_action();
}

void EditorAudioBus::_gui_input(const Ref<InputEvent> &p_event) {
void EditorAudioBus::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());

Ref<InputEventMouseButton> mb = p_event;
Expand Down Expand Up @@ -744,7 +744,7 @@ void EditorAudioBus::_effect_rmb(const Vector2 &p_pos) {
void EditorAudioBus::_bind_methods() {
ClassDB::bind_method("update_bus", &EditorAudioBus::update_bus);
ClassDB::bind_method("update_send", &EditorAudioBus::update_send);
ClassDB::bind_method("_gui_input", &EditorAudioBus::_gui_input);

ClassDB::bind_method("_get_drag_data_fw", &EditorAudioBus::get_drag_data_fw);
ClassDB::bind_method("_can_drop_data_fw", &EditorAudioBus::can_drop_data_fw);
ClassDB::bind_method("_drop_data_fw", &EditorAudioBus::drop_data_fw);
Expand Down
Loading

0 comments on commit 5cecdfa

Please sign in to comment.