Commit ac75fdd5 authored by cutealien's avatar cutealien

- Add functions to set/get cursor character and blinktime to IGUIEditBox

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4418 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 5562ee1d
--------------------------
Changes in 1.9 (not yet released)
- Add functions to set/get cursor character and blinktime to IGUIEditBox
- Collada exporter calculates values for orthographic camera now on export
- Collada exporter now exports the camera up-vector correctly.
- Add IColladaMeshWriter::findGeometryNameForNode
......
......@@ -133,6 +133,21 @@ namespace gui
//! Returns maximum amount of characters, previously set by setMax();
virtual u32 getMax() const = 0;
//! Set the character used for the cursor.
/** By default it's "_" */
virtual void setCursorChar(const wchar_t cursorChar) = 0;
//! Get the character used for the cursor.
virtual wchar_t getCursorChar() const = 0;
//! Set the blinktime for the cursor. 2x blinktime is one full cycle.
//** \param timeMs Blinktime in milliseconds. When set to 0 the cursor is constantly on without blinking */
virtual void setCursorBlinkTime(irr::u32 timeMs) = 0;
//! Get the cursor blinktime
virtual irr::u32 getCursorBlinkTime() const = 0;
};
......
......@@ -34,7 +34,7 @@ CGUIEditBox::CGUIEditBox(const wchar_t* text, bool border,
: IGUIEditBox(environment, parent, id, rectangle), 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), CursorPos(0), HScrollPos(0), VScrollPos(0), Max(0),
Operator(0), BlinkStartTime(0), CursorBlinkTime(350), CursorChar(L"_"), 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)
......@@ -896,14 +896,14 @@ void CGUIEditBox::draw()
}
s = txtLine->subString(0,CursorPos-startPos);
charcursorpos = font->getDimension(s.c_str()).Width +
font->getKerningWidth(L"_", CursorPos-startPos > 0 ? &((*txtLine)[CursorPos-startPos-1]) : 0);
font->getKerningWidth(CursorChar.c_str(), CursorPos-startPos > 0 ? &((*txtLine)[CursorPos-startPos-1]) : 0);
if (focus && (os::Timer::getTime() - BlinkStartTime) % 700 < 350)
if (focus && (CursorBlinkTime == 0 || (os::Timer::getTime() - BlinkStartTime) % (2*CursorBlinkTime) < CursorBlinkTime))
{
setTextRect(cursorLine);
CurrentTextRect.UpperLeftCorner.X += charcursorpos;
font->draw(L"_", CurrentTextRect,
font->draw(CursorChar, CurrentTextRect,
OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT),
false, true, &localClipRect);
}
......@@ -981,6 +981,30 @@ u32 CGUIEditBox::getMax() const
return Max;
}
//! Set the character used for the cursor.
/** By default it's "_" */
void CGUIEditBox::setCursorChar(const wchar_t cursorChar)
{
CursorChar[0] = cursorChar;
}
//! Get the character used for the cursor.
wchar_t CGUIEditBox::getCursorChar() const
{
return CursorChar[0];
}
//! Set the blinktime for the cursor. 2x blinktime is one full cycle.
void CGUIEditBox::setCursorBlinkTime(irr::u32 timeMs)
{
CursorBlinkTime = timeMs;
}
//! Get the cursor blinktime
irr::u32 CGUIEditBox::getCursorBlinkTime() const
{
return CursorBlinkTime;
}
bool CGUIEditBox::processMouse(const SEvent& event)
{
......@@ -1370,7 +1394,7 @@ void CGUIEditBox::calculateScrollPos()
return;
// get cursor area
irr::u32 cursorWidth = font->getDimension(L"_").Width;
irr::u32 cursorWidth = font->getDimension(CursorChar.c_str()).Width;
core::stringw *txtLine = hasBrokenText ? &BrokenText[cursLine] : &Text;
s32 cPos = hasBrokenText ? CursorPos - BrokenTextPositions[cursLine] : CursorPos; // column
s32 cStart = font->getDimension(txtLine->subString(0, cPos).c_str()).Width; // pixels from text-start
......
......@@ -113,6 +113,20 @@ namespace gui
//! Returns maximum amount of characters, previously set by setMax();
virtual u32 getMax() const;
//! Set the character used for the cursor.
/** By default it's "_" */
virtual void setCursorChar(const wchar_t cursorChar);
//! Get the character used for the cursor.
virtual wchar_t getCursorChar() const;
//! Set the blinktime for the cursor. 2x blinktime is one full cycle.
//** \param timeMs Blinktime in milliseconds. When set to 0 the cursor is constantly on without blinking */
virtual void setCursorBlinkTime(irr::u32 timeMs);
//! Get the cursor blinktime
virtual irr::u32 getCursorBlinkTime() const;
//! Sets whether the edit box is a password box. Setting this to true will
/** disable MultiLine, WordWrap and the ability to copy with ctrl+c or ctrl+x
\param passwordBox: true to enable password, false to disable
......@@ -165,6 +179,8 @@ namespace gui
IOSOperator* Operator;
u32 BlinkStartTime;
irr::u32 CursorBlinkTime;
core::stringw CursorChar; // IGUIFont::draw needs stringw instead of wchar_t
s32 CursorPos;
s32 HScrollPos, VScrollPos; // scroll position in characters
u32 Max;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment