summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/setupitem.cpp125
-rw-r--r--src/gui/widgets/setupitem.h44
-rw-r--r--src/gui/widgets/tabs/setup_perfomance.cpp28
-rw-r--r--src/gui/widgets/tabs/setup_perfomance.h3
4 files changed, 197 insertions, 3 deletions
diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp
index ee19caed1..67d52ec0e 100644
--- a/src/gui/widgets/setupitem.cpp
+++ b/src/gui/widgets/setupitem.cpp
@@ -27,6 +27,8 @@
#include "gui/fonts/font.h"
+#include "gui/models/listmodel.h"
+
#include "gui/windows/editdialog.h"
#include "gui/widgets/button.h"
@@ -692,7 +694,7 @@ void SetupItemDropDown::createControls()
mDropDown->setActionEventId(mEventName);
mDropDown->addActionListener(mParent);
mDropDown->setWidth(mWidth);
- mDropDown->setSelected(atoi(mValue.c_str()));
+ mDropDown->setSelected(selectionByValue());
mWidget = mDropDown;
if (!mText.empty())
@@ -706,6 +708,11 @@ void SetupItemDropDown::createControls()
mWidget->addActionListener(this);
}
+int SetupItemDropDown::selectionByValue()
+{
+ return atoi(mValue.c_str());
+}
+
void SetupItemDropDown::fromWidget()
{
if (mDropDown == nullptr)
@@ -719,7 +726,121 @@ void SetupItemDropDown::toWidget()
if (mDropDown == nullptr)
return;
- mDropDown->setSelected(atoi(mValue.c_str()));
+ mDropDown->setSelected(selectionByValue());
+}
+
+
+SetupItemDropDownStr::SetupItemDropDownStr(const std::string &restrict text,
+ const std::string &restrict
+ description,
+ const std::string &restrict keyName,
+ SetupTabScroll *restrict const
+ parent,
+ const std::string &restrict
+ eventName,
+ ListModel *restrict const model,
+ const int width,
+ const MainConfig mainConfig) :
+ SetupItem(text, description, keyName, parent, eventName, mainConfig),
+ mHorizont(nullptr),
+ mLabel(nullptr),
+ mModel(model),
+ mDropDown(nullptr),
+ mWidth(width)
+{
+ mValueType = VSTR;
+ createControls();
+}
+
+SetupItemDropDownStr::SetupItemDropDownStr(const std::string &restrict text,
+ const std::string &restrict
+ description,
+ const std::string &restrict keyName,
+ SetupTabScroll *restrict const
+ parent,
+ const std::string &restrict
+ eventName,
+ ListModel *restrict const model,
+ const int width,
+ const std::string &restrict def,
+ const MainConfig mainConfig) :
+ SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
+ mHorizont(nullptr),
+ mLabel(nullptr),
+ mModel(model),
+ mDropDown(nullptr),
+ mWidth(width)
+{
+ mValueType = VSTR;
+ createControls();
+}
+
+SetupItemDropDownStr::~SetupItemDropDownStr()
+{
+ mHorizont = nullptr;
+ mWidget = nullptr;
+ mModel = nullptr;
+ mDropDown = nullptr;
+ mLabel = nullptr;
+}
+
+void SetupItemDropDownStr::createControls()
+{
+ load();
+ mHorizont = new HorizontContainer(this, 32, 2);
+
+ mLabel = new Label(this, mText);
+ mLabel->setToolTip(mDescription);
+ mDropDown = new DropDown(this, mModel);
+ mDropDown->setActionEventId(mEventName);
+ mDropDown->addActionListener(mParent);
+ mDropDown->setWidth(mWidth);
+ mDropDown->setSelected(selectionByValue());
+
+ mWidget = mDropDown;
+ if (!mText.empty())
+ fixFirstItemSize(mLabel);
+ mHorizont->add(mLabel);
+ mHorizont->add(mDropDown);
+
+ mParent->getContainer()->add2(mHorizont, true, 4);
+ mParent->addControl(this);
+ mParent->addActionListener(this);
+ mWidget->addActionListener(this);
+}
+
+int SetupItemDropDownStr::selectionByValue()
+{
+ const int sz = mModel->getNumberOfElements();
+ for (int f = 0; f < sz; f ++)
+ {
+ if (mModel->getElementAt(f) == mValue)
+ {
+ return f;
+ }
+ }
+ return 0;
+}
+
+void SetupItemDropDownStr::fromWidget()
+{
+ if (mDropDown == nullptr)
+ return;
+
+ const int sel = mDropDown->getSelected();
+ // use first element in model as empty string
+ if (sel == 0 || sel >= mModel->getNumberOfElements())
+ mValue = "";
+ else
+ mValue = mModel->getElementAt(sel);
+}
+
+void SetupItemDropDownStr::toWidget()
+{
+ if (mDropDown == nullptr)
+ return;
+
+ mDropDown->setSelected(selectionByValue());
}
diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h
index a60c970c9..eec63a4bc 100644
--- a/src/gui/widgets/setupitem.h
+++ b/src/gui/widgets/setupitem.h
@@ -340,6 +340,50 @@ class SetupItemDropDown final : public SetupItem
void toWidget() override final;
+ int selectionByValue();
+
+ protected:
+ HorizontContainer *mHorizont;
+ Label *mLabel;
+ ListModel *mModel;
+ DropDown *mDropDown;
+ int mWidth;
+};
+
+class SetupItemDropDownStr final : public SetupItem
+{
+ public:
+ SetupItemDropDownStr(const std::string &restrict text,
+ const std::string &restrict description,
+ const std::string &restrict keyName,
+ SetupTabScroll *restrict const parent,
+ const std::string &restrict eventName,
+ ListModel *restrict const model,
+ const int width,
+ const MainConfig mainConfig = MainConfig_true);
+
+ SetupItemDropDownStr(const std::string &restrict text,
+ const std::string &restrict description,
+ const std::string &restrict keyName,
+ SetupTabScroll *restrict const parent,
+ const std::string &restrict eventName,
+ ListModel *restrict const model,
+ const int width,
+ const std::string &restrict def,
+ const MainConfig mainConfig = MainConfig_true);
+
+ A_DELETE_COPY(SetupItemDropDownStr)
+
+ ~SetupItemDropDownStr();
+
+ void createControls();
+
+ void fromWidget() override final;
+
+ void toWidget() override final;
+
+ int selectionByValue();
+
protected:
HorizontContainer *mHorizont;
Label *mLabel;
diff --git a/src/gui/widgets/tabs/setup_perfomance.cpp b/src/gui/widgets/tabs/setup_perfomance.cpp
index d28b82680..664183276 100644
--- a/src/gui/widgets/tabs/setup_perfomance.cpp
+++ b/src/gui/widgets/tabs/setup_perfomance.cpp
@@ -22,6 +22,8 @@
#include "gui/widgets/tabs/setup_perfomance.h"
+#include "configuration.h"
+
#include "gui/models/namesmodel.h"
#include "gui/widgets/containerplacer.h"
@@ -31,6 +33,9 @@
#include "utils/delete2.h"
#include "utils/gettext.h"
+#ifdef USE_SDL2
+#include "utils/sdlhelper.h"
+#endif // USE_SDL2
#include "debug.h"
@@ -48,7 +53,8 @@ static const char *const texturesList[] =
Setup_Perfomance::Setup_Perfomance(const Widget2 *const widget) :
SetupTabScroll(widget),
- mTexturesList(new NamesModel)
+ mTexturesList(new NamesModel),
+ mSdlDriversList(new NamesModel)
{
// TRANSLATORS: settings tab name
setName(_("Performance"));
@@ -58,6 +64,15 @@ Setup_Perfomance::Setup_Perfomance(const Widget2 *const widget) :
ContainerPlacer place = h.getPlacer(0, 0);
place(0, 0, mScroll, 10, 10);
+#ifdef USE_SDL2
+ StringVect sdlDriversList;
+ SDL::getRenderers(sdlDriversList,
+ config.getStringValue("sdlDriver"));
+ sdlDriversList.insert(sdlDriversList.begin(),
+ // TRANSLATORS: sdl driver name
+ N_("default"));
+#endif // USE_SDL2
+
// TRANSLATORS: settings option
new SetupItemLabel(_("Better performance (enable for better performance)"),
"", this);
@@ -138,6 +153,14 @@ Setup_Perfomance::Setup_Perfomance(const Widget2 *const widget) :
new SetupItemLabel(_("Different options (enable or disable can "
"improve performance)"), "", this);
+#ifdef USE_SDL2
+ mSdlDriversList->fillFromVector(sdlDriversList);
+ new SetupItemDropDownStr(
+ // TRANSLATORS: settings option
+ _("Try first sdl driver (only for SDL2 default mode)"),
+ "", "sdlDriver", this, "sdlDriverEvent", mSdlDriversList, 100);
+#endif // USE_SDL2
+
mTexturesList->fillFromArray(&texturesList[0], texturesListSize);
// TRANSLATORS: settings option
new SetupItemDropDown(_("Enable texture compression (OpenGL)"), "",
@@ -179,4 +202,7 @@ Setup_Perfomance::Setup_Perfomance(const Widget2 *const widget) :
Setup_Perfomance::~Setup_Perfomance()
{
delete2(mTexturesList);
+#ifdef USE_SDL2
+ delete2(mSdlDriversList);
+#endif // USE_SDL2
}
diff --git a/src/gui/widgets/tabs/setup_perfomance.h b/src/gui/widgets/tabs/setup_perfomance.h
index 6e933c0fc..a4043ab4e 100644
--- a/src/gui/widgets/tabs/setup_perfomance.h
+++ b/src/gui/widgets/tabs/setup_perfomance.h
@@ -38,6 +38,9 @@ class Setup_Perfomance final : public SetupTabScroll
private:
NamesModel *mTexturesList;
+#ifdef USE_SDL2
+ NamesModel *mSdlDriversList;
+#endif // USE_SDL2
};
#endif // GUI_WIDGETS_TABS_SETUP_PERFOMANCE_H