From 063cfb35efa155e6383a0262b20baa656732a89a Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 3 Nov 2018 12:35:55 -0700 Subject: GLK: Added glk style methods --- engines/gargoyle/glk.cpp | 70 +++++++++++++++++++++++++++++++---- engines/gargoyle/glk.h | 6 +-- engines/gargoyle/window_text_buffer.h | 8 ++-- engines/gargoyle/window_text_grid.cpp | 14 +++---- engines/gargoyle/window_text_grid.h | 7 +++- engines/gargoyle/windows.cpp | 5 +++ engines/gargoyle/windows.h | 16 +++++++- 7 files changed, 103 insertions(+), 23 deletions(-) diff --git a/engines/gargoyle/glk.cpp b/engines/gargoyle/glk.cpp index 7805207eb0..3148fa1544 100644 --- a/engines/gargoyle/glk.cpp +++ b/engines/gargoyle/glk.cpp @@ -444,18 +444,74 @@ void Glk::glk_stylehint_set(glui32 wintype, glui32 styl, glui32 hint, glsi32 val // TODO } -void Glk::glk_stylehint_clear(glui32 wintype, glui32 styl, glui32 hint) { +void Glk::glk_stylehint_clear(glui32 wintype, glui32 style, glui32 hint) { // TODO } -glui32 Glk::glk_style_distinguish(winid_t win, glui32 styl1, glui32 styl2) { - // TODO - return 0; +glui32 Glk::glk_style_distinguish(winid_t win, glui32 style1, glui32 style2) { + const WindowStyle *styles = win->getStyles(); + if (!styles) + return false; + + return styles[style1] == styles[style2] ? 0 : 1; } -glui32 Glk::glk_style_measure(winid_t win, glui32 styl, glui32 hint, glui32 *result) { - // TODO - return 0; +bool Glk::glk_style_measure(winid_t win, glui32 style, glui32 hint, glui32 *result) { + const WindowStyle *styles = win->getStyles(); + if (!styles) + return false; + + switch (hint) { + case stylehint_Indentation: + case stylehint_ParaIndentation: + *result = 0; + break; + + case stylehint_Justification: + *result = stylehint_just_LeftFlush; + break; + + case stylehint_Size: + *result = 1; + break; + + case stylehint_Weight: + *result = + (styles[style].font == PROPB || styles[style].font == PROPZ || + styles[style].font == MONOB || styles[style].font == MONOZ); + break; + + case stylehint_Oblique: + *result = + (styles[style].font == PROPI || styles[style].font == PROPZ || + styles[style].font == MONOI || styles[style].font == MONOZ); + break; + + case stylehint_Proportional: + *result = + (styles[style].font == PROPR || styles[style].font == PROPI || + styles[style].font == PROPB || styles[style].font == PROPZ); + break; + + case stylehint_TextColor: + *result = + (styles[style].fg[0] << 16) | (styles[style].fg[1] << 8) | (styles[style].fg[2]); + break; + + case stylehint_BackColor: + *result = + (styles[style].bg[0] << 16) | (styles[style].bg[1] << 8) | (styles[style].bg[2]); + break; + + case stylehint_ReverseColor: + *result = styles[style].reverse; + break; + + default: + return false; + } + + return true; } frefid_t Glk::glk_fileref_create_temp(glui32 usage, glui32 rock) { diff --git a/engines/gargoyle/glk.h b/engines/gargoyle/glk.h index ccd2e5b20d..bef6280971 100644 --- a/engines/gargoyle/glk.h +++ b/engines/gargoyle/glk.h @@ -110,9 +110,9 @@ public: void glk_stylehint_set(glui32 wintype, glui32 styl, glui32 hint, glsi32 val); - void glk_stylehint_clear(glui32 wintype, glui32 styl, glui32 hint); - glui32 glk_style_distinguish(winid_t win, glui32 styl1, glui32 styl2); - glui32 glk_style_measure(winid_t win, glui32 styl, glui32 hint, glui32 *result); + void glk_stylehint_clear(glui32 wintype, glui32 style, glui32 hint); + glui32 glk_style_distinguish(winid_t win, glui32 style1, glui32 style2); + bool glk_style_measure(winid_t win, glui32 style, glui32 hint, glui32 *result); frefid_t glk_fileref_create_temp(glui32 usage, glui32 rock); frefid_t glk_fileref_create_by_name(glui32 usage, const char *name, glui32 rock); diff --git a/engines/gargoyle/window_text_buffer.h b/engines/gargoyle/window_text_buffer.h index fdca1d8793..5359d4e60e 100644 --- a/engines/gargoyle/window_text_buffer.h +++ b/engines/gargoyle/window_text_buffer.h @@ -126,9 +126,6 @@ public: glui32 _echoLineInput; glui32 *_lineTerminators; - /* style hints and settings */ - WindowStyle _styles[style_NUMSTYLES]; - /* for copy selection */ glui32 *_copyBuf; int _copyPos; @@ -219,6 +216,11 @@ public: virtual void cancelCharEvent() override { _charRequest = _charRequestUni = false; } virtual void flowBreak() override; + + /** + * Returns a pointer to the styles for the window + */ + virtual const WindowStyle *getStyles() const override { return _styles; } }; } // End of namespace Gargoyle diff --git a/engines/gargoyle/window_text_grid.cpp b/engines/gargoyle/window_text_grid.cpp index 283922c59d..351d9fbe23 100644 --- a/engines/gargoyle/window_text_grid.cpp +++ b/engines/gargoyle/window_text_grid.cpp @@ -39,7 +39,7 @@ TextGridWindow::TextGridWindow(Windows *windows, uint32 rock) : Window(windows, _inArrayRock.num = 0; _lineTerminators = nullptr; - Common::copy(&g_conf->_gStyles[0], &g_conf->_gStyles[style_NUMSTYLES], styles); + Common::copy(&g_conf->_gStyles[0], &g_conf->_gStyles[style_NUMSTYLES], _styles); } TextGridWindow::~TextGridWindow() { @@ -598,9 +598,9 @@ void TextGridWindow::redraw() { for (b = 0; b < _width; b++) { if (ln->_attrs[a] != ln->_attrs[b]) { link = ln->_attrs[a].hyper; - font = ln->_attrs[a].attrFont(styles); - fgcolor = link ? g_conf->_linkColor : ln->_attrs[a].attrFg(styles); - bgcolor = ln->_attrs[a].attrBg(styles); + font = ln->_attrs[a].attrFont(_styles); + fgcolor = link ? g_conf->_linkColor : ln->_attrs[a].attrFg(_styles); + bgcolor = ln->_attrs[a].attrBg(_styles); w = (b - a) * g_conf->_cellW; screen.fillRect(Rect::fromXYWH(x, y, w, g_conf->_leading), bgcolor); o = x; @@ -620,9 +620,9 @@ void TextGridWindow::redraw() { } } link = ln->_attrs[a].hyper; - font = ln->_attrs[a].attrFont(styles); - fgcolor = link ? g_conf->_linkColor : ln->_attrs[a].attrFg(styles); - bgcolor = ln->_attrs[a].attrBg(styles); + font = ln->_attrs[a].attrFont(_styles); + fgcolor = link ? g_conf->_linkColor : ln->_attrs[a].attrFg(_styles); + bgcolor = ln->_attrs[a].attrBg(_styles); w = (b - a) * g_conf->_cellW; w += _bbox.right - (x + w); screen.fillRect(Rect::fromXYWH(x, y, w, g_conf->_leading), bgcolor); diff --git a/engines/gargoyle/window_text_grid.h b/engines/gargoyle/window_text_grid.h index 1fba707356..0040b195ba 100644 --- a/engines/gargoyle/window_text_grid.h +++ b/engines/gargoyle/window_text_grid.h @@ -74,8 +74,6 @@ public: Attributes _origAttr; gidispatch_rock_t _inArrayRock; glui32 *_lineTerminators; - - WindowStyle styles[style_NUMSTYLES]; ///< style hints and settings public: /** * Constructor @@ -167,6 +165,11 @@ public: virtual void requestHyperlinkEvent() override { _hyperRequest = true; } virtual void cancelCharEvent() override { _charRequest = _charRequestUni = false; } + + /** + * Returns a pointer to the styles for the window + */ + virtual const WindowStyle *getStyles() const override { return _styles; } }; } // End of namespace Gargoyle diff --git a/engines/gargoyle/windows.cpp b/engines/gargoyle/windows.cpp index 6d09d82819..89118819fa 100644 --- a/engines/gargoyle/windows.cpp +++ b/engines/gargoyle/windows.cpp @@ -618,6 +618,11 @@ void Window::setBackgroundColor(glui32 color) { warning("setBackgroundColor: not a graphics window"); } +const WindowStyle *Window::getStyles() const { + warning("getStyles: not a text window"); + return nullptr; +} + void Window::setTerminatorsLineEvent(glui32 *keycodes, glui32 count) { if (dynamic_cast(this) || dynamic_cast(this)) { delete _lineTerminatorsBase; diff --git a/engines/gargoyle/windows.h b/engines/gargoyle/windows.h index 20ce03d9b2..bd24892939 100644 --- a/engines/gargoyle/windows.h +++ b/engines/gargoyle/windows.h @@ -222,7 +222,14 @@ struct WindowStyle { FACES font; byte bg[3]; byte fg[3]; - int reverse; + bool reverse; + + /** + * Equality comparison + */ + bool operator==(const WindowStyle &src) const { + return !memcmp(this, &src, sizeof(WindowStyle)); + } }; /** @@ -295,6 +302,8 @@ struct Attributes { * Window definition */ class Window { +protected: + WindowStyle _styles[style_NUMSTYLES]; ///< style hints and settings for grid and buffer windows public: Windows *_windows; glui32 _rock; @@ -448,6 +457,11 @@ public: virtual void fillRect(glui32 color, const Rect &box); virtual void setBackgroundColor(glui32 color); + + /** + * Returns a pointer to the styles for the window + */ + virtual const WindowStyle *getStyles() const; }; typedef Window *winid_t; -- cgit v1.2.3