[Scummvm-cvs-logs] scummvm master -> 8725f2cff2357049a3759f24e3fa530c25644e25

eriktorbjorn eriktorbjorn at telia.com
Sun Feb 8 13:57:59 CET 2015


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
8725f2cff2 ZVISION: Limit input text to the width of the input control


Commit: 8725f2cff2357049a3759f24e3fa530c25644e25
    https://github.com/scummvm/scummvm/commit/8725f2cff2357049a3759f24e3fa530c25644e25
Author: Torbjörn Andersson (eriktorbjorn at users.sourceforge.net)
Date: 2015-02-08T13:56:01+01:00

Commit Message:
ZVISION: Limit input text to the width of the input control

This is to prevent the player from entering ridiculously long
savegame descriptions.

Changed paths:
    engines/zvision/scripting/controls/input_control.cpp
    engines/zvision/scripting/controls/input_control.h



diff --git a/engines/zvision/scripting/controls/input_control.cpp b/engines/zvision/scripting/controls/input_control.cpp
index b25aa13..20c8e7c 100644
--- a/engines/zvision/scripting/controls/input_control.cpp
+++ b/engines/zvision/scripting/controls/input_control.cpp
@@ -110,6 +110,10 @@ InputControl::InputControl(ZVision *engine, uint32 key, Common::SeekableReadStre
 		_engine->getScriptManager()->trimCommentsAndWhiteSpace(&line);
 		getParams(line, param, values);
 	}
+
+	_maxTxtWidth = _textRectangle.width();
+	if (_animation)
+		_maxTxtWidth -= _animation->getWidth();
 }
 
 InputControl::~InputControl() {
@@ -208,12 +212,20 @@ bool InputControl::process(uint32 deltaTimeInMillis) {
 		Graphics::Surface txt;
 		txt.copyFrom(*_background);
 
+		int32 oldTxtWidth = _txtWidth;
+
 		if (!_readOnly || !_focused)
 			_txtWidth = _engine->getTextRenderer()->drawTxt(_currentInputText, _stringInit, txt);
 		else
 			_txtWidth = _engine->getTextRenderer()->drawTxt(_currentInputText, _stringChooserInit, txt);
 
-		_engine->getRenderManager()->blitSurfaceToBkg(txt, _textRectangle.left, _textRectangle.top);
+		if (_readOnly || _txtWidth <= _maxTxtWidth)
+			_engine->getRenderManager()->blitSurfaceToBkg(txt, _textRectangle.left, _textRectangle.top);
+		else {
+			// Assume the last character caused the overflow.
+			_currentInputText.deleteLastChar();
+			_txtWidth = oldTxtWidth;
+		}
 
 		txt.free();
 	}
diff --git a/engines/zvision/scripting/controls/input_control.h b/engines/zvision/scripting/controls/input_control.h
index e23ba0b..7f272e8 100644
--- a/engines/zvision/scripting/controls/input_control.h
+++ b/engines/zvision/scripting/controls/input_control.h
@@ -56,6 +56,7 @@ private:
 	bool _readOnly;
 
 	int16 _txtWidth;
+	int16 _maxTxtWidth;
 	Video::VideoDecoder *_animation;
 	int32 _frameDelay;
 	int16 _frame;






More information about the Scummvm-git-logs mailing list