[Scummvm-cvs-logs] SF.net SVN: scummvm: [32902] scummvm/trunk/engines/parallaction

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Fri Jul 4 02:29:21 CEST 2008


Revision: 32902
          http://scummvm.svn.sourceforge.net/scummvm/?rev=32902&view=rev
Author:   peres001
Date:     2008-07-03 17:29:21 -0700 (Thu, 03 Jul 2008)

Log Message:
-----------
- Moved dialogue balloon management code from Gfx to its own class
- Added a class to draw balloons in BRA (still without text and with wrong placement)

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/callables_ns.cpp
    scummvm/trunk/engines/parallaction/dialogue.cpp
    scummvm/trunk/engines/parallaction/exec_br.cpp
    scummvm/trunk/engines/parallaction/exec_ns.cpp
    scummvm/trunk/engines/parallaction/graphics.cpp
    scummvm/trunk/engines/parallaction/graphics.h
    scummvm/trunk/engines/parallaction/gui_br.cpp
    scummvm/trunk/engines/parallaction/input.cpp
    scummvm/trunk/engines/parallaction/module.mk
    scummvm/trunk/engines/parallaction/parallaction.cpp
    scummvm/trunk/engines/parallaction/parallaction.h
    scummvm/trunk/engines/parallaction/parallaction_br.cpp

Added Paths:
-----------
    scummvm/trunk/engines/parallaction/balloons.cpp

