- Add an overwrite mode to editbox. This is patch #275 provided by Adam (aka kingadami)
https://sourceforge.net/p/irrlicht/patches/275/ git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4736 dfc29bdd-3216-0410-991c-e03cc46cb475master
parent
920b125bc2
commit
2c9d9abd57
|
@ -1,6 +1,7 @@
|
|||
--------------------------
|
||||
Changes in 1.9 (not yet released)
|
||||
|
||||
- Add an overwrite mode to editbox. Patch provided by Adam(aka kingadami).
|
||||
- Add IGUIImages::setDrawBounds/getDrawBounds to allow coding stuff like progress bars.
|
||||
- Add IGUIImages::setSourceRect/getSourceRect to allow using only parts of an image (can also be used to mirror and scroll them).
|
||||
- Dev-Cpp project file removed (wasn't really supported for some time already)
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace gui
|
|||
CGUIEditBox::CGUIEditBox(const wchar_t* text, bool border,
|
||||
IGUIEnvironment* environment, IGUIElement* parent, s32 id,
|
||||
const core::rect<s32>& rectangle)
|
||||
: IGUIEditBox(environment, parent, id, rectangle), MouseMarking(false),
|
||||
: IGUIEditBox(environment, parent, id, rectangle), OverwriteMode(false), MouseMarking(false),
|
||||
Border(border), Background(true), OverrideColorEnabled(false), MarkBegin(0), MarkEnd(0),
|
||||
OverrideColor(video::SColor(101,255,255,255)), OverrideFont(0), LastBreakFont(0),
|
||||
Operator(0), BlinkStartTime(0), CursorBlinkTime(350), CursorChar(L"_"), CursorPos(0), HScrollPos(0), VScrollPos(0), Max(0),
|
||||
|
@ -626,6 +626,12 @@ bool CGUIEditBox::processKey(const SEvent& event)
|
|||
textChanged = true;
|
||||
}
|
||||
break;
|
||||
case KEY_INSERT:
|
||||
if ( !isEnabled() )
|
||||
break;
|
||||
|
||||
OverwriteMode = !OverwriteMode;
|
||||
break;
|
||||
case KEY_DELETE:
|
||||
if ( !isEnabled() )
|
||||
break;
|
||||
|
@ -903,12 +909,28 @@ void CGUIEditBox::draw()
|
|||
setTextRect(cursorLine);
|
||||
CurrentTextRect.UpperLeftCorner.X += charcursorpos;
|
||||
|
||||
if ( OverwriteMode )
|
||||
{
|
||||
core::stringw character = Text.subString(CursorPos,1);
|
||||
s32 mend = font->getDimension(character.c_str()).Width;
|
||||
//Make sure the cursor box has at least some width to it
|
||||
if ( mend <= 0 )
|
||||
mend = font->getDimension(CursorChar.c_str()).Width;
|
||||
CurrentTextRect.LowerRightCorner.X = CurrentTextRect.UpperLeftCorner.X + mend;
|
||||
skin->draw2DRectangle(this, skin->getColor(EGDC_HIGH_LIGHT), CurrentTextRect, &localClipRect);
|
||||
font->draw(character.c_str(), CurrentTextRect,
|
||||
OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_HIGH_LIGHT_TEXT),
|
||||
false, true, &localClipRect);
|
||||
}
|
||||
else
|
||||
{
|
||||
font->draw(CursorChar, CurrentTextRect,
|
||||
OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT),
|
||||
false, true, &localClipRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// draw children
|
||||
IGUIElement::draw();
|
||||
|
@ -1347,6 +1369,37 @@ void CGUIEditBox::inputChar(wchar_t c)
|
|||
Text = s;
|
||||
CursorPos = realmbgn+1;
|
||||
}
|
||||
else if ( OverwriteMode )
|
||||
{
|
||||
//check to see if we are at the end of the text
|
||||
if ( (u32)CursorPos != Text.size())
|
||||
{
|
||||
s = Text.subString(0, CursorPos);
|
||||
s.append(c);
|
||||
if ( Text[CursorPos] == L'\n')
|
||||
{
|
||||
//just keep appending to the current line
|
||||
//This follows the behavior of over gui libraries behaviors
|
||||
s.append( Text.subString(CursorPos, Text.size()-CursorPos) );
|
||||
}
|
||||
else
|
||||
{
|
||||
//replace the next character
|
||||
s.append( Text.subString(CursorPos + 1,Text.size() - CursorPos + 1));
|
||||
}
|
||||
Text = s;
|
||||
++CursorPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
// add new character because we are at the end of the string
|
||||
s = Text.subString(0, CursorPos);
|
||||
s.append(c);
|
||||
s.append( Text.subString(CursorPos, Text.size()-CursorPos) );
|
||||
Text = s;
|
||||
++CursorPos;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// add new character
|
||||
|
|
|
@ -167,6 +167,7 @@ namespace gui
|
|||
bool processMouse(const SEvent& event);
|
||||
s32 getCursorPos(s32 x, s32 y);
|
||||
|
||||
bool OverwriteMode;
|
||||
bool MouseMarking;
|
||||
bool Border;
|
||||
bool Background;
|
||||
|
|
Loading…
Reference in New Issue