1/**************************************************************************/
2/* event_listener_line_edit.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#ifndef EVENT_LISTENER_LINE_EDIT_H
32#define EVENT_LISTENER_LINE_EDIT_H
33
34#include "scene/gui/line_edit.h"
35
36enum InputType {
37 INPUT_KEY = 1,
38 INPUT_MOUSE_BUTTON = 2,
39 INPUT_JOY_BUTTON = 4,
40 INPUT_JOY_MOTION = 8
41};
42
43class EventListenerLineEdit : public LineEdit {
44 GDCLASS(EventListenerLineEdit, LineEdit)
45
46 int allowed_input_types = INPUT_KEY | INPUT_MOUSE_BUTTON | INPUT_JOY_BUTTON | INPUT_JOY_MOTION;
47 bool ignore_next_event = true;
48 bool share_keycodes = false;
49 Ref<InputEvent> event;
50
51 bool _is_event_allowed(const Ref<InputEvent> &p_event) const;
52
53 void gui_input(const Ref<InputEvent> &p_event) override;
54 void _on_text_changed(const String &p_text);
55
56 void _on_focus();
57 void _on_unfocus();
58
59protected:
60 void _notification(int p_what);
61 static void _bind_methods();
62
63public:
64 static String get_event_text(const Ref<InputEvent> &p_event, bool p_include_device);
65 static String get_device_string(int p_device);
66
67 Ref<InputEvent> get_event() const;
68 void clear_event();
69
70 void set_allowed_input_types(int p_type_masks);
71 int get_allowed_input_types() const;
72
73 void grab_focus();
74
75public:
76 EventListenerLineEdit();
77};
78
79#endif // EVENT_LISTENER_LINE_EDIT_H
80