line_edit.h
1 /*************************************************************************/
2 /* line_edit.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 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 /*************************************************************************/
29 #ifndef LINE_EDIT_H
30 #define LINE_EDIT_H
31 
32 #include "scene/gui/control.h"
36 class LineEdit : public Control {
37 
38  OBJ_TYPE( LineEdit, Control );
39 
40 public:
41  enum Align {
42 
43  ALIGN_LEFT,
44  ALIGN_CENTER,
45  ALIGN_RIGHT,
46  ALIGN_FILL
47  };
48 private:
49  Align align;
50 
51  bool editable;
52  bool pass;
53 
54  String undo_text;
55  String text;
56 
57  int cursor_pos;
58  int window_pos;
59  int max_length; // 0 for no maximum
60 
61  int cached_width;
62 
63  struct Selection {
64 
65  int begin;
66  int end;
67  int cursor_start;
68  bool enabled;
69  bool creating;
70  bool doubleclick;
71  bool drag_attempt;
72  } selection;
73 
74  void shift_selection_check_pre(bool);
75  void shift_selection_check_post(bool);
76 
77  void selection_clear();
78  void selection_fill_at_cursor();
79  void selection_delete();
80  void set_window_pos(int p_pos);
81 
82  void set_cursor_at_pixel_pos(int p_x);
83 
84  void clear_internal();
85  void changed_internal();
86 
87  void copy_text();
88  void cut_text();
89  void paste_text();
90 
91 
92  void _input_event(InputEvent p_event);
93  void _notification(int p_what);
94 
95 protected:
96  static void _bind_methods();
97 public:
98  void set_align(Align p_align);
99  Align get_align() const;
100 
101  virtual Variant get_drag_data(const Point2& p_point);
102  virtual bool can_drop_data(const Point2& p_point,const Variant& p_data) const;
103  virtual void drop_data(const Point2& p_point,const Variant& p_data);
104 
105 
106  void select_all();
107 
108  void delete_char();
109  void set_text(String p_text);
110  String get_text() const;
111  void set_cursor_pos(int p_pos);
112  int get_cursor_pos() const;
113  void set_max_length(int p_max_length);
114  int get_max_length() const;
115  void append_at_cursor(String p_text);
116  void clear();
117 
118 
119  void set_editable(bool p_editable);
120  bool is_editable() const;
121 
122  void set_secret(bool p_secret);
123  bool is_secret() const;
124 
125  void select(int p_from=0, int p_to=-1);
126 
127  virtual Size2 get_minimum_size() const;
128 
129  virtual bool is_text_field() const;
130  LineEdit();
131  ~LineEdit();
132 
133 };
134 
135 
136 VARIANT_ENUM_CAST(LineEdit::Align);
137 
138 #endif
Definition: variant.h:74
Definition: input_event.h:263
Definition: math_2d.h:65
Definition: control.h:47
Definition: ustring.h:64
Definition: line_edit.h:36