spin_box.h
1 /*************************************************************************/
2 /* spin_box.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 SPIN_BOX_H
30 #define SPIN_BOX_H
31 
32 #include "scene/gui/line_edit.h"
33 #include "scene/gui/range.h"
34 #include "scene/main/timer.h"
35 
36 class SpinBox : public Range {
37 
38  OBJ_TYPE( SpinBox, Range );
39 
40  LineEdit *line_edit;
41  int last_w;
42 
43  Timer *range_click_timer;
44  void _range_click_timeout();
45 
46  void _text_entered(const String& p_string);
47  virtual void _value_changed(double);
48  String prefix;
49  String suffix;
50 
51  void _line_edit_input(const InputEvent& p_event);
52 
53 
54  struct Drag {
55  float base_val;
56  bool enabled;
57  Vector2 from;
58  Vector2 mouse_pos;
59  Vector2 capture_pos;
60  } drag;
61 
62 
63  void _line_edit_focus_exit();
64 
65 protected:
66 
67  void _input_event(const InputEvent& p_event);
68 
69 
70  void _notification(int p_what);
71 
72  static void _bind_methods();
73 public:
74 
75  LineEdit *get_line_edit();
76 
77  virtual Size2 get_minimum_size() const;
78 
79  void set_editable(bool p_editable);
80  bool is_editable() const;
81 
82  void set_suffix(const String& p_suffix);
83  String get_suffix() const;
84 
85  void set_prefix(const String& p_prefix);
86  String get_prefix() const;
87 
88  SpinBox();
89 };
90 
91 #endif // SPIN_BOX_H
Definition: timer.h:34
Definition: range.h:36
Definition: input_event.h:263
Definition: spin_box.h:36
Definition: math_2d.h:65
Definition: ustring.h:64
Definition: line_edit.h:36