2004-01-06 13:44:17 +00:00
|
|
|
/* Copyright (C) 1994-2004 Revolution Software Ltd
|
2003-07-28 01:47:41 +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 "common/stdafx.h"
|
2003-10-28 19:51:30 +00:00
|
|
|
#include "sword2/sword2.h"
|
|
|
|
#include "sword2/driver/menu.h"
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
namespace Sword2 {
|
|
|
|
|
2003-09-27 15:20:15 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// OSystem Event Handler. Full of cross platform goodness and 99% fat free!
|
|
|
|
// ---------------------------------------------------------------------------
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-11-11 07:43:02 +00:00
|
|
|
void Input::parseEvents(void) {
|
2003-07-28 01:47:41 +00:00
|
|
|
OSystem::Event event;
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
while (_vm->_system->poll_event(&event)) {
|
2003-11-11 07:43:02 +00:00
|
|
|
switch (event.event_code) {
|
2003-07-28 01:47:41 +00:00
|
|
|
case OSystem::EVENT_KEYDOWN:
|
2003-11-11 07:43:02 +00:00
|
|
|
writeKey(event.kbd.ascii, event.kbd.keycode, event.kbd.flags);
|
2003-07-28 01:47:41 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_MOUSEMOVE:
|
2003-11-11 07:43:02 +00:00
|
|
|
_mouseX = event.mouse.x;
|
|
|
|
_mouseY = event.mouse.y - MENUDEEP;
|
2003-07-28 01:47:41 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_LBUTTONDOWN:
|
2003-11-11 07:43:02 +00:00
|
|
|
logMouseEvent(RD_LEFTBUTTONDOWN);
|
2003-07-28 01:47:41 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_RBUTTONDOWN:
|
2003-11-11 07:43:02 +00:00
|
|
|
logMouseEvent(RD_RIGHTBUTTONDOWN);
|
2003-07-28 01:47:41 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_LBUTTONUP:
|
2003-11-11 07:43:02 +00:00
|
|
|
logMouseEvent(RD_LEFTBUTTONUP);
|
2003-07-28 01:47:41 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_RBUTTONUP:
|
2003-11-11 07:43:02 +00:00
|
|
|
logMouseEvent(RD_RIGHTBUTTONUP);
|
2003-07-28 01:47:41 +00:00
|
|
|
break;
|
2003-12-19 16:50:03 +00:00
|
|
|
case OSystem::EVENT_WHEELUP:
|
|
|
|
logMouseEvent(RD_WHEELUP);
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_WHEELDOWN:
|
|
|
|
logMouseEvent(RD_WHEELDOWN);
|
|
|
|
break;
|
2003-07-28 01:47:41 +00:00
|
|
|
case OSystem::EVENT_QUIT:
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->closeGame();
|
2003-07-28 01:47:41 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-04 15:11:30 +00:00
|
|
|
/**
|
|
|
|
* Tell updateDisplay() that the scene needs to be completely updated.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Graphics::setNeedFullRedraw(void) {
|
2003-10-15 06:40:31 +00:00
|
|
|
_needFullRedraw = true;
|
2003-08-29 06:42:34 +00:00
|
|
|
}
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
/**
|
2004-01-04 15:11:30 +00:00
|
|
|
* This function has two purposes: It redraws the scene, and it handles input
|
|
|
|
* events, palette fading, etc. It should be called at a high rate (> 20 per
|
|
|
|
* second), but the scene is usually only redrawn about 12 times per second,
|
|
|
|
* except when then screen is scrolling.
|
|
|
|
*
|
|
|
|
* @param redrawScene If true, redraw the scene.
|
2003-09-28 14:13:57 +00:00
|
|
|
*/
|
|
|
|
|
2004-01-04 15:11:30 +00:00
|
|
|
void Graphics::updateDisplay(bool redrawScene) {
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_input->parseEvents();
|
2003-10-15 06:40:31 +00:00
|
|
|
fadeServer();
|
2003-08-28 06:36:15 +00:00
|
|
|
|
2004-01-04 15:11:30 +00:00
|
|
|
if (redrawScene) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// Note that the entire scene is always rendered, which is less
|
|
|
|
// than optimal, but at least we can try to be intelligent
|
|
|
|
// about updating the screen afterwards.
|
|
|
|
|
|
|
|
if (_needFullRedraw) {
|
|
|
|
// Update the entire screen. This is necessary when
|
|
|
|
// scrolling, fading, etc.
|
|
|
|
|
|
|
|
_vm->_system->copy_rect(_buffer + MENUDEEP * _screenWide, _screenWide, 0, MENUDEEP, _screenWide, _screenDeep - 2 * MENUDEEP);
|
|
|
|
_needFullRedraw = false;
|
|
|
|
} else {
|
|
|
|
// Update only the dirty areas of the screen
|
|
|
|
|
|
|
|
int j, x, y;
|
|
|
|
int stripWide;
|
|
|
|
|
|
|
|
for (i = 0; i < _gridDeep; i++) {
|
|
|
|
stripWide = 0;
|
|
|
|
|
|
|
|
for (j = 0; j < _gridWide; j++) {
|
|
|
|
if (_dirtyGrid[i * _gridWide + j]) {
|
|
|
|
stripWide++;
|
|
|
|
} else if (stripWide) {
|
|
|
|
x = CELLWIDE * (j - stripWide);
|
|
|
|
y = CELLDEEP * i;
|
|
|
|
_vm->_system->copy_rect(_buffer + y * _screenWide + x, _screenWide, x, y, stripWide * CELLWIDE, CELLDEEP);
|
|
|
|
stripWide = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stripWide) {
|
|
|
|
x = CELLWIDE * (j - stripWide);
|
|
|
|
y = CELLDEEP * i;
|
|
|
|
_vm->_system->copy_rect(_buffer + y * _screenWide + x, _screenWide, x, y, stripWide * CELLWIDE, CELLDEEP);
|
|
|
|
stripWide = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Age the dirty cells one generation. This way we keep track
|
|
|
|
// of both the cells that were updated this time, and the ones
|
|
|
|
// that were updated the last time.
|
2003-08-28 06:36:15 +00:00
|
|
|
|
2004-01-04 15:11:30 +00:00
|
|
|
for (i = 0; i < _gridWide * _gridDeep; i++)
|
|
|
|
_dirtyGrid[i] >>= 1;
|
2003-08-29 06:42:34 +00:00
|
|
|
}
|
|
|
|
|
2004-01-04 15:11:30 +00:00
|
|
|
// We always need to update because of fades, menu animations, etc.
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_system->update_screen();
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-09-28 14:13:57 +00:00
|
|
|
/**
|
2003-10-07 07:07:47 +00:00
|
|
|
* Set the window title
|
2003-09-28 14:13:57 +00:00
|
|
|
*/
|
|
|
|
|
2003-11-11 07:43:02 +00:00
|
|
|
void Graphics::setWindowName(const char *windowName) {
|
2003-10-07 07:07:47 +00:00
|
|
|
OSystem::Property prop;
|
|
|
|
|
|
|
|
prop.caption = windowName;
|
2003-11-16 14:18:29 +00:00
|
|
|
_vm->_system->property(OSystem::PROP_SET_WINDOW_CAPTION, &prop);
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
2003-10-04 00:52:27 +00:00
|
|
|
|
|
|
|
} // End of namespace Sword2
|