[Scummvm-cvs-logs] SF.net SVN: scummvm:[48796] scummvm/trunk/engines/sci/graphics/controls.cpp
m_kiewitz at users.sourceforge.net
m_kiewitz at users.sourceforge.net
Sun Apr 25 18:43:16 CEST 2010
Revision: 48796
http://scummvm.svn.sourceforge.net/scummvm/?rev=48796&view=rev
Author: m_kiewitz
Date: 2010-04-25 16:43:16 +0000 (Sun, 25 Apr 2010)
Log Message:
-----------
SCI: we check for enough space, before adding pressed characters in textedit controls
Modified Paths:
--------------
scummvm/trunk/engines/sci/graphics/controls.cpp
Modified: scummvm/trunk/engines/sci/graphics/controls.cpp
===================================================================
--- scummvm/trunk/engines/sci/graphics/controls.cpp 2010-04-25 15:44:11 UTC (rev 48795)
+++ scummvm/trunk/engines/sci/graphics/controls.cpp 2010-04-25 16:43:16 UTC (rev 48796)
@@ -149,6 +149,7 @@
Common::String text;
uint16 textSize, eventType, eventKey;
bool textChanged = false;
+ bool textAddChar = false;
Common::Rect rect;
if (textReference.isNull())
@@ -195,9 +196,7 @@
default:
if (eventKey > 31 && eventKey < 256 && textSize < maxChars) {
// insert pressed character
- // we check, if there is space left for this character
-
- text.insertChar(eventKey, cursorPos++);
+ textAddChar = true;
textChanged = true;
}
break;
@@ -211,6 +210,20 @@
GuiResourceId fontId = GET_SEL32V(_segMan, controlObject, SELECTOR(font));
rect = Common::Rect(GET_SEL32V(_segMan, controlObject, SELECTOR(nsLeft)), GET_SEL32V(_segMan, controlObject, SELECTOR(nsTop)),
GET_SEL32V(_segMan, controlObject, SELECTOR(nsRight)), GET_SEL32V(_segMan, controlObject, SELECTOR(nsBottom)));
+ if (textAddChar) {
+ // We check, if we are really able to add the new char
+ uint16 textWidth = 0;
+ const char *textPtr = text.c_str();
+ _text16->SetFont(fontId);
+ while (*textPtr)
+ textWidth += _text16->_font->getCharWidth(*textPtr++);
+ textWidth += _text16->_font->getCharWidth(eventKey);
+ if (textWidth >= rect.width()) {
+ _text16->SetFont(oldFontId);
+ return;
+ }
+ text.insertChar(eventKey, cursorPos++);
+ }
texteditCursorErase();
_paint16->eraseRect(rect);
_text16->Box(text.c_str(), 0, rect, SCI_TEXT16_ALIGNMENT_LEFT, fontId);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list