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

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Tue Sep 25 17:58:45 CEST 2007


Revision: 29097
          http://scummvm.svn.sourceforge.net/scummvm/?rev=29097&view=rev
Author:   peres001
Date:     2007-09-25 08:58:44 -0700 (Tue, 25 Sep 2007)

Log Message:
-----------
Changed InventoryRenderer to draw inventory over a Surface, thus removing useless drawing routines.

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/inventory.cpp
    scummvm/trunk/engines/parallaction/inventory.h

Modified: scummvm/trunk/engines/parallaction/inventory.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/inventory.cpp	2007-09-25 04:59:44 UTC (rev 29096)
+++ scummvm/trunk/engines/parallaction/inventory.cpp	2007-09-25 15:58:44 UTC (rev 29097)
@@ -50,13 +50,14 @@
 Inventory *_inv = 0;
 InventoryRenderer *_re = 0;
 
-//	get inventory item index at position (x,y)
-//	in screen coordinates
-//
+
 int16 Parallaction::getHoverInventoryItem(int16 x, int16 y) {
 	return _re->hitTest(Common::Point(x,y));
 }
 
+void highlightInventoryItem(ItemPosition pos, byte color) {
+	_re->highlightItem(pos, color);
+}
 
 int Parallaction::addInventoryItem(ItemName item) {
 	return _inv->addItem(item);
@@ -70,7 +71,6 @@
 	_inv->removeItem(v);
 }
 
-
 bool Parallaction::isItemInInventory(int32 v) {
 	return (_inv->findItem(v) != -1);
 }
@@ -98,10 +98,17 @@
 	_inv->clear(keepVerbs);
 }
 
+void openInventory() {
+	_re->showInventory();
+}
 
+void closeInventory() {
+	_re->hideInventory();
+}
 
 
 
+
 void Parallaction_ns::jobShowInventory(void *parm, Job *j) {
 	Common::Rect r;
 	_re->getRect(r);
@@ -124,24 +131,16 @@
 	_gfx->restoreBackground(r);
 }
 
-void openInventory() {
-	_re->showInventory();
-}
 
-void closeInventory() {
-	_re->hideInventory();
-}
 
 
 
 InventoryRenderer::InventoryRenderer(Parallaction *vm) : _vm(vm) {
-	_buffer = (byte*)malloc(INVENTORY_WIDTH * INVENTORY_HEIGHT);
+	_surf.create(INVENTORY_WIDTH, INVENTORY_HEIGHT, 1);
 }
 
 InventoryRenderer::~InventoryRenderer() {
-	if (_buffer)
-		free(_buffer);
-	_buffer = 0;
+	_surf.free();
 }
 
 void InventoryRenderer::showInventory() {
@@ -182,16 +181,14 @@
 
 
 void InventoryRenderer::drawItem(ItemPosition pos, ItemName name) {
-	uint16 line = pos / INVENTORY_ITEMS_PER_LINE;
-	uint16 col = pos % INVENTORY_ITEMS_PER_LINE;
 
 	Common::Rect r;
-	_vm->_char._objs->getRect(0, r);
+	getItemRect(pos, r);
 
 	// FIXME: this will end up in a general blit function
 
 	byte* s = _vm->_char._objs->getData(name);
-	byte* d = _buffer + col * INVENTORYITEM_WIDTH + line * r.height() * INVENTORY_WIDTH;
+	byte* d = (byte*)_surf.getBasePtr(r.left, r.top);
 	for (uint32 i = 0; i < INVENTORYITEM_HEIGHT; i++) {
 		memcpy(d, s, INVENTORYITEM_WIDTH);
 
@@ -213,43 +210,29 @@
 	}
 }
 
-void drawBorder(const Common::Rect& r, byte *buffer, byte color) {
+void InventoryRenderer::highlightItem(ItemPosition pos, byte color) {
+	if (pos == -1)
+		return;
 
-	byte *d = buffer + r.left + INVENTORY_WIDTH * r.top;
+	Common::Rect r;
+	getItemRect(pos, r);
 
-	memset(d, color, r.width());
+	if (color != 12)
+		color = 19;
 
-	for (uint16 i = 0; i < r.height(); i++) {
-		d[i * INVENTORY_WIDTH] = color;
-		d[i * INVENTORY_WIDTH + r.width() - 1] = color;
-	}
-
-	d = buffer + r.left + INVENTORY_WIDTH * (r.bottom - 1);
-	memset(d, color, r.width());
-
-	return;
+	_surf.frameRect(r, color);
 }
 
-//
-//	draws a color border around the specified position in the inventory
-//
-void highlightInventoryItem(ItemPosition pos, byte color) {
+void InventoryRenderer::getItemRect(ItemPosition pos, Common::Rect &r) {
 
-	if (color != 12) color = 19;
+	r.setHeight(INVENTORYITEM_HEIGHT);
+	r.setWidth(INVENTORYITEM_WIDTH);
 
-	if (pos == -1) return;
-
 	uint16 line = pos / INVENTORY_ITEMS_PER_LINE;
 	uint16 col = pos % INVENTORY_ITEMS_PER_LINE;
 
-	Common::Rect r;
-	_vm->_char._objs->getRect(0, r);
-	r.setWidth(INVENTORYITEM_WIDTH);
-	r.moveTo(col * INVENTORYITEM_WIDTH, line * r.height());
+	r.moveTo(col * INVENTORYITEM_WIDTH, line * INVENTORYITEM_HEIGHT);
 
-	drawBorder(r, _re->getData(), color);
-
-	return;
 }
 
 
@@ -262,6 +245,8 @@
 
 
 
+
+
 Inventory::Inventory(uint16 maxItems) : _maxItems(maxItems), _numItems(0) {
 	_items = (InventoryItem*)calloc(_maxItems, sizeof(InventoryItem));
 

Modified: scummvm/trunk/engines/parallaction/inventory.h
===================================================================
--- scummvm/trunk/engines/parallaction/inventory.h	2007-09-25 04:59:44 UTC (rev 29096)
+++ scummvm/trunk/engines/parallaction/inventory.h	2007-09-25 15:58:44 UTC (rev 29097)
@@ -27,6 +27,7 @@
 #define PARALLACTION_INVENTORY_H
 
 
+#include "graphics/surface.h"
 
 namespace Parallaction {
 
@@ -91,9 +92,11 @@
 	Inventory 		*_inv;
 	Common::Point	_pos;
 
-	byte			*_buffer;
+	Graphics::Surface	_surf;
 
 protected:
+	void getItemRect(ItemPosition pos, Common::Rect &r);
+
 	void drawItem(ItemPosition pos, ItemName name);
 	void refresh();
 
@@ -107,8 +110,9 @@
 	void hideInventory();
 
 	ItemPosition hitTest(const Common::Point &p) const;
+	void highlightItem(ItemPosition pos, byte color);
 
-	byte*	getData() const { return _buffer; }
+	byte*	getData() const { return (byte*)_surf.pixels; }
 
 	void	getRect(Common::Rect &r) const;
 	int16	getNumLines() const;


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