[Scummvm-cvs-logs] CVS: residual driver.h,1.4,1.5 driver_gl.cpp,1.38,1.39 driver_gl.h,1.17,1.18 driver_tinygl.cpp,1.8,1.9 driver_tinygl.h,1.4,1.5 lua.cpp,1.111,1.112 textobject.cpp,1.18,1.19 textobject.h,1.8,1.9

Pawel Kolodziejski aquadran at users.sourceforge.net
Sun Mar 20 05:52:22 CET 2005


Update of /cvsroot/scummvm/residual
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6191

Modified Files:
	driver.h driver_gl.cpp driver_gl.h driver_tinygl.cpp 
	driver_tinygl.h lua.cpp textobject.cpp textobject.h 
Log Message:
reorganized TextObject code to easier bitmap recreation

Index: driver.h
===================================================================
RCS file: /cvsroot/scummvm/residual/driver.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- driver.h	19 Mar 2005 21:48:23 -0000	1.4
+++ driver.h	20 Mar 2005 13:51:40 -0000	1.5
@@ -74,6 +74,7 @@
 	virtual void loadEmergFont() = 0;
 	virtual TextObjectHandle *prepareToTextBitmap(uint8 *bitmap, int width, int height, const Color &fgColor) = 0;
 	virtual void drawTextBitmap(int x, int y, TextObjectHandle *handle) = 0;
+	virtual void destroyTextBitmap(TextObjectHandle *handle) = 0;
 
 	virtual void prepareSmushFrame(int width, int height, byte *bitmap) = 0;
 	virtual void drawSmushFrame(int offsetX, int offsetY) = 0;

Index: driver_gl.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/driver_gl.cpp,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- driver_gl.cpp	19 Mar 2005 21:48:23 -0000	1.38
+++ driver_gl.cpp	20 Mar 2005 13:51:40 -0000	1.39
@@ -652,3 +652,8 @@
 	glEnable(GL_DEPTH_TEST);
 	glEnable(GL_LIGHTING);
 }
+
+void DriverGL::destroyTextBitmap(TextObjectHandle *handle) {
+	glDeleteTextures(handle->numTex, (GLuint *)handle->texIds);
+	delete[] handle->texIds;
+}

Index: driver_gl.h
===================================================================
RCS file: /cvsroot/scummvm/residual/driver_gl.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- driver_gl.h	19 Mar 2005 21:48:23 -0000	1.17
+++ driver_gl.h	20 Mar 2005 13:51:40 -0000	1.18
@@ -65,6 +65,7 @@
 	void loadEmergFont();
 	TextObjectHandle *prepareToTextBitmap(uint8 *bitmap, int width, int height, const Color &fgColor);
 	void drawTextBitmap(int x, int y, TextObjectHandle *handle);
+	void destroyTextBitmap(TextObjectHandle *handle);
 
 	void prepareSmushFrame(int width, int height, byte *bitmap);
 	void drawSmushFrame(int offsetX, int offsetY);

Index: driver_tinygl.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/driver_tinygl.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- driver_tinygl.cpp	19 Mar 2005 21:48:23 -0000	1.8
+++ driver_tinygl.cpp	20 Mar 2005 13:51:40 -0000	1.9
@@ -441,3 +441,8 @@
 	SDL_SetColorKey((SDL_Surface *)handle->surface, SDL_SRCCOLORKEY, 0xf81f);
 	SDL_BlitSurface((SDL_Surface *)handle->surface, &srcRect, _screen, &dstRect);
 }
+
+void DriverTinyGL::destroyTextBitmap(TextObjectHandle *handle) {
+	delete handle->bitmapData;
+	SDL_FreeSurface((SDL_Surface *)handle->surface);
+}

Index: driver_tinygl.h
===================================================================
RCS file: /cvsroot/scummvm/residual/driver_tinygl.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- driver_tinygl.h	19 Mar 2005 21:48:23 -0000	1.4
+++ driver_tinygl.h	20 Mar 2005 13:51:40 -0000	1.5
@@ -68,6 +68,7 @@
 	void loadEmergFont();
 	TextObjectHandle *prepareToTextBitmap(uint8 *bitmap, int width, int height, const Color &fgColor);
 	void drawTextBitmap(int x, int y, TextObjectHandle *handle);
+	void destroyTextBitmap(TextObjectHandle *handle);
 
 	void prepareSmushFrame(int width, int height, byte *bitmap);
 	void drawSmushFrame(int offsetX, int offsetY);

