Skip to content

Commit

Permalink
UI|Client: Basic implementation of video settings
Browse files Browse the repository at this point in the history
The Video Settings dialog allows changing the display mode and window
attributes. The "Toggle Fullscreen" and "Show FPS" options were
relocated into the new dialog.

Improved ChoiceWidget with configurable opening direction and added
the "togglecentered" console command.
  • Loading branch information
skyjake committed Aug 27, 2013
1 parent 7158ad7 commit 4c7d432
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 6 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/client.pro
Expand Up @@ -386,6 +386,7 @@ DENG_HEADERS += \
include/ui/widgets/togglewidget.h \
include/ui/widgets/variabletoggleitem.h \
include/ui/widgets/variabletogglewidget.h \
include/ui/widgets/videosettingsdialog.h \
include/ui/widgets/widgetactions.h \
include/ui/windowsystem.h \
include/ui/zonedebug.h \
Expand Down Expand Up @@ -700,6 +701,7 @@ SOURCES += \
src/ui/widgets/taskbarwidget.cpp \
src/ui/widgets/togglewidget.cpp \
src/ui/widgets/variabletogglewidget.cpp \
src/ui/widgets/videosettingsdialog.cpp \
src/ui/widgets/widgetactions.cpp \
src/ui/windowsystem.cpp \
src/ui/zonedebug.cpp \
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/include/ui/widgets/choicewidget.h
Expand Up @@ -56,6 +56,8 @@ class ChoiceWidget : public ButtonWidget
public:
ChoiceWidget(de::String const &name = "");

void setOpeningDirection(ui::Direction dir);

ui::Context &items();

PopupMenuWidget &popup();
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/include/ui/widgets/taskbarwidget.h
Expand Up @@ -55,9 +55,11 @@ public slots:
void openAndPauseGame();
void close();
void openMainMenu();
void closeMainMenu();
void unloadGame();
void showAbout();
void showUpdaterSettings();
void showVideoSettings();

signals:
void opened();
Expand Down
42 changes: 42 additions & 0 deletions doomsday/client/include/ui/widgets/videosettingsdialog.h
@@ -0,0 +1,42 @@
/** @file videosettingsdialog.h Dialog for video settings.
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef DENG_CLIENT_VIDEOSETTINGSDIALOG_H
#define DENG_CLIENT_VIDEOSETTINGSDIALOG_H

#include "dialogwidget.h"

/**
* Dialog for modifying video settings.
*/
class VideoSettingsDialog : public DialogWidget
{
Q_OBJECT

public:
VideoSettingsDialog(de::String const &name = "videosettings");

protected slots:
void toggleAntialias();
void toggleVerticalSync();

private:
DENG2_PRIVATE(d)
};

#endif // DENG_CLIENT_VIDEOSETTINGSDIALOG_H
18 changes: 18 additions & 0 deletions doomsday/client/src/gl/gl_main.cpp
Expand Up @@ -54,6 +54,7 @@ D_CMD(SetFullRes);
D_CMD(SetWinRes);
D_CMD(ToggleFullscreen);
D_CMD(ToggleMaximized);
D_CMD(ToggleCentered);
D_CMD(CenterWindow);
D_CMD(DisplayModeInfo);
D_CMD(ListDisplayModes);
Expand Down Expand Up @@ -144,6 +145,7 @@ void GL_Register()
C_CMD ("setvidramp", "", UpdateGammaRamp);
C_CMD ("togglefullscreen", "", ToggleFullscreen);
C_CMD ("togglemaximized", "", ToggleMaximized);
C_CMD ("togglecentered", "", ToggleCentered);
C_CMD ("centerwindow", "", CenterWindow);

GL_TexRegister();
Expand Down Expand Up @@ -1242,6 +1244,22 @@ D_CMD(ToggleMaximized)
return win->changeAttributes(attribs);
}

D_CMD(ToggleCentered)
{
DENG2_UNUSED3(src, argc, argv);

ClientWindow *win = WindowSystem::mainPtr();

if(!win)
return false;

int attribs[] = {
ClientWindow::Centered, !win->isCentered(),
ClientWindow::End
};
return win->changeAttributes(attribs);
}

