SCI32: Expose a draw buffer on BitmapResource objects

Most of the time, we get a bitmap to draw on it. Exposing a buffer
avoids consumers having to create their own all the time, and
encourages use of common drawing code exposed by the buffer.
This commit is contained in:
Colin Snover 2016-06-21 16:00:05 -05:00
parent 521d2e299f
commit d6d0e00dc5
4 changed files with 21 additions and 15 deletions

View File

@ -619,9 +619,8 @@ reg_t kBitmapDrawText(EngineState *s, int argc, reg_t *argv) {
textRect.clip(Common::Rect(bitmap.getWidth(), bitmap.getHeight()));
reg_t textBitmapObject = g_sci->_gfxText32->createFontBitmap(textRect.width(), textRect.height(), Common::Rect(textRect.width(), textRect.height()), text, foreColor, backColor, skipColor, fontId, alignment, borderColor, dimmed, false);
Buffer bitmapBuffer(bitmap.getWidth(), bitmap.getHeight(), bitmap.getPixels());
CelObjMem textCel(textBitmapObject);
textCel.draw(bitmapBuffer, textRect, Common::Point(textRect.left, textRect.top), false);
textCel.draw(bitmap.getBuffer(), textRect, Common::Point(textRect.left, textRect.top), false);
s->_segMan->freeHunkEntry(textBitmapObject);
return s->r_acc;
@ -638,8 +637,7 @@ reg_t kBitmapDrawColor(EngineState *s, int argc, reg_t *argv) {
argv[4].toSint16() + 1
);
Buffer buffer(bitmap.getWidth(), bitmap.getHeight(), bitmap.getPixels());
buffer.fillRect(fillRect, argv[5].toSint16());
bitmap.getBuffer().fillRect(fillRect, argv[5].toSint16());
return s->r_acc;
}

View File

@ -191,6 +191,12 @@ struct Buffer : public Graphics::Surface {
uint16 scriptWidth;
uint16 scriptHeight;
Buffer() :
screenWidth(0),
screenHeight(0),
scriptWidth(320),
scriptHeight(200) {}
Buffer(const uint16 width, const uint16 height, uint8 *const pix) :
screenWidth(width),
screenHeight(height),

View File

@ -137,7 +137,6 @@ reg_t GfxText32::createFontBitmap(const CelInfo32 &celInfo, const Common::Rect &
BitmapResource bitmap(_segMan, _width, _height, _skipColor, 0, 0, _scaledWidth, _scaledHeight, 0, false);
_bitmap = bitmap.getObject();
Buffer buffer(_width, _height, bitmap.getPixels());
// NOTE: The engine filled the bitmap pixels with 11 here, which is silly
// because then it just erased the bitmap using the skip color. So we don't
@ -147,7 +146,7 @@ reg_t GfxText32::createFontBitmap(const CelInfo32 &celInfo, const Common::Rect &
erase(bitmapRect, false);
_backColor = backColor;
view.draw(buffer, bitmapRect, Common::Point(0, 0), false, Ratio(_scaledWidth, view._scaledWidth), Ratio(_scaledHeight, view._scaledHeight));
view.draw(bitmap.getBuffer(), bitmapRect, Common::Point(0, 0), false, Ratio(_scaledWidth, view._scaledWidth), Ratio(_scaledHeight, view._scaledHeight));
if (_backColor != skipColor && _foreColor != skipColor) {
erase(_textRect, false);
@ -616,14 +615,8 @@ Common::Rect GfxText32::getTextSize(const Common::String &text, int16 maxWidth,
void GfxText32::erase(const Common::Rect &rect, const bool doScaling) {
Common::Rect targetRect = doScaling ? scaleRect(rect) : rect;
byte *bitmap = _segMan->getHunkPointer(_bitmap);
byte *pixels = bitmap + READ_SCI11ENDIAN_UINT32(bitmap + 28);
// NOTE: There is an extra optimisation within the SCI code to
// do a single memset if the scaledRect is the same size as
// the bitmap, not implemented here.
Buffer buffer(_width, _height, pixels);
buffer.fillRect(targetRect, _backColor);
BitmapResource bitmap(_bitmap);
bitmap.getBuffer().fillRect(targetRect, _backColor);
}
int16 GfxText32::getStringWidth(const Common::String &text) {

View File

@ -26,6 +26,7 @@
#include "sci/engine/state.h"
#include "sci/graphics/celobj32.h"
#include "sci/graphics/frameout.h"
#include "sci/graphics/helpers.h"
namespace Sci {
@ -60,6 +61,7 @@ inline void set##property(uint##size value) {\
class BitmapResource {
byte *_bitmap;
reg_t _object;
Buffer _buffer;
/**
* Gets the size of the bitmap header for the current
@ -103,6 +105,8 @@ public:
if (_bitmap == nullptr || getUncompressedDataOffset() != getBitmapHeaderSize()) {
error("Invalid Text bitmap %04x:%04x", PRINT_REG(bitmap));
}
_buffer = Buffer(getWidth(), getHeight(), getPixels());
}
/**
@ -110,7 +114,6 @@ public:
* segment manager.
*/
inline BitmapResource(SegManager *segMan, const int16 width, const int16 height, const uint8 skipColor, const int16 displaceX, const int16 displaceY, const int16 scaledWidth, const int16 scaledHeight, const uint32 hunkPaletteOffset, const bool remap) {
_object = segMan->allocateHunkEntry("Bitmap()", getBitmapSize(width, height));
_bitmap = segMan->getHunkPointer(_object);
@ -131,12 +134,18 @@ public:
setControlOffset(0);
setScaledWidth(scaledWidth);
setScaledHeight(scaledHeight);
_buffer = Buffer(getWidth(), getHeight(), getPixels());
}
inline reg_t getObject() const {
return _object;
}
inline Buffer &getBuffer() {
return _buffer;
}
BITMAP_PROPERTY(16, Width, 0);
BITMAP_PROPERTY(16, Height, 2);