* Made the Screen class use the new Surface class.

* Added Screen::drawRect() method.
* Added support for updating dirty rectangles.

svn-id: r41657
This commit is contained in:
Denis Kasak 2009-06-19 00:13:05 +00:00
parent 9d0b940af3
commit adef44e451
2 changed files with 52 additions and 32 deletions

View File

@ -31,16 +31,14 @@
namespace Draci {
Screen::Screen(DraciEngine *vm) : _vm(vm) {
_surface = new Graphics::Surface();
_surface->create(kScreenWidth, kScreenHeight, 1);
this->clearScreen();
_surface = new Surface(kScreenWidth, kScreenHeight);
_palette = new byte[4 * kNumColours];
setPaletteEmpty();
this->clearScreen();
}
Screen::~Screen() {
_surface->free();
delete[] _surface;
delete _surface;
delete[] _palette;
}
@ -50,7 +48,7 @@ void Screen::setPaletteEmpty(unsigned int numEntries) {
}
_vm->_system->setPalette(_palette, 0, numEntries);
_vm->_system->updateScreen();
copyToScreen();
}
void Screen::setPalette(byte *data, uint16 start, uint16 num) {
@ -73,49 +71,71 @@ void Screen::setPalette(byte *data, uint16 start, uint16 num) {
}
_vm->_system->setPalette(_palette, start, num);
_vm->_system->updateScreen();
copyToScreen();
}
void Screen::copyToScreen() const {
byte *ptr = (byte *)_surface->getBasePtr(0, 0);
Common::List<Common::Rect> *dirtyRects = _surface->getDirtyRects();
Common::List<Common::Rect>::iterator it;
if (_surface->needsFullUpdate()) {
byte *ptr = (byte *)_surface->getBasePtr(0, 0);
_vm->_system->copyRectToScreen(ptr, kScreenWidth, 0, 0,
kScreenWidth, kScreenHeight);
_vm->_system->copyRectToScreen(ptr, kScreenWidth,
0, 0, kScreenWidth, kScreenHeight);
} else {
for (it = dirtyRects->begin(); it != dirtyRects->end(); ++it) {
byte *ptr = (byte *)_surface->getBasePtr(it->left, it->top);
_vm->_system->copyRectToScreen(ptr, kScreenWidth,
it->left, it->top, it->width(), it->height());
}
}
_vm->_system->updateScreen();
_surface->markClean();
}
void Screen::clearScreen() const {
byte *ptr = (byte *)_surface->getBasePtr(0, 0);
_surface->markDirty();
memset(ptr, 0, kScreenWidth * kScreenHeight);
}
void Screen::drawSprite(const Sprite &s) const {
byte *dst = (byte *)_surface->getBasePtr(s._x, s._y);
byte *src = s._data;
for (unsigned int i = 0; i < s._height; ++i) {
for(unsigned int j = 0; j < s._width; ++j) {
dst[j] = *src++;
}
dst += _surface->pitch;
}
}
void Screen::fillScreen(uint16 colour) const {
byte *ptr = (byte *)_surface->getBasePtr(0, 0);
_surface->markDirty();
memset(ptr, colour, kScreenWidth * kScreenHeight);
}
void Screen::drawRect(Common::Rect &r, uint8 colour) {
r.clip(_surface->w, _surface->h);
if (r.isEmpty())
return;
byte *ptr = (byte *)_surface->getBasePtr(r.left, r.top);
for (uint16 i = 0; i < r.width(); ++i) {
for (uint16 j = 0; j < r.height(); ++j) {
ptr[j * kScreenWidth + i] = colour;
}
}
_surface->markDirtyRect(r);
}
byte *Screen::getPalette() const {
return _palette;
}
Graphics::Surface *Screen::getSurface() {
Draci::Surface *Screen::getSurface() {
return _surface;
}

View File

@ -26,8 +26,7 @@
#ifndef DRACI_SCREEN_H
#define DRACI_SCREEN_H
#include "graphics/surface.h"
#include "draci/surface.h"
#include "draci/sprite.h"
namespace Draci {
@ -35,8 +34,8 @@ namespace Draci {
enum ScreenParameters {
kScreenWidth = 320,
kScreenHeight = 200,
kNumColours = 256
kNumColours = 256,
kDefaultTransparent = 255
};
class DraciEngine;
@ -54,10 +53,11 @@ public:
void clearScreen() const;
void drawSprite(const Sprite &s) const;
void fillScreen(uint16 colour) const;
Graphics::Surface *getSurface();
Surface *getSurface();
void drawRect(Common::Rect &r, uint8 colour);
private:
Graphics::Surface *_surface;
Surface *_surface;
byte *_palette;
DraciEngine *_vm;
};