D_CMD(CenterWindow)
{
DENG2_UNUSED3(src, argc, argv);
Expand Down
10 changes: 8 additions & 2 deletions doomsday/client/src/ui/widgets/choicewidget.cpp
Expand Up @@ -63,7 +63,6 @@ DENG2_OBSERVES(ContextWidgetOrganizer, WidgetCreation)
self.setFont("choice.selected");

choices = new PopupMenuWidget;
choices->setAnchorAndOpeningDirection(self.hitRule(), ui::Right);
choices->menu().items().audienceForAddition += this;
choices->menu().items().audienceForRemoval += this;
choices->menu().organizer().audienceForWidgetCreation += this;
Expand Down Expand Up @@ -172,7 +171,14 @@ DENG2_OBSERVES(ContextWidgetOrganizer, WidgetCreation)
};

ChoiceWidget::ChoiceWidget(String const &name) : ButtonWidget(name), d(new Instance(this))
{}
{
setOpeningDirection(ui::Right);
}

void ChoiceWidget::setOpeningDirection(Direction dir)
{
d->choices->setAnchorAndOpeningDirection(hitRule(), dir);
}

PopupMenuWidget &ChoiceWidget::popup()
{
Expand Down
33 changes: 29 additions & 4 deletions doomsday/client/src/ui/widgets/taskbarwidget.cpp
Expand Up @@ -24,6 +24,7 @@
#include "ui/widgets/popupmenuwidget.h"
#include "ui/widgets/blurwidget.h"
#include "ui/widgets/aboutdialog.h"
#include "ui/widgets/videosettingsdialog.h"
#include "updater/updatersettingsdialog.h"
#include "ui/clientwindow.h"
#include "ui/commandaction.h"
Expand All @@ -47,8 +48,9 @@ using namespace ui;

static TimeDelta OPEN_CLOSE_SPAN = 0.2;
static uint POS_PANEL = 0;
static uint POS_UNLOAD = 3;
static uint POS_UPDATER_SETTINGS = 6;
static uint POS_VIDEO_SETTINGS = 1;
static uint POS_UNLOAD = 2;
static uint POS_UPDATER_SETTINGS = 5;

DENG_GUI_PIMPL(TaskBarWidget),
public IGameChangeObserver
Expand Down Expand Up @@ -247,8 +249,10 @@ TaskBarWidget::TaskBarWidget() : GuiWidget("taskbar"), d(new Instance(this))
*/
d->mainMenu->menu().items()
<< new ui::ActionItem(_E(b) + tr("Open Control Panel"), new CommandAction("panel"))
<< new ui::ActionItem(tr("Toggle Fullscreen"), new CommandAction("togglefullscreen"))
<< new ui::VariableToggleItem(tr("Show FPS"), App::config()["window.main.showFps"])
//<< new ui::ActionItem(tr("Toggle Fullscreen"), new CommandAction("togglefullscreen"))
<< new ui::ActionItem(ui::Item::ShownAsButton, tr("Video Settings"),
new SignalAction(this, SLOT(showVideoSettings())))
//<< new ui::VariableToggleItem(tr("Show FPS"), App::config()["window.main.showFps"])
<< unloadMenu
<< new ui::Item(ui::Item::Separator)
<< new ui::ActionItem(tr("Check for Updates..."), new CommandAction("updateandnotify"))
Expand Down Expand Up @@ -464,6 +468,11 @@ void TaskBarWidget::openMainMenu()
d->mainMenu->open();
}

void TaskBarWidget::closeMainMenu()
{
d->mainMenu->close();
}

void TaskBarWidget::unloadGame()
{
Con_Execute(CMDS_DDAY, "unload", false, false);
Expand All @@ -490,3 +499,19 @@ void TaskBarWidget::showUpdaterSettings()
}
dlg->exec(root());
}

