From e655c50d17fdaea56567226187d0bf389047811a Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 4 Jan 2019 18:04:54 -0800 Subject: GLK: FROTZ: Simplified getting/setting window properties --- engines/glk/frotz/processor_windows.cpp | 10 +++++---- engines/glk/frotz/windows.cpp | 9 +++++--- engines/glk/frotz/windows.h | 38 +++++++++++++++++++++++++++++---- 3 files changed, 46 insertions(+), 11 deletions(-) (limited to 'engines/glk/frotz') diff --git a/engines/glk/frotz/processor_windows.cpp b/engines/glk/frotz/processor_windows.cpp index 9842368a9f..4045a9709a 100644 --- a/engines/glk/frotz/processor_windows.cpp +++ b/engines/glk/frotz/processor_windows.cpp @@ -228,14 +228,16 @@ void Processor::z_get_wind_prop() { } void Processor::z_put_wind_prop() { -#ifdef TODO flush_buffer(); - if (zargs[1] >= 16) + zword win = winarg0(); + WindowProperty prop = (WindowProperty)zargs[1]; + zword val = zargs[2]; + + if (prop >= TRUE_FG_COLOR) runtimeError(ERR_ILL_WIN_PROP); - ((zword *)(wp + winarg0()))[zargs[1]] = zargs[2]; -#endif + _wp[win][prop] = val; } void Processor::z_scroll_window() { diff --git a/engines/glk/frotz/windows.cpp b/engines/glk/frotz/windows.cpp index c1a4163a44..54f4c4aae0 100644 --- a/engines/glk/frotz/windows.cpp +++ b/engines/glk/frotz/windows.cpp @@ -110,15 +110,18 @@ void Window::setPosition(const Point &newPos) { _win->setPosition(Point((newPos.x - 1) * g_conf->_monoInfo._cellW, (newPos.y - 1) * g_conf->_monoInfo._cellH)); } -const uint16 &Window::getProperty(WindowProperty propType) { +const zword &Window::getProperty(WindowProperty propType) { if (_win) update(); return _properties[propType]; } -void Window::setProperty(WindowProperty propType, uint16 value) { - // TODO +void Window::setProperty(WindowProperty propType, zword value) { + switch (propType) { + default: + warning("Setting window property %d not yet supported", (int)propType); + } } void Window::checkRepositionLower() { diff --git a/engines/glk/frotz/windows.h b/engines/glk/frotz/windows.h index 56e0f99594..001fb50cf0 100644 --- a/engines/glk/frotz/windows.h +++ b/engines/glk/frotz/windows.h @@ -24,6 +24,7 @@ #define GLK_FROTZ_WINDOWS #include "glk/windows.h" +#include "glk/frotz/frotz_types.h" namespace Glk { namespace Frotz { @@ -45,20 +46,49 @@ class Windows; */ class Window { friend class Windows; + + /** + * Stub class for accessing window properties via the square brackets operator + */ + class PropertyAccessor { + private: + Window *_owner; + WindowProperty _prop; + public: + /** + * Constructor + */ + PropertyAccessor(Window *owner, WindowProperty prop) : _owner(owner), _prop(prop) {} + + /** + * Get + */ + operator zword() const { + return _owner->getProperty(_prop); + } + + /** + * Set + */ + PropertyAccessor &operator=(zword val) { + _owner->setProperty(_prop, val); + return *this; + } + }; private: Windows *_windows; winid_t _win; - uint16 _properties[TRUE_BG_COLOR + 1]; + zword _properties[TRUE_BG_COLOR + 1]; private: /** * Get a property value */ - const uint16 &getProperty(WindowProperty propType); + const zword &getProperty(WindowProperty propType); /** * Set a property value */ - void setProperty(WindowProperty propType, uint16 value); + void setProperty(WindowProperty propType, zword value); /** * Called when trying to reposition or resize windows. Does special handling for the lower window @@ -99,7 +129,7 @@ public: /** * Property accessor */ - const uint16 &operator[](WindowProperty propType) { return getProperty(propType); } + PropertyAccessor operator[](WindowProperty propType) { return PropertyAccessor(this, propType); } /** * Set the window size -- cgit v1.2.3