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 "titanic/support/text_cursor.h"
24 #include "titanic/events.h"
25 #include "titanic/support/screen_manager.h"
26 #include "titanic/titanic.h"
27 #include "common/textconsole.h"
28 
29 namespace Titanic {
30 
CTextCursor(CScreenManager * screenManager)31 CTextCursor::CTextCursor(CScreenManager *screenManager) :
32 		_screenManager(screenManager), _active(false), _blinkVisible(false),
33 		_backRenderSurface(nullptr), _frontRenderSurface(nullptr),
34 		_blinkDelay(300), _size(2, 10), _priorBlinkTime(0),
35 		_cursorR(0), _cursorG(0), _cursorB(0), _mode(-1) {
36 	_surface = screenManager->createSurface(10, 10, 16);
37 }
38 
~CTextCursor()39 CTextCursor::~CTextCursor() {
40 	delete _surface;
41 }
42 
setColor(byte r,byte g,byte b)43 void CTextCursor::setColor(byte r, byte g, byte b) {
44 	_cursorR = r;
45 	_cursorG = g;
46 	_cursorB = b;
47 }
48 
show()49 void CTextCursor::show() {
50 	_backRenderSurface = _screenManager->getSurface(SURFACE_BACKBUFFER);
51 	_frontRenderSurface = _screenManager->getFrontRenderSurface();
52 	_active = true;
53 	_priorBlinkTime = g_vm->_events->getTicksCount();
54 }
55 
hide()56 void CTextCursor::hide() {
57 	_active = false;
58 }
59 
draw()60 void CTextCursor::draw() {
61 	if (!_active)
62 		return;
63 
64 	// Handle updating whether the blinking cursor is visible or not
65 	uint newTicks = g_vm->_events->getTicksCount();
66 	while (newTicks > (_priorBlinkTime + _blinkDelay)) {
67 		_priorBlinkTime += _blinkDelay;
68 		_blinkVisible = !_blinkVisible;
69 	}
70 
71 	if (_blinkVisible) {
72 		Rect cursorRect = getCursorBounds();
73 		_surface->blitFrom(Common::Point(0, 0), _backRenderSurface, &cursorRect);
74 
75 		if (!_screenBounds.isEmpty())
76 			// Limit the cursor rect to only within designated screen area
77 			cursorRect.constrain(_screenBounds);
78 
79 		if (!cursorRect.isEmpty()) {
80 			// Draw cursor onto the screen
81 			_backRenderSurface->_ddSurface->fillRect(&cursorRect,
82 				_cursorR, _cursorG, _cursorB);
83 		}
84 
85 		//_screenManager->blitFrom(SURFACE_BACKBUFFER, _surface, &_pos);
86 	}
87 }
88 
89 } // End of namespace Titanic
90