From 48959935880a991d14768dac66f41c183eb0dd44 Mon Sep 17 00:00:00 2001 From: Denis Kasak Date: Wed, 1 Jul 2009 01:43:20 +0000 Subject: Added Text::setText() and Text::setColour() methods. Changed demo animation to use them. svn-id: r41984 --- engines/draci/draci.cpp | 26 +++++++++++++++++--------- engines/draci/sprite.cpp | 18 ++++++++++++++++-- engines/draci/sprite.h | 3 +++ 3 files changed, 36 insertions(+), 11 deletions(-) (limited to 'engines') diff --git a/engines/draci/draci.cpp b/engines/draci/draci.cpp index da81074655..3d8a6cc4f9 100644 --- a/engines/draci/draci.cpp +++ b/engines/draci/draci.cpp @@ -129,26 +129,30 @@ int DraciEngine::go() { Common::String testString = "Testing, testing, read all about it!"; xpos = (kScreenWidth - _font->getStringWidth(testString, 1)) / 2; ypos = 130; - Text txt1(testString, _font, kFontColour1, xpos, ypos, 1); + Text txt(testString, _font, kFontColour1, xpos, ypos, 1); - txt1.draw(surf); + txt.draw(surf); // Draw small string _font->setFont(kFontSmall); testString = "I'm smaller than the font above me."; xpos = (kScreenWidth - _font->getStringWidth(testString, 1)) / 2; ypos += 20; - Text txt2(testString, _font, kFontColour1, xpos, ypos, 1); + txt.setText(testString); + txt._x = xpos; + txt._y = ypos; - txt2.draw(surf); + txt.draw(surf); // Overflow handling test testString = "Checking overflooooooooooooooooooooooooow..."; xpos = 50; ypos += 20; - Text txt3(testString, _font, kFontColour1, xpos, ypos, 1); + txt.setText(testString); + txt._x = xpos; + txt._y = ypos; - txt3.draw(surf); + txt.draw(surf); _screen->copyToScreen(); @@ -162,6 +166,12 @@ int DraciEngine::go() { } testString = "I'm transparent"; + xpos = (kScreenWidth - _font->getStringWidth(testString, 1)) / 2; + ypos = 80; + txt.setText(testString); + txt.setColour(kDefaultTransparent); + txt._x = xpos; + txt._y = ypos; for (unsigned int t = 0; t < 25; ++t) { debugC(5, kDraciGeneralDebugLevel, "Drawing frame %d...", t); @@ -177,9 +187,7 @@ int DraciEngine::go() { sp.draw(surf); // Draw transparent text over dragon - _font->setColour(kDefaultTransparent); - _font->drawString(surf, testString, - (kScreenWidth - _font->getStringWidth(testString, 1)) / 2, 80, 1); + txt.draw(surf); _screen->copyToScreen(); _system->delayMillis(100); diff --git a/engines/draci/sprite.cpp b/engines/draci/sprite.cpp index 062499471d..b56727e15c 100644 --- a/engines/draci/sprite.cpp +++ b/engines/draci/sprite.cpp @@ -129,13 +129,13 @@ void Sprite::draw(Surface *surface) const { Text::Text(const Common::String &str, Font *font, byte fontColour, uint16 x, uint16 y, uint spacing) { uint len = str.size(); + _length = len; _x = x; _y = y; _text = new byte[len]; memcpy(_text, str.c_str(), len); - _length = len; _spacing = spacing; _colour = fontColour; @@ -144,7 +144,21 @@ Text::Text(const Common::String &str, Font *font, byte fontColour, } Text::~Text() { - delete _text; + delete[] _text; +} + +void Text::setText(const Common::String &str) { + delete[] _text; + + uint len = str.size(); + _length = len; + + _text = new byte[len]; + memcpy(_text, str.c_str(), len); +} + +void Text::setColour(byte fontColour) { + _colour = fontColour; } void Text::draw(Surface *surface) const { diff --git a/engines/draci/sprite.h b/engines/draci/sprite.h index 50b091e3d5..84c38527d4 100644 --- a/engines/draci/sprite.h +++ b/engines/draci/sprite.h @@ -78,6 +78,9 @@ public: uint16 x = 0, uint16 y = 0, uint spacing = 0); ~Text(); + void setText(const Common::String &str); + void setColour(byte fontColour); + void draw(Surface *surface) const; byte *_text; -- cgit v1.2.3