diff options
| -rw-r--r-- | engines/parallaction/inventory.cpp | 73 | ||||
| -rw-r--r-- | engines/parallaction/inventory.h | 8 | 
2 files changed, 35 insertions, 46 deletions
| diff --git a/engines/parallaction/inventory.cpp b/engines/parallaction/inventory.cpp index 56a29ea277..2f6b5ac7a1 100644 --- a/engines/parallaction/inventory.cpp +++ b/engines/parallaction/inventory.cpp @@ -50,13 +50,14 @@ namespace Parallaction {  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 @@ void Parallaction::dropItem(uint16 v) {  	_inv->removeItem(v);  } -  bool Parallaction::isItemInInventory(int32 v) {  	return (_inv->findItem(v) != -1);  } @@ -98,6 +98,13 @@ void cleanInventory(bool keepVerbs) {  	_inv->clear(keepVerbs);  } +void openInventory() { +	_re->showInventory(); +} + +void closeInventory() { +	_re->hideInventory(); +} @@ -124,24 +131,16 @@ void Parallaction_ns::jobHideInventory(void *parm, Job *j) {  	_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 @@ ItemPosition InventoryRenderer::hitTest(const Common::Point &p) const {  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 InventoryRenderer::refresh() {  	}  } -void drawBorder(const Common::Rect& r, byte *buffer, byte color) { - -	byte *d = buffer + r.left + INVENTORY_WIDTH * r.top; - -	memset(d, color, r.width()); +void InventoryRenderer::highlightItem(ItemPosition pos, byte color) { +	if (pos == -1) +		return; -	for (uint16 i = 0; i < r.height(); i++) { -		d[i * INVENTORY_WIDTH] = color; -		d[i * INVENTORY_WIDTH + r.width() - 1] = color; -	} +	Common::Rect r; +	getItemRect(pos, r); -	d = buffer + r.left + INVENTORY_WIDTH * (r.bottom - 1); -	memset(d, color, r.width()); +	if (color != 12) +		color = 19; -	return; +	_surf.frameRect(r, color);  } -// -//	draws a color border around the specified position in the inventory -// -void highlightInventoryItem(ItemPosition pos, byte color) { - -	if (color != 12) color = 19; +void InventoryRenderer::getItemRect(ItemPosition pos, Common::Rect &r) { -	if (pos == -1) return; +	r.setHeight(INVENTORYITEM_HEIGHT); +	r.setWidth(INVENTORYITEM_WIDTH);  	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()); - -	drawBorder(r, _re->getData(), color); +	r.moveTo(col * INVENTORYITEM_WIDTH, line * INVENTORYITEM_HEIGHT); -	return;  } @@ -262,6 +245,8 @@ void highlightInventoryItem(ItemPosition pos, byte color) { + +  Inventory::Inventory(uint16 maxItems) : _maxItems(maxItems), _numItems(0) {  	_items = (InventoryItem*)calloc(_maxItems, sizeof(InventoryItem)); diff --git a/engines/parallaction/inventory.h b/engines/parallaction/inventory.h index 442b97b41c..6440f48aa6 100644 --- a/engines/parallaction/inventory.h +++ b/engines/parallaction/inventory.h @@ -27,6 +27,7 @@  #define PARALLACTION_INVENTORY_H +#include "graphics/surface.h"  namespace Parallaction { @@ -91,9 +92,11 @@ class InventoryRenderer {  	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 @@ public:  	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; | 
