From 6f5f59af17290930ea75261c604471057e3b45e3 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 24 Jun 2016 22:39:01 -0400 Subject: TITANIC: Added various PET methods --- engines/titanic/pet_control/pet_glyphs.cpp | 58 ++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 6 deletions(-) (limited to 'engines/titanic/pet_control/pet_glyphs.cpp') 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 -- cgit v1.2.3