aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2019-01-04 16:39:21 -0800
committerPaul Gilbert2019-01-04 16:39:21 -0800
commitc41c6f33d53c896c35cda6ac761cdedf896d646c (patch)
tree4922d78c454a94c83794ea50be4ab14d742047f4
parent20191622f1e0dcec3b2b47332fc53fc0d0f9d7a8 (diff)
downloadscummvm-rg350-c41c6f33d53c896c35cda6ac761cdedf896d646c.tar.gz
scummvm-rg350-c41c6f33d53c896c35cda6ac761cdedf896d646c.tar.bz2
scummvm-rg350-c41c6f33d53c896c35cda6ac761cdedf896d646c.zip
GLK: FROTZ: Refactor V6 window arrangements
As I implement further code for Zork Zero, I'm becoming convinced that all of the windows 2+ are for graphics. A complication arose, though, that z_draw_picture doesn't have a window number specified. So creating Glk picture windows for each virtual window was somewhat redundant. The scheme I'm now going to move forward with is having a single picture wndow cover the entire screen in v6 mode, and the upper and lower panes on top of that. All other windows will not get an accompanying Glk window, and instead I'm caching all the window properties locally on the Frotz Window class, so that they can act like the simple placeholders I think they're intended as
-rw-r--r--engines/glk/frotz/glk_interface.cpp6
-rw-r--r--engines/glk/frotz/windows.cpp121
-rw-r--r--engines/glk/frotz/windows.h29
3 files changed, 77 insertions, 79 deletions
diff --git a/engines/glk/frotz/glk_interface.cpp b/engines/glk/frotz/glk_interface.cpp
index 1efb751a17..d6059ff943 100644
--- a/engines/glk/frotz/glk_interface.cpp
+++ b/engines/glk/frotz/glk_interface.cpp
@@ -145,10 +145,8 @@ void GlkInterface::initialize() {
if (_storyId == BEYOND_ZORK)
showBeyondZorkTitle();
- _wp._lower = glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
- _wp._upper = glk_window_open(_wp._lower, winmethod_Above | winmethod_Fixed, 0, wintype_TextGrid, 0);
-
- glk_set_window(_wp._lower);
+ _wp.setup(h_version == 6);
+ cwin = 0;
gos_curwin = _wp._lower;
/*
diff --git a/engines/glk/frotz/windows.cpp b/engines/glk/frotz/windows.cpp
index fcb57ceb57..c1a4163a44 100644
--- a/engines/glk/frotz/windows.cpp
+++ b/engines/glk/frotz/windows.cpp
@@ -23,12 +23,13 @@
#include "glk/frotz/windows.h"
#include "glk/frotz/frotz.h"
#include "glk/window_pair.h"
+#include "glk/window_text_buffer.h"
#include "glk/conf.h"
namespace Glk {
namespace Frotz {
-Windows::Windows() : _lower(_windows[0]), _upper(_windows[1]) {
+Windows::Windows() : _lower(_windows[0]), _upper(_windows[1]), _background(nullptr) {
for (size_t idx = 0; idx < 8; ++idx)
_windows[idx]._windows = this;
}
@@ -42,88 +43,78 @@ Window &Windows::operator[](uint idx) {
return _windows[idx];
}
+void Windows::setup(bool isVersion6) {
+ if (isVersion6) {
+ // For graphic games we have a background window covering the entire screen for greater
+ // flexibility of wher we draw pictures, and the lower and upper areas sit on top of them
+ _background = g_vm->glk_window_open(0, 0, 0, wintype_Graphics, 0);
+ _lower = g_vm->glk_window_open(g_vm->glk_window_get_root(),
+ winmethod_Arbitrary | winmethod_Fixed, 0, wintype_TextBuffer, 0);
+ _upper = g_vm->glk_window_open(g_vm->glk_window_get_root(),
+ winmethod_Arbitrary | winmethod_Fixed, 0, wintype_TextGrid, 0);
+ } else {
+ _lower = g_vm->glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
+ _upper = g_vm->glk_window_open(_lower, winmethod_Above | winmethod_Fixed, 0, wintype_TextGrid, 0);
+ }
+
+ _lower.update();
+ _upper.update();
+ g_vm->glk_set_window(_lower);
+}
+
/*--------------------------------------------------------------------------*/
-Window::Window() : _windows(nullptr), _win(nullptr), _tempVal(0) {}
+Window::Window() : _windows(nullptr), _win(nullptr) {
+ Common::fill(_properties, _properties + TRUE_BG_COLOR + 1, 0);
+ _properties[Y_POS] = _properties[X_POS] = 1;
+ _properties[Y_CURSOR] = _properties[X_CURSOR] = 1;
+ _properties[FONT_NUMBER] = TEXT_FONT;
+ _properties[FONT_SIZE] = 12;
+}
-winid_t Window::getWindow() {
- if (!_win) {
- // Window doesn't exist, so create it
- // TODO: For now I'm assuming all the extra created windows will be graphics, since Glk requires
- // us to specify it at creation time. Not sure if it's true or not for all V6 games
- _win = g_vm->glk_window_open(g_vm->glk_window_get_root(), winmethod_Arbitrary | winmethod_Fixed,
- 0, wintype_Graphics, 0);
- }
+void Window::update() {
+ assert(_win);
- return _win;
+ _properties[X_POS] = _win->_bbox.left / g_conf->_monoInfo._cellW + 1;
+ _properties[Y_POS] = _win->_bbox.top / g_conf->_monoInfo._cellH + 1;
+ _properties[X_SIZE] = _win->_bbox.width() / g_conf->_monoInfo._cellW;
+ _properties[Y_SIZE] = _win->_bbox.height() / g_conf->_monoInfo._cellH;
+
+ Point pt = _win->getCursor();
+ _properties[X_CURSOR] = pt.x / g_conf->_monoInfo._cellW + 1;
+ _properties[Y_CURSOR] = pt.y / g_conf->_monoInfo._cellH + 1;
+
+ TextBufferWindow *win = dynamic_cast<TextBufferWindow *>(_win);
+ _properties[LEFT_MARGIN] = (win ? win->_ladjw : 0) / g_conf->_monoInfo._cellW;
+ _properties[RIGHT_MARGIN] = (win ? win->_radjw : 0) / g_conf->_monoInfo._cellW;
+ _properties[FONT_SIZE] = g_conf->_monoInfo._size;
}
void Window::setSize(const Point &newSize) {
- winid_t win = getWindow();
checkRepositionLower();
- Point s(newSize.x * g_conf->_monoInfo._cellW, newSize.y * g_conf->_monoInfo._cellH);
- win->setSize(s);
-/* TODO
-
- // Keep the cursor within the window
- if (wp[win].y_cursor > zargs[1] || wp[win].x_cursor > zargs[2])
- reset_cursor(win);
+ _properties[X_SIZE] = newSize.x;
+ _properties[Y_SIZE] = newSize.y;
- os_window_height(win, _wp[win].y_size);
- */
+ if (_win)
+ _win->setSize(Point(newSize.x * g_conf->_monoInfo._cellW, newSize.y * g_conf->_monoInfo._cellH));
}
void Window::setPosition(const Point &newPos) {
- winid_t win = getWindow();
checkRepositionLower();
- Point pos((newPos.x - 1) * g_conf->_monoInfo._cellW, (newPos.y - 1) * g_conf->_monoInfo._cellH);
- win->setPosition(pos);
-}
+ _properties[X_POS] = newPos.x;
+ _properties[Y_POS] = newPos.y;
-const uint16 &Window::operator[](WindowProperty propType) {
- _tempVal = getProperty(propType);
- return _tempVal;
+ if (_win)
+ _win->setPosition(Point((newPos.x - 1) * g_conf->_monoInfo._cellW, (newPos.y - 1) * g_conf->_monoInfo._cellH));
}
-uint16 Window::getProperty(WindowProperty propType) {
- winid_t win = getWindow();
- Point pt;
-
- switch (propType) {
- case Y_POS:
- return win->_bbox.top / g_conf->_monoInfo._cellH;
- case X_POS:
- return win->_bbox.left / g_conf->_monoInfo._cellW;
- case Y_SIZE:
- return win->_bbox.height() / g_conf->_monoInfo._cellH;
- case X_SIZE:
- return win->_bbox.width() / g_conf->_monoInfo._cellW;
- case Y_CURSOR:
- return win->getCursor().y;
- case X_CURSOR:
- return win->getCursor().x;
-
- default:
- error("Read of an unimplemented property");
- /*
- LEFT_MARGIN = 6, RIGHT_MARGIN = 7, NEWLINE_INTERRUPT = 8, INTERRUPT_COUNTDOWN = 9,
- TEXT_STYLE = 10, COLOUR_DATA = 11, FONT_NUMBER = 12, FONT_SIZE = 13, ATTRIBUTES = 14,
- LINE_COUNT = 15, TRUE_FG_COLOR = 16, TRUE_BG_COLOR = 17
-
- case TRUE_FG_COLOR:
- store(os_to_true_colour(lo(wp[winarg0()].colour)));
-
- case TRUE_BG_COLOR:
- zword bg = hi(wp[winarg0()].colour);
-
- if (bg == TRANSPARENT_COLOUR)
- store((zword)-4);
- else
- store(os_to_true_colour(bg));
- */
- }
+const uint16 &Window::getProperty(WindowProperty propType) {
+ if (_win)
+ update();
+
+ return _properties[propType];
}
void Window::setProperty(WindowProperty propType, uint16 value) {
diff --git a/engines/glk/frotz/windows.h b/engines/glk/frotz/windows.h
index 43358665b2..56e0f99594 100644
--- a/engines/glk/frotz/windows.h
+++ b/engines/glk/frotz/windows.h
@@ -48,17 +48,12 @@ class Window {
private:
Windows *_windows;
winid_t _win;
- uint16 _tempVal; ///< used in calls to square brackets operator
+ uint16 _properties[TRUE_BG_COLOR + 1];
private:
/**
- * Gets a reference to the window, creating a new one if one doesn't already exist
- */
- winid_t getWindow();
-
- /**
* Get a property value
*/
- uint16 getProperty(WindowProperty propType);
+ const uint16 &getProperty(WindowProperty propType);
/**
* Set a property value
@@ -69,6 +64,11 @@ private:
* Called when trying to reposition or resize windows. Does special handling for the lower window
*/
void checkRepositionLower();
+
+ /**
+ * Updates the local window properties based on an attached Glk window
+ */
+ void update();
public:
/**
* Constructor
@@ -86,17 +86,20 @@ public:
/**
* Cast operator for getting a Glk window
*/
- operator winid_t() const { return _win; }
+ operator winid_t() const {
+ assert(_win);
+ return _win;
+ }
/**
- * Cast operator for testing if the window is valid (present)
+ * Cast operator for testing if the window has a proper Glk window attached to it
*/
operator bool() const { return _win != nullptr; }
/**
* Property accessor
*/
- const uint16 &operator[](WindowProperty propType);
+ const uint16 &operator[](WindowProperty propType) { return getProperty(propType); }
/**
* Set the window size
@@ -116,6 +119,7 @@ class Windows {
private:
Window _windows[8];
public:
+ winid_t _background;
Window &_lower;
Window &_upper;
public:
@@ -133,6 +137,11 @@ public:
* Array access
*/
Window &operator[](uint idx);
+
+ /**
+ * Setup the screen
+ */
+ void setup(bool isVersion6);
};
} // End of namespace Frotz