2009-02-17 15:17:01 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-02-15 08:34:13 +00:00
|
|
|
#include "common/scummsys.h"
|
|
|
|
#include "common/system.h"
|
2009-07-03 14:18:20 +00:00
|
|
|
#include "graphics/cursorman.h"
|
2009-02-23 09:39:09 +00:00
|
|
|
#include "graphics/primitives.h"
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-03-07 17:32:11 +00:00
|
|
|
#include "sci/sci.h"
|
2009-02-21 19:33:01 +00:00
|
|
|
#include "sci/gfx/gfx_driver.h"
|
|
|
|
#include "sci/gfx/gfx_tools.h"
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-21 10:23:36 +00:00
|
|
|
namespace Sci {
|
|
|
|
|
2009-06-06 10:21:48 +00:00
|
|
|
GfxDriver::GfxDriver(int xfact, int yfact, int bytespp) {
|
2009-02-15 06:10:59 +00:00
|
|
|
int i;
|
|
|
|
|
2009-06-06 10:21:48 +00:00
|
|
|
Graphics::PixelFormat format = { bytespp, 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
|
|
_mode = gfx_new_mode(xfact, yfact, format, new Palette(256), 0);
|
|
|
|
_mode->xsize = xfact * 320;
|
|
|
|
_mode->ysize = yfact * 200;
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
2009-06-06 10:21:48 +00:00
|
|
|
_priority[i] = gfx_pixmap_alloc_index_data(gfx_new_pixmap(_mode->xsize, _mode->ysize, GFX_RESID_NONE, -i, -777));
|
|
|
|
if (!_priority[i]) {
|
|
|
|
error("Out of memory: Could not allocate priority maps! (%dx%d)\n", _mode->xsize, _mode->ysize);
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// create the visual buffers
|
2009-02-24 12:01:28 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
2009-06-06 10:21:48 +00:00
|
|
|
_visual[i] = NULL;
|
|
|
|
_visual[i] = new byte[_mode->xsize * _mode->ysize];
|
|
|
|
if (!_visual[i]) {
|
|
|
|
error("Out of memory: Could not allocate visual buffers! (%dx%d)\n", _mode->xsize, _mode->ysize);
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
2009-06-06 10:21:48 +00:00
|
|
|
memset(_visual[i], 0, _mode->xsize * _mode->ysize);
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
2009-06-06 10:21:48 +00:00
|
|
|
_mode->palette->name = "global";
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
2009-06-06 10:21:48 +00:00
|
|
|
GfxDriver::~GfxDriver() {
|
2009-02-15 06:10:59 +00:00
|
|
|
int i;
|
2009-06-06 10:21:48 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
gfx_free_pixmap(_priority[i]);
|
|
|
|
_priority[i] = NULL;
|
|
|
|
}
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-06-06 10:21:48 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
delete[] _visual[i];
|
|
|
|
_visual[i] = NULL;
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Drawing operations
|
|
|
|
|
2009-02-23 09:39:09 +00:00
|
|
|
static void drawProc(int x, int y, int c, void *data) {
|
2009-06-06 10:21:48 +00:00
|
|
|
GfxDriver *drv = (GfxDriver *)data;
|
2009-06-06 10:40:32 +00:00
|
|
|
byte *p = drv->getVisual0();
|
2009-06-06 10:21:48 +00:00
|
|
|
p[y * 320* drv->getMode()->xfact + x] = c;
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
2009-06-06 10:21:48 +00:00
|
|
|
int GfxDriver::drawLine(Common::Point start, Common::Point end, gfx_color_t color,
|
|
|
|
gfx_line_mode_t line_mode, gfx_line_style_t line_style) {
|
2009-03-08 20:17:01 +00:00
|
|
|
uint32 scolor = color.visual.parent_index;
|
2009-06-06 10:21:48 +00:00
|
|
|
int xfact = (line_mode == GFX_LINE_MODE_FINE)? 1: _mode->xfact;
|
|
|
|
int yfact = (line_mode == GFX_LINE_MODE_FINE)? 1: _mode->yfact;
|
|
|
|
int xsize = _mode->xsize;
|
|
|
|
int ysize = _mode->ysize;
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
if (color.mask & GFX_MASK_VISUAL) {
|
2009-02-17 19:15:37 +00:00
|
|
|
Common::Point nstart, nend;
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-23 22:36:39 +00:00
|
|
|
for (int xc = 0; xc < xfact; xc++) {
|
|
|
|
for (int yc = 0; yc < yfact; yc++) {
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-02-23 22:36:39 +00:00
|
|
|
nstart.x = CLIP<int16>(start.x + xc, 0, xsize);
|
|
|
|
nstart.y = CLIP<int16>(start.y + yc, 0, ysize);
|
|
|
|
nend.x = CLIP<int16>(end.x + xc, 0, xsize - 1);
|
|
|
|
nend.y = CLIP<int16>(end.y + yc, 0, ysize - 1);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-06-06 10:21:48 +00:00
|
|
|
Graphics::drawLine(nstart.x, nstart.y, nend.x, nend.y, scolor, drawProc, this);
|
2009-02-23 22:36:39 +00:00
|
|
|
|
|
|
|
if (color.mask & GFX_MASK_PRIORITY) {
|
2009-06-06 10:21:48 +00:00
|
|
|
gfx_draw_line_pixmap_i(_priority[0], nstart, nend, color.priority);
|
2009-02-23 22:36:39 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GFX_OK;
|
|
|
|
}
|
|
|
|
|
2009-06-06 10:21:48 +00:00
|
|
|
int GfxDriver::drawFilledRect(rect_t rect, gfx_color_t color1, gfx_color_t color2,
|
2009-02-22 13:11:43 +00:00
|
|
|
gfx_rectangle_fill_t shade_mode) {
|
2009-02-15 06:10:59 +00:00
|
|
|
if (color1.mask & GFX_MASK_VISUAL) {
|
2009-03-16 00:07:12 +00:00
|
|
|
for (int i = rect.y; i < rect.y + rect.height; i++) {
|
2009-06-06 10:21:48 +00:00
|
|
|
memset(_visual[0] + i * _mode->xsize + rect.x, color1.visual.parent_index, rect.width);
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (color1.mask & GFX_MASK_PRIORITY)
|
2009-06-06 10:21:48 +00:00
|
|
|
gfx_draw_box_pixmap_i(_priority[0], rect, color1.priority);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
return GFX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pixmap operations
|
|
|
|
|
2009-06-06 10:21:48 +00:00
|
|
|
int GfxDriver::drawPixmap(gfx_pixmap_t *pxm, int priority, rect_t src, rect_t dest, gfx_buffer_t buffer) {
|
2009-02-24 12:01:28 +00:00
|
|
|
int bufnr = (buffer == GFX_BUFFER_STATIC) ? 1 : 0;
|
2009-02-15 06:10:59 +00:00
|
|
|
|
2009-03-16 00:07:12 +00:00
|
|
|
if (dest.width != src.width || dest.height != src.height) {
|
|
|
|
printf("Attempt to scale pixmap (%dx%d)->(%dx%d): Not supported\n", src.width, src.height, dest.width, dest.height);
|
2009-02-15 06:10:59 +00:00
|
|
|
return GFX_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-06-06 10:21:48 +00:00
|
|
|
gfx_crossblit_pixmap(_mode, pxm, priority, src, dest, _visual[bufnr], _mode->xsize,
|
|
|
|
_priority[bufnr]->index_data, _priority[bufnr]->index_width, 1, 0);
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
return GFX_OK;
|
|
|
|
}
|
|
|
|
|
2009-06-06 10:21:48 +00:00
|
|
|
int GfxDriver::grabPixmap(rect_t src, gfx_pixmap_t *pxm, gfx_map_mask_t map) {
|
2009-02-15 06:10:59 +00:00
|
|
|
if (src.x < 0 || src.y < 0) {
|
|
|
|
printf("Attempt to grab pixmap from invalid coordinates (%d,%d)\n", src.x, src.y);
|
|
|
|
return GFX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pxm->data) {
|
|
|
|
printf("Attempt to grab pixmap to unallocated memory\n");
|
|
|
|
return GFX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (map) {
|
|
|
|
|
|
|
|
case GFX_MASK_VISUAL:
|
2009-03-16 00:07:12 +00:00
|
|
|
pxm->width = src.width;
|
|
|
|
pxm->height = src.height;
|
|
|
|
for (int i = 0; i < src.height; i++) {
|
2009-06-06 10:21:48 +00:00
|
|
|
memcpy(pxm->data + i * src.width, _visual[0] + (i + src.y) * _mode->xsize + src.x, src.width);
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GFX_MASK_PRIORITY:
|
2009-02-21 14:11:41 +00:00
|
|
|
printf("FIXME: priority map grab not implemented yet!\n");
|
2009-02-15 06:10:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("Attempt to grab pixmap from invalid map 0x%02x\n", map);
|
|
|
|
return GFX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GFX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Buffer operations
|
|
|
|
|
2009-06-06 10:21:48 +00:00
|
|
|
int GfxDriver::update(rect_t src, Common::Point dest, gfx_buffer_t buffer) {
|
2009-02-15 06:10:59 +00:00
|
|
|
//TODO
|
|
|
|
|
|
|
|
/*
|
|
|
|
if (src.x != dest.x || src.y != dest.y) {
|
2009-03-16 00:07:12 +00:00
|
|
|
printf("Updating %d (%d,%d)(%dx%d) to (%d,%d) on %d\n", buffer, src.x, src.y, src.width, src.height, dest.x, dest.y, data_dest);
|
2009-02-15 06:10:59 +00:00
|
|
|
} else {
|
2009-03-16 00:07:12 +00:00
|
|
|
printf("Updating %d (%d,%d)(%dx%d) to %d\n", buffer, src.x, src.y, src.width, src.height, data_dest);
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
switch (buffer) {
|
|
|
|
case GFX_BUFFER_BACK:
|
2009-03-16 00:07:12 +00:00
|
|
|
for (int i = 0; i < src.height; i++) {
|
2009-06-06 10:21:48 +00:00
|
|
|
memcpy(_visual[0] + (dest.y + i) * _mode->xsize + dest.x,
|
|
|
|
_visual[1] + (src.y + i) * _mode->xsize + src.x, src.width);
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((src.x == dest.x) && (src.y == dest.y))
|
2009-06-06 10:21:48 +00:00
|
|
|
gfx_copy_pixmap_box_i(_priority[0], _priority[1], src);
|
2009-02-15 06:10:59 +00:00
|
|
|
break;
|
|
|
|
case GFX_BUFFER_FRONT:
|
2009-06-06 10:21:48 +00:00
|
|
|
g_system->copyRectToScreen(_visual[0] + src.x + src.y * _mode->xsize, _mode->xsize, dest.x, dest.y, src.width, src.height);
|
2009-02-24 12:01:28 +00:00
|
|
|
g_system->updateScreen();
|
2009-02-15 06:10:59 +00:00
|
|
|
break;
|
|
|
|
default:
|
2009-02-21 14:11:41 +00:00
|
|
|
GFXERROR("Invalid buffer %d in update!\n", buffer);
|
2009-02-15 06:10:59 +00:00
|
|
|
return GFX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GFX_OK;
|
|
|
|
}
|
|
|
|
|
2009-06-06 10:21:48 +00:00
|
|
|
int GfxDriver::setStaticBuffer(gfx_pixmap_t *pic, gfx_pixmap_t *priority) {
|
|
|
|
memcpy(_visual[1], pic->data, _mode->xsize * _mode->ysize);
|
|
|
|
gfx_copy_pixmap_box_i(_priority[1], priority, gfx_rect(0, 0, _mode->xsize, _mode->ysize));
|
2009-02-15 06:10:59 +00:00
|
|
|
|
|
|
|
return GFX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mouse pointer operations
|
|
|
|
|
2009-02-23 23:49:11 +00:00
|
|
|
// Scale cursor and map its colors to the global palette
|
2009-06-06 10:21:48 +00:00
|
|
|
byte *GfxDriver::createCursor(gfx_pixmap_t *pointer) {
|
2009-03-16 00:07:12 +00:00
|
|
|
int linewidth = pointer->width;
|
|
|
|
int lines = pointer->height;
|
2009-06-06 10:40:32 +00:00
|
|
|
byte *data = new byte[linewidth*lines];
|
2009-06-06 10:21:48 +00:00
|
|
|
byte *linebase = data, *pos;
|
|
|
|
byte *src = pointer->index_data;
|
2009-02-23 22:36:19 +00:00
|
|
|
|
2009-03-16 00:07:12 +00:00
|
|
|
for (int yc = 0; yc < pointer->index_height; yc++) {
|
2009-02-23 22:36:19 +00:00
|
|
|
pos = linebase;
|
|
|
|
|
2009-03-16 00:07:12 +00:00
|
|
|
for (int xc = 0; xc < pointer->index_width; xc++) {
|
2009-06-06 10:40:32 +00:00
|
|
|
byte color = *src;
|
2009-04-24 14:30:27 +00:00
|
|
|
// FIXME: The palette size check is a workaround for cursors using non-palette colour GFX_CURSOR_TRANSPARENT
|
2009-05-27 16:45:42 +00:00
|
|
|
// Note that some cursors don't have a palette in SQ5
|
|
|
|
if (pointer->palette && color < pointer->palette->size())
|
2009-03-08 20:17:01 +00:00
|
|
|
color = pointer->palette->getColor(color).parent_index;
|
2009-06-06 10:21:48 +00:00
|
|
|
for (int scalectr = 0; scalectr < _mode->xfact; scalectr++) {
|
2009-02-23 23:49:11 +00:00
|
|
|
*pos++ = color;
|
2009-02-23 22:36:19 +00:00
|
|
|
}
|
|
|
|
src++;
|
|
|
|
}
|
2009-06-06 10:21:48 +00:00
|
|
|
for (int scalectr = 1; scalectr < _mode->yfact; scalectr++)
|
2009-02-23 22:36:19 +00:00
|
|
|
memcpy(linebase + linewidth * scalectr, linebase, linewidth);
|
2009-06-06 10:21:48 +00:00
|
|
|
linebase += linewidth * _mode->yfact;
|
2009-02-23 22:36:19 +00:00
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-06 10:21:48 +00:00
|
|
|
int GfxDriver::setPointer(gfx_pixmap_t *pointer, Common::Point *hotspot) {
|
2009-04-24 12:30:57 +00:00
|
|
|
if ((pointer == NULL) || (hotspot == NULL)) {
|
2009-07-03 14:18:20 +00:00
|
|
|
CursorMan.showMouse(false);
|
2009-02-15 06:10:59 +00:00
|
|
|
} else {
|
2009-06-06 10:40:32 +00:00
|
|
|
byte *cursorData = createCursor(pointer);
|
2009-04-24 14:30:27 +00:00
|
|
|
|
2009-07-04 17:39:43 +00:00
|
|
|
// FIXME: The palette size check is a workaround for cursors using non-palette color GFX_CURSOR_TRANSPARENT
|
|
|
|
// Note that some cursors don't have a palette (e.g. in SQ5 and QFG3)
|
2009-06-06 10:40:32 +00:00
|
|
|
byte color_key = GFX_CURSOR_TRANSPARENT;
|
2009-05-27 16:45:42 +00:00
|
|
|
if ((pointer->color_key != GFX_PIXMAP_COLOR_KEY_NONE) && (pointer->palette && (unsigned int)pointer->color_key < pointer->palette->size()))
|
2009-04-24 14:30:27 +00:00
|
|
|
color_key = pointer->palette->getColor(pointer->color_key).parent_index;
|
2009-07-04 17:39:43 +00:00
|
|
|
// Some cursors don't have a palette, so we set the color key directly
|
2009-05-27 16:45:42 +00:00
|
|
|
if (!pointer->palette)
|
2009-07-04 17:39:43 +00:00
|
|
|
color_key = pointer->color_key;
|
2009-04-24 14:30:27 +00:00
|
|
|
|
2009-07-03 14:18:20 +00:00
|
|
|
CursorMan.replaceCursor(cursorData, pointer->width, pointer->height, hotspot->x, hotspot->y, color_key);
|
|
|
|
CursorMan.showMouse(true);
|
2009-06-05 23:08:35 +00:00
|
|
|
|
|
|
|
delete[] cursorData;
|
|
|
|
cursorData = 0;
|
2009-02-15 06:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return GFX_OK;
|
|
|
|
}
|
|
|
|
|
2009-02-21 10:23:36 +00:00
|
|
|
} // End of namespace Sci
|