From 212d4ed9135a15c08b98bc2e370f289513e80274 Mon Sep 17 00:00:00 2001 From: Nicola Mettifogo Date: Tue, 25 Sep 2007 15:58:44 +0000 Subject: Changed InventoryRenderer to draw inventory over a Surface, thus removing useless drawing routines. svn-id: r29097 --- engines/parallaction/inventory.cpp | 73 +++++++++++++++----------------------- 1 file changed, 29 insertions(+), 44 deletions(-) (limited to 'engines/parallaction/inventory.cpp') 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)); -- cgit v1.2.3