[Scummvm-cvs-logs] SF.net SVN: scummvm: [32950] scummvm/branches/gsoc2008-vkeybd

sk4425 at users.sourceforge.net sk4425 at users.sourceforge.net
Mon Jul 7 23:11:01 CEST 2008


Revision: 32950
          http://scummvm.svn.sourceforge.net/scummvm/?rev=32950&view=rev
Author:   sk4425
Date:     2008-07-07 14:10:58 -0700 (Mon, 07 Jul 2008)

Log Message:
-----------
MILESTONE: bitmap showing with key color transparency implemented!
- SurfaceKeyColored class handles blitting of keycolor transparency data
- ImageMap tested - Rect and Polygon areas seem to be working as expected

Modified Paths:
--------------
    scummvm/branches/gsoc2008-vkeybd/backends/common/virtual-keyboard-parser.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/common/virtual-keyboard-parser.h
    scummvm/branches/gsoc2008-vkeybd/backends/common/virtual-keyboard.cpp
    scummvm/branches/gsoc2008-vkeybd/common/image-map.cpp
    scummvm/branches/gsoc2008-vkeybd/common/image-map.h
    scummvm/branches/gsoc2008-vkeybd/dists/msvc8/scummvm.vcproj
    scummvm/branches/gsoc2008-vkeybd/graphics/module.mk

Added Paths:
-----------
    scummvm/branches/gsoc2008-vkeybd/graphics/surface-keycolored.cpp
    scummvm/branches/gsoc2008-vkeybd/graphics/surface-keycolored.h

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/virtual-keyboard-parser.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/virtual-keyboard-parser.cpp	2008-07-07 20:40:35 UTC (rev 32949)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/virtual-keyboard-parser.cpp	2008-07-07 21:10:58 UTC (rev 32950)
@@ -40,6 +40,9 @@
 	_callbacks["layout"]   = &VirtualKeyboardParser::parserCallback_Layout;
 	_callbacks["map"]	   = &VirtualKeyboardParser::parserCallback_Map;
 	_callbacks["area"]     = &VirtualKeyboardParser::parserCallback_Area;
+
+	_closedCallbacks["keyboard"] = &VirtualKeyboardParser::parserCallback_KeyboardClosed;
+	_closedCallbacks["mode"]     = &VirtualKeyboardParser::parserCallback_ModeClosed;
 }
 
 bool VirtualKeyboardParser::keyCallback(Common::String keyName) {
@@ -49,6 +52,13 @@
 	return (this->*(_callbacks[_activeKey.top()->name]))();
 }
 
+bool VirtualKeyboardParser::closedKeyCallback(Common::String keyName) {
+	if (!_closedCallbacks.contains(_activeKey.top()->name))
+		return true;
+	
+	return (this->*(_closedCallbacks[_activeKey.top()->name]))();
+}
+
 bool VirtualKeyboardParser::parserCallback_Keyboard() {
 	ParserNode *kbdNode = getActiveNode();
 
@@ -59,7 +69,6 @@
 
 	if (_kbdParsed)
 		return parserError("Only a single keyboard element is allowed");
-	_kbdParsed = true;
 
 	if (!kbdNode->values.contains("initial_mode"))
 		return parserError("Keyboard element must contain initial_mode attribute");
@@ -89,6 +98,13 @@
 	return true;
 }
 
+bool VirtualKeyboardParser::parserCallback_KeyboardClosed() {
+	_kbdParsed = true;
+	if (!_keyboard->_initialMode)
+		return parserError("Initial mode of keyboard pack not defined");
+	return true;
+}
+
 bool VirtualKeyboardParser::parserCallback_Mode() {
 	ParserNode *modeNode = getActiveNode();
 
@@ -146,6 +162,12 @@
 	return true;
 }
 
