aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/pet_control/pet_slider.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2016-04-22 21:43:12 -0400
committerPaul Gilbert2016-07-10 16:11:44 -0400
commit4915f8900aff374b2a71545e788cb95d9da7138a (patch)
tree6d988f68d89c8c5556fc7ec74ee2dd9a2a0c00dc /engines/titanic/pet_control/pet_slider.cpp
parenta719b0585fed6bcbce48e924d65cca5d9ff80bf8 (diff)
downloadscummvm-rg350-4915f8900aff374b2a71545e788cb95d9da7138a.tar.gz
scummvm-rg350-4915f8900aff374b2a71545e788cb95d9da7138a.tar.bz2
scummvm-rg350-4915f8900aff374b2a71545e788cb95d9da7138a.zip
TITANIC: Implement more slider functions
Diffstat (limited to 'engines/titanic/pet_control/pet_slider.cpp')
-rw-r--r--engines/titanic/pet_control/pet_slider.cpp181
1 files changed, 159 insertions, 22 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