Moved inventory surface management into inventory.cpp, thus removing Graphics::kBit3. Some duplicated code now exists in graphics.cpp and inventory.cpp.
svn-id: r26123
This commit is contained in:
parent
3346e270ba
commit
2ad8d70152
3 changed files with 47 additions and 61 deletions
|
@ -25,7 +25,6 @@
|
|||
#include "parallaction/graphics.h"
|
||||
#include "parallaction/parser.h"
|
||||
#include "parallaction/parallaction.h"
|
||||
#include "parallaction/inventory.h"
|
||||
#include "parallaction/disk.h"
|
||||
#include "parallaction/zone.h"
|
||||
|
||||
|
@ -312,7 +311,6 @@ void Gfx::copyScreen(Gfx::Buffers srcbuffer, Gfx::Buffers dstbuffer) {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
void Gfx::copyRect(Gfx::Buffers srcbuffer, uint16 sx, uint16 sy, Gfx::Buffers dstbuffer, uint16 dx, uint16 dy, uint16 w, uint16 h) {
|
||||
|
||||
byte *s = _buffers[srcbuffer] + (sx + sy * SCREEN_WIDTH);
|
||||
|
@ -957,23 +955,6 @@ void Gfx::copyRect(Gfx::Buffers dstbuffer, uint16 x, uint16 y, uint16 w, uint16
|
|||
}
|
||||
|
||||
|
||||
void Gfx::drawBorder(Gfx::Buffers buffer, uint16 x, uint16 y, uint16 w, uint16 h, byte color) {
|
||||
|
||||
byte *d = _buffers[buffer] + x + SCREEN_WIDTH * y;
|
||||
|
||||
memset(d, color, w);
|
||||
|
||||
for (uint16 i = 0; i < h; i++) {
|
||||
d[i * SCREEN_WIDTH] = color;
|
||||
d[i * SCREEN_WIDTH + w - 1] = color;
|
||||
}
|
||||
|
||||
d = _buffers[buffer] + x + SCREEN_WIDTH * (y + h - 1);
|
||||
memset(d, color, w);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void Gfx::grabRect(Gfx::Buffers srcbuffer, byte *dst, uint16 x, uint16 y, uint16 w, uint16 h, uint16 pitch) {
|
||||
|
||||
byte *s = _buffers[srcbuffer] + x + SCREEN_WIDTH * y;
|
||||
|
@ -1035,8 +1016,6 @@ void Gfx::initBuffers() {
|
|||
_buffers[kBitFront] = (byte*)malloc(SCREEN_SIZE);
|
||||
_buffers[kBitBack] = (byte*)malloc(SCREEN_SIZE);
|
||||
_buffers[kBit2] = (byte*)malloc(SCREEN_SIZE);
|
||||
_buffers[kBit3] = (byte*)malloc(SCREEN_SIZE); // this buffer is also used by menu so it must stay this size
|
||||
|
||||
_buffers[kMask0] = (byte*)malloc(SCREENMASK_WIDTH * SCREEN_HEIGHT);
|
||||
|
||||
return;
|
||||
|
@ -1073,7 +1052,6 @@ Gfx::~Gfx() {
|
|||
free(_buffers[kBitFront]);
|
||||
free(_buffers[kBitBack]);
|
||||
free(_buffers[kBit2]);
|
||||
free(_buffers[kBit3]);
|
||||
|
||||
freeCnv(&_font);
|
||||
|
||||
|
|
|
@ -72,7 +72,6 @@ public:
|
|||
kBitFront,
|
||||
kBitBack,
|
||||
kBit2,
|
||||
kBit3,
|
||||
// mask buffers
|
||||
kMask0
|
||||
};
|
||||
|
|
|
@ -31,8 +31,7 @@
|
|||
namespace Parallaction {
|
||||
|
||||
//
|
||||
// inventory is kept in Gfx::kBit3 at 0 offset
|
||||
// it is a grid made of (at most) 30 cells, 24x24 pixels each,
|
||||
// inventory is a grid made of (at most) 30 cells, 24x24 pixels each,
|
||||
// arranged in 6 lines
|
||||
//
|
||||
// inventory items are stored in cnv files in a 32x24 grid
|
||||
|
@ -51,9 +50,10 @@ namespace Parallaction {
|
|||
#define INVENTORY_WIDTH (INVENTORY_ITEMS_PER_LINE*INVENTORYITEM_WIDTH)
|
||||
#define INVENTORY_HEIGHT (INVENTORY_LINES*INVENTORYITEM_HEIGHT)
|
||||
|
||||
extern Cnv _yourObjects;
|
||||
uint16 _numInvLines = 0;
|
||||
static Point _invPosition = { 0, 0 };
|
||||
static byte *_buffer;
|
||||
extern Cnv _yourObjects;
|
||||
uint16 _numInvLines = 0;
|
||||
static Point _invPosition = { 0, 0 };
|
||||
|
||||
InventoryItem _inventory[INVENTORY_MAX_ITEMS] = {
|
||||
{ kZoneDoor, 1 }, // open/close icon
|
||||
|
@ -187,19 +187,35 @@ void drawInventoryItem(uint16 pos, InventoryItem *item) {
|
|||
uint16 line = pos / INVENTORY_ITEMS_PER_LINE;
|
||||
uint16 col = pos % INVENTORY_ITEMS_PER_LINE;
|
||||
|
||||
_vm->_gfx->copyRect(
|
||||
Gfx::kBit3,
|
||||
col * INVENTORYITEM_WIDTH,
|
||||
line * _yourObjects._height,
|
||||
INVENTORYITEM_WIDTH,
|
||||
_yourObjects._height,
|
||||
_yourObjects._array[item->_index],
|
||||
INVENTORYITEM_PITCH
|
||||
);
|
||||
// FIXME: this will end up in a general blit function
|
||||
byte* s = _yourObjects._array[item->_index];
|
||||
byte* d = _buffer + col * INVENTORYITEM_WIDTH + line * _yourObjects._height * INVENTORY_WIDTH;
|
||||
for (uint32 i = 0; i < INVENTORYITEM_HEIGHT; i++) {
|
||||
memcpy(d, s, INVENTORYITEM_WIDTH);
|
||||
|
||||
d += INVENTORY_WIDTH;
|
||||
s += INVENTORYITEM_PITCH;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void drawBorder(const Common::Rect& r, byte *buffer, byte color) {
|
||||
|
||||
byte *d = buffer + r.left + INVENTORY_WIDTH * r.top;
|
||||
|
||||
memset(d, color, r.width());
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//
|
||||
// draws a color border around the specified position in the inventory
|
||||
|
@ -213,14 +229,10 @@ void highlightInventoryItem(int16 pos, byte color) {
|
|||
uint16 line = pos / INVENTORY_ITEMS_PER_LINE;
|
||||
uint16 col = pos % INVENTORY_ITEMS_PER_LINE;
|
||||
|
||||
_vm->_gfx->drawBorder(
|
||||
Gfx::kBit3,
|
||||
col * INVENTORYITEM_WIDTH,
|
||||
line * _yourObjects._height,
|
||||
INVENTORYITEM_WIDTH,
|
||||
_yourObjects._height,
|
||||
color
|
||||
);
|
||||
Common::Rect r(INVENTORYITEM_WIDTH, _yourObjects._height);
|
||||
r.moveTo(col * INVENTORYITEM_WIDTH, line * _yourObjects._height);
|
||||
|
||||
drawBorder(r, _buffer, color);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -234,15 +246,15 @@ void extractInventoryGraphics(int16 pos, byte *dst) {
|
|||
int16 line = pos / INVENTORY_ITEMS_PER_LINE;
|
||||
int16 col = pos % INVENTORY_ITEMS_PER_LINE;
|
||||
|
||||
_vm->_gfx->grabRect(
|
||||
Gfx::kBit3,
|
||||
dst,
|
||||
col * INVENTORYITEM_WIDTH,
|
||||
line * _yourObjects._height,
|
||||
INVENTORYITEM_WIDTH,
|
||||
_yourObjects._height,
|
||||
INVENTORYITEM_PITCH
|
||||
);
|
||||
// FIXME: this will end up in a general blit function
|
||||
byte* d = dst;
|
||||
byte* s = _buffer + col * INVENTORYITEM_WIDTH + line * _yourObjects._height * INVENTORY_WIDTH;
|
||||
for (uint32 i = 0; i < INVENTORYITEM_HEIGHT; i++) {
|
||||
memcpy(d, s, INVENTORYITEM_WIDTH);
|
||||
|
||||
s += INVENTORY_WIDTH;
|
||||
d += INVENTORYITEM_PITCH;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -257,19 +269,15 @@ void jobShowInventory(void *parm, Job *j) {
|
|||
_numInvLines = (_numInvLines + 4) / INVENTORY_ITEMS_PER_LINE;
|
||||
|
||||
_vm->_gfx->copyRect(
|
||||
Gfx::kBit3,
|
||||
0,
|
||||
0,
|
||||
Gfx::kBitBack,
|
||||
_invPosition._x,
|
||||
_invPosition._y,
|
||||
INVENTORY_WIDTH,
|
||||
_numInvLines * INVENTORYITEM_HEIGHT
|
||||
_numInvLines * INVENTORYITEM_HEIGHT,
|
||||
_buffer,
|
||||
INVENTORY_WIDTH
|
||||
);
|
||||
|
||||
|
||||
// printf("done\n");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -355,6 +363,7 @@ void redrawInventory() {
|
|||
}
|
||||
|
||||
void initInventory() {
|
||||
_buffer = (byte*)malloc(INVENTORY_WIDTH * INVENTORY_HEIGHT); // this buffer is also used by menu so it must stay this size
|
||||
_yourObjects._count = 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue