aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2002-10-01 23:11:19 +0000
committerMax Horn2002-10-01 23:11:19 +0000
commit3d7552890a52067ed493c63522fb11bb13ed72bd (patch)
treeab6bb989f3a36b00cc8f6c15337aba640c1a1cd1
parent1e626a712828e630d0a8583ab1a9a0b838d2d6cf (diff)
downloadscummvm-rg350-3d7552890a52067ed493c63522fb11bb13ed72bd.tar.gz
scummvm-rg350-3d7552890a52067ed493c63522fb11bb13ed72bd.tar.bz2
scummvm-rg350-3d7552890a52067ed493c63522fb11bb13ed72bd.zip
fixed ListWidget drawin/behaviour if there are less items than fit on one page; enhanced launcher dialog to disable start button if nothing is selected
svn-id: r5068
-rw-r--r--gui/ListWidget.cpp23
-rw-r--r--gui/ListWidget.h5
-rw-r--r--gui/dialog.cpp4
-rw-r--r--gui/dialog.h2
-rw-r--r--gui/launcher.cpp18
-rw-r--r--gui/launcher.h1
-rw-r--r--gui/widget.cpp19
-rw-r--r--gui/widget.h4
8 files changed, 46 insertions, 30 deletions
diff --git a/gui/ListWidget.cpp b/gui/ListWidget.cpp
index 25c11b2065..fb01146b35 100644
--- a/gui/ListWidget.cpp
+++ b/gui/ListWidget.cpp
@@ -58,15 +58,19 @@ void ListWidget::scrollBarRecalc()
void ListWidget::handleMouseDown(int x, int y, int button, int clickCount)
{
- int oldSelectedItem = _selectedItem;
-
- if (_flags & WIDGET_ENABLED) {
+ if (isEnabled()) {
+ int oldSelectedItem = _selectedItem;
_selectedItem = (y - 1) / kLineHeight + _currentPos;
-
- if (_editMode && oldSelectedItem != _selectedItem) {
- // undo any changes made
- _list[oldSelectedItem] = _backupString;
- _editMode = false;
+ if (_selectedItem > _list.size() - 1)
+ _selectedItem = -1;
+
+ if (oldSelectedItem != _selectedItem) {
+ if (_editMode) {
+ // undo any changes made
+ _list[oldSelectedItem] = _backupString;
+ _editMode = false;
+ }
+ sendCommand(kListSelectionChangedCmd, _selectedItem);
}
draw();
}
@@ -96,7 +100,7 @@ bool ListWidget::handleKeyDown(char key, int modifiers)
// enter, confirm edit and exit editmode
_editMode = false;
dirty = true;
- sendCommand(kListItemChangedCmd, _selectedItem);
+ sendCommand(kListItemActivatedCmd, _selectedItem);
} else if (key == 27) {
// ESC, abort edit and exit editmode
_editMode = false;
@@ -172,6 +176,7 @@ bool ListWidget::handleKeyDown(char key, int modifiers)
draw();
if (_selectedItem != oldSelectedItem) {
+ sendCommand(kListSelectionChangedCmd, _selectedItem);
// also draw scrollbar
_scrollBar->draw();
}
diff --git a/gui/ListWidget.h b/gui/ListWidget.h
index abdd99b66e..7f05f72a2b 100644
--- a/gui/ListWidget.h
+++ b/gui/ListWidget.h
@@ -34,8 +34,9 @@ enum {
// Some special commands
enum {
- kListItemDoubleClickedCmd = 'LIdb', // 'data' will be item index
- kListItemChangedCmd = 'LIch', // 'data' will be item index
+ kListItemDoubleClickedCmd = 'LIdb', // double click on item - 'data' will be item index
+ kListItemActivatedCmd = 'LIac', // item activated by return/enter - 'data' will be item index
+ kListSelectionChangedCmd = 'Lsch', // selection changed - 'data' will be item index
};
/* ListWidget */
diff --git a/gui/dialog.cpp b/gui/dialog.cpp
index bfddcd81cb..95df03f1db 100644
--- a/gui/dialog.cpp
+++ b/gui/dialog.cpp
@@ -243,8 +243,8 @@ Widget *Dialog::findWidget(int x, int y)
return w;
}
-void Dialog::addButton(int x, int y, int w, int h, const ScummVM::String &label, uint32 cmd, char hotkey)
+Widget *Dialog::addButton(int x, int y, int w, int h, const ScummVM::String &label, uint32 cmd, char hotkey)
{
- new ButtonWidget(this, x, y, w, h, label, cmd, hotkey);
+ return new ButtonWidget(this, x, y, w, h, label, cmd, hotkey);
}
diff --git a/gui/dialog.h b/gui/dialog.h
index c6793129ee..0611b22ead 100644
--- a/gui/dialog.h
+++ b/gui/dialog.h
@@ -70,7 +70,7 @@ public:
protected:
Widget* findWidget(int x, int y); // Find the widget at pos x,y if any
- void addButton(int x, int y, int w, int h, const ScummVM::String &label, uint32 cmd, char hotkey);
+ Widget* addButton(int x, int y, int w, int h, const ScummVM::String &label, uint32 cmd, char hotkey);
};
#endif
diff --git a/gui/launcher.cpp b/gui/launcher.cpp
index e953982035..f602b1bb77 100644
--- a/gui/launcher.cpp
+++ b/gui/launcher.cpp
@@ -50,7 +50,8 @@ LauncherDialog::LauncherDialog(NewGui *gui, GameDetector &detector)
// Add three buttons at the bottom
addButton(1*(_w - 54)/6, _h - 24, 54, 16, "Quit", kQuitCmd, 'Q');
addButton(3*(_w - 54)/6, _h - 24, 54, 16, "Options", kOptionsCmd, 'O');
- addButton(5*(_w - 54)/6, _h - 24, 54, 16, "Start", kStartCmd, 'S');
+ _startButton = addButton(5*(_w - 54)/6, _h - 24, 54, 16, "Start", kStartCmd, 'S');
+ _startButton->setEnabled(false);
// Add list with game titles
_list = new ListWidget(this, 10, 10, 300, 112);
@@ -83,14 +84,13 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
case kListItemDoubleClickedCmd:
// Print out what was selected
item = _list->getSelected();
- if (item >= 0) {
- printf("Selected game: %s\n", _filenames[item].c_str());
- _detector.setGame(_filenames[item].c_str());
- close();
- } else {
- // TODO - beep or so ?
- // Ideally, the start button should be disabled if no game is selected
- }
+ assert(item >= 0);
+ _detector.setGame(_filenames[item].c_str());
+ close();
+ break;
+ case kListSelectionChangedCmd:
+ _startButton->setEnabled(_list->getSelected() >= 0);
+ _startButton->draw();
break;
case kQuitCmd:
g_system->quit();
diff --git a/gui/launcher.h b/gui/launcher.h
index 1bfcfc8e22..694121c24d 100644
--- a/gui/launcher.h
+++ b/gui/launcher.h
@@ -38,6 +38,7 @@ public:
protected:
ListWidget *_list;
+ Widget *_startButton;
StringList _filenames;
GameDetector &_detector;
};
diff --git a/gui/widget.cpp b/gui/widget.cpp
index 3788e4d237..39c2a6b69b 100644
--- a/gui/widget.cpp
+++ b/gui/widget.cpp
@@ -23,11 +23,16 @@
#include "dialog.h"
#include "newgui.h"
+
+
#ifdef _MSC_VER
+
# pragma warning( disable : 4068 ) // unknown pragma
+
#endif
+
Widget::Widget (Dialog *boss, int x, int y, int w, int h)
: _type(0), _boss(boss), _x(x), _y(y), _w(w), _h(h),
_id(0), _flags(0), _hasFocus(false)
@@ -98,7 +103,9 @@ void StaticTextWidget::setValue(int value)
void StaticTextWidget::drawWidget(bool hilite)
{
NewGui *gui = _boss->getGui();
- gui->drawString(_label.c_str(), _x, _y, _w, hilite ? gui->_textcolorhi : gui->_textcolor, _align);
+ gui->drawString(_label.c_str(), _x, _y, _w,
+ !isEnabled() ? gui->_color :
+ hilite ? gui->_textcolorhi : gui->_textcolor, _align);
}
@@ -114,7 +121,7 @@ ButtonWidget::ButtonWidget(Dialog *boss, int x, int y, int w, int h, const Strin
void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount)
{
- if (_flags & WIDGET_ENABLED && x >= 0 && x < _w && y >= 0 && y < _h)
+ if (isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h)
sendCommand(_cmd, 0);
}
@@ -142,7 +149,7 @@ CheckboxWidget::CheckboxWidget(Dialog *boss, int x, int y, int w, int h, const S
void CheckboxWidget::handleMouseDown(int x, int y, int button, int clickCount)
{
- if (_flags & WIDGET_ENABLED) {
+ if (isEnabled()) {
_state = !_state;
draw();
sendCommand(_cmd, 0);
@@ -177,7 +184,7 @@ SliderWidget::SliderWidget(Dialog *boss, int x, int y, int w, int h, const Strin
}
void SliderWidget::handleMouseMoved(int x, int y, int button) {
- if ((_flags & WIDGET_ENABLED) && _isDragging) {
+ if (isEnabled() && _isDragging) {
int newValue = posToValue(x);
if (newValue < _valueMin)
@@ -195,7 +202,7 @@ void SliderWidget::handleMouseMoved(int x, int y, int button) {
void SliderWidget::handleMouseDown(int x, int y, int button, int clickCount) {
- if (_flags & WIDGET_ENABLED) {
+ if (isEnabled()) {
int barx;
barx = valueToPos(_value);
@@ -208,7 +215,7 @@ void SliderWidget::handleMouseDown(int x, int y, int button, int clickCount) {
void SliderWidget::handleMouseUp(int x, int y, int button, int clickCount) {
- if ((_flags & WIDGET_ENABLED) && _isDragging) {
+ if (isEnabled() && _isDragging) {
sendCommand(_cmd, _value);
}
diff --git a/gui/widget.h b/gui/widget.h
index 3a544da61d..066252b0ec 100644
--- a/gui/widget.h
+++ b/gui/widget.h
@@ -108,7 +108,9 @@ public:
void clearFlags(int flags) { _flags &= ~flags; }
int getFlags() const { return _flags; }
- bool isVisible() const { return !(_flags & WIDGET_INVISIBLE); }
+ void setEnabled(bool e) { if (e) setFlags(WIDGET_ENABLED); else clearFlags(WIDGET_ENABLED); }
+ bool isEnabled() const { return _flags & WIDGET_ENABLED; }
+ bool isVisible() const { return !(_flags & WIDGET_INVISIBLE); }
protected:
virtual void drawWidget(bool hilite) {}