Code: Select all
Index: include/IGUIEditBox.h
===================================================================
--- include/IGUIEditBox.h (revision 2428)
+++ include/IGUIEditBox.h (working copy)
@@ -7,6 +7,7 @@
#include "IGUIElement.h"
#include "SColor.h"
+#include "irrArray.h"
namespace irr
{
@@ -90,6 +91,18 @@
//! Returns true if the edit box is currently a password box.
virtual bool isPasswordBox() const = 0;
+ //! Sets whether or not this edit box will use a list of allowed characters when receiving input.
+ virtual void setUseAllowableCharacters(bool useAllowableCharacters, irr::core::array< wchar_t > const & allowedCharacters) = 0;
+
+ //! Sets whether or not this edit box will use a list of allowed characters when receiving input.
+ virtual void setUseAllowableCharacters(bool useAllowableCharacters) = 0;
+
+ //! Returns true if the edit box is currently limiting the characters inputted into this box.
+ virtual bool isUsingAllowableCharacters() const = 0;
+
+ //! Returns the array of characters currently allowed for this edit box.
+ virtual irr::core::array< wchar_t > const & getAllowedCharacters() = 0;
+
//! Gets the size area of the text in the edit box
/** \return The size in pixels of the text */
virtual core::dimension2du getTextDimension() = 0;
Index: source/Irrlicht/CGUIEditBox.cpp
===================================================================
--- source/Irrlicht/CGUIEditBox.cpp (revision 2428)
+++ source/Irrlicht/CGUIEditBox.cpp (working copy)
@@ -37,7 +37,7 @@
Operator(0), BlinkStartTime(0), CursorPos(0), HScrollPos(0), VScrollPos(0), Max(0),
WordWrap(false), MultiLine(false), AutoScroll(true), PasswordBox(false),
PasswordChar(L'*'), HAlign(EGUIA_UPPERLEFT), VAlign(EGUIA_CENTER),
- CurrentTextRect(0,0,1,1), FrameRect(rectangle)
+ CurrentTextRect(0,0,1,1), FrameRect(rectangle), UseAllowableCharacters(false)
{
#ifdef _DEBUG
setDebugName("CGUIEditBox");
@@ -185,6 +185,29 @@
}
+void CGUIEditBox::setUseAllowableCharacters(bool useAllowableCharacters, irr::core::array< wchar_t > const & allowedCharacters)
+{
+ UseAllowableCharacters=useAllowableCharacters;
+ AllowedCharacters=allowedCharacters;
+}
+
+void CGUIEditBox::setUseAllowableCharacters(bool useAllowableCharacters)
+{
+ UseAllowableCharacters=useAllowableCharacters;
+}
+
+
+bool CGUIEditBox::isUsingAllowableCharacters() const
+{
+ return UseAllowableCharacters;
+}
+
+irr::core::array< wchar_t > const & CGUIEditBox::getAllowedCharacters()
+{
+ return AllowedCharacters;
+}
+
+
//! Sets text justification
void CGUIEditBox::setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical)
{
@@ -311,7 +334,20 @@
{
// insert text
core::stringw s = Text.subString(0, CursorPos);
- s.append(p);
+ if (UseAllowableCharacters)
+ {
+ core::stringw paste = p;
+ for ( u32 i = 0 ; i < paste.size() ;)
+ {
+ if ( AllowedCharacters.binary_search(paste[i]) == -1 )
+ paste.erase(i);
+ else
+ ++i;
+ }
+ s.append(paste);
+ }
+ else
+ s.append(p);
s.append( Text.subString(CursorPos, Text.size()-CursorPos) );
if (!Max || s.size()<=Max) // thx to Fish FH for fix
@@ -326,7 +362,20 @@
// replace text
core::stringw s = Text.subString(0, realmbgn);
- s.append(p);
+ if (UseAllowableCharacters)
+ {
+ core::stringw paste = p;
+ for ( u32 i = 0 ; i < paste.size() ;)
+ {
+ if ( AllowedCharacters.binary_search(paste[i]) == -1 )
+ paste.erase(i);
+ else
+ ++i;
+ }
+ s.append(paste);
+ }
+ else
+ s.append(p);
s.append( Text.subString(realmend, Text.size()-realmend) );
if (!Max || s.size()<=Max) // thx to Fish FH for fix
@@ -1252,7 +1301,7 @@
if (!IsEnabled)
return;
- if (c != 0)
+ if (c != 0 && ( ! UseAllowableCharacters || AllowedCharacters.binary_search( c ) != -1 ) )
{
if (Text.size() < Max || Max == 0)
{
Index: source/Irrlicht/CGUIEditBox.h
===================================================================
--- source/Irrlicht/CGUIEditBox.h (revision 2428)
+++ source/Irrlicht/CGUIEditBox.h (working copy)
@@ -97,6 +97,18 @@
//! Returns true if the edit box is currently a password box.
virtual bool isPasswordBox() const;
+ //! Sets whether or not this edit box will use a list of allowed characters when receiving input.
+ virtual void setUseAllowableCharacters(bool useAllowableCharacters, irr::core::array< wchar_t > const & allowedCharacters);
+
+ //! Sets whether or not this edit box will use a list of allowed characters when receiving input.
+ virtual void setUseAllowableCharacters(bool useAllowableCharacters);
+
+ //! Returns true if the edit box is currently limiting the characters inputted into this box.
+ virtual bool isUsingAllowableCharacters() const;
+
+ //! Returns the array of characters currently allowed for this edit box.
+ virtual irr::core::array< wchar_t > const & getAllowedCharacters();
+
//! Updates the absolute position, splits text if required
virtual void updateAbsolutePosition();
@@ -141,12 +153,13 @@
s32 HScrollPos, VScrollPos; // scroll position in characters
u32 Max;
- bool WordWrap, MultiLine, AutoScroll, PasswordBox;
+ bool WordWrap, MultiLine, AutoScroll, PasswordBox, UseAllowableCharacters;
wchar_t PasswordChar;
EGUI_ALIGNMENT HAlign, VAlign;
core::array< core::stringw > BrokenText;
core::array< s32 > BrokenTextPositions;
+ core::array< wchar_t > AllowedCharacters;
core::rect<s32> CurrentTextRect, FrameRect; // temporary values
};
Code: Select all
Index: examples/05.UserInterface/main.cpp
===================================================================
--- examples/05.UserInterface/main.cpp (revision 2428)
+++ examples/05.UserInterface/main.cpp (working copy)
@@ -244,6 +244,12 @@
env->addStaticText(L"Logging ListBox:", rect<s32>(50,110,250,130), true);
IGUIListBox * listbox = env->addListBox(rect<s32>(50, 140, 250, 210));
env->addEditBox(L"Editable Text", rect<s32>(350, 80, 550, 100));
+ IGUIEditBox * editbox = env->addEditBox(L"Editable Text", rect<s32>(350, 110, 550, 130));
+ wchar_t * warray = L"abc123";
+ irr::core::array< wchar_t > limitchars;
+ limitchars.set_pointer(warray, 6);
+ limitchars.set_free_when_destroyed(false);
+ editbox->setUseAllowableCharacters(true , limitchars);
// Store the appropriate data in a context structure.
SAppContext context;
https://sourceforge.net/tracker/?func=d ... tid=540678