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$
|
|
|
|
*/
|
|
|
|
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/stdafx.h"
|
2005-01-10 22:06:49 +00:00
|
|
|
#include "common/system.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
|
|
|
|
2005-09-03 16:26:00 +00:00
|
|
|
#if defined(PALMOS_68K)
|
|
|
|
#include "arm/native.h"
|
|
|
|
#include "arm/macros.h"
|
|
|
|
#endif
|
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
|
|
|
};
|
|
|
|
|
2005-06-21 22:08:21 +00:00
|
|
|
#if defined(__SYMBIAN32__) // Testing: could be removed? Just making sure that an CVS update doesn't break my code :P
|
|
|
|
#define USE_AUTO_SCALING false
|
|
|
|
#else
|
|
|
|
#define USE_AUTO_SCALING false
|
|
|
|
#endif
|
2003-11-19 23:46:39 +00:00
|
|
|
|
2002-09-19 17:44:41 +00:00
|
|
|
// Constructor
|
2005-06-02 12:29:01 +00:00
|
|
|
NewGui::NewGui() : _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() {
|
2005-06-02 12:29:01 +00:00
|
|
|
const int screenW = g_system->getOverlayWidth();
|
|
|
|
const int screenH = g_system->getOverlayHeight();
|
2005-01-06 19:09:34 +00:00
|
|
|
|
2005-06-02 12:29:01 +00:00
|
|
|
// TODO: Perhaps we should also set the widget size here. That'd allow
|
|
|
|
// us to remove much of the screen size checking from the individual
|
|
|
|
// widgets.
|
|
|
|
|
|
|
|
if (screenW >= 400 && screenH >= 300) {
|
2005-01-06 22:48:42 +00:00
|
|
|
_font = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
|
2005-06-02 12:29:01 +00:00
|
|
|
} else {
|
|
|
|
_font = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont);
|
|
|
|
}
|
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;
|
2005-01-06 22:51:25 +00:00
|
|
|
int button;
|
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);
|
2005-04-17 11:20:59 +00:00
|
|
|
for (int i = 0; i < _dialogStack.size(); i++) {
|
|
|
|
// For each dialog we draw we have to ensure the correct
|
|
|
|
// scaling mode is active.
|
|
|
|
updateScaleFactor();
|
2002-11-10 19:39:32 +00:00
|
|
|
_dialogStack[i]->drawDialog();
|
2005-04-17 11:20:59 +00:00
|
|
|
}
|
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)) {
|
2005-06-02 12:29:01 +00:00
|
|
|
Common::Point mouse(event.mouse.x - activeDialog->_x, event.mouse.y - activeDialog->_y);
|
2005-09-03 16:26:00 +00:00
|
|
|
|
2004-12-05 17:42:20 +00:00
|
|
|
switch (event.type) {
|
2003-09-24 06:33:59 +00:00
|
|
|
case OSystem::EVENT_KEYDOWN:
|
2005-09-03 16:26:00 +00:00
|
|
|
#if !defined(PALMOS_MODE)
|
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-03-12 15:29:16 +00:00
|
|
|
activeDialog->handleMouseMoved(mouse.x, mouse.y, 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:
|
2005-01-06 22:51:25 +00:00
|
|
|
button = (event.type == OSystem::EVENT_LBUTTONDOWN ? 1 : 2);
|
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-03-12 15:29:16 +00:00
|
|
|
activeDialog->handleMouseDown(mouse.x, mouse.y, button, _lastClick.count);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_LBUTTONUP:
|
|
|
|
case OSystem::EVENT_RBUTTONUP:
|
2005-01-06 22:51:25 +00:00
|
|
|
button = (event.type == OSystem::EVENT_LBUTTONUP ? 1 : 2);
|
2005-03-12 15:29:16 +00:00
|
|
|
activeDialog->handleMouseUp(mouse.x, mouse.y, button, _lastClick.count);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_WHEELUP:
|
2005-03-12 15:29:16 +00:00
|
|
|
activeDialog->handleMouseWheel(mouse.x, mouse.y, -1);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_WHEELDOWN:
|
2005-03-12 15:29:16 +00:00
|
|
|
activeDialog->handleMouseWheel(mouse.x, mouse.y, 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;
|
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-06-02 12:29:01 +00:00
|
|
|
_screen.hLine(x, y, x2, color);
|
2004-03-22 22:01:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NewGui::vLine(int x, int y, int y2, OverlayColor color) {
|
2005-06-02 12:29:01 +00:00
|
|
|
_screen.vLine(x, y, y2, color);
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
2005-04-16 11:40:15 +00:00
|
|
|
void NewGui::copyToSurface(Graphics::Surface *s, int x, int y, int w, int h) {
|
2005-06-02 12:29:01 +00:00
|
|
|
Common::Rect rect(x, y, x + w, y + h);
|
2005-04-16 11:40:15 +00:00
|
|
|
rect.clip(_screen.w, _screen.h);
|
|
|
|
|
|
|
|
if (!rect.isValidRect())
|
|
|
|
return;
|
|
|
|
|
|
|
|
s->w = rect.width();
|
|
|
|
s->h = rect.height();
|
|
|
|
s->bytesPerPixel = sizeof(OverlayColor);
|
|
|
|
s->pitch = s->w * s->bytesPerPixel;
|
|
|
|
s->pixels = (OverlayColor *)malloc(s->pitch * s->h);
|
|
|
|
|
|
|
|
w = s->w;
|
|
|
|
h = s->h;
|
|
|
|
|
|
|
|
OverlayColor *dst = (OverlayColor *)s->pixels;
|
|
|
|
OverlayColor *src = getBasePtr(rect.left, rect.top);
|
|
|
|
|
|
|
|
while (h--) {
|
|
|
|
memcpy(dst, src, s->pitch);
|
|
|
|
src += _screenPitch;
|
|
|
|
dst += s->w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewGui::drawSurface(const Graphics::Surface &s, int x, int y) {
|
2005-06-02 12:29:01 +00:00
|
|
|
Common::Rect rect(x, y, x + s.w, y + s.h);
|
2005-04-16 11:40:15 +00:00
|
|
|
rect.clip(_screen.w, _screen.h);
|
|
|
|
|
|
|
|
if (!rect.isValidRect())
|
|
|
|
return;
|
2005-09-03 16:26:00 +00:00
|
|
|
|
2005-04-16 11:40:15 +00:00
|
|
|
assert(s.bytesPerPixel == sizeof(OverlayColor));
|
|
|
|
|
|
|
|
OverlayColor *src = (OverlayColor *)s.pixels;
|
|
|
|
OverlayColor *dst = getBasePtr(rect.left, rect.top);
|
|
|
|
|
|
|
|
int w = rect.width();
|
|
|
|
int h = rect.height();
|
|
|
|
|
|
|
|
while (h--) {
|
|
|
|
memcpy(dst, src, s.pitch);
|
|
|
|
src += w;
|
|
|
|
dst += _screenPitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-06-02 12:29:01 +00:00
|
|
|
Common::Rect rect(x, y, x + w, y + h);
|
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;
|
|
|
|
|
2005-04-19 20:35:48 +00:00
|
|
|
if (_system->hasFeature(OSystem::kFeatureOverlaySupportsAlpha)) {
|
2005-04-03 19:41:20 +00:00
|
|
|
|
|
|
|
int a, r, g, b;
|
|
|
|
uint8 aa, ar, ag, ab;
|
|
|
|
_system->colorToARGB(color, aa, ar, ag, ab);
|
|
|
|
a = aa*level/(level+1);
|
|
|
|
if (a < 1)
|
|
|
|
return;
|
|
|
|
r = ar * a;
|
|
|
|
g = ag * a;
|
|
|
|
b = ab * a;
|
|
|
|
|
|
|
|
OverlayColor *ptr = getBasePtr(rect.left, rect.top);
|
2005-09-03 16:26:00 +00:00
|
|
|
|
2005-04-03 19:41:20 +00:00
|
|
|
h = rect.height();
|
|
|
|
w = rect.width();
|
|
|
|
while (h--) {
|
|
|
|
for (int i = 0; i < w; i++) {
|
|
|
|
_system->colorToARGB(ptr[i], aa, ar, ag, ab);
|
|
|
|
int a2 = aa + a - (a*aa)/255;
|
|
|
|
ptr[i] = _system->ARGBToColor(a2,
|
|
|
|
((255-a)*aa*ar/255+r)/a2,
|
|
|
|
((255-a)*aa*ag/255+g)/a2,
|
|
|
|
((255-a)*aa*ab/255+b)/a2);
|
|
|
|
}
|
|
|
|
ptr += _screenPitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-04-03 19:41:20 +00:00
|
|
|
int r, g, b;
|
|
|
|
uint8 ar, ag, ab;
|
|
|
|
_system->colorToRGB(color, ar, ag, ab);
|
|
|
|
r = ar * level;
|
|
|
|
g = ag * level;
|
|
|
|
b = ab * level;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-04-03 19:41:20 +00:00
|
|
|
OverlayColor *ptr = getBasePtr(rect.left, rect.top);
|
2005-09-03 16:26:00 +00:00
|
|
|
|
2005-04-03 19:41:20 +00:00
|
|
|
h = rect.height();
|
|
|
|
w = rect.width();
|
2005-09-03 16:26:00 +00:00
|
|
|
|
|
|
|
#ifdef PALMOS_68K
|
|
|
|
ARM_START(BlendRectType)
|
|
|
|
ARM_INIT(COMMON_BLENDRECT)
|
|
|
|
ARM_ADDM(w)
|
|
|
|
ARM_ADDM(h)
|
|
|
|
ARM_ADDM(ptr)
|
|
|
|
ARM_ADDM(_screenPitch)
|
|
|
|
ARM_ADDM(r)
|
|
|
|
ARM_ADDM(g)
|
|
|
|
ARM_ADDM(b)
|
|
|
|
ARM_ADDM(level)
|
|
|
|
ARM_CALL(ARM_COMMON, PNO_DATA())
|
|
|
|
ARM_END()
|
|
|
|
#endif
|
2005-04-03 19:41:20 +00:00
|
|
|
while (h--) {
|
|
|
|
for (int i = 0; i < w; i++) {
|
|
|
|
_system->colorToRGB(ptr[i], ar, ag, ab);
|
|
|
|
ptr[i] = _system->RGBToColor((ar + r) / (level+1),
|
|
|
|
(ag + g) / (level+1),
|
|
|
|
(ab + b) / (level+1));
|
|
|
|
}
|
|
|
|
ptr += _screenPitch;
|
2002-07-10 16:49:45 +00:00
|
|
|
}
|
2005-04-03 19:41:20 +00:00
|
|
|
|
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-06-02 12:29:01 +00:00
|
|
|
_screen.fillRect(Common::Rect(x, y, x + w, y + h), 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-06-02 12:29:01 +00:00
|
|
|
_screen.frameRect(Common::Rect(x, y, x + w, y + h), 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-06-02 12:29:01 +00:00
|
|
|
Common::Rect rect(x, y, x + w, y + h);
|
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-06-02 12:29:01 +00:00
|
|
|
font->drawChar(&_screen, chr, xx, yy, 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 {
|
2005-06-02 12:29:01 +00:00
|
|
|
return getFont().getStringWidth(str);
|
2002-09-19 17:03:24 +00:00
|
|
|
}
|
|
|
|
|
2005-01-06 22:48:42 +00:00
|
|
|
int NewGui::getCharWidth(byte c) const {
|
2005-06-02 12:29:01 +00:00
|
|
|
return getFont().getCharWidth(c);
|
2005-01-06 22:48:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int NewGui::getFontHeight() const {
|
2005-06-02 12:29:01 +00:00
|
|
|
return getFont().getFontHeight();
|
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-06-02 12:29:01 +00:00
|
|
|
getFont().drawString(&_screen, s, x, y, w, color, align, deltax, useEllipsis);
|
2002-12-12 12:07:46 +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
|