Added: scummvm/trunk/engines/parallaction/balloons.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/balloons.cpp	                        (rev 0)
+++ scummvm/trunk/engines/parallaction/balloons.cpp	2008-07-04 00:29:21 UTC (rev 32902)
@@ -0,0 +1,456 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "parallaction/graphics.h"
+#include "parallaction/parallaction.h"
+
+namespace Parallaction {
+
+
+#define	BALLOON_TRANSPARENT_COLOR_NS 2
+#define BALLOON_TRANSPARENT_COLOR_BR 0
+
+#define BALLOON_TAIL_WIDTH	12
+#define BALLOON_TAIL_HEIGHT	10
+
+
+byte _resBalloonTail[2][BALLOON_TAIL_WIDTH*BALLOON_TAIL_HEIGHT] = {
+	{
+	  0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02,
+	  0x02, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02,
+	  0x02, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02,
+	  0x02, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02,
+	  0x02, 0x02, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02,
+	  0x02, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02,
+	  0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02,
+	  0x02, 0x00, 0x01, 0x01, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
+	  0x00, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
+	  0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
+	},
+	{
+	  0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02,
+	  0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x02, 0x02, 0x02,
+	  0x02, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02,
+	  0x02, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02,
+	  0x02, 0x00, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
+	  0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02,
+	  0x02, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02,
+	  0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02,
+	  0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x01, 0x01, 0x00, 0x02, 0x02,
+	  0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x02, 0x02
+	}
+};
+
+class BalloonManager_ns : public BalloonManager {
+
+	static int16 _dialogueBalloonX[5];
+
+	struct Balloon {
+		Common::Rect outerBox;
+		Common::Rect innerBox;
+		Graphics::Surface *surface;
+		GfxObj	*obj;
+	} _intBalloons[5];
+
+	uint	_numBalloons;
+
+	void drawWrappedText(Font *font, Graphics::Surface* surf, char *text, byte color, int16 wrapwidth);
+	int createBalloon(int16 w, int16 h, int16 winding, uint16 borderThickness);
+	Balloon *getBalloon(uint id);
+
+	Gfx *_gfx;
+
+public:
+	BalloonManager_ns(Gfx *gfx);
+	~BalloonManager_ns();
+
+	void freeBalloons();
+	int setLocationBalloon(char *text, bool endGame);
+	int setDialogueBalloon(char *text, uint16 winding, byte textColor);
+	int setSingleBalloon(char *text, uint16 x, uint16 y, uint16 winding, byte textColor);
+	void setBalloonText(uint id, char *text, byte textColor);
+	int hitTestDialogueBalloon(int x, int y);
+};
+
+int16 BalloonManager_ns::_dialogueBalloonX[5] = { 80, 120, 150, 150, 150 };
+
+BalloonManager_ns::BalloonManager_ns(Gfx *gfx) : _numBalloons(0), _gfx(gfx) {
+
+}
+
+BalloonManager_ns::~BalloonManager_ns() {
+
+}
+
+
+BalloonManager_ns::Balloon* BalloonManager_ns::getBalloon(uint id) {
+	assert(id < _numBalloons);
+	return &_intBalloons[id];
+}
+
+int BalloonManager_ns::createBalloon(int16 w, int16 h, int16 winding, uint16 borderThickness) {
+	assert(_numBalloons < 5);
+
+	int id = _numBalloons;
+
+	Balloon *balloon = &_intBalloons[id];
+
+	int16 real_h = (winding == -1) ? h : h + 9;
+	balloon->surface = new Graphics::Surface;
+	balloon->surface->create(w, real_h, 1);
+	balloon->surface->fillRect(Common::Rect(w, real_h), BALLOON_TRANSPARENT_COLOR_NS);
+
+	Common::Rect r(w, h);
+	balloon->surface->fillRect(r, 0);
+	balloon->outerBox = r;
+
+	r.grow(-borderThickness);
+	balloon->surface->fillRect(r, 1);
+	balloon->innerBox = r;
+
+	if (winding != -1) {
+		// draws tail
+		// TODO: this bitmap tail should only be used for Dos games. Amiga should use a polygon fill.
+		winding = (winding == 0 ? 1 : 0);
+		Common::Rect s(BALLOON_TAIL_WIDTH, BALLOON_TAIL_HEIGHT);
+		s.moveTo(r.width()/2 - 5, r.bottom - 1);
+		_gfx->blt(s, _resBalloonTail[winding], balloon->surface, LAYER_FOREGROUND, BALLOON_TRANSPARENT_COLOR_NS);
+	}
+
+	_numBalloons++;
+
+	return id;
+}
+
+
+int BalloonManager_ns::setSingleBalloon(char *text, uint16 x, uint16 y, uint16 winding, byte textColor) {
+
+	int16 w, h;
+
+	_gfx->getStringExtent(_vm->_dialogueFont, text, MAX_BALLOON_WIDTH, &w, &h);
+
+	int id = createBalloon(w+5, h, winding, 1);
+	Balloon *balloon = &_intBalloons[id];
+
+	_gfx->drawWrappedText(_vm->_dialogueFont, balloon->surface, text, textColor, MAX_BALLOON_WIDTH);
+
+	// TODO: extract some text to make a name for obj
+	balloon->obj = _gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
+	balloon->obj->x = x;
+	balloon->obj->y = y;
+	balloon->obj->transparentKey = BALLOON_TRANSPARENT_COLOR_NS;
+
+	return id;
+}
+
+int BalloonManager_ns::setDialogueBalloon(char *text, uint16 winding, byte textColor) {
+
+	int16 w, h;
+
+	_gfx->getStringExtent(_vm->_dialogueFont, text, MAX_BALLOON_WIDTH, &w, &h);
+
+	int id = createBalloon(w+5, h, winding, 1);
+	Balloon *balloon = &_intBalloons[id];
+
+	_gfx->drawWrappedText(_vm->_dialogueFont, balloon->surface, text, textColor, MAX_BALLOON_WIDTH);
+
+	// TODO: extract some text to make a name for obj
+	balloon->obj = _gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
+	balloon->obj->x = _dialogueBalloonX[id];
+	balloon->obj->y = 10;
+	balloon->obj->transparentKey = BALLOON_TRANSPARENT_COLOR_NS;
+
+	if (id > 0) {
+		balloon->obj->y += _intBalloons[id - 1].obj->y + _intBalloons[id - 1].outerBox.height();
+	}
+
+
+	return id;
+}
+
+void BalloonManager_ns::setBalloonText(uint id, char *text, byte textColor) {
+	Balloon *balloon = getBalloon(id);
+	balloon->surface->fillRect(balloon->innerBox, 1);
+	_gfx->drawWrappedText(_vm->_dialogueFont, balloon->surface, text, textColor, MAX_BALLOON_WIDTH);
+}
+
+
+int BalloonManager_ns::setLocationBalloon(char *text, bool endGame) {
+
+	int16 w, h;
+
+	_gfx->getStringExtent(_vm->_dialogueFont, text, MAX_BALLOON_WIDTH, &w, &h);
+
+	int id = createBalloon(w+(endGame ? 5 : 10), h+5, -1, BALLOON_TRANSPARENT_COLOR_NS);
+	Balloon *balloon = &_intBalloons[id];
+	_gfx->drawWrappedText(_vm->_dialogueFont, balloon->surface, text, 0, MAX_BALLOON_WIDTH);
+
+	// TODO: extract some text to make a name for obj
+	balloon->obj = _gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
+	balloon->obj->x = 5;
+	balloon->obj->y = 5;
+	balloon->obj->transparentKey = BALLOON_TRANSPARENT_COLOR_NS;
+
+	return id;
+}
+
+int BalloonManager_ns::hitTestDialogueBalloon(int x, int y) {
+
+	Common::Point p;
+
+	for (uint i = 0; i < _numBalloons; i++) {
+		p.x = x - _intBalloons[i].obj->x;
+		p.y = y - _intBalloons[i].obj->y;
+
+		if (_intBalloons[i].innerBox.contains(p))
+			return i;
+	}
+
+	return -1;
+}
+
+void BalloonManager_ns::freeBalloons() {
+	_gfx->destroyBalloons();
+
+	for (uint i = 0; i < _numBalloons; i++) {
+		_intBalloons[i].obj = 0;
+		_intBalloons[i].surface = 0;	// no need to delete surface, since it is done by destroyBalloons
+	}
+
+	_numBalloons = 0;
+}
+
+
+
+
+
+
+
+
+class BalloonManager_br : public BalloonManager {
+
+	struct Balloon {
+		Common::Rect box;
+		Graphics::Surface *surface;
+		GfxObj	*obj;
+	} _intBalloons[3];
+
+	uint	_numBalloons;
+
+	Frames *_leftBalloon;
+	Frames *_rightBalloon;
+	Disk *_disk;
+	Gfx *_gfx;
+
+	void cacheAnims();
+	void drawWrappedText(Font *font, Graphics::Surface* surf, char *text, byte color, int16 wrapwidth);
+	int createBalloon(int16 w, int16 h, int16 winding, uint16 borderThickness);
+	Balloon *getBalloon(uint id);
+	Graphics::Surface *expandBalloon(Frames *data, int frameNum);
+
+
+public:
+	BalloonManager_br(Disk *disk, Gfx *gfx);
+	~BalloonManager_br();
+
+	void freeBalloons();
+	int setLocationBalloon(char *text, bool endGame);
+	int setDialogueBalloon(char *text, uint16 winding, byte textColor);
+	int setSingleBalloon(char *text, uint16 x, uint16 y, uint16 winding, byte textColor);
+	void setBalloonText(uint id, char *text, byte textColor);
+	int hitTestDialogueBalloon(int x, int y);
+};
+
+
+
+BalloonManager_br::Balloon* BalloonManager_br::getBalloon(uint id) {
+	assert(id < _numBalloons);
+	return &_intBalloons[id];
+}
+
+Graphics::Surface *BalloonManager_br::expandBalloon(Frames *data, int frameNum) {
+
+	Common::Rect rect;
+	data->getRect(frameNum, rect);
+
+	rect.translate(-rect.left, -rect.top);
+
+	Graphics::Surface *surf = new Graphics::Surface;
+	surf->create(rect.width(), rect.height(), 1);
+
+	_gfx->unpackBlt(rect, data->getData(frameNum), data->getRawSize(frameNum), surf, 0, BALLOON_TRANSPARENT_COLOR_BR);
+
+	return surf;
+}
+
+int BalloonManager_br::setSingleBalloon(char *text, uint16 x, uint16 y, uint16 winding, byte textColor) {
+	cacheAnims();
+
+	int id = _numBalloons;
+	Frames *src = 0;
+	int srcFrame = 0;
+
+	Balloon *balloon = &_intBalloons[id];
+
+	if (winding == 0) {
+		src = _leftBalloon;
+		srcFrame = 0;
+	} else
+	if (winding == 1) {
+		src = _rightBalloon;
+		srcFrame = 0;
+	}
+
+	assert(src);
+
+	balloon->surface = expandBalloon(src, srcFrame);
+	src->getRect(srcFrame, balloon->box);
+
+//	drawWrappedText(_vm->_dialogueFont, balloon->surface, text, textColor, MAX_BALLOON_WIDTH);
+
+	// TODO: extract some text to make a name for obj
+	balloon->obj = _gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
+	balloon->obj->x = x;
+	balloon->obj->y = y;
+	balloon->obj->transparentKey = BALLOON_TRANSPARENT_COLOR_BR;
+
+	_numBalloons++;
+
+	return id;
+}
+
+int BalloonManager_br::setDialogueBalloon(char *text, uint16 winding, byte textColor) {
+	cacheAnims();
+
+	int id = _numBalloons;
+	Frames *src = 0;
+	int srcFrame = 0;
+
+	Balloon *balloon = &_intBalloons[id];
+
+	if (winding == 0) {
+		src = _leftBalloon;
+		srcFrame = id;
+	} else
+	if (winding == 1) {
+		src = _rightBalloon;
+		srcFrame = 0;
+	}
+
+	assert(src);
+
+	balloon->surface = expandBalloon(src, srcFrame);
+	src->getRect(srcFrame, balloon->box);
+
+//	drawWrappedText(_vm->_dialogueFont, balloon->surface, text, textColor, MAX_BALLOON_WIDTH);
+
+	// TODO: extract some text to make a name for obj
+	balloon->obj = _gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
+	balloon->obj->x = 0;
+	balloon->obj->y = 10;
+	balloon->obj->transparentKey = BALLOON_TRANSPARENT_COLOR_BR;
+
+	if (id > 0) {
+		balloon->obj->y += _intBalloons[id - 1].obj->y + _intBalloons[id - 1].box.height();
+	}
+
+	_numBalloons++;
+
+	return id;
+}
+
+void BalloonManager_br::setBalloonText(uint id, char *text, byte textColor) { }
+
+int BalloonManager_br::setLocationBalloon(char *text, bool endGame) {
+/*
+	int16 w, h;
+
+	getStringExtent(_vm->_dialogueFont, text, MAX_BALLOON_WIDTH, &w, &h);
+
+	int id = createBalloon(w+(endGame ? 5 : 10), h+5, -1, BALLOON_TRANSPARENT_COLOR);
+	Balloon *balloon = &_intBalloons[id];
+	drawWrappedText(_vm->_dialogueFont, balloon->surface, text, 0, MAX_BALLOON_WIDTH);
+
+	// TODO: extract some text to make a name for obj
+	balloon->obj = _gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
+	balloon->obj->x = 5;
+	balloon->obj->y = 5;
+*/
+	return 0;
+}
+
+int BalloonManager_br::hitTestDialogueBalloon(int x, int y) {
+
+	Common::Point p;
+
+	for (uint i = 0; i < _numBalloons; i++) {
+		p.x = x - _intBalloons[i].obj->x;
+		p.y = y - _intBalloons[i].obj->y;
+
+		if (_intBalloons[i].box.contains(p))
+			return i;
+	}
+
+	return -1;
+}
+
+void BalloonManager_br::freeBalloons() {
+	_gfx->destroyBalloons();
+
+	for (uint i = 0; i < _numBalloons; i++) {
+		_intBalloons[i].obj = 0;
+		_intBalloons[i].surface = 0;	// no need to delete surface, since it is done by destroyBalloons
+	}
+
+	_numBalloons = 0;
+}
+
+void BalloonManager_br::cacheAnims() {
+	if (!_leftBalloon) {
+		_leftBalloon = _disk->loadFrames("fumetto.ani");
+		_rightBalloon = _disk->loadFrames("fumdx.ani");
+	}
+}
+
+BalloonManager_br::BalloonManager_br(Disk *disk, Gfx *gfx) : _numBalloons(0), _disk(disk), _gfx(gfx), _leftBalloon(0), _rightBalloon(0) {
+}
+
+BalloonManager_br::~BalloonManager_br() {
+	delete _leftBalloon;
+	delete _rightBalloon;
+}
+
+void Parallaction::setupBalloonManager() {
+	if (_vm->getGameType() == GType_Nippon) {
+		_balloonMan = new BalloonManager_ns(_vm->_gfx);
+	} else
+	if (_vm->getGameType() == GType_BRA) {
+		_balloonMan = new BalloonManager_br(_vm->_disk, _vm->_gfx);
+	} else {
+		error("Unknown game type");
+	}
+}
+
+} // namespace Parallaction


