Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
UI|Task Bar|Client: Added the Audio Settings dialog
The Audio Settings dialog replicates the options from the Control
Panel's Audio page.

Also added a specialized toggle widget for toggling cvars.
  • Loading branch information
skyjake committed Sep 2, 2013
1 parent 9b68e50 commit 2dc8092
Show file tree
Hide file tree
Showing 13 changed files with 336 additions and 23 deletions.
4 changes: 4 additions & 0 deletions doomsday/client/client.pro
Expand Up @@ -352,6 +352,7 @@ DENG_HEADERS += \
include/ui/dd_input.h \
include/ui/dd_ui.h \
include/ui/dialogs/aboutdialog.h \
include/ui/dialogs/audiosettingsdialog.h \
include/ui/dialogs/coloradjustmentdialog.h \
include/ui/dialogs/messagedialog.h \
include/ui/dialogs/videosettingsdialog.h \
Expand Down Expand Up @@ -397,6 +398,7 @@ DENG_HEADERS += \
include/ui/widgets/consolecommandwidget.h \
include/ui/widgets/consolewidget.h \
include/ui/widgets/cvarsliderwidget.h \
include/ui/widgets/cvartogglewidget.h \
include/ui/widgets/dialogwidget.h \
include/ui/widgets/documentwidget.h \
include/ui/widgets/gameselectionwidget.h \
Expand Down Expand Up @@ -680,6 +682,7 @@ SOURCES += \
src/ui/clientwindow.cpp \
src/ui/dd_input.cpp \
src/ui/dialogs/aboutdialog.cpp \
src/ui/dialogs/audiosettingsdialog.cpp \
src/ui/dialogs/coloradjustmentdialog.cpp \
src/ui/dialogs/messagedialog.cpp \
src/ui/dialogs/videosettingsdialog.cpp \
Expand Down Expand Up @@ -718,6 +721,7 @@ SOURCES += \
src/ui/widgets/consolecommandwidget.cpp \
src/ui/widgets/consolewidget.cpp \
src/ui/widgets/cvarsliderwidget.cpp \
src/ui/widgets/cvartogglewidget.cpp \
src/ui/widgets/dialogwidget.cpp \
src/ui/widgets/documentwidget.cpp \
src/ui/widgets/gameselectionwidget.cpp \
Expand Down
41 changes: 41 additions & 0 deletions doomsday/client/include/ui/dialogs/audiosettingsdialog.h
@@ -0,0 +1,41 @@
/** @file audiosettingsdialog.h Dialog for audio 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_AUDIOSETTINGSDIALOG_H
#define DENG_CLIENT_AUDIOSETTINGSDIALOG_H

#include "ui/widgets/dialogwidget.h"

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

public:
AudioSettingsDialog(de::String const &name = "audiosettings");

public slots:
void resetToDefaults();

private:
DENG2_PRIVATE(d)
};

#endif // DENG_CLIENT_AUDIOSETTINGSDIALOG_H
2 changes: 1 addition & 1 deletion doomsday/client/include/ui/widgets/cvarsliderwidget.h
Expand Up @@ -31,7 +31,7 @@ class CVarSliderWidget : public SliderWidget
public:
CVarSliderWidget(char const *cvarPath);

public:
public slots:
void updateFromCVar();

protected slots:
Expand Down
44 changes: 44 additions & 0 deletions doomsday/client/include/ui/widgets/cvartogglewidget.h
@@ -0,0 +1,44 @@
/** @file cvartogglewidget.h Console variable toggle.
*
* @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_CVARTOGGLEWIDGET_H
#define DENG_CLIENT_CVARTOGGLEWIDGET_H

#include "togglewidget.h"

/**
* Console variable toggle for on/off type of cvars (value 0 or 1).
*/
class CVarToggleWidget : public ToggleWidget
{
Q_OBJECT

public:
CVarToggleWidget(char const *cvarPath);

public slots:
void updateFromCVar();

protected slots:
void setCVarValueFromWidget();

private:
DENG2_PRIVATE(d)
};

#endif // DENG_CLIENT_CVARTOGGLEWIDGET_H
1 change: 1 addition & 0 deletions doomsday/client/include/ui/widgets/taskbarwidget.h
Expand Up @@ -60,6 +60,7 @@ public slots:
void showAbout();
void showUpdaterSettings();
void showVideoSettings();
void showAudioSettings();

