diff options
author | Paul Gilbert | 2019-02-23 16:30:58 -0800 |
---|---|---|
committer | Paul Gilbert | 2019-02-23 16:31:08 -0800 |
commit | 4efa9c73d4141116892ee1cf732cdfbc259821e4 (patch) | |
tree | 7f368ac5658b86a3fce9b3783f790e1616054618 | |
parent | 5f520aa386d829f2bbb168f31318f3422ecf01f1 (diff) | |
download | scummvm-rg350-4efa9c73d4141116892ee1cf732cdfbc259821e4.tar.gz scummvm-rg350-4efa9c73d4141116892ee1cf732cdfbc259821e4.tar.bz2 scummvm-rg350-4efa9c73d4141116892ee1cf732cdfbc259821e4.zip |
GLK: FROTZ: Add V6 text cursor logic
-rw-r--r-- | engines/glk/frotz/glk_interface.cpp | 23 | ||||
-rw-r--r-- | engines/glk/frotz/glk_interface.h | 2 | ||||
-rw-r--r-- | engines/glk/frotz/processor_screen.cpp | 75 | ||||
-rw-r--r-- | engines/glk/frotz/windows.cpp | 25 | ||||
-rw-r--r-- | engines/glk/frotz/windows.h | 5 |
5 files changed, 78 insertions, 52 deletions
diff --git a/engines/glk/frotz/glk_interface.cpp b/engines/glk/frotz/glk_interface.cpp index aa5139f7c1..ae26ee02eb 100644 --- a/engines/glk/frotz/glk_interface.cpp +++ b/engines/glk/frotz/glk_interface.cpp @@ -33,7 +33,7 @@ namespace Frotz { GlkInterface::GlkInterface(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gameDesc), - _pics(nullptr), oldstyle(0), curstyle(0), cury(1), curx(1), curr_font(1), prev_font(1), temp_font(0), + _pics(nullptr), oldstyle(0), curstyle(0), curr_font(1), prev_font(1), temp_font(0), curr_status_ht(0), mach_status_ht(0), gos_status(nullptr), gos_curwin(nullptr), gos_linepending(0), gos_linebuf(nullptr), gos_linewin(nullptr), gos_channel(nullptr), cwin(0), mwin(0), mouse_x(0), mouse_y(0), fixforced(0), menu_selected(0), enable_wrapping(false), enable_scripting(false), enable_scrolling(false), @@ -380,10 +380,10 @@ void GlkInterface::gos_update_width() { glk_window_get_size(_wp._upper, &width, nullptr); h_screen_cols = width; SET_BYTE(H_SCREEN_COLS, width); - if ((uint)curx > width) { - glk_window_move_cursor(_wp._upper, 0, cury - 1); - curx = 1; - } + + uint curx = _wp._upper[X_CURSOR]; + if (curx > width) + _wp._upper.setCursor(Point(1, _wp._upper[Y_CURSOR])); } } @@ -440,10 +440,10 @@ void GlkInterface::split_window(zword lines) { curr_status_ht = lines; } mach_status_ht = lines; - if (cury > lines) { - glk_window_move_cursor(_wp._upper, 0, 0); - curx = cury = 1; - } + + int curY = _wp._upper[Y_CURSOR]; + if (curY > lines) + _wp._upper.setCursor(Point(1, 1)); gos_update_width(); if (h_version == V3) @@ -521,9 +521,10 @@ void GlkInterface::smartstatusline() { memcpy(buf + 1 + scoreofs, c, scorelen * sizeof(zchar)); memcpy(buf + 1, a, roomlen * sizeof(zchar)); - glk_window_move_cursor(_wp._upper, 0, 0); + Point cursPos(_wp._upper[X_CURSOR], _wp._upper[Y_CURSOR]); + _wp._upper.setCursor(Point(1, 1)); glk_put_buffer_uni(buf, h_screen_cols); - glk_window_move_cursor(_wp._upper, cury - 1, curx - 1); + _wp._upper.setCursor(cursPos); } void GlkInterface::gos_cancel_pending_line() { diff --git a/engines/glk/frotz/glk_interface.h b/engines/glk/frotz/glk_interface.h index b52fdc4e6d..22518b8b37 100644 --- a/engines/glk/frotz/glk_interface.h +++ b/engines/glk/frotz/glk_interface.h @@ -64,8 +64,6 @@ public: uint zcolors[zcolor_NUMCOLORS]; int oldstyle; int curstyle; - int cury; - int curx; int fixforced; int curr_font; diff --git a/engines/glk/frotz/processor_screen.cpp b/engines/glk/frotz/processor_screen.cpp index 0bcf98278f..9ae076b689 100644 --- a/engines/glk/frotz/processor_screen.cpp +++ b/engines/glk/frotz/processor_screen.cpp @@ -104,8 +104,7 @@ void Processor::screen_char(zchar c) { if (gos_linepending && (gos_curwin == gos_linewin)) { gos_cancel_pending_line(); if (gos_curwin == _wp._upper) { - curx = 1; - cury ++; + _wp._upper.setCursor(Point(1, _wp._upper[Y_CURSOR] + 1)); } if (c == '\n') return; @@ -127,9 +126,10 @@ void Processor::screen_char(zchar c) { if (_wp._upper && gos_curwin == _wp._upper) { if (c == '\n' || c == ZC_RETURN) { glk_put_char('\n'); - curx = 1; - cury ++; + _wp._upper.setCursor(Point(1, _wp._upper[Y_CURSOR] + 1)); } else { + int curx = _wp._upper[X_CURSOR], cury = _wp._upper[Y_CURSOR]; + if (cury == 1) { if (curx <= (int)((sizeof statusline / sizeof(zchar)) - 1)) { statusline[curx - 1] = c; @@ -232,10 +232,14 @@ void Processor::z_buffer_screen() { void Processor::z_erase_line() { int i; + flush_buffer(); + if (_wp._upper && gos_curwin == _wp._upper) { + int curx = _wp[cwin][X_CURSOR], cury = _wp[cwin][Y_CURSOR]; + for (i = 0; i < h_screen_cols + 1 - curx; i++) glk_put_char(' '); - glk_window_move_cursor(gos_curwin, curx - 1, cury - 1); + _wp._upper.setCursor(Point(curx, cury)); } } @@ -251,12 +255,26 @@ void Processor::z_erase_window() { } void Processor::z_get_cursor() { - storew((zword)(zargs[0] + 0), cury); - storew((zword)(zargs[0] + 2), curx); + zword y, x; + + flush_buffer(); + + x = _wp[cwin][X_CURSOR]; + y = _wp[cwin][Y_CURSOR]; + + if (h_version != V6) { + // convert to grid positions + y = (y - 1) / h_font_height + 1; + x = (x - 1) / h_font_width + 1; + } + + storew((zword)(zargs[0] + 0), y); + storew((zword)(zargs[0] + 2), x); } void Processor::z_print_table() { zword addr = zargs[0]; + int curx = _wp[cwin][X_CURSOR], cury = _wp[cwin][Y_CURSOR]; zword xs = curx; int i, j; zbyte c; @@ -269,7 +287,7 @@ void Processor::z_print_table() { // Write text in width x height rectangle for (i = 0; i < zargs[2]; i++, curx = xs, cury++) { - glk_window_move_cursor(_wp[cwin], xs - 1, cury - 1); + _wp[cwin].setCursor(Point(xs, cury)); for (j = 0; j < zargs[1]; j++) { LOW_BYTE(addr, c); @@ -401,37 +419,18 @@ void Processor::z_set_font() { void Processor::z_set_cursor() { int x = (int16)zargs[1], y = (int16)zargs[0]; - assert(_wp._upper); + int win = (h_version == V6) ? winarg2() : cwin; - flush_buffer(); - - if (y < 0) { - // Cursor on/off - if (y == -2) - g_vm->_events->showMouseCursor(true); - else if (y == -1) - g_vm->_events->showMouseCursor(false); - return; - } - - if (!x || !y) { - winid_t win = _wp._upper; - Point cursorPos = win->getCursor(); - if (!x) - x = cursorPos.x; - if (!y) - y = cursorPos.y; - } + if (zargc < 3) + zargs[2] = -3; - curx = x; - cury = y; + flush_buffer(); + _wp[win].setCursor(Point(x, y)); - if (cury > mach_status_ht) { - mach_status_ht = cury; + if (gos_curwin == _wp._upper && _wp[win][Y_CURSOR] > (uint)mach_status_ht) { + mach_status_ht = _wp[win][Y_CURSOR]; reset_status_ht(); } - - glk_window_move_cursor(_wp._upper, curx - 1, cury - 1); } void Processor::z_set_text_style() { @@ -504,8 +503,8 @@ void Processor::z_set_window() { } void Processor::pad_status_line(int column) { - int spaces; - spaces = (h_screen_cols + 1 - curx) - column; + int curx = _wp._upper[X_CURSOR]; + int spaces = (h_screen_cols + 1 - curx) - column; while (spaces-- > 0) print_char(' '); } @@ -541,9 +540,7 @@ void Processor::z_show_status() { gos_curwin = _wp._upper; os_set_reverse_video(true); - - curx = cury = 1; - glk_window_move_cursor(_wp._upper, 0, 0); + _wp._upper.setCursor(Point(1, 1)); // If the screen width is below 55 characters then we have to use // the brief status line format diff --git a/engines/glk/frotz/windows.cpp b/engines/glk/frotz/windows.cpp index 71f6fb98ea..884d1d709d 100644 --- a/engines/glk/frotz/windows.cpp +++ b/engines/glk/frotz/windows.cpp @@ -118,6 +118,31 @@ void Window::setPosition(const Point &newPos) { _win->setPosition(Point((newPos.x - 1) * g_conf->_monoInfo._cellW, (newPos.y - 1) * g_conf->_monoInfo._cellH)); } +void Window::setCursor(const Point &newPos) { + int x = newPos.x, y = newPos.y; + + if (y < 0) { + // Cursor on/off + if (y == -2) + g_vm->_events->showMouseCursor(true); + else if (y == -1) + g_vm->_events->showMouseCursor(false); + return; + } + + if (!x || !y) { + update(); + + if (!x) + x = _properties[X_CURSOR]; + if (!y) + y = _properties[Y_CURSOR]; + } + + g_vm->glk_window_move_cursor(_win, x - 1, y - 1); +} + + const uint &Window::getProperty(WindowProperty propType) { if (_win) update(); diff --git a/engines/glk/frotz/windows.h b/engines/glk/frotz/windows.h index 3ee2fe6d93..3acb166108 100644 --- a/engines/glk/frotz/windows.h +++ b/engines/glk/frotz/windows.h @@ -140,6 +140,11 @@ public: * Set the position of a window */ void setPosition(const Point &newPos); + + /** + * Set the cursor position + */ + void setCursor(const Point &newPos); }; /** |