Skip to content

Commit

Permalink
UI|Client: Improved the video settings dialog
Browse files Browse the repository at this point in the history
ChoiceWidget has separate signals for user-initiated or other
selection changes.

On OS X, the color depth option is not displayed.
  • Loading branch information
skyjake committed Aug 27, 2013
1 parent 4c7d432 commit 9ae9239
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 16 deletions.
3 changes: 2 additions & 1 deletion doomsday/client/include/ui/widgets/choicewidget.h
Expand Up @@ -71,7 +71,8 @@ public slots:
void openPopup();

signals:
void selectionChanged(unsigned int pos);
void selectionChanged(uint pos);
void selectionChangedByUser(uint pos);

private:
DENG2_PRIVATE(d)
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/include/ui/widgets/videosettingsdialog.h
Expand Up @@ -34,6 +34,8 @@ class VideoSettingsDialog : public DialogWidget
protected slots:
void toggleAntialias();
void toggleVerticalSync();
void changeMode(uint selected);
void changeColorDepth(uint selected);

private:
DENG2_PRIVATE(d)
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/src/ui/widgets/choicewidget.cpp
Expand Up @@ -46,6 +46,8 @@ DENG2_OBSERVES(ContextWidgetOrganizer, WidgetCreation)
d->updateButtonWithSelection();
d->updateItemHighlight();
d->choices->dismiss();

emit d->self.selectionChangedByUser(d->selected);
}