signals:
void opened();
Expand Down
6 changes: 6 additions & 0 deletions doomsday/client/include/ui/widgets/togglewidget.h
Expand Up @@ -27,6 +27,8 @@
*/
class ToggleWidget : public ButtonWidget
{
Q_OBJECT

public:
enum ToggleState {
Active,
Expand Down Expand Up @@ -54,6 +56,10 @@ class ToggleWidget : public ButtonWidget
bool isActive() const { return toggleState() == Active; }
bool isInactive() const { return toggleState() == Inactive; }

signals:
void stateChanged(ToggleWidget::ToggleState active);
void stateChangedByUser(ToggleWidget::ToggleState active);

private:
DENG2_PRIVATE(d)
};
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/audio/s_main.cpp
Expand Up @@ -102,7 +102,7 @@ void S_Register(void)
C_VAR_INT("sound-rate", &sfxSampleRate, 0, 11025, 44100);
C_VAR_INT("sound-16bit", &sfx16Bit, 0, 0, 1);
C_VAR_INT("sound-3d", &sfx3D, 0, 0, 1);
C_VAR_FLOAT2("sound-reverb-volume", &sfxReverbStrength, 0, 0, 10, S_ReverbVolumeChanged);
C_VAR_FLOAT2("sound-reverb-volume", &sfxReverbStrength, 0, 0, 1.5f, S_ReverbVolumeChanged);

// Ccmds
C_CMD_FLAGS("playsound", NULL, PlaySound, CMDF_NO_DEDICATED);
Expand Down
131 changes: 131 additions & 0 deletions doomsday/client/src/ui/dialogs/audiosettingsdialog.cpp
@@ -0,0 +1,131 @@
/** @file audiosettingsdialog.cpp Dialog for audio 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/dialogs/audiosettingsdialog.h"
#include "ui/widgets/cvarsliderwidget.h"
#include "ui/widgets/cvartogglewidget.h"
#include "ui/widgets/choicewidget.h"

#include "con_main.h"
#include "SignalAction"

using namespace de;
using namespace ui;

DENG_GUI_PIMPL(AudioSettingsDialog)
{
CVarSliderWidget *sfxVolume;
CVarSliderWidget *musicVolume;
CVarSliderWidget *reverbVolume;
CVarToggleWidget *sound3D;
CVarToggleWidget *sound16bit;
ChoiceWidget *sampleRate;
CVarToggleWidget *soundInfo;

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

area.add(sfxVolume = new CVarSliderWidget("sound-volume"));
area.add(musicVolume = new CVarSliderWidget("music-volume"));
area.add(reverbVolume = new CVarSliderWidget("sound-reverb-volume"));
area.add(sound3D = new CVarToggleWidget("sound-3d"));
area.add(sound16bit = new CVarToggleWidget("sound-16bit"));
area.add(sampleRate = new ChoiceWidget);
area.add(soundInfo = new CVarToggleWidget("sound-info"));
}

void fetch()
{
sfxVolume->updateFromCVar();
musicVolume->updateFromCVar();
reverbVolume->updateFromCVar();
sound3D->updateFromCVar();
sound16bit->updateFromCVar();
soundInfo->updateFromCVar();

// Update the selected sample rate.
sampleRate->setSelected(sampleRate->items().findData(Con_GetInteger("sound-rate")));
}
};

AudioSettingsDialog::AudioSettingsDialog(String const &name)
: DialogWidget(name, WithHeading), d(new Instance(this))
{
heading().setText(tr("Audio Settings"));

LabelWidget *sfxVolLabel = new LabelWidget;
sfxVolLabel->setText(tr("SFX Volume:"));
area().add(sfxVolLabel);

LabelWidget *musicVolLabel = new LabelWidget;
musicVolLabel->setText(tr("Music Volume:"));
area().add(musicVolLabel);

LabelWidget *rvbVolLabel = new LabelWidget;
rvbVolLabel->setText(tr("Reverb Volume:"));
area().add(rvbVolLabel);

d->sound3D->setText(tr("3D Effects & Reverb"));
d->sound16bit->setText(tr("16-bit Resampling"));

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

d->sampleRate->items()
<< new ChoiceItem(tr("1x @ 11025 Hz"), 11025)
<< new ChoiceItem(tr("2x @ 22050 Hz"), 22050)
<< new ChoiceItem(tr("4x @ 44100 Hz"), 44100);

d->soundInfo->setText(tr("Developer Info"));

// Layout.
GridLayout layout(area().contentRule().left(), area().contentRule().top());
layout.setGridSize(2, 0);
layout.setColumnAlignment(0, ui::AlignRight);
layout << *sfxVolLabel << *d->sfxVolume
<< *musicVolLabel << *d->musicVolume
<< *rvbVolLabel << *d->reverbVolume
<< Const(0) << *d->sound3D
<< *rateLabel << *d->sampleRate
<< Const(0) << *d->sound16bit
<< Const(0) << *d->soundInfo;

area().setContentSize(layout.width(), layout.height());

buttons().items()
<< new DialogButtonItem(DialogWidget::Default | DialogWidget::Accept, tr("Close"))
<< new DialogButtonItem(DialogWidget::Action, tr("Reset to Defaults"),
new SignalAction(this, SLOT(resetToDefaults())));

d->fetch();
}

void AudioSettingsDialog::resetToDefaults()
{
Con_SetInteger("sound-volume", 255 );
Con_SetInteger("music-volume", 255 );
Con_SetFloat ("sound-reverb-volume", 0.5f );
Con_SetInteger("sound-info", 0 );
Con_SetInteger("sound-rate", 11025);
Con_SetInteger("sound-16bit", 0 );
Con_SetInteger("sound-3d", 0 );

d->fetch();
}
24 changes: 20 additions & 4 deletions doomsday/client/src/ui/widgets/cvarsliderwidget.cpp
Expand Up @@ -48,12 +48,28 @@ void CVarSliderWidget::updateFromCVar()
float step = 0;

cvar_t *var = d->var();
setRange(Rangef(var->min, var->max), step);
setValue(CVar_Float(var));
setPrecision(2);
if(var->type == CVT_FLOAT)
{
setRange(Rangef(var->min, var->max), step);
setValue(CVar_Float(var));
setPrecision(2);
}
else
{
setRange(Rangei(var->min, var->max));
setValue(CVar_Integer(var));
}
}

void CVarSliderWidget::setCVarValueFromWidget()
{
CVar_SetFloat(d->var(), value());
cvar_t *var = d->var();
if(var->type == CVT_FLOAT)
{
CVar_SetFloat(d->var(), value());
}
else
{
CVar_SetInteger(d->var(), round<int>(value()));
}
}
54 changes: 54 additions & 0 deletions doomsday/client/src/ui/widgets/cvartogglewidget.cpp
@@ -0,0 +1,54 @@
/** @file cvartogglewidget.cpp Console variable toggle.
*
* @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/cvartogglewidget.h"
#include "con_main.h"

using namespace de;
using namespace ui;

DENG2_PIMPL_NOREF(CVarToggleWidget)
{
char const *cvar;

cvar_t *var() const
{
cvar_t *cv = Con_FindVariable(cvar);
DENG2_ASSERT(cv != 0);
return cv;
}
};

CVarToggleWidget::CVarToggleWidget(char const *cvarPath) : d(new Instance)
{
d->cvar = cvarPath;
updateFromCVar();

connect(this, SIGNAL(stateChangedByUser(ToggleWidget::ToggleState)),
this, SLOT(setCVarValueFromWidget()));
}

void CVarToggleWidget::updateFromCVar()
{
setActive(CVar_Integer(d->var()) != 0);
}

void CVarToggleWidget::setCVarValueFromWidget()
{
CVar_SetInteger(d->var(), isActive()? 1 : 0);
}
3 changes: 3 additions & 0 deletions doomsday/client/src/ui/widgets/sliderwidget.cpp
Expand Up @@ -425,9 +425,12 @@ DENG_GUI_PIMPL(SliderWidget)
SliderWidget::SliderWidget(String const &name)
: GuiWidget(name), d(new Instance(this))
{
/*
// Testing.
setRange(Rangef(0, 1));
setPrecision(2);
setValue(.5f);
*/

// Default size.
rule().setInput(Rule::Width, style().rules().rule("slider.width"))
Expand Down

0 comments on commit 2dc8092

Please sign in to comment.