Skip to content

Commit

Permalink
UI|Control Panel|Client: Added Input Settings, removed old "Input" page
Browse files Browse the repository at this point in the history
A new config variable (Config.input.mouse.syncSensitivity) controls
whether the X and Y axis sensitivities are always the same when
modifying them in Input Settings.

Added an option to span cells in GridLayout, and sliders use double
values for extra precision. Sliders also support applying a factor
to the displayed values (does not affect the actual values).
  • Loading branch information
skyjake committed Sep 3, 2013
1 parent 09fc196 commit cd68959
Show file tree
Hide file tree
Showing 13 changed files with 382 additions and 93 deletions.
10 changes: 6 additions & 4 deletions doomsday/client/client.pro
Expand Up @@ -354,7 +354,9 @@ DENG_HEADERS += \
include/ui/dialogs/aboutdialog.h \
include/ui/dialogs/audiosettingsdialog.h \
include/ui/dialogs/coloradjustmentdialog.h \
include/ui/dialogs/inputsettingsdialog.h \
include/ui/dialogs/messagedialog.h \
include/ui/dialogs/networksettingsdialog.h \
include/ui/dialogs/videosettingsdialog.h \
include/ui/fi_main.h \
include/ui/finaleinterpreter.h \
Expand Down Expand Up @@ -473,8 +475,7 @@ INCLUDEPATH += \

HEADERS += \
$$DENG_API_HEADERS \
$$DENG_HEADERS \
include/ui/dialogs/networksettingsdialog.h
$$DENG_HEADERS

