aboutsummaryrefslogtreecommitdiff
path: root/gui/PopUpWidget.cpp
diff options
context:
space:
mode:
authorMax Horn2002-12-14 17:59:22 +0000
committerMax Horn2002-12-14 17:59:22 +0000
commit3575a2db06f393f6105b87019564d7e2cd44b9e8 (patch)
tree03da25810d99d450324fa2f82916e3e93d9e8b2a /gui/PopUpWidget.cpp
parent32b4bfacb2767cdc5960f24fd3096eb10c0a42f5 (diff)
downloadscummvm-rg350-3575a2db06f393f6105b87019564d7e2cd44b9e8.tar.gz
scummvm-rg350-3575a2db06f393f6105b87019564d7e2cd44b9e8.tar.bz2
scummvm-rg350-3575a2db06f393f6105b87019564d7e2cd44b9e8.zip
fixed arrow/mouse wheel scrolling: now honors seperator items (i.e. you can't select the anymore); seperator items are now marked by an empty string
svn-id: r5961
Diffstat (limited to 'gui/PopUpWidget.cpp')
-rw-r--r--gui/PopUpWidget.cpp55
1 files changed, 42 insertions, 13 deletions
diff --git a/gui/PopUpWidget.cpp b/gui/PopUpWidget.cpp
index 464388f257..ea7a005b96 100644
--- a/gui/PopUpWidget.cpp
+++ b/gui/PopUpWidget.cpp
@@ -70,6 +70,9 @@ protected:
int findItem(int x, int y) const;
void setSelection(int item);
bool isMouseDown();
+
+ void moveUp();
+ void moveDown();
};
PopUpDialog::PopUpDialog(PopUpWidget *boss, int clickX, int clickY)
@@ -139,13 +142,10 @@ void PopUpDialog::handleMouseUp(int x, int y, int button, int clickCount)
void PopUpDialog::handleMouseWheel(int x, int y, int direction)
{
- if (direction < 0) {
- if (_selection > 0)
- setSelection(_selection-1);
- } else if (direction > 0) {
- if (_selection < _popUpBoss->_entries.size()-1)
- setSelection(_selection+1);
- }
+ if (direction < 0)
+ moveUp();
+ else if (direction > 0)
+ moveDown();
}
void PopUpDialog::handleMouseMoved(int x, int y, int button)
@@ -153,7 +153,7 @@ void PopUpDialog::handleMouseMoved(int x, int y, int button)
// Compute over which item the mouse is...
int item = findItem(x, y);
- if (item >= 0 && _popUpBoss->_entries[item].name[0] == '-')
+ if (item >= 0 && _popUpBoss->_entries[item].name.size() == 0)
item = -1;
if (item == -1 && !isMouseDown())
@@ -180,12 +180,10 @@ void PopUpDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers)
close();
break;
case 256+17: // up arrow
- if (_selection > 0)
- setSelection(_selection-1);
+ moveUp();
break;
case 256+18: // down arrow
- if (_selection < _popUpBoss->_entries.size()-1)
- setSelection(_selection+1);
+ moveDown();
break;
case 256+22: // home
setSelection(0);
@@ -229,6 +227,37 @@ bool PopUpDialog::isMouseDown()
return false;
}
+void PopUpDialog::moveUp()
+{
+ if (_selection < 0) {
+ setSelection(_popUpBoss->_entries.size() - 1);
+ } else if (_selection > 0) {
+ int item = _selection;
+ do {
+ item--;
+ } while (item >= 0 && _popUpBoss->_entries[item].name.size() == 0);
+ if (item >= 0)
+ setSelection(item);
+ }
+}
+
+void PopUpDialog::moveDown()
+{
+ int lastItem = _popUpBoss->_entries.size() - 1;
+
+ if (_selection < 0) {
+ setSelection(0);
+ } else if (_selection < lastItem) {
+ int item = _selection;
+ do {
+ item++;
+ } while (item <= lastItem && _popUpBoss->_entries[item].name.size() == 0);
+ if (item <= lastItem)
+ setSelection(item);
+ }
+}
+
+
void PopUpDialog::drawMenuEntry(int entry, bool hilite)
{
// Draw one entry of the popup menu, including selection
@@ -239,7 +268,7 @@ void PopUpDialog::drawMenuEntry(int entry, bool hilite)
ScummVM::String &name = _popUpBoss->_entries[entry].name;
_gui->fillRect(x, y, w, kLineHeight, hilite ? _gui->_textcolorhi : _gui->_bgcolor);
- if (name[0] == '-') {
+ if (name.size() == 0) {
// Draw a seperator
_gui->hline(x, y+kLineHeight/2, x+w-1, _gui->_color);
_gui->hline(x+1, y+1+kLineHeight/2, x+w-1, _gui->_shadowcolor);