[Scummvm-git-logs] scummvm master -> 1425096dd7a7098a3a7517d1e6f893785ed7f1e3

dreammaster dreammaster at scummvm.org
Sun Nov 26 02:54:32 CET 2017


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:
1425096dd7 XEEN: Add animated cursor for text input


Commit: 1425096dd7a7098a3a7517d1e6f893785ed7f1e3
    https://github.com/scummvm/scummvm/commit/1425096dd7a7098a3a7517d1e6f893785ed7f1e3
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2017-11-25T20:54:25-05:00

Commit Message:
XEEN: Add animated cursor for text input

Changed paths:
    engines/xeen/dialogs_input.cpp
    engines/xeen/dialogs_input.h


diff --git a/engines/xeen/dialogs_input.cpp b/engines/xeen/dialogs_input.cpp
index f66bd24..6ffec50 100644
--- a/engines/xeen/dialogs_input.cpp
+++ b/engines/xeen/dialogs_input.cpp
@@ -42,7 +42,7 @@ int Input::getString(Common::String &line, uint maxLen, int maxWidth, bool isNum
 	_window->update();
 
 	while (!_vm->shouldQuit()) {
-		Common::KeyCode keyCode = doCursor(msg);
+		Common::KeyCode keyCode = waitForKey(msg);
 
 		bool refresh = false;
 		if ((keyCode == Common::KEYCODE_BACKSPACE || keyCode == Common::KEYCODE_DELETE)
@@ -72,7 +72,7 @@ int Input::getString(Common::String &line, uint maxLen, int maxWidth, bool isNum
 	return line.size();
 }
 
-Common::KeyCode Input::doCursor(const Common::String &msg) {
+Common::KeyCode Input::waitForKey(const Common::String &msg) {
 	EventsManager &events = *_vm->_events;
 	Interface &intf = *_vm->_interface;
 	Screen &screen = *_vm->_screen;
@@ -92,12 +92,14 @@ Common::KeyCode Input::doCursor(const Common::String &msg) {
 		if (flag)
 			intf.draw3d(false);
 		_window->writeString(msg);
+		animateCursor();
 		_window->update();
 
 		if (flag)
 			screen._windows[3].update();
 
 		events.wait(1);
+
 		if (events.isKeyPending()) {
 			Common::KeyState keyState;
 			events.getKey(keyState);
@@ -115,6 +117,22 @@ Common::KeyCode Input::doCursor(const Common::String &msg) {
 	return ch;
 }
 
+void Input::animateCursor() {
+	Screen &screen = *_vm->_screen;
+
+	// Iterate through each frame
+	_cursorAnimIndex = _cursorAnimIndex ? _cursorAnimIndex - 1 : 5;
+	static const int CURSOR_ANIMATION_IDS[] = { 32, 124, 126, 127, 126, 124 };
+
+	// Form a string for the cursor and write it out
+	Common::String cursorStr = Common::String::format("%c",
+		CURSOR_ANIMATION_IDS[_cursorAnimIndex]);
+
+	Common::Point writePos = screen._writePos;
+	_window->writeString(cursorStr);
+	screen._writePos = writePos;
+}
+
 /*------------------------------------------------------------------------*/
 
 StringInput::StringInput(XeenEngine *vm): Input(vm, &vm->_screen->_windows[6]) {
diff --git a/engines/xeen/dialogs_input.h b/engines/xeen/dialogs_input.h
index 26fdb47..c6b0e69 100644
--- a/engines/xeen/dialogs_input.h
+++ b/engines/xeen/dialogs_input.h
@@ -32,18 +32,25 @@ namespace Xeen {
 class Input : public ButtonContainer {
 private:
 	/**
-	 * Draws the cursor and waits until the user presses a key
+	 * Draws the text input and cursor and waits until the user presses a key
 	 */
-	Common::KeyCode doCursor(const Common::String &msg);
+	Common::KeyCode waitForKey(const Common::String &msg);
+
+	/**
+	 * Animates the box text cursor
+	 */
+	void animateCursor();
 protected:
 	Window *_window;
+	int _cursorAnimIndex;
 
 	/**
 	 * Allows the user to enter a string
 	 */
 	int getString(Common::String &line, uint maxLen, int maxWidth, bool isNumeric);
 
-	Input(XeenEngine *vm, Window *window) : ButtonContainer(vm), _window(window) {}
+	Input(XeenEngine *vm, Window *window) : ButtonContainer(vm),
+		_window(window), _cursorAnimIndex(0) {}
 public:
 	static int show(XeenEngine *vm, Window *window, Common::String &line,
 		uint maxLen, int maxWidth, bool isNumeric = false);





More information about the Scummvm-git-logs mailing list