aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2018-10-19 22:05:47 -0700
committerPaul Gilbert2018-12-08 19:05:59 -0800
commit256f7ff31264efcd23b86d1fe79fce8a3597e64a (patch)
tree0af93a86634da4f8f769b3b34b23907e1d5dd80b /engines
parent3c9987c0a7566f99da637a83c9a3fe64b160e6e4 (diff)
downloadscummvm-rg350-256f7ff31264efcd23b86d1fe79fce8a3597e64a.tar.gz
scummvm-rg350-256f7ff31264efcd23b86d1fe79fce8a3597e64a.tar.bz2
scummvm-rg350-256f7ff31264efcd23b86d1fe79fce8a3597e64a.zip
GLK: Skeleton implementation of window text stream
Diffstat (limited to 'engines')
-rw-r--r--engines/gargoyle/glk.cpp23
-rw-r--r--engines/gargoyle/glk.h4
-rw-r--r--engines/gargoyle/glk_types.h3
-rw-r--r--engines/gargoyle/module.mk1
-rw-r--r--engines/gargoyle/stream.cpp44
-rw-r--r--engines/gargoyle/stream.h74
-rw-r--r--engines/gargoyle/windows.cpp9
-rw-r--r--engines/gargoyle/windows.h13
8 files changed, 148 insertions, 23 deletions
diff --git a/engines/gargoyle/glk.cpp b/engines/gargoyle/glk.cpp
index 7274ff2af4..3e308d5506 100644
--- a/engines/gargoyle/glk.cpp
+++ b/engines/gargoyle/glk.cpp
@@ -22,6 +22,7 @@
#include "gargoyle/glk.h"
#include "gargoyle/events.h"
+#include "gargoyle/stream.h"
#include "gargoyle/windows.h"
namespace Gargoyle {
@@ -122,8 +123,7 @@ void Glk::glk_window_move_cursor(winid_t win, glui32 xpos, glui32 ypos) {
}
strid_t Glk::glk_window_get_stream(winid_t win) {
- // TODO
- return nullptr;
+ return win->_stream;
}
void Glk::glk_window_set_echo_stream(winid_t win, strid_t str) {
@@ -136,7 +136,7 @@ strid_t Glk::glk_window_get_echo_stream(winid_t win) {
}
void Glk::glk_set_window(winid_t win) {
- _windows->setCurrent(win ? win->str : nullptr);
+ _windows->setCurrent(win ? win->_stream : nullptr);
}
strid_t Glk::glk_stream_open_file(frefid_t fileref, glui32 fmode,
@@ -371,27 +371,28 @@ glui32 Glk::glk_buffer_to_title_case_uni(glui32 *buf, glui32 len,
}
void Glk::glk_put_char_uni(glui32 ch) {
- // TODO
+ glk_put_char_stream_uni(_windows->getCurrent(), ch);
}
void Glk::glk_put_string_uni(glui32 *s) {
- // TODO
+ glk_put_buffer_stream_uni(_windows->getCurrent(), s, strlen_uni(s));
}
void Glk::glk_put_buffer_uni(glui32 *buf, glui32 len) {
- // TODO
+ glk_put_buffer_stream_uni(_windows->getCurrent(), buf, len);
}
void Glk::glk_put_char_stream_uni(strid_t str, glui32 ch) {
- // TODO
+ str->writeUint32LE(ch);
}
-void Glk::glk_put_string_stream_uni(strid_t str, glui32 *s) {
- // TODO
+void Glk::glk_put_string_stream_uni(strid_t str, const glui32 *s) {
+ glk_put_buffer_stream_uni(str, s, strlen_uni(s));
}
-void Glk::glk_put_buffer_stream_uni(strid_t str, glui32 *buf, glui32 len) {
- // TODO
+void Glk::glk_put_buffer_stream_uni(strid_t str, const glui32 *buf, glui32 len) {
+ while (len-- > 0)
+ str->writeUint32LE(*buf++);
}
glsi32 Glk::glk_get_char_stream_uni(strid_t str) {
diff --git a/engines/gargoyle/glk.h b/engines/gargoyle/glk.h
index ce21910a1a..b0ef1714ac 100644
--- a/engines/gargoyle/glk.h
+++ b/engines/gargoyle/glk.h
@@ -171,8 +171,8 @@ public:
void glk_put_string_uni(glui32 *s);
void glk_put_buffer_uni(glui32 *buf, glui32 len);
void glk_put_char_stream_uni(strid_t str, glui32 ch);
- void glk_put_string_stream_uni(strid_t str, glui32 *s);
- void glk_put_buffer_stream_uni(strid_t str, glui32 *buf, glui32 len);
+ void glk_put_string_stream_uni(strid_t str, const glui32 *s);
+ void glk_put_buffer_stream_uni(strid_t str, const glui32 *buf, glui32 len);
glsi32 glk_get_char_stream_uni(strid_t str);
glui32 glk_get_buffer_stream_uni(strid_t str, glui32 *buf, glui32 len);
diff --git a/engines/gargoyle/glk_types.h b/engines/gargoyle/glk_types.h
index 82f70e3618..86b37fc5d7 100644
--- a/engines/gargoyle/glk_types.h
+++ b/engines/gargoyle/glk_types.h
@@ -24,6 +24,7 @@
#define GARGOYLE_GLK_TYPES_H
#include "common/scummsys.h"
+#include "common/stream.h"
namespace Gargoyle {
@@ -49,7 +50,7 @@ class Window;
* These types are opaque object identifiers. They're pointers to opaque
* C structures, which are defined differently by each library.
*/
-typedef struct glk_stream_struct *strid_t;
+typedef Common::WriteStream *strid_t;
typedef struct glk_fileref_struct *frefid_t;
typedef struct glk_schannel_struct *schanid_t;
diff --git a/engines/gargoyle/module.mk b/engines/gargoyle/module.mk
index e5542a763c..5acba6a7a4 100644
--- a/engines/gargoyle/module.mk
+++ b/engines/gargoyle/module.mk
@@ -6,6 +6,7 @@ MODULE_OBJS := \
gargoyle.o \
glk.o \
picture.o \
+ stream.o \
windows.o \
scott/detection.o \
scott/scott.o
diff --git a/engines/gargoyle/stream.cpp b/engines/gargoyle/stream.cpp
new file mode 100644
index 0000000000..a08579a97d
--- /dev/null
+++ b/engines/gargoyle/stream.cpp
@@ -0,0 +1,44 @@
+/* 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.
+ *
+ */
+
+#include "gargoyle/stream.h"
+
+namespace Gargoyle {
+
+uint32 WindowStream::write(const void *dataPtr, uint32 dataSize) {
+ // TODO
+ return dataSize;
+}
+
+bool WindowStream::flush() {
+ // TODO
+ return true;
+}
+
+size_t strlen_uni(const uint32 *s) {
+ size_t len = 0;
+ while (*s++)
+ ++len;
+ return len;
+}
+
+} // End of namespace Gargoyle
diff --git a/engines/gargoyle/stream.h b/engines/gargoyle/stream.h
new file mode 100644
index 0000000000..5a55fbc16a
--- /dev/null
+++ b/engines/gargoyle/stream.h
@@ -0,0 +1,74 @@
+/* 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_STREAM_H
+#define GARGOYLE_STREAM_H
+
+#include "common/stream.h"
+
+namespace Gargoyle {
+
+class Window;
+
+/**
+ * Implements the stream for writing text to a window
+ */
+class WindowStream : public Common::WriteStream {
+private:
+ uint32 _rock;
+ Window *_window;
+public:
+ /**
+ * Constructor
+ */
+ WindowStream(Window *window, uint32 rock = 0) : Common::WriteStream(),
+ _window(window), _rock(rock) {}
+
+ /**
+ * Write to the stream
+ */
+ virtual uint32 write(const void *dataPtr, uint32 dataSize);
+
+ /**
+ * Flush the stream
+ */
+ virtual bool flush();
+
+ /**
+ * Finalize and close this stream
+ */
+ virtual void finalize() { flush(); }
+
+ /**
+ * Returns the stream position
+ */
+ virtual int32 pos() const { return 0; }
+};
+
+/*
+ * Get the length of a unicode string
+ */
+size_t strlen_uni(const uint32 *s);
+
+} // End of namespace Gargoyle
+
+#endif
diff --git a/engines/gargoyle/windows.cpp b/engines/gargoyle/windows.cpp
index 42c5b1ab76..0abc8a8797 100644
--- a/engines/gargoyle/windows.cpp
+++ b/engines/gargoyle/windows.cpp
@@ -21,6 +21,7 @@
*/
#include "gargoyle/windows.h"
+#include "gargoyle/stream.h"
#include "common/algorithm.h"
#include "common/textconsole.h"
@@ -281,10 +282,6 @@ void Windows::clearSelection() {
_claimSelect = false;
}
-void Windows::setCurrent(Common::WriteStream *stream) {
- _currentStr = stream;
-}
-
void Windows::repaint(const Common::Rect &box) {
// TODO
}
@@ -295,7 +292,7 @@ Window::Window(Windows *windows, glui32 rock) : _magicnum(MAGIC_WINDOW_NUM),
_windows(windows), _rock(rock), _type(0), parent(nullptr), next(nullptr), prev(nullptr),
yadj(0), line_request(0), line_request_uni(0), char_request(0), char_request_uni(0),
mouse_request(0), hyper_request(0), more_request(0), scroll_request(0), image_loaded(0),
- echo_line_input(true), line_terminators(nullptr), termct(0), str(nullptr), echostr(nullptr) {
+ echo_line_input(true), line_terminators(nullptr), termct(0), _echoStream(nullptr) {
attr.fgset = 0;
attr.bgset = 0;
attr.reverse = 0;
@@ -307,6 +304,8 @@ Window::Window(Windows *windows, glui32 rock) : _magicnum(MAGIC_WINDOW_NUM),
Common::fill(&bgcolor[0], &bgcolor[3], 3);
Common::fill(&fgcolor[0], &fgcolor[3], 3);
disprock.num = 0;
+
+ _stream = new WindowStream(this, rock);
}
/*--------------------------------------------------------------------------*/
diff --git a/engines/gargoyle/windows.h b/engines/gargoyle/windows.h
index 112e903beb..17e7d16aef 100644
--- a/engines/gargoyle/windows.h
+++ b/engines/gargoyle/windows.h
@@ -116,7 +116,12 @@ public:
/**
* Set the current output stream
*/
- void setCurrent(Common::WriteStream *stream);
+ void setCurrent(Common::WriteStream *stream) { _currentStr = stream; }
+
+ /**
+ * Gets the current output stream
+ */
+ Common::WriteStream *getCurrent() const { return _currentStr; }
/**
* Repaint an area of the windows
@@ -179,12 +184,12 @@ public:
glui32 _rock;
glui32 _type;
- Window *parent; ///< pair window which contains this one
+ Window *parent; ///< pair window which contains this one
Common::Rect bbox;
int yadj;
- Common::WriteStream *str; ///< the window stream.
- Common::WriteStream *echostr; ///< the window's echo stream, if any.
+ Common::WriteStream *_stream; ///< the window stream.
+ Common::WriteStream *_echoStream; ///< the window's echo stream, if any.
int line_request;
int line_request_uni;