Property changes on: scummvm/trunk/engines/parallaction/balloons.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Modified: scummvm/trunk/engines/parallaction/callables_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/callables_ns.cpp	2008-07-03 22:39:18 UTC (rev 32901)
+++ scummvm/trunk/engines/parallaction/callables_ns.cpp	2008-07-04 00:29:21 UTC (rev 32902)
@@ -341,7 +341,7 @@
 	}
 
 	_input->waitUntilLeftClick();
-	_gfx->freeBalloons();
+	_balloonMan->freeBalloons();
 
 	return;
 }

Modified: scummvm/trunk/engines/parallaction/dialogue.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/dialogue.cpp	2008-07-03 22:39:18 UTC (rev 32901)
+++ scummvm/trunk/engines/parallaction/dialogue.cpp	2008-07-04 00:29:21 UTC (rev 32902)
@@ -93,7 +93,7 @@
 	uint16 passwordLen = 0;
 	_password[0] = '\0';
 
-	_vm->_gfx->setDialogueBalloon(_q->_answers[0]->_text, 1, 3);
+	_vm->_balloonMan->setDialogueBalloon(_q->_answers[0]->_text, 1, 3);
 	int id = _vm->_gfx->setItem(_answerer, ANSWER_CHARACTER_X, ANSWER_CHARACTER_Y);
 	_vm->_gfx->setItemFrame(id, 0);
 
