intlGUIEditBox.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. // Copyright (C) 2002-2013 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #pragma once
  5. #include "IrrCompileConfig.h"
  6. //#ifdef _IRR_COMPILE_WITH_GUI_
  7. #include <IGUIEditBox.h>
  8. #include "irrArray.h"
  9. #include "IOSOperator.h"
  10. #include "guiScrollBar.h"
  11. namespace irr
  12. {
  13. namespace gui
  14. {
  15. class intlGUIEditBox : public IGUIEditBox
  16. {
  17. public:
  18. //! constructor
  19. intlGUIEditBox(const wchar_t* text, bool border, IGUIEnvironment* environment,
  20. IGUIElement* parent, s32 id, const core::rect<s32>& rectangle,
  21. bool writable = true, bool has_vscrollbar = false);
  22. //! destructor
  23. virtual ~intlGUIEditBox();
  24. //! Sets another skin independent font.
  25. virtual void setOverrideFont(IGUIFont* font=0);
  26. //! Gets the override font (if any)
  27. /** \return The override font (may be 0) */
  28. virtual IGUIFont* getOverrideFont() const;
  29. //! Get the font which is used right now for drawing
  30. /** Currently this is the override font when one is set and the
  31. font of the active skin otherwise */
  32. virtual IGUIFont* getActiveFont() const;
  33. //! Sets another color for the text.
  34. virtual void setOverrideColor(video::SColor color);
  35. //! Gets the override color
  36. virtual video::SColor getOverrideColor() const;
  37. //! Sets if the text should use the overide color or the
  38. //! color in the gui skin.
  39. virtual void enableOverrideColor(bool enable);
  40. //! Checks if an override color is enabled
  41. /** \return true if the override color is enabled, false otherwise */
  42. virtual bool isOverrideColorEnabled(void) const;
  43. //! Sets whether to draw the background
  44. virtual void setDrawBackground(bool draw);
  45. virtual bool isDrawBackgroundEnabled() const { return true; }
  46. //! Turns the border on or off
  47. virtual void setDrawBorder(bool border);
  48. virtual bool isDrawBorderEnabled() const { return Border; }
  49. //! Enables or disables word wrap for using the edit box as multiline text editor.
  50. virtual void setWordWrap(bool enable);
  51. //! Checks if word wrap is enabled
  52. //! \return true if word wrap is enabled, false otherwise
  53. virtual bool isWordWrapEnabled() const;
  54. //! Enables or disables newlines.
  55. /** \param enable: If set to true, the EGET_EDITBOX_ENTER event will not be fired,
  56. instead a newline character will be inserted. */
  57. virtual void setMultiLine(bool enable);
  58. //! Checks if multi line editing is enabled
  59. //! \return true if mult-line is enabled, false otherwise
  60. virtual bool isMultiLineEnabled() const;
  61. //! Enables or disables automatic scrolling with cursor position
  62. //! \param enable: If set to true, the text will move around with the cursor position
  63. virtual void setAutoScroll(bool enable);
  64. //! Checks to see if automatic scrolling is enabled
  65. //! \return true if automatic scrolling is enabled, false if not
  66. virtual bool isAutoScrollEnabled() const;
  67. //! Gets the size area of the text in the edit box
  68. //! \return Returns the size in pixels of the text
  69. virtual core::dimension2du getTextDimension();
  70. //! Sets text justification
  71. virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical);
  72. //! called if an event happened.
  73. virtual bool OnEvent(const SEvent& event);
  74. //! draws the element and its children
  75. virtual void draw();
  76. //! Sets the new caption of this element.
  77. virtual void setText(const wchar_t* text);
  78. //! Sets the maximum amount of characters which may be entered in the box.
  79. //! \param max: Maximum amount of characters. If 0, the character amount is
  80. //! infinity.
  81. virtual void setMax(u32 max);
  82. //! Returns maximum amount of characters, previously set by setMax();
  83. virtual u32 getMax() const;
  84. //! Sets whether the edit box is a password box. Setting this to true will
  85. /** disable MultiLine, WordWrap and the ability to copy with ctrl+c or ctrl+x
  86. \param passwordBox: true to enable password, false to disable
  87. \param passwordChar: the character that is displayed instead of letters */
  88. virtual void setPasswordBox(bool passwordBox, wchar_t passwordChar = L'*');
  89. //! Returns true if the edit box is currently a password box.
  90. virtual bool isPasswordBox() const;
  91. //! Updates the absolute position, splits text if required
  92. virtual void updateAbsolutePosition();
  93. //! set true if this EditBox is writable
  94. virtual void setWritable(bool can_write_text);
  95. //! Writes attributes of the element.
  96. virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
  97. //! Reads attributes of the element
  98. virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
  99. virtual void setCursorChar(const wchar_t cursorChar) {}
  100. virtual wchar_t getCursorChar() const { return L'|'; }
  101. virtual void setCursorBlinkTime(u32 timeMs) {}
  102. virtual u32 getCursorBlinkTime() const { return 500; }
  103. protected:
  104. //! Breaks the single text line.
  105. void breakText();
  106. //! sets the area of the given line
  107. void setTextRect(s32 line);
  108. //! returns the line number that the cursor is on
  109. s32 getLineFromPos(s32 pos);
  110. //! adds a letter to the edit box
  111. void inputChar(wchar_t c);
  112. //! calculates the current scroll position
  113. void calculateScrollPos();
  114. //! send some gui event to parent
  115. void sendGuiEvent(EGUI_EVENT_TYPE type);
  116. //! set text markers
  117. void setTextMarkers(s32 begin, s32 end);
  118. bool processKey(const SEvent& event);
  119. bool processMouse(const SEvent& event);
  120. s32 getCursorPos(s32 x, s32 y);
  121. //! Create a vertical scrollbar
  122. void createVScrollBar();
  123. //! Update the vertical scrollbar (visibilty & scroll position)
  124. void updateVScrollBar();
  125. bool MouseMarking = false;
  126. bool Border;
  127. bool OverrideColorEnabled = false;
  128. s32 MarkBegin = 0;
  129. s32 MarkEnd = 0;
  130. video::SColor OverrideColor = video::SColor(101,255,255,255);
  131. gui::IGUIFont *OverrideFont = nullptr;
  132. gui::IGUIFont *LastBreakFont = nullptr;
  133. IOSOperator *Operator = nullptr;
  134. u64 BlinkStartTime = 0;
  135. s32 CursorPos = 0;
  136. s32 HScrollPos = 0;
  137. s32 VScrollPos = 0; // scroll position in characters
  138. u32 Max = 0;
  139. bool WordWrap = false;
  140. bool MultiLine = false;
  141. bool AutoScroll = true;
  142. bool PasswordBox = false;
  143. wchar_t PasswordChar = L'*';
  144. EGUI_ALIGNMENT HAlign = EGUIA_UPPERLEFT;
  145. EGUI_ALIGNMENT VAlign = EGUIA_CENTER;
  146. core::array<core::stringw> BrokenText;
  147. core::array<s32> BrokenTextPositions;
  148. core::rect<s32> CurrentTextRect = core::rect<s32>(0,0,1,1);
  149. core::rect<s32> FrameRect; // temporary values
  150. u32 m_scrollbar_width;
  151. GUIScrollBar *m_vscrollbar;
  152. bool m_writable;
  153. };
  154. } // end namespace gui
  155. } // end namespace irr
  156. //#endif // _IRR_COMPILE_WITH_GUI_