ASYLUM: Implement Encounter::drawText()

- Remove unused ResourcePack::count() method
- Add proper text centering calculation to drawText()

git-svn-id: http://asylumengine.googlecode.com/svn/trunk@660 0bfb4aae-4ea4-11de-8d8d-752d95cf3e3c
This commit is contained in:
Julien Templier 2010-12-06 18:05:18 +00:00 committed by Eugene Sandulenko
parent 1ea8f311a9
commit 5b43d804d9
No known key found for this signature in database
GPG Key ID: 014D387312D34F08
5 changed files with 54 additions and 19 deletions

View File

@ -58,7 +58,7 @@ Encounter::Encounter(AsylumEngine *engine) : _vm(engine),
_value1 = 0;
_tick = 0;
_data_455B14 = 0;
_data_455B3C = false;
_data_455B3C = 0;
_data_455B70 = 0;
_data_455BCC = false;
_data_455BD0 = false;
@ -328,7 +328,7 @@ bool Encounter::init() {
_data_455BE0 = false;
_data_455BE4 = false;
_data_455BCC = false;
_data_455B3C = true;
_data_455B3C = 1;
_rectIndex = -1;
_value1 = 0;
_data_455BF4 = 0;
@ -687,7 +687,7 @@ void Encounter::resetSpeech(uint32 keywordIndex, uint32 a2) {
setupPortraits();
_data_455BCC = false;
_data_455B3C = false;
_data_455B3C = 1;
if (keywordIndex) {
getSpeech()->setTextResourceId(keywordIndex + a2);
@ -751,7 +751,7 @@ void Encounter::setupSpeechText() {
}
_data_455BCC = false;
_data_455B3C = true;
_data_455B3C = 1;
}
void Encounter::setupSpeech(ResourceId textResourceId, ResourceId fontResourceId) {
@ -793,7 +793,7 @@ bool Encounter::setupSpeech(ResourceId id) {
getSpeech()->setTextDataPos(0);
_data_455BCC = false;
_data_455B3C = true;
_data_455B3C = 1;
setupPortraits();
@ -1119,10 +1119,27 @@ void Encounter::drawText(char *text, ResourceId font, int32 y) {
if (!text)
return;
//int width = _background.rect.width() - _portrait1.rect.width() - _portrait2.rect.width() - 20;
//int x = _point.x + _portrait1.rect.width() + 10;
int width = _background.rect.width() - _portrait1.rect.width() - _portrait2.rect.width() - 20;
int x = _point.x + _portrait1.rect.width() + 10;
error("[Encounter::drawText] not implemented!");
getText()->loadFont(font);
if (_data_455BCC) {
if (_data_455B3C != 1 && _tick < _vm->getTick()) {
_tick = _vm->getTick() + 1000 * getResource()->get(getSpeech()->getSoundResourceId())->size / 11025 / _data_455B3C;
if ((_data_455BF0 + 8) < _data_455B70)
_data_455BF0 += 8;
}
} else {
_data_455BCC = true;
_data_455B70 = getText()->draw(kTextCalculate, x, y, 16, width, text);
_data_455B3C = _data_455B70 / 8 + 1;
_data_455BF0 = 0;
_tick = _vm->getTick() + 1000 * getResource()->get(getSpeech()->getSoundResourceId())->size / 11025 / _data_455B3C;
}
getText()->draw(_data_455BF0, 7, kTextCenter, x, y, 16, width, text);
}
void Encounter::drawScreen() {

View File

@ -141,7 +141,7 @@ private:
// Internal data
int32 _data_455B14;
bool _data_455B3C;
uint32 _data_455B3C;
uint32 _data_455B70;
bool _data_455BCC;
bool _data_455BD0;

View File

@ -55,7 +55,6 @@ struct ResourceEntry {
class ResourcePack {
public:
ResourceEntry *get(uint16 index);
int count();
protected:
ResourcePack(Common::String filename);

View File

@ -171,17 +171,17 @@ void Text::draw(int32 x, int32 y, ResourceId resourceId) {
void Text::draw(const char *text, ResourceId fontResourceId, int32 y) {
if (text) {
loadFont(fontResourceId);
draw(true, 20, y, 16, 600, text);
draw(kTextCenter, 20, y, 16, 600, text);
}
}
void Text::draw(bool isCentered, int32 x, int32 y, int32 spacing, int32 width, const char *text) {
draw(0, 99, isCentered, x, y, spacing, width, text);
uint32 Text::draw(TextCentering centering, int32 x, int32 y, int32 spacing, int32 width, const char *text) {
return draw(0, 99, centering, x, y, spacing, width, text);
}
void Text::draw(int32 a1, int32 a2, bool isCentered, int32 x, int32 y, int32 spacing, int32 width, const char *text) {
uint32 Text::draw(int32 a1, int32 a2, TextCentering centering, int32 x, int32 y, int32 spacing, int32 width, const char *text) {
if (!text || !*text)
return;
return 0;
bool drawText = false;
int32 charWidth = 0;
@ -191,6 +191,8 @@ void Text::draw(int32 a1, int32 a2, bool isCentered, int32 x, int32 y, int32 spa
const char *string = text;
const char *endText = text;
uint32 printed = 0;
for (;;) {
label_start:
@ -201,14 +203,23 @@ label_start:
char currentChar = *endText;
if (index >= a1 && index <= (a1 + 2)) {
if (isCentered) {
switch (centering) {
default:
case kTextCalculate:
break;
case kTextCenter:
drawCentered(x, y, width, endText - string, string);
} else {
break;
case kTextNormal:
setPosition(x, y);
draw(text, endText - text);
break;
}
y += spacing;
++printed;
}
++index;
@ -271,6 +282,8 @@ label_start:
endText = txt;
drawText = true;
}
return printed;
}
void Text::drawCentered(int32 x, int32 y, int32 width, const char *text) {

View File

@ -36,6 +36,12 @@ class AsylumEngine;
class GraphicResource;
class ResourcePack;
enum TextCentering {
kTextNormal,
kTextCenter,
kTextCalculate
};
class Text {
public:
Text(AsylumEngine *engine);
@ -57,8 +63,8 @@ public:
void draw(int32 x, int32 y, ResourceId resourceId);
void draw(const char *text, ResourceId fontResourceId, int32 y);
void draw(const char *text, uint32 length);
void draw(bool isCentered, int32 x, int32 y, int32 spacing, int32 width, const char *text);
void draw(int32 a1, int32 a2, bool isCentered, int32 x, int32 y, int32 spacing, int32 width, const char *text);
uint32 draw(TextCentering centering, int32 x, int32 y, int32 spacing, int32 width, const char *text);
uint32 draw(int32 a1, int32 a2, TextCentering centering, int32 x, int32 y, int32 spacing, int32 width, const char *text);
void drawCentered(int32 x, int32 y, int32 width, const char *text);
void drawCentered(int32 x, int32 y, int32 width, ResourceId resourceId);