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
This commit is contained in:
Paul Gilbert 2019-01-04 16:39:21 -08:00
parent 20191622f1
commit c41c6f33d5
3 changed files with 79 additions and 81 deletions

View file

@ -145,10 +145,8 @@ void GlkInterface::initialize() {
if (_storyId == BEYOND_ZORK) if (_storyId == BEYOND_ZORK)
showBeyondZorkTitle(); showBeyondZorkTitle();
_wp._lower = glk_window_open(0, 0, 0, wintype_TextBuffer, 0); _wp.setup(h_version == 6);
_wp._upper = glk_window_open(_wp._lower, winmethod_Above | winmethod_Fixed, 0, wintype_TextGrid, 0); cwin = 0;
glk_set_window(_wp._lower);
gos_curwin = _wp._lower; gos_curwin = _wp._lower;
/* /*

View file

@ -23,12 +23,13 @@
#include "glk/frotz/windows.h" #include "glk/frotz/windows.h"
#include "glk/frotz/frotz.h" #include "glk/frotz/frotz.h"
#include "glk/window_pair.h" #include "glk/window_pair.h"
#include "glk/window_text_buffer.h"
#include "glk/conf.h" #include "glk/conf.h"
namespace Glk { namespace Glk {
namespace Frotz { 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) for (size_t idx = 0; idx < 8; ++idx)
_windows[idx]._windows = this; _windows[idx]._windows = this;
} }
@ -42,88 +43,78 @@ Window &Windows::operator[](uint idx) {
return _windows[idx]; return _windows[idx];
} }
/*--------------------------------------------------------------------------*/ void Windows::setup(bool isVersion6) {
if (isVersion6) {
Window::Window() : _windows(nullptr), _win(nullptr), _tempVal(0) {} // 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
winid_t Window::getWindow() { _background = g_vm->glk_window_open(0, 0, 0, wintype_Graphics, 0);
if (!_win) { _lower = g_vm->glk_window_open(g_vm->glk_window_get_root(),
// Window doesn't exist, so create it winmethod_Arbitrary | winmethod_Fixed, 0, wintype_TextBuffer, 0);
// TODO: For now I'm assuming all the extra created windows will be graphics, since Glk requires _upper = g_vm->glk_window_open(g_vm->glk_window_get_root(),
// us to specify it at creation time. Not sure if it's true or not for all V6 games winmethod_Arbitrary | winmethod_Fixed, 0, wintype_TextGrid, 0);
_win = g_vm->glk_window_open(g_vm->glk_window_get_root(), winmethod_Arbitrary | winmethod_Fixed, } else {
0, wintype_Graphics, 0); _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);
} }
return _win; _lower.update();
_upper.update();
g_vm->glk_set_window(_lower);
}
/*--------------------------------------------------------------------------*/
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;
}
void Window::update() {
assert(_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) { void Window::setSize(const Point &newSize) {
winid_t win = getWindow();
checkRepositionLower(); checkRepositionLower();
Point s(newSize.x * g_conf->_monoInfo._cellW, newSize.y * g_conf->_monoInfo._cellH); _properties[X_SIZE] = newSize.x;
win->setSize(s); _properties[Y_SIZE] = newSize.y;
/* TODO
// Keep the cursor within the window if (_win)
if (wp[win].y_cursor > zargs[1] || wp[win].x_cursor > zargs[2]) _win->setSize(Point(newSize.x * g_conf->_monoInfo._cellW, newSize.y * g_conf->_monoInfo._cellH));
reset_cursor(win);
os_window_height(win, _wp[win].y_size);
*/
} }
void Window::setPosition(const Point &newPos) { void Window::setPosition(const Point &newPos) {
winid_t win = getWindow();
checkRepositionLower(); checkRepositionLower();
Point pos((newPos.x - 1) * g_conf->_monoInfo._cellW, (newPos.y - 1) * g_conf->_monoInfo._cellH); _properties[X_POS] = newPos.x;
win->setPosition(pos); _properties[Y_POS] = newPos.y;
if (_win)
_win->setPosition(Point((newPos.x - 1) * g_conf->_monoInfo._cellW, (newPos.y - 1) * g_conf->_monoInfo._cellH));
} }
const uint16 &Window::operator[](WindowProperty propType) { const uint16 &Window::getProperty(WindowProperty propType) {
_tempVal = getProperty(propType); if (_win)
return _tempVal; update();
}
uint16 Window::getProperty(WindowProperty propType) { return _properties[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));
*/
}
} }
void Window::setProperty(WindowProperty propType, uint16 value) { void Window::setProperty(WindowProperty propType, uint16 value) {

View file

@ -48,17 +48,12 @@ class Window {
private: private:
Windows *_windows; Windows *_windows;
winid_t _win; winid_t _win;
uint16 _tempVal; ///< used in calls to square brackets operator uint16 _properties[TRUE_BG_COLOR + 1];
private: private:
/**
* Gets a reference to the window, creating a new one if one doesn't already exist
*/
winid_t getWindow();
/** /**
* Get a property value * Get a property value
*/ */
uint16 getProperty(WindowProperty propType); const uint16 &getProperty(WindowProperty propType);
/** /**
* Set a property value * Set a property value
@ -69,6 +64,11 @@ private:
* Called when trying to reposition or resize windows. Does special handling for the lower window * Called when trying to reposition or resize windows. Does special handling for the lower window
*/ */
void checkRepositionLower(); void checkRepositionLower();
/**
* Updates the local window properties based on an attached Glk window
*/
void update();
public: public:
/** /**
* Constructor * Constructor
@ -86,17 +86,20 @@ public:
/** /**
* Cast operator for getting a Glk window * 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; } operator bool() const { return _win != nullptr; }
/** /**
* Property accessor * Property accessor
*/ */
const uint16 &operator[](WindowProperty propType); const uint16 &operator[](WindowProperty propType) { return getProperty(propType); }
/** /**
* Set the window size * Set the window size
@ -116,6 +119,7 @@ class Windows {
private: private:
Window _windows[8]; Window _windows[8];
public: public:
winid_t _background;
Window &_lower; Window &_lower;
Window &_upper; Window &_upper;
public: public:
@ -133,6 +137,11 @@ public:
* Array access * Array access
*/ */
Window &operator[](uint idx); Window &operator[](uint idx);
/**
* Setup the screen
*/
void setup(bool isVersion6);
}; };
} // End of namespace Frotz } // End of namespace Frotz