Index: lua.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua.cpp,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -d -r1.111 -r1.112
--- lua.cpp	20 Mar 2005 11:53:15 -0000	1.111
+++ lua.cpp	20 Mar 2005 13:51:40 -0000	1.112
@@ -1160,8 +1160,7 @@
 	}
 }
 
-void getTextObjectParams(lua_Object table_obj, Font **font, int &x, int &y, int &width,
-						 int &height, Color **fgColor, bool &center, bool &ljustify) {
+void getTextObjectParams(TextObject *textObject, lua_Object table_obj) {
 	char *key_text = NULL;
 	lua_Object key;
 
@@ -1179,21 +1178,21 @@
 
 		key_text = lua_getstring(key);
 		if (strstr(key_text, "x"))
-			x = atoi(lua_getstring(lua_getresult(2)));
+			textObject->setX(atoi(lua_getstring(lua_getresult(2))));
 		else if (strstr(key_text, "y"))
-			y = atoi(lua_getstring(lua_getresult(2)));
+			textObject->setY(atoi(lua_getstring(lua_getresult(2))));
 		else if (strstr(key_text, "width"))
-			width = atoi(lua_getstring(lua_getresult(2)));
+			textObject->setWidth(atoi(lua_getstring(lua_getresult(2))));
 		else if (strstr(key_text, "height"))
-			height = atoi(lua_getstring(lua_getresult(2)));
+			textObject->setHeight(atoi(lua_getstring(lua_getresult(2))));
 		else if (strstr(key_text, "font"))
-			*font = check_font(2);
+			textObject->setFont(check_font(2));
 		else if (strstr(key_text, "fgcolor"))
-			*fgColor = check_color(2);
+			textObject->setFGColor(check_color(2));
 		else if (strstr(key_text, "center"))
-			center = !lua_isnil(lua_getresult(2));
+			textObject->setJustify(1);
 		else if (strstr(key_text, "ljustify"))
-			ljustify = !lua_isnil(lua_getresult(2));
+			textObject->setJustify(2);
 		else
 			error("Unknown getTextObjectParams key %s\n", key_text);
 	}
@@ -1206,23 +1205,27 @@
 	Font *font = NULL;
 
 	char *line = lua_getstring(lua_getparam(1));
-	lua_Object table_obj = lua_getparam(2);
-	if (lua_istable(table_obj))
-		getTextObjectParams(table_obj, &font, x, y, width, height, &fgColor, center, ljustify);
+	lua_Object tableObj = lua_getparam(2);
 
-	// Note: The debug func display_setup_name in _sets.LUA creates an empty TextObject,
-	// and fills it with ChangeTextObject
+	TextObject *textObject = new TextObject();
+	textObject->setDefaultsTextObjectParams();
+
+	if (lua_istable(tableObj))
+		getTextObjectParams(textObject, tableObj);
+
+	textObject->setText(line);
+	textObject->createBitmap();
 
-	TextObject *textObject = new TextObject((const char *)line, x, y, font, *fgColor);
 	lua_pushusertag(textObject, MKID('TEXT'));
+	lua_pushnumber(textObject->getBitmapWidth());
+	lua_pushnumber(textObject->getBitmapHeight());
 }
 
 static void KillTextObject() {
 	TextObject *textObjectParm;
 
-	if (lua_isnil(lua_getparam(1))) { // FIXME: check this.. nil is kill all lines?
+	if (lua_isnil(lua_getparam(1))) {
 		error("KillTextObject(NULL)");
-		//g_engine->killTextObjects();
 		return;
 	}
 
@@ -1239,77 +1242,38 @@
 	}
 }
 
