Fixed a bug which prevented BPictures to be drawn. Small cleanup

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16341 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2006-02-10 21:18:53 +00:00
parent d14dde17c4
commit 2c2773c4c3
2 changed files with 20 additions and 18 deletions

View File

@ -149,24 +149,21 @@ void TPicture::GetData(void *data, int32 size)
fData.Read(data, size);
}
//------------------------------------------------------------------------------
status_t TPicture::Play(void **callBackTable, int32 tableEntries,
void *userData)
status_t TPicture::Play(void **callBackTable, int32 tableEntries, void *userData)
{
// TODO: we should probably check if the functions in the table are not 0
// before calling them.
int16 op=0;
int32 size=0;
off_t pos=0;
// lenght of the stream
size_t length = fData.Seek(0, SEEK_END);
fData.Seek(0, SEEK_SET);
while (fData.Position() < size)
{
op = GetOp();
size = GetInt32();
pos = fData.Position();
while (fData.Position() < length) {
int16 op = GetOp();
int32 size = GetInt32();
off_t pos = fData.Position();
switch (op)
{
switch (op) {
case B_PIC_MOVE_PEN_BY:
{
BPoint where = GetCoord();

View File

@ -457,8 +457,6 @@ ServerPicture::ServerPicture()
ServerPicture::ServerPicture(const ServerPicture &picture)
:
fStack(picture.fStack)
{
fToken = gTokenSpace.NewToken(kPictureToken, this);
@ -474,9 +472,11 @@ ServerPicture::~ServerPicture()
void
ServerPicture::BeginOp(int16 op)
{
int32 size = 0;
fStack.push(fData.Position());
fData.Write(&op, sizeof(op));
// Init the size of the opcode block to 0
size_t size = 0;
fData.Write(&size, sizeof(size));
}
@ -487,10 +487,15 @@ ServerPicture::EndOp()
off_t curPos = fData.Position();
off_t stackPos = fStack.top();
fStack.pop();
// The size of the op is calculated like this:
// current position on the stream minus the position on the stack,
// minus the space occupied by the op code itself (int16)
// and the space occupied by the size field (size_t)
size_t size = curPos - stackPos - sizeof(size_t) - sizeof(int16);
size_t size = curPos - stackPos - 6;
fData.Seek(stackPos + 2, SEEK_SET);
// Size was set to 0 in BeginOp(). Now we overwrite it with the correct value
fData.Seek(stackPos + sizeof(int16), SEEK_SET);
fData.Write(&size, sizeof(size));
fData.Seek(curPos, SEEK_SET);
}