[Scummvm-git-logs] scummvm master -> 54726ef20d6f56a118b5cc7295021d29c86a04c4

dreammaster noreply at scummvm.org
Mon Nov 9 06:05:08 UTC 2026


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

Summary:
1df4070041 GRAPHICS: VIEWS: Add event-based engine base to Graphics::Views
bd684f43d8 GRAPHICS: VIEWS: Don't needlessly redraw obscured views after view removal
54726ef20d GRAPHICS: VIEWS: Force frame redraw after keypresses & mouse clicks


Commit: 1df4070041b08c0bbcf63743c961c6a135509e63
    https://github.com/scummvm/scummvm/commit/1df4070041b08c0bbcf63743c961c6a135509e63
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2026-11-08T20:05:02-10:00

Commit Message:
GRAPHICS: VIEWS: Add event-based engine base to Graphics::Views

Changed paths:
  A devtools/create_engine/files_events/configure.engine
  A graphics/views/events.cpp
  A graphics/views/events.h
  A graphics/views/gfx_surface.cpp
  A graphics/views/gfx_surface.h
  A graphics/views/messages.cpp
  A graphics/views/messages.h
  A graphics/views/rect.h
  A graphics/views/view.cpp
  A graphics/views/view.h
  R devtools/create_engine/files_events/events.cpp
  R devtools/create_engine/files_events/events.h
  R devtools/create_engine/files_events/messages.cpp
  R devtools/create_engine/files_events/messages.h
  R devtools/create_engine/files_events/view.cpp
  R devtools/create_engine/files_events/view.h
    configure
    devtools/create_engine/create_engine.cpp
    devtools/create_engine/files_events/view1.h
    devtools/create_engine/files_events/xyzzy.cpp
    devtools/create_engine/files_events/xyzzy.h
    graphics/module.mk


diff --git a/configure b/configure
index 1f24e389a75..0782d674a8a 100755
--- a/configure
+++ b/configure
@@ -211,6 +211,7 @@ _mt32emu=yes
 _lua=yes
 _mactoolbox=yes
 _mfc=yes
+_views=yes
 _build_scalers=yes
 _build_hq_scalers=yes
 _build_edge_scalers=yes
@@ -374,6 +375,7 @@ add_component truemotion1 "TrueMotion 1" "_truemotion1" "USE_TRUEMOTION1"
 add_component universaltracker "External Tracker Libraries" "_universaltracker" "USE_UNIVERSALTRACKER"
 add_component unp64 "UNP64" "_unp64" "USE_UNP64"
 add_component vc1 "VC-1 / WMV3" "_vc1" "USE_VC1"
+add_component views "Event-based Views" "_views" "USE_VIEWS"
 add_component vgmtrans_audio "VGMTrans Soundfont audio" "_vgmtrans_audio" "USE_VGMTRANS_AUDIO"
 add_component xan "XAN" "_xan" "USE_XAN"
 
diff --git a/devtools/create_engine/create_engine.cpp b/devtools/create_engine/create_engine.cpp
index 12aa7f1a77f..33ff83eb07a 100644
--- a/devtools/create_engine/create_engine.cpp
+++ b/devtools/create_engine/create_engine.cpp
@@ -49,20 +49,17 @@ static const char *const FILENAMES[] = {
 };
 
 static const char *const FILENAMES_EVENTS[] = {
-	"files/configure.engine", "files/console.cpp", "files/console.h",
+	"files_events/configure.engine", "files/console.cpp", "files/console.h",
 	"files/credits.pl", "files/detection.cpp", "files/detection.h",
 	"files/detection_tables.h",
-	"files_events/events.cpp", "files_events/events.h",
-	"files_events/messages.cpp", "files_events/messages.h",
 	"files/metaengine.cpp", "files/metaengine.h",
 	"files_events/module.mk", "files_events/xyzzy.cpp",
 	"files_events/xyzzy.h", "files/POTFILES", "files_events/views.h",
-	"files_events/view.cpp", "files_events/view.h",
 	"files_events/view1.cpp", "files_events/view1.h",
 	nullptr
 };
 
