From 2c2773c4c367ced48cb5fac1a212a2365e918c43 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Fri, 10 Feb 2006 21:18:53 +0000 Subject: [PATCH] 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 --- src/kits/interface/TPicture.cpp | 21 +++++++++------------ src/servers/app/ServerPicture.cpp | 17 +++++++++++------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/kits/interface/TPicture.cpp b/src/kits/interface/TPicture.cpp index 439c86f9f1..f3c981a4d9 100644 --- a/src/kits/interface/TPicture.cpp +++ b/src/kits/interface/TPicture.cpp @@ -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(); diff --git a/src/servers/app/ServerPicture.cpp b/src/servers/app/ServerPicture.cpp index 3890545e7e..36f30828b6 100644 --- a/src/servers/app/ServerPicture.cpp +++ b/src/servers/app/ServerPicture.cpp @@ -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); }