#include <util/numeric.h>
#include "intlGUIEditBox.h"
-#if defined(_IRR_COMPILE_WITH_GUI_) && IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9
-
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IGUIFont.h"
#include "IVideoDriver.h"
-//#include "rect.h"
//#include "irrlicht/os.cpp"
#include "porting.h"
//#include "Keycodes.h"
intlGUIEditBox::intlGUIEditBox(const wchar_t* text, bool border,
IGUIEnvironment* environment, IGUIElement* parent, s32 id,
const core::rect<s32>& rectangle, bool writable, bool has_vscrollbar)
- : IGUIEditBox(environment, parent, id, rectangle),
+ : GUIEditBox(environment, parent, id, rectangle),
Border(border), FrameRect(rectangle),
m_scrollbar_width(0), m_vscrollbar(NULL), m_writable(writable)
{
//! destructor
intlGUIEditBox::~intlGUIEditBox()
{
- if (OverrideFont)
- OverrideFont->drop();
-
if (Operator)
Operator->drop();
-}
-
-
-//! Sets another skin independent font.
-void intlGUIEditBox::setOverrideFont(IGUIFont* font)
-{
- if (OverrideFont == font)
- return;
-
- if (OverrideFont)
- OverrideFont->drop();
-
- OverrideFont = font;
-
- if (OverrideFont)
- OverrideFont->grab();
-
- breakText();
-}
-
-IGUIFont * intlGUIEditBox::getOverrideFont() const
-{
- return OverrideFont;
-}
-
-//! Get the font which is used right now for drawing
-IGUIFont* intlGUIEditBox::getActiveFont() const
-{
- if ( OverrideFont )
- return OverrideFont;
- IGUISkin* skin = Environment->getSkin();
- if (skin)
- return skin->getFont();
- return 0;
-}
-
-//! Sets another color for the text.
-void intlGUIEditBox::setOverrideColor(video::SColor color)
-{
- OverrideColor = color;
- OverrideColorEnabled = true;
-}
-video::SColor intlGUIEditBox::getOverrideColor() const
-{
- return OverrideColor;
+ if (m_vscrollbar)
+ m_vscrollbar->drop();
}
//! Turns the border on or off
{
}
-//! Sets if the text should use the overide color or the color in the gui skin.
-void intlGUIEditBox::enableOverrideColor(bool enable)
-{
- OverrideColorEnabled = enable;
-}
-
-bool intlGUIEditBox::isOverrideColorEnabled() const
-{
- _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
- return OverrideColorEnabled;
-}
-
-//! Enables or disables word wrap
-void intlGUIEditBox::setWordWrap(bool enable)
-{
- WordWrap = enable;
- breakText();
-}
-
-
void intlGUIEditBox::updateAbsolutePosition()
{
core::rect<s32> oldAbsoluteRect(AbsoluteRect);
}
}
-
-//! Checks if word wrap is enabled
-bool intlGUIEditBox::isWordWrapEnabled() const
-{
- _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
- return WordWrap;
-}
-
-
-//! Enables or disables newlines.
-void intlGUIEditBox::setMultiLine(bool enable)
-{
- MultiLine = enable;
-}
-
-
-//! Checks if multi line editing is enabled
-bool intlGUIEditBox::isMultiLineEnabled() const
-{
- _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
- return MultiLine;
-}
-
-
void intlGUIEditBox::setPasswordBox(bool passwordBox, wchar_t passwordChar)
{
PasswordBox = passwordBox;
bool intlGUIEditBox::isPasswordBox() const
{
- _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return PasswordBox;
}
break;
case EET_KEY_INPUT_EVENT:
{
-#if (defined(__linux__) || defined(__FreeBSD__))
+#if (defined(__linux__) || defined(__FreeBSD__)) || defined(__DragonFly__)
// ################################################################
// ValkaTR:
// This part is the difference from the original intlGUIEditBox
case KEY_END:
{
s32 p = Text.size();
- if (WordWrap || MultiLine)
+ if (m_word_wrap || m_multiline)
{
p = getLineFromPos(CursorPos);
p = BrokenTextPositions[p] + (s32)BrokenText[p].size();
{
s32 p = 0;
- if (WordWrap || MultiLine)
+ if (m_word_wrap || m_multiline)
{
p = getLineFromPos(CursorPos);
p = BrokenTextPositions[p];
}
break;
case KEY_RETURN:
- if (MultiLine)
+ if (m_multiline)
{
inputChar(L'\n');
return true;
BlinkStartTime = porting::getTimeMs();
break;
case KEY_UP:
- if (MultiLine || (WordWrap && BrokenText.size() > 1) )
+ if (m_multiline || (m_word_wrap && BrokenText.size() > 1) )
{
s32 lineNo = getLineFromPos(CursorPos);
s32 mb = (MarkBegin == MarkEnd) ? CursorPos : (MarkBegin > MarkEnd ? MarkBegin : MarkEnd);
}
break;
case KEY_DOWN:
- if (MultiLine || (WordWrap && BrokenText.size() > 1) )
+ if (m_multiline || (m_word_wrap && BrokenText.size() > 1) )
{
s32 lineNo = getLineFromPos(CursorPos);
s32 mb = (MarkBegin == MarkEnd) ? CursorPos : (MarkBegin < MarkEnd ? MarkBegin : MarkEnd);
// draw the text
- IGUIFont* font = OverrideFont;
- if (!OverrideFont)
+ IGUIFont* font = m_override_font;
+ if (!m_override_font)
font = skin->getFont();
s32 cursorLine = 0;
core::stringw s, s2;
// get mark position
- const bool ml = (!PasswordBox && (WordWrap || MultiLine));
+ const bool ml = (!PasswordBox && (m_word_wrap || m_multiline));
const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;
const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;
const s32 hlineStart = ml ? getLineFromPos(realmbgn) : 0;
// Save the override color information.
// Then, alter it if the edit box is disabled.
- const bool prevOver = OverrideColorEnabled;
- const video::SColor prevColor = OverrideColor;
+ const bool prevOver = m_override_color_enabled;
+ const video::SColor prevColor = m_override_color;
if (!Text.empty()) {
- if (!IsEnabled && !OverrideColorEnabled)
+ if (!IsEnabled && !m_override_color_enabled)
{
- OverrideColorEnabled = true;
- OverrideColor = skin->getColor(EGDC_GRAY_TEXT);
+ m_override_color_enabled = true;
+ m_override_color = skin->getColor(EGDC_GRAY_TEXT);
}
for (s32 i=0; i < lineCount; ++i)
// draw normal text
font->draw(txtLine->c_str(), CurrentTextRect,
- OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT),
+ m_override_color_enabled ? m_override_color : skin->getColor(EGDC_BUTTON_TEXT),
false, true, &localClipRect);
// draw mark and marked text
if (!s.empty())
font->draw(s.c_str(), CurrentTextRect,
- OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_HIGH_LIGHT_TEXT),
+ m_override_color_enabled ? m_override_color : skin->getColor(EGDC_HIGH_LIGHT_TEXT),
false, true, &localClipRect);
}
}
// Return the override color information to its previous settings.
- OverrideColorEnabled = prevOver;
- OverrideColor = prevColor;
+ m_override_color_enabled = prevOver;
+ m_override_color = prevColor;
}
// draw cursor
- if (WordWrap || MultiLine)
+ if (m_word_wrap || m_multiline)
{
cursorLine = getLineFromPos(CursorPos);
txtLine = &BrokenText[cursorLine];
CurrentTextRect.UpperLeftCorner.X += charcursorpos;
font->draw(L"_", CurrentTextRect,
- OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT),
+ m_override_color_enabled ? m_override_color : skin->getColor(EGDC_BUTTON_TEXT),
false, true, &localClipRect);
}
}
}
-//! Enables or disables automatic scrolling with cursor position
-//! \param enable: If set to true, the text will move around with the cursor position
-void intlGUIEditBox::setAutoScroll(bool enable)
-{
- AutoScroll = enable;
-}
-
-
-//! Checks to see if automatic scrolling is enabled
-//! \return true if automatic scrolling is enabled, false if not
-bool intlGUIEditBox::isAutoScrollEnabled() const
-{
- _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
- return AutoScroll;
-}
-
-
//! Gets the area of the text in the edit box
//! \return Returns the size in pixels of the text
core::dimension2du intlGUIEditBox::getTextDimension()
s32 intlGUIEditBox::getCursorPos(s32 x, s32 y)
{
- IGUIFont* font = OverrideFont;
+ IGUIFont* font = m_override_font;
IGUISkin* skin = Environment->getSkin();
- if (!OverrideFont)
+ if (!m_override_font)
font = skin->getFont();
- const u32 lineCount = (WordWrap || MultiLine) ? BrokenText.size() : 1;
+ const u32 lineCount = (m_word_wrap || m_multiline) ? BrokenText.size() : 1;
core::stringw *txtLine = NULL;
s32 startPos = 0;
// is it inside this region?
if (y >= CurrentTextRect.UpperLeftCorner.Y && y <= CurrentTextRect.LowerRightCorner.Y) {
// we've found the clicked line
- txtLine = (WordWrap || MultiLine) ? &BrokenText[curr_line_idx] : &Text;
- startPos = (WordWrap || MultiLine) ? BrokenTextPositions[curr_line_idx] : 0;
+ txtLine = (m_word_wrap || m_multiline) ? &BrokenText[curr_line_idx] : &Text;
+ startPos = (m_word_wrap || m_multiline) ? BrokenTextPositions[curr_line_idx] : 0;
break;
}
}
{
IGUISkin* skin = Environment->getSkin();
- if ((!WordWrap && !MultiLine) || !skin)
+ if ((!m_word_wrap && !m_multiline) || !skin)
return;
BrokenText.clear(); // need to reallocate :/
BrokenTextPositions.set_used(0);
- IGUIFont* font = OverrideFont;
- if (!OverrideFont)
+ IGUIFont* font = m_override_font;
+ if (!m_override_font)
font = skin->getFont();
if (!font)
s32 lastLineStart = 0;
s32 size = Text.size();
s32 length = 0;
- s32 elWidth = RelativeRect.getWidth() - 6;
+ s32 elWidth = RelativeRect.getWidth() - m_scrollbar_width - 10;
wchar_t c;
for (s32 i=0; i<size; ++i)
}
// don't break if we're not a multi-line edit box
- if (!MultiLine)
+ if (!m_multiline)
lineBreak = false;
if (c == L' ' || c == 0 || i == (size-1))
s32 whitelgth = font->getDimension(whitespace.c_str()).Width;
s32 worldlgth = font->getDimension(word.c_str()).Width;
- if (WordWrap && length + worldlgth + whitelgth > elWidth)
+ if (m_word_wrap && length + worldlgth + whitelgth > elWidth)
{
// break to next line
length = worldlgth;
if (!skin)
return;
- IGUIFont* font = OverrideFont ? OverrideFont : skin->getFont();
+ IGUIFont* font = m_override_font ? m_override_font : skin->getFont();
if (!font)
return;
// get text dimension
- const u32 lineCount = (WordWrap || MultiLine) ? BrokenText.size() : 1;
- if (WordWrap || MultiLine)
+ const u32 lineCount = (m_word_wrap || m_multiline) ? BrokenText.size() : 1;
+ if (m_word_wrap || m_multiline)
{
d = font->getDimension(BrokenText[line].c_str());
}
s32 intlGUIEditBox::getLineFromPos(s32 pos)
{
- if (!WordWrap && !MultiLine)
+ if (!m_word_wrap && !m_multiline)
return 0;
s32 i=0;
void intlGUIEditBox::calculateScrollPos()
{
- if (!AutoScroll)
+ if (!m_autoscroll)
return;
// calculate horizontal scroll position
setTextRect(cursLine);
// don't do horizontal scrolling when wordwrap is enabled.
- if (!WordWrap)
+ if (!m_word_wrap)
{
// get cursor position
IGUISkin* skin = Environment->getSkin();
if (!skin)
return;
- IGUIFont* font = OverrideFont ? OverrideFont : skin->getFont();
+ IGUIFont* font = m_override_font ? m_override_font : skin->getFont();
if (!font)
return;
- core::stringw *txtLine = MultiLine ? &BrokenText[cursLine] : &Text;
- s32 cPos = MultiLine ? CursorPos - BrokenTextPositions[cursLine] : CursorPos;
+ core::stringw *txtLine = m_multiline ? &BrokenText[cursLine] : &Text;
+ s32 cPos = m_multiline ? CursorPos - BrokenTextPositions[cursLine] : CursorPos;
s32 cStart = CurrentTextRect.UpperLeftCorner.X + HScrollPos +
font->getDimension(txtLine->subString(0, cPos).c_str()).Width;
// todo: adjust scrollbar
}
- if (!WordWrap && !MultiLine)
+ if (!m_word_wrap && !m_multiline)
return;
// vertical scroll position
{
s32 fontHeight = 1;
- if (OverrideFont) {
- fontHeight = OverrideFont->getDimension(L"").Height;
+ if (m_override_font) {
+ fontHeight = m_override_font->getDimension(L"").Height;
} else {
if (IGUISkin* skin = Environment->getSkin()) {
if (IGUIFont* font = skin->getFont()) {
irr::core::rect<s32> scrollbarrect = FrameRect;
scrollbarrect.UpperLeftCorner.X += FrameRect.getWidth() - m_scrollbar_width;
- m_vscrollbar = Environment->addScrollBar(false, scrollbarrect, getParent(), getID());
+ m_vscrollbar = new GUIScrollBar(Environment, getParent(), -1,
+ scrollbarrect, false, true);
+
m_vscrollbar->setVisible(false);
m_vscrollbar->setSmallStep(3 * fontHeight);
m_vscrollbar->setLargeStep(10 * fontHeight);
if (scrollymax != m_vscrollbar->getMax()) {
// manage a newline or a deleted line
m_vscrollbar->setMax(scrollymax);
+ m_vscrollbar->setPageSize(s32(getTextDimension().Height));
calculateScrollPos();
} else {
// manage a newline or a deleted line
s32 scrollymax = getTextDimension().Height - FrameRect.getHeight();
if (scrollymax != m_vscrollbar->getMax()) {
m_vscrollbar->setMax(scrollymax);
+ m_vscrollbar->setPageSize(s32(getTextDimension().Height));
}
- if (!m_vscrollbar->isVisible() && MultiLine) {
+ if (!m_vscrollbar->isVisible() && m_multiline) {
AbsoluteRect.LowerRightCorner.X -= m_scrollbar_width;
m_vscrollbar->setVisible(true);
VScrollPos = 0;
m_vscrollbar->setPos(0);
m_vscrollbar->setMax(1);
+ m_vscrollbar->setPageSize(s32(getTextDimension().Height));
m_vscrollbar->setVisible(false);
}
}
{
// IGUIEditBox::serializeAttributes(out,options);
- out->addBool ("OverrideColorEnabled",OverrideColorEnabled );
- out->addColor ("OverrideColor", OverrideColor);
- // out->addFont("OverrideFont",OverrideFont);
- out->addInt ("MaxChars", Max);
- out->addBool ("WordWrap", WordWrap);
- out->addBool ("MultiLine", MultiLine);
- out->addBool ("AutoScroll", AutoScroll);
- out->addBool ("PasswordBox", PasswordBox);
+ out->addBool ("OverrideColorEnabled", m_override_color_enabled );
+ out->addColor ("OverrideColor", m_override_color);
+ // out->addFont("OverrideFont",m_override_font);
+ out->addInt ("MaxChars", Max);
+ out->addBool ("WordWrap", m_word_wrap);
+ out->addBool ("MultiLine", m_multiline);
+ out->addBool ("AutoScroll", m_autoscroll);
+ out->addBool ("PasswordBox", PasswordBox);
core::stringw ch = L" ";
ch[0] = PasswordChar;
- out->addString("PasswordChar", ch.c_str());
- out->addEnum ("HTextAlign", HAlign, GUIAlignmentNames);
- out->addEnum ("VTextAlign", VAlign, GUIAlignmentNames);
- out->addBool ("Writable", m_writable);
+ out->addString("PasswordChar", ch.c_str());
+ out->addEnum ("HTextAlign", HAlign, GUIAlignmentNames);
+ out->addEnum ("VTextAlign", VAlign, GUIAlignmentNames);
+ out->addBool ("Writable", m_writable);
IGUIEditBox::serializeAttributes(out,options);
}
} // end namespace gui
} // end namespace irr
-
-#endif // _IRR_COMPILE_WITH_GUI_