-// Called from both Callback and Main CTO functions. This routine is NOT
-// thread safe.
-static void ChangeTextObject_Real(char *keyName, void *data) {
-	static TextObject *modifyObject = NULL; // Set by main CTO call 'object'
-	lua_Object *keyValue = NULL;
-
-	if (strstr(keyName, "object")) {
-		modifyObject = (TextObject*)data;
-		return;
-	}
-
-	if (!modifyObject)	// We *need* a modify object for remaining calls
-		return;
-
-	keyValue = (lua_Object*)data;
-
-	// FIXME: X/Y sets depend on GetTextObjectDimensions
-
-	if (strstr(keyName, "fgcolor")) {
-		modifyObject->setColor(check_color(2));
-	} else if (strstr(keyName, "x")) {
-		//modifyObject->setX(atoi(lua_getstring(keyValue)));
-	} else if (strstr(keyName, "y")) {
-		//modifyObject->setY(atoi(lua_getstring(keyValue)));
-	} else {
-		printf("ChangeTextObject() - Unknown key %s\n", keyName);
-	}
-}
-
-// Callback from table walk method in Main CTO function
-static void ChangeTextObject_CB(void) {
-	char *keyName = NULL;
-	lua_Object keyValue;
-
-	keyName = lua_getstring(lua_getparam(1));
-	keyValue = lua_getresult(2);
-	ChangeTextObject_Real(keyName, &keyValue);
-};
-
-// Main CTO handler and LUA interface
 static void ChangeTextObject() {
-	return;
-	char *textID = lua_getstring(lua_getparam(1));
+	TextObject *textObject = check_textobject(1);
 	lua_Object tableObj = lua_getparam(2);
-	TextObject *modifyObject = NULL;
 
+	TextObject *modifyObject = NULL;
 	for (Engine::TextListType::const_iterator i = g_engine->textsBegin(); i != g_engine->textsEnd(); i++) {
 		TextObject *textO = *i;
 
-		if (strstr(textO->name(), textID)) {
+		if (strstr(textO->name(), textObject->name())) {
 			modifyObject = textO;
 			break;
 		}
 	}
 
 	if (!modifyObject)
-		error("ChangeTextObject(%s): Cannot find active text object", textID);
+		error("ChangeTextObject(): Cannot find active text object");
 
-	if (!lua_istable(tableObj))
-		return;
+	modifyObject->destroyBitmap();
 
-	ChangeTextObject_Real("object", modifyObject);
-	lua_pushobject(tableObj);
-	lua_pushcfunction(ChangeTextObject_CB);	// Callback handler
-	lua_call("foreach");
+	if (lua_istable(tableObj))
+		getTextObjectParams(modifyObject, tableObj);
+
+	modifyObject->createBitmap();
+
+	lua_pushnumber(modifyObject->getBitmapWidth());
+	lua_pushnumber(modifyObject->getBitmapHeight());
 }
 
 static void GetTextObjectDimensions() {
-	warning("STUB: GetTextObjectDimensions()");
-	lua_pushnumber(100);	// Dummy X
-	lua_pushnumber(100);	// Dummy Y
+	TextObject *textObjectParam = check_textobject(1);
+	lua_pushnumber(textObjectParam->getBitmapWidth());
+	lua_pushnumber(textObjectParam->getBitmapHeight());
 }
 
 static void SetSpeechMode() {

Index: textobject.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/textobject.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- textobject.cpp	20 Mar 2005 11:49:21 -0000	1.18
+++ textobject.cpp	20 Mar 2005 13:51:40 -0000	1.19
@@ -23,20 +23,48 @@
 
 std::string parseMsgText(const char *msg, char *msgId);
 
-TextObject::TextObject(const char *text, const int x, const int y, /*const*/ Font *font, const Color& fgColor) :
-		_fgColor(fgColor), _x(x), _y(y) {
+TextObject::TextObject() :
+		_created(false), _x(0), _y(0), _width(0), _height(0), _textBitmap(NULL),
+		_bitmapWidth(0), _bitmapHeight(0), _textObjectHandle(NULL), _justify(0),
+		_font(NULL), _text(NULL) {
+	memset(_textID, 0, 10);
+	_fgColor._vals[0] = 0;
+	_fgColor._vals[1] = 0;
+	_fgColor._vals[2] = 0;
+}
 
-	strcpy(_textID, text);
+TextObject::~TextObject() {
+	destroyBitmap();
+}
+
+void TextObject::setDefaultsTextObjectParams() {
+	_x = 0;
+	_y = 0;
+	_width = 0;
+	_height = 0;
+	_font = NULL;
+	_fgColor._vals[0] = 0;
+	_fgColor._vals[1] = 0;
+	_fgColor._vals[2] = 0;
+	_justify = 0;
+	_text = NULL;
+}
+
+void TextObject::createBitmap() {
+	if (_created)
+		destroyBitmap();
+
+	strcpy(_textID, _text);
 	char msgId[32];
 	std::string msg = parseMsgText(_textID, msgId);
 
-	// Calculate bitmap dimensions
-	_bitmapHeight = _bitmapWidth = 0;
+	_bitmapWidth = 0;
+	_bitmapHeight = 0;
 
 	for (int i = 0; msg[i] != '\0'; ++i) {
-		_bitmapWidth += font->getCharLogicalWidth(msg[i]) + font->getCharStartingCol(msg[i]);
+		_bitmapWidth += _font->getCharLogicalWidth(msg[i]) + _font->getCharStartingCol(msg[i]);
 
-		int h = font->getCharHeight(msg[i]) + font->getCharStartingLine(msg[i]);
+		int h = _font->getCharHeight(msg[i]) + _font->getCharStartingLine(msg[i]);
 		if (h > _bitmapHeight)
 			_bitmapHeight = h;
 	}
@@ -50,14 +78,14 @@
 	int offset = 0;
 	for (int line = 0; line < _bitmapHeight; ++line) {
 		for (int c = 0; msg[c] != '\0'; ++c) {
-			uint32 charWidth = font->getCharWidth(msg[c]);
-			uint32 charLogicalWidth = font->getCharLogicalWidth(msg[c]);
-			uint8 startingCol = font->getCharStartingCol(msg[c]);
-			uint8 startingLine = font->getCharStartingLine(msg[c]);
+			uint32 charWidth = _font->getCharWidth(msg[c]);
+			uint32 charLogicalWidth = _font->getCharLogicalWidth(msg[c]);
+			uint8 startingCol = _font->getCharStartingCol(msg[c]);
+			uint8 startingLine = _font->getCharStartingLine(msg[c]);
 
-			if (startingLine < line + 1 && font->getCharHeight(msg[c]) + startingLine > line) {
+			if (startingLine < line + 1 && _font->getCharHeight(msg[c]) + startingLine > line) {
 				memcpy(_textBitmap + offset + startingCol,
-					font->getCharData(msg[c]) + charWidth * (line - startingLine), charWidth);
+					_font->getCharData(msg[c]) + charWidth * (line - startingLine), charWidth);
 			}
 
 			offset += charLogicalWidth + startingCol;
@@ -66,19 +94,18 @@
 
 	_textObjectHandle = g_driver->prepareToTextBitmap(_textBitmap, _bitmapWidth, _bitmapHeight, _fgColor);
 
+	_created = true;
 	g_engine->registerTextObject(this);
 }
 
-TextObject::~TextObject() {
-	delete[] _textBitmap;
-	if (_textObjectHandle->bitmapData)
-		delete _textObjectHandle->bitmapData;
-	if (_textObjectHandle->surface)
-		SDL_FreeSurface((SDL_Surface *)_textObjectHandle->surface);
-	if (_textObjectHandle->texIds)
-		delete _textObjectHandle->texIds;
-
-	delete _textObjectHandle;
+void TextObject::destroyBitmap() {
+	if (_textObjectHandle) {
+		delete[] _textBitmap;
+		g_driver->destroyTextBitmap(_textObjectHandle);
+		delete _textObjectHandle;
+		_textObjectHandle = NULL;
+	}
+	_created = false;
 }
 
 void TextObject::draw() {

Index: textobject.h
===================================================================
RCS file: /cvsroot/scummvm/residual/textobject.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- textobject.h	19 Mar 2005 21:48:23 -0000	1.8
+++ textobject.h	20 Mar 2005 13:51:40 -0000	1.9
@@ -28,19 +28,40 @@
 
 class TextObject {
 public:
-	TextObject(const char *text, const int x, const int y, /*const*/ Font *font, const Color& fgColor);
+	TextObject();
 	~TextObject();
-	void setX(int x) {_x = x; }
-	void setY(int y) {_y = y; }
-	void setColor(Color *newColor) { _fgColor = newColor; }
+	void createBitmap();
+	void destroyBitmap();
+	void setDefaultsTextObjectParams();
+	void setText(char *text) { _text = text; }
+	void setX(int x) { _x = x; }
+	void setY(int y) { _y = y; }
+	void setWidth(int width) { _width = width; }
+	void setHeight(int height) { _height = height; }
+	void setFGColor(Color *fgColor) { _fgColor = fgColor; }
+	void setFont(Font *font) { _font = font; }
+	void setJustify(int justify) { _justify = justify; }
+	int getBitmapWidth() { return _bitmapWidth; }
+	int getBitmapHeight() { return _bitmapHeight; }
 
 	const char *name() const { return _textID; }
 	void draw();
 
+	enum Justify {
+		NONE,
+		CENTER,
+		LJUSTIFY
+	};
+
 protected:
+	bool _created;
 	Color _fgColor;
 	int _x, _y;
-	char _textID[10];
+	int _width, _height;
+	int _justify;
+	Font *_font;
+	char *_text;
+	char _textID[32];
 	uint8 *_textBitmap;
 	int _bitmapHeight, _bitmapWidth;
 	Driver::TextObjectHandle *_textObjectHandle;





More information about the Scummvm-git-logs mailing list