aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorbjörn Andersson2005-05-19 17:03:31 +0000
committerTorbjörn Andersson2005-05-19 17:03:31 +0000
commit81453854ee693aa31bbbd733043c114653265feb (patch)
tree8b548c0f4cb4a667461607503ce7996411813c64
parente8cb767e5bd0c34a68d31cb1debf9c86ab27a372 (diff)
downloadscummvm-rg350-81453854ee693aa31bbbd733043c114653265feb.tar.gz
scummvm-rg350-81453854ee693aa31bbbd733043c114653265feb.tar.bz2
scummvm-rg350-81453854ee693aa31bbbd733043c114653265feb.zip
Big version of the popup widget. It could use a bit more polish, though...
svn-id: r18185
-rw-r--r--gui/PopUpWidget.cpp114
-rw-r--r--gui/PopUpWidget.h5
-rw-r--r--gui/dialog.cpp17
-rw-r--r--gui/dialog.h5
-rw-r--r--gui/launcher.cpp12
-rw-r--r--gui/options.cpp28
6 files changed, 127 insertions, 54 deletions
diff --git a/gui/PopUpWidget.cpp b/gui/PopUpWidget.cpp
index b1bfa18c4e..49ab6efe19 100644
--- a/gui/PopUpWidget.cpp
+++ b/gui/PopUpWidget.cpp
@@ -19,6 +19,7 @@
*/
#include "stdafx.h"
+#include "common/system.h"
#include "gui/dialog.h"
#include "gui/newgui.h"
#include "gui/PopUpWidget.h"
@@ -26,20 +27,6 @@
namespace GUI {
-#define UP_DOWN_BOX_HEIGHT 10
-
-// Little up/down arrow
-static uint32 up_down_arrows[8] = {
- 0x00000000,
- 0x00001000,
- 0x00011100,
- 0x00111110,
- 0x00000000,
- 0x00111110,
- 0x00011100,
- 0x00001000,
-};
-
//
// PopUpDialog
//
@@ -47,12 +34,14 @@ static uint32 up_down_arrows[8] = {
class PopUpDialog : public Dialog {
protected:
PopUpWidget *_popUpBoss;
+ const Graphics::Font *_font;
+ int _lineHeight;
int _clickX, _clickY;
byte *_buffer;
int _selection;
uint32 _openTime;
public:
- PopUpDialog(PopUpWidget *boss, int clickX, int clickY);
+ PopUpDialog(PopUpWidget *boss, int clickX, int clickY, WidgetSize ws = kDefaultWidgetSize);
void drawDialog();
@@ -72,28 +61,44 @@ protected:
void moveDown();
};
-PopUpDialog::PopUpDialog(PopUpWidget *boss, int clickX, int clickY)
+PopUpDialog::PopUpDialog(PopUpWidget *boss, int clickX, int clickY, WidgetSize ws)
: Dialog(0, 0, 16, 16),
_popUpBoss(boss) {
+ switch (ws) {
+ case kNormalWidgetSize:
+ _font = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont);
+ break;
+ case kBigWidgetSize:
+ _font = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
+ break;
+ case kDefaultWidgetSize:
+ _font = &g_gui.getFont();
+ break;
+ }
+
+ _lineHeight = _font->getFontHeight() + 2;
+
// Copy the selection index
_selection = _popUpBoss->_selectedItem;
// Calculate real popup dimensions
_x = _popUpBoss->getAbsX() + _popUpBoss->_labelWidth;
- _y = _popUpBoss->getAbsY() - _popUpBoss->_selectedItem * kLineHeight;
- _h = _popUpBoss->_entries.size() * kLineHeight + 2;
- _w = _popUpBoss->_w - 10 - _popUpBoss->_labelWidth;
+ _y = _popUpBoss->getAbsY() - _popUpBoss->_selectedItem * _lineHeight;
+ _h = _popUpBoss->_entries.size() * _lineHeight + 2;
+ _w = _popUpBoss->_w - _lineHeight + 2 - _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
- // screen height, and also OSystem should send out notification messages when the screen
+ // FIXME - OSystem should send out notification messages when the screen
// resolution changes... we could generalize CommandReceiver and CommandSender.
- if (_h >= 200)
- _h = 199;
+
+ const int screenH = g_system->getOverlayHeight();
+
+ if (_h >= screenH)
+ _h = screenH - 1;
if (_y < 0)
_y = 0;
- else if (_y + _h >= 200)
- _y = 199 - _h;
+ else if (_y + _h >= screenH)
+ _y = screenH - 1 - _h;
// TODO - implement scrolling if we had to move the menu, or if there are too many entries
@@ -187,7 +192,7 @@ void PopUpDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) {
int PopUpDialog::findItem(int x, int y) const {
if (x >= 0 && x < _w && y >= 0 && y < _h) {
- return (y - 2) / kLineHeight;
+ return (y - 2) / _lineHeight;
}
return -1;
}
@@ -247,19 +252,19 @@ void PopUpDialog::drawMenuEntry(int entry, bool hilite) {
// Draw one entry of the popup menu, including selection
assert(entry >= 0);
int x = _x + 1;
- int y = _y + 1 + kLineHeight * entry;
+ int y = _y + 1 + _lineHeight * entry;
int w = _w - 2;
Common::String &name = _popUpBoss->_entries[entry].name;
- g_gui.fillRect(x, y, w, kLineHeight, hilite ? g_gui._textcolorhi : g_gui._bgcolor);
+ g_gui.fillRect(x, y, w, _lineHeight, hilite ? g_gui._textcolorhi : g_gui._bgcolor);
if (name.size() == 0) {
// Draw a separator
- g_gui.hLine(x - 1, y + kLineHeight / 2, x + w, g_gui._shadowcolor);
- g_gui.hLine(x, y + 1 + kLineHeight / 2, x + w, g_gui._color);
+ g_gui.hLine(x - 1, y + _lineHeight / 2, x + w, g_gui._shadowcolor);
+ g_gui.hLine(x, y + 1 + _lineHeight / 2, x + w, g_gui._color);
} else {
- g_gui.drawString(name, x + 1, y + 2, w - 2, hilite ? g_gui._bgcolor : g_gui._textcolor);
+ g_gui.drawString(_font, name, x + 1, y + 2, w - 2, hilite ? g_gui._bgcolor : g_gui._textcolor);
}
- g_gui.addDirtyRect(x, y, w, kLineHeight);
+ g_gui.addDirtyRect(x, y, w, _lineHeight);
}
@@ -269,21 +274,35 @@ void PopUpDialog::drawMenuEntry(int entry, bool hilite) {
// PopUpWidget
//
-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) {
+PopUpWidget::PopUpWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint labelWidth, WidgetSize ws)
+ : Widget(boss, x, y - 1, w, h + 2), CommandSender(boss), _ws(ws), _label(label), _labelWidth(labelWidth) {
_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS;
_type = kPopUpWidget;
_selectedItem = -1;
+ switch (_ws) {
+ case kNormalWidgetSize:
+ _font = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont);
+ break;
+ case kBigWidgetSize:
+ _font = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
+ break;
+ case kDefaultWidgetSize:
+ _font = &g_gui.getFont();
+ break;
+ }
+
+ _lineHeight = _font->getFontHeight() + 2;
+
if (!_label.isEmpty() && _labelWidth == 0)
- _labelWidth = g_gui.getStringWidth(_label);
+ _labelWidth = _font->getStringWidth(_label);
}
void PopUpWidget::handleMouseDown(int x, int y, int button, int clickCount) {
if (isEnabled()) {
- PopUpDialog popupDialog(this, x + getAbsX(), y + getAbsY());
+ PopUpDialog popupDialog(this, x + getAbsX(), y + getAbsY(), _ws);
int newSel = popupDialog.runModal();
if (newSel != -1 && _selectedItem != newSel) {
_selectedItem = newSel;
@@ -332,7 +351,7 @@ void PopUpWidget::drawWidget(bool hilite) {
// Draw the label, if any
if (_labelWidth > 0)
- gui->drawString(_label, _x, _y + 3, _labelWidth, isEnabled() ? gui->_textcolor : gui->_color, kTextAlignRight);
+ gui->drawString(_font, _label, _x, _y + 3, _labelWidth, isEnabled() ? gui->_textcolor : gui->_color, kTextAlignRight);
// Draw a thin frame around us.
gui->hLine(x, _y, x + w - 1, gui->_color);
@@ -340,13 +359,26 @@ void PopUpWidget::drawWidget(bool hilite) {
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);
+ // Draw a set of arrows at the right end to signal this is a dropdown/popup
+ Common::Point p0, p1;
+
+ p0 = Common::Point(x + w + 1 - _h / 2, _y + 4);
+ p1 = Common::Point(x + w + 1 - _h / 2, _y + _h - 4);
+
+ Graphics::Surface &surf = g_gui.getScreen();
+ OverlayColor color = !isEnabled() ? gui->_color : hilite ? gui->_textcolorhi : gui->_textcolor;
+
+ // Evil HACK to draw filled triangles
+ // FIXME: The "big" version is pretty ugly.
+ for (; p1.y - p0.y > 1; p0.y++, p0.x--, p1.y--, p1.x++) {
+ surf.drawLine(p0.x, p0.y, p1.x, p0.y, color);
+ surf.drawLine(p0.x, p1.y, p1.x, p1.y, color);
+ }
// Draw the selected entry, if any
if (_selectedItem >= 0) {
- TextAlignment 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);
+ TextAlignment align = (_font->getStringWidth(_entries[_selectedItem].name) > w-6) ? kTextAlignRight : kTextAlignLeft;
+ gui->drawString(_font, _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 6a1e2f9cc8..cd55c9ea56 100644
--- a/gui/PopUpWidget.h
+++ b/gui/PopUpWidget.h
@@ -48,14 +48,17 @@ class PopUpWidget : public Widget, public CommandSender {
};
typedef Common::Array<Entry> EntryList;
protected:
+ const WidgetSize _ws;
+ const Graphics::Font *_font;
EntryList _entries;
+ int _lineHeight;
int _selectedItem;
String _label;
uint _labelWidth;
public:
- PopUpWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint labelWidth = 0);
+ PopUpWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint labelWidth = 0, WidgetSize ws = kDefaultWidgetSize);
void handleMouseDown(int x, int y, int button, int clickCount);
diff --git a/gui/dialog.cpp b/gui/dialog.cpp
index 78a3ca6d33..2b5de0ba9b 100644
--- a/gui/dialog.cpp
+++ b/gui/dialog.cpp
@@ -24,6 +24,7 @@
#include "gui/newgui.h"
#include "gui/dialog.h"
#include "gui/widget.h"
+#include "gui/PopUpWidget.h"
#include "common/system.h"
@@ -341,6 +342,22 @@ SliderWidget *Dialog::addSlider(GuiObject *boss, int x, int y, uint32 cmd, Widge
return new SliderWidget(boss, x, y, w, h, cmd);
}
+PopUpWidget *Dialog::addPopUp(int x, int y, int w, const Common::String &label, uint labelWidth, WidgetSize ws) {
+ return addPopUp(this, x, y, w, label, labelWidth, ws);
+}
+
+PopUpWidget *Dialog::addPopUp(GuiObject *boss, int x, int y, int w, const Common::String &label, uint labelWidth, WidgetSize ws) {
+ const Graphics::Font *font;
+
+ if (ws == kBigWidgetSize) {
+ font = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
+ } else {
+ font = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont);
+ }
+
+ return new PopUpWidget(boss, x, y, w, font->getFontHeight() + 2, label, labelWidth, ws);
+}
+
uint32 GuiObject::getMillis() {
return g_system->getMillis();
}
diff --git a/gui/dialog.h b/gui/dialog.h
index e4bd5238bd..ec024d5df1 100644
--- a/gui/dialog.h
+++ b/gui/dialog.h
@@ -30,7 +30,7 @@
namespace GUI {
class NewGui;
-class ButtonWidget;
+class PopUpWidget;
// Some "common" commands sent to handleCommand()
enum {
@@ -96,6 +96,9 @@ protected:
SliderWidget *addSlider(GuiObject *boss, int x, int y, uint32 cmd, WidgetSize ws = kDefaultWidgetSize);
SliderWidget *addSlider(int x, int y, uint32 cmd, WidgetSize ws = kDefaultWidgetSize);
+ PopUpWidget *addPopUp(GuiObject *boss, int x, int y, int w, const Common::String &label, uint labelWidth = 0, WidgetSize ws = kDefaultWidgetSize);
+ PopUpWidget *addPopUp(int x, int y, int w, const Common::String &label, uint labelWidth = 0, WidgetSize ws = kDefaultWidgetSize);
+
void setResult(int result) { _result = result; }
int getResult() const { return _result; }
};
diff --git a/gui/launcher.cpp b/gui/launcher.cpp
index 19750361d0..b32de81c02 100644
--- a/gui/launcher.cpp
+++ b/gui/launcher.cpp
@@ -147,22 +147,24 @@ EditGameDialog::EditGameDialog(const String &domain, GameSettings target)
GUI::WidgetSize ws;
int buttonHeight;
int buttonWidth;
+ int labelWidth;
if (screenW >= 400 && screenH >= 300) {
ws = GUI::kBigWidgetSize;
_h = screenH - 2 * 40; // TODO/FIXME
buttonHeight = kBigButtonHeight;
buttonWidth = kBigButtonWidth;
+ labelWidth = 90;
} else {
ws = GUI::kNormalWidgetSize;
_h = screenH - 2 * 30; // TODO/FIXME
buttonHeight = kButtonHeight;
buttonWidth = kButtonWidth;
+ labelWidth = 60;
}
const int x = 5;
const int w = _w - 15;
- const int labelWidth = 65;
const int vBorder = 5; // Tab border
int yoffset;
@@ -197,8 +199,8 @@ EditGameDialog::EditGameDialog(const String &domain, GameSettings target)
yoffset += 16;
// Language popup
- _langPopUp = new PopUpWidget(tab, x, yoffset, w, kLineHeight, "Language: ", labelWidth);
- yoffset += 16;
+ _langPopUp = addPopUp(tab, x, yoffset, w, "Language: ", labelWidth, ws);
+ yoffset += _langPopUp->getHeight() + 4;
_langPopUp->appendEntry("<default>");
_langPopUp->appendEntry("");
const Common::LanguageDescription *l = Common::g_languages;
@@ -207,8 +209,8 @@ EditGameDialog::EditGameDialog(const String &domain, GameSettings target)
}
// Platform popup
- _platformPopUp = new PopUpWidget(tab, x, yoffset, w, kLineHeight, "Platform: ", labelWidth);
- yoffset += 16;
+ _platformPopUp = addPopUp(tab, x, yoffset, w, "Platform: ", labelWidth, ws);
+ yoffset += _platformPopUp->getHeight() + 4;
_platformPopUp->appendEntry("<default>");
_platformPopUp->appendEntry("");
const Common::PlatformDescription *p = Common::g_platforms;
diff --git a/gui/options.cpp b/gui/options.cpp
index de5897f9ad..f1f8088d83 100644
--- a/gui/options.cpp
+++ b/gui/options.cpp
@@ -313,9 +313,17 @@ int OptionsDialog::addGraphicControls(GuiObject *boss, int yoffset, WidgetSize w
const int w = _w - 2 * 10;
const OSystem::GraphicsMode *gm = g_system->getSupportedGraphicsModes();
+ int labelWidth;
+
+ if (ws == kBigWidgetSize) {
+ labelWidth = 150;
+ } else {
+ labelWidth = 100;
+ }
+
// The GFX mode popup
- _gfxPopUp = new PopUpWidget(boss, x-5, yoffset, w+5, kLineHeight, "Graphics mode: ", 100);
- yoffset += 16;
+ _gfxPopUp = addPopUp(boss, x-5, yoffset, w+5, "Graphics mode: ", labelWidth, ws);
+ yoffset += _gfxPopUp->getHeight() + 4;
_gfxPopUp->appendEntry("<default>");
_gfxPopUp->appendEntry("");
@@ -325,8 +333,8 @@ int OptionsDialog::addGraphicControls(GuiObject *boss, int yoffset, WidgetSize w
}
// RenderMode popup
- _renderModePopUp = new PopUpWidget(boss, x-5, yoffset, w+5, kLineHeight, "Render mode: ", 100);
- yoffset += 16;
+ _renderModePopUp = addPopUp(boss, x-5, yoffset, w+5, "Render mode: ", labelWidth, ws);
+ yoffset += _renderModePopUp->getHeight() + 4;
_renderModePopUp->appendEntry("<default>", Common::kRenderDefault);
_renderModePopUp->appendEntry("");
const Common::RenderModeDescription *rm = Common::g_renderModes;
@@ -357,9 +365,17 @@ int OptionsDialog::addAudioControls(GuiObject *boss, int yoffset, WidgetSize ws)
const int x = 10;
const int w = _w - 20;
+ int labelWidth;
+
+ if (ws == kBigWidgetSize) {
+ labelWidth = 150;
+ } else {
+ labelWidth = 100;
+ }
+
// The MIDI mode popup & a label
- _midiPopUp = new PopUpWidget(boss, x-5, yoffset, w+5, kLineHeight, "Music driver: ", 100);
- yoffset += 18;
+ _midiPopUp = addPopUp(boss, x-5, yoffset, w+5, "Music driver: ", labelWidth, ws);
+ yoffset += _midiPopUp->getHeight() + 4;
// Populate it
const MidiDriverDescription *md = MidiDriver::getAvailableMidiDrivers();