Replaced the remaining old string code with the new label code. All the text is now drawn in the framebuffer instead of being blitted onto the internal game screen buffer.

svn-id: r30360
This commit is contained in:
Nicola Mettifogo 2008-01-09 21:46:57 +00:00
parent 29d1749db5
commit bdf440fdae
8 changed files with 237 additions and 139 deletions

View File

@ -384,42 +384,36 @@ void Parallaction_ns::_c_frankenstein(void *parm) {
void Parallaction_ns::_c_finito(void *parm) {
const char **v8C = endMsg0;
const char **v7C = endMsg1;
const char **v6C = endMsg2;
const char **v5C = endMsg3;
const char **v4C = endMsg4;
const char **v3C = endMsg5;
const char **v2C = endMsg6;
const char **v1C = endMsg7;
setPartComplete(_char);
cleanInventory();
_gfx->setPalette(_gfx->_palette);
_gfx->setFont(_menuFont);
_gfx->setFontShadow(true);
uint id[4];
if (allPartsComplete()) {
_gfx->displayCenteredString(70, v4C[_language]);
_gfx->displayCenteredString(100, v3C[_language]);
_gfx->displayCenteredString(130, v2C[_language]);
_gfx->displayCenteredString(160, v1C[_language]);
id[0] = _gfx->createLabel(_menuFont, endMsg4[_language], 1);
id[1] = _gfx->createLabel(_menuFont, endMsg5[_language], 1);
id[2] = _gfx->createLabel(_menuFont, endMsg6[_language], 1);
id[3] = _gfx->createLabel(_menuFont, endMsg7[_language], 1);
} else {
id[0] = _gfx->createLabel(_menuFont, endMsg0[_language], 1);
id[1] = _gfx->createLabel(_menuFont, endMsg1[_language], 1);
id[2] = _gfx->createLabel(_menuFont, endMsg2[_language], 1);
id[3] = _gfx->createLabel(_menuFont, endMsg3[_language], 1);
}
_gfx->updateScreen();
waitUntilLeftClick();
_gfx->showLabel(id[0], CENTER_LABEL_HORIZONTAL, 70);
_gfx->showLabel(id[1], CENTER_LABEL_HORIZONTAL, 100);
_gfx->showLabel(id[2], CENTER_LABEL_HORIZONTAL, 130);
_gfx->showLabel(id[3], CENTER_LABEL_HORIZONTAL, 160);
waitUntilLeftClick();
_gfx->freeLabels();
if (allPartsComplete()) {
scheduleLocationSwitch("estgrotta.drki");
} else {
_gfx->displayCenteredString(70, v8C[_language]);
_gfx->displayCenteredString(100, v7C[_language]);
_gfx->displayCenteredString(130, v6C[_language]);
_gfx->displayCenteredString(160, v5C[_language]);
_gfx->updateScreen();
waitUntilLeftClick();
selectStartLocation();
}
@ -439,14 +433,12 @@ void Parallaction_ns::_c_testResult(void *parm) {
_disk->selectArchive("disk1");
parseLocation("common");
_gfx->setFont(_menuFont);
_gfx->setFontShadow(true);
uint id[2];
id[0] = _gfx->createLabel(_menuFont, _slideText[0], 1);
id[1] = _gfx->createLabel(_menuFont, _slideText[1], 1);
_gfx->displayCenteredString(38, _slideText[0]);
_gfx->displayCenteredString(58, _slideText[1]);
_gfx->copyScreen(Gfx::kBitFront, Gfx::kBitBack);
_gfx->copyScreen(Gfx::kBitFront, Gfx::kBit2);
_gfx->showLabel(id[0], CENTER_LABEL_HORIZONTAL, 38);
_gfx->showLabel(id[1], CENTER_LABEL_HORIZONTAL, 58);
return;
}
@ -485,14 +477,15 @@ void Parallaction_ns::_c_startIntro(void *parm) {
void Parallaction_ns::_c_endIntro(void *parm) {
_gfx->setFont(_menuFont);
_gfx->setFontShadow(true);
debugC(1, kDebugExec, "endIntro()");
uint id[2];
for (uint16 _si = 0; _si < 6; _si++) {
_gfx->displayCenteredString(80, _credits[_si]._role);
_gfx->displayCenteredString(100, _credits[_si]._name);
id[0] = _gfx->createLabel(_menuFont, _credits[_si]._role, 1);
id[1] = _gfx->createLabel(_menuFont, _credits[_si]._name, 1);
_gfx->showLabel(id[0], CENTER_LABEL_HORIZONTAL, 80);
_gfx->showLabel(id[1], CENTER_LABEL_HORIZONTAL, 100);
_gfx->updateScreen();
@ -505,18 +498,21 @@ void Parallaction_ns::_c_endIntro(void *parm) {
waitTime( 1 );
}
_gfx->copyScreen(Gfx::kBitBack, Gfx::kBitFront);
_gfx->freeLabels();
}
debugC(1, kDebugExec, "endIntro(): done showing credits");
_soundMan->stopMusic();
if ((getFeatures() & GF_DEMO) == 0) {
_gfx->displayCenteredString(80, "CLICK MOUSE BUTTON TO START");
_gfx->updateScreen();
id[0] = _gfx->createLabel(_menuFont, "CLICK MOUSE BUTTON TO START", 1);
_gfx->showLabel(id[0], CENTER_LABEL_HORIZONTAL, 80);
waitUntilLeftClick();
_gfx->freeLabels();
_engineFlags &= ~kEngineBlockInput;
selectStartLocation();

View File

@ -360,7 +360,7 @@ void Gfx::updateScreen() {
drawItems();
drawBalloons();
drawLabel();
drawLabels();
g_system->updateScreen();
return;
@ -541,17 +541,82 @@ Label *Gfx::renderFloatingLabel(Font *font, char *text) {
return label;
}
uint Gfx::createLabel(Font *font, const char *text, byte color) {
assert(_numLabels < MAX_NUM_LABELS);
void Gfx::setLabel(Label *label) {
_label = label;
Label *label = new Label;
Graphics::Surface *cnv = &label->_cnv;
if (_label) {
_label->resetPosition();
uint w, h;
if (_vm->getPlatform() == Common::kPlatformAmiga) {
w = font->getStringWidth(text) + 2;
h = font->height() + 2;
cnv->create(w, h, 1);
cnv->fillRect(Common::Rect(w,h), LABEL_TRANSPARENT_COLOR);
font->setColor(0);
font->drawString((byte*)cnv->getBasePtr(0, 2), cnv->pitch, text);
font->setColor(color);
font->drawString((byte*)cnv->getBasePtr(2, 0), cnv->pitch, text);
} else {
w = font->getStringWidth(text);
h = font->height();
cnv->create(w, h, 1);
cnv->fillRect(Common::Rect(w,h), LABEL_TRANSPARENT_COLOR);
font->setColor(color);
font->drawString((byte*)cnv->getBasePtr(0, 0), cnv->pitch, text);
}
uint id = _numLabels;
_labels[id] = label;
_numLabels++;
return id;
}
void Gfx::showLabel(uint id, int16 x, int16 y) {
assert(id < _numLabels);
_labels[id]->_visible = true;
if (x == CENTER_LABEL_HORIZONTAL) {
x = CLIP<int16>((_vm->_screenWidth - _labels[id]->_cnv.w) / 2, 0, _vm->_screenWidth/2);
}
if (y == CENTER_LABEL_VERTICAL) {
y = CLIP<int16>((_vm->_screenHeight - _labels[id]->_cnv.h) / 2, 0, _vm->_screenHeight/2);
}
_labels[id]->_pos.x = x;
_labels[id]->_pos.y = y;
}
void Gfx::hideLabel(uint id) {
assert(id < _numLabels);
_labels[id]->_visible = false;
}
void Gfx::freeLabels() {
for (uint i = 0; i < _numLabels; i++) {
delete _labels[i];
}
_numLabels = 0;
}
void Gfx::setFloatingLabel(Label *label) {
_floatingLabel = label;
if (_floatingLabel) {
_floatingLabel->resetPosition();
}
}
void Gfx::drawLabel() {
if (!_label) {
void Gfx::updateFloatingLabel() {
if (!_floatingLabel) {
return;
}
@ -561,30 +626,67 @@ void Gfx::drawLabel() {
_vm->getCursorPos(cursor);
if (_vm->_activeItem._id != 0) {
_si = cursor.x + 16 - _label->_cnv.w/2;
_si = cursor.x + 16 - _floatingLabel->_cnv.w/2;
_di = cursor.y + 34;
} else {
_si = cursor.x + 8 - _label->_cnv.w/2;
_si = cursor.x + 8 - _floatingLabel->_cnv.w/2;
_di = cursor.y + 21;
}
if (_si < 0) _si = 0;
if (_di > 190) _di = 190;
if (_label->_cnv.w + _si > _vm->_screenWidth)
_si = _vm->_screenWidth - _label->_cnv.w;
if (_floatingLabel->_cnv.w + _si > _vm->_screenWidth)
_si = _vm->_screenWidth - _floatingLabel->_cnv.w;
_label->_pos.x = _si;
_label->_pos.y = _di;
_floatingLabel->_pos.x = _si;
_floatingLabel->_pos.y = _di;
}
Common::Rect r(_label->_cnv.w, _label->_cnv.h);
r.moveTo(_label->_pos);
void Gfx::drawLabels() {
if ((!_floatingLabel) && (_numLabels == 0)) {
return;
}
updateFloatingLabel();
Graphics::Surface* surf = g_system->lockScreen();
flatBlit(r, (byte*)_label->_cnv.getBasePtr(0, 0), surf, LABEL_TRANSPARENT_COLOR);
for (uint i = 0; i < _numLabels; i++) {
if (_labels[i]->_visible) {
Common::Rect r(_labels[i]->_cnv.w, _labels[i]->_cnv.h);
r.moveTo(_labels[i]->_pos);
flatBlit(r, (byte*)_labels[i]->_cnv.getBasePtr(0, 0), surf, LABEL_TRANSPARENT_COLOR);
}
}
if (_floatingLabel) {
Common::Rect r(_floatingLabel->_cnv.w, _floatingLabel->_cnv.h);
r.moveTo(_floatingLabel->_pos);
flatBlit(r, (byte*)_floatingLabel->_cnv.getBasePtr(0, 0), surf, LABEL_TRANSPARENT_COLOR);
}
g_system->unlockScreen();
}
Label::Label() {
resetPosition();
_visible = false;
}
Label::~Label() {
free();
}
void Label::free() {
_cnv.free();
resetPosition();
}
void Label::resetPosition() {
_pos.x = -1000;
_pos.y = -1000;
}
//
// Cnv management
@ -701,25 +803,6 @@ void Gfx::restoreGetBackground(const Common::Rect& r, byte *data) {
void Gfx::displayString(uint16 x, uint16 y, const char *text, byte color) {
byte *dst = (byte*)_buffers[kBitFront]->getBasePtr(x, y);
if (_fontShadow) {
dst = (byte*)_buffers[kBitFront]->getBasePtr(x-2, y+2);
_font->setColor(0);
_font->drawString(dst, _vm->_screenWidth, text);
}
dst = (byte*)_buffers[kBitFront]->getBasePtr(x, y);
_font->setColor(color);
_font->drawString(dst, _vm->_screenWidth, text);
}
void Gfx::displayCenteredString(uint16 y, const char *text) {
uint16 x = (_vm->_screenWidth - getStringWidth(text)) / 2;
displayString(x, y, text, 1);
}
uint16 Gfx::getStringWidth(const char *text) {
return _font->getStringWidth(text);
}
@ -865,7 +948,8 @@ Gfx::Gfx(Parallaction* vm) :
_numBalloons = 0;
_numItems = 0;
_label = 0;
_numLabels = 0;
_floatingLabel = 0;
_screenX = 0;
_screenY = 0;

View File

@ -220,6 +220,25 @@ public:
};
#define CENTER_LABEL_HORIZONTAL -1
#define CENTER_LABEL_VERTICAL -1
struct Label {
Graphics::Surface _cnv;
Common::Point _pos;
bool _visible;
Label();
~Label();
void free();
void resetPosition();
};
#define NUM_BUFFERS 4
#define MAX_BALLOON_WIDTH 130
@ -243,16 +262,19 @@ public:
public:
// balloons and text
void displayString(uint16 x, uint16 y, const char *text, byte color);
void displayCenteredString(uint16 y, const char *text);
uint16 getStringWidth(const char *text);
void getStringExtent(char *text, uint16 maxwidth, int16* width, int16* height);
// labels
Label *_label;
void setLabel(Label *label);
Label *_floatingLabel;
void setFloatingLabel(Label *label);
Label *renderFloatingLabel(Font *font, char *text);
uint createLabel(Font *font, const char *text, byte color);
void showLabel(uint id, int16 x, int16 y);
void hideLabel(uint id);
void freeLabels();
// cut/paste
void flatBlitCnv(Graphics::Surface *cnv, int16 x, int16 y, Gfx::Buffers buffer);
void flatBlitCnv(Frames *cnv, uint16 frame, int16 x, int16 y, Gfx::Buffers buffer);
@ -354,8 +376,13 @@ protected:
uint _numItems;
#define MAX_NUM_LABELS 5
Label* _labels[MAX_NUM_LABELS];
uint _numLabels;
void drawInventory();
void drawLabel();
void updateFloatingLabel();
void drawLabels();
void drawItems();
void drawBalloons();

View File

@ -127,9 +127,6 @@ void Parallaction_ns::guiStart() {
guiSplash();
_gfx->setFont(_introFont);
_gfx->setFontShadow(true);
_language = guiChooseLanguage();
_disk->setLanguage(_language);
@ -192,19 +189,21 @@ int Parallaction_ns::guiNewGame() {
const char **v14 = introMsg3;
_gfx->setFont(_menuFont);
_gfx->setFontShadow(true);
_disk->selectArchive("disk1");
setBackground("test", NULL, NULL);
_gfx->swapBuffers();
_gfx->displayCenteredString(50, v14[0]);
_gfx->displayCenteredString(70, v14[1]);
_gfx->displayCenteredString(100, v14[2]);
_gfx->displayCenteredString(120, v14[3]);
uint id[4];
id[0] = _gfx->createLabel(_menuFont, v14[0], 1);
id[1] = _gfx->createLabel(_menuFont, v14[1], 1);
id[2] = _gfx->createLabel(_menuFont, v14[2], 1);
id[3] = _gfx->createLabel(_menuFont, v14[3], 1);
_gfx->showLabel(id[0], CENTER_LABEL_HORIZONTAL, 50);
_gfx->showLabel(id[1], CENTER_LABEL_HORIZONTAL, 70);
_gfx->showLabel(id[2], CENTER_LABEL_HORIZONTAL, 100);
_gfx->showLabel(id[3], CENTER_LABEL_HORIZONTAL, 120);
showCursor(false);
@ -217,6 +216,8 @@ int Parallaction_ns::guiNewGame() {
showCursor(true);
_gfx->freeLabels();
if (_mouseButtons != kMouseRightUp) {
return START_INTRO;
}
@ -259,7 +260,10 @@ uint16 Parallaction_ns::guiChooseLanguage() {
// user can choose language in dos version
showSlide("lingua");
_gfx->displayString(60, 30, "SELECT LANGUAGE", 1);
uint id = _gfx->createLabel(_introFont, "SELECT LANGUAGE", 1);
_gfx->showLabel(id, 60, 30);
setArrowCursor();
int selection = -1;
@ -275,6 +279,8 @@ uint16 Parallaction_ns::guiChooseLanguage() {
beep();
_gfx->freeLabels();
return selection;
}
@ -288,6 +294,10 @@ uint16 Parallaction_ns::guiSelectGame() {
uint16 _si = 0;
uint16 _di = 3;
uint id0, id1;
id0 = _gfx->createLabel(_introFont, loadGameMsg[_language], 1);
id1 = _gfx->createLabel(_introFont, newGameMsg[_language], 1);
_mouseButtons = kMouseNone;
while (_mouseButtons != kMouseLeftUp) {
@ -296,23 +306,24 @@ uint16 Parallaction_ns::guiSelectGame() {
_si = (_mousePos.x > 160) ? 1 : 0;
if (_si != _di) {
_di = _si;
_gfx->copyScreen(Gfx::kBitBack, Gfx::kBitFront);
if (_si != 0) {
// load a game
_gfx->displayString(60, 30, loadGameMsg[_language], 1);
_gfx->hideLabel(id1);
_gfx->showLabel(id0, 60, 30);
} else {
// new game
_gfx->displayString(60, 30, newGameMsg[_language], 1);
_gfx->hideLabel(id0);
_gfx->showLabel(id1, 60, 30);
}
_di = _si;
}
_gfx->updateScreen();
g_system->delayMillis(30);
}
_gfx->freeLabels();
return _si ? LOAD_GAME : NEW_GAME;
}
@ -391,6 +402,10 @@ int Parallaction_ns::guiSelectCharacter() {
bool fail;
uint id[2];
id[0] = _gfx->createLabel(_introFont, introMsg1[_language], 1);
id[1] = _gfx->createLabel(_introFont, introMsg2[_language], 1);
while (true) {
points[0] = 0;
@ -398,7 +413,8 @@ int Parallaction_ns::guiSelectCharacter() {
points[2] = 0;
fail = false;
_gfx->displayString(60, 30, introMsg1[_language], 1); // displays message
_gfx->hideLabel(id[1]);
_gfx->showLabel(id[0], 60, 30);
_di = 0;
while (_di < PASSWORD_LEN) {
@ -437,14 +453,17 @@ int Parallaction_ns::guiSelectCharacter() {
}
_gfx->copyScreen(Gfx::kBitBack, Gfx::kBitFront);
_gfx->displayString(60, 30, introMsg2[_language], 1);
_gfx->hideLabel(id[0]);
_gfx->showLabel(id[1], 60, 30);
_gfx->updateScreen();
g_system->delayMillis(2000);
_gfx->copyScreen(Gfx::kBitBack, Gfx::kBitFront);
}
_gfx->freeLabels();
_gfx->setBlackPalette();
_gfx->updateScreen();

View File

@ -194,24 +194,6 @@ uint16 Zone::height() const {
return _bottom - _top;
}
Label::Label() {
resetPosition();
}
Label::~Label() {
free();
}
void Label::free() {
_cnv.free();
resetPosition();
}
void Label::resetPosition() {
_pos.x = -1000;
_pos.y = -1000;
}
Answer::Answer() {
_text = NULL;
_mood = 0;

View File

@ -257,17 +257,6 @@ struct TypeData {
}
};
struct Label {
Graphics::Surface _cnv;
Common::Point _pos;
Label();
~Label();
void free();
void resetPosition();
};
#define ZONENAME_LENGTH 32

View File

@ -320,12 +320,12 @@ void Parallaction::processInput(InputData *data) {
switch (data->_event) {
case kEvEnterZone:
debugC(2, kDebugInput, "processInput: kEvEnterZone");
_gfx->setLabel(data->_label);
_gfx->setFloatingLabel(data->_label);
break;
case kEvExitZone:
debugC(2, kDebugInput, "processInput: kEvExitZone");
_gfx->setLabel(0);
_gfx->setFloatingLabel(0);
break;
case kEvAction:
@ -340,7 +340,7 @@ void Parallaction::processInput(InputData *data) {
case kEvOpenInventory:
_procCurrentHoverItem = -1;
_hoverZone = NULL;
_gfx->setLabel(0);
_gfx->setFloatingLabel(0);
if (hitZone(kZoneYou, _mousePos.x, _mousePos.y) == 0) {
setArrowCursor();
}

View File

@ -184,7 +184,7 @@ void Parallaction_ns::setArrowCursor() {
debugC(1, kDebugInput, "setting mouse cursor to arrow");
// this stuff is needed to avoid artifacts with labels and selected items when switching cursors
_gfx->setLabel(0);
_gfx->setFloatingLabel(0);
_activeItem._id = 0;
_system->setMouseCursor(_mouseArrow, MOUSEARROW_WIDTH, MOUSEARROW_HEIGHT, 0, 0, 0);
@ -298,7 +298,8 @@ void Parallaction_ns::changeLocation(char *location) {
// WORKAROUND: this hideLabel has been added to avoid crashes caused by
// execution of label jobs after a location switch. The other workaround in
// Parallaction::runGame should have been rendered useless by this one.
_gfx->setLabel(0);
_gfx->setFloatingLabel(0);
_gfx->freeLabels();
_hoverZone = NULL;
if (_engineFlags & kEngineBlockInput) {
@ -320,10 +321,10 @@ void Parallaction_ns::changeLocation(char *location) {
if (locname.hasSlide()) {
showSlide(locname.slide());
_gfx->setFont(_menuFont);
_gfx->displayCenteredString(14, _slideText[0]); // displays text on screen
_gfx->updateScreen();
uint id = _gfx->createLabel(_menuFont, _slideText[0], 1);
_gfx->showLabel(id, CENTER_LABEL_HORIZONTAL, 14);
waitUntilLeftClick();
_gfx->freeLabels();
}
if (locname.hasCharacter()) {