@@ -118,7 +118,7 @@
 		}
 
 		if (changed) {
-			_vm->_gfx->setBalloonText(0, _q->_answers[0]->_text, 3);
+			_vm->_balloonMan->setBalloonText(0, _q->_answers[0]->_text, 3);
 			_vm->_gfx->updateScreen();
 			changed = false;
 		}
@@ -143,7 +143,7 @@
 
 	}
 
-	_vm->_gfx->hideDialogueStuff();
+	_vm->hideDialogueStuff();
 
 	return 0;
 
@@ -162,7 +162,7 @@
 	// display suitable answers
 	if (((a->_yesFlags & flags) == a->_yesFlags) && ((a->_noFlags & ~flags) == a->_noFlags)) {
 
-		int id = _vm->_gfx->setDialogueBalloon(a->_text, 1, 3);
+		int id = _vm->_balloonMan->setDialogueBalloon(a->_text, 1, 3);
 		assert(id >= 0);
 		_visAnswers[id] = i;
 
@@ -190,13 +190,13 @@
 
 	if (!scumm_stricmp(_q->_text, "NULL")) return;
 
-	_vm->_gfx->setSingleBalloon(_q->_text, QUESTION_BALLOON_X, QUESTION_BALLOON_Y, _q->_mood & 0x10, 0);
+	_vm->_balloonMan->setSingleBalloon(_q->_text, QUESTION_BALLOON_X, QUESTION_BALLOON_Y, _q->_mood & 0x10, 0);
 	int id = _vm->_gfx->setItem(_questioner, QUESTION_CHARACTER_X, QUESTION_CHARACTER_Y);
 	_vm->_gfx->setItemFrame(id, _q->_mood & 0xF);
 
 	_vm->_gfx->updateScreen();
 	_vm->_input->waitUntilLeftClick();
-	_vm->_gfx->hideDialogueStuff();
+	_vm->hideDialogueStuff();
 
 	return;
 }