-const char *const ENGINES = "create_project ..\\.. --msvc\n";
+const char *const ENGINES = "create_project ..\\.. --msvc";
 
 bool fileExists(const char *name) {
 #ifdef _WIN32
@@ -183,7 +180,7 @@ void create_batch_file(const char *prefix) {
 
 	// Get each line until there are none left
 	while (fgets(line, MAX_LINE_LENGTH, in)) {
-		if (!strcmp(line, ENGINES)) {
+		if (!strncmp(line, ENGINES, strlen(ENGINES))) {
 			snprintf(line + strlen(line) - 1, MAX_LINE_LENGTH - strlen(line) + 1,
 				" --disable-all-engines --disable-detection-full --enable-engine=%s\n",
 				engineLowercase);
diff --git a/devtools/create_engine/files_events/configure.engine b/devtools/create_engine/files_events/configure.engine
new file mode 100644
index 00000000000..b26de280e3d
--- /dev/null
+++ b/devtools/create_engine/files_events/configure.engine
@@ -0,0 +1,3 @@
+# This file is included from the main "configure" script
+# add_engine [name] [desc] [build-by-default] [subengines] [base games] [deps] [components]
+add_engine xyzzy "Xyzzy" no "" "" "" "views"
diff --git a/devtools/create_engine/files_events/view1.h b/devtools/create_engine/files_events/view1.h
index 62d0fc50bf9..0eab19cc52a 100644
--- a/devtools/create_engine/files_events/view1.h
+++ b/devtools/create_engine/files_events/view1.h
@@ -22,11 +22,13 @@
 #ifndef XYZZY_VIEW1_H
 #define XYZZY_VIEW1_H
 
-#include "xyzzy/view.h"
+#include "graphics/views/view.h"
 
 namespace Xyzzy {
 
-class View1 : public View {
+using namespace Graphics::Views;
+
+class View1 : public Graphics::Views::View {
 private:
 	byte _pal[256 * 3] = { 0 };
 	int _offset = 0;
diff --git a/devtools/create_engine/files_events/xyzzy.cpp b/devtools/create_engine/files_events/xyzzy.cpp
index d3a7e15bd92..86aa68d3117 100644
--- a/devtools/create_engine/files_events/xyzzy.cpp
+++ b/devtools/create_engine/files_events/xyzzy.cpp
@@ -22,6 +22,7 @@
 #include "xyzzy/xyzzy.h"
 #include "xyzzy/detection.h"
 #include "xyzzy/console.h"
+#include "xyzzy/views.h"
 #include "common/scummsys.h"
 #include "common/config-manager.h"
 #include "common/debug-channels.h"
@@ -34,8 +35,8 @@ namespace Xyzzy {
 
 XyzzyEngine *g_engine;
 
-XyzzyEngine::XyzzyEngine(OSystem *syst, const ADGameDescription *gameDesc) : Engine(syst),
-	_gameDescription(gameDesc), _randomSource("Xyzzy") {
+XyzzyEngine::XyzzyEngine(OSystem *syst, const ADGameDescription *gameDesc) :
+		Engine(syst), Events("Xyzzy"), _gameDescription(gameDesc) {
 	g_engine = this;
 }
 
@@ -57,7 +58,11 @@ Common::Error XyzzyEngine::run() {
 	// Set the engine's debugger console
 	setDebugger(new Console());
 
+	// Set up the view list and run the game
+	Views views;
+	addView("View1");
 	runGame();
+	(void)views;		// Suppress any warnings of unused local
 
 	return Common::kNoError;
 }
diff --git a/devtools/create_engine/files_events/xyzzy.h b/devtools/create_engine/files_events/xyzzy.h
index eb2cac31841..a37f841b72d 100644
--- a/devtools/create_engine/files_events/xyzzy.h
+++ b/devtools/create_engine/files_events/xyzzy.h
@@ -33,18 +33,18 @@
 #include "engines/engine.h"
 #include "engines/savestate.h"
 #include "graphics/screen.h"
+#include "graphics/views/view.h"
 
 #include "xyzzy/detection.h"
-#include "xyzzy/events.h"
 
 namespace Xyzzy {
 
 struct XyzzyGameDescription;
 
-class XyzzyEngine : public Engine, public Events {
+class XyzzyEngine : public Engine, public Graphics::Views::Events {
 private:
 	const ADGameDescription *_gameDescription;
-	Common::RandomSource _randomSource;
+
 protected:
 	// Engine APIs
 	Common::Error run() override;
@@ -67,13 +67,6 @@ public:
 	 */
 	Common::String getGameId() const;
 
-	/**
-	 * Gets a random number
-	 */
-	uint32 getRandomNumber(uint maxNum) {
-		return _randomSource.getRandomNumber(maxNum);
-	}
-
 	bool hasFeature(EngineFeature f) const override {
 		return
 		    (f == kSupportsLoadingDuringRuntime) ||
diff --git a/graphics/module.mk b/graphics/module.mk
index 2cc720b52d6..618da593121 100644
--- a/graphics/module.mk
+++ b/graphics/module.mk
@@ -211,6 +211,14 @@ MODULE_OBJS += \
 	scaler/edge.o
 endif
 
+ifdef USE_VIEWS
+MODULE_OBJS += \
+	views/events.o \
+	views/gfx_surface.o \
+	views/messages.o \
+	views/view.o
+endif
+
 endif
 
 ifeq ($(BACKEND),atari)
diff --git a/devtools/create_engine/files_events/events.cpp b/graphics/views/events.cpp
similarity index 66%
rename from devtools/create_engine/files_events/events.cpp
rename to graphics/views/events.cpp
index 7d3b2335865..616479b4142 100644
--- a/devtools/create_engine/files_events/events.cpp
+++ b/graphics/views/events.cpp
@@ -19,17 +19,24 @@
  *
  */
 
+#include "common/system.h"
 #include "common/config-manager.h"
+#include "common/events.h"
+#include "common/text-to-speech.h"
+#include "engines/engine.h"
+#include "graphics/fonts/dosfont.h"
 #include "graphics/screen.h"
-#include "xyzzy/events.h"
-#include "xyzzy/xyzzy.h"
-#include "xyzzy/views.h"
+#include "graphics/views/events.h"
 
-namespace Xyzzy {
+namespace Graphics {
+namespace Views {
+
+#define FRAME_RATE 20
+#define FRAME_DELAY (1000 / FRAME_RATE)
 
 Events *g_events;
 
-Events::Events() : UIElement("Root", nullptr) {
+Events::Events(const Common::String &engineName) : UIElement("Root", nullptr), _randomSource(engineName) {
 	g_events = this;
 }
 
@@ -38,44 +45,65 @@ Events::~Events() {
 }
 
 void Events::runGame() {
-	uint currTime, nextFrameTime = 0;
+	uint nextFrameTime = 0;
 	_screen = new Graphics::Screen();
-	Views views;	// Loads all views in the structure
 
 	// Run the game
 	int saveSlot = ConfMan.getInt("save_slot");
 	if (saveSlot != -1)
 		g_engine->loadGameState(saveSlot);
 
-	addView("View1");
-
+	// Main game loop
 	Common::Event e;
 	while (!_views.empty() && !shouldQuit()) {
 		while (g_system->getEventManager()->pollEvent(e)) {
 			if (e.type == Common::EVENT_QUIT ||
-					e.type == Common::EVENT_RETURN_TO_LAUNCHER) {
+				e.type == Common::EVENT_RETURN_TO_LAUNCHER) {
 				_views.clear();
 				break;
-			} else {
-				processEvent(e);
 			}
+
+			processEvent(e);
 		}
 
 		if (_views.empty())
 			break;
 
 		g_system->delayMillis(10);
-		if ((currTime = g_system->getMillis()) >= nextFrameTime) {
+
+		uint currTime = g_system->getMillis();
+		if (currTime >= nextFrameTime) {
 			nextFrameTime = currTime + FRAME_DELAY;
-			tick();
-			drawElements();
-			_screen->update();
+			nextFrame();
 		}
 	}
 
 	delete _screen;
 }
 
+int Events::getRandomNumber(int minNumber, int maxNumber) {
+	return _randomSource.getRandomNumberRng(minNumber, maxNumber);
+}
+
+int Events::getRandomNumber(int maxNumber) {
+	return _randomSource.getRandomNumber(maxNumber);
+}
+
+void Events::nextFrame() {
+	// Do tick action to the views to handle gameplay logic
+	tick();
+
+	// Draw the current view's elements as needed, and update screen
+	drawElements();
+	updateScreen();
+}
+
+void Events::updateScreen() {
+	_screen->update();
+}
+
+#define LOOP_THRESHOLD 5
+
 void Events::processEvent(Common::Event &ev) {
 	switch (ev.type) {
 	case Common::EVENT_KEYDOWN:
@@ -105,35 +133,44 @@ void Events::processEvent(Common::Event &ev) {
 
 void Events::replaceView(UIElement *ui, bool replaceAllViews) {
 	assert(ui);
-	UIElement *priorView = focusedView();
+	UIElement *oldView = focusedView();
 
 	if (replaceAllViews) {
 		clearViews();
 
 	} else if (!_views.empty()) {
-		priorView->msgUnfocus(UnfocusMessage());
+		oldView->msgUnfocus(UnfocusMessage());
 		_views.pop();
 	}
 
+	// Redraw any prior views to erase the removed view
+	for (uint i = 0; i < _views.size(); ++i) {
+		_views[i]->redraw();
+		_views[i]->draw();
+	}
+
+	// Add the new view
 	_views.push(ui);
+
 	ui->redraw();
-	ui->msgFocus(FocusMessage(priorView));
+	ui->msgFocus(FocusMessage(oldView));
+	ui->draw();
 }
 
 void Events::replaceView(const Common::String &name, bool replaceAllViews) {
-	replaceView(findView(name));
+	replaceView(findView(name), replaceAllViews);
 }
 
 void Events::addView(UIElement *ui) {
 	assert(ui);
-	UIElement *priorView = focusedView();
+	UIElement *oldView = focusedView();
 
 	if (!_views.empty())
-		priorView->msgUnfocus(UnfocusMessage());
+		oldView->msgUnfocus(UnfocusMessage());
 
 	_views.push(ui);
 	ui->redraw();
-	ui->msgFocus(FocusMessage(priorView));
+	ui->msgFocus(FocusMessage(oldView));
 }
 
 void Events::addView(const Common::String &name) {
@@ -141,30 +178,23 @@ void Events::addView(const Common::String &name) {
 }
 
 void Events::popView() {
-	UIElement *priorView = focusedView();
-	priorView->msgUnfocus(UnfocusMessage());
+	UIElement *oldView = focusedView();
+	oldView->msgUnfocus(UnfocusMessage());
 	_views.pop();
 
-	for (int i = 0; i < (int)_views.size() - 1; ++i) {
+	for (uint i = 0; i < _views.size(); ++i) {
 		_views[i]->redraw();
 		_views[i]->draw();
 	}
 
 	if (!_views.empty()) {
 		UIElement *view = focusedView();
-		view->msgFocus(FocusMessage(priorView));
+		view->msgFocus(FocusMessage(oldView));
 		view->redraw();
 		view->draw();
 	}
 }
 
-void Events::redrawViews() {
-	for (uint i = 0; i < _views.size(); ++i) {
-		_views[i]->redraw();
-		_views[i]->draw();
-	}
-}
-
 bool Events::isPresent(const Common::String &name) const {
 	for (uint i = 0; i < _views.size(); ++i) {
 		if (_views[i]->_name == name)
@@ -174,6 +204,11 @@ bool Events::isPresent(const Common::String &name) const {
 	return false;
 }
 
+void Events::drawElements() {
+	if (!_views.empty())
+		focusedView()->drawElements();
+}
+
 void Events::clearViews() {
 	if (!_views.empty())
 		focusedView()->msgUnfocus(UnfocusMessage());
@@ -181,22 +216,14 @@ void Events::clearViews() {
 	_views.clear();
 }
 
-void Events::addKeypress(const Common::KeyCode kc) {
-	Common::KeyState ks;
-	ks.keycode = kc;
-	if (kc >= Common::KEYCODE_SPACE && kc <= Common::KEYCODE_TILDE)
-		ks.ascii = kc;
-
-	focusedView()->msgKeypress(KeypressMessage(ks));
+Graphics::Font *Events::createFont() const {
+	return new Graphics::DosFont();
 }
 
 /*------------------------------------------------------------------------*/
 
-Bounds::Bounds(Common::Rect &innerBounds) :
-		_bounds(0, 0, 320, 200),
-		_innerBounds(innerBounds),
-		left(_bounds.left), top(_bounds.top),
-		right(_bounds.right), bottom(_bounds.bottom) {
+Bounds::Bounds(Common::Rect &innerBounds) : _bounds(0, 0, 320, 200), _innerBounds(innerBounds),
+		left(_bounds.left), top(_bounds.top), right(_bounds.right), bottom(_bounds.bottom) {
 }
 
 Bounds &Bounds::operator=(const Common::Rect &r) {
@@ -214,14 +241,11 @@ void Bounds::setBorderSize(size_t borderSize) {
 
 /*------------------------------------------------------------------------*/
 
-UIElement::UIElement(const Common::String &name) :
-		_name(name), _parent(g_engine), _bounds(_innerBounds) {
-	g_engine->_children.push_back(this);
+UIElement::UIElement(const Common::String &name) : _name(name), _parent(g_events), _bounds(_innerBounds) {
+	g_events->_children.push_back(this);
 }
 
-UIElement::UIElement(const Common::String &name, UIElement *uiParent) :
-		_name(name), _parent(uiParent),
-		_bounds(_innerBounds) {
+UIElement::UIElement(const Common::String &name, UIElement *uiParent) : _name(name), _parent(uiParent), _bounds(_innerBounds) {
 	if (_parent)
 		_parent->_children.push_back(this);
 }
@@ -247,22 +271,12 @@ UIElement *UIElement::findViewGlobally(const Common::String &name) {
 	return g_events->findView(name);
 }
 
-void UIElement::focus() {
-	g_events->replaceView(this);
-}
-
 void UIElement::close() {
 	assert(g_events->focusedView() == this);
 	g_events->popView();
-}
-
-bool UIElement::isFocused() const {
-	return g_events->focusedView() == this;
-}
-
-void UIElement::clearSurface() {
-	Graphics::ManagedSurface s = getSurface();
-	s.fillRect(Common::Rect(s.w, s.h), 0);
+#ifdef USE_TTS
+	stopTextToSpeech();
+#endif
 }
 
 void UIElement::draw() {
@@ -288,9 +302,9 @@ UIElement *UIElement::findView(const Common::String &name) {
 	if (_name.equalsIgnoreCase(name))
 		return this;
 
-	UIElement *result;
 	for (size_t i = 0; i < _children.size(); ++i) {
-		if ((result = _children[i]->findView(name)) != nullptr)
+		UIElement *result = _children[i]->findView(name);
+		if (result != nullptr)
 			return result;
 	}
 
@@ -317,16 +331,17 @@ void UIElement::addView() {
 	g_events->addView(this);
 }
 
-Graphics::ManagedSurface UIElement::getSurface() const {
-	return Graphics::ManagedSurface(*g_events->getScreen(), _bounds);
+GfxSurface UIElement::getSurface(bool innerBounds) const {
+	return GfxSurface(*g_events->getScreen(),
+		innerBounds ? _innerBounds : _bounds);
 }
 
 int UIElement::getRandomNumber(int minNumber, int maxNumber) {
-	return g_engine->getRandomNumber(maxNumber - minNumber + 1) + minNumber;
+	return g_events->getRandomNumber(minNumber, maxNumber);
 }
 
 int UIElement::getRandomNumber(int maxNumber) {
-	return g_engine->getRandomNumber(maxNumber);
+	return g_events->getRandomNumber(maxNumber);
 }
 
 void UIElement::delaySeconds(uint seconds) {
@@ -341,4 +356,18 @@ void UIElement::timeout() {
 	redraw();
 }
 
-} // namespace Xyzzy
+#ifdef USE_TTS
+
+void UIElement::stopTextToSpeech() {
+	Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
+	if (ttsMan && ConfMan.getBool("tts_enabled") && ttsMan->isSpeaking()) {
+		ttsMan->stop();
+	}
+
+	_previousSaid.clear();
+}
+
+#endif
+
+} // namespace Views
+} // namespace Graphics
diff --git a/devtools/create_engine/files_events/events.h b/graphics/views/events.h
similarity index 53%
rename from devtools/create_engine/files_events/events.h
rename to graphics/views/events.h
index 08d3a336280..77527ea9866 100644
--- a/devtools/create_engine/files_events/events.h
+++ b/graphics/views/events.h
@@ -19,18 +19,20 @@
  *
  */
 
-#ifndef XYZZY_EVENTS_H
-#define XYZZY_EVENTS_H
+#ifndef GRAPHICS_VIEWS_EVENTS_H
+#define GRAPHICS_VIEWS_EVENTS_H
 
 #include "common/array.h"
+#include "common/random.h"
 #include "common/stack.h"
+#include "graphics/font.h"
+#include "graphics/views/gfx_surface.h"
+#include "graphics/views/messages.h"
+#include "graphics/views/rect.h"
 #include "graphics/screen.h"
-#include "xyzzy/messages.h"
 
-namespace Xyzzy {
-
-#define FRAME_RATE 20
-#define FRAME_DELAY (1000 / FRAME_RATE)
+namespace Graphics {
+namespace Views {
 
 class Events;
 
@@ -44,19 +46,29 @@ private:
 	Common::Rect _bounds;
 	Common::Rect &_innerBounds;
 	int _borderSize = 0;
+
 public:
 	const int16 &left;
 	const int16 ⊤
 	const int16 &right;
 	const int16 ⊥
+
 public:
 	Bounds(Common::Rect &innerBounds);
-	operator const Common::Rect &() const { return _bounds; }
+	operator const Common::Rect &() const {
+		return _bounds;
+	}
 	Bounds &operator=(const Common::Rect &r);
 	void setBorderSize(size_t borderSize);
-	size_t borderSize() const { return _borderSize; }
-	int16 width() const { return _bounds.width(); }
-	int16 height() const { return _bounds.height(); }
+	size_t borderSize() const {
+		return _borderSize;
+	}
+	int16 width() const {
+		return _bounds.width();
+	}
+	int16 height() const {
+		return _bounds.height();
+	}
 };
 
 /**
@@ -64,8 +76,10 @@ public:
  */
 class UIElement {
 	friend class Events;
+
 private:
 	int _timeoutCtr = 0;
+
 protected:
 	UIElement *_parent;
 	Common::Array<UIElement *> _children;
@@ -73,6 +87,10 @@ protected:
 	Bounds _bounds;
 	bool _needsRedraw = true;
 	Common::String _name;
+#ifdef USE_TTS
+	Common::String _previousSaid;
+#endif
+
 protected:
 	/**
 	 * Set a delay countdown in seconds, after which timeout() is called
@@ -108,56 +126,52 @@ private:
 	 * Outer method for doing drawing
 	 *
 	 */
-	void drawElements();
+	virtual void drawElements();
 
 	/**
 	 * Finds a view globally
 	 */
 	static UIElement *findViewGlobally(const Common::String &name);
+
 public:
 	UIElement(const Common::String &name, UIElement *uiParent);
 	UIElement(const Common::String &name);
-	virtual ~UIElement() {}
+	virtual ~UIElement() {
+	}
 
 	/**
 	 * Returns true if the elements needs to be redrawn
 	 */
-	bool needsRedraw() const { return _needsRedraw; }
+	bool needsRedraw() const {
+		return _needsRedraw;
+	}
 
 	/**
 	 * Sets that the element needs to be redrawn
 	 */
 	void redraw();
 
-	/**
-	 * Focuses the element as the current view
-	 */
-	void focus();
-
 	/**
 	 * Closes the current view. The view must have been added
 	 * via addView, so there's a remaining view afterwards
 	 */
 	virtual void close();
 
-	/*
-	 * Returns true if the view is focused
-	 */
-	bool isFocused() const;
-
 	/**
 	 * Sets the focus to a new view
 	 */
-	void replaceView(UIElement *ui, bool replaceAllViews = false);
-	void replaceView(const Common::String &name, bool replaceAllViews = false);
+	virtual void replaceView(UIElement *ui, bool replaceAllViews = false);
+	virtual void replaceView(const Common::String &name, bool replaceAllViews = false);
 
 	/**
 	 * Adds a focused view to the view stack without replacing current one
 	 */
-	void addView(UIElement *ui);
-	void addView(const Common::String &name);
+	virtual void addView(UIElement *ui);
+	virtual void addView(const Common::String &name);
 	void addView();
-	void open() { addView(); }
+	void open() {
+		addView();
+	}
 
 	/**
 	 * Returns a random number
@@ -180,14 +194,16 @@ public:
 	}
 
 	/**
-	 * Returns a surface for drawing the element
+	 * Gets a view's name
 	 */
-	Graphics::ManagedSurface getSurface() const;
+	const Common::String &getName() const {
+		return _name;
+	}
 
 	/**
-	 * Clear the surface
+	 * Returns a surface for drawing the element
 	 */
-	virtual void clearSurface();
+	GfxSurface getSurface(bool innerBounds = false) const;
 
 	/**
 	 * Draws the element
@@ -207,30 +223,44 @@ public:
 	/**
 	 * Handles events
 	 */
-	// Mouse move only has a minimal implementation for performance reasons
+	 // Mouse move only has a minimal implementation for performance reasons
 protected:
-	virtual bool msgMouseMove(const MouseMoveMessage &msg) { return false; }
+	virtual bool msgMouseMove(const MouseMoveMessage &msg) {
+		return false;
+	}
+
+#ifdef USE_TTS
+	/**
+	 * Stops TTS voicing and clears the previously spoken text
+	 */
+	void stopTextToSpeech();
+#endif
+
 public:
-	bool send(const MouseMoveMessage &msg) { return msgMouseMove(msg); }
-
-	#define MESSAGE(NAME) \
-	protected: \
-		virtual bool msg##NAME(const NAME##Message &e) { \
-			for (Common::Array<UIElement *>::iterator it = _children.begin(); \
-					it != _children.end(); ++it) { \
-				if ((*it)->msg##NAME(e)) return true; \
-			} \
-			return false; \
-		} \
-	public: \
-		bool send(const Common::String &viewName, const NAME##Message &msg) { \
-			UIElement *view = UIElement::findViewGlobally(viewName); \
-			assert(view); \
-			return view->msg##NAME(msg); \
-		} \
-		bool send(const NAME##Message &msg) { \
-			return msg##NAME(msg); \
-		} \
+	bool send(const MouseMoveMessage &msg) {
+		return msgMouseMove(msg);
+	}
+
+#define MESSAGE(NAME)                                                     \
+protected:                                                                \
+	virtual bool msg##NAME(const NAME##Message &e) {                      \
+		for (Common::Array<UIElement *>::iterator it = _children.begin(); \
+			 it != _children.end(); ++it) {                               \
+			if ((*it)->msg##NAME(e))                                      \
+				return true;                                              \
+		}                                                                 \
+		return false;                                                     \
+	}                                                                     \
+                                                                          \
+public:                                                                   \
+	bool send(const Common::String &viewName, const NAME##Message &msg) { \
+		UIElement *view = UIElement::findViewGlobally(viewName);          \
+		assert(view);                                                     \
+		return view->msg##NAME(msg);                                      \
+	}                                                                     \
+	bool send(const NAME##Message &msg) {                                 \
+		return msg##NAME(msg);                                            \
+	}
 
 	MESSAGE(Focus);
 	MESSAGE(Unfocus);
@@ -242,7 +272,43 @@ public:
 	MESSAGE(Action);
 	MESSAGE(Game);
 	MESSAGE(Value);
-	#undef MESSAGE
+#undef MESSAGE
+
+protected:
+	/**
+	 * Handles messages of types that the library has no dedicated msgXXX
+	 * method for - i.e. message structs an engine defines for itself, derived
+	 * from Message. Overrides should identify the types they care about
+	 * (typically with dynamic_cast) and return the base class's result for
+	 * everything else. The default passes the message to each child in turn
+	 */
+	virtual bool msgCustom(const Message &msg) {
+		for (Common::Array<UIElement *>::iterator it = _children.begin();
+			 it != _children.end(); ++it) {
+			if ((*it)->msgCustom(msg))
+				return true;
+		}
+		return false;
+	}
+
+public:
+	/**
+	 * Sends an engine-defined message, either to this element or the named
+	 * view. Only used for types without one of the dedicated overloads
+	 * above, which are preferred when they match exactly. Note that a type
+	 * derived from one of the built-in messages will therefore come through
+	 * here rather than being converted to its base
+	 */
+	template<class T>
+	bool send(const T &msg) {
+		return msgCustom(msg);
+	}
+	template<class T>
+	bool send(const Common::String &viewName, const T &msg) {
+		UIElement *view = UIElement::findViewGlobally(viewName);
+		assert(view);
+		return view->msgCustom(msg);
+	}
 };
 
 /**
@@ -255,13 +321,17 @@ public:
 class Events : public UIElement {
 private:
 	Graphics::Screen *_screen = nullptr;
+	Common::RandomSource _randomSource;
 	Common::Stack<UIElement *> _views;
-protected:
+
+	void nextFrame();
+
 	/**
 	 * Process an event
 	 */
 	void processEvent(Common::Event &ev);
 
+protected:
 	/**
 	 * Returns true if the game should quit
 	 */
@@ -270,10 +340,10 @@ protected:
 	/**
 	 * Overrides events we want to only go to the focused view
 	 */
-	#define MESSAGE(NAME) \
-		bool msg##NAME(const NAME##Message &e) override { \
-			return !_views.empty() ? focusedView()->msg##NAME(e) : false; \
-		}
+#define MESSAGE(NAME)                                                 \
+	bool msg##NAME(const NAME##Message &e) override {                 \
+		return !_views.empty() ? focusedView()->msg##NAME(e) : false; \
+	}
 	MESSAGE(Action);
 	MESSAGE(Focus);
 	MESSAGE(Unfocus);
@@ -283,9 +353,17 @@ protected:
 	MESSAGE(MouseDown);
 	MESSAGE(MouseUp);
 	MESSAGE(MouseMove);
-	#undef MESSAGE
+#undef MESSAGE
+
+	/**
+	 * Fallback for custom messages, to route them to the currently focused view
+	 */
+	bool msgCustom(const Message &msg) override {
+		return !_views.empty() ? focusedView()->msgCustom(msg) : false;
+	}
+
 public:
-	Events();
+	Events(const Common::String &engineName);
 	virtual ~Events();
 
 	/**
@@ -293,17 +371,23 @@ public:
 	 */
 	void runGame();
 
+	/**
+	 * Returns a random number
+	 */
+	int getRandomNumber(int minNumber, int maxNumber);
+	int getRandomNumber(int maxNumber);
+
 	/**
 	 * Sets the focus to a new view
 	 */
-	void replaceView(UIElement *ui, bool replaceAllViews = false);
-	void replaceView(const Common::String &name, bool replaceAllViews = false);
+	void replaceView(UIElement *ui, bool replaceAllViews = false) override;
+	void replaceView(const Common::String &name, bool replaceAllViews = false) override;
 
 	/**
 	 * Adds a focused view to the view stack without replacing current one
 	 */
-	void addView(UIElement *ui);
-	void addView(const Common::String &name);
+	void addView(UIElement *ui) override;
+	void addView(const Common::String &name) override;
 
 	/**
 	 * Clears the view list
@@ -315,13 +399,6 @@ public:
 	 */
 	void popView();
 
-	/**
-	 * Redraws the views in order. This is used in rare cases
-	 * where a view draws outside it's defined area, and needs
-	 * to restore whether the background was before
-	 */
-	void redrawViews();
-
 	/**
 	 * Returns the currently focused view, if any
 	 */
@@ -333,22 +410,21 @@ public:
 	 * Returns the view prior to the current view, if any
 	 */
 	UIElement *priorView() const {
-		return _views.size() < 2 ? nullptr :
-			_views[_views.size() - 2];
+		return _views.size() < 2 ? nullptr : _views[_views.size() - 2];
 	}
 
 	/**
-	 * Returns true if a view of a given name is present
-	 * at all in the visible view stack
+	 * Returns the earliest view on the view stack, if any
 	 */
-	bool isPresent(const Common::String &name) const;
+	UIElement *baseView() const {
+		return _views.empty() ? nullptr : _views[0];
+	}
 
 	/**
-	 * Returns true if combat is active
+	 * Returns true if a view of a given name is present
+	 * at all in the visible view stack
 	 */
-	bool isInCombat() const {
-		return isPresent("Combat");
-	}
+	bool isPresent(const Common::String &name) const;
 
 	/**
 	 * Returns the underlying screen
@@ -360,20 +436,13 @@ public:
 	/**
 	 * Draws the focused view
 	 */
-	void drawElements() {
-		if (!_views.empty())
-			focusedView()->drawElements();
-	}
-
-	/**
-	 * Add a keypress to the event queue
-	 */
-	void addKeypress(const Common::KeyCode kc);
+	void drawElements() override;
 
 	/**
 	 * Events manager doesn't have any intrinsic drawing
 	 */
-	void draw() override {}
+	void draw() override {
+	}
 
 	/**
 	 * Called once every game frame
@@ -388,10 +457,21 @@ public:
 	void close() override {
 		focusedView()->close();
 	}
+
+	/**
+	 * Updates the underlying screen
+	 */
+	void updateScreen();
+
+	/**
+	 * Returns a font object that GfxSurface instances can use
+	 */
+	virtual Graphics::Font *createFont() const;
 };
 
 extern Events *g_events;
 
-} // namespace Xyzzy
+} // namespace Views
+} // namespace Graphics
 
 #endif
diff --git a/graphics/views/gfx_surface.cpp b/graphics/views/gfx_surface.cpp
new file mode 100644
index 00000000000..0e95edc6c3e
--- /dev/null
+++ b/graphics/views/gfx_surface.cpp
@@ -0,0 +1,175 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "graphics/views/gfx_surface.h"
+#include "graphics/views/events.h"
+
+namespace Graphics {
+namespace Views {
+
+GfxSurface::GfxSurface() : Graphics::ManagedSurface() {
+	_font = Common::SharedPtr<Graphics::Font>(g_events->createFont());
+}
+
+GfxSurface::GfxSurface(Graphics::ManagedSurface &surf, const Common::Rect &bounds) : Graphics::ManagedSurface(surf, bounds) {
+	_font = Common::SharedPtr<Graphics::Font>(g_events->createFont());
+}
+
+GfxSurface::~GfxSurface() {
+	_font.reset();
+}
+
+void GfxSurface::writeString(const Common::Point &pt, const Common::String &str,
+		Graphics::TextAlign align) {
+	_textPos = pt;
+	writeString(str, align);
+}
+
+void GfxSurface::writeString(const Common::String &str, Graphics::TextAlign align) {
+	size_t strSize = 0;
+	for (const char *p = str.c_str(); *p; ++p)
+		strSize += Common::isPrint(*p) ? 1 : 0;
+
+	switch (align) {
+	case Graphics::kTextAlignCenter:
+		_textPos.x -= strSize / 2;
+		break;
+	case Graphics::kTextAlignRight:
+		_textPos.x -= strSize;
+		break;
+	case Graphics::kTextAlignLeft:
+	default:
+		break;
+	}
+
+	for (const char *p = str.c_str(); *p; ++p) {
+		if (*p == '\n') {
+			assert(align == Graphics::kTextAlignLeft);
+			newLine();
+		} else {
+			writeChar(*p);
+		}
+	}
+}
+
+void GfxSurface::writeString(const Common::Point &pt, const char *str, ...) {
+	va_list alist;
+
+	// Start reading values
+	va_start(alist, str);
+	Common::String msg = Common::String::vformat(str, alist);
+	va_end(alist);
+
+	writeString(pt, msg, Graphics::kTextAlignLeft);
+}
+
+void GfxSurface::writeString(const char *str, ...) {
+	va_list alist;
+
+	// Start reading values
+	va_start(alist, str);
+	Common::String msg = Common::String::vformat(str, alist);
+	va_end(alist);
+
+	writeString(msg, Graphics::kTextAlignLeft);
+}
+
+void GfxSurface::writeChar(uint32 chr) {
+	const int fontW = _font->getMaxCharWidth();
+	const int fontH = _font->getFontHeight();
+	const int textW = this->w / fontW;
+
+	if (chr != '\n') {
+		fillRect(Common::Rect(_textPos.x * fontW, _textPos.y * fontH, (_textPos.x + 1) * fontW, (_textPos.y + 1) * fontH), _bgColor);
+
+		_font->drawChar(this, chr, _textPos.x * fontW, _textPos.y * fontH, _textColor);
+		_textPos.x++;
+	}
+
+	if (_textPos.x >= textW || chr == '\n') {
+		newLine();
+	}
+}
+
+void GfxSurface::writeChar(const Common::Point &pt, uint32 chr) {
+	setTextPos(pt);
+	writeChar(chr);
+}
+
+void GfxSurface::newLine() {
+	_textPos.x = 0;
+	_textPos.y++;
+
+	const int fontH = _font->getFontHeight();
+	const int textH = this->h / fontH;
+	if (_textPos.y >= textH) {
+		_textPos.y = textH - 1;
+
+		if (_scrollable) {
+			// Scroll the screen contents up
+			blitFrom(*this, Common::Rect(0, fontH, this->w, this->h), Common::Point(0, 0));
+			fillRect(Common::Rect(0, this->h - fontH, this->w, this->h), 0);
+		}
+	}
+}
+
+void GfxSurface::setTextPos(const Common::Point &pt) {
+	_textPos = pt;
+}
+
+int GfxSurface::getStringWidth(const Common::String &str) const {
+	return str.size() * _font->getMaxCharWidth();
+}
+
+byte GfxSurface::setColor(byte color) {
+	byte oldColor = _textColor;
+	_textColor = color;
+	return oldColor;
+}
+
+void GfxSurface::setColor(byte fgColor, byte bgColor) {
+	_textColor = fgColor;
+	_bgColor = bgColor;
+}
+
+void GfxSurface::reverseColor() {
+	SWAP(_textColor, _bgColor);
+}
+
+void GfxSurface::xorBlitFrom(const ManagedSurface &src, const Common::Point &destPos) {
+	xorBlitFrom(src, Common::Rect(0, 0, src.w, src.h), destPos);
+}
+
+void GfxSurface::xorBlitFrom(const ManagedSurface &src, const Common::Rect &srcRect, const Common::Point &destPos) {
+	Graphics::Surface area = getSubArea(Common::Rect(destPos.x, destPos.y,
+		destPos.x + srcRect.width(), destPos.y + srcRect.height()));
+
+	for (int yCtr = 0; yCtr < srcRect.height(); ++yCtr) {
+		const byte *pSrc = (const byte *)src.getBasePtr(srcRect.left, srcRect.top + yCtr);
+		byte *pDest = (byte *)area.getBasePtr(0, yCtr);
+
+		for (int xCtr = 0; xCtr < srcRect.width(); ++xCtr, ++pSrc, ++pDest)
+			*pDest ^= *pSrc;
+	}
+}
+
+} // namespace Views
+} // namespace Graphics
diff --git a/graphics/views/gfx_surface.h b/graphics/views/gfx_surface.h
new file mode 100644
index 00000000000..34e8949624a
--- /dev/null
+++ b/graphics/views/gfx_surface.h
@@ -0,0 +1,108 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef GRAPHICS_VIEWS_GFX_SURFACE_H
+#define GRAPHICS_VIEWS_GFX_SURFACE_H
+
+#include "common/ptr.h"
+#include "common/rect.h"
+#include "graphics/font.h"
+#include "graphics/managed_surface.h"
+#include "graphics/views/rect.h"
+
+namespace Graphics {
+namespace Views {
+
+class GfxSurface : public Graphics::ManagedSurface {
+private:
+	Common::SharedPtr<Graphics::Font> _font;
+	Common::Point _textPos;
+	byte _textColor = 255;
+	byte _bgColor = 0;
+	bool _scrollable = false;
+
+	void newLine();
+
+public:
+	GfxSurface();
+	GfxSurface(Graphics::ManagedSurface &surf, const Common::Rect &bounds);
+	~GfxSurface();
+
+	/**
+	 * Write some text to the surface
+	 */
+	void writeString(const Common::Point &pt, const Common::String &str,
+		Graphics::TextAlign align = Graphics::kTextAlignLeft);
+	void writeString(const Common::String &str, Graphics::TextAlign align = Graphics::kTextAlignLeft);
+	void writeString(const Common::Point &pt, const char *str, ...);
+	void writeString(const char *str, ...);
+
+	/**
+	 * Write a character to the surface
+	 * @param chr	Character to write
+	 */
+	void writeChar(uint32 chr);
+	void writeChar(const Common::Point &pt, uint32 chr);
+
+	/**
+	 * Get the width of a string in pixels
+	 * @param str	String to measure
+	 * @return		Width of string
+	*/
+	int getStringWidth(const Common::String &str) const;
+
+	void setTextPos(const Common::Point &pt);
+	const Common::Point &getTextPos() const {
+		return _textPos;
+	}
+
+	/**
+	 * Set the text color
+	 * @param color		New color palette index
+	 * @return			Previous color
+	 */
+	byte setColor(byte color);
+	void setColor(byte fgColor, byte bgColor);
+
+	/**
+	 * Swap foreground and background text color
+	 */
+	void reverseColor();
+
+	/**
+	 * Set whether surface area can scroll when text is writing beyond the bottom of the surface
+	 * @param flag 
+	 */
+	void setScrollable(bool flag) {
+		_scrollable = flag;
+	}
+
+	/**
+	 * Custom blitting using xor of the destination rather than a straight copy
+	 */
+	void xorBlitFrom(const ManagedSurface &src, const Common::Point &destPos);
+	void xorBlitFrom(const ManagedSurface &src, const Common::Rect &srcRect, const Common::Point &destPos);
+};
+
+} // namespace Views
+} // namespace Graphics
+
+#endif
diff --git a/devtools/create_engine/files_events/messages.cpp b/graphics/views/messages.cpp
similarity index 87%
rename from devtools/create_engine/files_events/messages.cpp
rename to graphics/views/messages.cpp
index 8c8664d1eae..7680288c062 100644
--- a/devtools/create_engine/files_events/messages.cpp
+++ b/graphics/views/messages.cpp
@@ -19,12 +19,13 @@
  *
  */
 
-#include "xyzzy/messages.h"
+#include "graphics/views/messages.h"
 
-namespace Xyzzy {
+namespace Graphics {
+namespace Views {
 
 MouseMessage::MouseMessage(Common::EventType type,
-		const Common::Point &pos) : Message(), _pos(pos) {
+	const Common::Point &pos) : Message(), _pos(pos) {
 	switch (type) {
 	case Common::EVENT_RBUTTONDOWN:
 	case Common::EVENT_RBUTTONUP:
@@ -40,4 +41,5 @@ MouseMessage::MouseMessage(Common::EventType type,
 	}
 }
 
-} // namespace Xyzzy
+} // namespace Views
+} // namespace Graphics
diff --git a/devtools/create_engine/files_events/messages.h b/graphics/views/messages.h
similarity index 56%
rename from devtools/create_engine/files_events/messages.h
rename to graphics/views/messages.h
index f8f7ad6ae5f..33a48c33f9e 100644
--- a/devtools/create_engine/files_events/messages.h
+++ b/graphics/views/messages.h
@@ -19,24 +19,32 @@
  *
  */
 
-#ifndef XYZZY_MESSAGES_H
-#define XYZZY_MESSAGES_H
+#ifndef GRAPHICS_VIEWS_MESSAGES_H
+#define GRAPHICS_VIEWS_MESSAGES_H
 
-#include "common/array.h"
 #include "common/events.h"
-#include "common/str.h"
 
-namespace Xyzzy {
+namespace Graphics {
+namespace Views {
 
 class UIElement;
 
-struct Message {};
+/**
+ * Base class for all messages. It's polymorphic so engine-specific message
+ * types can be identified with dynamic_cast when they arrive through
+ * UIElement::msgCustom, without needing to be known to this library
+ */
+struct Message {
+	virtual ~Message() {
+	}
+};
 
 struct FocusMessage : public Message {
 	UIElement *_priorView = nullptr;
-	FocusMessage() : Message() {}
-	FocusMessage(UIElement *priorView) : Message(),
-		_priorView(priorView) {}
+	FocusMessage() : Message() {
+	}
+	FocusMessage(UIElement *priorView) : Message(), _priorView(priorView) {
+	}
 };
 
 struct UnfocusMessage : public Message {};
@@ -44,34 +52,42 @@ struct MouseEnterMessage : public Message {};
 struct MouseLeaveMessage : public Message {};
 
 struct KeypressMessage : public Message, public Common::KeyState {
-	KeypressMessage() : Message() {}
-	KeypressMessage(const Common::KeyState &ks) :
-		Message(), Common::KeyState(ks) {}
+	KeypressMessage() : Message() {
+	}
+	KeypressMessage(const Common::KeyState &ks) : Message(), Common::KeyState(ks) {
+	}
 };
 
 struct MouseMessage : public Message {
-	enum Button { MB_LEFT, MB_RIGHT, MB_MIDDLE };
+	enum Button {
+		MB_LEFT,
+		MB_RIGHT,
+		MB_MIDDLE
+	};
 	Button _button;
 	Common::Point _pos;
 
-	MouseMessage() : Message(), _button(MB_LEFT) {}
-	MouseMessage(Button btn, const Common::Point &pos) :
-		Message(), _button(btn), _pos(pos) {}
+	MouseMessage() : Message(), _button(MB_LEFT) {
+	}
+	MouseMessage(Button btn, const Common::Point &pos) : Message(), _button(btn), _pos(pos) {
+	}
 	MouseMessage(Common::EventType type, const Common::Point &pos);
 };
 struct MouseDownMessage : public MouseMessage {
-	MouseDownMessage() : MouseMessage() {}
-	MouseDownMessage(Button btn, const Common::Point &pos) :
-		MouseMessage(btn, pos) {}
-	MouseDownMessage(Common::EventType type, const Common::Point &pos) :
-		MouseMessage(type, pos) {}
+	MouseDownMessage() : MouseMessage() {
+	}
+	MouseDownMessage(Button btn, const Common::Point &pos) : MouseMessage(btn, pos) {
+	}
+	MouseDownMessage(Common::EventType type, const Common::Point &pos) : MouseMessage(type, pos) {
+	}
 };
 struct MouseUpMessage : public MouseMessage {
-	MouseUpMessage() : MouseMessage() {}
-	MouseUpMessage(Button btn, const Common::Point &pos) :
-		MouseMessage(btn, pos) {}
-	MouseUpMessage(Common::EventType type, const Common::Point &pos) :
-		MouseMessage(type, pos) {}
+	MouseUpMessage() : MouseMessage() {
+	}
+	MouseUpMessage(Button btn, const Common::Point &pos) : MouseMessage(btn, pos) {
+	}
+	MouseUpMessage(Common::EventType type, const Common::Point &pos) : MouseMessage(type, pos) {
+	}
 };
 typedef MouseMessage MouseMoveMessage;
 
@@ -80,32 +96,35 @@ struct GameMessage : public Message {
 	int _value;
 	Common::String _stringValue;
 
-	GameMessage() : Message(), _value(-1) {}
-	GameMessage(const Common::String &name) : Message(),
-		_name(name), _value(-1) {}
-	GameMessage(const Common::String &name, int value) : Message(),
-		_name(name), _value(value) {}
-	GameMessage(const Common::String &name, const Common::String &value) :
-		Message(), _name(name), _stringValue(value) {}
+	GameMessage() : Message(), _value(-1) {
+	}
+	GameMessage(const Common::String &name) : Message(), _name(name), _value(-1) {
+	}
+	GameMessage(const Common::String &name, int value) : Message(), _name(name), _value(value) {
+	}
+	GameMessage(const Common::String &name, const Common::String &value) : Message(), _name(name), _stringValue(value), _value(0) {
+	}
 };
 
 struct ValueMessage : public Message {
 	int _value;
 
-	ValueMessage() : Message(), _value(0) {}
-	ValueMessage(int value) : Message(),
-		_value(value) {}
+	ValueMessage() : Message(), _value(0) {
+	}
+	ValueMessage(int value) : Message(), _value(value) {
+	}
 };
 
 struct ActionMessage : public Message {
 	int _action;
+
 	ActionMessage() : Message(), _action(0) {
 	}
-	ActionMessage(int action) : Message(),
-		_action(action) {
+	ActionMessage(int action) : Message(), _action(action) {
 	}
 };
 
-} // namespace Xyzzy
+} // namespace Views
+} // namespace Graphics
 
 #endif
diff --git a/graphics/views/rect.h b/graphics/views/rect.h
new file mode 100644
index 00000000000..893355f8365
--- /dev/null
+++ b/graphics/views/rect.h
@@ -0,0 +1,55 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef GRAPHICS_VIEWS_RECT_H
+#define GRAPHICS_VIEWS_RECT_H
+
+#include "common/rect.h"
+
+namespace Graphics {
+namespace Views {
+
+/**
+ * Simple derived point class that converts text coordinates to graphic screen coordinates
+ */
+class TextPoint : public Common::Point {
+public:
+	TextPoint() : Common::Point() {
+	}
+	TextPoint(int16 x1, int16 y1) : Common::Point(x1 * 8, y1 * 8) {
+	}
+};
+
+/**
+ * Simple derived rect class that converts text coordinates to graphic screen coordinates
+ */
+class TextRect : public Common::Rect {
+public:
+	TextRect() : Common::Rect() {
+	}
+	TextRect(int16 x1, int16 y1, int16 x2, int16 y2) : Common::Rect(x1 * 8, y1 * 8, (x2 + 1) * 8, (y2 + 1) * 8) {
+	}
+};
+
+} // namespace Views
+} // namespace Graphics
+
+#endif
diff --git a/devtools/create_engine/files_events/view.cpp b/graphics/views/view.cpp
similarity index 94%
rename from devtools/create_engine/files_events/view.cpp
rename to graphics/views/view.cpp
index 8b2ea758f31..fdc1be30cd4 100644
--- a/devtools/create_engine/files_events/view.cpp
+++ b/graphics/views/view.cpp
@@ -19,9 +19,10 @@
  *
  */
 
-#include "xyzzy/view.h"
+#include "graphics/views/view.h"
 
-namespace Xyzzy {
+namespace Graphics {
+namespace Views {
 
 void View::checkFocusedControl(const Common::Point &mousePos) {
 	if (_focusedElement) {
@@ -78,4 +79,5 @@ bool View::msgMouseUp(const MouseUpMessage &msg) {
 	return child ? child->send(msg) : false;
 }
 
-} // namespace Xyzzy
+} // namespace Views
+} // namespace Graphics
diff --git a/devtools/create_engine/files_events/view.h b/graphics/views/view.h
similarity index 92%
rename from devtools/create_engine/files_events/view.h
rename to graphics/views/view.h
index f916883d400..4bba0c17692 100644
--- a/devtools/create_engine/files_events/view.h
+++ b/graphics/views/view.h
@@ -19,12 +19,13 @@
  *
  */
 
-#ifndef XYZZY_VIEW_H
-#define XYZZY_VIEW_H
+#ifndef GRAPHICS_VIEWS_VIEW_H
+#define GRAPHICS_VIEWS_VIEW_H
 
-#include "xyzzy/events.h"
+#include "graphics/views/events.h"
 
-namespace Xyzzy {
+namespace Graphics {
+namespace Views {
 
 /**
  * Base view class for screens and dialogs that appear on-screen.
@@ -68,6 +69,7 @@ public:
 	bool msgMouseUp(const MouseUpMessage &msg) override;
 };
 
-} // namespace Xyzzy
+} // namespace Views
+} // namespace Graphics
 
 #endif


Commit: bd684f43d8790f02035e223680f23eaffacb7c56
    https://github.com/scummvm/scummvm/commit/bd684f43d8790f02035e223680f23eaffacb7c56
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2026-11-08T20:05:02-10:00

Commit Message:
GRAPHICS: VIEWS: Don't needlessly redraw obscured views after view removal

Changed paths:
    graphics/views/events.cpp
    graphics/views/events.h


diff --git a/graphics/views/events.cpp b/graphics/views/events.cpp
index 616479b4142..8f8e60e6790 100644
--- a/graphics/views/events.cpp
+++ b/graphics/views/events.cpp
@@ -143,10 +143,13 @@ void Events::replaceView(UIElement *ui, bool replaceAllViews) {
 		_views.pop();
 	}
 
-	// Redraw any prior views to erase the removed view
-	for (uint i = 0; i < _views.size(); ++i) {
-		_views[i]->redraw();
-		_views[i]->draw();
+	if (oldView && !ui->_bounds.contains(oldView->_bounds)) {
+		// The new view won't completely cover the replaced view, so we need to redraw
+		// all the remaining views, if any, in order before drawing the new view
+		for (uint i = 0; i < _views.size(); ++i) {
+			_views[i]->redraw();
+			_views[i]->draw();
+		}
 	}
 
 	// Add the new view
@@ -178,17 +181,23 @@ void Events::addView(const Common::String &name) {
 }
 
 void Events::popView() {
+	// Unfocus the current view and pop if off the view stack
 	UIElement *oldView = focusedView();
 	oldView->msgUnfocus(UnfocusMessage());
 	_views.pop();
 
-	for (uint i = 0; i < _views.size(); ++i) {
-		_views[i]->redraw();
-		_views[i]->draw();
+	UIElement *view = focusedView();
+
+	if (view && !view->_bounds.contains(oldView->_bounds)) {
+		// The closed view won't entirely be erased by redrawn top view. So we have to
+		// iterate through all the remaining views to redraw the entire screen
+		for (uint i = 0; i < _views.size(); ++i) {
+			_views[i]->redraw();
+			_views[i]->draw();
+		}
 	}
 
-	if (!_views.empty()) {
-		UIElement *view = focusedView();
+	if (view) {
 		view->msgFocus(FocusMessage(oldView));
 		view->redraw();
 		view->draw();
diff --git a/graphics/views/events.h b/graphics/views/events.h
index 77527ea9866..a36da5f4eef 100644
--- a/graphics/views/events.h
+++ b/graphics/views/events.h
@@ -69,6 +69,9 @@ public:
 	int16 height() const {
 		return _bounds.height();
 	}
+	bool contains(const Common::Rect &r) const {
+		return _bounds.contains(r);
+	}
 };
 
 /**


Commit: 54726ef20d6f56a118b5cc7295021d29c86a04c4
    https://github.com/scummvm/scummvm/commit/54726ef20d6f56a118b5cc7295021d29c86a04c4
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2026-11-08T20:05:02-10:00

Commit Message:
GRAPHICS: VIEWS: Force frame redraw after keypresses & mouse clicks

Important for ensuring view updates during key repeats

Changed paths:
    graphics/views/events.cpp


diff --git a/graphics/views/events.cpp b/graphics/views/events.cpp
index 8f8e60e6790..f56fcb3be37 100644
--- a/graphics/views/events.cpp
+++ b/graphics/views/events.cpp
@@ -64,6 +64,13 @@ void Events::runGame() {
 			}
 
 			processEvent(e);
+
+			// Any event other than mouse moves is followed by an immediate frame, so a
+			// stream of repeated events can't starve the views of being redrawn
+			if (e.type != Common::EVENT_MOUSEMOVE) {
+				nextFrameTime = 0;
+				break;
+			}
 		}
 
 		if (_views.empty())




More information about the Scummvm-git-logs mailing list