aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/graphics
diff options
context:
space:
mode:
authorMartin Kiewitz2010-04-25 16:43:16 +0000
committerMartin Kiewitz2010-04-25 16:43:16 +0000
commit14ac9b54a029fe4400ee5f6bd70e39e1ff459100 (patch)
tree881e345ae44056513522fbbb0c1946799696c06e /engines/sci/graphics
parentc893ba1508ac849c34ca555496a3eb465192a362 (diff)
downloadscummvm-rg350-14ac9b54a029fe4400ee5f6bd70e39e1ff459100.tar.gz
scummvm-rg350-14ac9b54a029fe4400ee5f6bd70e39e1ff459100.tar.bz2
scummvm-rg350-14ac9b54a029fe4400ee5f6bd70e39e1ff459100.zip
SCI: we check for enough space, before adding pressed characters in textedit controls
svn-id: r48796
Diffstat (limited to 'engines/sci/graphics')
-rw-r--r--engines/sci/graphics/controls.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/engines/sci/graphics/controls.cpp b/engines/sci/graphics/controls.cpp
index 6ffb316924..855147144c 100644
--- a/engines/sci/graphics/controls.cpp
+++ b/engines/sci/graphics/controls.cpp
@@ -149,6 +149,7 @@ void GfxControls::kernelTexteditChange(reg_t controlObject, reg_t eventObject) {
Common::String text;
uint16 textSize, eventType, eventKey;
bool textChanged = false;
+ bool textAddChar = false;
Common::Rect rect;
if (textReference.isNull())
@@ -195,9 +196,7 @@ void GfxControls::kernelTexteditChange(reg_t controlObject, reg_t eventObject) {
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 @@ void GfxControls::kernelTexteditChange(reg_t controlObject, reg_t eventObject) {
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);