From 5f55288495c293551d1f46dccf82c903f99fce2c Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sat, 22 Mar 2014 16:55:18 -0500 Subject: [PATCH] Fixed SVGs being cut off by scaling based on height instead of width. Fixed buttons not being quite vertically centered. Hooked up new switch graphics. Updated slider logic to only move in multiples of the specified increment. --- data/converted/slider_knob_png.cpp | 121 ----------------------------- src/components/MenuComponent.cpp | 7 +- src/components/SliderComponent.cpp | 51 ++++++------ src/components/SliderComponent.h | 8 +- src/components/SwitchComponent.cpp | 9 ++- src/components/SwitchComponent.h | 1 + src/guis/GuiMenu.cpp | 6 +- src/resources/SVGResource.cpp | 2 +- 8 files changed, 41 insertions(+), 164 deletions(-) delete mode 100644 data/converted/slider_knob_png.cpp diff --git a/data/converted/slider_knob_png.cpp b/data/converted/slider_knob_png.cpp deleted file mode 100644 index 26dc7a4ca..000000000 --- a/data/converted/slider_knob_png.cpp +++ /dev/null @@ -1,121 +0,0 @@ -//this file was auto-generated from "slider_knob.png" by res2h - -#include "../Resources.h" - -const size_t slider_knob_png_size = 1140; -const unsigned char slider_knob_png_data[1140] = { - 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00, - 0x00,0x0d,0x49,0x48,0x44,0x52,0x00,0x00,0x00,0x10, - 0x00,0x00,0x00,0x10,0x08,0x06,0x00,0x00,0x00,0x1f, - 0xf3,0xff,0x61,0x00,0x00,0x00,0x19,0x74,0x45,0x58, - 0x74,0x53,0x6f,0x66,0x74,0x77,0x61,0x72,0x65,0x00, - 0x41,0x64,0x6f,0x62,0x65,0x20,0x49,0x6d,0x61,0x67, - 0x65,0x52,0x65,0x61,0x64,0x79,0x71,0xc9,0x65,0x3c, - 0x00,0x00,0x03,0x24,0x69,0x54,0x58,0x74,0x58,0x4d, - 0x4c,0x3a,0x63,0x6f,0x6d,0x2e,0x61,0x64,0x6f,0x62, - 0x65,0x2e,0x78,0x6d,0x70,0x00,0x00,0x00,0x00,0x00, - 0x3c,0x3f,0x78,0x70,0x61,0x63,0x6b,0x65,0x74,0x20, - 0x62,0x65,0x67,0x69,0x6e,0x3d,0x22,0xef,0xbb,0xbf, - 0x22,0x20,0x69,0x64,0x3d,0x22,0x57,0x35,0x4d,0x30, - 0x4d,0x70,0x43,0x65,0x68,0x69,0x48,0x7a,0x72,0x65, - 0x53,0x7a,0x4e,0x54,0x63,0x7a,0x6b,0x63,0x39,0x64, - 0x22,0x3f,0x3e,0x20,0x3c,0x78,0x3a,0x78,0x6d,0x70, - 0x6d,0x65,0x74,0x61,0x20,0x78,0x6d,0x6c,0x6e,0x73, - 0x3a,0x78,0x3d,0x22,0x61,0x64,0x6f,0x62,0x65,0x3a, - 0x6e,0x73,0x3a,0x6d,0x65,0x74,0x61,0x2f,0x22,0x20, - 0x78,0x3a,0x78,0x6d,0x70,0x74,0x6b,0x3d,0x22,0x41, - 0x64,0x6f,0x62,0x65,0x20,0x58,0x4d,0x50,0x20,0x43, - 0x6f,0x72,0x65,0x20,0x35,0x2e,0x33,0x2d,0x63,0x30, - 0x31,0x31,0x20,0x36,0x36,0x2e,0x31,0x34,0x35,0x36, - 0x36,0x31,0x2c,0x20,0x32,0x30,0x31,0x32,0x2f,0x30, - 0x32,0x2f,0x30,0x36,0x2d,0x31,0x34,0x3a,0x35,0x36, - 0x3a,0x32,0x37,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x22,0x3e,0x20,0x3c,0x72,0x64,0x66,0x3a,0x52, - 0x44,0x46,0x20,0x78,0x6d,0x6c,0x6e,0x73,0x3a,0x72, - 0x64,0x66,0x3d,0x22,0x68,0x74,0x74,0x70,0x3a,0x2f, - 0x2f,0x77,0x77,0x77,0x2e,0x77,0x33,0x2e,0x6f,0x72, - 0x67,0x2f,0x31,0x39,0x39,0x39,0x2f,0x30,0x32,0x2f, - 0x32,0x32,0x2d,0x72,0x64,0x66,0x2d,0x73,0x79,0x6e, - 0x74,0x61,0x78,0x2d,0x6e,0x73,0x23,0x22,0x3e,0x20, - 0x3c,0x72,0x64,0x66,0x3a,0x44,0x65,0x73,0x63,0x72, - 0x69,0x70,0x74,0x69,0x6f,0x6e,0x20,0x72,0x64,0x66, - 0x3a,0x61,0x62,0x6f,0x75,0x74,0x3d,0x22,0x22,0x20, - 0x78,0x6d,0x6c,0x6e,0x73,0x3a,0x78,0x6d,0x70,0x3d, - 0x22,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x6e,0x73, - 0x2e,0x61,0x64,0x6f,0x62,0x65,0x2e,0x63,0x6f,0x6d, - 0x2f,0x78,0x61,0x70,0x2f,0x31,0x2e,0x30,0x2f,0x22, - 0x20,0x78,0x6d,0x6c,0x6e,0x73,0x3a,0x78,0x6d,0x70, - 0x4d,0x4d,0x3d,0x22,0x68,0x74,0x74,0x70,0x3a,0x2f, - 0x2f,0x6e,0x73,0x2e,0x61,0x64,0x6f,0x62,0x65,0x2e, - 0x63,0x6f,0x6d,0x2f,0x78,0x61,0x70,0x2f,0x31,0x2e, - 0x30,0x2f,0x6d,0x6d,0x2f,0x22,0x20,0x78,0x6d,0x6c, - 0x6e,0x73,0x3a,0x73,0x74,0x52,0x65,0x66,0x3d,0x22, - 0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x6e,0x73,0x2e, - 0x61,0x64,0x6f,0x62,0x65,0x2e,0x63,0x6f,0x6d,0x2f, - 0x78,0x61,0x70,0x2f,0x31,0x2e,0x30,0x2f,0x73,0x54, - 0x79,0x70,0x65,0x2f,0x52,0x65,0x73,0x6f,0x75,0x72, - 0x63,0x65,0x52,0x65,0x66,0x23,0x22,0x20,0x78,0x6d, - 0x70,0x3a,0x43,0x72,0x65,0x61,0x74,0x6f,0x72,0x54, - 0x6f,0x6f,0x6c,0x3d,0x22,0x41,0x64,0x6f,0x62,0x65, - 0x20,0x50,0x68,0x6f,0x74,0x6f,0x73,0x68,0x6f,0x70, - 0x20,0x43,0x53,0x36,0x20,0x28,0x4d,0x61,0x63,0x69, - 0x6e,0x74,0x6f,0x73,0x68,0x29,0x22,0x20,0x78,0x6d, - 0x70,0x4d,0x4d,0x3a,0x49,0x6e,0x73,0x74,0x61,0x6e, - 0x63,0x65,0x49,0x44,0x3d,0x22,0x78,0x6d,0x70,0x2e, - 0x69,0x69,0x64,0x3a,0x36,0x46,0x44,0x45,0x41,0x33, - 0x43,0x34,0x39,0x44,0x38,0x41,0x31,0x31,0x45,0x33, - 0x41,0x39,0x31,0x44,0x42,0x44,0x46,0x44,0x34,0x30, - 0x39,0x39,0x32,0x45,0x45,0x33,0x22,0x20,0x78,0x6d, - 0x70,0x4d,0x4d,0x3a,0x44,0x6f,0x63,0x75,0x6d,0x65, - 0x6e,0x74,0x49,0x44,0x3d,0x22,0x78,0x6d,0x70,0x2e, - 0x64,0x69,0x64,0x3a,0x36,0x46,0x44,0x45,0x41,0x33, - 0x43,0x35,0x39,0x44,0x38,0x41,0x31,0x31,0x45,0x33, - 0x41,0x39,0x31,0x44,0x42,0x44,0x46,0x44,0x34,0x30, - 0x39,0x39,0x32,0x45,0x45,0x33,0x22,0x3e,0x20,0x3c, - 0x78,0x6d,0x70,0x4d,0x4d,0x3a,0x44,0x65,0x72,0x69, - 0x76,0x65,0x64,0x46,0x72,0x6f,0x6d,0x20,0x73,0x74, - 0x52,0x65,0x66,0x3a,0x69,0x6e,0x73,0x74,0x61,0x6e, - 0x63,0x65,0x49,0x44,0x3d,0x22,0x78,0x6d,0x70,0x2e, - 0x69,0x69,0x64,0x3a,0x33,0x42,0x37,0x42,0x36,0x33, - 0x37,0x46,0x39,0x44,0x38,0x38,0x31,0x31,0x45,0x33, - 0x41,0x39,0x31,0x44,0x42,0x44,0x46,0x44,0x34,0x30, - 0x39,0x39,0x32,0x45,0x45,0x33,0x22,0x20,0x73,0x74, - 0x52,0x65,0x66,0x3a,0x64,0x6f,0x63,0x75,0x6d,0x65, - 0x6e,0x74,0x49,0x44,0x3d,0x22,0x78,0x6d,0x70,0x2e, - 0x64,0x69,0x64,0x3a,0x33,0x42,0x37,0x42,0x36,0x33, - 0x38,0x30,0x39,0x44,0x38,0x38,0x31,0x31,0x45,0x33, - 0x41,0x39,0x31,0x44,0x42,0x44,0x46,0x44,0x34,0x30, - 0x39,0x39,0x32,0x45,0x45,0x33,0x22,0x2f,0x3e,0x20, - 0x3c,0x2f,0x72,0x64,0x66,0x3a,0x44,0x65,0x73,0x63, - 0x72,0x69,0x70,0x74,0x69,0x6f,0x6e,0x3e,0x20,0x3c, - 0x2f,0x72,0x64,0x66,0x3a,0x52,0x44,0x46,0x3e,0x20, - 0x3c,0x2f,0x78,0x3a,0x78,0x6d,0x70,0x6d,0x65,0x74, - 0x61,0x3e,0x20,0x3c,0x3f,0x78,0x70,0x61,0x63,0x6b, - 0x65,0x74,0x20,0x65,0x6e,0x64,0x3d,0x22,0x72,0x22, - 0x3f,0x3e,0x1b,0x1b,0x31,0x47,0x00,0x00,0x00,0xe6, - 0x49,0x44,0x41,0x54,0x78,0xda,0xa4,0x93,0x4d,0x0a, - 0xc2,0x30,0x10,0x46,0x63,0x14,0xc5,0x63,0x58,0x10, - 0xfc,0x01,0xbd,0x83,0xb8,0xa8,0xe8,0x31,0x0a,0xba, - 0x70,0xe3,0xaa,0xb7,0x50,0x0a,0x0a,0x0a,0xf5,0x18, - 0x82,0x8b,0xe2,0x25,0xac,0x82,0x9b,0x82,0x87,0x10, - 0xa1,0x62,0xf1,0x1b,0x99,0x48,0x74,0x51,0x6c,0x3a, - 0xf0,0xa0,0x4c,0xfb,0xbe,0x84,0x74,0x52,0x70,0x5d, - 0x57,0xfc,0x54,0x0b,0x38,0x60,0x00,0x6a,0xdc,0x8b, - 0xc0,0x1e,0xf8,0xe0,0xac,0x7f,0x2c,0xb5,0xe7,0x32, - 0x58,0x82,0x23,0x98,0x81,0x06,0xa8,0x30,0x4d,0xee, - 0xd1,0xbb,0x35,0xa8,0x2a,0xa9,0xa4,0xc9,0x3b,0xd0, - 0x17,0xe9,0x45,0x0b,0x8e,0x41,0x9d,0x77,0x18,0xab, - 0x1d,0x2c,0xfe,0x90,0xf5,0xea,0x81,0xb9,0x4a,0x6c, - 0x73,0x6a,0xd6,0x9a,0x90,0x2b,0xf9,0xc0,0x8a,0x06, - 0x01,0xe4,0x38,0x14,0x60,0x0b,0xf3,0xb2,0x29,0xc0, - 0xca,0x11,0x60,0x49,0x91,0xaf,0xde,0x7f,0x21,0xca, - 0x11,0x70,0x95,0x3c,0x61,0xa6,0x15,0x50,0xc0,0x16, - 0x3c,0x0d,0x64,0x72,0x7c,0x0a,0x08,0xc1,0xc6,0x20, - 0x80,0x9c,0x50,0x1d,0x22,0xcd,0x79,0x90,0x41,0x3e, - 0xb0,0xf3,0xb9,0x4c,0x31,0x18,0x82,0x15,0x48,0x52, - 0xc4,0x84,0x57,0x1e,0xb1,0xf3,0x75,0x1b,0xa9,0x31, - 0x05,0x1d,0xe0,0x81,0x0b,0x78,0x80,0x1b,0x38,0x71, - 0xaf,0xcb,0x23,0x7c,0x57,0xd2,0x4b,0x80,0x01,0x00, - 0x3d,0x15,0x2b,0x10,0xc1,0x8a,0x11,0x59,0x00,0x00, - 0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 -}; diff --git a/src/components/MenuComponent.cpp b/src/components/MenuComponent.cpp index 01d5c72ae..3deddd040 100644 --- a/src/components/MenuComponent.cpp +++ b/src/components/MenuComponent.cpp @@ -81,7 +81,7 @@ std::vector MenuComponent::getHelpPrompts() std::shared_ptr makeButtonGrid(Window* window, const std::vector< std::shared_ptr >& buttons) { - std::shared_ptr buttonGrid = std::make_shared(window, Vector2i(buttons.size(), 1)); + std::shared_ptr buttonGrid = std::make_shared(window, Vector2i(buttons.size(), 2)); float buttonGridWidth = (float)BUTTON_GRID_HORIZ_PADDING * buttons.size(); // initialize to padding for(int i = 0; i < (int)buttons.size(); i++) @@ -93,8 +93,9 @@ std::shared_ptr makeButtonGrid(Window* window, const std::vector< { buttonGrid->setColWidthPerc(i, (buttons.at(i)->getSize().x() + BUTTON_GRID_HORIZ_PADDING) / buttonGridWidth); } - - buttonGrid->setSize(buttonGridWidth, buttons.at(0)->getSize().y() + BUTTON_GRID_VERT_PADDING); + + buttonGrid->setSize(buttonGridWidth, buttons.at(0)->getSize().y() + BUTTON_GRID_VERT_PADDING + 2); + buttonGrid->setRowHeightPerc(1, 2 / buttonGrid->getSize().y()); // spacer row to deal with dropshadow to make buttons look centered return buttonGrid; } diff --git a/src/components/SliderComponent.cpp b/src/components/SliderComponent.cpp index 76d374d78..78dc0468b 100644 --- a/src/components/SliderComponent.cpp +++ b/src/components/SliderComponent.cpp @@ -5,16 +5,17 @@ #include "../Log.h" #include "../Util.h" +#define MOVE_REPEAT_DELAY 500 +#define MOVE_REPEAT_RATE 40 + 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), mKnob(window), mSuffix(suffix) + mMin(min), mMax(max), mSingleIncrement(increment), mMoveRate(0), mKnob(window), mSuffix(suffix) { assert((min - max) != 0); + // some sane default value mValue = (max + min) / 2; - //calculate move scale - mMoveScale = ((max - min) * 0.0007f) / increment; - mKnob.setOrigin(0.5f, 0.5f); mKnob.setImage(":/slider_knob.svg"); @@ -26,24 +27,19 @@ bool SliderComponent::input(InputConfig* config, Input input) if(config->isMappedTo("left", input)) { if(input.value) - mMoveRate = -mIncrement; - else - mMoveRate = 0; - - //setting mRepeatWaitTimer to 0 will trigger an initial move in our update method - mRepeatWaitTimer = 0; + setValue(mValue - mSingleIncrement); + mMoveRate = input.value ? -mSingleIncrement : 0; + mMoveAccumulator = -MOVE_REPEAT_DELAY; return true; } if(config->isMappedTo("right", input)) { if(input.value) - mMoveRate = mIncrement; - else - mMoveRate = 0; - - mRepeatWaitTimer = 0; + setValue(mValue + mSingleIncrement); + mMoveRate = input.value ? mSingleIncrement : 0; + mMoveAccumulator = -MOVE_REPEAT_DELAY; return true; } @@ -54,20 +50,12 @@ void SliderComponent::update(int deltaTime) { if(mMoveRate != 0) { - if(mRepeatWaitTimer == 0) - mValue += mMoveRate; - else if(mRepeatWaitTimer >= 450) - mValue += mMoveRate * deltaTime * mMoveScale; - - if(mValue < mMin) - mValue = mMin; - if(mValue > mMax) - mValue = mMax; - - onValueChanged(); - - if(mRepeatWaitTimer < 450) - mRepeatWaitTimer += deltaTime; + mMoveAccumulator += deltaTime; + while(mMoveAccumulator >= MOVE_REPEAT_RATE) + { + setValue(mValue + mMoveRate); + mMoveAccumulator -= MOVE_REPEAT_RATE; + } } GuiComponent::update(deltaTime); @@ -97,6 +85,11 @@ void SliderComponent::render(const Eigen::Affine3f& parentTrans) void SliderComponent::setValue(float value) { mValue = value; + if(value < mMin) + value = mMin; + else if(value > mMax) + value = mMax; + onValueChanged(); } diff --git a/src/components/SliderComponent.h b/src/components/SliderComponent.h index efdd81999..fc0d7ea68 100644 --- a/src/components/SliderComponent.h +++ b/src/components/SliderComponent.h @@ -29,15 +29,13 @@ private: float mMin, mMax; float mValue; - float mIncrement; - float mMoveScale; - int mRepeatWaitTimer; + float mSingleIncrement; + float mMoveRate; + int mMoveAccumulator; ImageComponent mKnob; std::string mSuffix; std::shared_ptr mFont; std::shared_ptr mValueCache; - - float mMoveRate; }; diff --git a/src/components/SwitchComponent.cpp b/src/components/SwitchComponent.cpp index 97536351c..c6fdf61f0 100644 --- a/src/components/SwitchComponent.cpp +++ b/src/components/SwitchComponent.cpp @@ -5,11 +5,16 @@ SwitchComponent::SwitchComponent(Window* window, bool state) : GuiComponent(window), mImage(window), mState(state) { - mImage.setImage(":/checkbox_unchecked.svg"); + mImage.setImage(":/off.svg"); mImage.setResize(0, Font::get(FONT_SIZE_MEDIUM)->getLetterHeight()); mSize = mImage.getSize(); } +void SwitchComponent::onSizeChanged() +{ + mImage.setSize(mSize); +} + bool SwitchComponent::input(InputConfig* config, Input input) { if(config->isMappedTo("a", input) && input.value) @@ -44,7 +49,7 @@ void SwitchComponent::setState(bool state) void SwitchComponent::onStateChanged() { - mImage.setImage(mState ? ":/checkbox_checked.svg" : ":/checkbox_unchecked.svg"); + mImage.setImage(mState ? ":/on.svg" : ":/off.svg"); } std::vector SwitchComponent::getHelpPrompts() diff --git a/src/components/SwitchComponent.h b/src/components/SwitchComponent.h index 14c994808..cb267f8dc 100644 --- a/src/components/SwitchComponent.h +++ b/src/components/SwitchComponent.h @@ -12,6 +12,7 @@ public: bool input(InputConfig* config, Input input) override; void render(const Eigen::Affine3f& parentTrans) override; + void onSizeChanged() override; bool getState() const; void setState(bool state); diff --git a/src/guis/GuiMenu.cpp b/src/guis/GuiMenu.cpp index f0a819a9e..a67544567 100644 --- a/src/guis/GuiMenu.cpp +++ b/src/guis/GuiMenu.cpp @@ -89,10 +89,10 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN auto s = new GuiSettings(mWindow, "UI SETTINGS"); // dim time - auto dim_time = std::make_shared(mWindow, 0.f, 1200.f, 30.f, "s"); - dim_time->setValue((float)(Settings::getInstance()->getInt("DimTime") / 1000)); + auto dim_time = std::make_shared(mWindow, 0.f, 30.f, 1.f, "m"); + dim_time->setValue((float)(Settings::getInstance()->getInt("DimTime") / (1000 * 60))); s->addWithLabel("DIM SCREEN AFTER", dim_time); - s->addSaveFunc([dim_time] { Settings::getInstance()->setInt("DimTime", (int)(dim_time->getValue() * 1000)); }); + s->addSaveFunc([dim_time] { Settings::getInstance()->setInt("DimTime", (int)round(dim_time->getValue()) * (1000 * 60)); }); // framerate auto framerate = std::make_shared(mWindow); diff --git a/src/resources/SVGResource.cpp b/src/resources/SVGResource.cpp index f11bbdfbe..39ece9e51 100644 --- a/src/resources/SVGResource.cpp +++ b/src/resources/SVGResource.cpp @@ -51,7 +51,7 @@ void SVGResource::rasterizeAt(size_t width, size_t height) unsigned char* imagePx = (unsigned char*)malloc(width * height * 4); NSVGrasterizer* rast = nsvgCreateRasterizer(); - nsvgRasterize(rast, mSVGImage, 0, 0, width / mSVGImage->width, imagePx, width, height, width * 4); + nsvgRasterize(rast, mSVGImage, 0, 0, height / mSVGImage->height, imagePx, width, height, width * 4); nsvgDeleteRasterizer(rast); // flip the pixels