intlGUIEditBox.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 "IGUIScrollBar.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. //! Turns the border on or off
  46. virtual void setDrawBorder(bool border);
  47. //! Enables or disables word wrap for using the edit box as multiline text editor.
  48. virtual void setWordWrap(bool enable);
  49. //! Checks if word wrap is enabled
  50. //! \return true if word wrap is enabled, false otherwise
  51. virtual bool isWordWrapEnabled() const;
  52. //! Enables or disables newlines.
  53. /** \param enable: If set to true, the EGET_EDITBOX_ENTER event will not be fired,
  54. instead a newline character will be inserted. */
  55. virtual void setMultiLine(bool enable);
  56. //! Checks if multi line editing is enabled
  57. //! \return true if mult-line is enabled, false otherwise
  58. virtual bool isMultiLineEnabled() const;
  59. //! Enables or disables automatic scrolling with cursor position
  60. //! \param enable: If set to true, the text will move around with the cursor position
  61. virtual void setAutoScroll(bool enable);
  62. //! Checks to see if automatic scrolling is enabled
  63. //! \return true if automatic scrolling is enabled, false if not
  64. virtual bool isAutoScrollEnabled() const;
  65. //! Gets the size area of the text in the edit box
  66. //! \return Returns the size in pixels of the text
  67. virtual core::dimension2du getTextDimension();
  68. //! Sets text justification
  69. virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical);
  70. //! called if an event happened.
  71. virtual bool OnEvent(const SEvent& event);
  72. //! draws the element and its children
  73. virtual void draw();
  74. //! Sets the new caption of this element.
  75. virtual void setText(const wchar_t* text);
  76. //! Sets the maximum amount of characters which may be entered in the box.
  77. //! \param max: Maximum amount of characters. If 0, the character amount is
  78. //! infinity.
  79. virtual void setMax(u32 max);
  80. //! Returns maximum amount of characters, previously set by setMax();
  81. virtual u32 getMax() const;
  82. //! Sets whether the edit box is a password box. Setting this to true will
  83. /** disable MultiLine, WordWrap and the ability to copy with ctrl+c or ctrl+x
  84. \param passwordBox: true to enable password, false to disable
  85. \param passwordChar: the character that is displayed instead of letters */
  86. virtual void setPasswordBox(bool passwordBox, wchar_t passwordChar = L'*');
  87. //! Returns true if the edit box is currently a password box.
  88. virtual bool isPasswordBox() const;
  89. //! Updates the absolute position, splits text if required
  90. virtual void updateAbsolutePosition();
  91. //! set true if this EditBox is writable
  92. virtual void setWritable(bool can_write_text);
  93. //! Writes attributes of the element.
  94. virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
  95. //! Reads attributes of the element
  96. virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
  97. protected:
  98. //! Breaks the single text line.
  99. void breakText();
  100. //! sets the area of the given line
  101. void setTextRect(s32 line);
  102. //! returns the line number that the cursor is on
  103. s32 getLineFromPos(s32 pos);
  104. //! adds a letter to the edit box
  105. void inputChar(wchar_t c);
  106. //! calculates the current scroll position
  107. void calculateScrollPos();
  108. //! send some gui event to parent
  109. void sendGuiEvent(EGUI_EVENT_TYPE type);
  110. //! set text markers
  111. void setTextMarkers(s32 begin, s32 end);
  112. bool processKey(const SEvent& event);
  113. bool processMouse(const SEvent& event);
  114. s32 getCursorPos(s32 x, s32 y);
  115. //! Create a vertical scrollbar
  116. void createVScrollBar();
  117. //! Update the vertical scrollbar (visibilty & scroll position)
  118. void updateVScrollBar();
  119. bool MouseMarking = false;
  120. bool Border;
  121. bool OverrideColorEnabled = false;
  122. s32 MarkBegin = 0;
  123. s32 MarkEnd = 0;
  124. video::SColor OverrideColor = video::SColor(101,255,255,255);
  125. gui::IGUIFont *OverrideFont = nullptr;
  126. gui::IGUIFont *LastBreakFont = nullptr;
  127. IOSOperator *Operator = nullptr;
  128. u64 BlinkStartTime = 0;
  129. s32 CursorPos = 0;
  130. s32 HScrollPos = 0;
  131. s32 VScrollPos = 0; // scroll position in characters
  132. u32 Max = 0;
  133. bool WordWrap = false;
  134. bool MultiLine = false;
  135. bool AutoScroll = true;
  136. bool PasswordBox = false;
  137. wchar_t PasswordChar = L'*';
  138. EGUI_ALIGNMENT HAlign = EGUIA_UPPERLEFT;
  139. EGUI_ALIGNMENT VAlign = EGUIA_CENTER;
  140. core::array<core::stringw> BrokenText;
  141. core::array<s32> BrokenTextPositions;
  142. core::rect<s32> CurrentTextRect = core::rect<s32>(0,0,1,1);
  143. core::rect<s32> FrameRect; // temporary values
  144. u32 m_scrollbar_width;
  145. IGUIScrollBar *m_vscrollbar;
  146. bool m_writable;
  147. };
  148. } // end namespace gui
  149. } // end namespace irr
  150. //#endif // _IRR_COMPILE_WITH_GUI_