From 63079834fa7fd7f4592b0a52e709d01b431740e2 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 3 Dec 2018 20:32:12 -0800 Subject: GLK: FROTZ: Improved rendering of Beyond Zork description area --- engines/glk/frotz/glk_interface.cpp | 2 ++ engines/glk/frotz/processor_screen.cpp | 47 ++++++++++++++++++++-------------- engines/glk/window_text_grid.h | 5 ++++ engines/glk/windows.h | 5 ++++ 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/engines/glk/frotz/glk_interface.cpp b/engines/glk/frotz/glk_interface.cpp index c2d6ca2703..7367375f05 100644 --- a/engines/glk/frotz/glk_interface.cpp +++ b/engines/glk/frotz/glk_interface.cpp @@ -203,6 +203,8 @@ bool GlkInterface::initPictures() { } int GlkInterface::os_char_width(zchar z) { + // Note: I'm presuming this is 1 because Glk Text Grid windows take care of font sizes internally, + // so we can pretend that any font has a 1x1 size return 1; } diff --git a/engines/glk/frotz/processor_screen.cpp b/engines/glk/frotz/processor_screen.cpp index 6627bf672d..2ec012854a 100644 --- a/engines/glk/frotz/processor_screen.cpp +++ b/engines/glk/frotz/processor_screen.cpp @@ -181,8 +181,9 @@ void Processor::z_get_cursor() { void Processor::z_print_table() { zword addr = zargs[0]; - zword x; + zword xs = curx; int i, j; + zbyte c; // Supply default arguments if (zargc < 3) @@ -191,18 +192,10 @@ void Processor::z_print_table() { zargs[3] = 0; // Write text in width x height rectangle - x = curx; - - for (i = 0; i < zargs[2]; i++) { - if (i != 0) { - cury += 1; - curx = x; - } + for (i = 0; i < zargs[2]; i++, curx = xs, cury++) { + glk_window_move_cursor(cwin == 0 ? gos_lower : gos_upper, xs - 1, cury - 1); for (j = 0; j < zargs[1]; j++) { - - zbyte c; - LOW_BYTE(addr, c); addr++; @@ -330,17 +323,33 @@ void Processor::z_set_font() { } void Processor::z_set_cursor() { - cury = zargs[0]; - curx = zargs[1]; + int x = (int16)zargs[1], y = (int16)zargs[0]; + assert(gos_upper); - if (gos_upper) { - if (cury > mach_status_ht) { - mach_status_ht = cury; - reset_status_ht(); - } + flush_buffer(); - glk_window_move_cursor(gos_upper, curx - 1, cury - 1); + if (y < 0) { + // Cursor on/off + error("TODO: Turning cursor on/off"); } + + if (!x || !y) { + Point cursorPos = gos_upper->getCursor(); + if (!x) + x = cursorPos.x; + if (!y) + y = cursorPos.y; + } + + curx = x; + cury = y; + + if (cury > mach_status_ht) { + mach_status_ht = cury; + reset_status_ht(); + } + + glk_window_move_cursor(gos_upper, curx - 1, cury - 1); } void Processor::z_set_text_style() { diff --git a/engines/glk/window_text_grid.h b/engines/glk/window_text_grid.h index 30a0f79b25..d7830e08ef 100644 --- a/engines/glk/window_text_grid.h +++ b/engines/glk/window_text_grid.h @@ -107,6 +107,11 @@ public: */ virtual bool unputCharUni(uint32 ch) override; + /** + * Get the cursor position + */ + virtual Point getCursor() const override { return Point(_curX, _curY); } + /** * Move the cursor */ diff --git a/engines/glk/windows.h b/engines/glk/windows.h index 27380fa23e..4b71aa0fab 100644 --- a/engines/glk/windows.h +++ b/engines/glk/windows.h @@ -439,6 +439,11 @@ public: return false; } + /** + * Get the cursor position + */ + virtual Point getCursor() const { return Point(); } + /** * Move the cursor */ -- cgit v1.2.3