aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2003-11-03 01:00:26 +0000
committerMax Horn2003-11-03 01:00:26 +0000
commit9f3edb11c5369094c2c3af8ad72adfb2e396abdc (patch)
tree6a3c31aaf5315490f88edfe4d913564e7b9d45f4
parentcfd658cd299bb10474b164cc4b453dddfc2e0e2a (diff)
downloadscummvm-rg350-9f3edb11c5369094c2c3af8ad72adfb2e396abdc.tar.gz
scummvm-rg350-9f3edb11c5369094c2c3af8ad72adfb2e396abdc.tar.bz2
scummvm-rg350-9f3edb11c5369094c2c3af8ad72adfb2e396abdc.zip
added a builtin label to PopUpWidget
svn-id: r11076
-rw-r--r--gui/PopUpWidget.cpp35
-rw-r--r--gui/PopUpWidget.h21
-rw-r--r--gui/options.cpp8
-rw-r--r--gui/widget.cpp4
-rw-r--r--gui/widget.h5
5 files changed, 34 insertions, 39 deletions
diff --git a/gui/PopUpWidget.cpp b/gui/PopUpWidget.cpp
index bb1a4ac565..d289fe0f34 100644
--- a/gui/PopUpWidget.cpp
+++ b/gui/PopUpWidget.cpp
@@ -38,8 +38,6 @@ static uint32 up_down_arrows[8] = {
0x00001000,
};
-const Common::String PopUpWidget::emptyStr;
-
//
// PopUpDialog
//
@@ -56,12 +54,10 @@ public:
void drawDialog();
-// void handleMouseDown(int x, int y, int button, int clickCount);
void handleMouseUp(int x, int y, int button, int clickCount);
void handleMouseWheel(int x, int y, int direction); // Scroll through entries with scroll wheel
void handleMouseMoved(int x, int y, int button); // Redraw selections depending on mouse position
void handleKeyDown(uint16 ascii, int keycode, int modifiers); // Scroll through entries with arrow keys etc.
-// void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
protected:
void drawMenuEntry(int entry, bool hilite);
@@ -81,10 +77,10 @@ PopUpDialog::PopUpDialog(PopUpWidget *boss, int clickX, int clickY)
_selection = _popUpBoss->_selectedItem;
// Calculate real popup dimensions
- _x = _popUpBoss->getAbsX();
+ _x = _popUpBoss->getAbsX() + _popUpBoss->_labelWidth;
_y = _popUpBoss->getAbsY() - _popUpBoss->_selectedItem * kLineHeight;
_h = _popUpBoss->_entries.size() * kLineHeight + 2;
- _w = _popUpBoss->_w - 10;
+ _w = _popUpBoss->_w - 10 - _popUpBoss->_labelWidth;
// Perform clipping / switch to scrolling mode if we don't fit on the screen
// FIXME - hard coded screen height 200. We really need an API in OSystem to query the
@@ -271,10 +267,10 @@ void PopUpDialog::drawMenuEntry(int entry, bool hilite) {
// PopUpWidget
//
-PopUpWidget::PopUpWidget(GuiObject *boss, int x, int y, int w, int h)
- : Widget(boss, x, y - 1, w, h + 2), CommandSender(boss) {
+PopUpWidget::PopUpWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint labelWidth)
+ : Widget(boss, x, y - 1, w, h + 2), CommandSender(boss), _label(label), _labelWidth(labelWidth) {
_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS;
- _type = 'POPU';
+ _type = kPopUpWidget;
_selectedItem = -1;
}
@@ -316,20 +312,25 @@ void PopUpWidget::setSelected(int item) {
void PopUpWidget::drawWidget(bool hilite) {
NewGui *gui = &g_gui;
+ int x = _x + _labelWidth;
+ int w = _w - _labelWidth;
+
+ // Draw the label, if any
+ if (_labelWidth > 0)
+ gui->drawString(_label, _x, _y + 2, _labelWidth, isEnabled() ? gui->_textcolor : gui->_color, kTextAlignRight);
// Draw a thin frame around us.
- // TODO - should look different than the EditTextWidget fram
- gui->hLine(_x, _y, _x + _w - 1, gui->_color);
- gui->hLine(_x, _y +_h-1, _x + _w - 1, gui->_shadowcolor);
- gui->vLine(_x, _y, _y+_h-1, gui->_color);
- gui->vLine(_x + _w - 1, _y, _y +_h - 1, gui->_shadowcolor);
+ gui->hLine(x, _y, x + w - 1, gui->_color);
+ gui->hLine(x, _y +_h-1, x + w - 1, gui->_shadowcolor);
+ gui->vLine(x, _y, _y+_h-1, gui->_color);
+ gui->vLine(x + w - 1, _y, _y +_h - 1, gui->_shadowcolor);
// Draw an arrow pointing down at the right end to signal this is a dropdown/popup
- gui->drawBitmap(up_down_arrows, _x+_w - 10, _y+2, !isEnabled() ? gui->_color : hilite ? gui->_textcolorhi : gui->_textcolor);
+ gui->drawBitmap(up_down_arrows, x+w - 10, _y+2, !isEnabled() ? gui->_color : hilite ? gui->_textcolorhi : gui->_textcolor);
// Draw the selected entry, if any
if (_selectedItem >= 0) {
- int align = (gui->getStringWidth(_entries[_selectedItem].name) > _w-6) ? kTextAlignRight : kTextAlignLeft;
- gui->drawString(_entries[_selectedItem].name, _x+2, _y+3, _w-6, !isEnabled() ? gui->_color : gui->_textcolor, align);
+ int align = (gui->getStringWidth(_entries[_selectedItem].name) > w-6) ? kTextAlignRight : kTextAlignLeft;
+ gui->drawString(_entries[_selectedItem].name, x+2, _y+3, w-6, !isEnabled() ? gui->_color : gui->_textcolor, align);
}
}
diff --git a/gui/PopUpWidget.h b/gui/PopUpWidget.h
index f5d7ad6da9..44eff7d174 100644
--- a/gui/PopUpWidget.h
+++ b/gui/PopUpWidget.h
@@ -29,8 +29,8 @@ enum {
kPopUpItemSelectedCmd = 'POPs'
};
-/* PopUpWidget
- * A popup or dropdown widget which, when clicked, "pop up" a list of items and
+/**
+ * Popup or dropdown widget which, when clicked, "pop up" a list of items and
* lets the user pick on of them.
*
* Implementation wise, when the user selects an item, then a kPopUpItemSelectedCmd
@@ -46,30 +46,23 @@ class PopUpWidget : public Widget, public CommandSender {
};
typedef Common::List<Entry> EntryList;
protected:
- static const String emptyStr;
-
EntryList _entries;
int _selectedItem;
+ String _label;
+ uint _labelWidth;
+
public:
- PopUpWidget(GuiObject *boss, int x, int y, int w, int h);
+ PopUpWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint labelWidth);
void handleMouseDown(int x, int y, int button, int clickCount);
-/*
- void handleMouseUp(int x, int y, int button, int clickCount);
-// void handleMouseWheel(int x, int y, int direction); // Scroll through entries with scroll wheel
- void handleMouseMoved(int x, int y, int button); // Redraw selections depending on mouse position
-// bool handleKeyDown(uint16 ascii, int keycode, int modifiers); // Scroll through entries with arrow keys etc.
-// void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
-*/
void appendEntry(const String &entry, uint32 tag = (uint32)-1);
-// void setEntries(const EntryList &entries);
void clearEntries();
void setSelected(int item);
int getSelected() const { return _selectedItem; }
- const String& getSelectedString() const { return (_selectedItem >= 0) ? _entries[_selectedItem].name : emptyStr; }
+ const String& getSelectedString() const { return (_selectedItem >= 0) ? _entries[_selectedItem].name : String::emptyString; }
protected:
void drawWidget(bool hilite);
diff --git a/gui/options.cpp b/gui/options.cpp
index d2f282a087..9fa82af91b 100644
--- a/gui/options.cpp
+++ b/gui/options.cpp
@@ -77,9 +77,9 @@ GlobalOptionsDialog::GlobalOptionsDialog(GameDetector &detector)
// The GFX mode popup & a label
// TODO - add an API to query the list of available GFX modes, and to get/set the mode
- new StaticTextWidget(tab, 5, vBorder+2, 100, kLineHeight, "Graphics mode: ", kTextAlignRight);
+ //new StaticTextWidget(tab, 5, vBorder+2, 100, kLineHeight, "Graphics mode: ", kTextAlignRight);
PopUpWidget *gfxPopUp;
- gfxPopUp = new PopUpWidget(tab, 105, vBorder, 180, kLineHeight);
+ gfxPopUp = new PopUpWidget(tab, 6, vBorder, 280, kLineHeight, "Graphics mode: ", 100);
gfxPopUp->appendEntry("<default>");
gfxPopUp->appendEntry("");
gfxPopUp->appendEntry("Normal (no scaling)");
@@ -106,8 +106,8 @@ GlobalOptionsDialog::GlobalOptionsDialog(GameDetector &detector)
tab->addTab("Audio");
// The MIDI mode popup & a label
- new StaticTextWidget(tab, 5, vBorder+2, 100, kLineHeight, "Music driver: ", kTextAlignRight);
- _midiPopUp = new PopUpWidget(tab, 105, vBorder, 180, kLineHeight);
+ //new StaticTextWidget(tab, 5, vBorder+2, 100, kLineHeight, "Music driver: ", kTextAlignRight);
+ _midiPopUp = new PopUpWidget(tab, 6, vBorder, 280, kLineHeight, "Music driver: ", 100);
// Populate it
const MidiDriverDescription *md = getAvailableMidiDrivers();
diff --git a/gui/widget.cpp b/gui/widget.cpp
index 451f74af5d..35e8535479 100644
--- a/gui/widget.cpp
+++ b/gui/widget.cpp
@@ -200,7 +200,7 @@ void CheckboxWidget::drawWidget(bool hilite) {
#pragma mark -
-SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, int labelWidth, uint32 cmd, uint8 hotkey)
+SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint labelWidth, uint32 cmd, uint8 hotkey)
: ButtonWidget(boss, x, y, w, h, label, cmd, hotkey),
_value(0), _oldValue(0),_valueMin(0), _valueMax(100), _isDragging(false),
_labelWidth(labelWidth) {
@@ -211,7 +211,7 @@ SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h, const St
void SliderWidget::handleMouseMoved(int x, int y, int button) {
// TODO: when the mouse is dragged outside the widget, the slider should
// snap back to the old value.
- if (isEnabled() && _isDragging && x >= _labelWidth) {
+ if (isEnabled() && _isDragging && x >= (int)_labelWidth) {
int newValue = posToValue(x - _labelWidth);
if (newValue < _valueMin)
newValue = _valueMin;
diff --git a/gui/widget.h b/gui/widget.h
index ae9e07d63e..fe6ae0b8c3 100644
--- a/gui/widget.h
+++ b/gui/widget.h
@@ -48,6 +48,7 @@ enum {
kSliderWidget = 'SLDE',
kListWidget = 'LIST',
kScrollBarWidget = 'SCRB',
+ kPopUpWidget = 'POPU',
kTabWidget = 'TABW'
};
@@ -190,9 +191,9 @@ protected:
int _value, _oldValue;
int _valueMin, _valueMax;
bool _isDragging;
- int _labelWidth;
+ uint _labelWidth;
public:
- SliderWidget(GuiObject *boss, int x, int y, int w, int h, const String &label = String::emptyString, int labelWidth = 0, uint32 cmd = 0, uint8 hotkey = 0);
+ SliderWidget(GuiObject *boss, int x, int y, int w, int h, const String &label = String::emptyString, uint labelWidth = 0, uint32 cmd = 0, uint8 hotkey = 0);
void setValue(int value) { _value = value; }
int getValue() const { return _value; }