[Scummvm-cvs-logs] CVS: scummvm/gui PopUpWidget.cpp,1.21,1.22 PopUpWidget.h,1.4,1.5 options.cpp,1.31,1.32 widget.cpp,1.23,1.24 widget.h,1.28,1.29
Max Horn
fingolfin at users.sourceforge.net
Sun Nov 2 17:01:06 CET 2003
Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1:/tmp/cvs-serv11159
Modified Files:
PopUpWidget.cpp PopUpWidget.h options.cpp widget.cpp widget.h
Log Message:
added a builtin label to PopUpWidget
Index: PopUpWidget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/PopUpWidget.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- PopUpWidget.cpp 2 Nov 2003 17:41:01 -0000 1.21
+++ PopUpWidget.cpp 3 Nov 2003 01:00:25 -0000 1.22
@@ -38,8 +38,6 @@
0x00001000,
};
-const Common::String PopUpWidget::emptyStr;
-
//
// PopUpDialog
//
@@ -56,12 +54,10 @@
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 @@
_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 @@
// 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::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);
}
}
Index: PopUpWidget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/PopUpWidget.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- PopUpWidget.h 2 Nov 2003 14:50:44 -0000 1.4
+++ PopUpWidget.h 3 Nov 2003 01:00:25 -0000 1.5
@@ -29,8 +29,8 @@
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 @@
};
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);
Index: options.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/options.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- options.cpp 3 Nov 2003 00:43:29 -0000 1.31
+++ options.cpp 3 Nov 2003 01:00:26 -0000 1.32
@@ -77,9 +77,9 @@
// 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 @@
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();
Index: widget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- widget.cpp 3 Nov 2003 00:43:29 -0000 1.23
+++ widget.cpp 3 Nov 2003 01:00:26 -0000 1.24
@@ -200,7 +200,7 @@
#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 @@
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;
Index: widget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- widget.h 3 Nov 2003 00:43:29 -0000 1.28
+++ widget.h 3 Nov 2003 01:00:26 -0000 1.29
@@ -48,6 +48,7 @@
kSliderWidget = 'SLDE',
kListWidget = 'LIST',
kScrollBarWidget = 'SCRB',
+ kPopUpWidget = 'POPU',
kTabWidget = 'TABW'
};
@@ -190,9 +191,9 @@
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; }
More information about the Scummvm-git-logs
mailing list