From 237925e5fddf21dba86155fc9d10aba7355cc9ed Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Sun, 5 Dec 2010 22:11:07 +0000 Subject: MOHAWK: improve LBPaletteItem support svn-id: r54793 --- engines/mohawk/livingbooks.cpp | 44 ++++++++++++++++++++++++++++++++++++------ engines/mohawk/livingbooks.h | 6 ++++-- 2 files changed, 42 insertions(+), 8 deletions(-) (limited to 'engines') diff --git a/engines/mohawk/livingbooks.cpp b/engines/mohawk/livingbooks.cpp index 2bbb27bbb9..ee340af2db 100644 --- a/engines/mohawk/livingbooks.cpp +++ b/engines/mohawk/livingbooks.cpp @@ -2573,6 +2573,7 @@ void LBGroupItem::stop() { LBPaletteItem::LBPaletteItem(MohawkEngine_LivingBooks *vm, Common::Rect rect) : LBItem(vm, rect) { debug(3, "new LBPaletteItem"); + _fadeInStart = 0; } void LBPaletteItem::readData(uint16 type, uint16 size, Common::SeekableSubReadStreamEndian *stream) { @@ -2580,8 +2581,8 @@ void LBPaletteItem::readData(uint16 type, uint16 size, Common::SeekableSubReadSt case kLBPaletteXData: { assert(size == 8 + 255 * 4); - _start = stream->readUint16(); - _count = stream->readUint16(); + _fadeInPeriod = stream->readUint16(); + _fadeInStep = stream->readUint16(); _drawStart = stream->readUint16(); _drawCount = stream->readUint16(); stream->read(_palette, 255 * 4); @@ -2593,11 +2594,42 @@ void LBPaletteItem::readData(uint16 type, uint16 size, Common::SeekableSubReadSt } } -void LBPaletteItem::draw() { - if (!_visible || !_globalVisible) - return; +bool LBPaletteItem::togglePlaying(bool playing, bool restart) { + // TODO: this likely isn't the right place + + if (playing) { + _fadeInStart = _vm->_system->getMillis(); + _fadeInCurrent = 0; + + return true; + } + + return LBItem::togglePlaying(playing, restart); +} - _vm->_system->setPalette(_palette + _drawStart * 4, _drawStart, _drawCount); +void LBPaletteItem::update() { + if (_fadeInStart) { + uint32 elapsedTime = _vm->_system->getMillis() - _fadeInStart; + uint32 divTime = elapsedTime / _fadeInStep; + + if (divTime > _fadeInPeriod) + divTime = _fadeInPeriod; + + if (_fadeInCurrent != divTime) { + _fadeInCurrent = divTime; + + // TODO: actual fading-in + if (_visible && _globalVisible) + _vm->_system->setPalette(_palette + _drawStart * 4, _drawStart, _drawCount); + } + + if (elapsedTime >= (uint32)_fadeInPeriod * (uint32)_fadeInStep) { + // TODO: correct? + _fadeInStart = 0; + } + } + + LBItem::update(); } LBLiveTextItem::LBLiveTextItem(MohawkEngine_LivingBooks *vm, Common::Rect rect) : LBItem(vm, rect) { diff --git a/engines/mohawk/livingbooks.h b/engines/mohawk/livingbooks.h index 4215889574..db6948e2ad 100644 --- a/engines/mohawk/livingbooks.h +++ b/engines/mohawk/livingbooks.h @@ -365,10 +365,12 @@ public: void readData(uint16 type, uint16 size, Common::SeekableSubReadStreamEndian *stream); - void draw(); + bool togglePlaying(bool playing, bool restart); + void update(); protected: - uint16 _start, _count, _drawStart, _drawCount; + uint16 _fadeInPeriod, _fadeInStep, _drawStart, _drawCount; + uint32 _fadeInStart, _fadeInCurrent; byte _palette[255 * 4]; }; -- cgit v1.2.3