aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2016-04-17 15:02:01 -0400
committerPaul Gilbert2016-07-10 16:11:19 -0400
commit22248ccbf20535d9c14da2e376ae7ff3c9b4081b (patch)
tree8105b0d8e49b9e67129b09fabf66d6ad33dad660 /engines
parentd971edf02ea8074b71be852fdcee48e095ff49a9 (diff)
downloadscummvm-rg350-22248ccbf20535d9c14da2e376ae7ff3c9b4081b.tar.gz
scummvm-rg350-22248ccbf20535d9c14da2e376ae7ff3c9b4081b.tar.bz2
scummvm-rg350-22248ccbf20535d9c14da2e376ae7ff3c9b4081b.zip
TITANIC: Implement glyphs drawing
Diffstat (limited to 'engines')
-rw-r--r--engines/titanic/pet_control/pet_glyphs.cpp76
-rw-r--r--engines/titanic/pet_control/pet_glyphs.h38
2 files changed, 101 insertions, 13 deletions
diff --git a/engines/titanic/pet_control/pet_glyphs.cpp b/engines/titanic/pet_control/pet_glyphs.cpp
index 41ac4ae5e1..fc3fcc593a 100644
--- a/engines/titanic/pet_control/pet_glyphs.cpp
+++ b/engines/titanic/pet_control/pet_glyphs.cpp
@@ -29,10 +29,10 @@ void CPetGlyph::setOwner(CPetControl *petControl, CPetGlyphs *owner) {
_owner = owner;
}
-void CPetGlyph::translateDraw(CScreenManager *screenManager, int deltaX, int deltaY) {
- _element.translate(deltaX, deltaY);
+void CPetGlyph::drawAt(CScreenManager *screenManager, int x, int y) {
+ _element.translate(x, y);
_element.draw(screenManager);
- _element.translate(-deltaX, -deltaY);
+ _element.translate(-x, -y);
}
void CPetGlyph::proc14() {
@@ -49,10 +49,14 @@ bool CPetGlyph::translateContains(const Point &delta, const Point &pt) {
/*------------------------------------------------------------------------*/
+CPetGlyphs::CPetGlyphs() : _firstVisibleIndex(0), _numVisibleGlyphs(7),
+ _highlightIndex(-1), _field1C(-1), _field20(0), _field24(0) {
+}
+
void CPetGlyphs::clear() {
changeHighlight(-1);
destroyContents();
- _field10 = 0;
+ _firstVisibleIndex = 0;
}
void CPetGlyphs::proc8() {
@@ -72,7 +76,51 @@ void CPetGlyphs::proc11() {
}
void CPetGlyphs::draw(CScreenManager *screenManager) {
- warning("TODO: CPetGlyphs::draw");
+ if (_highlightIndex != -1) {
+ int index = getHighlightedIndex(_highlightIndex);
+ if (index != -1) {
+ Point tempPoint;
+ Point pt = getPosition(index);
+ pt -= Point(12, 13);
+ _selection.translate(pt.x, pt.y);
+ _selection.draw(screenManager);
+ _selection.translate(-pt.x, -pt.y);
+ }
+ }
+
+ // Iterate through displaying glyphs on the screen
+ int listSize = size();
+ for (int index = 0; index < _numVisibleGlyphs; ++index) {
+ int itemIndex = getItemIndex(index);
+
+ if (itemIndex >= 0 && itemIndex < listSize) {
+ Point pt = getPosition(itemIndex);
+ CPetGlyph *glyph = getGlyph(itemIndex);
+
+ if (glyph) {
+ // TODO: Comparison with highlighted index, and a redundant push?
+ glyph->drawAt(screenManager, pt.x, pt.y);
+ }
+ }
+ }
+
+ // Draw scrolling arrows if more than a screen's worth of items are showing
+ if (listSize > _numVisibleGlyphs || _field20 != 16) {
+ _scrollLeft.draw(screenManager);
+ _scrollRight.draw(screenManager);
+ }
+
+ // Handle secondary highlight
+ if (_highlightIndex != -1) {
+ CPetGlyph *glyph = getGlyph(_highlightIndex);
+ if (glyph)
+ glyph->drawHighlight();
+ }
+}
+
+Point CPetGlyphs::getPosition(int index) {
+ Point tempPoint(37 + index * 58, 375);
+ return tempPoint;
}
void CPetGlyphs::changeHighlight(int index) {
@@ -83,4 +131,22 @@ void CPetGlyphs::highlight(int index) {
warning("TODO: CPetGlyphs::highlight");
}
+int CPetGlyphs::getHighlightedIndex(int index) {
+ int idx = index - _firstVisibleIndex;
+ return (idx >= 0 && idx < _numVisibleGlyphs) ? idx : -1;
+}
+
+int CPetGlyphs::getItemIndex(int index) {
+ return _firstVisibleIndex + index;
+}
+
+CPetGlyph *CPetGlyphs::getGlyph(int index) {
+ for (iterator i = begin(); i != end(); ++i) {
+ if (index-- == 0)
+ return *i;
+ }
+
+ return nullptr;
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/pet_control/pet_glyphs.h b/engines/titanic/pet_control/pet_glyphs.h
index a34276661d..6160c454a1 100644
--- a/engines/titanic/pet_control/pet_glyphs.h
+++ b/engines/titanic/pet_control/pet_glyphs.h
@@ -62,9 +62,12 @@ public:
* Draw the glyph at a translated position without permanently
* changing the position
*/
- virtual void translateDraw(CScreenManager *screenManager, int deltaX, int deltaY);
+ virtual void drawAt(CScreenManager *screenManager, int x, int y);
- virtual void proc13() {}
+ /**
+ * Handles any secondary drawing of a glyph as highlighted
+ */
+ virtual void drawHighlight() {}
virtual void proc14();
@@ -106,10 +109,31 @@ public:
};
class CPetGlyphs : public List<CPetGlyph> {
+private:
+ /**
+ * Get a position for the glyph
+ */
+ Point getPosition(int index);
+
+ /**
+ * Returns the on-screen index for the highlight to be shown at
+ */
+ int getHighlightedIndex(int index);
+
+ /**
+ * Returns the index of a glyph given the visible on-screen glyph number
+ */
+ int getItemIndex(int index);
+
+ /**
+ * Return a specified glyph
+ */
+ CPetGlyph *getGlyph(int index);
protected:
- int _field10;
- int _field14;
- int _field18;
+ int _firstVisibleIndex;
+ int _totalGlyphs;
+ int _numVisibleGlyphs;
+ int _highlightIndex;
int _field1C;
int _field20;
int _field24;
@@ -122,9 +146,7 @@ protected:
*/
void changeHighlight(int index);
public:
- CPetGlyphs::CPetGlyphs() : _field10(0), _field14(7),
- _field18(-1), _field1C(-1), _field20(0), _field24(0) {
- }
+ CPetGlyphs();
/**
* Clears the glyph list