From 49218970131904419777873019fbc8067d1d7a30 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 1 Mar 2017 22:22:16 -0500 Subject: TITANIC: Implemented CStarView MouseMoveMsg --- engines/titanic/star_control/fpoint.cpp | 3 +- engines/titanic/star_control/fpoint.h | 5 ++- .../titanic/star_control/star_control_sub12.cpp | 4 +-- engines/titanic/star_control/star_control_sub12.h | 8 ++++- engines/titanic/star_control/star_control_sub2.cpp | 4 +-- engines/titanic/star_control/star_control_sub2.h | 2 +- engines/titanic/star_control/star_view.cpp | 37 ++++++++++++++++------ engines/titanic/star_control/star_view.h | 4 +-- 8 files changed, 48 insertions(+), 19 deletions(-) (limited to 'engines') diff --git a/engines/titanic/star_control/fpoint.cpp b/engines/titanic/star_control/fpoint.cpp index a2829572f8..a7c764177a 100644 --- a/engines/titanic/star_control/fpoint.cpp +++ b/engines/titanic/star_control/fpoint.cpp @@ -25,13 +25,14 @@ namespace Titanic { -void FPoint::normalize() { +double FPoint::normalize() { double hyp = sqrt(_x * _x + _y * _y); assert(hyp != 0.0); double fraction = 1.0 / hyp; _x *= fraction; _y *= fraction; + return hyp; } } // End of namespace Titanic diff --git a/engines/titanic/star_control/fpoint.h b/engines/titanic/star_control/fpoint.h index 9ce58c08af..d967351289 100644 --- a/engines/titanic/star_control/fpoint.h +++ b/engines/titanic/star_control/fpoint.h @@ -23,6 +23,8 @@ #ifndef TITANIC_FPOINT_H #define TITANIC_FPOINT_H +#include "common/rect.h" + namespace Titanic { /** @@ -34,6 +36,7 @@ public: public: FPoint() : _x(0), _y(0) {} FPoint(double x, double y) : _x(x), _y(y) {} + FPoint(const Common::Point &pt) : _x(pt.x), _y(pt.y) {} bool operator==(const FPoint &p) const { return _x == p._x && _y == p._y; } bool operator!=(const FPoint &p) const { return _x != p._x || _y != p._y; } @@ -54,7 +57,7 @@ public: * Normalises the X and Y coordinates as fractions relative to the * value of the hypotenuse formed by a triangle from the origin (0,0) */ - void normalize(); + double normalize(); }; } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub12.cpp b/engines/titanic/star_control/star_control_sub12.cpp index e8d49992bb..b60bb0ae3f 100644 --- a/engines/titanic/star_control/star_control_sub12.cpp +++ b/engines/titanic/star_control/star_control_sub12.cpp @@ -216,8 +216,8 @@ FVector CStarControlSub12::proc31(int index, const FVector &v) { return _sub13.fn18(index, v); } -void CStarControlSub12::proc32(double v1, double v2) { - error("TODO: CStarControlSub12::proc32"); +void CStarControlSub12::setViewportPosition(const FPoint &pt) { + // TODO } bool CStarControlSub12::setArrayVector(const FVector &v) { diff --git a/engines/titanic/star_control/star_control_sub12.h b/engines/titanic/star_control/star_control_sub12.h index 8da45df5c0..648225140f 100644 --- a/engines/titanic/star_control/star_control_sub12.h +++ b/engines/titanic/star_control/star_control_sub12.h @@ -25,6 +25,7 @@ #include "titanic/support/simple_file.h" #include "titanic/star_control/fmatrix.h" +#include "titanic/star_control/fpoint.h" #include "titanic/star_control/star_control_sub13.h" #include "titanic/star_control/star_control_sub20.h" @@ -93,7 +94,12 @@ public: virtual FVector proc29(const FVector &v); virtual FVector proc30(int index, const FVector &v); virtual FVector proc31(int index, const FVector &v); - virtual void proc32(double v1, double v2); + + /** + * Sets the viewport position within the starfield + */ + virtual void setViewportPosition(const FPoint &pt); + virtual int getCurrentIndex() const { return _currentIndex; } virtual bool setArrayVector(const FVector &v); virtual bool proc35(); diff --git a/engines/titanic/star_control/star_control_sub2.cpp b/engines/titanic/star_control/star_control_sub2.cpp index fcbb70cbcb..f020e2ceb5 100644 --- a/engines/titanic/star_control/star_control_sub2.cpp +++ b/engines/titanic/star_control/star_control_sub2.cpp @@ -24,9 +24,9 @@ namespace Titanic { -bool CStarControlSub2::proc3(int v1) { +bool CStarControlSub2::loadYale(int v1) { clear(); - // TODO + error("Original loadYale not supported"); return true; } diff --git a/engines/titanic/star_control/star_control_sub2.h b/engines/titanic/star_control/star_control_sub2.h index cd7781548f..c3d756e793 100644 --- a/engines/titanic/star_control/star_control_sub2.h +++ b/engines/titanic/star_control/star_control_sub2.h @@ -31,7 +31,7 @@ class CStarControlSub2: public CBaseStar { public: virtual ~CStarControlSub2() {} - virtual bool proc3(int v1); + virtual bool loadYale(int v1); virtual bool proc4(int v1, int v2, int v3, int v4, int v5); virtual bool loadStar(); virtual bool proc7(int v1, int v2); diff --git a/engines/titanic/star_control/star_view.cpp b/engines/titanic/star_control/star_view.cpp index d10e0ee094..46e4702caa 100644 --- a/engines/titanic/star_control/star_view.cpp +++ b/engines/titanic/star_control/star_view.cpp @@ -31,9 +31,8 @@ namespace Titanic { CStarView::CStarView() : _sub12(nullptr, nullptr), _sub13((void *)nullptr), _owner(nullptr), _starField(nullptr), _videoSurface(nullptr), _field118(0), _videoSurface2(nullptr), _homePhotoMask(nullptr), - _field218(0), _field21C(0) { - CStar20Data data = { 0, 0, 0x47C35000, 0, 0x41A00000, - 0x3F800000, 0x3F800000, 0x3F800000 }; + _field218(0), _showingPhoto(false) { + CStar20Data data = { 0, 0, 100000.0, 0, 20.0, 1.0, 1.0, 1.0 }; _sub12.proc3(&data); } @@ -47,7 +46,7 @@ void CStarView::load(SimpleFile *file, int param) { _sub13.load(file, 0); _field218 = file->readNumber(); - _field21C = file->readNumber(); + _showingPhoto = file->readNumber(); } } @@ -59,7 +58,7 @@ void CStarView::save(SimpleFile *file, int indent) { _sub13.save(file, indent); file->writeNumberLine(_field218, indent); - file->writeNumberLine(_field21C, indent); + file->writeNumberLine(_showingPhoto, indent); } void CStarView::setup(CScreenManager *screenManager, CStarField *starField, CStarControl *starControl) { @@ -76,13 +75,13 @@ void CStarView::draw(CScreenManager *screenManager) { return; if (_fader.isActive()) { - CVideoSurface *surface = _field21C ? _videoSurface2 : _videoSurface; + CVideoSurface *surface = _showingPhoto ? _videoSurface2 : _videoSurface; surface = _fader.fade(screenManager, surface); screenManager->blitFrom(SURFACE_PRIMARY, surface); } else { Point destPos(20, 10); - if (_field21C) { + if (_showingPhoto) { screenManager->blitFrom(SURFACE_PRIMARY, _videoSurface2, &destPos); if (!_homePhotoMask && _owner) { @@ -110,8 +109,28 @@ void CStarView::MouseButtonDownMsg(int unused, const Point &pt) { // TODO } -void CStarView::MouseMoveMsg(int unused, const Point &pt) { - // TODO +bool CStarView::MouseMoveMsg(int unused, const Point &pt) { + if (!_showingPhoto && (_fader._index < 0 || _fader._count >= 0)) { + FPoint fpt = pt; + FPoint centerPt(300.0, 170.0); + + if (fpt != centerPt) { + double threshold = MIN(centerPt._x, centerPt._y) * 0.5; + FPoint tempPt = fpt - centerPt; + + double distance = tempPt.normalize(); + if (distance >= threshold) { + distance -= threshold; + + FPoint relPt(tempPt._x * -2.0 * distance / threshold, + tempPt._y * -2.0 * distance / threshold); + _sub12.setViewportPosition(relPt); + return true; + } + } + } + + return false; } CErrorCode CStarView::KeyCharMsg(int key) { diff --git a/engines/titanic/star_control/star_view.h b/engines/titanic/star_control/star_view.h index 5e958c8053..4fd640cb9d 100644 --- a/engines/titanic/star_control/star_view.h +++ b/engines/titanic/star_control/star_view.h @@ -47,7 +47,7 @@ private: CVideoSurface *_videoSurface2; CGameObject *_homePhotoMask; int _field218; - int _field21C; + bool _showingPhoto; #if 0 int _field210; #endif @@ -86,7 +86,7 @@ public: /** * Handles mouse move messages */ - void MouseMoveMsg(int unused, const Point &pt); + bool MouseMoveMsg(int unused, const Point &pt); /** * Handles keyboard messages -- cgit v1.2.3