mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 14:15:38 +00:00
Added DIMTIME slider to settings.
Sliders now show their exact value + a unit suffix to the right of the slider.
This commit is contained in:
parent
2862171dab
commit
92a6678736
|
@ -7,13 +7,14 @@
|
|||
#include "../scrapers/GamesDBScraper.h"
|
||||
|
||||
GuiSettingsMenu::GuiSettingsMenu(Window* window) : GuiComponent(window),
|
||||
mList(window, Eigen::Vector2i(2, 6)),
|
||||
mList(window, Eigen::Vector2i(2, 7)),
|
||||
mBox(mWindow, ":/frame.png", 0x444444FF),
|
||||
mDrawFramerateSwitch(window),
|
||||
mVolumeSlider(window, 0, 100, 1),
|
||||
mVolumeSlider(window, 0, 100, 1, "%"),
|
||||
mDisableSoundsSwitch(window, false),
|
||||
mScraperOptList(window),
|
||||
mScrapeRatingsSwitch(window),
|
||||
mDimSlider(window, 0, 60, 1, "s"),
|
||||
mSaveButton(window)
|
||||
{
|
||||
loadStates();
|
||||
|
@ -80,10 +81,20 @@ GuiSettingsMenu::GuiSettingsMenu(Window* window) : GuiComponent(window),
|
|||
|
||||
mList.setEntry(Vector2i(1, 4), Vector2i(1, 1), &mScrapeRatingsSwitch, true, ComponentListComponent::AlignCenter);
|
||||
|
||||
// dim time label
|
||||
label = new TextComponent(mWindow);
|
||||
label->setText("Dim after: ");
|
||||
label->setColor(0x0000FFFF);
|
||||
mLabels.push_back(label);
|
||||
mList.setEntry(Vector2i(0, 5), Vector2i(1, 1), label, false, ComponentListComponent::AlignRight);
|
||||
|
||||
// dim slider
|
||||
mList.setEntry(Vector2i(1, 5), Vector2i(1, 1), &mDimSlider, true, ComponentListComponent::AlignCenter);
|
||||
|
||||
//save button
|
||||
mSaveButton.setText("SAVE", 0x00FF00FF);
|
||||
mSaveButton.setPressedFunc([this] () { applyStates(); delete this; });
|
||||
mList.setEntry(Vector2i(0, 5), Vector2i(2, 1), &mSaveButton, true, ComponentListComponent::AlignCenter, Matrix<bool, 1, 2>(false, true));
|
||||
mList.setEntry(Vector2i(0, 6), Vector2i(2, 1), &mSaveButton, true, ComponentListComponent::AlignCenter, Matrix<bool, 1, 2>(false, true));
|
||||
|
||||
//center list
|
||||
mList.setPosition(Renderer::getScreenWidth() / 2 - mList.getSize().x() / 2, Renderer::getScreenHeight() / 2 - mList.getSize().y() / 2);
|
||||
|
@ -126,6 +137,8 @@ void GuiSettingsMenu::loadStates()
|
|||
mDisableSoundsSwitch.setState(s->getBool("DISABLESOUNDS"));
|
||||
|
||||
mScrapeRatingsSwitch.setState(s->getBool("ScrapeRatings"));
|
||||
|
||||
mDimSlider.setValue((float)(s->getInt("DIMTIME") / 1000));
|
||||
}
|
||||
|
||||
void GuiSettingsMenu::applyStates()
|
||||
|
@ -142,5 +155,7 @@ void GuiSettingsMenu::applyStates()
|
|||
|
||||
s->setBool("ScrapeRatings", mScrapeRatingsSwitch.getState());
|
||||
|
||||
s->setInt("DIMTIME", (int)(mDimSlider.getValue() * 1000));
|
||||
|
||||
s->saveFile();
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ private:
|
|||
SwitchComponent mDisableSoundsSwitch;
|
||||
OptionListComponent< std::shared_ptr<Scraper> > mScraperOptList;
|
||||
SwitchComponent mScrapeRatingsSwitch;
|
||||
SliderComponent mDimSlider;
|
||||
ButtonComponent mSaveButton;
|
||||
|
||||
std::vector<GuiComponent*> mLabels;
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#include "SliderComponent.h"
|
||||
#include <assert.h>
|
||||
#include "../Renderer.h"
|
||||
#include "../resources/Font.h"
|
||||
#include "../Log.h"
|
||||
|
||||
SliderComponent::SliderComponent(Window* window, float min, float max, float increment) : GuiComponent(window),
|
||||
mMin(min), mMax(max), mIncrement(increment), mMoveRate(0), mRepeatWaitTimer(0)
|
||||
SliderComponent::SliderComponent(Window* window, float min, float max, float increment, const std::string& suffix) : GuiComponent(window),
|
||||
mMin(min), mMax(max), mIncrement(increment), mMoveRate(0), mRepeatWaitTimer(0), mSuffix(suffix)
|
||||
{
|
||||
assert((min - max) != 0);
|
||||
|
||||
|
@ -12,7 +14,7 @@ SliderComponent::SliderComponent(Window* window, float min, float max, float inc
|
|||
//calculate move scale
|
||||
mMoveScale = ((max - min) * 0.0007f) / increment;
|
||||
|
||||
setSize(128, 32);
|
||||
setSize(196, 32);
|
||||
}
|
||||
|
||||
bool SliderComponent::input(InputConfig* config, Input input)
|
||||
|
@ -58,6 +60,8 @@ void SliderComponent::update(int deltaTime)
|
|||
if(mValue > mMax)
|
||||
mValue = mMax;
|
||||
|
||||
onValueChanged();
|
||||
|
||||
if(mRepeatWaitTimer < 450)
|
||||
mRepeatWaitTimer += deltaTime;
|
||||
}
|
||||
|
@ -70,30 +74,71 @@ void SliderComponent::render(const Eigen::Affine3f& parentTrans)
|
|||
Eigen::Affine3f trans = parentTrans * getTransform();
|
||||
Renderer::setMatrix(trans);
|
||||
|
||||
float width = mSize.x() - (mValueCache ? mValueCache->metrics.size.x() + 4 : 0);
|
||||
|
||||
//render line
|
||||
const int lineWidth = 2;
|
||||
Renderer::drawRect(0, (int)mSize.y() / 2 - lineWidth / 2, (int)mSize.x(), lineWidth, 0x000000CC);
|
||||
Renderer::drawRect(0, (int)mSize.y() / 2 - lineWidth / 2, (int)width, lineWidth, 0x000000CC);
|
||||
|
||||
//render left end
|
||||
const int capWidth = (int)(mSize.x() * 0.03f);
|
||||
Renderer::drawRect(0, 0, capWidth, (int)mSize.y(), 0x000000CC);
|
||||
|
||||
//render right end
|
||||
Renderer::drawRect((int)mSize.x() - capWidth, 0, capWidth, (int)mSize.y(), 0x000000CC);
|
||||
Renderer::drawRect((int)width - capWidth, 0, capWidth, (int)mSize.y(), 0x000000CC);
|
||||
|
||||
//render our value
|
||||
const int lineLength = (int)mSize.x() - capWidth;
|
||||
const int lineLength = (int)width - capWidth;
|
||||
Renderer::drawRect((int)(((mValue + mMin) / mMax) * lineLength), 0, capWidth, (int)mSize.y(), 0x0000FFFF);
|
||||
|
||||
// suffix
|
||||
if(mValueCache)
|
||||
mFont->renderTextCache(mValueCache.get());
|
||||
|
||||
GuiComponent::renderChildren(trans);
|
||||
}
|
||||
|
||||
void SliderComponent::setValue(float value)
|
||||
{
|
||||
mValue = value;
|
||||
onValueChanged();
|
||||
}
|
||||
|
||||
float SliderComponent::getValue()
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
|
||||
void SliderComponent::onSizeChanged()
|
||||
{
|
||||
if(!mSuffix.empty())
|
||||
{
|
||||
mFont = Font::get((int)(mSize.y() * 0.7f));
|
||||
onValueChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void SliderComponent::onValueChanged()
|
||||
{
|
||||
if(mFont)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << std::fixed;
|
||||
ss.precision(0);
|
||||
ss << mValue;
|
||||
ss << mSuffix;
|
||||
const std::string val = ss.str();
|
||||
|
||||
ss.str("");
|
||||
ss.clear();
|
||||
ss << std::fixed;
|
||||
ss.precision(0);
|
||||
ss << mMax;
|
||||
ss << mSuffix;
|
||||
const std::string max = ss.str();
|
||||
|
||||
float w = mFont->sizeText(max).x();
|
||||
mValueCache = std::shared_ptr<TextCache>(mFont->buildTextCache(val, mSize.x() - w, 0, 0x000000FF));
|
||||
mValueCache->metrics.size[0] = w; // fudge the width
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,14 @@
|
|||
|
||||
#include "../GuiComponent.h"
|
||||
|
||||
class TextCache;
|
||||
class Font;
|
||||
|
||||
class SliderComponent : public GuiComponent
|
||||
{
|
||||
public:
|
||||
//Minimum value (far left of the slider), maximum value (far right of the slider), increment size (how much just pressing L/R moves by).
|
||||
SliderComponent(Window* window, float min, float max, float increment);
|
||||
//Minimum value (far left of the slider), maximum value (far right of the slider), increment size (how much just pressing L/R moves by), unit to display (optional).
|
||||
SliderComponent(Window* window, float min, float max, float increment, const std::string& suffix = "");
|
||||
|
||||
void setValue(float val);
|
||||
float getValue();
|
||||
|
@ -15,12 +18,20 @@ public:
|
|||
void update(int deltaTime) override;
|
||||
void render(const Eigen::Affine3f& parentTrans) override;
|
||||
|
||||
void onSizeChanged() override;
|
||||
|
||||
private:
|
||||
void onValueChanged();
|
||||
|
||||
float mMin, mMax;
|
||||
float mValue;
|
||||
float mIncrement;
|
||||
float mMoveScale;
|
||||
int mRepeatWaitTimer;
|
||||
|
||||
std::string mSuffix;
|
||||
std::shared_ptr<Font> mFont;
|
||||
std::shared_ptr<TextCache> mValueCache;
|
||||
|
||||
float mMoveRate;
|
||||
};
|
||||
|
|
|
@ -38,8 +38,8 @@ void DetailedGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& them
|
|||
mHeaderImage.setResize(mSize.x() * 0.5f, 0, true);
|
||||
BasicGameListView::onThemeChanged(theme);
|
||||
|
||||
if(mHeaderImage.getPosition().y() + mHeaderImage.getSize().y() > mImage.getPosition().y())
|
||||
mHeaderImage.setResize(0, mSize.y() * 0.185f, true);
|
||||
//if(mHeaderImage.getPosition().y() + mHeaderImage.getSize().y() > mImage.getPosition().y())
|
||||
// mHeaderImage.setResize(0, mSize.y() * 0.185f, true);
|
||||
|
||||
using namespace ThemeFlags;
|
||||
mImage.applyTheme(theme, getName(), "gameimage", POSITION | ThemeFlags::SIZE);
|
||||
|
|
Loading…
Reference in a new issue