diff options
Diffstat (limited to 'src/gui/intlGUIEditBox.cpp')
-rw-r--r-- | src/gui/intlGUIEditBox.cpp | 1072 |
1 files changed, 558 insertions, 514 deletions
diff --git a/src/gui/intlGUIEditBox.cpp b/src/gui/intlGUIEditBox.cpp index 1c8bb64de..10395423c 100644 --- a/src/gui/intlGUIEditBox.cpp +++ b/src/gui/intlGUIEditBox.cpp @@ -45,8 +45,9 @@ todo: optional scrollbars ctrl+left/right to select word - double click/ctrl click: word select + drag to select whole words, triple click to - select line optional? dragging selected text numerical + double click/ctrl click: word select + drag to select whole words, triple click to select line + optional? dragging selected text + numerical */ namespace irr @@ -55,16 +56,16 @@ namespace gui { //! constructor -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), - Border(border), FrameRect(rectangle), m_scrollbar_width(0), - m_vscrollbar(NULL), m_writable(writable) +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), + Border(border), FrameRect(rectangle), + m_scrollbar_width(0), m_vscrollbar(NULL), m_writable(writable) { -#ifdef _DEBUG + #ifdef _DEBUG setDebugName("intlintlGUIEditBox"); -#endif + #endif Text = text; @@ -81,11 +82,12 @@ intlGUIEditBox::intlGUIEditBox(const wchar_t *text, bool border, IGUISkin *skin = 0; if (Environment) skin = Environment->getSkin(); - if (Border && skin) { - FrameRect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X) + 1; - FrameRect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y) + 1; - FrameRect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X) + 1; - FrameRect.LowerRightCorner.Y -= skin->getSize(EGDS_TEXT_DISTANCE_Y) + 1; + if (Border && skin) + { + FrameRect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X)+1; + FrameRect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y)+1; + FrameRect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X)+1; + FrameRect.LowerRightCorner.Y -= skin->getSize(EGDS_TEXT_DISTANCE_Y)+1; } if (skin && has_vscrollbar) { @@ -102,6 +104,7 @@ intlGUIEditBox::intlGUIEditBox(const wchar_t *text, bool border, setWritable(writable); } + //! destructor intlGUIEditBox::~intlGUIEditBox() { @@ -115,8 +118,9 @@ intlGUIEditBox::~intlGUIEditBox() m_vscrollbar->drop(); } + //! Sets another skin independent font. -void intlGUIEditBox::setOverrideFont(IGUIFont *font) +void intlGUIEditBox::setOverrideFont(IGUIFont* font) { if (OverrideFont == font) return; @@ -132,17 +136,17 @@ void intlGUIEditBox::setOverrideFont(IGUIFont *font) breakText(); } -IGUIFont *intlGUIEditBox::getOverrideFont() const +IGUIFont * intlGUIEditBox::getOverrideFont() const { return OverrideFont; } //! Get the font which is used right now for drawing -IGUIFont *intlGUIEditBox::getActiveFont() const +IGUIFont* intlGUIEditBox::getActiveFont() const { - if (OverrideFont) + if ( OverrideFont ) return OverrideFont; - IGUISkin *skin = Environment->getSkin(); + IGUISkin* skin = Environment->getSkin(); if (skin) return skin->getFont(); return 0; @@ -189,37 +193,44 @@ void intlGUIEditBox::setWordWrap(bool enable) breakText(); } + void intlGUIEditBox::updateAbsolutePosition() { - core::rect<s32> oldAbsoluteRect(AbsoluteRect); + core::rect<s32> oldAbsoluteRect(AbsoluteRect); IGUIElement::updateAbsolutePosition(); - if (oldAbsoluteRect != AbsoluteRect) { - breakText(); + if ( oldAbsoluteRect != AbsoluteRect ) + { + breakText(); } } + //! Checks if word wrap is enabled bool intlGUIEditBox::isWordWrapEnabled() const { return WordWrap; } + //! Enables or disables newlines. void intlGUIEditBox::setMultiLine(bool enable) { MultiLine = enable; } + //! Checks if multi line editing is enabled bool intlGUIEditBox::isMultiLineEnabled() const { return MultiLine; } + void intlGUIEditBox::setPasswordBox(bool passwordBox, wchar_t passwordChar) { PasswordBox = passwordBox; - if (PasswordBox) { + if (PasswordBox) + { PasswordChar = passwordChar; setMultiLine(false); setWordWrap(false); @@ -227,11 +238,13 @@ void intlGUIEditBox::setPasswordBox(bool passwordBox, wchar_t passwordChar) } } + bool intlGUIEditBox::isPasswordBox() const { return PasswordBox; } + //! Sets text justification void intlGUIEditBox::setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical) { @@ -239,35 +252,40 @@ void intlGUIEditBox::setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT VAlign = vertical; } + //! called if an event happened. -bool intlGUIEditBox::OnEvent(const SEvent &event) +bool intlGUIEditBox::OnEvent(const SEvent& event) { - if (IsEnabled) { + if (IsEnabled) + { - switch (event.EventType) { + switch(event.EventType) + { case EET_GUI_EVENT: - if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST) { - if (event.GUIEvent.Caller == this) { + if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST) + { + if (event.GUIEvent.Caller == this) + { MouseMarking = false; - setTextMarkers(0, 0); + setTextMarkers(0,0); } } break; - case EET_KEY_INPUT_EVENT: { + case EET_KEY_INPUT_EVENT: + { #if (defined(__linux__) || defined(__FreeBSD__)) || defined(__DragonFly__) - // ################################################################ + // ################################################################ // ValkaTR: - // This part is the difference from the original intlGUIEditBox - // It converts UTF-8 character into a UCS-2 (wchar_t) - wchar_t wc = L'_'; - mbtowc(&wc, (char *)&event.KeyInput.Char, - sizeof(event.KeyInput.Char)); + // This part is the difference from the original intlGUIEditBox + // It converts UTF-8 character into a UCS-2 (wchar_t) + wchar_t wc = L'_'; + mbtowc( &wc, (char *) &event.KeyInput.Char, sizeof(event.KeyInput.Char) ); - // printf( "char: %lc (%u) \r\n", wc, wc ); + //printf( "char: %lc (%u) \r\n", wc, wc ); - SEvent irrevent(event); - irrevent.KeyInput.Char = wc; - // ################################################################ + SEvent irrevent(event); + irrevent.KeyInput.Char = wc; + // ################################################################ if (processKey(irrevent)) return true; @@ -277,7 +295,7 @@ bool intlGUIEditBox::OnEvent(const SEvent &event) #endif // defined(linux) break; - } + } case EET_MOUSE_INPUT_EVENT: if (processMouse(event)) return true; @@ -290,7 +308,8 @@ bool intlGUIEditBox::OnEvent(const SEvent &event) return IGUIElement::OnEvent(event); } -bool intlGUIEditBox::processKey(const SEvent &event) + +bool intlGUIEditBox::processKey(const SEvent& event) { if (!event.KeyInput.PressedDown) return false; @@ -301,14 +320,17 @@ bool intlGUIEditBox::processKey(const SEvent &event) // control shortcut handling - if (event.KeyInput.Control) { + if (event.KeyInput.Control) + { // german backlash '\' entered with control + '?' - if (event.KeyInput.Char == '\\') { + if ( event.KeyInput.Char == '\\' ) + { inputChar(event.KeyInput.Char); return true; } - switch (event.KeyInput.Key) { + switch(event.KeyInput.Key) + { case KEY_KEY_A: // select all newMarkBegin = 0; @@ -316,11 +338,10 @@ bool intlGUIEditBox::processKey(const SEvent &event) break; case KEY_KEY_C: // copy to clipboard - if (!PasswordBox && Operator && MarkBegin != MarkEnd) { - const s32 realmbgn = - MarkBegin < MarkEnd ? MarkBegin : MarkEnd; - const s32 realmend = - MarkBegin < MarkEnd ? MarkEnd : MarkBegin; + if (!PasswordBox && Operator && MarkBegin != MarkEnd) + { + const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; + const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; core::stringc s; s = Text.subString(realmbgn, realmend - realmbgn).c_str(); @@ -330,23 +351,19 @@ bool intlGUIEditBox::processKey(const SEvent &event) case KEY_KEY_X: // cut to the clipboard if (!PasswordBox && Operator && MarkBegin != MarkEnd) { - const s32 realmbgn = - MarkBegin < MarkEnd ? MarkBegin : MarkEnd; - const s32 realmend = - MarkBegin < MarkEnd ? MarkEnd : MarkBegin; + const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; + const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; // copy core::stringc sc; - sc = Text.subString(realmbgn, realmend - realmbgn) - .c_str(); + sc = Text.subString(realmbgn, realmend - realmbgn).c_str(); Operator->copyToClipboard(sc.c_str()); if (IsEnabled && m_writable) { // delete core::stringw s; s = Text.subString(0, realmbgn); - s.append(Text.subString(realmend, - Text.size() - realmend)); + s.append( Text.subString(realmend, Text.size()-realmend) ); Text = s; CursorPos = realmbgn; @@ -361,43 +378,38 @@ bool intlGUIEditBox::processKey(const SEvent &event) break; // paste from the clipboard - if (Operator) { - const s32 realmbgn = - MarkBegin < MarkEnd ? MarkBegin : MarkEnd; - const s32 realmend = - MarkBegin < MarkEnd ? MarkEnd : MarkBegin; + if (Operator) + { + const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; + const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; // add new character - const c8 *p = Operator->getTextFromClipboard(); - if (p) { - if (MarkBegin == MarkEnd) { + const c8* p = Operator->getTextFromClipboard(); + if (p) + { + if (MarkBegin == MarkEnd) + { // insert text - core::stringw s = Text.subString( - 0, CursorPos); + core::stringw s = Text.subString(0, CursorPos); s.append(p); - s.append(Text.subString(CursorPos, - Text.size() - CursorPos)); + s.append( Text.subString(CursorPos, Text.size()-CursorPos) ); - if (!Max || s.size() <= Max) // thx to - // Fish FH - // for fix + if (!Max || s.size()<=Max) // thx to Fish FH for fix { Text = s; s = p; CursorPos += s.size(); } - } else { + } + else + { // replace text - core::stringw s = Text.subString( - 0, realmbgn); + core::stringw s = Text.subString(0, realmbgn); s.append(p); - s.append(Text.subString(realmend, - Text.size() - realmend)); + s.append( Text.subString(realmend, Text.size()-realmend) ); - if (!Max || s.size() <= Max) // thx to - // Fish FH - // for fix + if (!Max || s.size()<=Max) // thx to Fish FH for fix { Text = s; s = p; @@ -413,11 +425,14 @@ bool intlGUIEditBox::processKey(const SEvent &event) break; case KEY_HOME: // move/highlight to start of text - if (event.KeyInput.Shift) { + if (event.KeyInput.Shift) + { newMarkEnd = CursorPos; newMarkBegin = 0; CursorPos = 0; - } else { + } + else + { CursorPos = 0; newMarkBegin = 0; newMarkEnd = 0; @@ -425,11 +440,14 @@ bool intlGUIEditBox::processKey(const SEvent &event) break; case KEY_END: // move/highlight to end of text - if (event.KeyInput.Shift) { + if (event.KeyInput.Shift) + { newMarkBegin = CursorPos; newMarkEnd = Text.size(); CursorPos = 0; - } else { + } + else + { CursorPos = Text.size(); newMarkBegin = 0; newMarkEnd = 0; @@ -441,281 +459,293 @@ bool intlGUIEditBox::processKey(const SEvent &event) } // default keyboard handling else - switch (event.KeyInput.Key) { - case KEY_END: { + switch(event.KeyInput.Key) + { + case KEY_END: + { s32 p = Text.size(); - if (WordWrap || MultiLine) { + if (WordWrap || MultiLine) + { p = getLineFromPos(CursorPos); p = BrokenTextPositions[p] + (s32)BrokenText[p].size(); - if (p > 0 && (Text[p - 1] == L'\r' || - Text[p - 1] == L'\n')) - p -= 1; + if (p > 0 && (Text[p-1] == L'\r' || Text[p-1] == L'\n' )) + p-=1; } - if (event.KeyInput.Shift) { + if (event.KeyInput.Shift) + { if (MarkBegin == MarkEnd) newMarkBegin = CursorPos; newMarkEnd = p; - } else { + } + else + { newMarkBegin = 0; newMarkEnd = 0; } CursorPos = p; BlinkStartTime = porting::getTimeMs(); - } break; - case KEY_HOME: { + } + break; + case KEY_HOME: + { s32 p = 0; - if (WordWrap || MultiLine) { + if (WordWrap || MultiLine) + { p = getLineFromPos(CursorPos); p = BrokenTextPositions[p]; } - if (event.KeyInput.Shift) { + if (event.KeyInput.Shift) + { if (MarkBegin == MarkEnd) newMarkBegin = CursorPos; newMarkEnd = p; - } else { + } + else + { newMarkBegin = 0; newMarkEnd = 0; } CursorPos = p; BlinkStartTime = porting::getTimeMs(); - } break; - case KEY_RETURN: - if (MultiLine) { - inputChar(L'\n'); - return true; - } else { - sendGuiEvent(EGET_EDITBOX_ENTER); - } - break; - case KEY_LEFT: + } + break; + case KEY_RETURN: + if (MultiLine) + { + inputChar(L'\n'); + return true; + } + else + { + sendGuiEvent( EGET_EDITBOX_ENTER ); + } + break; + case KEY_LEFT: - if (event.KeyInput.Shift) { - if (CursorPos > 0) { - if (MarkBegin == MarkEnd) - newMarkBegin = CursorPos; + if (event.KeyInput.Shift) + { + if (CursorPos > 0) + { + if (MarkBegin == MarkEnd) + newMarkBegin = CursorPos; - newMarkEnd = CursorPos - 1; - } - } else { - newMarkBegin = 0; - newMarkEnd = 0; + newMarkEnd = CursorPos-1; } + } + else + { + newMarkBegin = 0; + newMarkEnd = 0; + } - if (CursorPos > 0) - CursorPos--; - BlinkStartTime = porting::getTimeMs(); - break; + if (CursorPos > 0) CursorPos--; + BlinkStartTime = porting::getTimeMs(); + break; - case KEY_RIGHT: - if (event.KeyInput.Shift) { - if (Text.size() > (u32)CursorPos) { - if (MarkBegin == MarkEnd) - newMarkBegin = CursorPos; + case KEY_RIGHT: + if (event.KeyInput.Shift) + { + if (Text.size() > (u32)CursorPos) + { + if (MarkBegin == MarkEnd) + newMarkBegin = CursorPos; - newMarkEnd = CursorPos + 1; - } - } else { - newMarkBegin = 0; - newMarkEnd = 0; + newMarkEnd = CursorPos+1; } + } + else + { + newMarkBegin = 0; + newMarkEnd = 0; + } - if (Text.size() > (u32)CursorPos) - CursorPos++; - BlinkStartTime = porting::getTimeMs(); - break; - case KEY_UP: - if (MultiLine || (WordWrap && BrokenText.size() > 1)) { - s32 lineNo = getLineFromPos(CursorPos); - s32 mb = (MarkBegin == MarkEnd) - ? CursorPos - : (MarkBegin > MarkEnd ? MarkBegin - : MarkEnd); - if (lineNo > 0) { - s32 cp = CursorPos - BrokenTextPositions[lineNo]; - if ((s32)BrokenText[lineNo - 1].size() < cp) - CursorPos = BrokenTextPositions[lineNo - - 1] + - (s32)BrokenText[lineNo - 1] - .size() - - 1; - else - CursorPos = BrokenTextPositions[lineNo - - 1] + - cp; - } - - if (event.KeyInput.Shift) { - newMarkBegin = mb; - newMarkEnd = CursorPos; - } else { - newMarkBegin = 0; - newMarkEnd = 0; - } + if (Text.size() > (u32)CursorPos) CursorPos++; + BlinkStartTime = porting::getTimeMs(); + break; + case KEY_UP: + if (MultiLine || (WordWrap && BrokenText.size() > 1) ) + { + s32 lineNo = getLineFromPos(CursorPos); + s32 mb = (MarkBegin == MarkEnd) ? CursorPos : (MarkBegin > MarkEnd ? MarkBegin : MarkEnd); + if (lineNo > 0) + { + s32 cp = CursorPos - BrokenTextPositions[lineNo]; + if ((s32)BrokenText[lineNo-1].size() < cp) + CursorPos = BrokenTextPositions[lineNo-1] + (s32)BrokenText[lineNo-1].size()-1; + else + CursorPos = BrokenTextPositions[lineNo-1] + cp; + } - } else { - return false; + if (event.KeyInput.Shift) + { + newMarkBegin = mb; + newMarkEnd = CursorPos; + } + else + { + newMarkBegin = 0; + newMarkEnd = 0; } - break; - case KEY_DOWN: - if (MultiLine || (WordWrap && BrokenText.size() > 1)) { - s32 lineNo = getLineFromPos(CursorPos); - s32 mb = (MarkBegin == MarkEnd) - ? CursorPos - : (MarkBegin < MarkEnd ? MarkBegin - : MarkEnd); - if (lineNo < (s32)BrokenText.size() - 1) { - s32 cp = CursorPos - BrokenTextPositions[lineNo]; - if ((s32)BrokenText[lineNo + 1].size() < cp) - CursorPos = BrokenTextPositions[lineNo + - 1] + - BrokenText[lineNo + 1] - .size() - - 1; - else - CursorPos = BrokenTextPositions[lineNo + - 1] + - cp; - } - if (event.KeyInput.Shift) { - newMarkBegin = mb; - newMarkEnd = CursorPos; - } else { - newMarkBegin = 0; - newMarkEnd = 0; - } + } + else + { + return false; + } + break; + case KEY_DOWN: + if (MultiLine || (WordWrap && BrokenText.size() > 1) ) + { + s32 lineNo = getLineFromPos(CursorPos); + s32 mb = (MarkBegin == MarkEnd) ? CursorPos : (MarkBegin < MarkEnd ? MarkBegin : MarkEnd); + if (lineNo < (s32)BrokenText.size()-1) + { + s32 cp = CursorPos - BrokenTextPositions[lineNo]; + if ((s32)BrokenText[lineNo+1].size() < cp) + CursorPos = BrokenTextPositions[lineNo+1] + BrokenText[lineNo+1].size()-1; + else + CursorPos = BrokenTextPositions[lineNo+1] + cp; + } - } else { - return false; + if (event.KeyInput.Shift) + { + newMarkBegin = mb; + newMarkEnd = CursorPos; + } + else + { + newMarkBegin = 0; + newMarkEnd = 0; } - break; - case KEY_BACK: - if (!this->IsEnabled || !m_writable) - break; + } + else + { + return false; + } + break; - if (!Text.empty()) { - core::stringw s; + case KEY_BACK: + if (!this->IsEnabled || !m_writable) + break; - if (MarkBegin != MarkEnd) { - // delete marked text - const s32 realmbgn = MarkBegin < MarkEnd - ? MarkBegin - : MarkEnd; - const s32 realmend = MarkBegin < MarkEnd - ? MarkEnd - : MarkBegin; + if (!Text.empty()) { + core::stringw s; - s = Text.subString(0, realmbgn); - s.append(Text.subString(realmend, - Text.size() - realmend)); - Text = s; + if (MarkBegin != MarkEnd) + { + // delete marked text + const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; + const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; - CursorPos = realmbgn; - } else { - // delete text behind cursor - if (CursorPos > 0) - s = Text.subString(0, CursorPos - 1); - else - s = L""; - s.append(Text.subString(CursorPos, - Text.size() - CursorPos)); - Text = s; - --CursorPos; - } + s = Text.subString(0, realmbgn); + s.append( Text.subString(realmend, Text.size()-realmend) ); + Text = s; - if (CursorPos < 0) - CursorPos = 0; - BlinkStartTime = porting::getTimeMs(); - newMarkBegin = 0; - newMarkEnd = 0; - textChanged = true; + CursorPos = realmbgn; + } + else + { + // delete text behind cursor + if (CursorPos>0) + s = Text.subString(0, CursorPos-1); + else + s = L""; + s.append( Text.subString(CursorPos, Text.size()-CursorPos) ); + Text = s; + --CursorPos; } - break; - case KEY_DELETE: - if (!this->IsEnabled || !m_writable) - break; - - if (!Text.empty()) { - core::stringw s; - if (MarkBegin != MarkEnd) { - // delete marked text - const s32 realmbgn = MarkBegin < MarkEnd - ? MarkBegin - : MarkEnd; - const s32 realmend = MarkBegin < MarkEnd - ? MarkEnd - : MarkBegin; + if (CursorPos < 0) + CursorPos = 0; + BlinkStartTime = porting::getTimeMs(); + newMarkBegin = 0; + newMarkEnd = 0; + textChanged = true; + } + break; + case KEY_DELETE: + if (!this->IsEnabled || !m_writable) + break; - s = Text.subString(0, realmbgn); - s.append(Text.subString(realmend, - Text.size() - realmend)); - Text = s; + if (!Text.empty()) { + core::stringw s; - CursorPos = realmbgn; - } else { - // delete text before cursor - s = Text.subString(0, CursorPos); - s.append(Text.subString(CursorPos + 1, - Text.size() - CursorPos - 1)); - Text = s; - } + if (MarkBegin != MarkEnd) + { + // delete marked text + const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; + const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; - if (CursorPos > (s32)Text.size()) - CursorPos = (s32)Text.size(); + s = Text.subString(0, realmbgn); + s.append( Text.subString(realmend, Text.size()-realmend) ); + Text = s; - BlinkStartTime = porting::getTimeMs(); - newMarkBegin = 0; - newMarkEnd = 0; - textChanged = true; + CursorPos = realmbgn; + } + else + { + // delete text before cursor + s = Text.subString(0, CursorPos); + s.append( Text.subString(CursorPos+1, Text.size()-CursorPos-1) ); + Text = s; } - break; - case KEY_ESCAPE: - case KEY_TAB: - case KEY_SHIFT: - case KEY_F1: - case KEY_F2: - case KEY_F3: - case KEY_F4: - case KEY_F5: - case KEY_F6: - case KEY_F7: - case KEY_F8: - case KEY_F9: - case KEY_F10: - case KEY_F11: - case KEY_F12: - case KEY_F13: - case KEY_F14: - case KEY_F15: - case KEY_F16: - case KEY_F17: - case KEY_F18: - case KEY_F19: - case KEY_F20: - case KEY_F21: - case KEY_F22: - case KEY_F23: - case KEY_F24: - // ignore these keys - return false; + if (CursorPos > (s32)Text.size()) + CursorPos = (s32)Text.size(); - default: - inputChar(event.KeyInput.Char); - return true; + BlinkStartTime = porting::getTimeMs(); + newMarkBegin = 0; + newMarkEnd = 0; + textChanged = true; } + break; - // Set new text markers - setTextMarkers(newMarkBegin, newMarkEnd); + case KEY_ESCAPE: + case KEY_TAB: + case KEY_SHIFT: + case KEY_F1: + case KEY_F2: + case KEY_F3: + case KEY_F4: + case KEY_F5: + case KEY_F6: + case KEY_F7: + case KEY_F8: + case KEY_F9: + case KEY_F10: + case KEY_F11: + case KEY_F12: + case KEY_F13: + case KEY_F14: + case KEY_F15: + case KEY_F16: + case KEY_F17: + case KEY_F18: + case KEY_F19: + case KEY_F20: + case KEY_F21: + case KEY_F22: + case KEY_F23: + case KEY_F24: + // ignore these keys + return false; + + default: + inputChar(event.KeyInput.Char); + return true; + } + + // Set new text markers + setTextMarkers( newMarkBegin, newMarkEnd ); // break the text if it has changed - if (textChanged) { + if (textChanged) + { breakText(); sendGuiEvent(EGET_EDITBOX_CHANGED); } @@ -725,6 +755,7 @@ bool intlGUIEditBox::processKey(const SEvent &event) return true; } + //! draws the element and its children void intlGUIEditBox::draw() { @@ -733,7 +764,7 @@ void intlGUIEditBox::draw() const bool focus = Environment->hasFocus(this); - IGUISkin *skin = Environment->getSkin(); + IGUISkin* skin = Environment->getSkin(); if (!skin) return; @@ -741,16 +772,17 @@ void intlGUIEditBox::draw() // draw the border - if (Border) { + if (Border) + { if (m_writable) { - skin->draw3DSunkenPane(this, skin->getColor(EGDC_WINDOW), false, - true, FrameRect, &AbsoluteClippingRect); + skin->draw3DSunkenPane(this, skin->getColor(EGDC_WINDOW), + false, true, FrameRect, &AbsoluteClippingRect); } - FrameRect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X) + 1; - FrameRect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y) + 1; - FrameRect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X) + 1; - FrameRect.LowerRightCorner.Y -= skin->getSize(EGDS_TEXT_DISTANCE_Y) + 1; + FrameRect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X)+1; + FrameRect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y)+1; + FrameRect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X)+1; + FrameRect.LowerRightCorner.Y -= skin->getSize(EGDS_TEXT_DISTANCE_Y)+1; } updateVScrollBar(); @@ -759,15 +791,17 @@ void intlGUIEditBox::draw() // draw the text - IGUIFont *font = OverrideFont; + IGUIFont* font = OverrideFont; if (!OverrideFont) font = skin->getFont(); s32 cursorLine = 0; s32 charcursorpos = 0; - if (font) { - if (LastBreakFont != font) { + if (font) + { + if (LastBreakFont != font) + { breakText(); } @@ -792,107 +826,97 @@ void intlGUIEditBox::draw() const video::SColor prevColor = OverrideColor; if (!Text.empty()) { - if (!IsEnabled && !OverrideColorEnabled) { + if (!IsEnabled && !OverrideColorEnabled) + { OverrideColorEnabled = true; OverrideColor = skin->getColor(EGDC_GRAY_TEXT); } - for (s32 i = 0; i < lineCount; ++i) { + for (s32 i=0; i < lineCount; ++i) + { setTextRect(i); - // clipping test - don't draw anything outside the visible - // area + // clipping test - don't draw anything outside the visible area core::rect<s32> c = localClipRect; c.clipAgainst(CurrentTextRect); if (!c.isValid()) continue; // get current line - if (PasswordBox) { - if (BrokenText.size() != 1) { + if (PasswordBox) + { + if (BrokenText.size() != 1) + { BrokenText.clear(); BrokenText.push_back(core::stringw()); } - if (BrokenText[0].size() != Text.size()) { + if (BrokenText[0].size() != Text.size()) + { BrokenText[0] = Text; - for (u32 q = 0; q < Text.size(); ++q) { - BrokenText[0][q] = PasswordChar; + for (u32 q = 0; q < Text.size(); ++q) + { + BrokenText[0] [q] = PasswordChar; } } txtLine = &BrokenText[0]; startPos = 0; - } else { + } + else + { txtLine = ml ? &BrokenText[i] : &Text; startPos = ml ? BrokenTextPositions[i] : 0; } + // draw normal text font->draw(txtLine->c_str(), CurrentTextRect, - OverrideColorEnabled - ? OverrideColor - : skin->getColor(EGDC_BUTTON_TEXT), - false, true, &localClipRect); + OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT), + false, true, &localClipRect); // draw mark and marked text - if (focus && MarkBegin != MarkEnd && i >= hlineStart && - i < hlineStart + hlineCount) { + if (focus && MarkBegin != MarkEnd && i >= hlineStart && i < hlineStart + hlineCount) + { s32 mbegin = 0, mend = 0; - s32 lineStartPos = 0, - lineEndPos = txtLine->size(); + s32 lineStartPos = 0, lineEndPos = txtLine->size(); - if (i == hlineStart) { + if (i == hlineStart) + { // highlight start is on this line - s = txtLine->subString( - 0, realmbgn - startPos); - mbegin = font->getDimension(s.c_str()) - .Width; + s = txtLine->subString(0, realmbgn - startPos); + mbegin = font->getDimension(s.c_str()).Width; // deal with kerning mbegin += font->getKerningWidth( - &((*txtLine)[realmbgn - - startPos]), - realmbgn - startPos > 0 - ? &((*txtLine)[realmbgn - - startPos - - 1]) - : 0); + &((*txtLine)[realmbgn - startPos]), + realmbgn - startPos > 0 ? &((*txtLine)[realmbgn - startPos - 1]) : 0); lineStartPos = realmbgn - startPos; } - if (i == hlineStart + hlineCount - 1) { + if (i == hlineStart + hlineCount - 1) + { // highlight end is on this line - s2 = txtLine->subString( - 0, realmend - startPos); - mend = font->getDimension(s2.c_str()) - .Width; + s2 = txtLine->subString(0, realmend - startPos); + mend = font->getDimension(s2.c_str()).Width; lineEndPos = (s32)s2.size(); - } else - mend = font->getDimension(txtLine->c_str()) - .Width; + } + else + mend = font->getDimension(txtLine->c_str()).Width; CurrentTextRect.UpperLeftCorner.X += mbegin; - CurrentTextRect.LowerRightCorner.X = - CurrentTextRect.UpperLeftCorner - .X + - mend - mbegin; + CurrentTextRect.LowerRightCorner.X = CurrentTextRect.UpperLeftCorner.X + mend - mbegin; // draw mark - skin->draw2DRectangle(this, - skin->getColor(EGDC_HIGH_LIGHT), - CurrentTextRect, &localClipRect); + skin->draw2DRectangle(this, skin->getColor(EGDC_HIGH_LIGHT), CurrentTextRect, &localClipRect); // draw marked text - s = txtLine->subString(lineStartPos, - lineEndPos - lineStartPos); + s = txtLine->subString(lineStartPos, lineEndPos - lineStartPos); if (!s.empty()) font->draw(s.c_str(), CurrentTextRect, - OverrideColorEnabled - ? OverrideColor - : skin->getColor(EGDC_HIGH_LIGHT_TEXT), - false, true, - &localClipRect); + OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_HIGH_LIGHT_TEXT), + false, true, &localClipRect); + } } @@ -903,31 +927,24 @@ void intlGUIEditBox::draw() // draw cursor - if (WordWrap || MultiLine) { + if (WordWrap || MultiLine) + { cursorLine = getLineFromPos(CursorPos); txtLine = &BrokenText[cursorLine]; startPos = BrokenTextPositions[cursorLine]; } - s = txtLine->subString(0, CursorPos - startPos); + 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(L"_", CursorPos-startPos > 0 ? &((*txtLine)[CursorPos-startPos-1]) : 0); - if (m_writable) { - if (focus && (porting::getTimeMs() - BlinkStartTime) % 700 < - 350) { + if (m_writable) { + if (focus && (porting::getTimeMs() - BlinkStartTime) % 700 < 350) { setTextRect(cursorLine); CurrentTextRect.UpperLeftCorner.X += charcursorpos; font->draw(L"_", CurrentTextRect, - OverrideColorEnabled - ? OverrideColor - : skin->getColor(EGDC_BUTTON_TEXT), - false, true, &localClipRect); + OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_BUTTON_TEXT), + false, true, &localClipRect); } } } @@ -936,8 +953,9 @@ void intlGUIEditBox::draw() IGUIElement::draw(); } + //! Sets the new caption of this element. -void intlGUIEditBox::setText(const wchar_t *text) +void intlGUIEditBox::setText(const wchar_t* text) { Text = text; if (u32(CursorPos) > Text.size()) @@ -946,6 +964,7 @@ void intlGUIEditBox::setText(const wchar_t *text) breakText(); } + //! 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) @@ -953,6 +972,7 @@ 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 @@ -960,6 +980,7 @@ bool intlGUIEditBox::isAutoScrollEnabled() const 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() @@ -969,7 +990,8 @@ core::dimension2du intlGUIEditBox::getTextDimension() setTextRect(0); ret = CurrentTextRect; - for (u32 i = 1; i < BrokenText.size(); ++i) { + for (u32 i=1; i < BrokenText.size(); ++i) + { setTextRect(i); ret.addInternalPoint(CurrentTextRect.UpperLeftCorner); ret.addInternalPoint(CurrentTextRect.LowerRightCorner); @@ -978,6 +1000,7 @@ core::dimension2du intlGUIEditBox::getTextDimension() return core::dimension2du(ret.getSize()); } + //! Sets the maximum amount of characters which may be entered in the box. //! \param max: Maximum amount of characters. If 0, the character amount is //! infinity. @@ -989,48 +1012,60 @@ void intlGUIEditBox::setMax(u32 max) Text = Text.subString(0, Max); } + //! Returns maximum amount of characters, previously set by setMax(); u32 intlGUIEditBox::getMax() const { return Max; } -bool intlGUIEditBox::processMouse(const SEvent &event) + +bool intlGUIEditBox::processMouse(const SEvent& event) { - switch (event.MouseInput.Event) { + switch(event.MouseInput.Event) + { case irr::EMIE_LMOUSE_LEFT_UP: - if (Environment->hasFocus(this)) { + if (Environment->hasFocus(this)) + { CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); - if (MouseMarking) { - setTextMarkers(MarkBegin, CursorPos); + if (MouseMarking) + { + setTextMarkers( MarkBegin, CursorPos ); } MouseMarking = false; calculateScrollPos(); return true; } break; - case irr::EMIE_MOUSE_MOVED: { - if (MouseMarking) { - CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); - setTextMarkers(MarkBegin, CursorPos); - calculateScrollPos(); - return true; + case irr::EMIE_MOUSE_MOVED: + { + if (MouseMarking) + { + CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); + setTextMarkers( MarkBegin, CursorPos ); + calculateScrollPos(); + return true; + } } - } break; + break; case EMIE_LMOUSE_PRESSED_DOWN: - if (!Environment->hasFocus(this)) { + if (!Environment->hasFocus(this)) + { BlinkStartTime = porting::getTimeMs(); MouseMarking = true; CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); - setTextMarkers(CursorPos, CursorPos); + setTextMarkers(CursorPos, CursorPos ); calculateScrollPos(); return true; - } else { - if (!AbsoluteClippingRect.isPointInside(core::position2d<s32>( - event.MouseInput.X, event.MouseInput.Y))) { + } + else + { + if (!AbsoluteClippingRect.isPointInside( + core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y))) { return false; } + // move cursor CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); @@ -1039,7 +1074,7 @@ bool intlGUIEditBox::processMouse(const SEvent &event) newMarkBegin = CursorPos; MouseMarking = true; - setTextMarkers(newMarkBegin, CursorPos); + setTextMarkers( newMarkBegin, CursorPos); calculateScrollPos(); return true; } @@ -1058,10 +1093,11 @@ bool intlGUIEditBox::processMouse(const SEvent &event) return false; } + s32 intlGUIEditBox::getCursorPos(s32 x, s32 y) { - IGUIFont *font = OverrideFont; - IGUISkin *skin = Environment->getSkin(); + IGUIFont* font = OverrideFont; + IGUISkin* skin = Environment->getSkin(); if (!OverrideFont) font = skin->getFont(); @@ -1076,19 +1112,14 @@ s32 intlGUIEditBox::getCursorPos(s32 x, s32 y) setTextRect(curr_line_idx); if (curr_line_idx == 0 && y < CurrentTextRect.UpperLeftCorner.Y) y = CurrentTextRect.UpperLeftCorner.Y; - if (curr_line_idx == lineCount - 1 && - y > CurrentTextRect.LowerRightCorner.Y) + if (curr_line_idx == lineCount - 1 && y > CurrentTextRect.LowerRightCorner.Y) y = CurrentTextRect.LowerRightCorner.Y; // is it inside this region? - if (y >= CurrentTextRect.UpperLeftCorner.Y && - y <= CurrentTextRect.LowerRightCorner.Y) { + 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 = (WordWrap || MultiLine) ? &BrokenText[curr_line_idx] : &Text; + startPos = (WordWrap || MultiLine) ? BrokenTextPositions[curr_line_idx] : 0; break; } } @@ -1098,20 +1129,20 @@ s32 intlGUIEditBox::getCursorPos(s32 x, s32 y) else if (x > CurrentTextRect.LowerRightCorner.X) x = CurrentTextRect.LowerRightCorner.X; - s32 idx = font->getCharacterFromPos( - txtLine->c_str(), x - CurrentTextRect.UpperLeftCorner.X); - // Special handling for last line, if we are on limits, add 1 extra shift because - // idx will be the last char, not null char of the wstring + s32 idx = font->getCharacterFromPos(txtLine->c_str(), x - CurrentTextRect.UpperLeftCorner.X); + // Special handling for last line, if we are on limits, add 1 extra shift because idx + // will be the last char, not null char of the wstring if (curr_line_idx == lineCount - 1 && x == CurrentTextRect.LowerRightCorner.X) idx++; return rangelim(idx + startPos, 0, S32_MAX); } + //! Breaks the single text line. void intlGUIEditBox::breakText() { - IGUISkin *skin = Environment->getSkin(); + IGUISkin* skin = Environment->getSkin(); if ((!WordWrap && !MultiLine) || !skin) return; @@ -1119,7 +1150,7 @@ void intlGUIEditBox::breakText() BrokenText.clear(); // need to reallocate :/ BrokenTextPositions.set_used(0); - IGUIFont *font = OverrideFont; + IGUIFont* font = OverrideFont; if (!OverrideFont) font = skin->getFont(); @@ -1137,7 +1168,8 @@ void intlGUIEditBox::breakText() s32 elWidth = RelativeRect.getWidth() - 6; wchar_t c; - for (s32 i = 0; i < size; ++i) { + for (s32 i=0; i<size; ++i) + { c = Text[i]; bool lineBreak = false; @@ -1145,12 +1177,13 @@ void intlGUIEditBox::breakText() { lineBreak = true; c = ' '; - if (Text[i + 1] == L'\n') // Windows breaks + if (Text[i+1] == L'\n') // Windows breaks { - Text.erase(i + 1); + Text.erase(i+1); --size; } - } else if (c == L'\n') // Unix breaks + } + else if (c == L'\n') // Unix breaks { lineBreak = true; c = ' '; @@ -1160,23 +1193,25 @@ void intlGUIEditBox::breakText() if (!MultiLine) lineBreak = false; - if (c == L' ' || c == 0 || i == (size - 1)) { + if (c == L' ' || c == 0 || i == (size-1)) + { if (!word.empty()) { // here comes the next whitespace, look if // we can break the last word to the next line. - s32 whitelgth = font->getDimension(whitespace.c_str()) - .Width; + s32 whitelgth = font->getDimension(whitespace.c_str()).Width; s32 worldlgth = font->getDimension(word.c_str()).Width; - if (WordWrap && length + worldlgth + whitelgth > - elWidth) { + if (WordWrap && length + worldlgth + whitelgth > elWidth) + { // break to next line length = worldlgth; BrokenText.push_back(line); BrokenTextPositions.push_back(lastLineStart); lastLineStart = i - (s32)word.size(); line = word; - } else { + } + else + { // add word to line line += whitespace; line += word; @@ -1190,18 +1225,21 @@ void intlGUIEditBox::breakText() whitespace += c; // compute line break - if (lineBreak) { + if (lineBreak) + { line += whitespace; line += word; BrokenText.push_back(line); BrokenTextPositions.push_back(lastLineStart); - lastLineStart = i + 1; + lastLineStart = i+1; line = L""; word = L""; whitespace = L""; length = 0; } - } else { + } + else + { // yippee this is a word.. word += c; } @@ -1213,37 +1251,40 @@ void intlGUIEditBox::breakText() BrokenTextPositions.push_back(lastLineStart); } + void intlGUIEditBox::setTextRect(s32 line) { core::dimension2du d; - IGUISkin *skin = Environment->getSkin(); + IGUISkin* skin = Environment->getSkin(); if (!skin) return; - IGUIFont *font = OverrideFont ? OverrideFont : skin->getFont(); + IGUIFont* font = OverrideFont ? OverrideFont : skin->getFont(); if (!font) return; // get text dimension const u32 lineCount = (WordWrap || MultiLine) ? BrokenText.size() : 1; - if (WordWrap || MultiLine) { + if (WordWrap || MultiLine) + { d = font->getDimension(BrokenText[line].c_str()); - } else { + } + else + { d = font->getDimension(Text.c_str()); d.Height = AbsoluteRect.getHeight(); } d.Height += font->getKerningHeight(); // justification - switch (HAlign) { + switch (HAlign) + { case EGUIA_CENTER: // align to h centre - CurrentTextRect.UpperLeftCorner.X = - (FrameRect.getWidth() / 2) - (d.Width / 2); - CurrentTextRect.LowerRightCorner.X = - (FrameRect.getWidth() / 2) + (d.Width / 2); + CurrentTextRect.UpperLeftCorner.X = (FrameRect.getWidth()/2) - (d.Width/2); + CurrentTextRect.LowerRightCorner.X = (FrameRect.getWidth()/2) + (d.Width/2); break; case EGUIA_LOWERRIGHT: // align to right edge @@ -1254,77 +1295,82 @@ void intlGUIEditBox::setTextRect(s32 line) // align to left edge CurrentTextRect.UpperLeftCorner.X = 0; CurrentTextRect.LowerRightCorner.X = d.Width; + } - switch (VAlign) { + switch (VAlign) + { case EGUIA_CENTER: // align to v centre - CurrentTextRect.UpperLeftCorner.Y = (FrameRect.getHeight() / 2) - - (lineCount * d.Height) / 2 + - d.Height * line; + CurrentTextRect.UpperLeftCorner.Y = + (FrameRect.getHeight()/2) - (lineCount*d.Height)/2 + d.Height*line; break; case EGUIA_LOWERRIGHT: // align to bottom edge - CurrentTextRect.UpperLeftCorner.Y = FrameRect.getHeight() - - lineCount * d.Height + - d.Height * line; + CurrentTextRect.UpperLeftCorner.Y = + FrameRect.getHeight() - lineCount*d.Height + d.Height*line; break; default: // align to top edge - CurrentTextRect.UpperLeftCorner.Y = d.Height * line; + CurrentTextRect.UpperLeftCorner.Y = d.Height*line; break; } - CurrentTextRect.UpperLeftCorner.X -= HScrollPos; + CurrentTextRect.UpperLeftCorner.X -= HScrollPos; CurrentTextRect.LowerRightCorner.X -= HScrollPos; - CurrentTextRect.UpperLeftCorner.Y -= VScrollPos; + CurrentTextRect.UpperLeftCorner.Y -= VScrollPos; CurrentTextRect.LowerRightCorner.Y = CurrentTextRect.UpperLeftCorner.Y + d.Height; CurrentTextRect += FrameRect.UpperLeftCorner; + } + s32 intlGUIEditBox::getLineFromPos(s32 pos) { if (!WordWrap && !MultiLine) return 0; - s32 i = 0; - while (i < (s32)BrokenTextPositions.size()) { + s32 i=0; + while (i < (s32)BrokenTextPositions.size()) + { if (BrokenTextPositions[i] > pos) - return i - 1; + return i-1; ++i; } return (s32)BrokenTextPositions.size() - 1; } + void intlGUIEditBox::inputChar(wchar_t c) { if (!IsEnabled || !m_writable) return; - if (c != 0) { - if (Text.size() < Max || Max == 0) { + if (c != 0) + { + if (Text.size() < Max || Max == 0) + { core::stringw s; - if (MarkBegin != MarkEnd) { + if (MarkBegin != MarkEnd) + { // replace marked text - const s32 realmbgn = - MarkBegin < MarkEnd ? MarkBegin : MarkEnd; - const s32 realmend = - MarkBegin < MarkEnd ? MarkEnd : MarkBegin; + const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; + const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; s = Text.subString(0, realmbgn); s.append(c); - s.append(Text.subString( - realmend, Text.size() - realmend)); + s.append( Text.subString(realmend, Text.size()-realmend) ); Text = s; - CursorPos = realmbgn + 1; - } else { + CursorPos = realmbgn+1; + } + else + { // add new character s = Text.subString(0, CursorPos); s.append(c); - s.append(Text.subString( - CursorPos, Text.size() - CursorPos)); + s.append( Text.subString(CursorPos, Text.size()-CursorPos) ); Text = s; ++CursorPos; } @@ -1338,6 +1384,7 @@ void intlGUIEditBox::inputChar(wchar_t c) calculateScrollPos(); } + void intlGUIEditBox::calculateScrollPos() { if (!AutoScroll) @@ -1348,22 +1395,21 @@ void intlGUIEditBox::calculateScrollPos() setTextRect(cursLine); // don't do horizontal scrolling when wordwrap is enabled. - if (!WordWrap) { + if (!WordWrap) + { // get cursor position - IGUISkin *skin = Environment->getSkin(); + IGUISkin* skin = Environment->getSkin(); if (!skin) return; - IGUIFont *font = OverrideFont ? OverrideFont : skin->getFont(); + IGUIFont* font = OverrideFont ? OverrideFont : skin->getFont(); if (!font) return; core::stringw *txtLine = MultiLine ? &BrokenText[cursLine] : &Text; - s32 cPos = MultiLine ? CursorPos - BrokenTextPositions[cursLine] - : CursorPos; + s32 cPos = MultiLine ? CursorPos - BrokenTextPositions[cursLine] : CursorPos; s32 cStart = CurrentTextRect.UpperLeftCorner.X + HScrollPos + - font->getDimension(txtLine->subString(0, cPos).c_str()) - .Width; + font->getDimension(txtLine->subString(0, cPos).c_str()).Width; s32 cEnd = cStart + font->getDimension(L"_ ").Width; @@ -1382,11 +1428,9 @@ void intlGUIEditBox::calculateScrollPos() // vertical scroll position if (FrameRect.LowerRightCorner.Y < CurrentTextRect.LowerRightCorner.Y) - VScrollPos += CurrentTextRect.LowerRightCorner.Y - - FrameRect.LowerRightCorner.Y; // scrolling downwards + VScrollPos += CurrentTextRect.LowerRightCorner.Y - FrameRect.LowerRightCorner.Y; // scrolling downwards else if (FrameRect.UpperLeftCorner.Y > CurrentTextRect.UpperLeftCorner.Y) - VScrollPos += CurrentTextRect.UpperLeftCorner.Y - - FrameRect.UpperLeftCorner.Y; // scrolling upwards + VScrollPos += CurrentTextRect.UpperLeftCorner.Y - FrameRect.UpperLeftCorner.Y; // scrolling upwards // todo: adjust scrollbar if (m_vscrollbar) @@ -1396,24 +1440,26 @@ void intlGUIEditBox::calculateScrollPos() //! set text markers void intlGUIEditBox::setTextMarkers(s32 begin, s32 end) { - if (begin != MarkBegin || end != MarkEnd) { - MarkBegin = begin; - MarkEnd = end; - sendGuiEvent(EGET_EDITBOX_MARKING_CHANGED); - } + if ( begin != MarkBegin || end != MarkEnd ) + { + MarkBegin = begin; + MarkEnd = end; + sendGuiEvent(EGET_EDITBOX_MARKING_CHANGED); + } } //! send some gui event to parent void intlGUIEditBox::sendGuiEvent(EGUI_EVENT_TYPE type) { - if (Parent) { - SEvent e; - e.EventType = EET_GUI_EVENT; - e.GUIEvent.Caller = this; - e.GUIEvent.Element = 0; - e.GUIEvent.EventType = type; - - Parent->OnEvent(e); + if ( Parent ) + { + SEvent e; + e.EventType = EET_GUI_EVENT; + e.GUIEvent.Caller = this; + e.GUIEvent.Element = 0; + e.GUIEvent.EventType = type; + + Parent->OnEvent(e); } } @@ -1425,8 +1471,8 @@ void intlGUIEditBox::createVScrollBar() if (OverrideFont) { fontHeight = OverrideFont->getDimension(L"").Height; } else { - if (IGUISkin *skin = Environment->getSkin()) { - if (IGUIFont *font = skin->getFont()) { + if (IGUISkin* skin = Environment->getSkin()) { + if (IGUIFont* font = skin->getFont()) { fontHeight = font->getDimension(L"").Height; } } @@ -1436,8 +1482,8 @@ void intlGUIEditBox::createVScrollBar() irr::core::rect<s32> scrollbarrect = FrameRect; scrollbarrect.UpperLeftCorner.X += FrameRect.getWidth() - m_scrollbar_width; - m_vscrollbar = new GUIScrollBar( - Environment, getParent(), -1, scrollbarrect, false, true); + m_vscrollbar = new GUIScrollBar(Environment, getParent(), -1, + scrollbarrect, false, true); m_vscrollbar->setVisible(false); m_vscrollbar->setSmallStep(3 * fontHeight); @@ -1469,7 +1515,7 @@ void intlGUIEditBox::updateVScrollBar() } // check if a vertical scrollbar is needed ? - if (getTextDimension().Height > (u32)FrameRect.getHeight()) { + if (getTextDimension().Height > (u32) FrameRect.getHeight()) { s32 scrollymax = getTextDimension().Height - FrameRect.getHeight(); if (scrollymax != m_vscrollbar->getMax()) { m_vscrollbar->setMax(scrollymax); @@ -1500,34 +1546,33 @@ void intlGUIEditBox::setWritable(bool can_write_text) } //! Writes attributes of the element. -void intlGUIEditBox::serializeAttributes( - io::IAttributes *out, io::SAttributeReadWriteOptions *options = 0) const +void intlGUIEditBox::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const { // IGUIEditBox::serializeAttributes(out,options); - out->addBool("OverrideColorEnabled", OverrideColorEnabled); - out->addColor("OverrideColor", OverrideColor); + 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->addInt ("MaxChars", Max); + out->addBool ("WordWrap", WordWrap); + out->addBool ("MultiLine", MultiLine); + out->addBool ("AutoScroll", 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); + IGUIEditBox::serializeAttributes(out,options); } + //! Reads attributes of the element -void intlGUIEditBox::deserializeAttributes( - io::IAttributes *in, io::SAttributeReadWriteOptions *options = 0) +void intlGUIEditBox::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) { - IGUIEditBox::deserializeAttributes(in, options); + IGUIEditBox::deserializeAttributes(in,options); setOverrideColor(in->getAttributeAsColor("OverrideColor")); enableOverrideColor(in->getAttributeAsBool("OverrideColorEnabled")); @@ -1542,14 +1587,13 @@ void intlGUIEditBox::deserializeAttributes( else setPasswordBox(in->getAttributeAsBool("PasswordBox"), ch[0]); - setTextAlignment((EGUI_ALIGNMENT)in->getAttributeAsEnumeration( - "HTextAlign", GUIAlignmentNames), - (EGUI_ALIGNMENT)in->getAttributeAsEnumeration( - "VTextAlign", GUIAlignmentNames)); + setTextAlignment( (EGUI_ALIGNMENT) in->getAttributeAsEnumeration("HTextAlign", GUIAlignmentNames), + (EGUI_ALIGNMENT) in->getAttributeAsEnumeration("VTextAlign", GUIAlignmentNames)); setWritable(in->getAttributeAsBool("Writable")); // setOverrideFont(in->getAttributeAsFont("OverrideFont")); } + } // end namespace gui } // end namespace irr |