@@ -261,9 +261,9 @@
 	_vm->_gfx->setItemFrame(id, _q->_answers[0]->_mood & 0xF);
 
 	if (numAvailableAnswers == 1) {
-		_vm->_gfx->setBalloonText(0, _q->_answers[0]->_text, 0);
+		_vm->_balloonMan->setBalloonText(0, _q->_answers[0]->_text, 0);
 		_vm->_input->waitUntilLeftClick();
-		_vm->_gfx->hideDialogueStuff();
+		_vm->hideDialogueStuff();
 		return 0;
 	}
 
@@ -277,15 +277,15 @@
 		_vm->_input->readInput();
 		_vm->_input->getCursorPos(p);
 		event = _vm->_input->getLastButtonEvent();
-		selection = _vm->_gfx->hitTestDialogueBalloon(p.x, p.y);
+		selection = _vm->_balloonMan->hitTestDialogueBalloon(p.x, p.y);
 
 		if (selection != oldSelection) {
 			if (oldSelection != -1) {
-				_vm->_gfx->setBalloonText(oldSelection, _q->_answers[_visAnswers[oldSelection]]->_text, 3);
+				_vm->_balloonMan->setBalloonText(oldSelection, _q->_answers[_visAnswers[oldSelection]]->_text, 3);
 			}
 
 			if (selection != -1) {
-				_vm->_gfx->setBalloonText(selection, _q->_answers[_visAnswers[selection]]->_text, 0);
+				_vm->_balloonMan->setBalloonText(selection, _q->_answers[_visAnswers[selection]]->_text, 0);
 				_vm->_gfx->setItemFrame(0, _q->_answers[_visAnswers[selection]]->_mood & 0xF);
 			}
 		}
@@ -300,7 +300,7 @@
 		oldSelection = selection;
 	}
 
-	_vm->_gfx->hideDialogueStuff();
+	_vm->hideDialogueStuff();
 
 	return _visAnswers[selection];
 }

Modified: scummvm/trunk/engines/parallaction/exec_br.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/exec_br.cpp	2008-07-03 22:39:18 UTC (rev 32901)
+++ scummvm/trunk/engines/parallaction/exec_br.cpp	2008-07-04 00:29:21 UTC (rev 32902)
@@ -100,8 +100,13 @@
 }
 
 void Parallaction_br::clearSubtitles() {
-	_gfx->hideLabel(_subtitle[0]);
-	_gfx->hideLabel(_subtitle[1]);
+	if (_subtitle[0] != -1) {
+		_gfx->hideLabel(_subtitle[0]);
+	}
+
+	if (_subtitle[1] != -1) {
+		_gfx->hideLabel(_subtitle[1]);
+	}
 }
 
 

Modified: scummvm/trunk/engines/parallaction/exec_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/exec_ns.cpp	2008-07-03 22:39:18 UTC (rev 32901)
+++ scummvm/trunk/engines/parallaction/exec_ns.cpp	2008-07-04 00:29:21 UTC (rev 32902)
@@ -469,7 +469,7 @@
 		}
 
 		_gfx->setHalfbriteMode(true);
-		_gfx->setSingleBalloon(data->_description, 0, 90, 0, 0);
+		_balloonMan->setSingleBalloon(data->_description, 0, 90, 0, 0);
 		Common::Rect r;
 		data->_cnv->getRect(0, r);
 		id = _gfx->setItem(data->_cnv, 140, (_screenHeight - r.height())/2);
@@ -477,7 +477,7 @@
 		id = _gfx->setItem(_char._head, 100, 152);
 		_gfx->setItemFrame(id, 0);
 	} else {
-		_gfx->setSingleBalloon(data->_description, 140, 10, 0, 0);
+		_balloonMan->setSingleBalloon(data->_description, 140, 10, 0, 0);
 		id = _gfx->setItem(_char._talk, 190, 80);
 		_gfx->setItemFrame(id, 0);
 	}

Modified: scummvm/trunk/engines/parallaction/graphics.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/graphics.cpp	2008-07-03 22:39:18 UTC (rev 32901)
+++ scummvm/trunk/engines/parallaction/graphics.cpp	2008-07-04 00:29:21 UTC (rev 32902)
@@ -64,11 +64,7 @@
 
 
 #define	LABEL_TRANSPARENT_COLOR 0xFF
