2002-07-05 16:56:53 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2005-01-01 16:09:25 +00:00
|
|
|
* Copyright (C) 2002-2005 The ScummVM project
|
2002-07-05 16:56:53 +00:00
|
|
|
*
|
|
|
|
* 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"
|
2003-08-01 12:21:04 +00:00
|
|
|
#include "common/util.h"
|
2004-03-13 13:03:25 +00:00
|
|
|
#include "gui/newgui.h"
|
|
|
|
#include "gui/dialog.h"
|
2003-11-19 23:46:39 +00:00
|
|
|
|
|
|
|
|
2004-12-28 20:29:42 +00:00
|
|
|
DECLARE_SINGLETON(GUI::NewGui);
|
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
2002-07-07 22:44:30 +00:00
|
|
|
/*
|
|
|
|
* TODO list
|
2002-09-22 04:03:45 +00:00
|
|
|
* - add more widgets: edit field, popup, radio buttons, ...
|
|
|
|
*
|
|
|
|
* Other ideas:
|
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" ?
|
2005-01-06 19:09:34 +00:00
|
|
|
* - come up with a new look & feel / theme for the GUI
|
2002-07-07 22:44:30 +00:00
|
|
|
* - ...
|
|
|
|
*/
|
|
|
|
|
2002-09-30 12:56:59 +00:00
|
|
|
enum {
|
2003-03-06 19:52:54 +00:00
|
|
|
kDoubleClickDelay = 500, // milliseconds
|
2003-08-28 19:20:30 +00:00
|
|
|
kCursorAnimateDelay = 250,
|
2002-09-30 12:56:59 +00:00
|
|
|
kKeyRepeatInitialDelay = 400,
|
2002-12-25 00:48:13 +00:00
|
|
|
kKeyRepeatSustainDelay = 100
|
2002-09-30 12:56:59 +00:00
|
|
|
};
|
|
|
|
|
2003-11-19 23:46:39 +00:00
|
|
|
|
2002-09-19 17:44:41 +00:00
|
|
|
// Constructor
|
2005-01-06 19:09:34 +00:00
|
|
|
NewGui::NewGui() : _scaleEnable(true), _needRedraw(false),
|
2005-01-06 21:15:52 +00:00
|
|
|
_stateIsSaved(false), _font(0), _cursorAnimateCounter(0), _cursorAnimateTimer(0) {
|
2005-01-06 19:09:34 +00:00
|
|
|
|
2005-01-01 18:53:47 +00:00
|
|
|
_system = &OSystem::instance();
|
2003-11-02 02:18:16 +00:00
|
|
|
|
2002-09-19 23:06:54 +00:00
|
|
|
// Clear the cursor
|
|
|
|
memset(_cursor, 0xFF, sizeof(_cursor));
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-11-22 14:02:54 +00:00
|
|
|
// Reset key repeat
|
|
|
|
_currentKeyDown.keycode = 0;
|
2005-01-06 19:09:34 +00:00
|
|
|
|
|
|
|
// updates the scaling factor
|
|
|
|
updateScaleFactor();
|
2002-07-07 22:44:30 +00:00
|
|
|
}
|
|
|
|
|
2003-09-06 20:21:54 +00:00
|
|
|
void NewGui::updateColors() {
|
|
|
|
// Setup some default GUI colors.
|
|
|
|
_bgcolor = _system->RGBToColor(0, 0, 0);
|
2003-11-03 01:16:29 +00:00
|
|
|
_color = _system->RGBToColor(104, 104, 104);
|
2003-09-06 20:21:54 +00:00
|
|
|
_shadowcolor = _system->RGBToColor(64, 64, 64);
|
|
|
|
_textcolor = _system->RGBToColor(32, 160, 32);
|
|
|
|
_textcolorhi = _system->RGBToColor(0, 255, 0);
|
|
|
|
}
|
|
|
|
|
2005-01-06 19:09:34 +00:00
|
|
|
void NewGui::updateScaleFactor() {
|
|
|
|
if(!_scaleEnable) {
|
|
|
|
_scaleFactor = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kDefaultGUIWidth = 320,
|
|
|
|
kDefaultGUIHeight = 200
|
|
|
|
};
|
|
|
|
|
|
|
|
_scaleFactor = MIN(_system->getWidth() / kDefaultGUIWidth, _system->getHeight() / kDefaultGUIHeight);
|
2005-01-06 21:15:52 +00:00
|
|
|
|
2005-01-06 22:48:42 +00:00
|
|
|
// Pick the font depending on the scale factor.
|
|
|
|
if (_scaleFactor == 1)
|
|
|
|
_font = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont);
|
|
|
|
else
|
|
|
|
_font = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
|
2005-01-06 19:09:34 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void NewGui::runLoop() {
|
2002-10-16 17:37:30 +00:00
|
|
|
Dialog *activeDialog = _dialogStack.top();
|
|
|
|
bool didSaveState = false;
|
2002-07-26 19:41:20 +00:00
|
|
|
|
2002-10-16 17:37:30 +00:00
|
|
|
if (activeDialog == 0)
|
|
|
|
return;
|
2005-01-06 19:09:34 +00:00
|
|
|
|
2003-09-06 20:21:54 +00:00
|
|
|
// Setup some default GUI colors. Normally this will be done whenever an
|
2003-11-19 23:46:39 +00:00
|
|
|
// EVENT_SCREEN_CHANGED is received. However, not yet all backends support
|
|
|
|
// that event, so we also do it "manually" whenever a run loop is entered.
|
2003-09-06 20:21:54 +00:00
|
|
|
updateColors();
|
2005-01-06 19:09:34 +00:00
|
|
|
updateScaleFactor();
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-10-16 17:37:30 +00:00
|
|
|
if (!_stateIsSaved) {
|
|
|
|
saveState();
|
|
|
|
didSaveState = true;
|
|
|
|
}
|
2002-07-13 22:41:29 +00:00
|
|
|
|
2002-12-25 00:46:34 +00:00
|
|
|
while (!_dialogStack.empty() && activeDialog == _dialogStack.top()) {
|
2002-09-22 04:03:45 +00:00
|
|
|
activeDialog->handleTickle();
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-09-28 16:19:28 +00:00
|
|
|
if (_needRedraw) {
|
2002-09-22 04:03:45 +00:00
|
|
|
// Restore the overlay to its initial state, then draw all dialogs.
|
|
|
|
// This is necessary to get the blending right.
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->clearOverlay();
|
|
|
|
_system->grabOverlay((OverlayColor *)_screen.pixels, _screenPitch);
|
2002-10-16 17:37:30 +00:00
|
|
|
for (int i = 0; i < _dialogStack.size(); i++)
|
2002-11-10 19:39:32 +00:00
|
|
|
_dialogStack[i]->drawDialog();
|
2002-09-28 16:19:28 +00:00
|
|
|
_needRedraw = false;
|
2002-09-22 04:03:45 +00:00
|
|
|
}
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-09-22 04:03:45 +00:00
|
|
|
animateCursor();
|
2005-01-06 19:09:34 +00:00
|
|
|
_system->updateScreen();
|
2002-09-22 04:03:45 +00:00
|
|
|
|
2002-10-16 17:37:30 +00:00
|
|
|
OSystem::Event event;
|
2004-09-28 20:19:37 +00:00
|
|
|
uint32 time = _system->getMillis();
|
2002-09-30 12:56:59 +00:00
|
|
|
|
2004-09-28 20:19:37 +00:00
|
|
|
while (_system->pollEvent(event)) {
|
2004-12-05 17:42:20 +00:00
|
|
|
switch (event.type) {
|
2003-09-24 06:33:59 +00:00
|
|
|
case OSystem::EVENT_KEYDOWN:
|
2004-01-26 07:35:31 +00:00
|
|
|
#if !defined(__PALM_OS__)
|
2003-09-24 06:33:59 +00:00
|
|
|
// init continuous event stream
|
2004-01-26 07:35:31 +00:00
|
|
|
// not done on PalmOS because keyboard is emulated and keyup is not generated
|
2003-09-24 06:33:59 +00:00
|
|
|
_currentKeyDown.ascii = event.kbd.ascii;
|
|
|
|
_currentKeyDown.keycode = event.kbd.keycode;
|
|
|
|
_currentKeyDown.flags = event.kbd.flags;
|
|
|
|
_keyRepeatTime = time + kKeyRepeatInitialDelay;
|
2003-04-30 13:57:57 +00:00
|
|
|
#endif
|
2003-09-24 06:33:59 +00:00
|
|
|
activeDialog->handleKeyDown(event.kbd.ascii, event.kbd.keycode, event.kbd.flags);
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_KEYUP:
|
|
|
|
activeDialog->handleKeyUp(event.kbd.ascii, event.kbd.keycode, event.kbd.flags);
|
|
|
|
if (event.kbd.keycode == _currentKeyDown.keycode)
|
|
|
|
// only stop firing events if it's the current key
|
|
|
|
_currentKeyDown.keycode = 0;
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_MOUSEMOVE:
|
2005-01-06 19:09:34 +00:00
|
|
|
activeDialog->handleMouseMoved(event.mouse.x - (activeDialog->_x * _scaleFactor), event.mouse.y - (activeDialog->_y * _scaleFactor), 0);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
// We don't distinguish between mousebuttons (for now at least)
|
|
|
|
case OSystem::EVENT_LBUTTONDOWN:
|
2004-10-17 19:40:34 +00:00
|
|
|
case OSystem::EVENT_RBUTTONDOWN:
|
2003-09-24 06:33:59 +00:00
|
|
|
if (_lastClick.count && (time < _lastClick.time + kDoubleClickDelay)
|
|
|
|
&& ABS(_lastClick.x - event.mouse.x) < 3
|
|
|
|
&& ABS(_lastClick.y - event.mouse.y) < 3) {
|
|
|
|
_lastClick.count++;
|
|
|
|
} else {
|
|
|
|
_lastClick.x = event.mouse.x;
|
|
|
|
_lastClick.y = event.mouse.y;
|
|
|
|
_lastClick.count = 1;
|
|
|
|
}
|
|
|
|
_lastClick.time = time;
|
2005-01-06 19:09:34 +00:00
|
|
|
activeDialog->handleMouseDown(event.mouse.x - (activeDialog->_x * _scaleFactor), event.mouse.y - (activeDialog->_y * _scaleFactor), 1, _lastClick.count);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_LBUTTONUP:
|
|
|
|
case OSystem::EVENT_RBUTTONUP:
|
2005-01-06 19:09:34 +00:00
|
|
|
activeDialog->handleMouseUp(event.mouse.x - (activeDialog->_x * _scaleFactor), event.mouse.y - (activeDialog->_y * _scaleFactor), 1, _lastClick.count);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_WHEELUP:
|
2005-01-06 19:09:34 +00:00
|
|
|
activeDialog->handleMouseWheel(event.mouse.x - (activeDialog->_x * _scaleFactor), event.mouse.y - (activeDialog->_y * _scaleFactor), -1);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_WHEELDOWN:
|
2005-01-06 19:09:34 +00:00
|
|
|
activeDialog->handleMouseWheel(event.mouse.x - (activeDialog->_x * _scaleFactor), event.mouse.y - (activeDialog->_y * _scaleFactor), 1);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_QUIT:
|
|
|
|
_system->quit();
|
|
|
|
return;
|
|
|
|
case OSystem::EVENT_SCREEN_CHANGED:
|
|
|
|
updateColors();
|
2005-01-06 19:09:34 +00:00
|
|
|
updateScaleFactor();
|
2004-03-13 13:03:25 +00:00
|
|
|
activeDialog->handleScreenChanged();
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
2002-07-13 18:32:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-22 04:03:45 +00:00
|
|
|
// check if event should be sent again (keydown)
|
2003-03-06 19:52:54 +00:00
|
|
|
if (_currentKeyDown.keycode != 0) {
|
|
|
|
if (_keyRepeatTime < time) {
|
2002-09-22 04:03:45 +00:00
|
|
|
// fire event
|
2002-11-22 14:02:54 +00:00
|
|
|
activeDialog->handleKeyDown(_currentKeyDown.ascii, _currentKeyDown.keycode, _currentKeyDown.flags);
|
2002-09-30 12:56:59 +00:00
|
|
|
_keyRepeatTime = time + kKeyRepeatSustainDelay;
|
2002-09-22 04:03:45 +00:00
|
|
|
}
|
2002-07-18 14:47:25 +00:00
|
|
|
}
|
2002-09-22 04:03:45 +00:00
|
|
|
|
|
|
|
// Delay for a moment
|
2004-09-28 20:19:37 +00:00
|
|
|
_system->delayMillis(10);
|
2002-07-18 14:47:25 +00:00
|
|
|
}
|
2005-01-06 19:09:34 +00:00
|
|
|
|
2002-10-16 17:37:30 +00:00
|
|
|
if (didSaveState)
|
|
|
|
restoreState();
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void NewGui::saveState() {
|
2002-12-28 04:51:34 +00:00
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
// Backup old cursor
|
2004-03-28 16:30:50 +00:00
|
|
|
_oldCursorMode = _system->showMouse(true);
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2003-09-20 00:47:56 +00:00
|
|
|
// Enable the overlay
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->showOverlay();
|
2003-09-20 00:47:56 +00:00
|
|
|
|
|
|
|
// Create a screen buffer for the overlay data, and fill it with
|
|
|
|
// whatever is visible on the screen rught now.
|
2004-03-28 16:30:50 +00:00
|
|
|
_screen.h = _system->getOverlayHeight();
|
|
|
|
_screen.w = _system->getOverlayWidth();
|
2004-03-13 13:22:14 +00:00
|
|
|
_screen.bytesPerPixel = sizeof(OverlayColor);
|
|
|
|
_screen.pitch = _screen.w * _screen.bytesPerPixel;
|
|
|
|
_screenPitch = _screen.w;
|
|
|
|
_screen.pixels = (OverlayColor*)calloc(_screen.w * _screen.h, sizeof(OverlayColor));
|
|
|
|
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->grabOverlay((OverlayColor *)_screen.pixels, _screenPitch);
|
2002-10-16 17:37:30 +00:00
|
|
|
|
2002-11-22 14:02:54 +00:00
|
|
|
_currentKeyDown.keycode = 0;
|
2002-10-16 17:37:30 +00:00
|
|
|
_lastClick.x = _lastClick.y = 0;
|
|
|
|
_lastClick.time = 0;
|
|
|
|
_lastClick.count = 0;
|
|
|
|
|
|
|
|
_stateIsSaved = true;
|
2005-01-06 19:09:34 +00:00
|
|
|
_scaleEnable = true;
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void NewGui::restoreState() {
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->showMouse(_oldCursorMode);
|
2002-07-05 16:56:53 +00:00
|
|
|
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->hideOverlay();
|
2004-03-13 13:22:14 +00:00
|
|
|
if (_screen.pixels) {
|
|
|
|
free(_screen.pixels);
|
|
|
|
_screen.pixels = 0;
|
2002-09-19 16:06:51 +00:00
|
|
|
}
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2004-02-28 12:58:13 +00:00
|
|
|
_system->updateScreen();
|
2005-01-06 19:09:34 +00:00
|
|
|
|
2002-10-16 17:37:30 +00:00
|
|
|
_stateIsSaved = false;
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void NewGui::openDialog(Dialog *dialog) {
|
2002-07-07 21:46:53 +00:00
|
|
|
_dialogStack.push(dialog);
|
2002-09-28 16:19:28 +00:00
|
|
|
_needRedraw = true;
|
2002-07-07 21:46:53 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void NewGui::closeTopDialog() {
|
2002-07-10 16:49:45 +00:00
|
|
|
// Don't do anything if no dialog is open
|
|
|
|
if (_dialogStack.empty())
|
|
|
|
return;
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-07-10 16:49:45 +00:00
|
|
|
// Remove the dialog from the stack
|
2002-07-07 21:46:53 +00:00
|
|
|
_dialogStack.pop();
|
2002-09-28 16:19:28 +00:00
|
|
|
_needRedraw = true;
|
2002-07-07 21:46:53 +00:00
|
|
|
}
|
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2004-08-15 13:15:55 +00:00
|
|
|
const Graphics::Font &NewGui::getFont() const {
|
2005-01-06 21:15:52 +00:00
|
|
|
return *_font;
|
2004-08-15 13:15:55 +00:00
|
|
|
}
|
|
|
|
|
2004-02-28 12:58:13 +00:00
|
|
|
OverlayColor *NewGui::getBasePtr(int x, int y) {
|
2004-11-25 23:35:02 +00:00
|
|
|
return (OverlayColor *)_screen.getBasePtr(x, y);
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
2004-02-28 12:58:13 +00:00
|
|
|
void NewGui::box(int x, int y, int width, int height, OverlayColor colorA, OverlayColor colorB) {
|
2003-10-01 15:00:26 +00:00
|
|
|
hLine(x + 1, y, x + width - 2, colorA);
|
|
|
|
hLine(x, y + 1, x + width - 1, colorA);
|
|
|
|
vLine(x, y + 1, y + height - 2, colorA);
|
|
|
|
vLine(x + 1, y, y + height - 1, colorA);
|
|
|
|
|
|
|
|
hLine(x + 1, y + height - 2, x + width - 1, colorB);
|
|
|
|
hLine(x + 1, y + height - 1, x + width - 2, colorB);
|
|
|
|
vLine(x + width - 1, y + 1, y + height - 2, colorB);
|
|
|
|
vLine(x + width - 2, y + 1, y + height - 1, colorB);
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
2004-03-22 22:01:10 +00:00
|
|
|
void NewGui::hLine(int x, int y, int x2, OverlayColor color) {
|
2005-01-06 19:09:34 +00:00
|
|
|
_screen.hLine(x * _scaleFactor, y * _scaleFactor, x2 * _scaleFactor, color);
|
2004-03-22 22:01:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NewGui::vLine(int x, int y, int y2, OverlayColor color) {
|
2005-01-06 19:09:34 +00:00
|
|
|
_screen.vLine(x * _scaleFactor, y * _scaleFactor, y2 * _scaleFactor, color);
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
2004-02-28 12:58:13 +00:00
|
|
|
void NewGui::blendRect(int x, int y, int w, int h, OverlayColor color, int level) {
|
2003-04-30 13:57:57 +00:00
|
|
|
#ifdef NEWGUI_256
|
2003-11-03 01:14:40 +00:00
|
|
|
fillRect(x, y, w, h, color);
|
2003-04-30 13:57:57 +00:00
|
|
|
#else
|
2005-01-06 19:09:34 +00:00
|
|
|
Common::Rect rect(x * _scaleFactor, y * _scaleFactor, (x + w) * _scaleFactor, (y + h) * _scaleFactor);
|
2004-11-27 00:55:48 +00:00
|
|
|
rect.clip(_screen.w, _screen.h);
|
2005-01-06 19:09:34 +00:00
|
|
|
|
2004-11-27 00:55:48 +00:00
|
|
|
if (!rect.isValidRect())
|
|
|
|
return;
|
|
|
|
|
2002-12-14 16:07:26 +00:00
|
|
|
int r, g, b;
|
2002-12-13 16:15:58 +00:00
|
|
|
uint8 ar, ag, ab;
|
2003-03-08 06:53:32 +00:00
|
|
|
_system->colorToRGB(color, ar, ag, ab);
|
2002-12-14 16:07:26 +00:00
|
|
|
r = ar * level;
|
|
|
|
g = ag * level;
|
|
|
|
b = ab * level;
|
|
|
|
|
2004-11-27 00:55:48 +00:00
|
|
|
OverlayColor *ptr = getBasePtr(rect.left, rect.top);
|
2002-07-10 16:49:45 +00:00
|
|
|
|
2004-11-27 00:55:48 +00:00
|
|
|
h = rect.height();
|
|
|
|
w = rect.width();
|
2002-07-10 16:49:45 +00:00
|
|
|
while (h--) {
|
|
|
|
for (int i = 0; i < w; i++) {
|
2003-03-08 06:53:32 +00:00
|
|
|
_system->colorToRGB(ptr[i], ar, ag, ab);
|
2003-11-08 23:22:16 +00:00
|
|
|
ptr[i] = _system->RGBToColor((ar + r) / (level+1),
|
|
|
|
(ag + g) / (level+1),
|
|
|
|
(ab + b) / (level+1));
|
2002-07-10 16:49:45 +00:00
|
|
|
}
|
2002-09-28 16:19:28 +00:00
|
|
|
ptr += _screenPitch;
|
2002-07-10 16:49:45 +00:00
|
|
|
}
|
2003-04-30 13:57:57 +00:00
|
|
|
#endif
|
2002-07-10 16:49:45 +00:00
|
|
|
}
|
|
|
|
|
2004-02-28 12:58:13 +00:00
|
|
|
void NewGui::fillRect(int x, int y, int w, int h, OverlayColor color) {
|
2005-01-06 19:09:34 +00:00
|
|
|
_screen.fillRect(Common::Rect(x * _scaleFactor, y * _scaleFactor, (x+w) * _scaleFactor, (y+h) * _scaleFactor), color);
|
2002-07-12 16:24:11 +00:00
|
|
|
}
|
|
|
|
|
2004-02-28 12:58:13 +00:00
|
|
|
void NewGui::frameRect(int x, int y, int w, int h, OverlayColor color) {
|
2005-01-06 19:09:34 +00:00
|
|
|
_screen.frameRect(Common::Rect(x * _scaleFactor, y * _scaleFactor, (x+w) * _scaleFactor, (y+h) * _scaleFactor), color);
|
2002-07-10 22:49:41 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void NewGui::addDirtyRect(int x, int y, int w, int h) {
|
2005-01-06 19:09:34 +00:00
|
|
|
Common::Rect rect(x * _scaleFactor, y * _scaleFactor, (x + w) * _scaleFactor, (y + h) * _scaleFactor);
|
2004-11-27 00:55:48 +00:00
|
|
|
rect.clip(_screen.w, _screen.h);
|
2005-01-06 19:09:34 +00:00
|
|
|
|
2004-11-27 00:55:48 +00:00
|
|
|
if (!rect.isValidRect())
|
|
|
|
return;
|
|
|
|
|
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.
|
2004-11-27 00:55:48 +00:00
|
|
|
OverlayColor *buf = getBasePtr(rect.left, rect.top);
|
|
|
|
_system->copyRectToOverlay(buf, _screenPitch, rect.left, rect.top, rect.width(), rect.height());
|
2002-07-08 00:10:11 +00:00
|
|
|
}
|
|
|
|
|
2004-08-15 13:49:13 +00:00
|
|
|
void NewGui::drawChar(byte chr, int xx, int yy, OverlayColor color, const Graphics::Font *font) {
|
|
|
|
if (font == 0)
|
|
|
|
font = &getFont();
|
2005-01-06 22:48:42 +00:00
|
|
|
font->drawChar(&_screen, chr, xx * _scaleFactor, yy * _scaleFactor, color);
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
2002-07-07 23:37:47 +00:00
|
|
|
|
2005-01-06 22:48:42 +00:00
|
|
|
int NewGui::getStringWidth(const String &str) const {
|
|
|
|
return getFont().getStringWidth(str) / _scaleFactor;
|
2002-09-19 17:03:24 +00:00
|
|
|
}
|
|
|
|
|
2005-01-06 22:48:42 +00:00
|
|
|
int NewGui::getCharWidth(byte c) const {
|
|
|
|
return getFont().getCharWidth(c) / _scaleFactor;
|
|
|
|
}
|
|
|
|
|
|
|
|
int NewGui::getFontHeight() const {
|
|
|
|
return getFont().getFontHeight() / _scaleFactor;
|
2002-09-19 17:03:24 +00:00
|
|
|
}
|
|
|
|
|
2004-03-13 13:03:25 +00:00
|
|
|
void NewGui::drawString(const String &s, int x, int y, int w, OverlayColor color, TextAlignment align, int deltax, bool useEllipsis) {
|
2005-01-06 22:48:42 +00:00
|
|
|
getFont().drawString(&_screen, s, x * _scaleFactor, y * _scaleFactor, w * _scaleFactor, color, align, deltax, useEllipsis);
|
2002-12-12 12:07:46 +00:00
|
|
|
}
|
|
|
|
|
2002-09-19 23:06:54 +00:00
|
|
|
//
|
|
|
|
// Draw an 8x8 bitmap at location (x,y)
|
|
|
|
//
|
2004-11-27 00:55:48 +00:00
|
|
|
void NewGui::drawBitmap(uint32 *bitmap, int tx, int ty, OverlayColor color, int h) {
|
2005-01-06 19:09:34 +00:00
|
|
|
tx *= _scaleFactor; ty *= _scaleFactor;
|
|
|
|
h *= _scaleFactor;
|
2004-11-27 00:55:48 +00:00
|
|
|
OverlayColor *ptr = getBasePtr(tx, ty);
|
2002-07-07 23:37:47 +00:00
|
|
|
|
2004-11-27 00:55:48 +00:00
|
|
|
for (int y = 0; y < h; y++, ptr += _screenPitch) {
|
2002-07-07 23:37:47 +00:00
|
|
|
uint32 mask = 0xF0000000;
|
2004-11-27 00:55:48 +00:00
|
|
|
if (ty + y < 0 || ty + y >= _screen.h)
|
|
|
|
continue;
|
2005-01-06 19:09:34 +00:00
|
|
|
for (int x = 0; x < 8 * _scaleFactor; x++) {
|
|
|
|
if(!(x % 2) && _scaleFactor != 1 && x != 0)
|
|
|
|
mask >>= 4;
|
|
|
|
else if(_scaleFactor == 1)
|
|
|
|
mask >>= 4;
|
|
|
|
|
2004-11-27 00:55:48 +00:00
|
|
|
if (tx + x < 0 || tx + x >= _screen.w)
|
|
|
|
continue;
|
2005-01-06 19:09:34 +00:00
|
|
|
if (bitmap[y / _scaleFactor] & mask)
|
|
|
|
ptr[x] = color;
|
2002-07-07 23:37:47 +00:00
|
|
|
}
|
2002-07-10 16:49:45 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-19 23:06:54 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Draw the mouse cursor (animated). This is mostly ripped from the cursor code in gfx.cpp
|
|
|
|
// We could plug in a different cursor here if we like to.
|
|
|
|
//
|
2003-03-06 19:52:54 +00:00
|
|
|
void NewGui::animateCursor() {
|
2005-01-06 19:09:34 +00:00
|
|
|
int time = _system->getMillis();
|
2002-09-22 04:03:45 +00:00
|
|
|
if (time > _cursorAnimateTimer + kCursorAnimateDelay) {
|
2002-09-19 23:06:54 +00:00
|
|
|
const byte colors[4] = { 15, 15, 7, 8 };
|
2002-09-22 04:03:45 +00:00
|
|
|
const byte color = colors[_cursorAnimateCounter];
|
2002-09-19 23:06:54 +00:00
|
|
|
int i;
|
2005-01-06 19:09:34 +00:00
|
|
|
|
2002-09-28 15:58:25 +00:00
|
|
|
for (i = 0; i < 15; i++) {
|
|
|
|
if ((i < 6) || (i > 8)) {
|
|
|
|
_cursor[16 * 7 + i] = color;
|
|
|
|
_cursor[16 * i + 7] = color;
|
2002-09-19 23:06:54 +00:00
|
|
|
}
|
|
|
|
}
|
2005-01-06 19:09:34 +00:00
|
|
|
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->setMouseCursor(_cursor, 16, 16, 7, 7);
|
2002-09-22 04:03:45 +00:00
|
|
|
|
|
|
|
_cursorAnimateTimer = time;
|
|
|
|
_cursorAnimateCounter = (_cursorAnimateCounter + 1) % 4;
|
2002-09-19 23:06:54 +00:00
|
|
|
}
|
|
|
|
}
|
2003-04-30 13:57:57 +00:00
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
} // End of namespace GUI
|