aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/sherlock/events.cpp33
-rw-r--r--engines/sherlock/tattoo/widget_base.cpp100
-rw-r--r--engines/sherlock/tattoo/widget_base.h14
-rw-r--r--engines/sherlock/tattoo/widget_files.cpp26
-rw-r--r--engines/sherlock/tattoo/widget_files.h6
-rw-r--r--engines/sherlock/tattoo/widget_talk.cpp75
6 files changed, 151 insertions, 103 deletions
diff --git a/engines/sherlock/events.cpp b/engines/sherlock/events.cpp
index 456f055e1a..46e4e09191 100644
--- a/engines/sherlock/events.cpp
+++ b/engines/sherlock/events.cpp
@@ -251,7 +251,38 @@ bool Events::checkForNextFrameCounter() {
}
Common::KeyState Events::getKey() {
- return _pendingKeys.pop();
+ Common::KeyState keyState = _pendingKeys.pop();
+
+ switch (keyState.keycode) {
+ case Common::KEYCODE_KP1:
+ keyState.keycode = Common::KEYCODE_END;
+ break;
+ case Common::KEYCODE_KP2:
+ keyState.keycode = Common::KEYCODE_DOWN;
+ break;
+ case Common::KEYCODE_KP3:
+ keyState.keycode = Common::KEYCODE_PAGEDOWN;
+ break;
+ case Common::KEYCODE_KP4:
+ keyState.keycode = Common::KEYCODE_LEFT;
+ break;
+ case Common::KEYCODE_KP6:
+ keyState.keycode = Common::KEYCODE_RIGHT;
+ break;
+ case Common::KEYCODE_KP7:
+ keyState.keycode = Common::KEYCODE_HOME;
+ break;
+ case Common::KEYCODE_KP8:
+ keyState.keycode = Common::KEYCODE_UP;
+ break;
+ case Common::KEYCODE_KP9:
+ keyState.keycode = Common::KEYCODE_PAGEUP;
+ break;
+ default:
+ break;
+ }
+
+ return keyState;
}
void Events::clearEvents() {
diff --git a/engines/sherlock/tattoo/widget_base.cpp b/engines/sherlock/tattoo/widget_base.cpp
index 60d057edfc..e0b903916b 100644
--- a/engines/sherlock/tattoo/widget_base.cpp
+++ b/engines/sherlock/tattoo/widget_base.cpp
@@ -32,6 +32,7 @@ namespace Tattoo {
WidgetBase::WidgetBase(SherlockEngine *vm) : _vm(vm) {
_scroll = false;
+ _dialogTimer = 0;
}
void WidgetBase::summonWindow() {
@@ -222,16 +223,17 @@ void WidgetBase::drawDialogRect(const Common::Rect &r, bool raised) {
void WidgetBase::checkTabbingKeys(int numOptions) {
}
-void WidgetBase::drawScrollBar(int index, int pageSize, int count) {
+Common::Rect WidgetBase::getScrollBarBounds() const {
Common::Rect r(BUTTON_SIZE, _bounds.height() - 6);
r.moveTo(_bounds.width() - BUTTON_SIZE - 3, 3);
- drawScrollBar(index, pageSize, count, r);
+ return r;
}
-void WidgetBase::drawScrollBar(int index, int pageSize, int count, const Common::Rect &r) {
+void WidgetBase::drawScrollBar(int index, int pageSize, int count) {
TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui;
// Fill the area with transparency
+ Common::Rect r = getScrollBarBounds();
_surface.fillRect(r, TRANSPARENCY);
bool raised = ui._scrollHighlight != 1;
@@ -263,25 +265,21 @@ void WidgetBase::drawScrollBar(int index, int pageSize, int count, const Common:
r.right / 2, r.bottom - 1 - BUTTON_SIZE + 3 + BUTTON_SIZE / 2), color);
// Draw the scroll position bar
- int barHeight = (_bounds.height() - BUTTON_SIZE * 2) * pageSize / count;
- barHeight = CLIP(barHeight, BUTTON_SIZE, _bounds.height() - BUTTON_SIZE * 2);
- int barY = (r.height() - BUTTON_SIZE * 2 - barHeight) * index / pageSize + r.top + BUTTON_SIZE;
+ int barHeight = (r.height() - BUTTON_SIZE * 2) * pageSize / count;
+ barHeight = CLIP(barHeight, BUTTON_SIZE, r.height() - BUTTON_SIZE * 2);
+ int barY = r.top + BUTTON_SIZE + (r.height() - BUTTON_SIZE * 2 - barHeight) * index / (count - pageSize);
_surface.fillRect(Common::Rect(r.left + 2, barY + 2, r.right - 2, barY + barHeight - 3), INFO_MIDDLE);
ui.drawDialogRect(_surface, Common::Rect(r.left, barY, r.right, barY + barHeight), true);
}
void WidgetBase::handleScrollbarEvents(int index, int pageSize, int count) {
- handleScrollbarEvents(index, pageSize, count, Common::Rect(_bounds.right - BUTTON_SIZE - 3, _bounds.top + 3, _bounds.right - 3, _bounds.bottom - 3));
-}
-
-void WidgetBase::handleScrollbarEvents(int index, int pageSize, int count, const Common::Rect &r) {
Events &events = *_vm->_events;
TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui;
Common::Point mousePos = events.mousePos();
// If they have selected the sollbar, return with the Scroll Bar Still selected
- if (ui._scrollHighlight == 3)
+ if ((events._pressed || events._released) && ui._scrollHighlight == SH_THUMBNAIL)
return;
ui._scrollHighlight = SH_NONE;
@@ -289,10 +287,13 @@ void WidgetBase::handleScrollbarEvents(int index, int pageSize, int count, const
if ((!events._pressed && !events._rightReleased) || !_scroll)
return;
+ Common::Rect r = getScrollBarBounds();
+ r.translate(_bounds.left, _bounds.top);
+
// Calculate the Scroll Position bar
- int barHeight = (_bounds.height() - BUTTON_SIZE * 2) * pageSize / count;
- barHeight = CLIP(barHeight, BUTTON_SIZE, _bounds.height() - BUTTON_SIZE * 2);
- int barY = (r.height() - BUTTON_SIZE * 2 - barHeight) * index / pageSize + r.top + BUTTON_SIZE;
+ int barHeight = (r.height() - BUTTON_SIZE * 2) * pageSize / count;
+ barHeight = CLIP(barHeight, BUTTON_SIZE, r.height() - BUTTON_SIZE * 2);
+ int barY = r.top + BUTTON_SIZE + (r.height() - BUTTON_SIZE * 2 - barHeight) * index / (count - pageSize);
if (Common::Rect(r.left, r.top, r.right, r.top + BUTTON_SIZE).contains(mousePos))
// Mouse on scroll up button
@@ -311,6 +312,77 @@ void WidgetBase::handleScrollbarEvents(int index, int pageSize, int count, const
ui._scrollHighlight = SH_SCROLL_DOWN;
}
+void WidgetBase::handleScrolling(int &scrollIndex, int pageSize, int max) {
+ Events &events = *_vm->_events;
+ TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui;
+ Common::KeyCode keycode = ui._keyState.keycode;
+ Common::Point mousePos = events.mousePos();
+
+ Common::Rect r = getScrollBarBounds();
+ r.translate(_bounds.left, _bounds.top);
+
+ if (ui._scrollHighlight != SH_NONE || keycode == Common::KEYCODE_HOME || keycode == Common::KEYCODE_END
+ || keycode == Common::KEYCODE_PAGEUP || keycode == Common::KEYCODE_PAGEDOWN
+ || keycode == Common::KEYCODE_UP || keycode == Common::KEYCODE_DOWN) {
+ // Check for the scrollbar
+ if (ui._scrollHighlight == SH_THUMBNAIL) {
+ int yp = mousePos.y;
+ yp = CLIP(yp, r.top + BUTTON_SIZE + 3, r.bottom - BUTTON_SIZE - 3);
+
+ // Calculate the line number that corresponds to the position that the mouse is on the scrollbar
+ int lineNum = (yp - _bounds.top - BUTTON_SIZE - 3) * 100 / (_bounds.height() - BUTTON_SIZE * 2 - 6)
+ * max / 100 - 3;
+
+ // If the new position would place part of the text outsidethe text window, adjust it so it doesn't
+ if (lineNum < 0)
+ lineNum = 0;
+ else if (lineNum + pageSize > max) {
+ lineNum = max - pageSize;
+
+ // Make sure it's not below zero now
+ if (lineNum < 0)
+ lineNum = 0;
+ }
+
+ scrollIndex = lineNum;
+ }
+
+ // Get the current frame so we can check the scroll timer against it
+ uint32 frameNum = events.getFrameCounter();
+
+ if (frameNum > _dialogTimer) {
+ // Set the timeout for the next scroll if the mouse button remains held down
+ _dialogTimer = (_dialogTimer == 0) ? frameNum + pageSize : frameNum + 1;
+
+ // Check for Scroll Up
+ if ((ui._scrollHighlight == SH_SCROLL_UP || keycode == Common::KEYCODE_UP) && scrollIndex)
+ --scrollIndex;
+
+ // Check for Page Up
+ else if ((ui._scrollHighlight == SH_PAGE_UP || keycode == Common::KEYCODE_PAGEUP) && scrollIndex)
+ scrollIndex -= pageSize;
+
+ // Check for Page Down
+ else if ((ui._scrollHighlight == SH_PAGE_DOWN || keycode == Common::KEYCODE_PAGEDOWN)
+ && (scrollIndex + pageSize < max)) {
+ scrollIndex += pageSize;
+ if (scrollIndex + pageSize >max)
+ scrollIndex = max - pageSize;
+ }
+
+ // Check for Scroll Down
+ else if ((ui._scrollHighlight == SH_SCROLL_DOWN || keycode == Common::KEYCODE_DOWN) && (scrollIndex + pageSize < max))
+ ++scrollIndex;
+ }
+
+ if (keycode == Common::KEYCODE_END)
+ scrollIndex = max - pageSize;
+
+ if (scrollIndex < 0 || keycode == Common::KEYCODE_HOME)
+ scrollIndex = 0;
+ }
+}
+
} // End of namespace Tattoo
} // End of namespace Sherlock
diff --git a/engines/sherlock/tattoo/widget_base.h b/engines/sherlock/tattoo/widget_base.h
index 87f513e7b8..dcafc8fb21 100644
--- a/engines/sherlock/tattoo/widget_base.h
+++ b/engines/sherlock/tattoo/widget_base.h
@@ -36,6 +36,8 @@ class ImageFile;
namespace Tattoo {
class WidgetBase {
+private:
+ uint32 _dialogTimer;
protected:
SherlockEngine *_vm;
Common::Rect _bounds;
@@ -70,14 +72,14 @@ protected:
void drawDialogRect(const Common::Rect &r, bool raised = true);
/**
- * Draw the scrollbar for the dialog
+ * Return the area of a widget that the scrollbar will be drawn in
*/
- void drawScrollBar(int index, int pageSize, int count);
+ virtual Common::Rect getScrollBarBounds() const;
/**
- * Draw a scrollbar for the dialog in a specified area
+ * Draw the scrollbar for the dialog
*/
- void drawScrollBar(int index, int pageSize, int count, const Common::Rect &r);
+ void drawScrollBar(int index, int pageSize, int count);
/**
* Handles any events when the mouse is on the scrollbar
@@ -85,9 +87,9 @@ protected:
void handleScrollbarEvents(int index, int pageSize, int count);
/**
- * Handles any events when the mouse is on the scrollbar
+ * Handle adjusting a passed scrolling index as necessary
*/
- void handleScrollbarEvents(int index, int pageSize, int count, const Common::Rect &r);
+ void handleScrolling(int &scrollIndex, int pageSize, int max);
/**
* Close the dialog
diff --git a/engines/sherlock/tattoo/widget_files.cpp b/engines/sherlock/tattoo/widget_files.cpp
index 21dd10851f..4a0c0495e0 100644
--- a/engines/sherlock/tattoo/widget_files.cpp
+++ b/engines/sherlock/tattoo/widget_files.cpp
@@ -38,7 +38,6 @@ WidgetFiles::WidgetFiles(SherlockEngine *vm, const Common::String &target) :
SaveManager(vm, target), WidgetBase(vm), _vm(vm) {
_fileMode = SAVEMODE_NONE;
_selector = _oldSelector = -1;
- savegameIndex = 0;
}
void WidgetFiles::show(SaveMode mode) {
@@ -162,11 +161,8 @@ void WidgetFiles::render(FilesRenderMode mode) {
}
// Draw the Scrollbar if neccessary
- if (mode != RENDER_NAMES) {
- Common::Rect scrollRect(BUTTON_SIZE, _bounds.height() - _surface.fontHeight() - 16);
- scrollRect.moveTo(_bounds.width() - BUTTON_SIZE - 3, _surface.fontHeight() + 13);
- drawScrollBar(_savegameIndex, FILES_LINES_COUNT, _savegames.size(), scrollRect);
- }
+ if (mode != RENDER_NAMES)
+ drawScrollBar(_savegameIndex, FILES_LINES_COUNT, _savegames.size());
}
void WidgetFiles::handleEvents() {
@@ -175,17 +171,25 @@ void WidgetFiles::handleEvents() {
// Handle scrollbar events
ScrollHighlight oldHighlight = ui._scrollHighlight;
- Common::Rect scrollRect(BUTTON_SIZE, _bounds.height() - _surface.fontHeight() - 16);
- scrollRect.moveTo(_bounds.right - BUTTON_SIZE - 3, _bounds.top + _surface.fontHeight() + 13);
- handleScrollbarEvents(_savegameIndex, FILES_LINES_COUNT, _savegames.size(), scrollRect);
+ handleScrollbarEvents(_savegameIndex, FILES_LINES_COUNT, _savegames.size());
- // If the highlight has changed, redraw the scrollbar
- if (ui._scrollHighlight != oldHighlight)
+ int oldScrollIndex = _savegameIndex;
+ handleScrolling(_savegameIndex, FILES_LINES_COUNT, _savegames.size());
+
+ // Only redraw the window if the the scrollbar position has changed
+ if (ui._scrollHighlight != oldHighlight || oldScrollIndex != _savegameIndex)
render(RENDER_NAMES_AND_SCROLLBAR);
// TODO
}
+Common::Rect WidgetFiles::getScrollBarBounds() const {
+ Common::Rect scrollRect(BUTTON_SIZE, _bounds.height() - _surface.fontHeight() - 16);
+ scrollRect.moveTo(_bounds.width() - BUTTON_SIZE - 3, _surface.fontHeight() + 13);
+
+ return scrollRect;
+}
+
} // End of namespace Tattoo
} // End of namespace Sherlock
diff --git a/engines/sherlock/tattoo/widget_files.h b/engines/sherlock/tattoo/widget_files.h
index bf4eb85d2b..e861206d4b 100644
--- a/engines/sherlock/tattoo/widget_files.h
+++ b/engines/sherlock/tattoo/widget_files.h
@@ -40,7 +40,6 @@ private:
SherlockEngine *_vm;
SaveMode _fileMode;
int _selector, _oldSelector;
- int savegameIndex;
/**
* Render the dialog
@@ -56,6 +55,11 @@ private:
* Show the ScummVM Load Game dialog
*/
void showScummVMRestoreDialog();
+
+ /**
+ * Return the area of a widget that the scrollbar will be drawn in
+ */
+ virtual Common::Rect getScrollBarBounds() const;
public:
WidgetFiles(SherlockEngine *vm, const Common::String &target);
virtual ~WidgetFiles() {}
diff --git a/engines/sherlock/tattoo/widget_talk.cpp b/engines/sherlock/tattoo/widget_talk.cpp
index 5190773dd1..bc2f8339d2 100644
--- a/engines/sherlock/tattoo/widget_talk.cpp
+++ b/engines/sherlock/tattoo/widget_talk.cpp
@@ -123,77 +123,12 @@ void WidgetTalk::handleEvents() {
ScrollHighlight oldHighlight = ui._scrollHighlight;
handleScrollbarEvents(_talkScrollIndex, NUM_VISIBLE_TALK_LINES, _statementLines.size());
- // If the highlight has changed, redraw the scrollbar
- if (ui._scrollHighlight != oldHighlight)
- render(HL_SCROLLBAR_ONLY);
-
- if (ui._scrollHighlight != SH_NONE || keycode == Common::KEYCODE_HOME || keycode == Common::KEYCODE_END
- || keycode == Common::KEYCODE_PAGEUP || keycode == Common::KEYCODE_PAGEDOWN) {
- int scrollIndex = _talkScrollIndex;
-
- // Check for the scrollbar
- if (ui._scrollHighlight == SH_THUMBNAIL) {
- int yp = mousePos.y;
- yp = CLIP(yp, _bounds.top + BUTTON_SIZE + 3, _bounds.bottom - BUTTON_SIZE - 3);
-
- // Calculate the line number that corresponds to the position that the mouse is on the scrollbar
- int lineNum = (yp - _bounds.top - BUTTON_SIZE - 3) * 100 / (_bounds.height() - BUTTON_SIZE * 2 - 6)
- * _statementLines.size() / 100 - 3;
-
- // If the new position would place part of the text outsidethe text window, adjust it so it doesn't
- if (lineNum < 0)
- lineNum = 0;
- else if (lineNum + NUM_VISIBLE_TALK_LINES > (int)_statementLines.size()) {
- lineNum = (int)_statementLines.size() - NUM_VISIBLE_TALK_LINES;
-
- // Make sure it's not below zero now
- if (lineNum < 0)
- lineNum = 0;
- }
-
- _talkScrollIndex = lineNum;
- }
-
- // Get the current frame so we can check the scroll timer against it
- uint32 frameNum = events.getFrameCounter();
-
- if (frameNum > _dialogTimer) {
- // Set the timeout for the next scroll if the mouse button remains held down
- _dialogTimer = (_dialogTimer == 0) ? frameNum + NUM_VISIBLE_TALK_LINES : frameNum + 1;
+ int oldScrollIndex = _talkScrollIndex;
+ handleScrolling(_talkScrollIndex, NUM_VISIBLE_TALK_LINES, _statementLines.size());
- // Check for Scroll Up
- if (ui._scrollHighlight == SH_SCROLL_UP && _talkScrollIndex)
- --_talkScrollIndex;
-
- // Check for Page Up
- if ((ui._scrollHighlight == SH_PAGE_UP || keycode == Common::KEYCODE_PAGEUP) && _talkScrollIndex)
- _talkScrollIndex -= NUM_VISIBLE_TALK_LINES;
-
- // Check for Page Down
- if ((ui._scrollHighlight == SH_PAGE_DOWN || keycode == Common::KEYCODE_PAGEDOWN)
- && (_talkScrollIndex + NUM_VISIBLE_TALK_LINES < (int)_statementLines.size())) {
- _talkScrollIndex += 6;
- if (_talkScrollIndex + NUM_VISIBLE_TALK_LINES >(int)_statementLines.size())
- _talkScrollIndex = _statementLines.size() - NUM_VISIBLE_TALK_LINES;
- }
-
- // Check for Scroll Down
- if (ui._scrollHighlight == SH_SCROLL_DOWN && (_talkScrollIndex + NUM_VISIBLE_TALK_LINES < (int)_statementLines.size()))
- _talkScrollIndex++;
- }
-
- if (keycode == Common::KEYCODE_END)
- _talkScrollIndex = _statementLines.size() - NUM_VISIBLE_TALK_LINES;
-
- if (_talkScrollIndex < 0 || keycode == Common::KEYCODE_HOME)
- _talkScrollIndex = 0;
-
- // Only redraw the window if the the scrollbar position has changed
- if (scrollIndex != _talkScrollIndex) {
- _surface.fillRect(Common::Rect(4, 5, _surface.w() - BUTTON_SIZE - 8, _surface.h() - 4), TRANSPARENCY);
- render(HL_NO_HIGHLIGHTING);
- }
- }
+ // Only redraw the window if the the scrollbar position has changed
+ if (ui._scrollHighlight != oldHighlight || oldScrollIndex != _talkScrollIndex)
+ render(HL_SCROLLBAR_ONLY);
// Flag if they started pressing outside of the window
if (events._firstPress && !_bounds.contains(mousePos))