2002-07-05 16:56:53 +00:00
|
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
|
* Copyright (C) 2002 The ScummVM project
|
|
|
|
|
*
|
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
*
|
|
|
|
|
* $Header$
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
2002-08-29 23:45:15 +00:00
|
|
|
|
#include "util.h"
|
|
|
|
|
#include "scumm/scumm.h"
|
|
|
|
|
#include "scumm/sound.h"
|
2002-07-05 16:56:53 +00:00
|
|
|
|
#include "newgui.h"
|
2002-08-29 23:45:15 +00:00
|
|
|
|
#include "dialog.h"
|
2002-09-19 17:44:41 +00:00
|
|
|
|
#include "scumm/dialogs.h"
|
2002-07-05 16:56:53 +00:00
|
|
|
|
|
2002-07-07 22:44:30 +00:00
|
|
|
|
/*
|
|
|
|
|
* TODO list
|
2002-09-19 21:45:56 +00:00
|
|
|
|
* - get a nicer font which contains diacrits (<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> etc.)
|
2002-07-07 22:44:30 +00:00
|
|
|
|
* - add more widgets
|
2002-07-08 01:04:29 +00:00
|
|
|
|
* - allow multi line (l/c/r aligned) text via StaticTextWidget ?
|
2002-07-07 22:44:30 +00:00
|
|
|
|
* - add "close" widget to all dialogs (with a flag to turn it off) ?
|
|
|
|
|
* - make dialogs "moveable" ?
|
2002-09-19 21:45:56 +00:00
|
|
|
|
* - come up with a new look & feel / theme for the GUI
|
2002-07-07 22:44:30 +00:00
|
|
|
|
* - ...
|
|
|
|
|
*/
|
|
|
|
|
|
2002-09-19 17:44:41 +00:00
|
|
|
|
// Built-in font
|
|
|
|
|
static byte guifont[] = {0,0,99,1,226,8,4,8,6,8,6,0,0,0,0,0,0,0,0,0,0,0,8,2,1,8,0,0,0,0,0,0,0,0,0,0,0,0,4,3,7,8,7,7,8,4,5,5,8,7,4,7,3,8,7,7,7,7,8,7,7,7,7,7,3,4,7,5,7,7,8,7,7,7,7,7,7,7,7,5,7,7,
|
|
|
|
|
7,8,7,7,7,7,7,7,7,7,7,8,7,7,7,5,8,5,8,8,7,7,7,6,7,7,7,7,7,5,6,7,5,8,7,7,7,7,7,7,7,7,7,8,7,7,7,5,3,5,0,8,7,7,7,7,7,7,0,6,7,7,7,5,5,5,7,0,6,8,8,7,7,7,7,7,0,7,7,0,0,
|
|
|
|
|
0,0,0,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,0,0,0,0,0,0,0,0,1,3,6,12,
|
|
|
|
|
24,62,3,0,128,192,96,48,24,124,192,0,0,3,62,24,12,6,3,1,0,192,124,24,48,96,192,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,237,74,72,0,0,0,0,0,128,128,128,0,0,0,0,0,0,0,0,0,0,0,0,0,60,66,153,161,161,153,66,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
|
0,0,0,0,0,0,0,0,0,96,96,96,96,0,0,96,0,102,102,102,0,0,0,0,0,102,102,255,102,255,102,102,0,24,62,96,60,6,124,24,0,98,102,12,24,48,102,70,0,60,102,60,56,103,102,63,0,96,48,16,0,0,0,0,0,24,48,96,96,96,48,24,0,96,48,24,24,24,48,96,0,
|
|
|
|
|
0,102,60,255,60,102,0,0,0,24,24,126,24,24,0,0,0,0,0,0,0,48,48,96,0,0,0,126,0,0,0,0,0,0,0,0,0,96,96,0,0,3,6,12,24,48,96,0,60,102,102,102,102,102,60,0,24,24,56,24,24,24,126,0,60,102,6,12,48,96,126,0,60,102,6,28,6,102,60,0,6,
|
|
|
|
|
14,30,102,127,6,6,0,126,96,124,6,6,102,60,0,60,102,96,124,102,102,60,0,126,102,12,24,24,24,24,0,60,102,102,60,102,102,60,0,60,102,102,62,6,102,60,0,0,0,96,0,0,96,0,0,0,0,48,0,0,48,48,96,14,24,48,96,48,24,14,0,0,0,120,0,120,0,0,0,112,24,
|
|
|
|
|
12,6,12,24,112,0,60,102,6,12,24,0,24,0,0,0,0,255,255,0,0,0,24,60,102,126,102,102,102,0,124,102,102,124,102,102,124,0,60,102,96,96,96,102,60,0,120,108,102,102,102,108,120,0,126,96,96,120,96,96,126,0,126,96,96,120,96,96,96,0,60,102,96,110,102,102,60,0,102,102,102,
|
|
|
|
|
126,102,102,102,0,120,48,48,48,48,48,120,0,30,12,12,12,12,108,56,0,102,108,120,112,120,108,102,0,96,96,96,96,96,96,126,0,99,119,127,107,99,99,99,0,102,118,126,126,110,102,102,0,60,102,102,102,102,102,60,0,124,102,102,124,96,96,96,0,60,102,102,102,102,60,14,0,124,102,102,124,
|
|
|
|
|
120,108,102,0,60,102,96,60,6,102,60,0,126,24,24,24,24,24,24,0,102,102,102,102,102,102,60,0,102,102,102,102,102,60,24,0,99,99,99,107,127,119,99,0,102,102,60,24,60,102,102,0,102,102,102,60,24,24,24,0,126,6,12,24,48,96,126,0,120,96,96,96,96,96,120,0,3,6,12,24,48,
|
|
|
|
|
96,192,0,120,24,24,24,24,24,120,0,0,0,0,0,0,219,219,0,0,0,0,0,0,0,0,255,102,102,102,0,0,0,0,0,0,0,60,6,62,102,62,0,0,96,96,124,102,102,124,0,0,0,60,96,96,96,60,0,0,6,6,62,102,102,62,0,0,0,60,102,126,96,60,0,0,14,24,62,24,24,
|
|
|
|
|
24,0,0,0,62,102,102,62,6,124,0,96,96,124,102,102,102,0,0,48,0,112,48,48,120,0,0,12,0,12,12,12,12,120,0,96,96,108,120,108,102,0,0,112,48,48,48,48,120,0,0,0,102,127,127,107,99,0,0,0,124,102,102,102,102,0,0,0,60,102,102,102,60,0,0,0,124,102,102,124,96,
|
|
|
|
|
96,0,0,62,102,102,62,6,6,0,0,124,102,96,96,96,0,0,0,62,96,60,6,124,0,0,24,126,24,24,24,14,0,0,0,102,102,102,102,62,0,0,0,102,102,102,60,24,0,0,0,99,107,127,62,54,0,0,0,102,60,24,60,102,0,0,0,102,102,102,62,12,120,0,0,126,12,24,48,126,0,
|
|
|
|
|
24,48,48,96,48,48,24,0,96,96,96,0,96,96,96,0,96,48,48,24,48,48,96,0,0,0,0,0,0,0,0,0,8,12,14,255,255,14,12,8,60,102,96,96,102,60,24,56,102,0,102,102,102,102,62,0,12,24,60,102,126,96,60,0,24,36,60,6,62,102,62,0,102,0,60,6,62,102,62,0,48,
|
|
|
|
|
24,60,6,62,102,62,0,0,0,0,0,0,0,0,0,0,60,96,96,96,60,24,56,24,36,60,102,126,96,60,0,102,0,60,102,126,96,60,0,48,24,60,102,126,96,60,0,0,216,0,112,48,48,120,0,48,72,0,112,48,48,120,0,96,48,0,112,48,48,120,0,102,24,60,102,126,102,102,0,0,0,
|
|
|
|
|
0,0,0,0,0,0,24,48,124,96,120,96,124,0,0,0,108,26,126,216,110,0,30,40,40,126,72,136,142,0,24,36,60,102,102,102,60,0,102,0,60,102,102,102,60,0,48,24,60,102,102,102,60,0,24,36,0,102,102,102,62,0,48,24,102,102,102,102,62,0,0,0,0,0,0,0,0,0,102,60,102,
|
|
|
|
|
102,102,102,60,0,102,0,102,102,102,102,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,24,60,6,62,102,62,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
|
0,0,0,0,0,0,28,54,54,124,102,102,124,64,0,0,0};
|
|
|
|
|
|
|
|
|
|
// Constructor
|
2002-09-19 16:06:51 +00:00
|
|
|
|
NewGui::NewGui(Scumm *s) : _s(s), _system(s->_system), _screen(0),
|
2002-09-19 21:45:56 +00:00
|
|
|
|
_use_alpha_blending(true), _need_redraw(false), _prepare_for_gui(true),
|
2002-07-18 14:47:25 +00:00
|
|
|
|
_currentKeyDown(0)
|
2002-09-19 16:06:51 +00:00
|
|
|
|
{
|
2002-09-19 21:45:56 +00:00
|
|
|
|
// Setup some default GUI colors.
|
|
|
|
|
// TODO - either use nicer values, or maybe make this configurable?
|
|
|
|
|
_bgcolor = RGB_TO_16(0, 0, 0);
|
|
|
|
|
_color = RGB_TO_16(80, 80, 80);
|
|
|
|
|
_shadowcolor = RGB_TO_16(64, 64, 64);
|
|
|
|
|
_textcolor = RGB_TO_16(32, 160, 32);
|
|
|
|
|
_textcolorhi = RGB_TO_16(0, 255, 0);
|
2002-07-07 22:44:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
|
void NewGui::loop()
|
|
|
|
|
{
|
2002-07-07 21:46:53 +00:00
|
|
|
|
Dialog *activeDialog = _dialogStack.top();
|
2002-08-04 01:18:06 +00:00
|
|
|
|
int i;
|
2002-07-07 21:46:53 +00:00
|
|
|
|
|
2002-07-10 16:49:45 +00:00
|
|
|
|
if (_prepare_for_gui) {
|
|
|
|
|
saveState();
|
2002-09-19 16:06:51 +00:00
|
|
|
|
|
2002-07-26 19:41:20 +00:00
|
|
|
|
_eventList.clear();
|
|
|
|
|
_currentKeyDown = 0;
|
2002-07-27 14:16:14 +00:00
|
|
|
|
|
|
|
|
|
_lastClick.x = _lastClick.y = 0;
|
|
|
|
|
_lastClick.time = 0;
|
|
|
|
|
_lastClick.count = 0;
|
2002-07-26 19:41:20 +00:00
|
|
|
|
|
2002-07-10 16:49:45 +00:00
|
|
|
|
_prepare_for_gui = false;
|
|
|
|
|
}
|
2002-07-13 22:41:29 +00:00
|
|
|
|
|
|
|
|
|
activeDialog->handleTickle();
|
|
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
|
if (_need_redraw) {
|
2002-09-19 16:06:51 +00:00
|
|
|
|
// Restore the overlay to its initial state, then draw all dialogs.
|
|
|
|
|
// This is necessary to get the blending right.
|
|
|
|
|
_system->clear_overlay();
|
|
|
|
|
_system->grab_overlay(_screen, _screen_pitch);
|
2002-08-04 01:18:06 +00:00
|
|
|
|
for (i = 0; i < _dialogStack.size(); i++)
|
|
|
|
|
_dialogStack[i]->draw();
|
2002-07-05 16:56:53 +00:00
|
|
|
|
_need_redraw = false;
|
|
|
|
|
}
|
2002-07-10 16:49:45 +00:00
|
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
|
_s->animateCursor();
|
2002-07-13 18:32:09 +00:00
|
|
|
|
|
|
|
|
|
if (_eventList.size() > 0)
|
|
|
|
|
{
|
|
|
|
|
OSystem::Event t;
|
|
|
|
|
|
2002-08-04 01:18:06 +00:00
|
|
|
|
for (i = 0; i < _eventList.size(); i++)
|
2002-07-13 18:32:09 +00:00
|
|
|
|
{
|
2002-07-15 20:11:39 +00:00
|
|
|
|
t = _eventList[i];
|
2002-07-13 18:32:09 +00:00
|
|
|
|
|
|
|
|
|
switch(t.event_code) {
|
|
|
|
|
case OSystem::EVENT_KEYDOWN:
|
|
|
|
|
activeDialog->handleKeyDown(t.kbd.ascii, t.kbd.flags);
|
2002-07-18 14:47:25 +00:00
|
|
|
|
|
|
|
|
|
// init continuous event stream
|
|
|
|
|
_currentKeyDown = t.kbd.ascii;
|
|
|
|
|
_currentKeyDownFlags = t.kbd.flags;
|
2002-07-27 14:16:14 +00:00
|
|
|
|
_keyRepeatEvenCount = 1;
|
|
|
|
|
_keyRepeatLoopCount = 0;
|
2002-07-13 18:32:09 +00:00
|
|
|
|
break;
|
2002-07-16 21:18:06 +00:00
|
|
|
|
case OSystem::EVENT_KEYUP:
|
|
|
|
|
activeDialog->handleKeyUp(t.kbd.ascii, t.kbd.flags);
|
2002-07-18 14:47:25 +00:00
|
|
|
|
if (t.kbd.ascii == _currentKeyDown)
|
|
|
|
|
// only stop firing events if it's the current key
|
|
|
|
|
_currentKeyDown = 0;
|
2002-07-13 18:32:09 +00:00
|
|
|
|
break;
|
|
|
|
|
case OSystem::EVENT_MOUSEMOVE:
|
2002-07-13 22:41:29 +00:00
|
|
|
|
activeDialog->handleMouseMoved(t.mouse.x - activeDialog->_x, t.mouse.y - activeDialog->_y, 0);
|
2002-07-13 18:32:09 +00:00
|
|
|
|
break;
|
|
|
|
|
// We don't distinguish between mousebuttons (for now at least)
|
|
|
|
|
case OSystem::EVENT_LBUTTONDOWN:
|
2002-07-27 14:16:14 +00:00
|
|
|
|
case OSystem::EVENT_RBUTTONDOWN: {
|
2002-09-19 16:06:51 +00:00
|
|
|
|
uint32 time = _system->get_msecs();
|
2002-09-08 12:56:44 +00:00
|
|
|
|
if (_lastClick.count && (time < _lastClick.time + kDoubleClickDelay)
|
2002-07-27 14:16:14 +00:00
|
|
|
|
&& ABS(_lastClick.x - t.mouse.x) < 3
|
|
|
|
|
&& ABS(_lastClick.y - t.mouse.y) < 3) {
|
|
|
|
|
_lastClick.count++;
|
|
|
|
|
} else {
|
|
|
|
|
_lastClick.x = t.mouse.x;
|
|
|
|
|
_lastClick.y = t.mouse.y;
|
|
|
|
|
_lastClick.count = 1;
|
|
|
|
|
}
|
|
|
|
|
_lastClick.time = time;
|
|
|
|
|
}
|
|
|
|
|
activeDialog->handleMouseDown(t.mouse.x - activeDialog->_x, t.mouse.y - activeDialog->_y, 1, _lastClick.count);
|
2002-07-13 18:32:09 +00:00
|
|
|
|
break;
|
|
|
|
|
case OSystem::EVENT_LBUTTONUP:
|
|
|
|
|
case OSystem::EVENT_RBUTTONUP:
|
2002-07-27 14:16:14 +00:00
|
|
|
|
activeDialog->handleMouseUp(t.mouse.x - activeDialog->_x, t.mouse.y - activeDialog->_y, 1, _lastClick.count);
|
2002-07-13 18:32:09 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_eventList.clear();
|
2002-07-05 16:56:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-18 14:47:25 +00:00
|
|
|
|
// check if event should be sent again (keydown)
|
|
|
|
|
if (_currentKeyDown != 0)
|
|
|
|
|
{
|
|
|
|
|
// if only fired once, wait longer
|
2002-07-27 14:16:14 +00:00
|
|
|
|
if ( _keyRepeatLoopCount >= ((_keyRepeatEvenCount > 1) ? 2 : 4) )
|
|
|
|
|
// ^ loops to wait first event
|
|
|
|
|
// ^ loops to wait after first event
|
2002-07-18 14:47:25 +00:00
|
|
|
|
{
|
|
|
|
|
// fire event
|
|
|
|
|
activeDialog->handleKeyDown(_currentKeyDown, _currentKeyDownFlags);
|
2002-07-27 14:16:14 +00:00
|
|
|
|
_keyRepeatEvenCount++;
|
|
|
|
|
_keyRepeatLoopCount = 0;
|
2002-07-18 14:47:25 +00:00
|
|
|
|
}
|
2002-07-27 14:16:14 +00:00
|
|
|
|
_keyRepeatLoopCount++;
|
2002-07-18 14:47:25 +00:00
|
|
|
|
}
|
2002-07-05 16:56:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
|
void NewGui::saveState()
|
|
|
|
|
{
|
2002-08-14 20:43:56 +00:00
|
|
|
|
_old_soundsPaused = _s->_sound->_soundsPaused;
|
|
|
|
|
_s->_sound->pauseSounds(true);
|
2002-07-05 16:56:53 +00:00
|
|
|
|
|
|
|
|
|
// Backup old cursor
|
|
|
|
|
memcpy(_old_grabbedCursor, _s->_grabbedCursor, sizeof(_old_grabbedCursor));
|
|
|
|
|
_old_cursorWidth = _s->_cursorWidth;
|
|
|
|
|
_old_cursorHeight = _s->_cursorHeight;
|
|
|
|
|
_old_cursorHotspotX = _s->_cursorHotspotX;
|
|
|
|
|
_old_cursorHotspotY = _s->_cursorHotspotY;
|
2002-09-19 16:06:51 +00:00
|
|
|
|
_old_cursor_mode = _system->show_mouse(true);
|
2002-07-05 16:56:53 +00:00
|
|
|
|
|
|
|
|
|
_s->_cursorAnimate++;
|
|
|
|
|
_s->gdi._cursorActive = 1;
|
2002-09-19 16:06:51 +00:00
|
|
|
|
|
|
|
|
|
// TODO - add getHeight & getWidth methods to OSystem
|
|
|
|
|
_system->show_overlay();
|
|
|
|
|
_screen = new int16[_s->_realWidth * _s->_realHeight];
|
|
|
|
|
_screen_pitch = _s->_realWidth;
|
|
|
|
|
_system->grab_overlay(_screen, _screen_pitch);
|
2002-07-05 16:56:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NewGui::restoreState()
|
|
|
|
|
{
|
|
|
|
|
_s->_cursorAnimate--;
|
|
|
|
|
|
|
|
|
|
// Restore old cursor
|
|
|
|
|
memcpy(_s->_grabbedCursor, _old_grabbedCursor, sizeof(_old_grabbedCursor));
|
|
|
|
|
_s->_cursorWidth = _old_cursorWidth;
|
|
|
|
|
_s->_cursorHeight = _old_cursorHeight;
|
|
|
|
|
_s->_cursorHotspotX = _old_cursorHotspotX;
|
|
|
|
|
_s->_cursorHotspotY = _old_cursorHotspotY;
|
|
|
|
|
_s->updateCursor();
|
|
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
|
_system->show_mouse(_old_cursor_mode);
|
2002-07-05 16:56:53 +00:00
|
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
|
_s->_sound->pauseSounds(_old_soundsPaused);
|
2002-09-19 16:06:51 +00:00
|
|
|
|
|
|
|
|
|
_system->hide_overlay();
|
|
|
|
|
if (_screen) {
|
|
|
|
|
delete _screen;
|
|
|
|
|
_screen = 0;
|
|
|
|
|
}
|
2002-07-05 16:56:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-07 21:46:53 +00:00
|
|
|
|
void NewGui::openDialog(Dialog *dialog)
|
|
|
|
|
{
|
2002-07-10 16:49:45 +00:00
|
|
|
|
if (_dialogStack.empty())
|
|
|
|
|
_prepare_for_gui = true;
|
|
|
|
|
|
2002-07-07 21:46:53 +00:00
|
|
|
|
_dialogStack.push(dialog);
|
|
|
|
|
_need_redraw = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NewGui::closeTopDialog()
|
|
|
|
|
{
|
2002-07-10 16:49:45 +00:00
|
|
|
|
// Don't do anything if no dialog is open
|
|
|
|
|
if (_dialogStack.empty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Remove the dialog from the stack
|
2002-07-07 21:46:53 +00:00
|
|
|
|
_dialogStack.pop();
|
|
|
|
|
if (_dialogStack.empty())
|
|
|
|
|
restoreState();
|
|
|
|
|
else
|
2002-07-10 16:49:45 +00:00
|
|
|
|
_need_redraw = true;
|
2002-07-07 21:46:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-07 23:37:47 +00:00
|
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
|
#pragma mark -
|
|
|
|
|
|
2002-07-07 23:37:47 +00:00
|
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
|
int16 *NewGui::getBasePtr(int x, int y)
|
2002-07-05 16:56:53 +00:00
|
|
|
|
{
|
2002-09-19 16:06:51 +00:00
|
|
|
|
return _screen + x + y * _screen_pitch;
|
2002-07-05 16:56:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NewGui::box(int x, int y, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
hline(x + 1, y, x + width - 2, _color);
|
|
|
|
|
hline(x, y + 1, x + width - 1, _color);
|
|
|
|
|
vline(x, y + 1, y + height - 2, _color);
|
|
|
|
|
vline(x + 1, y, y + height - 1, _color);
|
|
|
|
|
|
|
|
|
|
hline(x + 1, y + height - 2, x + width - 1, _shadowcolor);
|
|
|
|
|
hline(x + 1, y + height - 1, x + width - 2, _shadowcolor);
|
|
|
|
|
vline(x + width - 1, y + 1, y + height - 2, _shadowcolor);
|
|
|
|
|
vline(x + width - 2, y + 1, y + height - 1, _shadowcolor);
|
|
|
|
|
}
|
|
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
|
void NewGui::line(int x, int y, int x2, int y2, int16 color)
|
2002-07-05 16:56:53 +00:00
|
|
|
|
{
|
2002-09-19 16:06:51 +00:00
|
|
|
|
int16 *ptr;
|
2002-07-07 13:14:34 +00:00
|
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
|
if (x2 < x)
|
2002-07-07 13:14:34 +00:00
|
|
|
|
x2 ^= x ^= x2 ^= x; // Swap x2 and x
|
2002-07-05 16:56:53 +00:00
|
|
|
|
|
|
|
|
|
if (y2 < y)
|
2002-07-07 13:14:34 +00:00
|
|
|
|
y2 ^= y ^= y2 ^= y; // Swap y2 and y
|
2002-07-05 16:56:53 +00:00
|
|
|
|
|
|
|
|
|
ptr = getBasePtr(x, y);
|
|
|
|
|
|
|
|
|
|
if (ptr == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (x == x2) {
|
|
|
|
|
/* vertical line */
|
|
|
|
|
while (y++ <= y2) {
|
|
|
|
|
*ptr = color;
|
2002-09-19 16:06:51 +00:00
|
|
|
|
ptr += _screen_pitch;
|
2002-07-05 16:56:53 +00:00
|
|
|
|
}
|
|
|
|
|
} else if (y == y2) {
|
|
|
|
|
/* horizontal line */
|
|
|
|
|
while (x++ <= x2) {
|
|
|
|
|
*ptr++ = color;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
|
void NewGui::blendRect(int x, int y, int w, int h, int16 color)
|
2002-07-10 16:49:45 +00:00
|
|
|
|
{
|
2002-09-19 21:45:56 +00:00
|
|
|
|
int r = RED_FROM_16(color) * 3;
|
|
|
|
|
int g = GREEN_FROM_16(color) * 3;
|
|
|
|
|
int b = BLUE_FROM_16(color) * 3;
|
2002-09-19 16:06:51 +00:00
|
|
|
|
int16 *ptr = getBasePtr(x, y);
|
2002-07-10 16:49:45 +00:00
|
|
|
|
if (ptr == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
while (h--) {
|
|
|
|
|
for (int i = 0; i < w; i++) {
|
2002-09-19 21:45:56 +00:00
|
|
|
|
ptr[i] = RGB_TO_16((RED_FROM_16(ptr[i])+r)/4,
|
|
|
|
|
(GREEN_FROM_16(ptr[i])+g)/4,
|
|
|
|
|
(BLUE_FROM_16(ptr[i])+b)/4);
|
2002-07-10 16:49:45 +00:00
|
|
|
|
}
|
2002-09-19 16:06:51 +00:00
|
|
|
|
ptr += _screen_pitch;
|
2002-07-10 16:49:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
|
void NewGui::fillRect(int x, int y, int w, int h, int16 color)
|
2002-07-05 16:56:53 +00:00
|
|
|
|
{
|
2002-09-19 16:06:51 +00:00
|
|
|
|
int i;
|
|
|
|
|
int16 *ptr = getBasePtr(x, y);
|
2002-07-05 16:56:53 +00:00
|
|
|
|
if (ptr == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
while (h--) {
|
2002-09-19 16:06:51 +00:00
|
|
|
|
for (i = 0; i < w; i++) {
|
2002-07-10 16:49:45 +00:00
|
|
|
|
ptr[i] = color;
|
2002-07-09 12:33:09 +00:00
|
|
|
|
}
|
2002-09-19 16:06:51 +00:00
|
|
|
|
ptr += _screen_pitch;
|
2002-07-05 16:56:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
|
void NewGui::checkerRect(int x, int y, int w, int h, int16 color)
|
2002-07-12 16:24:11 +00:00
|
|
|
|
{
|
2002-09-19 16:06:51 +00:00
|
|
|
|
int i;
|
|
|
|
|
int16 *ptr = getBasePtr(x, y);
|
2002-07-12 16:24:11 +00:00
|
|
|
|
if (ptr == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
while (h--) {
|
2002-09-19 16:06:51 +00:00
|
|
|
|
for (i = 0; i < w; i++) {
|
2002-07-12 16:24:11 +00:00
|
|
|
|
if ((h ^ i) & 1)
|
|
|
|
|
ptr[i] = color;
|
|
|
|
|
}
|
2002-09-19 16:06:51 +00:00
|
|
|
|
ptr += _screen_pitch;
|
2002-07-12 16:24:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
|
void NewGui::frameRect(int x, int y, int w, int h, int16 color)
|
2002-07-10 22:49:41 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
2002-09-19 16:06:51 +00:00
|
|
|
|
int16 *ptr, *basePtr = getBasePtr(x, y);
|
2002-07-10 22:49:41 +00:00
|
|
|
|
if (basePtr == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ptr = basePtr;
|
|
|
|
|
for (i = 0; i < w; i++, ptr++)
|
|
|
|
|
*ptr = color;
|
|
|
|
|
ptr--;
|
2002-09-19 16:06:51 +00:00
|
|
|
|
for (i = 0; i < h; i++, ptr += _screen_pitch)
|
2002-07-10 22:49:41 +00:00
|
|
|
|
*ptr = color;
|
|
|
|
|
ptr = basePtr;
|
2002-09-19 16:06:51 +00:00
|
|
|
|
for (i = 0; i < h; i++, ptr += _screen_pitch)
|
2002-07-10 22:49:41 +00:00
|
|
|
|
*ptr = color;
|
2002-09-19 16:06:51 +00:00
|
|
|
|
ptr -= _screen_pitch;
|
2002-07-10 22:49:41 +00:00
|
|
|
|
for (i = 0; i < w; i++, ptr++)
|
|
|
|
|
*ptr = color;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NewGui::addDirtyRect(int x, int y, int w, int h)
|
2002-07-08 00:10:11 +00:00
|
|
|
|
{
|
2002-09-19 16:06:51 +00:00
|
|
|
|
// For now we don't keep yet another list of dirty rects but simply
|
|
|
|
|
// blit the affected area directly to the overlay. At least for our current
|
|
|
|
|
// GUI/widget/dialog code that is just fine.
|
|
|
|
|
int16 *buf = getBasePtr(x, y);
|
|
|
|
|
_system->copy_rect_overlay(buf, _screen_pitch, x, y, w, h);
|
2002-07-08 00:10:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
|
void NewGui::drawChar(const char str, int xx, int yy, int16 color)
|
2002-07-05 16:56:53 +00:00
|
|
|
|
{
|
|
|
|
|
unsigned int buffer = 0, mask = 0, x, y;
|
|
|
|
|
byte *tmp;
|
|
|
|
|
|
|
|
|
|
tmp = &guifont[0];
|
|
|
|
|
tmp += 224 + (str + 1) * 8;
|
|
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
|
int16 *ptr = getBasePtr(xx, yy);
|
2002-07-05 16:56:53 +00:00
|
|
|
|
if (ptr == NULL)
|
2002-07-07 13:14:34 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
|
for (y = 0; y < 8; y++) {
|
|
|
|
|
for (x = 0; x < 8; x++) {
|
2002-09-19 16:06:51 +00:00
|
|
|
|
unsigned char c;
|
2002-07-05 16:56:53 +00:00
|
|
|
|
if ((mask >>= 1) == 0) {
|
|
|
|
|
buffer = *tmp++;
|
|
|
|
|
mask = 0x80;
|
|
|
|
|
}
|
2002-09-19 16:06:51 +00:00
|
|
|
|
c = ((buffer & mask) != 0);
|
|
|
|
|
if (c)
|
|
|
|
|
ptr[x] = color;
|
2002-07-05 16:56:53 +00:00
|
|
|
|
}
|
2002-09-19 16:06:51 +00:00
|
|
|
|
ptr += _screen_pitch;
|
2002-07-05 16:56:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-07-07 23:37:47 +00:00
|
|
|
|
|
2002-09-19 17:03:24 +00:00
|
|
|
|
int NewGui::getStringWidth(const char *str)
|
|
|
|
|
{
|
|
|
|
|
int space = 0;
|
|
|
|
|
while (*str)
|
|
|
|
|
space += getCharWidth(*str++);
|
|
|
|
|
return space;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int NewGui::getCharWidth(char c)
|
|
|
|
|
{
|
|
|
|
|
int space;
|
|
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
|
case '.':
|
|
|
|
|
case ':':
|
|
|
|
|
case '\'':
|
|
|
|
|
case '!':
|
|
|
|
|
space = 3;
|
|
|
|
|
break;
|
|
|
|
|
case 'I':
|
|
|
|
|
case 'i':
|
|
|
|
|
case 'l':
|
|
|
|
|
space = 5;
|
|
|
|
|
break;
|
|
|
|
|
case ';':
|
|
|
|
|
case ' ':
|
|
|
|
|
space = 4;
|
|
|
|
|
break;
|
|
|
|
|
case '(':
|
|
|
|
|
case ')':
|
|
|
|
|
space = 5;
|
|
|
|
|
break;
|
|
|
|
|
case 'c':
|
|
|
|
|
space = 6;
|
|
|
|
|
break;
|
|
|
|
|
case '4':
|
|
|
|
|
case '/':
|
|
|
|
|
case 'W':
|
|
|
|
|
case 'w':
|
|
|
|
|
case 'M':
|
|
|
|
|
case 'm':
|
|
|
|
|
space = 8;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
space = 7;
|
|
|
|
|
}
|
|
|
|
|
return space;
|
|
|
|
|
}
|
|
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
|
void NewGui::drawString(const char *str, int x, int y, int w, int16 color, int align)
|
2002-07-05 16:56:53 +00:00
|
|
|
|
{
|
2002-09-19 17:03:24 +00:00
|
|
|
|
int width = getStringWidth(str);
|
|
|
|
|
if (align == kTextAlignCenter)
|
|
|
|
|
x = x + (w - width - 1)/2;
|
|
|
|
|
else if (align == kTextAlignRight)
|
|
|
|
|
x = x + w - width;
|
|
|
|
|
while (*str) {
|
|
|
|
|
drawChar(*str, x, y, color);
|
|
|
|
|
x += getCharWidth(*str);
|
|
|
|
|
str++;
|
2002-07-05 16:56:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-07-07 23:37:47 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Draw an 8x8 bitmap at location (x,y)
|
|
|
|
|
*/
|
2002-09-19 16:06:51 +00:00
|
|
|
|
void NewGui::drawBitmap(uint32 bitmap[8], int x, int y, int16 color)
|
2002-07-07 23:37:47 +00:00
|
|
|
|
{
|
2002-09-19 16:06:51 +00:00
|
|
|
|
int16 *ptr = getBasePtr(x, y);
|
2002-07-07 23:37:47 +00:00
|
|
|
|
if (ptr == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (int y2 = 0; y2 < 8; y2++) {
|
|
|
|
|
uint32 mask = 0xF0000000;
|
|
|
|
|
for (int x2 = 0; x2 < 8; x2++) {
|
|
|
|
|
if (bitmap[y2] & mask)
|
|
|
|
|
ptr[x2] = color;
|
|
|
|
|
mask >>= 4;
|
|
|
|
|
}
|
2002-09-19 16:06:51 +00:00
|
|
|
|
ptr += _screen_pitch;
|
2002-07-10 16:49:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|