Skip to content

Commit

Permalink
DIRECTOR: Load Shared Cast Bitmaps (anchor point is incorrect).
Browse files Browse the repository at this point in the history
More Text Cast Formatting.
  • Loading branch information
stevenhoefel committed Jan 10, 2017
1 parent 66624ef commit 19b0cc7
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 51 deletions.
5 changes: 4 additions & 1 deletion engines/director/archive.cpp
Expand Up @@ -408,7 +408,10 @@ bool RIFXArchive::openStream(Common::SeekableReadStream *stream, uint32 startOff
keyRes = &resources[resources.size() - 1];
else if (tag == MKTAG('C', 'A', 'S', '*'))
casRes = &resources[resources.size() - 1];
else
//or the children of
else if (tag == MKTAG('S', 'T', 'X', 'T') ||
tag == MKTAG('B', 'I', 'T', 'D') ||
tag == MKTAG('D', 'I', 'B', ' '))
_types[tag][i] = res;
}

Expand Down
24 changes: 20 additions & 4 deletions engines/director/cast.cpp
Expand Up @@ -62,10 +62,8 @@ BitmapCast::BitmapCast(Common::ReadStreamEndian &stream, uint16 version) {
}

TextCast::TextCast(Common::ReadStreamEndian &stream, uint16 version) {
if (version < 5) {
if (version <= 3)
flags1 = stream.readByte();

if (version < 4) {
flags1 = stream.readByte();
borderSize = static_cast<SizeType>(stream.readByte());
gutterSize = static_cast<SizeType>(stream.readByte());
boxShadow = static_cast<SizeType>(stream.readByte());
Expand Down Expand Up @@ -93,6 +91,24 @@ TextCast::TextCast(Common::ReadStreamEndian &stream, uint16 version) {
// TODO: FIXME: guesswork
fontId = stream.readByte();
fontSize = stream.readByte();
} else if (version < 5) {
borderSize = static_cast<SizeType>(stream.readByte());
gutterSize = static_cast<SizeType>(stream.readByte());
boxShadow = static_cast<SizeType>(stream.readByte());
textType = static_cast<TextType>(stream.readByte());
textAlign = static_cast<TextAlignType>(stream.readSint16()); //this is because 'right' is -1? or should that be 255?
stream.readUint16();
stream.readUint16();
stream.readUint16();
stream.readUint16();

fontId = 1; //this is in STXT

initialRect = Score::readRect(stream);
stream.readUint16();
textShadow = static_cast<SizeType>(stream.readByte());
byte flags = stream.readByte();
fontSize = stream.readUint16();
} else {
initialRect = Score::readRect(stream);
boundingRect = Score::readRect(stream);
Expand Down
3 changes: 2 additions & 1 deletion engines/director/cast.h
Expand Up @@ -121,8 +121,9 @@ struct TextCast : Cast {
TextType textType;
TextAlignType textAlign;
SizeType textShadow;
byte textSlant;
Common::Array<TextFlag> textFlags;
int16 palinfo1, palinfo2, palinfo3;
uint16 palinfo1, palinfo2, palinfo3;
};

enum ButtonType {
Expand Down
111 changes: 68 additions & 43 deletions engines/director/frame.cpp
Expand Up @@ -545,10 +545,10 @@ void Frame::renderSprites(Graphics::ManagedSurface &surface, bool renderTrail) {
if (_vm->getVersion() < 4) {
switch (_sprites[i]->_spriteType) {
case 0x01:
case 0x0c: //this is actually a mouse-over shape? I don't think it's a real button.
castType = kCastBitmap;
break;
case 0x02:
case 0x0c: //this is actually a mouse-over shape? I don't think it's a real button.
castType = kCastShape;
break;
case 0x07:
Expand Down Expand Up @@ -730,11 +730,19 @@ Image::ImageDecoder *Frame::getImageFrom(uint16 spriteId) {
return img;
}

if (_vm->_currentScore->getArchive()->hasResource(MKTAG('B', 'I', 'T', 'D'), imgId)) {
Common::SeekableReadStream *pic = _vm->_currentScore->getArchive()->getResource(MKTAG('B', 'I', 'T', 'D'), imgId);
Common::SeekableReadStream *pic = NULL;
BitmapCast *bc = NULL;

if (_vm->getSharedBMP() != NULL && _vm->getSharedBMP()->contains(imgId)) {
pic = _vm->getSharedBMP()->getVal(imgId);
bc = static_cast<BitmapCast *>(_vm->getSharedCasts()->getVal(spriteId));
} else if (_vm->_currentScore->getArchive()->hasResource(MKTAG('B', 'I', 'T', 'D'), imgId)) {
pic = _vm->_currentScore->getArchive()->getResource(MKTAG('B', 'I', 'T', 'D'), imgId);
bc = static_cast<BitmapCast *>(_vm->_currentScore->_casts[spriteId]);
}

if (pic != NULL && bc != NULL) {
if (_vm->getVersion() < 4) {
BitmapCast *bc = static_cast<BitmapCast *>(_vm->_currentScore->_casts[spriteId]);
int w = bc->initialRect.width(), h = bc->initialRect.height();

debugC(2, kDebugImages, "id: %d, w: %d, h: %d, flags: %x, some: %x, unk1: %d, unk2: %d",
Expand Down Expand Up @@ -763,12 +771,6 @@ Image::ImageDecoder *Frame::getImageFrom(uint16 spriteId) {
return img;
}

if (_vm->getSharedBMP() != NULL && _vm->getSharedBMP()->contains(imgId)) {
img = new Image::BitmapDecoder();
img->loadStream(*_vm->getSharedBMP()->getVal(imgId));
return img;
}

warning("Image %d not found", spriteId);
return img;
}
Expand All @@ -783,6 +785,11 @@ void Frame::renderText(Graphics::ManagedSurface &surface, uint16 spriteID, uint1
textStream = _vm->getSharedSTXT()->getVal(spriteID + 1024);
}

byte buf[1024];
textStream->read(buf, textStream->size());

This comment has been minimized.

Copy link
@sev-

sev- Jan 10, 2017

Member

That cries for a buffer overflow

This comment has been minimized.

Copy link
@stevenhoefel

stevenhoefel Jan 10, 2017

Author Contributor

Apologies, this is debug text and should be wrapped in an if statement checking if the debug channel is enabled.

textStream->seek(0);
Common::hexdump(buf, textStream->size());

renderText(surface, spriteID, textStream, false);
}

Expand All @@ -792,8 +799,6 @@ void Frame::renderText(Graphics::ManagedSurface &surface, uint16 spriteID, Commo
uint16 castID = _sprites[spriteID]->_castId;
TextCast *textCast = static_cast<TextCast *>(_vm->_currentScore->_casts[castID]);



uint32 unk1 = textStream->readUint32();
uint32 strLen = textStream->readUint32();
uint32 dataLen = textStream->readUint32();
Expand All @@ -811,6 +816,21 @@ void Frame::renderText(Graphics::ManagedSurface &surface, uint16 spriteID, Commo
if (strLen < 200)
debugC(3, kDebugText, "text: '%s'", text.c_str());

if (_vm->getVersion() >= 4) {
uint16 a = textStream->readUint16();
uint32 b = textStream->readUint32();
uint16 c = textStream->readUint16();
uint16 d = textStream->readUint16();
textCast->fontId = textStream->readUint16();
textCast->textSlant = textStream->readByte();
textStream->readByte();
textCast->fontSize = textStream->readUint16();

textCast->palinfo1 = textStream->readUint16();
textCast->palinfo2 = textStream->readUint16();
textCast->palinfo3 = textStream->readUint16();
}

uint32 rectLeft = textCast->initialRect.left;
uint32 rectTop = textCast->initialRect.top;

Expand All @@ -819,7 +839,7 @@ void Frame::renderText(Graphics::ManagedSurface &surface, uint16 spriteID, Commo
int height = _sprites[spriteID]->_height;
int width = _sprites[spriteID]->_width;

Graphics::MacFont macFont(textCast->fontId, textCast->fontSize);
Graphics::MacFont macFont(textCast->fontId, textCast->fontSize, textCast->textSlant);

if (_vm->_currentScore->_fontMap.contains(textCast->fontId)) {
// Override
Expand All @@ -830,48 +850,53 @@ void Frame::renderText(Graphics::ManagedSurface &surface, uint16 spriteID, Commo

debugC(3, kDebugText, "renderText: x: %d y: %d w: %d h: %d font: '%s'", x, y, width, height, _vm->_wm->_fontMan->getFontName(macFont));

uint16 boxShadow = (uint16)textCast->boxShadow;
uint16 borderSize = (uint16)textCast->borderSize;
uint16 padding = (uint16)textCast->gutterSize;
uint16 textShadow = (uint16)textCast->textShadow;

int alignment = (int)textCast->textAlign;
if (alignment == 0xff) alignment = 3;
else alignment++;


if (textShadow > 0) {
font->drawString(&surface, text,
x + borderSize + padding + textShadow,
y + (borderSize / 2) + (padding / 2) + (textShadow - 1),
width, (_sprites[spriteID]->_ink == kInkTypeReverse ? 255 : 0), (Graphics::TextAlign)alignment);
}

//TODO: the colour is wrong here... need to determine the correct colour for all versions!
font->drawString(&surface, text, x, y, width, (_sprites[spriteID]->_ink == kInkTypeReverse ? 255 : 0), (Graphics::TextAlign)textCast->textAlign);
font->drawString(&surface, text,
x + borderSize + padding,
y + (borderSize / 2) + (padding / 2) - (textShadow > 0 ? 1 : 0),
width, (_sprites[spriteID]->_ink == kInkTypeReverse ? 255 : 0), (Graphics::TextAlign)alignment);

if (isButtonLabel)
return;

if (textCast->borderSize != kSizeNone) {
uint16 size = textCast->borderSize;

// Indent from borders, measured in d4
x -= 1;
y -= 4;
if (borderSize != kSizeNone) {

This comment has been minimized.

Copy link
@sev-

sev- Jan 10, 2017

Member

Somewhere this broke text rendering in The Apartment

This comment has been minimized.

Copy link
@stevenhoefel

stevenhoefel Jan 10, 2017

Author Contributor

Actually, text rendering is fine, as the text in the menu on the left in "The Apartment" is actually a single bitmap. There are shapes over the menu on the left which are currently being drawn as filled rectangles, these need to be invisible to accept the click handlers.
The only text on the first screen in The Apartment is on the right, the "Press enter..." which needs to have wrapping and auto-height implemented.

x += (borderSize / 2);
y += (borderSize / 2);

height += 4;
width += 1;
width += (padding * 2);
height += 6 + (padding);

while (size) {
surface.frameRect(Common::Rect(x, y, x + height, y + width), 0);
x--;
y--;
while (borderSize) {
height += 2;
width += 2;
size--;
x--;
y--;
surface.frameRect(Common::Rect(x, y, x + width, y + height), 0);
borderSize--;
}
}

if (textCast->gutterSize != kSizeNone) {
x -= 1;
y -= 4;

height += 4;
width += 1;
uint16 size = textCast->gutterSize;

surface.frameRect(Common::Rect(x, y, x + height, y + width), 0);

while (size) {
surface.drawLine(x + width, y, x + width, y + height, 0);
surface.drawLine(x, y + height, x + width, y + height, 0);
x++;
y++;
size--;
if (boxShadow > 0) {
for (int loop = 0; loop < boxShadow; loop++) {
surface.drawLine(x + boxShadow, y + height + loop, x + width, y + height + loop, 0);
surface.drawLine(x + width + loop, y + boxShadow, x + width + loop, y + height + boxShadow - 1, 0);
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions graphics/macgui/macfontmanager.h
Expand Up @@ -48,8 +48,13 @@ enum {

enum {
kMacFontRegular,
kMacFontBold,
kMacFontItalic
kMacFontBold = 1,
kMacFontItalic = 2,

This comment has been minimized.

Copy link
@sev-

sev- Jan 10, 2017

Member

You could use shifts here, e.g. 1 << 0, 1 << 1, etc. Could help readability

kMacFontUnderline = 4,
kMacFontOutline = 8,
kMacFontShadow = 16,
kMacFontCondense = 32,
kMacFontExtend = 64,
};

class BdfFont;
Expand Down

1 comment on commit 19b0cc7

@wjp
Copy link
Contributor

@wjp wjp commented on 19b0cc7 Jan 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also review our commit message guidelines on the wiki.

Please sign in to comment.