-#define	BALLOON_TRANSPARENT_COLOR 2
 
-
-int16 Gfx::_dialogueBalloonX[5] = { 80, 120, 150, 150, 150 };
-
 void halfbritePixel(int x, int y, int color, void *data) {
 	byte *buffer = (byte*)data;
 	buffer[x + y * _vm->_screenWidth] &= ~0x20;
@@ -238,38 +234,7 @@
 }
 
 
-#define BALLOON_TAIL_WIDTH	12
-#define BALLOON_TAIL_HEIGHT	10
 
-
-byte _resBalloonTail[2][BALLOON_TAIL_WIDTH*BALLOON_TAIL_HEIGHT] = {
-	{
-	  0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02,
-	  0x02, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02,
-	  0x02, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02,
-	  0x02, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02,
-	  0x02, 0x02, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02,
-	  0x02, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02,
-	  0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02,
-	  0x02, 0x00, 0x01, 0x01, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
-	  0x00, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
-	  0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
-	},
-	{
-	  0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02,
-	  0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x02, 0x02, 0x02,
-	  0x02, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02,
-	  0x02, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02,
-	  0x02, 0x00, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
-	  0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02,
-	  0x02, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02, 0x02,
-	  0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x01, 0x01, 0x00, 0x02, 0x02, 0x02,
-	  0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x01, 0x01, 0x00, 0x02, 0x02,
-	  0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x02, 0x02
-	}
-};
-
-
 void Gfx::setPalette(Palette pal) {
 	byte sysPal[256*4];
 
@@ -777,7 +742,6 @@
 
 	setPalette(_palette);
 
-	_numBalloons = 0;
 	_numItems = 0;
 	_floatingLabel = NO_FLOATING_LABEL;
 
@@ -828,52 +792,13 @@
 	_items[item].data->setFlags(kGfxObjVisible);
 }
 
-Gfx::Balloon* Gfx::getBalloon(uint id) {
-	assert(id < _numBalloons);
-	return &_intBalloons[id];
-}
 
-int Gfx::createBalloon(int16 w, int16 h, int16 winding, uint16 borderThickness) {
-	assert(_numBalloons < 5);
-
-	int id = _numBalloons;
-
-	Gfx::Balloon *balloon = &_intBalloons[id];
-
-	int16 real_h = (winding == -1) ? h : h + 9;
-	balloon->surface = new Graphics::Surface;
-	balloon->surface->create(w, real_h, 1);
-	balloon->surface->fillRect(Common::Rect(w, real_h), BALLOON_TRANSPARENT_COLOR);
-
-	Common::Rect r(w, h);
-	balloon->surface->fillRect(r, 0);
-	balloon->outerBox = r;
-
-	r.grow(-borderThickness);
-	balloon->surface->fillRect(r, 1);
-	balloon->innerBox = r;
-
-	if (winding != -1) {
-		// draws tail
-		// TODO: this bitmap tail should only be used for Dos games. Amiga should use a polygon fill.
-		winding = (winding == 0 ? 1 : 0);
-		Common::Rect s(BALLOON_TAIL_WIDTH, BALLOON_TAIL_HEIGHT);
-		s.moveTo(r.width()/2 - 5, r.bottom - 1);
-		blt(s, _resBalloonTail[winding], balloon->surface, LAYER_FOREGROUND, BALLOON_TRANSPARENT_COLOR);
-	}
-
-	_numBalloons++;
-
-	return id;
-}
-
 GfxObj* Gfx::registerBalloon(Frames *frames, const char *text) {
 
 	GfxObj *obj = new GfxObj(kGfxObjTypeBalloon, frames, text);
 
 	obj->layer = LAYER_FOREGROUND;
 	obj->frame = 0;
-	obj->transparentKey = BALLOON_TRANSPARENT_COLOR;
 	obj->setFlags(kGfxObjVisible);
 
 	_balloons.push_back(obj);
@@ -881,110 +806,17 @@
 	return obj;
 }
 
