line_edit.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #include "scene/gui/control.h"
  32. /**
  33. @author Juan Linietsky <reduzio@gmail.com>
  34. */
  35. class LineEdit : public Control {
  36. OBJ_TYPE( LineEdit, Control );
  37. public:
  38. enum Align {
  39. ALIGN_LEFT,
  40. ALIGN_CENTER,
  41. ALIGN_RIGHT,
  42. ALIGN_FILL
  43. };
  44. private:
  45. Align align;
  46. bool editable;
  47. bool pass;
  48. String undo_text;
  49. String text;
  50. int cursor_pos;
  51. int window_pos;
  52. int max_length; // 0 for no maximum
  53. int cached_width;
  54. struct Selection {
  55. int begin;
  56. int end;
  57. int cursor_start;
  58. bool enabled;
  59. bool creating;
  60. bool doubleclick;
  61. bool drag_attempt;
  62. } selection;
  63. void shift_selection_check_pre(bool);
  64. void shift_selection_check_post(bool);
  65. void selection_clear();
  66. void selection_fill_at_cursor();
  67. void selection_delete();
  68. void set_window_pos(int p_pos);
  69. void set_cursor_at_pixel_pos(int p_x);
  70. void clear_internal();
  71. void changed_internal();
  72. void copy_text();
  73. void cut_text();
  74. void paste_text();
  75. void _input_event(InputEvent p_event);
  76. void _notification(int p_what);
  77. protected:
  78. static void _bind_methods();
  79. public:
  80. void set_align(Align p_align);
  81. Align get_align() const;
  82. virtual Variant get_drag_data(const Point2& p_point);
  83. virtual bool can_drop_data(const Point2& p_point,const Variant& p_data) const;
  84. virtual void drop_data(const Point2& p_point,const Variant& p_data);
  85. void select_all();
  86. void delete_char();
  87. void set_text(String p_text);
  88. String get_text() const;
  89. void set_cursor_pos(int p_pos);
  90. int get_cursor_pos() const;
  91. void set_max_length(int p_max_length);
  92. int get_max_length() const;
  93. void append_at_cursor(String p_text);
  94. void clear();
  95. void set_editable(bool p_editable);
  96. bool is_editable() const;
  97. void set_secret(bool p_secret);
  98. bool is_secret() const;
  99. void select(int p_from=0, int p_to=-1);
  100. virtual Size2 get_minimum_size() const;
  101. virtual bool is_text_field() const;
  102. LineEdit();
  103. ~LineEdit();
  104. };
  105. VARIANT_ENUM_CAST(LineEdit::Align);
  106. #endif