2002-07-05 16:56:53 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2004-01-06 12:45:34 +00:00
|
|
|
* Copyright (C) 2002-2004 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-08-15 13:15:55 +00:00
|
|
|
// Uncomment the following to enable the new font code:
|
|
|
|
//#define NEW_FONT_CODE
|
|
|
|
|
|
|
|
|
|
|
|
|
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" ?
|
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-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
|
2004-03-13 13:22:14 +00:00
|
|
|
NewGui::NewGui() : _needRedraw(false),
|
2003-03-06 19:52:54 +00:00
|
|
|
_stateIsSaved(false), _cursorAnimateCounter(0), _cursorAnimateTimer(0) {
|
2003-11-02 02:18:16 +00:00
|
|
|
|
|
|
|
_system = OSystem::instance();
|
|
|
|
|
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;
|
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);
|
|
|
|
}
|
|
|
|
|
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;
|
2002-09-22 04:03:45 +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();
|
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();
|
2004-02-28 12:58:13 +00:00
|
|
|
_system->updateScreen();
|
2002-09-22 04:03:45 +00:00
|
|
|
|
2002-10-16 17:37:30 +00:00
|
|
|
OSystem::Event event;
|
2003-11-02 02:18:16 +00:00
|
|
|
uint32 time = _system->get_msecs();
|
2002-09-30 12:56:59 +00:00
|
|
|
|
2002-09-22 04:03:45 +00:00
|
|
|
while (_system->poll_event(&event)) {
|
2003-09-24 06:33:59 +00:00
|
|
|
switch (event.event_code) {
|
|
|
|
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:
|
|
|
|
activeDialog->handleMouseMoved(event.mouse.x - activeDialog->_x, event.mouse.y - activeDialog->_y, 0);
|
|
|
|
break;
|
|
|
|
// We don't distinguish between mousebuttons (for now at least)
|
|
|
|
case OSystem::EVENT_LBUTTONDOWN:
|
|
|
|
case OSystem::EVENT_RBUTTONDOWN: {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
activeDialog->handleMouseDown(event.mouse.x - activeDialog->_x, event.mouse.y - activeDialog->_y, 1, _lastClick.count);
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_LBUTTONUP:
|
|
|
|
case OSystem::EVENT_RBUTTONUP:
|
|
|
|
activeDialog->handleMouseUp(event.mouse.x - activeDialog->_x, event.mouse.y - activeDialog->_y, 1, _lastClick.count);
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_WHEELUP:
|
|
|
|
activeDialog->handleMouseWheel(event.mouse.x - activeDialog->_x, event.mouse.y - activeDialog->_y, -1);
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_WHEELDOWN:
|
|
|
|
activeDialog->handleMouseWheel(event.mouse.x - activeDialog->_x, event.mouse.y - activeDialog->_y, 1);
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_QUIT:
|
|
|
|
_system->quit();
|
|
|
|
return;
|
|
|
|
case OSystem::EVENT_SCREEN_CHANGED:
|
|
|
|
updateColors();
|
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
|
|
|
|
_system->delay_msecs(10);
|
2002-07-18 14:47:25 +00:00
|
|
|
}
|
2002-09-27 13:06:58 +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();
|
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 {
|
|
|
|
#ifdef NEW_FONT_CODE
|
|
|
|
return Graphics::g_sysfont;
|
|
|
|
#else
|
|
|
|
return Graphics::g_scummfont;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2004-02-28 12:58:13 +00:00
|
|
|
OverlayColor *NewGui::getBasePtr(int x, int y) {
|
2004-03-13 13:22:14 +00:00
|
|
|
return (OverlayColor *)((byte *)_screen.pixels + x * _screen.bytesPerPixel + y * _screen.pitch);
|
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) {
|
2004-02-28 12:58:13 +00:00
|
|
|
OverlayColor *ptr;
|
2002-07-07 13:14:34 +00:00
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
if (x2 < x)
|
2002-11-05 22:34:50 +00:00
|
|
|
SWAP(x2, x);
|
2002-07-05 16:56:53 +00:00
|
|
|
|
2004-03-22 22:01:10 +00:00
|
|
|
ptr = getBasePtr(x, y);
|
|
|
|
|
|
|
|
while (x++ <= x2) {
|
|
|
|
*ptr++ = color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewGui::vLine(int x, int y, int y2, OverlayColor color) {
|
|
|
|
OverlayColor *ptr;
|
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
if (y2 < y)
|
2002-11-05 22:34:50 +00:00
|
|
|
SWAP(y2, y);
|
2002-07-05 16:56:53 +00:00
|
|
|
|
|
|
|
ptr = getBasePtr(x, y);
|
|
|
|
|
2004-03-22 22:01:10 +00:00
|
|
|
while (y++ <= y2) {
|
|
|
|
*ptr = color;
|
|
|
|
ptr += _screenPitch;
|
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
|
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-02-28 12:58:13 +00:00
|
|
|
OverlayColor *ptr = getBasePtr(x, y);
|
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) {
|
2002-09-19 16:06:51 +00:00
|
|
|
int i;
|
2004-02-28 12:58:13 +00:00
|
|
|
OverlayColor *ptr = getBasePtr(x, y);
|
2002-07-05 16:56:53 +00:00
|
|
|
|
|
|
|
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-28 16:19:28 +00:00
|
|
|
ptr += _screenPitch;
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-28 12:58:13 +00:00
|
|
|
void NewGui::checkerRect(int x, int y, int w, int h, OverlayColor color) {
|
2002-09-19 16:06:51 +00:00
|
|
|
int i;
|
2004-02-28 12:58:13 +00:00
|
|
|
OverlayColor *ptr = getBasePtr(x, y);
|
2002-07-12 16:24:11 +00:00
|
|
|
|
|
|
|
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-28 16:19:28 +00:00
|
|
|
ptr += _screenPitch;
|
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) {
|
2002-07-10 22:49:41 +00:00
|
|
|
int i;
|
2004-02-28 12:58:13 +00:00
|
|
|
OverlayColor *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-28 16:19:28 +00:00
|
|
|
for (i = 0; i < h; i++, ptr += _screenPitch)
|
2002-07-10 22:49:41 +00:00
|
|
|
*ptr = color;
|
|
|
|
ptr = basePtr;
|
2002-09-28 16:19:28 +00:00
|
|
|
for (i = 0; i < h; i++, ptr += _screenPitch)
|
2002-07-10 22:49:41 +00:00
|
|
|
*ptr = color;
|
2002-09-28 16:19:28 +00:00
|
|
|
ptr -= _screenPitch;
|
2002-07-10 22:49:41 +00:00
|
|
|
for (i = 0; i < w; i++, ptr++)
|
|
|
|
*ptr = color;
|
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void NewGui::addDirtyRect(int x, int y, int w, int h) {
|
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-02-28 12:58:13 +00:00
|
|
|
OverlayColor *buf = getBasePtr(x, y);
|
2004-03-28 16:30:50 +00:00
|
|
|
_system->copyRectToOverlay(buf, _screenPitch, x, y, w, h);
|
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();
|
|
|
|
font->drawChar(&_screen, chr, xx, yy, color);
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
2002-07-07 23:37:47 +00:00
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
int NewGui::getStringWidth(const String &str) {
|
2004-08-15 13:15:55 +00:00
|
|
|
return getFont().getStringWidth(str);
|
2002-09-19 17:03:24 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
int NewGui::getCharWidth(byte c) {
|
2004-08-15 13:15:55 +00:00
|
|
|
return getFont().getCharWidth(c);
|
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) {
|
2004-08-15 13:15:55 +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 an 8x8 bitmap at location (x,y)
|
|
|
|
//
|
2004-02-28 12:58:13 +00:00
|
|
|
void NewGui::drawBitmap(uint32 *bitmap, int x, int y, OverlayColor color, int h) {
|
|
|
|
OverlayColor *ptr = getBasePtr(x, y);
|
2002-07-07 23:37:47 +00:00
|
|
|
|
2002-12-12 23:22:48 +00:00
|
|
|
for (y = 0; y < h; y++) {
|
2002-07-07 23:37:47 +00:00
|
|
|
uint32 mask = 0xF0000000;
|
2002-12-12 23:22:48 +00:00
|
|
|
for (x = 0; x < 8; x++) {
|
|
|
|
if (bitmap[y] & mask)
|
|
|
|
ptr[x] = color;
|
2002-07-07 23:37:47 +00:00
|
|
|
mask >>= 4;
|
|
|
|
}
|
2002-09-28 16:19:28 +00:00
|
|
|
ptr += _screenPitch;
|
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() {
|
2003-11-02 02:18:16 +00:00
|
|
|
int time = _system->get_msecs();
|
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;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|