+bool VirtualKeyboardParser::parserCallback_ModeClosed() {
+	if (!_mode->image)
+		return parserError("'%s' layout missing from '%s' mode", _mode->resolution.c_str(), _mode->name.c_str());
+	return true;
+}
+
 bool VirtualKeyboardParser::parserCallback_Event() {
 	ParserNode *evtNode = getActiveNode();
 
@@ -262,15 +284,14 @@
 
 	Common::String shape = areaNode->values["shape"];
 	if (shape == "rect") {
+		Common::Rect *rect = _mode->imageMap.createRectArea(areaNode->values["target"]);
 		int x1, y1, x2, y2;
 		if (!parseIntegerKey(areaNode->values["coords"].c_str(), 4, &x1, &y1, &x2, &y2))
 			return parserError("Invalid coords for rect area");
-
-		Common::Rect rect(x1, y1, x2, y2);
-		_mode->imageMap.addRectMapArea(rect, areaNode->values["target"]);
+		rect->left = x1; rect->top = y1; rect->right = x2; rect->bottom = y2;
 	} else if (shape == "poly") {
 		Common::StringTokenizer tok (areaNode->values["coords"], ", ");
-		Common::Polygon poly;
+		Common::Polygon *poly = _mode->imageMap.createPolygonArea(areaNode->values["target"]);
 		for (Common::String st = tok.nextToken(); !st.empty(); st = tok.nextToken()) {
 			int x, y;
 			if (sscanf(st.c_str(), "%d", &x) != 1)
@@ -278,11 +299,10 @@
 			st = tok.nextToken();
 			if (sscanf(st.c_str(), "%d", &y) != 1)
 				return parserError("Invalid coords for polygon area");
-			poly.addPoint(x, y);
+			poly->addPoint(x, y);
 		}
-		if (poly.getPointCount() < 3)
+		if (poly->getPointCount() < 3)
 			return parserError("Invalid coords for polygon area");
-		_mode->imageMap.addPolygonMapArea(poly, areaNode->values["target"]);
 	} else
 		return parserError("Area shape '%s' not known", shape.c_str());
 

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/virtual-keyboard-parser.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/virtual-keyboard-parser.h	2008-07-07 20:40:35 UTC (rev 32949)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/virtual-keyboard-parser.h	2008-07-07 21:10:58 UTC (rev 32950)
@@ -49,6 +49,7 @@
 	bool _kbdParsed;
 
 	bool keyCallback(Common::String keyName);
+	bool closedKeyCallback(Common::String keyName);
 	void cleanup() {
 		_mode = 0;
 		_kbdParsed = _modeParsed = false;
@@ -62,7 +63,11 @@
 	bool parserCallback_Map();
 	bool parserCallback_Area();
 
+	bool parserCallback_KeyboardClosed();
+	bool parserCallback_ModeClosed();
+
 	Common::HashMap<Common::String, ParserCallback, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> _callbacks;
+	Common::HashMap<Common::String, ParserCallback, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> _closedCallbacks;
 };
 
 } // end of namespace GUI

Modified: scummvm/branches/gsoc2008-vkeybd/backends/common/virtual-keyboard.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/common/virtual-keyboard.cpp	2008-07-07 20:40:35 UTC (rev 32949)
+++ scummvm/branches/gsoc2008-vkeybd/backends/common/virtual-keyboard.cpp	2008-07-07 21:10:58 UTC (rev 32950)
@@ -28,6 +28,7 @@
 #include "common/config-manager.h"
 #include "common/events.h"
 #include "graphics/imageman.h"
+#include "graphics/surface-keycolored.h"
 #include "common/unzip.h"
 
 namespace Common {
@@ -101,24 +102,10 @@
 		return false;
 	}
 
-	if (!_parser->parse())
-		return false;
-
-	if (!_initialMode)
-		warning("Initial mode of keyboard pack not defined");
-
-	ModeMap::iterator it;
-	for (it = _modes.begin(); it != _modes.end(); it++) {
-		// if no image then it means layout tag for the 
-		// required resolution was missing from the mode tag.
-		if (!it->_value.image) {
-			warning("'%s' layout missing from '%s' mode", it->_value.resolution.c_str(), it->_value.name.c_str());
-			return false;
-		}
-	}
-
-	_loaded = true;
-	return true;
+	_loaded = _parser->parse();
+	if (_loaded)
+		printf("Keyboard pack '%s' loaded successfully!\n", packName.c_str());
+	return _loaded;
 }
 
 void VirtualKeyboard::reposition()
@@ -159,10 +146,11 @@
 	if (x < 0 || x > _currentMode->image->w) return;
 	if (y < 0 || y > _currentMode->image->h) return;
 
