aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/pet_control/pet_glyphs.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2016-06-24 22:39:01 -0400
committerPaul Gilbert2016-07-15 19:24:46 -0400
commit6f5f59af17290930ea75261c604471057e3b45e3 (patch)
treef7aa9d83f0b606e2d714a55ad77bb3b5bf488ebd /engines/titanic/pet_control/pet_glyphs.cpp
parentc2f6110d0218802b811c1172f114b5d8ed8bf37c (diff)
downloadscummvm-rg350-6f5f59af17290930ea75261c604471057e3b45e3.tar.gz
scummvm-rg350-6f5f59af17290930ea75261c604471057e3b45e3.tar.bz2
scummvm-rg350-6f5f59af17290930ea75261c604471057e3b45e3.zip
TITANIC: Added various PET methods
Diffstat (limited to 'engines/titanic/pet_control/pet_glyphs.cpp')
-rw-r--r--engines/titanic/pet_control/pet_glyphs.cpp58
1 files changed, 52 insertions, 6 deletions
diff --git a/engines/titanic/pet_control/pet_glyphs.cpp b/engines/titanic/pet_control/pet_glyphs.cpp
index 1aea34f708..2e9b590db1 100644
--- a/engines/titanic/pet_control/pet_glyphs.cpp
+++ b/engines/titanic/pet_control/pet_glyphs.cpp
@@ -71,6 +71,10 @@ void CPetGlyph::setName(const CString &name, CPetControl *petControl) {
_element.reset(name, petControl, MODE_UNSELECTED);
}
+bool CPetGlyph::isHighlighted() const {
+ return _owner->isGlyphHighlighted(this);
+}
+
/*------------------------------------------------------------------------*/
CPetGlyphs::CPetGlyphs() : _firstVisibleIndex(0), _numVisibleGlyphs(TOTAL_GLYPHS),
@@ -177,7 +181,7 @@ void CPetGlyphs::draw(CScreenManager *screenManager) {
}
}
-Point CPetGlyphs::getPosition(int index) {
+Point CPetGlyphs::getPosition(int index) const {
Point tempPoint(37 + index * 70, 375);
return tempPoint;
}
@@ -230,7 +234,7 @@ void CPetGlyphs::highlight(const CPetGlyph *glyph) {
highlight(indexOf(glyph));
}
-int CPetGlyphs::getHighlightedIndex(int index) {
+int CPetGlyphs::getHighlightedIndex(int index) const {
int idx = index - _firstVisibleIndex;
return (idx >= 0 && idx < _numVisibleGlyphs) ? idx : -1;
}
@@ -416,15 +420,27 @@ bool CPetGlyphs::KeyCharMsg(int key) {
bool CPetGlyphs::VirtualKeyCharMsg(int key) {
bool handled = false;
- warning("TODO: CPetGlyphs::virtualKeyCharMsg");
- if (!handled && _highlightIndex >= 0) {
+ switch (key) {
+ case Common::KEYCODE_LEFT:
+ decSelection();
+ return true;
+
+ case Common::KEYCODE_RIGHT:
+ incSelection();
+ return true;
+
+ default:
+ break;
+ }
+
+ if (_highlightIndex >= 0) {
CPetGlyph *glyph = getGlyph(_highlightIndex);
if (glyph && glyph->VirtualKeyCharMsg(key))
- handled = true;
+ return true;
}
- return handled;
+ return false;
}
bool CPetGlyphs::enterHighlighted() {
@@ -492,4 +508,34 @@ void CPetGlyphs::decSelection() {
}
}
+CGameObject *CPetGlyphs::getObjectAt(const Point &pt) {
+ for (int idx = 0; idx < _numVisibleGlyphs; ++idx) {
+ Rect glyphRect = getRect(idx);
+ if (glyphRect.contains(pt)) {
+ CPetGlyph *glyph = getGlyph(getItemIndex(idx));
+ if (glyph)
+ return glyph->getObjectAt();
+ }
+ }
+
+ return nullptr;
+}
+
+bool CPetGlyphs::isGlyphHighlighted(const CPetGlyph *glyph) const {
+ if (_highlightIndex == -1)
+ return false;
+
+ return indexOf(glyph) == _highlightIndex;
+}
+
+Point CPetGlyphs::getHighlightedGlyphPos() const {
+ if (_highlightIndex != -1) {
+ int idx = getHighlightedIndex(_highlightIndex);
+ if (idx >= 0)
+ return getPosition(idx);
+ }
+
+ return Point(0, 0);
+}
+
} // End of namespace Titanic