GLK: Implementing text buffer window methods

This commit is contained in:
Paul Gilbert 2018-10-23 19:25:00 -07:00 committed by Paul Gilbert
parent cb2b7d439f
commit ba907c9aec
18 changed files with 1461 additions and 193 deletions

View File

@ -24,9 +24,28 @@
namespace Gargoyle {
int Draw::drawStringUni(int x, int y, int fidx, byte *rgb, glui32 *s, int n, int spw) {
int Draw::drawString(int x, int y, int fidx, const byte *rgb, const char *s, int n, int spw) {
// TODO
return 0;
}
int Draw::drawStringUni(int x, int y, int fidx, const byte *rgb, const glui32 *s, int n, int spw) {
// TODO
return 0;
}
int Draw::stringWidth(int fidx, const char *s, int n, int spw) {
// TODO
return 0;
}
int Draw::stringWidthUni(int fidx, const glui32 *s, int n, int spw) {
// TODO
return 0;
}
void Draw::drawCaret(const Common::Point &pos) {
// TODO
}
} // End of namespace Gargoyle

View File

@ -23,14 +23,22 @@
#ifndef GARGOYLE_DRAW_H
#define GARGOYLE_DRAW_H
#include "common/events.h"
#include "common/rect.h"
#include "gargoyle/glk_types.h"
namespace Gargoyle {
class Draw {
protected:
int drawStringUni(int x, int y, int fidx, byte *rgb, glui32 *s, int n, int spw);
int drawString(int x, int y, int fidx, const byte *rgb, const char *s, int n, int spw);
int drawStringUni(int x, int y, int fidx, const byte *rgb, const glui32 *s, int n, int spw);
int stringWidth(int fidx, const char *s, int n, int spw);
int stringWidthUni(int fidx, const glui32 *s, int n, int spw);
void drawCaret(const Common::Point &pos);
};
} // End of namespace Gargoyle

View File

@ -31,8 +31,10 @@
#include "gargoyle/gargoyle.h"
#include "gargoyle/conf.h"
#include "gargoyle/events.h"
#include "gargoyle/picture.h"
#include "gargoyle/streams.h"
#include "gargoyle/windows.h"
#include "gargoyle/window_mask.h"
namespace Gargoyle {
@ -40,7 +42,8 @@ GargoyleEngine *g_vm;
GargoyleEngine::GargoyleEngine(OSystem *syst, const GargoyleGameDescription *gameDesc) :
_gameDescription(gameDesc), Engine(syst), _random("Gargoyle"), _conf(nullptr),
_events(nullptr), _screen(nullptr), _windows(nullptr),
_events(nullptr), _picList(nullptr), _screen(nullptr), _windows(nullptr),
_windowMask(nullptr), _copySelect(false),
gli_unregister_obj(nullptr), gli_register_arr(nullptr), gli_unregister_arr(nullptr) {
g_vm = this;
}
@ -48,9 +51,11 @@ GargoyleEngine::GargoyleEngine(OSystem *syst, const GargoyleGameDescription *gam
GargoyleEngine::~GargoyleEngine() {
delete _conf;
delete _events;
delete _picList;
delete _screen;
delete _streams;
delete _windows;
delete _windowMask;
}
void GargoyleEngine::initialize() {
@ -64,8 +69,10 @@ void GargoyleEngine::initialize() {
_screen = new Graphics::Screen();
_conf = new Conf();
_events = new Events();
_picList = new PicList();
_streams = new Streams();
_windows = new Windows(_screen);
_windowMask = new WindowMask();
}
Common::Error GargoyleEngine::run() {

View File

@ -36,7 +36,9 @@ namespace Gargoyle {
class Conf;
class Events;
class PicList;
class Windows;
class WindowMask;
class Streams;
enum InterpreterType {
@ -94,8 +96,11 @@ protected:
public:
Conf *_conf;
Events *_events;
PicList *_picList;
Streams *_streams;
Windows *_windows;
WindowMask *_windowMask;
bool _copySelect;
void (*gli_unregister_obj)(void *obj, glui32 objclass, gidispatch_rock_t objrock);
gidispatch_rock_t (*gli_register_arr)(void *array, glui32 len, const char *typecode);
void (*gli_unregister_arr)(void *array, glui32 len, const char *typecode, gidispatch_rock_t objrock);

View File

@ -53,6 +53,35 @@ class Window;
typedef struct glk_fileref_struct *frefid_t;
typedef struct glk_schannel_struct *schanid_t;
/**
* Usurp C1 space for ligatures and smart typography glyphs
*/
enum Enc {
ENC_LIG_FI = 128,
ENC_LIG_FL = 129,
ENC_LSQUO = 130,
ENC_RSQUO = 131,
ENC_LDQUO = 132,
ENC_RDQUO = 133,
ENC_NDASH = 134,
ENC_MDASH = 135,
ENC_FLOWBREAK = 136
};
/**
* These are the Unicode versions
*/
enum UniChars {
UNI_LIG_FI = 0xFB01,
UNI_LIG_FL = 0xFB02,
UNI_LSQUO = 0x2018,
UNI_RSQUO = 0x2019,
UNI_LDQUO = 0x201c,
UNI_RDQUO = 0x201d,
UNI_NDASH = 0x2013,
UNI_MDASH = 0x2014
};
enum Gestalt {
gestalt_Version = 0,
gestalt_CharInput = 1,

View File

@ -24,6 +24,16 @@
namespace Gargoyle {
void PicList::increment() {
// TODO
}
void PicList::decrement() {
// TODO
}
/*--------------------------------------------------------------------------*/
void Picture::increment() {
++_refCount;
}
@ -35,4 +45,19 @@ void Picture::decrement() {
}
}
Picture *Picture::load(uint32 id) {
// TODO: gli_picture_load
return nullptr;
}
Picture *Picture::scale(int sx, int sy) {
// TODO: gli_picture_scale
return nullptr;
}
void Picture::drawPicture(int x0, int y0, int dx0, int dy0, int dx1, int dy1) {
// TODO: drawPicture
}
} // End of namespace Gargoyle

View File

@ -27,7 +27,17 @@
namespace Gargoyle {
class PicList {
public:
void increment();
void decrement();
};
struct Picture : Graphics::Surface {
public:
static Picture *load(uint32 id);
public:
int _refCount;
uint32 _id;
bool _scaled;
@ -46,6 +56,16 @@ struct Picture : Graphics::Surface {
* Decrement reference counter
*/
void decrement();
/**
* Rescale the picture to a new picture of a given size
*/
Picture *scale(int sx, int sy);
/**
* Draw the picture
*/
void drawPicture(int x0, int y0, int dx0, int dy0, int dx1, int dy1);
};
} // End of namespace Gargoyle

49
engines/gargoyle/speech.h Normal file
View File

@ -0,0 +1,49 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef GARGOYLE_SPEECH_H
#define GARGOYLE_SPEECH_H
#include "common/events.h"
#include "gargoyle/glk_types.h"
namespace Gargoyle {
/**
* Currently not implemented
*/
class Speech {
protected:
void gli_initialize_tts(void) {}
void gli_tts_flush(void) {}
void gli_tts_purge(void) {}
void gli_tts_speak(const glui32 *buf, size_t len) {}
void gli_free_tts(void) {}
};
} // End of namespace Gargoyle
#endif

View File

@ -86,4 +86,9 @@ void GraphicsWindow::redraw() {
// TODO
}
glui32 GraphicsWindow::imageDraw(glui32 image, glui32 align, bool scaled, glui32 width, glui32 height) {
// TODO: win_graphics_draw_picture
return 0;
}
} // End of namespace Gargoyle

View File

@ -77,6 +77,9 @@ public:
*/
virtual void redraw() override;
virtual glui32 imageDraw(glui32 image, glui32 align, bool scaled, glui32 width = 0,
glui32 height = 0) override;
/**
* Get the window dimensions
*/

View File

@ -202,7 +202,7 @@ int WindowMask::checkSelection(uint x0, uint y0, uint x1, uint y1) {
return false;
}
int WindowMask::getSelection(uint x0, uint y0, uint x1, uint y1, uint *rx0, uint *rx1) {
int WindowMask::getSelection(uint x0, uint y0, uint x1, uint y1, int *rx0, int *rx1) {
uint row, upper, lower, above, below;
int row_selected, found_left, found_right;
int from_right, from_below, is_above, is_below;

View File

@ -30,13 +30,14 @@ namespace Gargoyle {
class Window;
struct WindowMask {
class WindowMask {
public:
size_t _hor, _ver;
glui32 **_links;
Common::Rect _select;
static int _lastX, _lastY;
public:
/**
* Constructor
*/
@ -59,7 +60,7 @@ struct WindowMask {
int checkSelection(uint x0, uint y0, uint x1, uint y1);
int getSelection(uint x0, uint y0, uint x1, uint y1, uint *rx0, uint *rx1);
int getSelection(uint x0, uint y0, uint x1, uint y1, int *rx0, int *rx1);
};
} // End of namespace Gargoyle

File diff suppressed because it is too large Load Diff

View File

@ -25,47 +25,72 @@
#include "gargoyle/windows.h"
#include "gargoyle/picture.h"
#include "gargoyle/speech.h"
namespace Gargoyle {
/**
* Text Buffer window
*/
class TextBufferWindow : public Window {
class TextBufferWindow : public Window, Speech {
/**
* Structure for a row within the window
*/
struct TextBufferRow {
Common::Array<uint32> chars;
Common::Array<Attributes> attr;
int len, newline;
bool dirty, repaint;
Picture *lpic, *rpic;
glui32 lhyper, rhyper;
int lm, rm;
glui32 _chars[TBLINELEN];
Attributes _attrs[TBLINELEN];
int _len, _newLine;
bool _dirty, _repaint;
Picture *_lPic, *_rPic;
glui32 _lHyper, _rHyper;
int _lm, _rm;
/**
* Constructor
*/
TextBufferRow();
/**
* Resize the row
*/
void resize(size_t newSize);
};
typedef Common::Array<TextBufferRow> TextBufferRows;
private:
void reflow();
void touchScroll();
bool putPicture(Picture *pic, glui32 align, glui32 linkval);
/**
* @remarks Only for input text
*/
void putText(const char *buf, int len, int pos, int oldlen);
/**
* @remarks Only for input text
*/
void putTextUni(const glui32 *buf, int len, int pos, int oldlen);
void flowBreak();
bool flowBreak();
void acceptLine(glui32 keycode);
/**
* Return true if a following quotation mark should be an opening mark,
* false if it should be a closing mark. Opening quotation marks will
* appear following an open parenthesis, open square bracket, or
* whitespace.
*/
bool leftquote(glui32 c);
/**
* Mark a given text row as modified
*/
void touch(int line);
void scrollOneLine(bool forced);
void scrollResize();
int calcWidth(glui32 *chars, Attributes *attrs, int startchar, int numchars, int spw);
/**
* Copy the passed text to the clipboard
*/
void copyTextToClipboard(const glui32 *text, size_t len);
public:
int _width, _height;
int _spaced;
@ -106,7 +131,7 @@ public:
glui32 *_lineTerminators;
/* style hints and settings */
WindowStyle styles[style_NUMSTYLES];
WindowStyle _styles[style_NUMSTYLES];
/* for copy selection */
glui32 *_copyBuf;
@ -142,16 +167,16 @@ public:
*/
virtual bool unputCharUni(uint32 ch) override;
/**
* Move the cursor
*/
virtual void moveCursor(const Common::Point &newPos) override;
/**
* Clear the window
*/
virtual void clear() override;
/**
* Click the window
*/
virtual void click(const Common::Point &newPos) override;
/**
* Prepare for inputing a line
*/
@ -176,6 +201,15 @@ public:
* Redraw the window
*/
virtual void redraw() override;
virtual glui32 imageDraw(glui32 image, glui32 align, bool scaled, glui32 width = 0,
glui32 height = 0) override;
virtual void acceptReadLine(glui32 arg) override;
virtual void acceptReadChar(glui32 arg) override;
int acceptScroll(glui32 arg);
};
} // End of namespace Gargoyle

View File

@ -23,6 +23,7 @@
#include "gargoyle/window_text_grid.h"
#include "gargoyle/conf.h"
#include "gargoyle/gargoyle.h"
#include "gargoyle/window_mask.h"
namespace Gargoyle {
@ -203,7 +204,7 @@ void TextGridWindow::click(const Common::Point &newPos) {
}
if (_hyperRequest) {
glui32 linkval = _windows->getHyperlink(newPos);
glui32 linkval = g_vm->_windowMask->getHyperlink(newPos);
if (linkval)
{
g_vm->_events->eventStore(evtype_Hyperlink, this, linkval, 0);
@ -588,7 +589,7 @@ void TextGridWindow::redraw() {
y = y0 + i * g_conf->_leading;
/* clear any stored hyperlink coordinates */
_windows->setHyperlink(0, x0, y, x0 + g_conf->_cellW * _width, y + g_conf->_leading);
g_vm->_windowMask->putHyperlink(0, x0, y, x0 + g_conf->_cellW * _width, y + g_conf->_leading);
a = 0;
for (b = 0; b < _width; b++) {
@ -610,7 +611,7 @@ void TextGridWindow::redraw() {
if (link) {
_windows->drawRect(x, y + g_conf->_baseLine + 1, w,
g_conf->_linkStyle, g_conf->_linkColor);
_windows->setHyperlink(link, x, y, x + w, y + g_conf->_leading);
g_vm->_windowMask->putHyperlink(link, x, y, x + w, y + g_conf->_leading);
}
x += w;
a = b;
@ -634,7 +635,7 @@ void TextGridWindow::redraw() {
if (link) {
_windows->drawRect(x, y + g_conf->_baseLine + 1, w,
g_conf->_linkStyle, g_conf->_linkColor);
_windows->setHyperlink(link, x, y, x + w, y + g_conf->_leading);
g_vm->_windowMask->putHyperlink(link, x, y, x + w, y + g_conf->_leading);
}
}
}

View File

@ -56,17 +56,10 @@ private:
*/
void touch(int line);
void acceptReadChar(glui32 arg);
/**
* Return or enter, during line input. Ends line input.
*/
void acceptLine(glui32 keycode);
/**
* Any regular key, during line input.
*/
void acceptReadLine(glui32 arg);
public:
int _width, _height;
TextGridRows _lines;
@ -158,6 +151,10 @@ public:
* Redraw the window
*/
virtual void redraw() override;
virtual void acceptReadLine(glui32 arg) override;
virtual void acceptReadChar(glui32 arg) override;
};
} // End of namespace Gargoyle

View File

@ -37,6 +37,8 @@ bool Windows::_overrideReverse;
bool Windows::_overrideFgSet;
bool Windows::_overrideBgSet;
bool Windows::_forceRedraw;
bool Windows::_claimSelect;
bool Windows::_moreFocus;
int Windows::_overrideFgVal;
int Windows::_overrideBgVal;
int Windows::_zcolor_fg;
@ -48,14 +50,15 @@ byte Windows::_zcolor_Bright[3];
/*--------------------------------------------------------------------------*/
Windows::Windows(Graphics::Screen *screen) :
_screen(screen), _moreFocus(false), _windowList(nullptr),
_rootWin(nullptr), _focusWin(nullptr), _mask(nullptr), _claimSelect(0) {
Windows::Windows(Graphics::Screen *screen) : _screen(screen), _windowList(nullptr),
_rootWin(nullptr), _focusWin(nullptr), _mask(nullptr) {
_mask = new WindowMask();
_overrideReverse = false;
_overrideFgSet = false;
_overrideBgSet = false;
_forceRedraw = true;
_claimSelect = false;
_moreFocus = false;
_overrideFgVal = 0;
_overrideBgVal = 0;
_zcolor_fg = _zcolor_bg = 0;
@ -234,6 +237,10 @@ void Windows::redraw() {
// TODO: gli_windows_redraw
}
void Windows::redrawRect(const Common::Rect &r) {
// TODO: gli_redraw_rect
}
void Windows::repaint(const Common::Rect &box) {
// TODO
}
@ -291,7 +298,7 @@ Window::Window(Windows *windows, glui32 rock) : _windows(windows), _rock(rock),
_type(0), _parent(nullptr), _next(nullptr), _prev(nullptr), _yAdj(0),
_lineRequest(0), _lineRequestUni(0), _charRequest(0), _charRequestUni(0),
_mouseRequest(0), _hyperRequest(0), _moreRequest(0), _scrollRequest(0), _imageLoaded(0),
_echoLineInput(true), _lineTerminatorsBase(nullptr), _termCt(0), _echoStream(nullptr) {
_echoLineInputBase(true), _lineTerminatorsBase(nullptr), _termCt(0), _echoStream(nullptr) {
_attr.fgset = 0;
_attr.bgset = 0;
_attr.reverse = 0;
@ -337,6 +344,10 @@ void Window::cancelLineEvent(Event *ev) {
g_vm->_events->clearEvent(ev);
}
void Window::moveCursor(const Common::Point &newPos) {
warning("moveCursor: not a TextGrid window");
}
void Window::requestLineEvent(char *buf, glui32 maxlen, glui32 initlen) {
warning("requestLineEvent: window does not support keyboard input");
}
@ -353,6 +364,14 @@ void Window::redraw() {
}
}
void Window::acceptReadLine(glui32 arg) {
warning("acceptReadLine:: window does not support keyboard input");
}
void Window::acceptReadChar(glui32 arg) {
warning("acceptReadChar:: window does not support keyboard input");
}
bool Window::checkTerminator(glui32 ch) {
if (ch == keycode_Escape)
return true;

View File

@ -85,8 +85,6 @@ private:
Window * _windowList; ///< List of all windows
Window *_rootWin; ///< The topmost window
Window *_focusWin; ///< The window selected by the player
bool _moreFocus;
bool _claimSelect;
WindowMask *_mask;
private:
/**
@ -108,6 +106,8 @@ public:
static bool _overrideFgSet;
static bool _overrideBgSet;
static bool _forceRedraw;
static bool _claimSelect;
static bool _moreFocus;
static int _overrideFgVal;
static int _overrideBgVal;
static int _zcolor_fg, _zcolor_bg;
@ -157,6 +157,8 @@ public:
void redraw();
void redrawRect(const Common::Rect &r);
/**
* Repaint an area of the windows
*/
@ -176,18 +178,6 @@ public:
* Returns the end point of window iteration
*/
iterator end() { return iterator(nullptr); }
/**
* Gets a hyperlink
*/
glui32 getHyperlink(const Common::Point &pos) { return _mask->getHyperlink(pos); }
/**
* Sets a hyperlink
*/
void setHyperlink(glui32 linkval, uint x0, uint y0, uint x1, uint y1) {
return _mask->putHyperlink(linkval, x0, y0, x1, y1);
}
};
/**
@ -278,7 +268,7 @@ public:
int _scrollRequest;
int _imageLoaded;
glui32 _echoLineInput;
glui32 _echoLineInputBase;
glui32 *_lineTerminatorsBase;
glui32 _termCt;
@ -323,7 +313,7 @@ public:
/**
* Move the cursor
*/
virtual void moveCursor(const Common::Point &newPos) {}
virtual void moveCursor(const Common::Point &newPos);
/**
* Clear the window
@ -364,6 +354,15 @@ public:
* Redraw the window
*/
virtual void redraw();
virtual glui32 imageDraw(glui32 image, glui32 align, bool scaled, glui32 width = 0,
glui32 height = 0) { return false; }
virtual void acceptReadLine(glui32 arg);
virtual void acceptReadChar(glui32 arg);
int acceptScroll(glui32 arg);
};
typedef Window *winid_t;