Skip to content

Commit

Permalink
SHERLOCK: Move scroll variables from Screen to TattooUserInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed May 31, 2015
1 parent c7e9219 commit 8d60f1e
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 68 deletions.
2 changes: 1 addition & 1 deletion engines/sherlock/scene.cpp
Expand Up @@ -336,7 +336,7 @@ bool Scene::loadScene(const Common::String &filename) {
screen.translatePalette(screen._cMap);
screen.setupBGArea(screen._cMap);

screen.initScrollVars();
ui.initScrollVars();

// Read in background
if (_lzwMode) {
Expand Down
23 changes: 10 additions & 13 deletions engines/sherlock/screen.cpp
Expand Up @@ -44,10 +44,6 @@ Screen::Screen(SherlockEngine *vm) : Surface(g_system->getWidth(), g_system->get
// Rose Tattoo specific fields
_fadeBytesRead = _fadeBytesToRead = 0;
_oldFadePercent = 0;
_scrollSize = 0;
_scrollSpeed = 0;
_currentScroll = 0;
_targetScroll = 0;
_flushScreen = false;
}

Expand Down Expand Up @@ -310,6 +306,16 @@ void Screen::flushScaleImage(ImageFrame *frame, const Common::Point &pt, int16 *
*height = newBounds.height();
}

void Screen::blockMove(const Common::Rect &r, const Common::Point &scrollPos) {
Common::Rect bounds = r;
bounds.translate(scrollPos.x, scrollPos.y);
slamRect(bounds);
}

void Screen::blockMove(const Common::Point &scrollPos) {
blockMove(Common::Rect(0, 0, w(), h()), scrollPos);
}

void Screen::print(const Common::Point &pt, byte color, const char *formatStr, ...) {
// Create the string to display
va_list args;
Expand Down Expand Up @@ -491,15 +497,6 @@ void Screen::setupBGArea(const byte cMap[PALETTE_SIZE]) {
warning("TODO");
}

/**
* Initializes scroll variables
*/
void Screen::initScrollVars() {
_scrollSize = 0;
_currentScroll = 0;
_targetScroll = 0;
}

void Screen::translatePalette(byte palette[PALETTE_SIZE]) {
for (int idx = 0; idx < PALETTE_SIZE; ++idx)
palette[idx] = VGA_COLOR_TRANS(palette[idx]);
Expand Down
14 changes: 10 additions & 4 deletions engines/sherlock/screen.h
Expand Up @@ -99,8 +99,6 @@ class Screen : public Surface {
byte _cMap[PALETTE_SIZE];
byte _sMap[PALETTE_SIZE];
byte _tMap[PALETTE_SIZE];
int _currentScroll, _targetScroll;
int _scrollSize, _scrollSpeed;
bool _flushScreen;
public:
Screen(SherlockEngine *vm);
Expand Down Expand Up @@ -191,6 +189,16 @@ class Screen : public Surface {
void flushScaleImage(ImageFrame *frame, const Common::Point &pt, int16 *xp, int16 *yp,
int16 *width, int16 *height, int scaleVal);

/**
* Copies data from the back buffer to the screen, taking into account scrolling position
*/
void blockMove(const Common::Rect &r, const Common::Point &scrollPos);

/**
* Copies the entire screen from the back buffer, taking into account scrolling position
*/
void blockMove(const Common::Point &scorllPos);

/**
* Returns the width of a string in pixels
*/
Expand Down Expand Up @@ -257,8 +265,6 @@ class Screen : public Surface {

void setupBGArea(const byte cMap[PALETTE_SIZE]);

void initScrollVars();

/**
* Translate a palette from 6-bit RGB values to full 8-bit values suitable for passing
* to the underlying palette manager
Expand Down
72 changes: 37 additions & 35 deletions engines/sherlock/tattoo/tattoo_scene.cpp
Expand Up @@ -99,8 +99,8 @@ void TattooScene::doBgAnimEraseBackground() {

if (_mask != nullptr) {
if (screen._backBuffer1.w() > screen.w())
screen.blitFrom(screen._backBuffer1, Common::Point(0, 0), Common::Rect(screen._currentScroll, 0,
screen._currentScroll + screen.w(), screen.h()));
screen.blitFrom(screen._backBuffer1, Common::Point(0, 0), Common::Rect(ui._currentScroll.x, 0,
ui._currentScroll.x + screen.w(), screen.h()));
else
screen.blitFrom(screen._backBuffer1);

Expand Down Expand Up @@ -175,22 +175,22 @@ void TattooScene::doBgAnimEraseBackground() {
}

// Adjust the Target Scroll if needed
if ((people[people._walkControl]._position.x / FIXED_INT_MULTIPLIER - screen._currentScroll) <
if ((people[people._walkControl]._position.x / FIXED_INT_MULTIPLIER - ui._currentScroll.x) <
(SHERLOCK_SCREEN_WIDTH / 8) && people[people._walkControl]._delta.x < 0) {

screen._targetScroll = (short)(people[people._walkControl]._position.x / FIXED_INT_MULTIPLIER -
ui._targetScroll.x = (short)(people[people._walkControl]._position.x / FIXED_INT_MULTIPLIER -
SHERLOCK_SCREEN_WIDTH / 8 - 250);
if (screen._targetScroll < 0)
screen._targetScroll = 0;
if (ui._targetScroll.x < 0)
ui._targetScroll.x = 0;
}

if ((people[people._walkControl]._position.x / FIXED_INT_MULTIPLIER - screen._currentScroll) > (SHERLOCK_SCREEN_WIDTH / 4 * 3)
if ((people[people._walkControl]._position.x / FIXED_INT_MULTIPLIER - ui._currentScroll.x) > (SHERLOCK_SCREEN_WIDTH / 4 * 3)
&& people[people._walkControl]._delta.x > 0)
screen._targetScroll = (short)(people[people._walkControl]._position.x / FIXED_INT_MULTIPLIER -
ui._targetScroll.x = (short)(people[people._walkControl]._position.x / FIXED_INT_MULTIPLIER -
SHERLOCK_SCREEN_WIDTH / 4 * 3 + 250);

if (screen._targetScroll > screen._scrollSize)
screen._targetScroll = screen._scrollSize;
if (ui._targetScroll.x > ui._scrollSize)
ui._targetScroll.x = ui._scrollSize;

ui.doScroll();
}
Expand Down Expand Up @@ -231,6 +231,7 @@ void TattooScene::doBgAnim() {
void TattooScene::doBgAnimUpdateBgObjectsAndAnim() {
People &people = *_vm->_people;
Screen &screen = *_vm->_screen;
TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui;

for (uint idx = 0; idx < _bgShapes.size(); ++idx) {
Object &obj = _bgShapes[idx];
Expand All @@ -255,33 +256,33 @@ void TattooScene::doBgAnimUpdateBgObjectsAndAnim() {
if (_mask != nullptr) {
switch (_currentScene) {
case 7:
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x - SHERLOCK_SCREEN_WIDTH, 110), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x, 110), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x + SHERLOCK_SCREEN_WIDTH, 110), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x - SHERLOCK_SCREEN_WIDTH, 110), ui._currentScroll.x);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x, 110), ui._currentScroll.x);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x + SHERLOCK_SCREEN_WIDTH, 110), ui._currentScroll.x);
break;

case 8:
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x - SHERLOCK_SCREEN_WIDTH, 180), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x, 180), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x + SHERLOCK_SCREEN_WIDTH, 180), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x - SHERLOCK_SCREEN_WIDTH, 180), ui._currentScroll.x);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x, 180), ui._currentScroll.x);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x + SHERLOCK_SCREEN_WIDTH, 180), ui._currentScroll.x);
if (!_vm->readFlags(880))
screen._backBuffer1.maskArea((*_mask1)[0], Common::Point(940, 300), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask1)[0], Common::Point(940, 300), ui._currentScroll.x);
break;

case 18:
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x, 203), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x, 203), ui._currentScroll.x);
if (!_vm->readFlags(189))
screen._backBuffer1.maskArea((*_mask1)[0], Common::Point(124 + _maskOffset.x, 239), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask1)[0], Common::Point(124 + _maskOffset.x, 239), ui._currentScroll.x);
break;

case 53:
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x, 110), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x - SHERLOCK_SCREEN_WIDTH, 110), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x, 110), ui._currentScroll.x);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x - SHERLOCK_SCREEN_WIDTH, 110), ui._currentScroll.x);
break;

case 68:
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x, 203), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask1)[0], Common::Point(124 + _maskOffset.x, 239), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x, 203), ui._currentScroll.x);
screen._backBuffer1.maskArea((*_mask1)[0], Common::Point(124 + _maskOffset.x, 239), ui._currentScroll.x);
break;
}
}
Expand All @@ -291,38 +292,39 @@ void TattooScene::doBgAnimUpdateBgObjectsAndAnim() {
void TattooScene::updateBackground() {
People &people = *_vm->_people;
Screen &screen = *_vm->_screen;
TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui;

Scene::updateBackground();

if (_mask != nullptr) {
switch (_currentScene) {
case 7:
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x - SHERLOCK_SCREEN_WIDTH, 110), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x, 110), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x + SHERLOCK_SCREEN_WIDTH, 110), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x - SHERLOCK_SCREEN_WIDTH, 110), ui._currentScroll.x);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x, 110), ui._currentScroll.x);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x + SHERLOCK_SCREEN_WIDTH, 110), ui._currentScroll.x);
break;

case 8:
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x - SHERLOCK_SCREEN_WIDTH, 180), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x, 180), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x + SHERLOCK_SCREEN_WIDTH, 180), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x - SHERLOCK_SCREEN_WIDTH, 180), ui._currentScroll.x);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x, 180), ui._currentScroll.x);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x + SHERLOCK_SCREEN_WIDTH, 180), ui._currentScroll.x);
if (!_vm->readFlags(880))
screen._backBuffer1.maskArea((*_mask1)[0], Common::Point(940, 300), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask1)[0], Common::Point(940, 300), ui._currentScroll.x);
break;

case 18:
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(0, 203), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(0, 203), ui._currentScroll.x);
if (!_vm->readFlags(189))
screen._backBuffer1.maskArea((*_mask1)[0], Common::Point(124, 239), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask1)[0], Common::Point(124, 239), ui._currentScroll.x);
break;

case 53:
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x, 110), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(_maskOffset.x, 110), ui._currentScroll.x);
break;

case 68:
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(0, 203), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask1)[0], Common::Point(124, 239), screen._currentScroll);
screen._backBuffer1.maskArea((*_mask)[0], Common::Point(0, 203), ui._currentScroll.x);
screen._backBuffer1.maskArea((*_mask1)[0], Common::Point(124, 239), ui._currentScroll.x);
break;

default:
Expand Down
46 changes: 31 additions & 15 deletions engines/sherlock/tattoo/tattoo_user_interface.cpp
Expand Up @@ -33,6 +33,13 @@ TattooUserInterface::TattooUserInterface(SherlockEngine *vm): UserInterface(vm)
_invMenuBuffer = nullptr;
_tagBuffer = nullptr;
_invGraphic = nullptr;
_scrollSize = _scrollSpeed = 0;
}

void TattooUserInterface::initScrollVars() {
_scrollSize = 0;
_currentScroll.x = _currentScroll.y = 0;
_targetScroll.x = _targetScroll.y = 0;
}

void TattooUserInterface::handleInput() {
Expand All @@ -41,13 +48,14 @@ void TattooUserInterface::handleInput() {
}

void TattooUserInterface::drawInterface(int bufferNum) {
TattooScene &scene = *(TattooScene *)_vm->_scene;
Screen &screen = *_vm->_screen;
TattooEngine &vm = *((TattooEngine *)_vm);
TattooEngine &vm = *(TattooEngine *)_vm;

if (_invMenuBuffer != nullptr) {
Common::Rect r = _invMenuBounds;
r.grow(-3);
r.translate(-screen._currentScroll, 0);
r.translate(-_currentScroll.x, 0);
_grayAreas.clear();
_grayAreas.push_back(r);

Expand All @@ -58,7 +66,7 @@ void TattooUserInterface::drawInterface(int bufferNum) {
if (_menuBuffer != nullptr) {
Common::Rect r = _menuBounds;
r.grow(-3);
r.translate(-screen._currentScroll, 0);
r.translate(-_currentScroll.x, 0);
_grayAreas.clear();
_grayAreas.push_back(r);

Expand All @@ -76,6 +84,14 @@ void TattooUserInterface::drawInterface(int bufferNum) {

if (vm._creditsActive)
vm.drawCredits();

// Bring the widgets to the screen
if (scene._mask != nullptr)
screen._flushScreen = true;

//if (screen._flushScreen)
// screen.blockMove(_currentScroll.x);

}

void TattooUserInterface::doBgAnimRestoreUI() {
Expand Down Expand Up @@ -118,27 +134,27 @@ void TattooUserInterface::doBgAnimRestoreUI() {

void TattooUserInterface::doScroll() {
Screen &screen = *_vm->_screen;
int oldScroll = screen._currentScroll;
int oldScroll = _currentScroll.x;

// If we're already at the target scroll position, nothing needs to be done
if (screen._targetScroll == screen._currentScroll)
if (_targetScroll.x == _currentScroll.x)
return;

screen._flushScreen = true;
if (screen._targetScroll > screen._currentScroll) {
screen._currentScroll += screen._scrollSpeed;
if (screen._currentScroll > screen._targetScroll)
screen._currentScroll = screen._targetScroll;
} else if (screen._targetScroll < screen._currentScroll) {
screen._currentScroll -= screen._scrollSpeed;
if (screen._currentScroll < screen._targetScroll)
screen._currentScroll = screen._targetScroll;
if (_targetScroll.x > _currentScroll.x) {
_currentScroll.x += _scrollSpeed;
if (_currentScroll.x > _targetScroll.x)
_currentScroll.x = _targetScroll.x;
} else if (_targetScroll.x < _currentScroll.x) {
_currentScroll.x -= _scrollSpeed;
if (_currentScroll.x < _targetScroll.x)
_currentScroll.x = _targetScroll.x;
}

if (_menuBuffer != nullptr)
_menuBounds.translate(screen._currentScroll - oldScroll, 0);
_menuBounds.translate(_currentScroll.x - oldScroll, 0);
if (_invMenuBuffer != nullptr)
_invMenuBounds.translate(screen._currentScroll - oldScroll, 0);
_invMenuBounds.translate(_currentScroll.x - oldScroll, 0);
}

void TattooUserInterface::drawGrayAreas() {
Expand Down
8 changes: 8 additions & 0 deletions engines/sherlock/tattoo/tattoo_user_interface.h
Expand Up @@ -50,6 +50,9 @@ class TattooUserInterface : public UserInterface {
* Draws designated areas of the screen that are meant to be grayed out using grayscale colors
*/
void drawGrayAreas();
public:
Common::Point _currentScroll, _targetScroll;
int _scrollSize, _scrollSpeed;
public:
TattooUserInterface(SherlockEngine *vm);

Expand All @@ -74,6 +77,11 @@ class TattooUserInterface : public UserInterface {
* Draw the user interface onto the screen's back buffers
*/
virtual void drawInterface(int bufferNum = 3);

/**
* Initializes scroll variables
*/
virtual void initScrollVars();
};

} // End of namespace Tattoo
Expand Down
5 changes: 5 additions & 0 deletions engines/sherlock/user_interface.h
Expand Up @@ -123,6 +123,11 @@ class UserInterface {
* Print the previously selected object's decription
*/
virtual void printObjectDesc() {}

/**
* Initializes scroll variables
*/
virtual void initScrollVars() {}
};

} // End of namespace Sherlock
Expand Down

0 comments on commit 8d60f1e

Please sign in to comment.