mirror of
https://github.com/scummvm/scummvm.git
synced 2026-06-20 05:45:29 +00:00
GLK: Added WindowStream put methods
This commit is contained in:
committed by
Paul Gilbert
parent
ac9a122e3d
commit
855fd39a9e
@@ -40,7 +40,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), _screen(nullptr), _windows(nullptr),
|
||||
gli_unregister_obj(nullptr), gli_register_arr(nullptr), gli_unregister_arr(nullptr) {
|
||||
g_vm = this;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "engines/advancedDetector.h"
|
||||
#include "engines/engine.h"
|
||||
#include "graphics/screen.h"
|
||||
#include "gargoyle/glk_types.h"
|
||||
|
||||
namespace Gargoyle {
|
||||
|
||||
@@ -95,6 +96,10 @@ public:
|
||||
Events *_events;
|
||||
Streams *_streams;
|
||||
Windows *_windows;
|
||||
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);
|
||||
|
||||
public:
|
||||
GargoyleEngine(OSystem *syst, const GargoyleGameDescription *gameDesc);
|
||||
virtual ~GargoyleEngine();
|
||||
|
||||
@@ -89,22 +89,60 @@ void WindowStream::putCharUni(uint32 ch) {
|
||||
return;
|
||||
++_writeCount;
|
||||
|
||||
//TODO
|
||||
if (_window->_lineRequest || _window->_lineRequestUni) {
|
||||
if (g_conf->_safeClicks && g_vm->_events->_forceClick) {
|
||||
_window->cancelLineEvent(nullptr);
|
||||
g_vm->_events->_forceClick = false;
|
||||
} else {
|
||||
warning("putCharUni: window has pending line request");
|
||||
}
|
||||
}
|
||||
|
||||
_window->putCharUni(ch);
|
||||
if (_window->_echoStream)
|
||||
_window->_echoStream->putCharUni(ch);
|
||||
}
|
||||
|
||||
void WindowStream::putBuffer(const unsigned char *buf, size_t len) {
|
||||
void WindowStream::putBuffer(const char *buf, size_t len) {
|
||||
if (!_writable)
|
||||
return;
|
||||
++_writeCount;
|
||||
//TODO
|
||||
_writeCount += len;
|
||||
|
||||
if (_window->_lineRequest || _window->_lineRequestUni) {
|
||||
if (g_conf->_safeClicks && g_vm->_events->_forceClick) {
|
||||
_window->cancelLineEvent(nullptr);
|
||||
g_vm->_events->_forceClick = false;
|
||||
} else {
|
||||
warning("putBuffer: window has pending line request");
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t lx = 0; lx < len; lx++, buf++)
|
||||
_window->putChar(*buf);
|
||||
if (_window->_echoStream)
|
||||
_window->_echoStream->putBuffer(buf, len);
|
||||
|
||||
}
|
||||
|
||||
void WindowStream::putBufferUni(const uint32 *buf, size_t len) {
|
||||
if (!_writable)
|
||||
return;
|
||||
++_writeCount;
|
||||
//TODO
|
||||
_writeCount += len;
|
||||
|
||||
if (_window->_lineRequest || _window->_lineRequestUni) {
|
||||
if (g_conf->_safeClicks && g_vm->_events->_forceClick) {
|
||||
_window->cancelLineEvent(nullptr);
|
||||
g_vm->_events->_forceClick = false;
|
||||
}
|
||||
else {
|
||||
warning("putBuffer: window has pending line request");
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t lx = 0; lx < len; lx++, buf++)
|
||||
_window->putCharUni(*buf);
|
||||
if (_window->_echoStream)
|
||||
_window->_echoStream->putBufferUni(buf, len);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@@ -132,7 +170,7 @@ void MemoryStream::putCharUni(uint32 ch) {
|
||||
|
||||
}
|
||||
|
||||
void MemoryStream::putBuffer(const unsigned char *buf, size_t len) {
|
||||
void MemoryStream::putBuffer(const char *buf, size_t len) {
|
||||
//TODO
|
||||
|
||||
}
|
||||
@@ -156,7 +194,7 @@ void FileStream::putCharUni(uint32 ch) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
void FileStream::putBuffer(const unsigned char *buf, size_t len) {
|
||||
void FileStream::putBuffer(const char *buf, size_t len) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
|
||||
@@ -93,12 +93,28 @@ public:
|
||||
/**
|
||||
* Write a buffer
|
||||
*/
|
||||
virtual void putBuffer(const unsigned char *buf, size_t len) = 0;
|
||||
virtual void putBuffer(const char *buf, size_t len) = 0;
|
||||
|
||||
/**
|
||||
* Write a unicode character
|
||||
*/
|
||||
virtual void putBufferUni(const uint32 *buf, size_t len) = 0;
|
||||
|
||||
/**
|
||||
* Send a line to the stream with a trailing newline
|
||||
*/
|
||||
void echoLine(char *buf, glui32 len) {
|
||||
putBuffer(buf, len);
|
||||
putChar('\n');
|
||||
};
|
||||
|
||||
/**
|
||||
* Send a line to the stream with a trailing newline
|
||||
*/
|
||||
void echoLineUni(glui32 *buf, glui32 len) {
|
||||
putBufferUni(buf, len);
|
||||
putCharUni('\n');
|
||||
}
|
||||
};
|
||||
typedef Stream *strid_t;
|
||||
|
||||
@@ -133,7 +149,7 @@ public:
|
||||
/**
|
||||
* Write a buffer
|
||||
*/
|
||||
virtual void putBuffer(const unsigned char *buf, size_t len) override;
|
||||
virtual void putBuffer(const char *buf, size_t len) override;
|
||||
|
||||
/**
|
||||
* Write a unicode character
|
||||
@@ -170,7 +186,7 @@ public:
|
||||
/**
|
||||
* Write a buffer
|
||||
*/
|
||||
virtual void putBuffer(const unsigned char *buf, size_t len) override;
|
||||
virtual void putBuffer(const char *buf, size_t len) override;
|
||||
|
||||
/**
|
||||
* Write a unicode character
|
||||
@@ -202,7 +218,7 @@ public:
|
||||
/**
|
||||
* Write a buffer
|
||||
*/
|
||||
virtual void putBuffer(const unsigned char *buf, size_t len) override;
|
||||
virtual void putBuffer(const char *buf, size_t len) override;
|
||||
|
||||
/**
|
||||
* Write a unicode character
|
||||
|
||||
@@ -297,7 +297,7 @@ TextGridWindow::TextGridWindow(Windows *windows, uint32 rock) : Window(windows,
|
||||
_width = _height = 0;
|
||||
_curX = _curY = 0;
|
||||
_inBuf = nullptr;
|
||||
_inorgX = _inorgY = 0;
|
||||
_inOrgX = _inOrgY = 0;
|
||||
_inMax = 0;
|
||||
_inCurs = _inLen = 0;
|
||||
_inArrayRock.num = 0;
|
||||
@@ -316,9 +316,9 @@ void TextGridWindow::rearrange(const Common::Rect &box) {
|
||||
if (newwid == _width && newhgt == _height)
|
||||
return;
|
||||
|
||||
lines.resize(newhgt);
|
||||
_lines.resize(newhgt);
|
||||
for (int y = 0; y < newhgt; ++y) {
|
||||
lines[y].resize(newwid);
|
||||
_lines[y].resize(newwid);
|
||||
touch(y);
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ void TextGridWindow::rearrange(const Common::Rect &box) {
|
||||
|
||||
void TextGridWindow::touch(int line) {
|
||||
int y = bbox.top + line * g_conf->_leading;
|
||||
lines[line].dirty = true;
|
||||
_lines[line].dirty = true;
|
||||
_windows->repaint(Common::Rect(bbox.left, y, bbox.right, y + g_conf->_leading));
|
||||
}
|
||||
|
||||
@@ -339,6 +339,12 @@ glui32 TextGridWindow::getSplit(glui32 size, bool vertical) const {
|
||||
}
|
||||
|
||||
void TextGridWindow::cancelLineEvent(Event *ev) {
|
||||
int ix;
|
||||
void *inbuf;
|
||||
int inmax;
|
||||
int unicode = _lineRequestUni;
|
||||
gidispatch_rock_t inarrayrock;
|
||||
TextGridRow *ln = &_lines[_inOrgY];
|
||||
Event dummyEv;
|
||||
|
||||
if (!ev)
|
||||
@@ -350,7 +356,51 @@ void TextGridWindow::cancelLineEvent(Event *ev) {
|
||||
return;
|
||||
|
||||
|
||||
// TODO : textgrid_cancel_line
|
||||
inbuf = _inBuf;
|
||||
inmax = _inMax;
|
||||
inarrayrock = _inArrayRock;
|
||||
|
||||
if (!unicode) {
|
||||
for (ix = 0; ix<_inLen; ix++)
|
||||
{
|
||||
glui32 ch = ln->chars[_inOrgX + ix];
|
||||
if (ch > 0xff)
|
||||
ch = '?';
|
||||
((char *)inbuf)[ix] = (char)ch;
|
||||
}
|
||||
if (_echoStream)
|
||||
_echoStream->echoLine((char *)_inBuf, _inLen);
|
||||
} else {
|
||||
for (ix = 0; ix<_inLen; ix++)
|
||||
((glui32 *)inbuf)[ix] = ln->chars[_inOrgX + ix];
|
||||
if (_echoStream)
|
||||
_echoStream->echoLineUni((glui32 *)inbuf, _inLen);
|
||||
}
|
||||
|
||||
_curY = _inOrgY + 1;
|
||||
_curX = 0;
|
||||
_attr = _origAttr;
|
||||
|
||||
ev->_type = evtype_LineInput;
|
||||
ev->_window = this;
|
||||
ev->_val1 = _inLen;
|
||||
ev->_val2 = 0;
|
||||
|
||||
_lineRequest = false;
|
||||
_lineRequestUni = false;
|
||||
|
||||
if (_lineTerminators) {
|
||||
free(_lineTerminators);
|
||||
_lineTerminators = nullptr;
|
||||
}
|
||||
|
||||
_inBuf = nullptr;
|
||||
_inMax = 0;
|
||||
_inOrgX = 0;
|
||||
_inOrgY = 0;
|
||||
|
||||
if (g_vm->gli_unregister_arr)
|
||||
(*g_vm->gli_unregister_arr)(inbuf, inmax, unicode ? "&+#!Iu" : "&+#!Cn", inarrayrock);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@@ -791,6 +841,12 @@ glui32 TextBufferWindow::getSplit(glui32 size, bool vertical) const {
|
||||
}
|
||||
|
||||
void TextBufferWindow::cancelLineEvent(Event *ev) {
|
||||
gidispatch_rock_t inarrayrock;
|
||||
int ix;
|
||||
int len;
|
||||
void *inbuf;
|
||||
int inmax;
|
||||
int unicode = _lineRequestUni;
|
||||
Event dummyEv;
|
||||
|
||||
if (!ev)
|
||||
@@ -801,8 +857,61 @@ void TextBufferWindow::cancelLineEvent(Event *ev) {
|
||||
if (!_lineRequest && !_lineRequestUni)
|
||||
return;
|
||||
|
||||
if (!_inBuf)
|
||||
return;
|
||||
|
||||
// TODO : textbuffer_cancel_line
|
||||
inbuf = _inBuf;
|
||||
inmax = _inMax;
|
||||
inarrayrock = _inArrayRock;
|
||||
|
||||
len = _numChars - _inFence;
|
||||
if (_echoStream)
|
||||
_echoStream->echoLineUni(_chars + _inFence, len);
|
||||
|
||||
if (len > inmax)
|
||||
len = inmax;
|
||||
|
||||
if (!unicode)
|
||||
{
|
||||
for (ix = 0; ix<len; ix++)
|
||||
{
|
||||
glui32 ch = _chars[_inFence + ix];
|
||||
if (ch > 0xff)
|
||||
ch = '?';
|
||||
((char *)inbuf)[ix] = (char)ch;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (ix = 0; ix<len; ix++)
|
||||
((glui32 *)inbuf)[ix] = _chars[_inFence + ix];
|
||||
}
|
||||
|
||||
_attr = _origAttr;
|
||||
|
||||
ev->_type = evtype_LineInput;
|
||||
ev->_window = this;
|
||||
ev->_val1 = len;
|
||||
ev->_val2 = 0;
|
||||
|
||||
_lineRequest = false;
|
||||
_lineRequestUni = false;
|
||||
if (_lineTerminators) {
|
||||
free(_lineTerminators);
|
||||
_lineTerminators = nullptr;
|
||||
}
|
||||
_inBuf = nullptr;
|
||||
_inMax = 0;
|
||||
|
||||
if (_echoLineInput) {
|
||||
putCharUni('\n');
|
||||
} else {
|
||||
_numChars = _inFence;
|
||||
touch(0);
|
||||
}
|
||||
|
||||
if (g_vm->gli_unregister_arr)
|
||||
(*g_vm->gli_unregister_arr)(inbuf, inmax, unicode ? "&+#!Iu" : "&+#!Cn", inarrayrock);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
@@ -313,13 +313,13 @@ private:
|
||||
void touch(int line);
|
||||
public:
|
||||
int _width, _height;
|
||||
TextGridRows lines;
|
||||
TextGridRows _lines;
|
||||
|
||||
int _curX, _curY; ///< the window cursor position
|
||||
|
||||
///< for line input
|
||||
void *_inBuf; ///< unsigned char* for latin1, glui32* for unicode
|
||||
int _inorgX, _inorgY;
|
||||
int _inOrgX, _inOrgY;
|
||||
int _inMax;
|
||||
int _inCurs, _inLen;
|
||||
Attributes _origAttr;
|
||||
|
||||
Reference in New Issue
Block a user