-	Common::MapArea *area = _currentMode->imageMap.findMapArea(x, y);
-	if (!area) return;
-	if (!_currentMode->events.contains(area->getTarget())) return;
-	Event evt = _currentMode->events[area->getTarget()];
+	Common::String area = _currentMode->imageMap.findMapArea(x, y);
+	if (area.empty()) return;
+	printf("Map area found! - %s\n", area.c_str());
+	if (!_currentMode->events.contains(area)) return;
+	Event evt = _currentMode->events[area];
 	
 	switch (evt.type) {
 	case kEventKey:
@@ -214,6 +202,7 @@
 	while (_displaying) {
 		if (_needRedraw) redraw();
 
+		_system->updateScreen();
 		Common::Event event;
 		while (eventMan->pollEvent(event)) {
 			switch (event.type) {
@@ -238,12 +227,18 @@
 }
 
 void VirtualKeyboard::redraw() {
+	Graphics::SurfaceKeyColored surf;
+
+	surf.create(_system->getOverlayWidth(), _system->getOverlayHeight(), sizeof(OverlayColor));
+
+	_system->grabOverlay((OverlayColor*)surf.pixels, surf.w);
+
+	surf.blit(_currentMode->image, _pos.x, _pos.y, _system->RGBToColor(0xff, 0, 0xff));
+	_system->copyRectToOverlay((OverlayColor*)surf.pixels, surf.w, 0, 0, surf.w, surf.h);
+
+	surf.free();
+
 	_needRedraw = false;
-	_system->clearOverlay();
-	_system->copyRectToOverlay((OverlayColor*)_currentMode->image->pixels, 
-		_currentMode->image->w, _pos.x, _pos.y, 
-		_currentMode->image->w, _currentMode->image->h);
-	_system->updateScreen();
 }
 
 bool VirtualKeyboard::pollEvent(Common::Event &event) {

Modified: scummvm/branches/gsoc2008-vkeybd/common/image-map.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/common/image-map.cpp	2008-07-07 20:40:35 UTC (rev 32949)
+++ scummvm/branches/gsoc2008-vkeybd/common/image-map.cpp	2008-07-07 21:10:58 UTC (rev 32950)
@@ -27,6 +27,41 @@
 
 namespace Common {
 
+ImageMap::~ImageMap() {
+	HashMap<String, Shape*>::iterator it;
+	for (it = _areas.begin(); it != _areas.end(); it++) {
+		delete it->_value;
+	}
+}
+
+Rect *ImageMap::createRectArea(const String& id) {
+	if (_areas.contains(id)) {
+		warning("Image map already contains an area with target of '%s'");
+		return 0;
+	}
+	Rect *r = new Rect();
+	_areas[id] = r;
+	return r;
+}
+
+Polygon *ImageMap::createPolygonArea(const String& id) {
+	if (_areas.contains(id)) {
+		warning("Image map already contains an area with target of '%s'");
+		return 0;
+	}
+	Polygon *p = new Polygon();
+	_areas[id] = p;
+	return p;
+}
+
+/*
+void ImageMap::addMapArea(Shape *shape, const String& target) {
+	if (_areas.contains(target)) {
+		warning("Image map already contains an area with target of '%s'");
+		return;
+	}
+	_areas[target] = shape;
+}
 void ImageMap::addRectMapArea(const Rect& rect, const String& target) {
 	areas.push_back(MapArea(rect, target));
 }
@@ -34,14 +69,14 @@
 void ImageMap::addPolygonMapArea(const Polygon& poly, const String& target) {
 	areas.push_back(MapArea(poly, target));
 }
-
-MapArea *ImageMap::findMapArea(int16 x, int16 y) {
-	Array<MapArea>::iterator it;
-	for (it = areas.begin(); it != areas.end(); it++) {
-		if (it->contains(x, y))
-			return it;
+*/
+String ImageMap::findMapArea(int16 x, int16 y) {
+	HashMap<String, Shape*>::iterator it;
+	for (it = _areas.begin(); it != _areas.end(); it++) {
+		if (it->_value->contains(x, y))
+			return it->_key;
 	}
-	return 0;
+	return "";
 }
 
 

Modified: scummvm/branches/gsoc2008-vkeybd/common/image-map.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/common/image-map.h	2008-07-07 20:40:35 UTC (rev 32949)
+++ scummvm/branches/gsoc2008-vkeybd/common/image-map.h	2008-07-07 21:10:58 UTC (rev 32950)
@@ -26,7 +26,8 @@
 #ifndef COMMON_IMAGEMAP_H
 #define COMMON_IMAGEMAP_H
 
-#include "common/array.h"
+#include "common/hashmap.h"
+#include "common/hash-str.h"
 #include "common/rect.h"
 #include "common/polygon.h"
 
@@ -54,8 +55,7 @@
 protected:
 	/* shape defining the MapArea's boundary */
 	Shape *_shape;
-	/* generalised flags for the area
-	 * TODO: change this */
+	/* string describing the target of MapArea */
 	String _target;
 };
 
@@ -63,13 +63,19 @@
 
 public:
 
-	void addRectMapArea(const Rect& rect, const String& target);
+	~ImageMap();
+	
+	Rect *createRectArea(const String& id);
+	Polygon *createPolygonArea(const String& id);
+
+	//void addMapArea(Shape *shape, const String& target);
+	/*void addRectMapArea(const Rect& rect, const String& target);
 	void addPolygonMapArea(const Polygon& poly, const String& target);
+*/
+	String findMapArea(int16 x, int16 y);
 
-	MapArea *findMapArea(int16 x, int16 y);
-
 protected:
-	Array<MapArea> areas;
+	HashMap<String, Shape*> _areas;
 };
 
 

Modified: scummvm/branches/gsoc2008-vkeybd/dists/msvc8/scummvm.vcproj
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/dists/msvc8/scummvm.vcproj	2008-07-07 20:40:35 UTC (rev 32949)
+++ scummvm/branches/gsoc2008-vkeybd/dists/msvc8/scummvm.vcproj	2008-07-07 21:10:58 UTC (rev 32950)
@@ -1362,6 +1362,14 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\graphics\surface-keycolored.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\..\graphics\surface-keycolored.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\graphics\surface.cpp"
 				>
 			</File>

Modified: scummvm/branches/gsoc2008-vkeybd/graphics/module.mk
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/graphics/module.mk	2008-07-07 20:40:35 UTC (rev 32949)
+++ scummvm/branches/gsoc2008-vkeybd/graphics/module.mk	2008-07-07 21:10:58 UTC (rev 32950)
@@ -16,7 +16,8 @@
 	primitives.o \
 	scaler.o \
 	scaler/thumbnail.o \
-	surface.o
+	surface.o \
+	surface-keycolored.o
 
 ifndef DISABLE_SCALERS
 MODULE_OBJS += \

Added: scummvm/branches/gsoc2008-vkeybd/graphics/surface-keycolored.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/graphics/surface-keycolored.cpp	                        (rev 0)
+++ scummvm/branches/gsoc2008-vkeybd/graphics/surface-keycolored.cpp	2008-07-07 21:10:58 UTC (rev 32950)
@@ -0,0 +1,28 @@
+#include "graphics/surface-keycolored.h"
+
+namespace Graphics {
+
+void SurfaceKeyColored::blit(Surface *surf_src, int16 x, int16 y, OverlayColor trans) {
+	
+	if (bytesPerPixel != sizeof(OverlayColor) || surf_src->bytesPerPixel != sizeof(OverlayColor)) return ;
+
+	OverlayColor *dst = (OverlayColor*) getBasePtr(x, y);
+	const OverlayColor *src = (const OverlayColor*)surf_src->pixels;
+
+	int blitW = (surf_src->w + x > w) ? w - x : surf_src->w;
+	int blitH = (surf_src->h + y > h) ? h - y : surf_src->h;
+	int dstAdd = w - blitW;
+	int srcAdd = surf_src->w - blitW;
+
+	for (int i = 0; i < blitH; ++i) { 
+		for (int j = 0; j < blitW; ++j, ++dst, ++src) { 
+			OverlayColor col = *src;
+			if (col != trans)
+				*dst = col;
+		}
+		dst += dstAdd;
+		src += srcAdd; 
+	}
+}
+
+} // end of namespace Graphics
\ No newline at end of file


Property changes on: scummvm/branches/gsoc2008-vkeybd/graphics/surface-keycolored.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Added: scummvm/branches/gsoc2008-vkeybd/graphics/surface-keycolored.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/graphics/surface-keycolored.h	                        (rev 0)
+++ scummvm/branches/gsoc2008-vkeybd/graphics/surface-keycolored.h	2008-07-07 21:10:58 UTC (rev 32950)
@@ -0,0 +1,17 @@
+
+#ifndef GRAPHICS_SURFACE_KEYCOLORED_H
+#define GRAPHICS_SURFACE_KEYCOLORED_H
+
+#include "graphics/surface.h"
+
+namespace Graphics {
+
+struct SurfaceKeyColored : Surface {
+
+	void blit(Surface *surf_src, int16 x, int16 y, OverlayColor trans);
+};
+
+
+} // end of namespace Graphics
+
+#endif
\ No newline at end of file


Property changes on: scummvm/branches/gsoc2008-vkeybd/graphics/surface-keycolored.h
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native


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