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"
|
|
|
|
#include "scumm.h"
|
|
|
|
#include "newgui.h"
|
|
|
|
#include "guimaps.h"
|
|
|
|
#include "gui/dialog.h"
|
|
|
|
|
|
|
|
#define hline(x, y, x2, color) line(x, y, x2, y, color);
|
|
|
|
#define vline(x, y, y2, color) line(x, y, x, y2, color);
|
|
|
|
|
2002-07-09 12:33:09 +00:00
|
|
|
// 8-bit alpha blending routines
|
|
|
|
int BlendCache[256][256];
|
|
|
|
|
|
|
|
int RGBMatch(byte *palette, int r, int g, int b) {
|
|
|
|
int i, bestidx = 0, besterr = 0xFFFFFF;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
for (i = 0;i < 256;i++) {
|
|
|
|
byte *pal = palette + (i * 3);
|
|
|
|
int r_diff = r - (int)*pal++;
|
|
|
|
int g_diff = g - (int)*pal++;
|
|
|
|
int b_diff = b - (int)*pal++;
|
|
|
|
r_diff *= r_diff; g_diff *= g_diff; b_diff *= b_diff;
|
|
|
|
|
|
|
|
error = r_diff + g_diff + b_diff;
|
|
|
|
if (error < besterr) {
|
|
|
|
besterr = error;
|
|
|
|
bestidx = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bestidx;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Blend(int src, int dst, byte *palette) {
|
|
|
|
int r, g, b, idx;
|
|
|
|
int alpha = 128; // Level of transparency [0-256]
|
|
|
|
byte *srcpal = palette + (dst * 3);
|
|
|
|
byte *dstpal = palette + (src * 3);
|
|
|
|
|
|
|
|
if (BlendCache[dst][src] > -1)
|
|
|
|
return BlendCache[dst][src];
|
|
|
|
|
|
|
|
r = (*srcpal++ * alpha);
|
|
|
|
r += (*dstpal++ * (256-alpha));
|
|
|
|
r /= 256;
|
|
|
|
|
|
|
|
g = (*srcpal++ * alpha);
|
|
|
|
g += (*dstpal++ * (256-alpha));
|
|
|
|
g /= 256;
|
|
|
|
|
|
|
|
b = (*srcpal++ * alpha);
|
|
|
|
b += (*dstpal++ * (256-alpha));
|
|
|
|
b /= 256;
|
|
|
|
|
|
|
|
return (BlendCache[dst][src] = RGBMatch(palette, r , g , b ));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearBlendCache(byte *palette, int weight) {
|
|
|
|
for (int i = 0; i < 256; i++)
|
|
|
|
for (int j = 0 ; j < 256 ; j++)
|
|
|
|
// BlendCache[i][j] = i; // No alphablending
|
|
|
|
// BlendCache[i][j] = j; // 100% translucent
|
|
|
|
BlendCache[i][j] = -1; // Enable alphablending
|
|
|
|
}
|
2002-07-05 16:56:53 +00:00
|
|
|
|
2002-07-07 22:44:30 +00:00
|
|
|
/*
|
|
|
|
* TODO list
|
2002-07-09 12:38:50 +00:00
|
|
|
* - keep a copy of the original game background, for alpha/moving
|
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
|
|
|
* - add support for right/center aligned text
|
|
|
|
* - 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-07-08 00:10:11 +00:00
|
|
|
NewGui::NewGui(Scumm *s) : _s(s), _need_redraw(false), _pauseDialog(0),
|
|
|
|
_saveLoadDialog(0), _aboutDialog(0), _optionsDialog(0)
|
2002-07-09 12:33:09 +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-07 21:46:53 +00:00
|
|
|
openDialog(_pauseDialog);
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NewGui::saveloadDialog()
|
|
|
|
{
|
2002-07-09 12:33:09 +00:00
|
|
|
ClearBlendCache(_s->_currentPalette, 128);
|
2002-07-08 00:10:11 +00:00
|
|
|
if (!_saveLoadDialog)
|
|
|
|
_saveLoadDialog = new SaveLoadDialog(this);
|
2002-07-07 21:46:53 +00:00
|
|
|
openDialog(_saveLoadDialog);
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 22:44:30 +00:00
|
|
|
void NewGui::aboutDialog()
|
|
|
|
{
|
2002-07-08 00:10:11 +00:00
|
|
|
// if (!_aboutDialog)
|
|
|
|
// _aboutDialog = new AboutDialog(this);
|
2002-07-07 22:44:30 +00:00
|
|
|
// openDialog(_aboutDialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewGui::optionsDialog()
|
|
|
|
{
|
2002-07-08 00:10:11 +00:00
|
|
|
if (!_optionsDialog)
|
|
|
|
_optionsDialog = new OptionsDialog(this);
|
2002-07-07 22:44:30 +00:00
|
|
|
openDialog(_optionsDialog);
|
|
|
|
}
|
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
void NewGui::loop()
|
|
|
|
{
|
2002-07-07 21:46:53 +00:00
|
|
|
Dialog *activeDialog = _dialogStack.top();
|
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
if (_need_redraw) {
|
2002-07-07 21:46:53 +00:00
|
|
|
activeDialog->draw();
|
2002-07-05 16:56:53 +00:00
|
|
|
saveState();
|
|
|
|
_need_redraw = false;
|
|
|
|
}
|
|
|
|
_s->animateCursor();
|
|
|
|
_s->getKeyInput(0);
|
2002-07-08 13:52:50 +00:00
|
|
|
if (_s->_mouseButStat & MBS_LEFT_CLICK) {
|
2002-07-07 21:46:53 +00:00
|
|
|
activeDialog->handleClick(_s->mouse.x, _s->mouse.y, _s->_mouseButStat);
|
2002-07-05 16:56:53 +00:00
|
|
|
} else if (_s->_lastKeyHit) {
|
2002-07-07 21:46:53 +00:00
|
|
|
activeDialog->handleKey(_s->_lastKeyHit, 0);
|
2002-07-06 12:57:51 +00:00
|
|
|
} else if (_old_mouse.x != _s->mouse.x || _old_mouse.y != _s->mouse.y) {
|
2002-07-08 13:52:50 +00:00
|
|
|
activeDialog->handleMouseMoved(_s->mouse.x, _s->mouse.y, _s->_leftBtnPressed);
|
2002-07-06 12:57:51 +00:00
|
|
|
_old_mouse.x = _s->mouse.x;
|
|
|
|
_old_mouse.y = _s->mouse.y;
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_s->drawDirtyScreenParts();
|
|
|
|
_s->_mouseButStat = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
void NewGui::saveState()
|
|
|
|
{
|
|
|
|
_old_soundsPaused = _s->_soundsPaused;
|
|
|
|
_s->pauseSounds(true);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
_old_cursor_mode = _s->_system->show_mouse(true);
|
|
|
|
|
|
|
|
_s->_cursorAnimate++;
|
|
|
|
_s->gdi._cursorActive = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
_s->_system->show_mouse(_old_cursor_mode);
|
|
|
|
|
|
|
|
_s->pauseSounds(_old_soundsPaused);
|
|
|
|
}
|
|
|
|
|
2002-07-07 21:46:53 +00:00
|
|
|
void NewGui::openDialog(Dialog *dialog)
|
|
|
|
{
|
|
|
|
_dialogStack.push(dialog);
|
|
|
|
_need_redraw = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewGui::closeTopDialog()
|
|
|
|
{
|
|
|
|
_dialogStack.pop();
|
|
|
|
if (_dialogStack.empty())
|
|
|
|
restoreState();
|
|
|
|
else
|
|
|
|
_dialogStack.top()->draw();
|
|
|
|
}
|
|
|
|
|
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-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-07-08 00:10:11 +00:00
|
|
|
byte *NewGui::getBasePtr(int x, int y)
|
2002-07-05 16:56:53 +00:00
|
|
|
{
|
2002-07-08 00:10:11 +00:00
|
|
|
VirtScreen *vs = _s->findVirtScreen(y);
|
2002-07-05 16:56:53 +00:00
|
|
|
|
|
|
|
if (vs == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return vs->screenPtr + x + (y - vs->topline) * 320 +
|
2002-07-07 13:14:34 +00:00
|
|
|
_s->_screenStartStrip * 8 + (_s->camera._cur.y - 100) * 320;
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewGui::line(int x, int y, int x2, int y2, byte color)
|
|
|
|
{
|
|
|
|
byte *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;
|
|
|
|
ptr += 320;
|
|
|
|
}
|
|
|
|
} else if (y == y2) {
|
|
|
|
/* horizontal line */
|
|
|
|
while (x++ <= x2) {
|
|
|
|
*ptr++ = color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-08 22:11:47 +00:00
|
|
|
void NewGui::fillArea(int x, int y, int w, int h, byte color)
|
2002-07-05 16:56:53 +00:00
|
|
|
{
|
2002-07-08 00:10:11 +00:00
|
|
|
byte *ptr = getBasePtr(x, y);
|
2002-07-05 16:56:53 +00:00
|
|
|
if (ptr == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (h--) {
|
2002-07-09 12:33:09 +00:00
|
|
|
for (int i = 0; i < w; i++) {
|
|
|
|
int srcc = ptr[i];
|
|
|
|
ptr[i] = Blend(srcc, color, _s->_currentPalette);
|
|
|
|
}
|
|
|
|
//ptr[i] = color;
|
2002-07-05 16:56:53 +00:00
|
|
|
ptr += 320;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-08 00:10:11 +00:00
|
|
|
void NewGui::setAreaDirty(int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
VirtScreen *vs = _s->findVirtScreen(y);
|
|
|
|
|
|
|
|
if (vs != NULL)
|
|
|
|
_s->setVirtscreenDirty(vs, x, y, x + w, y + h);
|
|
|
|
}
|
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
void NewGui::drawChar(const char str, int xx, int yy)
|
|
|
|
{
|
|
|
|
unsigned int buffer = 0, mask = 0, x, y;
|
|
|
|
byte *tmp;
|
|
|
|
int tempc = _color;
|
|
|
|
_color = _textcolor;
|
|
|
|
|
|
|
|
tmp = &guifont[0];
|
|
|
|
tmp += 224 + (str + 1) * 8;
|
|
|
|
|
|
|
|
byte *ptr = getBasePtr(xx, yy);
|
|
|
|
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++) {
|
|
|
|
unsigned char color;
|
|
|
|
if ((mask >>= 1) == 0) {
|
|
|
|
buffer = *tmp++;
|
|
|
|
mask = 0x80;
|
|
|
|
}
|
|
|
|
color = ((buffer & mask) != 0);
|
|
|
|
if (color)
|
|
|
|
ptr[x] = _color;
|
|
|
|
}
|
|
|
|
ptr += 320;
|
|
|
|
}
|
|
|
|
_color = tempc;
|
|
|
|
|
|
|
|
}
|
2002-07-07 23:37:47 +00:00
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
void NewGui::drawString(const char *str, int x, int y, int w, byte color)
|
|
|
|
{
|
|
|
|
StringTab *st = &_s->string[5];
|
|
|
|
st->charset = 1;
|
|
|
|
st->center = false;
|
|
|
|
st->color = color;
|
|
|
|
st->xpos = x;
|
|
|
|
st->ypos = y;
|
|
|
|
st->right = x + w;
|
|
|
|
|
|
|
|
if (_s->_gameId) { /* If a game is active.. */
|
|
|
|
_s->_messagePtr = (byte *)str;
|
|
|
|
_s->drawString(5);
|
|
|
|
} else {
|
|
|
|
uint len = strlen(str);
|
|
|
|
for (uint letter = 0; letter < len; letter++)
|
|
|
|
drawChar(str[letter], st->xpos + (letter * 8), st->ypos);
|
|
|
|
}
|
|
|
|
}
|
2002-07-07 23:37:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Draw an 8x8 bitmap at location (x,y)
|
|
|
|
*/
|
|
|
|
void NewGui::drawBitmap(uint32 bitmap[8], int x, int y, byte color)
|
|
|
|
{
|
2002-07-08 00:10:11 +00:00
|
|
|
byte *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;
|
|
|
|
}
|
|
|
|
ptr += 320;
|
|
|
|
}
|
|
|
|
}
|