-int Gfx::setSingleBalloon(char *text, uint16 x, uint16 y, uint16 winding, byte textColor) {
-
-	int16 w, h;
-
-	getStringExtent(_vm->_dialogueFont, text, MAX_BALLOON_WIDTH, &w, &h);
-
-	int id = createBalloon(w+5, h, winding, 1);
-	Gfx::Balloon *balloon = &_intBalloons[id];
-
-	drawWrappedText(_vm->_dialogueFont, balloon->surface, text, textColor, MAX_BALLOON_WIDTH);
-
-	// TODO: extract some text to make a name for obj
-	balloon->obj = registerBalloon(new SurfaceToFrames(balloon->surface), 0);
-	balloon->obj->x = x;
-	balloon->obj->y = y;
-
-	return id;
-}
-
-int Gfx::setDialogueBalloon(char *text, uint16 winding, byte textColor) {
-
-	int16 w, h;
-
-	getStringExtent(_vm->_dialogueFont, text, MAX_BALLOON_WIDTH, &w, &h);
-
-	int id = createBalloon(w+5, h, winding, 1);
-	Gfx::Balloon *balloon = &_intBalloons[id];
-
-	drawWrappedText(_vm->_dialogueFont, balloon->surface, text, textColor, MAX_BALLOON_WIDTH);
-
-	// TODO: extract some text to make a name for obj
-	balloon->obj = registerBalloon(new SurfaceToFrames(balloon->surface), 0);
-	balloon->obj->x = _dialogueBalloonX[id];
-	balloon->obj->y = 10;
-
-	if (id > 0) {
-		balloon->obj->y += _intBalloons[id - 1].obj->y + _intBalloons[id - 1].outerBox.height();
+void Gfx::destroyBalloons() {
+	for (uint i = 0; i < _balloons.size(); i++) {
+		delete _balloons[i];
 	}
-
-
-	return id;
-}
-
-void Gfx::setBalloonText(uint id, char *text, byte textColor) {
-	Gfx::Balloon *balloon = getBalloon(id);
-	balloon->surface->fillRect(balloon->innerBox, 1);
-	drawWrappedText(_vm->_dialogueFont, balloon->surface, text, textColor, MAX_BALLOON_WIDTH);
-}
-
-
-int Gfx::setLocationBalloon(char *text, bool endGame) {
-
-	int16 w, h;
-
-	getStringExtent(_vm->_dialogueFont, text, MAX_BALLOON_WIDTH, &w, &h);
-
-	int id = createBalloon(w+(endGame ? 5 : 10), h+5, -1, BALLOON_TRANSPARENT_COLOR);
-	Gfx::Balloon *balloon = &_intBalloons[id];
-	drawWrappedText(_vm->_dialogueFont, balloon->surface, text, 0, MAX_BALLOON_WIDTH);
-
-	// TODO: extract some text to make a name for obj
-	balloon->obj = registerBalloon(new SurfaceToFrames(balloon->surface), 0);
-	balloon->obj->x = 5;
-	balloon->obj->y = 5;
-
-	return id;
-}
-
-int Gfx::hitTestDialogueBalloon(int x, int y) {
-
-	Common::Point p;
-
-	for (uint i = 0; i < _numBalloons; i++) {
-		p.x = x - _intBalloons[i].obj->x;
-		p.y = y - _intBalloons[i].obj->y;
-
-		if (_intBalloons[i].innerBox.contains(p))
-			return i;
-	}
-
-	return -1;
-}
-
-
-void Gfx::freeBalloons() {
 	_balloons.clear();
-
-	for (uint i = 0; i < _numBalloons; i++) {
-		delete _intBalloons[i].obj;
-		_intBalloons[i].obj = 0;
-		_intBalloons[i].surface = 0;	// no need to delete surface, since it is done by obj (GfxObj)
-	}
-	_numBalloons = 0;
 }
 
 void Gfx::freeItems() {
 	_numItems = 0;
 }
 
-void Gfx::hideDialogueStuff() {
-	freeItems();
-	freeBalloons();
-}
-
 void Gfx::freeBackground() {
 	_backgroundInfo.free();
 }

Modified: scummvm/trunk/engines/parallaction/graphics.h
===================================================================
--- scummvm/trunk/engines/parallaction/graphics.h	2008-07-03 22:39:18 UTC (rev 32901)
+++ scummvm/trunk/engines/parallaction/graphics.h	2008-07-04 00:29:21 UTC (rev 32902)
@@ -450,6 +450,20 @@
 	kBackgroundSlide = 2
 };
 
+
+class BalloonManager {
+public:
+	virtual ~BalloonManager() { }
+
+	virtual void freeBalloons() = 0;
+	virtual int setLocationBalloon(char *text, bool endGame) = 0;
+	virtual int setDialogueBalloon(char *text, uint16 winding, byte textColor) = 0;
+	virtual int setSingleBalloon(char *text, uint16 x, uint16 y, uint16 winding, byte textColor) = 0;
+	virtual void setBalloonText(uint id, char *text, byte textColor) = 0;
+	virtual int hitTestDialogueBalloon(int x, int y) = 0;
+};
+
+
 typedef Common::HashMap<Common::String, int32, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> VarMap;
 
 class Gfx {
@@ -479,13 +493,9 @@
 	void freeLabels();
 
 	// dialogue balloons
-	int setLocationBalloon(char *text, bool endGame);
-	int setDialogueBalloon(char *text, uint16 winding, byte textColor);
-	int setSingleBalloon(char *text, uint16 x, uint16 y, uint16 winding, byte textColor);
-	void setBalloonText(uint id, char *text, byte textColor);
-	int hitTestDialogueBalloon(int x, int y);
 	void getStringExtent(Font *font, char *text, uint16 maxwidth, int16* width, int16* height);
 	GfxObj* registerBalloon(Frames *frames, const char *text);
+	void destroyBalloons();
 
 	// other items
 	int setItem(GfxObj* obj, uint16 x, uint16 y, byte transparentColor = 0);
@@ -551,17 +561,7 @@
 	int32 				getRenderMode(const char *type);
 
 public:
-	static int16 _dialogueBalloonX[5];
 
-	struct Balloon {
-		Common::Rect outerBox;
-		Common::Rect innerBox;
-		Graphics::Surface *surface;
-		GfxObj	*obj;
-	} _intBalloons[5];
-
-	uint	_numBalloons;
-
 	struct Item {
 		GfxObj *data;
 	} _items[14];
@@ -585,9 +585,6 @@
 
 	void copyRect(const Common::Rect &r, Graphics::Surface &src, Graphics::Surface &dst);
 
-	int createBalloon(int16 w, int16 h, int16 winding, uint16 borderThickness);
-	Balloon *getBalloon(uint id);
-
 	// low level text and patches
 	void drawText(Font *font, Graphics::Surface* surf, uint16 x, uint16 y, const char *text, byte color);
 	void drawWrappedText(Font *font, Graphics::Surface* surf, char *text, byte color, int16 wrapwidth);

Modified: scummvm/trunk/engines/parallaction/gui_br.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/gui_br.cpp	2008-07-03 22:39:18 UTC (rev 32901)
+++ scummvm/trunk/engines/parallaction/gui_br.cpp	2008-07-04 00:29:21 UTC (rev 32902)
@@ -195,7 +195,7 @@
 	}
 
 	_system->showMouse(false);
-	_gfx->hideDialogueStuff();
+	hideDialogueStuff();
 
 	for (i = 0; i < availItems; i++) {
 		delete _lines[i];

Modified: scummvm/trunk/engines/parallaction/input.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/input.cpp	2008-07-03 22:39:18 UTC (rev 32901)
+++ scummvm/trunk/engines/parallaction/input.cpp	2008-07-04 00:29:21 UTC (rev 32902)
@@ -174,7 +174,7 @@
 void Input::updateCommentInput() {
 	waitUntilLeftClick();
 
-	_vm->_gfx->hideDialogueStuff();
+	_vm->hideDialogueStuff();
 	_vm->_gfx->setHalfbriteMode(false);
 
 	_inputMode = kInputModeGame;

Modified: scummvm/trunk/engines/parallaction/module.mk
===================================================================
--- scummvm/trunk/engines/parallaction/module.mk	2008-07-03 22:39:18 UTC (rev 32901)
+++ scummvm/trunk/engines/parallaction/module.mk	2008-07-04 00:29:21 UTC (rev 32902)
@@ -1,6 +1,7 @@
 MODULE := engines/parallaction
 
 MODULE_OBJS := \
+	balloons_o \
 	callables_br.o \
 	callables_ns.o \
 	debug.o \

Modified: scummvm/trunk/engines/parallaction/parallaction.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.cpp	2008-07-03 22:39:18 UTC (rev 32901)
+++ scummvm/trunk/engines/parallaction/parallaction.cpp	2008-07-04 00:29:21 UTC (rev 32902)
@@ -134,6 +134,8 @@
 
 	_debugger = new Debugger(this);
 
+	setupBalloonManager();
+
 	return 0;
 }
 
@@ -281,7 +283,7 @@
 }
 
 void Parallaction::showLocationComment(const char *text, bool end) {
-	_gfx->setLocationBalloon(const_cast<char*>(text), end);
+	_balloonMan->setLocationBalloon(const_cast<char*>(text), end);
 }
 
 
@@ -422,7 +424,7 @@
 
 	showLocationComment(_location._comment, false);
 	_input->waitUntilLeftClick();
-	_gfx->freeBalloons();
+	_balloonMan->freeBalloons();
 
 	// fades maximum intensity palette towards approximation of main palette
 	for (uint16 _si = 0; _si<6; _si++) {

Modified: scummvm/trunk/engines/parallaction/parallaction.h
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.h	2008-07-03 22:39:18 UTC (rev 32901)
+++ scummvm/trunk/engines/parallaction/parallaction.h	2008-07-04 00:29:21 UTC (rev 32902)
@@ -429,6 +429,15 @@
 	Inventory *_inventory;
 	InventoryRenderer *_inventoryRenderer;
 
+	BalloonManager *_balloonMan;
+
+	void setupBalloonManager();
+
+	void hideDialogueStuff() {
+		_gfx->freeItems();
+		_balloonMan->freeBalloons();
+	}
+
 };
 
 

Modified: scummvm/trunk/engines/parallaction/parallaction_br.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction_br.cpp	2008-07-03 22:39:18 UTC (rev 32901)
+++ scummvm/trunk/engines/parallaction/parallaction_br.cpp	2008-07-04 00:29:21 UTC (rev 32902)
@@ -80,6 +80,9 @@
 
 	_part = -1;
 
+	_subtitle[0] = -1;
+	_subtitle[1] = -1;
+
 	Parallaction::init();
 
 	return 0;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list