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"
|
|
|
|
#include "guimaps.h"
|
2002-08-29 23:45:15 +00:00
|
|
|
#include "dialog.h"
|
2002-07-05 16:56:53 +00:00
|
|
|
|
2002-07-07 22:44:30 +00:00
|
|
|
/*
|
|
|
|
* TODO list
|
2002-09-19 17:03:24 +00:00
|
|
|
* - use a nice font
|
2002-07-08 01:04:29 +00:00
|
|
|
* - implement the missing / incomplete dialogs
|
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-07-09 12:38:50 +00:00
|
|
|
* - come up with a new look&feel / theme for the GUI
|
2002-07-07 22:44:30 +00:00
|
|
|
* - ...
|
|
|
|
*/
|
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
|
|
|
|
NewGui::NewGui(Scumm *s) : _s(s), _system(s->_system), _screen(0),
|
|
|
|
_use_alpha_blending(true), _need_redraw(false),_prepare_for_gui(true),
|
2002-07-18 14:47:25 +00:00
|
|
|
_pauseDialog(0), _saveLoadDialog(0), _aboutDialog(0), _optionsDialog(0),
|
|
|
|
_currentKeyDown(0)
|
2002-09-19 16:06:51 +00:00
|
|
|
{
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NewGui::pauseDialog()
|
|
|
|
{
|
2002-07-08 00:10:11 +00:00
|
|
|
if (!_pauseDialog)
|
|
|
|
_pauseDialog = new PauseDialog(this);
|
2002-07-26 20:38:55 +00:00
|
|
|
_pauseDialog->open();
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NewGui::saveloadDialog()
|
|
|
|
{
|
2002-07-08 00:10:11 +00:00
|
|
|
if (!_saveLoadDialog)
|
2002-09-19 16:06:51 +00:00
|
|
|
_saveLoadDialog = new SaveLoadDialog(this, _s);
|
2002-07-26 20:38:55 +00:00
|
|
|
_saveLoadDialog->open();
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 22:44:30 +00:00
|
|
|
void NewGui::aboutDialog()
|
|
|
|
{
|
2002-07-19 10:10:02 +00:00
|
|
|
if (!_aboutDialog)
|
|
|
|
_aboutDialog = new AboutDialog(this);
|
2002-07-26 20:38:55 +00:00
|
|
|
_aboutDialog->open();
|
2002-07-07 22:44:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NewGui::optionsDialog()
|
|
|
|
{
|
2002-07-08 00:10:11 +00:00
|
|
|
if (!_optionsDialog)
|
|
|
|
_optionsDialog = new OptionsDialog(this);
|
2002-07-26 20:38:55 +00:00
|
|
|
_optionsDialog->open();
|
2002-07-07 22:44:30 +00:00
|
|
|
}
|
|
|
|
|
2002-07-26 00:41:07 +00:00
|
|
|
void NewGui::soundDialog()
|
|
|
|
{
|
|
|
|
if (!_soundDialog)
|
2002-09-19 16:06:51 +00:00
|
|
|
_soundDialog = new SoundDialog(this, _s);
|
2002-07-26 20:38:55 +00:00
|
|
|
_soundDialog->open();
|
2002-07-26 00:41:07 +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
|
|
|
|
|
|
|
// Setup some default GUI colors
|
|
|
|
_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, 192, 32);
|
|
|
|
_textcolorhi = RGB_TO_16(0, 255, 0);
|
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
|
|
|
_s->drawDirtyScreenParts();
|
|
|
|
}
|
|
|
|
|
|
|
|
#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->_fullRedraw = true;
|
|
|
|
_s->_completeScreenRedraw = true;
|
|
|
|
_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-05 16:56:53 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2002-07-07 22:44:30 +00:00
|
|
|
const char *NewGui::queryResString(int stringno)
|
2002-07-05 16:56:53 +00:00
|
|
|
{
|
|
|
|
char *result;
|
|
|
|
int string;
|
|
|
|
|
|
|
|
if (stringno == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (_s->_features & GF_AFTER_V7)
|
|
|
|
string = _s->_vars[string_map_table_v7[stringno - 1].num];
|
|
|
|
else if (_s->_features & GF_AFTER_V6)
|
|
|
|
string = _s->_vars[string_map_table_v6[stringno - 1].num];
|
|
|
|
else
|
|
|
|
string = string_map_table_v5[stringno - 1].num;
|
|
|
|
|
|
|
|
result = (char *)_s->getStringAddress(string);
|
2002-09-17 16:12:16 +00:00
|
|
|
if (result && *result == '/') {
|
|
|
|
_s->translateText((char*)result, (char*)&_s->transText);
|
|
|
|
strcpy((char*)result, (char*)&_s->transText);
|
|
|
|
}
|
2002-07-05 16:56:53 +00:00
|
|
|
|
2002-07-07 13:14:34 +00:00
|
|
|
if (!result) { // Gracelessly degrade to english :)
|
2002-07-05 16:56:53 +00:00
|
|
|
if (_s->_features & GF_AFTER_V6)
|
|
|
|
return string_map_table_v6[stringno - 1].string;
|
|
|
|
else
|
|
|
|
return string_map_table_v5[stringno - 1].string;
|
|
|
|
}
|
2002-07-07 13:14:34 +00:00
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-07-07 22:44:30 +00:00
|
|
|
const char *NewGui::queryCustomString(int stringno)
|
|
|
|
{
|
|
|
|
return string_map_table_custom[stringno];
|
|
|
|
}
|
|
|
|
|
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 17:03:24 +00:00
|
|
|
int r = RED_FROM_16(color) * 2;
|
|
|
|
int g = GREEN_FROM_16(color) * 2;
|
|
|
|
int b = BLUE_FROM_16(color) * 2;
|
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 17:03:24 +00:00
|
|
|
ptr[i] = RGB_TO_16((RED_FROM_16(ptr[i])+r)/3,
|
|
|
|
(GREEN_FROM_16(ptr[i])+g)/3,
|
|
|
|
(BLUE_FROM_16(ptr[i])+b)/3);
|
2002-09-19 16:06:51 +00:00
|
|
|
// ptr[i] = color;
|
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
|
|
|
}
|
|
|
|
}
|