1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "glk/advsys/glk_interface.h"
24 
25 namespace Glk {
26 namespace AdvSys {
27 
initialize()28 bool GlkInterface::initialize() {
29 	_window = glk_window_open(0, 0, 0, wintype_TextBuffer, 1);
30 	return _window != nullptr;
31 }
32 
print(const Common::String & msg)33 void GlkInterface::print(const Common::String &msg) {
34 	// Don't print out text if loading a savegame directly from the launcher, since we don't
35 	// want any of the intro text displayed by the startup code to show
36 	if (_saveSlot == -1)
37 		glk_put_string_stream(glk_window_get_stream(_window), msg.c_str());
38 }
39 
print(const Common::U32String & msg)40 void GlkInterface::print(const Common::U32String &msg) {
41 	// Don't print out text if loading a savegame directly from the launcher, since we don't
42 	// want any of the intro text displayed by the startup code to show
43 	if (_saveSlot == -1)
44 		glk_put_string_stream_uni(glk_window_get_stream(_window), msg.u32_str());
45 }
46 
print(int number)47 void GlkInterface::print(int number) {
48 	Common::String s = Common::String::format("%d", number);
49 	print(s);
50 }
51 
readLine()52 Common::String GlkInterface::readLine() {
53 	event_t ev;
54 	char line[200];
55 
56 	print(": ");
57 
58 	if (!_pendingLine.empty()) {
59 		// The next input line has been manually provided, so return it
60 		print(_pendingLine);
61 		print("\n");
62 
63 		Common::String l = _pendingLine;
64 		_pendingLine = "";
65 		return l;
66 	}
67 
68 	glk_request_line_event(_window, line, 199, 0);
69 
70 	do {
71 		glk_select(&ev);
72 		if (ev.type == evtype_Quit)
73 			return "";
74 		else if (ev.type == evtype_LineInput) {
75 			line[ev.val1] = '\0';
76 			return Common::String(line);
77 		}
78 	} while (!shouldQuit() && ev.type != evtype_Quit);
79 
80 	return "";
81 }
82 
83 } // End of namespace AdvSys
84 } // End of namespace Glk
85