Action *duplicate() const
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/ui/widgets/dialogwidget.cpp
Expand Up @@ -437,10 +437,10 @@ bool DialogWidget::handleEvent(Event const &event)
}
else
{
if(event.type() == Event::MouseButton &&
if((event.type() == Event::MouseButton || event.type() == Event::MousePosition) &&
hitTest(event.as<MouseEvent>().pos()))
{
// Non-modal dialogs eat mouse clicks inside the dialog.
// Non-modal dialogs eat mouse clicks/position inside the dialog.
return true;
}
}
Expand Down
101 changes: 88 additions & 13 deletions doomsday/client/src/ui/widgets/videosettingsdialog.cpp
Expand Up @@ -29,10 +29,15 @@

#include <de/App>
#include <de/DisplayMode>
#include <QPoint>

using namespace de;
using namespace ui;

#ifndef MACOSX
# define USE_COLOR_DEPTH_CHOICE
#endif

DENG2_PIMPL(VideoSettingsDialog),
DENG2_OBSERVES(PersistentCanvasWindow, AttributeChange)
{
Expand All @@ -44,20 +49,24 @@ DENG2_OBSERVES(PersistentCanvasWindow, AttributeChange)
ToggleWidget *fsaa;
ToggleWidget *vsync;
ChoiceWidget *modes;
#ifdef USE_COLOR_DEPTH_CHOICE
ChoiceWidget *depths;
#endif

Instance(Public *i) : Base(i), win(ClientWindow::main())
{
ScrollAreaWidget &area = self.area();

area.add(showFps = new VariableToggleWidget(App::config()["window.main.showFps"]));
area.add(fullscreen = new ToggleWidget);
area.add(maximized = new ToggleWidget);
area.add(centered = new ToggleWidget);
area.add(fsaa = new ToggleWidget);
area.add(vsync = new ToggleWidget);
area.add(modes = new ChoiceWidget);
#ifdef USE_COLOR_DEPTH_CHOICE
area.add(depths = new ChoiceWidget);

#endif
win.audienceForAttributeChange += this;
}

Expand All @@ -76,6 +85,39 @@ DENG2_OBSERVES(PersistentCanvasWindow, AttributeChange)
centered->setActive(win.isCentered());
fsaa->setActive(Con_GetInteger("vid-fsaa") != 0);
vsync->setActive(Con_GetInteger("vid-vsync") != 0);

// Select the current resolution/size in the mode list.
Canvas::Size current;
if(win.isFullScreen())
{
current = win.fullscreenSize();
}
else
{
current = win.windowRect().size();
}

// Update selected display mode.
ui::Context::Pos closest = ui::Context::InvalidPos;
int delta;
for(ui::Context::Pos i = 0; i < modes->items().size(); ++i)
{
QPoint const res = modes->items().at(i).data().toPoint();
int dx = res.x() - current.x;
int dy = res.y() - current.y;
int d = dx*dx + dy*dy;
if(closest == ui::Context::InvalidPos || d < delta)
{
closest = i;
delta = d;
}
}
modes->setSelected(closest);

#ifdef USE_COLOR_DEPTH_CHOICE
// Select the current color depth in the depth list.
depths->setSelected(depths->items().findData(win.colorDepthBits()));
#endif
}

void windowAttributesChanged(PersistentCanvasWindow &)
Expand Down Expand Up @@ -116,13 +158,22 @@ VideoSettingsDialog::VideoSettingsDialog(String const &name)
for(int i = 0; i < DisplayMode_Count(); ++i)
{
DisplayMode const *m = DisplayMode_ByIndex(i);
String desc = String("%1 x %2 (%3:%4)").arg(m->width).arg(m->height)
QPoint const res(m->width, m->height);

if(d->modes->items().findData(res) != ui::Context::InvalidPos)
{
// Got this already.
continue;
}

String desc = String("%1 x %2 (%3:%4)")
.arg(m->width).arg(m->height)
.arg(m->ratioX).arg(m->ratioY);
if(m->refreshRate > 0) desc += String(" @ %1 Hz").arg(m->refreshRate, 0, 'f', 1);

d->modes->items() << new ChoiceItem(desc, i);
d->modes->items() << new ChoiceItem(desc, res);
}

#ifdef USE_COLOR_DEPTH_CHOICE
LabelWidget *colorLabel = new LabelWidget;
colorLabel->setText(tr("Colors:"));
area().add(colorLabel);
Expand All @@ -131,36 +182,44 @@ VideoSettingsDialog::VideoSettingsDialog(String const &name)
d->depths->items()
<< new ChoiceItem(tr("32-bit"), 32)
<< new ChoiceItem(tr("16-bit"), 16);
#endif

buttons().items()
<< new DialogButtonItem(DialogWidget::Action, tr("Reset to Defaults"))
<< new DialogButtonItem(DialogWidget::Action, tr("Color Adjustments..."),
new SignalAction(&d->win.taskBar(), SLOT(closeMainMenu())));

// Layout all widgets.
Rule const &gap = style().rules().rule("dialog.gap");

GridLayout layout(area().contentRule().left(),
area().contentRule().top(), GridLayout::RowFirst);
layout.setGridSize(2, 3);
layout.setColumnPadding(style().rules().rule("gap"));
layout.setColumnPadding(style().rules().rule("dialog.gap"));
layout << *d->showFps
<< *d->fsaa
<< *d->vsync
<< *d->fullscreen
<< *d->maximized
<< *d->centered;

SequentialLayout modeLayout(d->vsync->rule().left(), d->vsync->rule().bottom(), ui::Right);
modeLayout << *modeLabel << *d->modes << *colorLabel << *d->depths;
SequentialLayout modeLayout(d->vsync->rule().left(), d->vsync->rule().bottom() + gap, ui::Right);
modeLayout << *modeLabel << *d->modes;

/*SequentialLayout layout2(modeLabel->rule().left(), modeLabel->rule().bottom());
layout2 << *color << *def;*/
#ifdef USE_COLOR_DEPTH_CHOICE
modeLayout << *colorLabel << *d->depths;
#endif

area().setContentSize(OperatorRule::maximum(layout.width(),
modeLayout.width()
/*layout2.width()*/),
layout.height() + modeLayout.height()/* + layout2.height()*/);
area().setContentSize(OperatorRule::maximum(layout.width(), modeLayout.width()),
layout.height() + gap + modeLayout.height());

d->fetch();

connect(d->modes, SIGNAL(selectionChangedByUser(uint)), this, SLOT(changeMode(uint)));

#ifdef USE_COLOR_DEPTH_CHOICE
connect(d->depths, SIGNAL(selectionChangedByUser(uint)), this, SLOT(changeColorDepth(uint)));
#endif
}

void VideoSettingsDialog::toggleAntialias()
Expand All @@ -172,3 +231,19 @@ void VideoSettingsDialog::toggleVerticalSync()
{
Con_SetInteger("vid-vsync", !Con_GetInteger("vid-vsync"));
}

void VideoSettingsDialog::changeMode(uint selected)
{
QPoint res = d->modes->items().at(selected).data().toPoint();
Con_Executef(CMDS_DDAY, true, "setres %i %i", int(res.x()), int(res.y()));
}

void VideoSettingsDialog::changeColorDepth(uint selected)
{
#ifdef USE_COLOR_DEPTH_CHOICE
Con_Executef(CMDS_DDAY, true, "setcolordepth %i",
d->depths->items().at(selected).data().toInt());
#else
DENG2_UNUSED(selected);
#endif
}

0 comments on commit 9ae9239

Please sign in to comment.