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  * Additional copyright for this file:
8  * Copyright (C) 1995 Presto Studios, Inc.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19 
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  *
24  */
25 
26 #include "graphics/surface.h"
27 #include "graphics/font.h"
28 
29 #include "buried/buried.h"
30 #include "buried/gameui.h"
31 #include "buried/graphics.h"
32 #include "buried/livetext.h"
33 #include "buried/resources.h"
34 
35 namespace Buried {
36 
LiveTextWindow(BuriedEngine * vm,Window * parent)37 LiveTextWindow::LiveTextWindow(BuriedEngine *vm, Window *parent) : Window(vm, parent) {
38 	// Initialize member variables to empty
39 	_textTranslation = false;
40 
41 	// Create font
42 	_fontHeight = (_vm->getLanguage() == Common::JA_JPN) ? 12 : 14;
43 	_font = _vm->_gfx->createFont(_fontHeight);
44 
45 	// Create window
46 	_rect = Common::Rect(137, 21, 447, 87);
47 
48 	// Update the text in the window
49 	updateLiveText(_vm->getString(IDS_SAVE_GAME_MESSAGE), false);
50 }
51 
~LiveTextWindow()52 LiveTextWindow::~LiveTextWindow() {
53 	delete _font;
54 }
55 
updateLiveText(const Common::String & text,bool notifyUser)56 bool LiveTextWindow::updateLiveText(const Common::String &text, bool notifyUser) {
57 	// Set translated text flag
58 	_textTranslation = false;
59 
60 	if (text.empty()) {
61 		_text.clear();
62 
63 		invalidateWindow(false);
64 
65 		((GameUIWindow *)_parent)->setWarningState(false);
66 		return true;
67 	}
68 
69 	_text = text;
70 
71 	// Redraw the window
72 	invalidateWindow(false);
73 
74 	if (notifyUser)
75 		((GameUIWindow *)_parent)->flashWarningLight();
76 
77 	return true;
78 }
79 
updateTranslationText(const Common::String & text,bool notifyUser)80 bool LiveTextWindow::updateTranslationText(const Common::String &text, bool notifyUser) {
81 	if (text.empty()) {
82 		_text.clear();
83 
84 		invalidateWindow(false);
85 
86 		((GameUIWindow *)_parent)->setWarningState(false);
87 		return true;
88 	}
89 
90 	_text = text;
91 
92 	// Set translated text flag
93 	_textTranslation = true;
94 
95 	// Redraw the window
96 	invalidateWindow(false);
97 
98 	((GameUIWindow *)_parent)->setWarningState(false);
99 
100 	return true;
101 }
102 
translateBiochipClosing()103 void LiveTextWindow::translateBiochipClosing() {
104 	// If the current text is translated text, then kill it now
105 	if (_textTranslation)
106 		updateLiveText();
107 }
108 
onPaint()109 void LiveTextWindow::onPaint() {
110 	// Draw the background bitmap
111 	Graphics::Surface *surface = _vm->_gfx->getBitmap(IDB_LIVE_TEXT_BACKGROUND);
112 
113 	// Draw the text on top of that
114 	if (!_text.empty())
115 		_vm->_gfx->renderText(surface, _font, _text, 30, 4, 270, 50, _vm->_gfx->getColor(212, 109, 0), _fontHeight);
116 
117 	Common::Rect absoluteRect = getAbsoluteRect();
118 	_vm->_gfx->blit(surface, absoluteRect.left, absoluteRect.top);
119 
120 	surface->free();
121 	delete surface;
122 }
123 
onEnable(bool enable)124 void LiveTextWindow::onEnable(bool enable) {
125 	if (enable)
126 		_vm->removeMouseMessages(this);
127 }
128 
129 } // End of namespace Buried
130