intlGUIEditBox.h 5.9 KB

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