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(int number)40 void GlkInterface::print(int number) {
41 	Common::String s = Common::String::format("%d", number);
42 	print(s);
43 }
44 
readLine()45 Common::String GlkInterface::readLine() {
46 	event_t ev;
47 	char line[200];
48 
49 	print(": ");
50 
51 	if (!_pendingLine.empty()) {
52 		// The next input line has been manually provided, so return it
53 		print(_pendingLine);
54 		print("\n");
55 
56 		Common::String l = _pendingLine;
57 		_pendingLine = "";
58 		return l;
59 	}
60 
61 	glk_request_line_event(_window, line, 199, 0);
62 
63 	do {
64 		glk_select(&ev);
65 		if (ev.type == evtype_Quit)
66 			return "";
67 		else if (ev.type == evtype_LineInput) {
68 			line[ev.val1] = '\0';
69 			return Common::String(line);
70 		}
71 	} while (!shouldQuit() && ev.type != evtype_Quit);
72 
73 	return "";
74 }
75 
76 } // End of namespace AdvSys
77 } // End of namespace Glk
78