Skip to content

Commit

Permalink
TONY: Refactor RMPointer class to use the ScummVM CursorMan
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Jun 13, 2012
1 parent 5bafab9 commit 746dcf3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 42 deletions.
73 changes: 45 additions & 28 deletions engines/tony/game.cpp
Expand Up @@ -29,6 +29,7 @@
#include "common/file.h"
#include "common/savefile.h"
#include "common/textconsole.h"
#include "graphics/cursorman.h"
#include "tony/mpal/lzo.h"
#include "tony/mpal/memory.h"
#include "tony/mpal/mpal.h"
Expand Down Expand Up @@ -1543,46 +1544,62 @@ void RMPointer::draw(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim
_ctx->n = _nCurPointer;
if (_ctx->n == TA_COMBINE) _ctx->n = TA_USE;

// Copy the destination coordinates in the primitive
prim->setDst(_pos);
_cursorHotspot = _hotspot[_ctx->n];

if (_pos._x >= 0 && _pos._y >= 0 && _pos._x < RM_SX && _pos._y < RM_SY) {
// Call the Draw method of the poitner
prim->getDst() -= _hotspot[_ctx->n];

if (_nCurSpecialPointer == 0) {
CORO_INVOKE_2(_pointer[_ctx->n]->draw, bigBuf, prim);
} else {
if (_nCurSpecialPointer == PTR_CUSTOM)
CORO_INVOKE_2(_nCurCustomPointer->draw, bigBuf, prim);
else
// Call the draw on the special pointer
CORO_INVOKE_2(_specialPointer[_nCurSpecialPointer - 1]->draw, bigBuf, prim);
}
// Call the Draw method of the pointer
if (_nCurSpecialPointer == 0) {
CORO_INVOKE_2(_pointer[_ctx->n]->draw, bigBuf, prim);
} else {
if (_nCurSpecialPointer == PTR_CUSTOM)
CORO_INVOKE_2(_nCurCustomPointer->draw, bigBuf, prim);
else
// Call the draw on the special pointer
CORO_INVOKE_2(_specialPointer[_nCurSpecialPointer - 1]->draw, bigBuf, prim);
}

CORO_END_CODE;
}

void RMPointer::doFrame(RMGfxTargetBuffer *bigBuf) {
// Add it to the list of primitives
bigBuf->addPrim(new RMGfxPrimitive(this));
int RMPointer::curAction(void) {
if (_nCurSpecialPointer != 0)
return 0;

// If there is a special pointer, does DoFrame
if (_nCurSpecialPointer != 0 && _nCurSpecialPointer != PTR_CUSTOM)
_specialPointer[_nCurSpecialPointer - 1]->doFrame(bigBuf, false);
return _nCurPointer;
}

void RMPointer::removeThis(CORO_PARAM, bool &result) {
// Always remove from the OT list, to support disabling the pointer
result = true;
/**
* Show the cursor
*/
void RMPointer::showCursor() {
if (!CursorMan.isVisible()) {
CursorMan.showMouse(true);

updateCursor();
}
}

int RMPointer::curAction(void) {
if (_nCurSpecialPointer != 0)
return 0;
/**
* Hide the cursor
*/
void RMPointer::hideCursor() {
if (CursorMan.isVisible()) {
CursorMan.showMouse(false);
}
}

return _nCurPointer;

void RMPointer::updateCursor() {
// Create an intermediate buffer and draw the cursor onto it
RMGfxTargetBuffer buf;
buf.create(64, 64, 16);
RMGfxPrimitive prim;

draw(Common::nullContext, buf, &prim);

// Get the raw pixel data and set the cursor to it
const byte *cursorData = buf;
Graphics::PixelFormat pixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0);
CursorMan.replaceCursor(cursorData, 64, 64, _cursorHotspot._x, _cursorHotspot._y, 0, 1, &pixelFormat);
}

} // End of namespace Tony
28 changes: 16 additions & 12 deletions engines/tony/game.h
Expand Up @@ -54,11 +54,11 @@ namespace Tony {
delete raw;


class RMPointer : public RMGfxTask {
class RMPointer {
private:
RMGfxSourceBuffer8 *_pointer[16];
RMPoint _hotspot[16];
RMPoint _pos;
RMPoint _cursorHotspot;

RMItem *_specialPointer[16];

Expand All @@ -67,6 +67,8 @@ class RMPointer : public RMGfxTask {

RMGfxSourceBuffer8 *_nCurCustomPointer;

void updateCursor();

public:
enum POINTER {
PTR_NONE = 0,
Expand Down Expand Up @@ -95,27 +97,22 @@ class RMPointer : public RMGfxTask {
// Overloading of priorities
int priority();

// Overloading draw method
virtual void draw(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim);

// Sets the current co-ordinates
void setCoord(const RMPoint &pt) {
_pos = pt;
}

// Overloading of the method to see if rising from the list
virtual void removeThis(CORO_PARAM, bool &result);
// draw method
void draw(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim);

// Sets a new action as current
void setAction(RMTonyAction action) {
_nCurPointer = action;
updateCursor();
}

// Sets a new pointer
void setSpecialPointer(POINTER ptr) {
_nCurSpecialPointer = ptr;
if (_nCurSpecialPointer && _nCurSpecialPointer != PTR_CUSTOM)
_specialPointer[ptr - 1]->setPattern(1);

updateCursor();
}
POINTER getSpecialPointer(void) {
return (POINTER)_nCurSpecialPointer;
Expand All @@ -124,10 +121,17 @@ class RMPointer : public RMGfxTask {
// Set the new custom pointer
void setCustomPointer(RMGfxSourceBuffer8 *ptr) {
_nCurCustomPointer = ptr;
updateCursor();
}

// Return the current action to be applied according to the pointer
int curAction(void);

/** Show the cursor */
void showCursor();

/** Hide the cursor */
void hideCursor();
};

class RMOptionButton: public RMGfxTaskSetPrior {
Expand Down
5 changes: 3 additions & 2 deletions engines/tony/gfxengine.cpp
Expand Up @@ -305,8 +305,9 @@ void RMGfxEngine::doFrame(CORO_PARAM, bool bDrawLocation) {
_tony.setScrollPosition(_loc.scrollPosition());

if ((!_tony.inAction() && _bInput) || _bAlwaysDrawMouse) {
_point.setCoord(_input.mousePos());
_point.doFrame(&_bigBuf);
_point.showCursor();
} else {
_point.hideCursor();
}

// **********************
Expand Down

0 comments on commit 746dcf3

Please sign in to comment.