From 10a5b70b0af167c1f154a4c9dbe8829fe966fffa Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 27 Mar 2019 19:07:08 -0700 Subject: GLK: FROTZ: Handle creating Glk window when switching to/from fixed width styles --- engines/glk/frotz/windows.cpp | 22 ++++++++++++++++------ engines/glk/frotz/windows.h | 7 ++++--- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/engines/glk/frotz/windows.cpp b/engines/glk/frotz/windows.cpp index 8ebc263151..0619030567 100644 --- a/engines/glk/frotz/windows.cpp +++ b/engines/glk/frotz/windows.cpp @@ -23,6 +23,7 @@ #include "glk/frotz/windows.h" #include "glk/frotz/frotz.h" #include "glk/window_pair.h" +#include "glk/window_text_grid.h" #include "glk/window_text_buffer.h" #include "glk/conf.h" @@ -143,6 +144,11 @@ void Window::setPosition(const Point &newPos) { void Window::setCursor(const Point &newPos) { int x = newPos.x, y = newPos.y; + if (!(_currStyle & FIXED_WIDTH_STYLE)) { + _currStyle |= FIXED_WIDTH_STYLE; + ensureGlkWindow(); + } + if (y < 0) { // Cursor on/off if (y == -2) @@ -226,10 +232,10 @@ uint Window::setFont(uint font) { return result; } -void Window::setStyle(int style) { +void Window::setStyle(uint style) { if (style == 0) _currStyle = 0; - else if (style != -1) + else if (style != 0xf000) // not tickle time _currStyle |= style; @@ -247,8 +253,7 @@ void Window::setStyle(int style) { void Window::updateStyle() { uint style = _currStyle; - if (!_win) - createGlkWindow(); + ensureGlkWindow(); if (style & REVERSE_STYLE) setReverseVideo(true); @@ -289,9 +294,14 @@ void Window::setReverseVideo(bool reverse) { _win->_stream->setReverseVideo(reverse); } -void Window::createGlkWindow() { +void Window::ensureGlkWindow() { // Create a new window - if (_index == 1) { + if (_win && (dynamic_cast(_win) != nullptr) != ((_currStyle & FIXED_WIDTH_STYLE) != 0)) { + g_vm->glk_window_close(_win); + _win = nullptr; + } + + if (_currStyle & FIXED_WIDTH_STYLE) { // Text grid window _win = g_vm->glk_window_open(g_vm->glk_window_get_root(), winmethod_Arbitrary | winmethod_Fixed, 0, wintype_TextGrid, 0); diff --git a/engines/glk/frotz/windows.h b/engines/glk/frotz/windows.h index fe59cc7e00..f12d9eec20 100644 --- a/engines/glk/frotz/windows.h +++ b/engines/glk/frotz/windows.h @@ -102,9 +102,10 @@ private: void update(); /** - * Creates a new Glk window to attach to the window + * Creates a new Glk window to attach to the window if not already present, or recreates the window + * if the font style has changed to/from fixed width */ - void createGlkWindow(); + void ensureGlkWindow(); /** * Updates the current font/style @@ -191,7 +192,7 @@ public: /** * Set the textstyle */ - void setStyle(int style = -1); + void setStyle(uint style = 0xf000); /** * Set reverse video -- cgit v1.2.3