# Platform-specific sources.
win32 {
Expand Down Expand Up @@ -686,7 +687,9 @@ SOURCES += \
src/ui/dialogs/aboutdialog.cpp \
src/ui/dialogs/audiosettingsdialog.cpp \
src/ui/dialogs/coloradjustmentdialog.cpp \
src/ui/dialogs/inputsettingsdialog.cpp \
src/ui/dialogs/messagedialog.cpp \
src/ui/dialogs/networksettingsdialog.cpp \
src/ui/dialogs/videosettingsdialog.cpp \
src/ui/fi_main.cpp \
src/ui/finaleinterpreter.cpp \
Expand Down Expand Up @@ -787,8 +790,7 @@ SOURCES += \
src/world/surface.cpp \
src/world/thinkers.cpp \
src/world/vertex.cpp \
src/world/world.cpp \
src/ui/dialogs/networksettingsdialog.cpp
src/world/world.cpp

!deng_nosdlmixer:!deng_nosdl {
HEADERS += include/audio/sys_audiod_sdlmixer.h
Expand Down
45 changes: 45 additions & 0 deletions doomsday/client/include/ui/dialogs/inputsettingsdialog.h
@@ -0,0 +1,45 @@
/** @file inputsettingsdialog.h Dialog for input 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_INPUTSETTINGSDIALOG_H
#define DENG_CLIENT_INPUTSETTINGSDIALOG_H

#include "ui/widgets/dialogwidget.h"

/**
* Dialog for modifying input settings.
*/
class InputSettingsDialog : public DialogWidget
{
Q_OBJECT

public:
InputSettingsDialog(de::String const &name = "inputsettings");

public slots:
void resetToDefaults();

protected slots:
void mouseTogglesChanged();
void mouseSensitivityChanged(double value);

private:
DENG2_PRIVATE(d)
};

#endif // DENG_CLIENT_INPUTSETTINGSDIALOG_H
2 changes: 1 addition & 1 deletion doomsday/client/include/ui/framework/gridlayout.h
Expand Up @@ -58,7 +58,7 @@ class GridLayout
GridLayout &operator << (GuiWidget &widget) { return append(widget); }
GridLayout &operator << (de::Rule const &empty) { return append(empty); }

GridLayout &append(GuiWidget &widget);
GridLayout &append(GuiWidget &widget, int cellSpan = 1);
GridLayout &append(de::Rule const &empty);

/**
Expand Down
2 changes: 0 additions & 2 deletions doomsday/client/include/ui/widgets/cvarsliderwidget.h
Expand Up @@ -33,8 +33,6 @@ class CVarSliderWidget : public SliderWidget

public slots:
void updateFromCVar();

protected slots:
void setCVarValueFromWidget();

private:
Expand Down
20 changes: 15 additions & 5 deletions doomsday/client/include/ui/widgets/sliderwidget.h
Expand Up @@ -37,11 +37,21 @@ class SliderWidget : public GuiWidget

void setRange(de::Rangei const &intRange, int step = 0);
void setRange(de::Rangef const &floatRange, float step = 0);
void setRange(de::Ranged const &doubleRange, de::ddouble step = 0);
void setPrecision(int precisionDecimals);
void setValue(float value);
void setValue(de::ddouble value);

de::Rangef range() const;
float value() const;
/**
* Displayed values are multiplied by this factor when displayed.
* Does not affect the real value of the slider.
*
* @param factor Display multiplier.
*/
void setDisplayFactor(de::ddouble factor);

de::Ranged range() const;
de::ddouble value() const;
de::ddouble displayFactor() const;

// Events.
void viewResized();
Expand All @@ -53,8 +63,8 @@ public slots:
void setValueFromText(QString text);

signals:
void valueChanged(float value);
void valueChangedByUser(float value);
void valueChanged(double value);
void valueChangedByUser(double value);

protected:
void glInit();
Expand Down
1 change: 1 addition & 0 deletions doomsday/client/include/ui/widgets/taskbarwidget.h
Expand Up @@ -61,6 +61,7 @@ public slots:
void showUpdaterSettings();
void showVideoSettings();
void showAudioSettings();
void showInputSettings();
void showNetworkSettings();

signals:
Expand Down
5 changes: 5 additions & 0 deletions doomsday/client/modules/appconfig.de
Expand Up @@ -29,6 +29,11 @@ def setDefaults(d)
# Applies the client's defaults.
# - d: Record where to set the values.

# Input defaults.
record d.input
record d.input.mouse
d.input.mouse.syncSensitivity = True

try
import DisplayMode

Expand Down
185 changes: 185 additions & 0 deletions doomsday/client/src/ui/dialogs/inputsettingsdialog.cpp
@@ -0,0 +1,185 @@
/** @file inputettingsdialog.cpp Dialog for input 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/inputsettingsdialog.h"
#include "ui/widgets/cvarsliderwidget.h"
#include "ui/widgets/cvartogglewidget.h"
#include "ui/widgets/variabletogglewidget.h"

#include "con_main.h"
#include "SignalAction"
#include <de/App>

using namespace de;
using namespace ui;

DENG_GUI_PIMPL(InputSettingsDialog)
{
VariableToggleWidget *syncMouse;
CVarSliderWidget *mouseSensiX;
CVarSliderWidget *mouseSensiY;
ToggleWidget *mouseDisableX;
ToggleWidget *mouseDisableY;
ToggleWidget *mouseInvertX;
ToggleWidget *mouseInvertY;
CVarToggleWidget *joyEnable;

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

area.add(syncMouse = new VariableToggleWidget(App::config()["input.mouse.syncSensitivity"]));
area.add(mouseSensiX = new CVarSliderWidget("input-mouse-x-scale"));
area.add(mouseSensiY = new CVarSliderWidget("input-mouse-y-scale"));
area.add(mouseDisableX = new ToggleWidget);
area.add(mouseDisableY = new ToggleWidget);
area.add(mouseInvertX = new ToggleWidget);
area.add(mouseInvertY = new ToggleWidget);
area.add(joyEnable = new CVarToggleWidget("input-joy"));
}

void fetch()
{
mouseSensiX->updateFromCVar();
mouseSensiY->updateFromCVar();
joyEnable->updateFromCVar();

mouseDisableX->setActive(Con_GetInteger("input-mouse-x-flags") & IDA_DISABLED);
mouseDisableY->setActive(Con_GetInteger("input-mouse-y-flags") & IDA_DISABLED);
mouseInvertX->setActive(Con_GetInteger("input-mouse-x-flags") & IDA_INVERT);
mouseInvertY->setActive(Con_GetInteger("input-mouse-y-flags") & IDA_INVERT);

enableOrDisable();
}

void enableOrDisable()
{
mouseSensiX->disable(mouseDisableX->isActive());
mouseSensiY->disable(mouseDisableY->isActive());
mouseInvertX->disable(mouseDisableX->isActive());
mouseInvertY->disable(mouseDisableY->isActive());
}

void updateMouseFlags()
{
Con_SetInteger("input-mouse-x-flags",
(mouseDisableX->isActive()? IDA_DISABLED : 0) |
(mouseInvertX->isActive()? IDA_INVERT : 0));

Con_SetInteger("input-mouse-y-flags",
(mouseDisableY->isActive()? IDA_DISABLED : 0) |
(mouseInvertY->isActive()? IDA_INVERT : 0));

enableOrDisable();
}
};

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

d->syncMouse->setText(tr("Uniform Mouse Axis Sensitivity"));

LabelWidget *mouseXLabel = new LabelWidget;
mouseXLabel->setText(_E(b) + tr("Mouse X"));
area().add(mouseXLabel);

LabelWidget *mouseYLabel = new LabelWidget;
mouseYLabel->setText(_E(b) + tr("Mouse Y"));
area().add(mouseYLabel);

mouseXLabel->margins().setTop(style().rules().rule("gap"));
mouseYLabel->margins().setTop(style().rules().rule("gap"));

// The sensitivity cvars are unlimited.
d->mouseSensiX->setRange(Rangef(.00005f, .0075f));
d->mouseSensiX->setDisplayFactor(1000);
d->mouseSensiY->setRange(Rangef(.00005f, .0075f));
d->mouseSensiY->setDisplayFactor(1000);

connect(d->mouseSensiX, SIGNAL(valueChangedByUser(double)), this, SLOT(mouseSensitivityChanged(double)));
connect(d->mouseSensiY, SIGNAL(valueChangedByUser(double)), this, SLOT(mouseSensitivityChanged(double)));

d->mouseInvertX->setText(tr("Invert Axis"));
d->mouseDisableX->setText(tr("Disable Axis"));

d->mouseInvertY->setText(tr("Invert Axis"));
d->mouseDisableY->setText(tr("Disable Axis"));

connect(d->mouseInvertX, SIGNAL(stateChangedByUser(ToggleWidget::ToggleState)), this, SLOT(mouseTogglesChanged()));
connect(d->mouseInvertY, SIGNAL(stateChangedByUser(ToggleWidget::ToggleState)), this, SLOT(mouseTogglesChanged()));
connect(d->mouseDisableX, SIGNAL(stateChangedByUser(ToggleWidget::ToggleState)), this, SLOT(mouseTogglesChanged()));
connect(d->mouseDisableY, SIGNAL(stateChangedByUser(ToggleWidget::ToggleState)), this, SLOT(mouseTogglesChanged()));

d->joyEnable->setText(tr("Joystick Enabled"));

// Layout.
GridLayout layout(area().contentRule().left(), area().contentRule().top());
layout.setGridSize(2, 0);
//layout.setColumnAlignment(0, ui::AlignRight);
layout.append(*d->joyEnable, 2)
.append(*d->syncMouse, 2);
layout << *mouseXLabel << *mouseYLabel
<< *d->mouseSensiX << *d->mouseSensiY
<< *d->mouseInvertX << *d->mouseInvertY
<< *d->mouseDisableX << *d->mouseDisableY;

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 InputSettingsDialog::resetToDefaults()
{
Con_SetFloat ("input-mouse-x-scale", .001f);
Con_SetFloat ("input-mouse-y-scale", .001f);
Con_SetInteger("input-mouse-x-flags", 0 );
Con_SetInteger("input-mouse-y-flags", 0 );
Con_SetInteger("input-joy", 1 );

d->fetch();
}

void InputSettingsDialog::mouseTogglesChanged()
{
d->updateMouseFlags();
}

void InputSettingsDialog::mouseSensitivityChanged(double value)
{
// Keep mouse axes synced?
if(d->syncMouse->isActive())
{
if(sender() == d->mouseSensiX)
{
d->mouseSensiY->setValue(value);
d->mouseSensiY->setCVarValueFromWidget();
}
else
{
d->mouseSensiX->setValue(value);
d->mouseSensiX->setCVarValueFromWidget();
}
}
}

0 comments on commit cd68959

Please sign in to comment.