void TaskBarWidget::showVideoSettings()
{
VideoSettingsDialog *dlg = new VideoSettingsDialog;
dlg->setDeleteAfterDismissed(true);
if(d->mainMenu->isOpen())
{
dlg->setAnchorAndOpeningDirection(d->mainMenu->menu().organizer().
itemWidget(POS_VIDEO_SETTINGS)->hitRule(),
ui::Left);

connect(d->mainMenu, SIGNAL(closed()), dlg, SLOT(close()));
}
root().add(dlg);
dlg->open();
}
174 changes: 174 additions & 0 deletions doomsday/client/src/ui/widgets/videosettingsdialog.cpp
@@ -0,0 +1,174 @@
/** @file videosettingsdialog.cpp Dialog for video settings.
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#include "ui/widgets/videosettingsdialog.h"
#include "ui/widgets/variabletogglewidget.h"
#include "ui/widgets/choicewidget.h"
#include "ui/widgets/taskbarwidget.h"
#include "ui/widgets/sequentiallayout.h"
#include "ui/widgets/gridlayout.h"
#include "ui/clientwindow.h"
#include "ui/commandaction.h"
#include "ui/signalaction.h"
#include "con_main.h"

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

using namespace de;
using namespace ui;

DENG2_PIMPL(VideoSettingsDialog),
DENG2_OBSERVES(PersistentCanvasWindow, AttributeChange)
{
ClientWindow &win;
VariableToggleWidget *showFps;
ToggleWidget *fullscreen;
ToggleWidget *maximized;
ToggleWidget *centered;
ToggleWidget *fsaa;
ToggleWidget *vsync;
ChoiceWidget *modes;
ChoiceWidget *depths;

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);
area.add(depths = new ChoiceWidget);

win.audienceForAttributeChange += this;
}

~Instance()
{
win.audienceForAttributeChange -= this;
}

/**
* Updates the widgets with the actual current state.
*/
void fetch()
{
fullscreen->setActive(win.isFullScreen());
maximized->setActive(win.isMaximized());
centered->setActive(win.isCentered());
fsaa->setActive(Con_GetInteger("vid-fsaa") != 0);
vsync->setActive(Con_GetInteger("vid-vsync") != 0);
}

void windowAttributesChanged(PersistentCanvasWindow &)
{
fetch();
}
};

VideoSettingsDialog::VideoSettingsDialog(String const &name)
: DialogWidget(name), d(new Instance(this))
{
// Fullscreen, Maximized, Centered, FPS, FSAA, VSync

// Toggles for video/window options.
d->fullscreen->setText(tr("Fullscreen"));
d->fullscreen->setAction(new CommandAction("togglefullscreen"));

d->maximized->setText(tr("Maximized"));
d->maximized->setAction(new CommandAction("togglemaximized"));

d->centered->setText(tr("Center Window"));
d->centered->setAction(new CommandAction("togglecentered"));

d->showFps->setText(tr("Show FPS"));

d->fsaa->setText(tr("Antialias"));
d->fsaa->setAction(new SignalAction(this, SLOT(toggleAntialias())));

d->vsync->setText(tr("VSync"));
d->vsync->setAction(new SignalAction(this, SLOT(toggleVerticalSync())));

LabelWidget *modeLabel = new LabelWidget;
modeLabel->setText(tr("Mode:"));
area().add(modeLabel);

// Choice of display modes + 16/32-bit color depth.
d->modes->setOpeningDirection(ui::Up);
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)
.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);
}

LabelWidget *colorLabel = new LabelWidget;
colorLabel->setText(tr("Colors:"));
area().add(colorLabel);

d->depths->setOpeningDirection(ui::Up);
d->depths->items()
<< new ChoiceItem(tr("32-bit"), 32)
<< new ChoiceItem(tr("16-bit"), 16);

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.
GridLayout layout(area().contentRule().left(),
area().contentRule().top(), GridLayout::RowFirst);
layout.setGridSize(2, 3);
layout.setColumnPadding(style().rules().rule("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 layout2(modeLabel->rule().left(), modeLabel->rule().bottom());
layout2 << *color << *def;*/

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

d->fetch();
}

void VideoSettingsDialog::toggleAntialias()
{
Con_SetInteger("vid-fsaa", !Con_GetInteger("vid-fsaa"));
}

void VideoSettingsDialog::toggleVerticalSync()
{
Con_SetInteger("vid-vsync", !Con_GetInteger("vid-vsync"));
}

0 comments on commit 4c7d432

Please sign in to comment.