aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2016-04-22 21:43:12 -0400
committerPaul Gilbert2016-07-10 16:11:44 -0400
commit4915f8900aff374b2a71545e788cb95d9da7138a (patch)
tree6d988f68d89c8c5556fc7ec74ee2dd9a2a0c00dc
parenta719b0585fed6bcbce48e924d65cca5d9ff80bf8 (diff)
downloadscummvm-rg350-4915f8900aff374b2a71545e788cb95d9da7138a.tar.gz
scummvm-rg350-4915f8900aff374b2a71545e788cb95d9da7138a.tar.bz2
scummvm-rg350-4915f8900aff374b2a71545e788cb95d9da7138a.zip
TITANIC: Implement more slider functions
-rw-r--r--engines/titanic/pet_control/pet_slider.cpp181
-rw-r--r--engines/titanic/pet_control/pet_slider.h120
2 files changed, 253 insertions, 48 deletions
diff --git a/engines/titanic/pet_control/pet_slider.cpp b/engines/titanic/pet_control/pet_slider.cpp
index 4abf0227a1..bb43cf5741 100644
--- a/engines/titanic/pet_control/pet_slider.cpp
+++ b/engines/titanic/pet_control/pet_slider.cpp
@@ -26,29 +26,31 @@
namespace Titanic {
CPetSlider::CPetSlider() {
- _field4 = 0;
- _field8 = 0;
- _field1C = 0;
- _field20 = 0;
- _field24 = 0;
- _field28 = 0;
- _field2C = 0;
- _field30 = 0;
- _field34 = 0;
+ _flags = 0;
+ _thumbWidth = 0;
+ _thumbHeight = 0;
+ _sliderOffset = 0;
+ _thumbFocused = false;
}
-void CPetSlider::initBounds(Rect *rect) {
- if (rect)
- *rect = _bounds2;
- _bounds2.clear();
+Rect CPetSlider::clearDirtyArea() {
+ Rect result = _dirtyArea;
+ _dirtyArea.clear();
+ return result;
}
-void CPetSlider::proc8() {
-
+bool CPetSlider::checkThumb(const Point &pt) {
+ _thumbFocused = thumbContains(pt);
+ if (_thumbFocused)
+ return true;
+ else
+ return containsPt(pt);
}
-void CPetSlider::proc9() {
-
+bool CPetSlider::resetThumbFocus() {
+ bool result = _thumbFocused;
+ _thumbFocused = false;
+ return result;
}
void CPetSlider::proc10() {
@@ -59,8 +61,15 @@ void CPetSlider::proc11() {
}
-void CPetSlider::proc12() {
+bool CPetSlider::proc12(const Point &pt) {
+ if (thumbContains(pt))
+ return true;
+ if (!containsPt(pt))
+ return false;
+ int newOffset = calcSliderOffset(pt);
+ setSliderOffset(newOffset);
+ return true;
}
void CPetSlider::proc13() {
@@ -71,20 +80,99 @@ void CPetSlider::proc14() {
}
-void CPetSlider::proc15() {
+bool CPetSlider::contains(const Point &pt) const {
+ return thumbContains(pt) || containsPt(pt);
+}
+
+double CPetSlider::getOffsetPixels() const {
+ int maxVal = 0, minVal = 0;
+ if (_flags & ORIENTATION_HORIZONTAL) {
+ maxVal = _slidingRect.right;
+ minVal = _slidingRect.left;
+ }
+ if (_flags & ORIENTATION_VERTICAL) {
+ maxVal = _slidingRect.bottom;
+ minVal = _slidingRect.top;
+ }
+
+ if (minVal == maxVal)
+ return 0.0;
+
+ return _sliderOffset / (maxVal - minVal);
}
-void CPetSlider::proc16() {
+void CPetSlider::setSliderOffset(double offset) {
+ if (_flags & ORIENTATION_HORIZONTAL)
+ _sliderOffset = offset * (_slidingRect.right - _slidingRect.left);
+ if (_flags & ORIENTATION_VERTICAL)
+ _sliderOffset = offset * (_slidingRect.bottom - _slidingRect.top);
}
-void CPetSlider::proc17() {
+void CPetSlider::setOffsetPixels(int offset) {
+ // Add the slider's old position to the dirty area
+ Rect tempRect = getThumbRect();
+ _dirtyArea.combine(tempRect);
+
+ // Set the new offset
+ _sliderOffset = offset;
+ // Add the thumb's new location to the dirty area
+ tempRect = getThumbRect();
+ _dirtyArea.combine(tempRect);
}
-void CPetSlider::proc18() {
+Point CPetSlider::getBackgroundDrawPos() {
+ return Point(_bounds.left, _bounds.top);
+}
+Point CPetSlider::getThumbDrawPos() {
+ Point thumbPos = getThumbCentroidPos();
+ thumbPos -= Point(_thumbWidth / 2, _thumbHeight / 2);
+ return thumbPos;
+}
+
+Point CPetSlider::getThumbCentroidPos() const {
+ Point pt;
+
+ if (_flags & ORIENTATION_HORIZONTAL) {
+ pt = Point(_slidingRect.left + _sliderOffset,
+ _slidingRect.top + _slidingRect.height() / 2);
+ }
+
+ if (_flags & ORIENTATION_VERTICAL) {
+ pt = Point(_slidingRect.left + _slidingRect.width() / 2,
+ _slidingRect.top + _sliderOffset);
+ }
+
+ return pt;
+}
+
+bool CPetSlider::thumbContains(const Point &pt) const {
+ return getThumbRect().contains(pt);
+}
+
+Rect CPetSlider::getThumbRect() const {
+ Rect thumbRect(0, 0, _thumbWidth, _thumbHeight);
+ Point centroid = getThumbCentroidPos();
+ thumbRect.moveTo(centroid.x - _thumbWidth / 2, centroid.y - _thumbHeight / 2);
+
+ return thumbRect;
+}
+
+int CPetSlider::calcSliderOffset(const Point &pt) const {
+ int result = 0;
+
+ if (_flags & ORIENTATION_HORIZONTAL) {
+ result = CLIP(pt.x, _slidingRect.left, _slidingRect.right) - _slidingRect.left;
+ }
+
+ if (_flags & ORIENTATION_VERTICAL) {
+ result = CLIP(pt.y, _slidingRect.top, _slidingRect.bottom) - _slidingRect.top;
+ }
+
+ return result;
}
/*------------------------------------------------------------------------*/
@@ -101,4 +189,53 @@ void CPetSoundSlider::setupThumb(const CString &name, CPetControl *petControl) {
}
}
+void CPetSoundSlider::setupBackground2(const CString &name, CPetControl *petControl) {
+ if (petControl) {
+ CString numStr = "3";
+ int mode = petControl->getState8();
+ if (mode <= 3) {
+ numStr = CString(mode);
+ } else if (mode == 4) {
+ mode = petControl->getStateC();
+ if (mode == 1) {
+ numStr = CString(mode);
+ }
+ }
+
+ CString fullName = numStr + name;
+ setupBackground(fullName, petControl);
+ }
+}
+
+void CPetSoundSlider::setupThumb2(const CString &name, CPetControl *petControl) {
+ if (petControl) {
+ CString numStr = "3";
+ int mode = petControl->getState8();
+ if (mode <= 3) {
+ numStr = CString(mode);
+ }
+ else if (mode == 4) {
+ mode = petControl->getStateC();
+ if (mode == 1) {
+ numStr = CString(mode);
+ }
+ }
+
+ CString fullName = numStr + name;
+ setupThumb(fullName, petControl);
+ }
+}
+
+void CPetSoundSlider::draw(CScreenManager *screenManager) {
+ if (_background) {
+ Point pt = getBackgroundDrawPos();
+ _background->draw(screenManager, pt);
+ }
+
+ if (_thumb) {
+ Point pt = getThumbDrawPos();
+ _thumb->draw(screenManager, pt);
+ }
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/pet_control/pet_slider.h b/engines/titanic/pet_control/pet_slider.h
index a30697a023..a8ef3cbf36 100644
--- a/engines/titanic/pet_control/pet_slider.h
+++ b/engines/titanic/pet_control/pet_slider.h
@@ -29,21 +29,55 @@
namespace Titanic {
+enum SliderOrientation { ORIENTATION_HORIZONTAL = 1, ORIENTATION_VERTICAL = 2 };
+
class CPetControl;
class CPetSlider {
private:
- int _field4;
- int _field8;
+ int _flags;
Rect _bounds;
- int _field1C;
- int _field20;
- int _field24;
- int _field28;
- int _field2C;
- int _field30;
- int _field34;
- Rect _bounds2;
+ Rect _slidingRect;
+ int _thumbWidth;
+ int _thumbHeight;
+ int _sliderOffset;
+ bool _thumbFocused;
+ Rect _dirtyArea;
+private:
+ /**
+ * Center the center position of the slider's thumb
+ */
+ Point getThumbCentroidPos() const;
+
+ /**
+ * Returns true if the passed point is within the thumb
+ */
+ bool thumbContains(const Point &pt) const;
+
+ /**
+ * Gets the area the slider's thumbnail covers
+ */
+ Rect getThumbRect() const;
+
+ /**
+ * Calculates the slider offset at the specificed position
+ */
+ int calcSliderOffset(const Point &pt) const;
+protected:
+ /**
+ * Get the position to draw the background at
+ */
+ Point getBackgroundDrawPos();
+
+ /**
+ * Get the position to draw the slider thumbnail at
+ */
+ Point getThumbDrawPos();
+
+ /**
+ * Returns true if the passed point falls within the slider's bounds
+ */
+ bool containsPt(const Point &pt) const { return _bounds.contains(pt); }
public:
CPetSlider();
@@ -60,42 +94,61 @@ public:
/**
* Setup the background
*/
- virtual void setupBackground(const CString &name, CTreeItem *treeItem) {}
+ virtual void setupBackground2(const CString &name, CPetControl *petControl) {}
/**
* Setup the thumb
*/
- virtual void setupThumb(const CString &name, CTreeItem *treeItem) {}
+ virtual void setupThumb2(const CString &name, CPetControl *petControl) {}
/**
* Reset the slider
*/
virtual void reset(const CString &name) {}
- virtual void proc5() {}
- virtual void proc6() {}
-
/**
- * Reset the bounds of the slider
+ * Draw the slider
+ */
+ virtual void draw(CScreenManager *screenManager) {}
+
+ /**
+ * Reset the dirty area
*/
- virtual void initBounds(Rect *rect);
+ virtual Rect clearDirtyArea();
- virtual void proc8();
- virtual void proc9();
+ /**
+ * Checks whether the slider is highlighted
+ */
+ virtual bool checkThumb(const Point &pt);
+
+ /**
+ * Resets the thumb focused flag
+ */
+ virtual bool resetThumbFocus();
+
virtual void proc10();
virtual void proc11();
- virtual void proc12();
+ virtual bool proc12(const Point &pt);
virtual void proc13();
virtual void proc14();
- virtual void proc15();
- virtual void proc16();
- virtual void proc17();
- virtual void proc18();
+
+
+ virtual bool contains(const Point &pt) const;
/**
- * Returns true if the passed point falls within the slider's bounds
+ * Returns the slider offset in pixels
+ */
+ virtual double getOffsetPixels() const;
+
+ /**
+ * Sets the slider offset
+ */
+ virtual void setSliderOffset(double offset);
+
+ /**
+ * Set a new slider offset in pixels
*/
- bool contains(const Point &pt) const { return _bounds.contains(pt); }
+ virtual void setOffsetPixels(int offset);
};
class CPetSoundSlider : public CPetSlider {
@@ -115,6 +168,21 @@ public:
* Setup the thumb
*/
virtual void setupThumb(const CString &name, CPetControl *petControl);
+
+ /**
+ * Setup the background
+ */
+ virtual void setupBackground2(const CString &name, CPetControl *petControl);
+
+ /**
+ * Setup the thumb
+ */
+ virtual void setupThumb2(const CString &name, CPetControl *petControl);
+
+ /**
+ * Draw the slider
+ */
+ virtual void draw(CScreenManager *screenManager);
};
} // End of namespace Titanic