New slider art.

This commit is contained in:
Aloshi 2014-03-07 18:16:08 -06:00
parent 5da0f01472
commit 076131f35c
7 changed files with 167 additions and 33 deletions

View file

@ -311,6 +311,7 @@ set(ES_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/data/converted/arrow_png.cpp
${CMAKE_CURRENT_SOURCE_DIR}/data/converted/checkbox_checked_png.cpp
${CMAKE_CURRENT_SOURCE_DIR}/data/converted/checkbox_unchecked_png.cpp
${CMAKE_CURRENT_SOURCE_DIR}/data/converted/slider_knob_png.cpp
)
SOURCE_GROUP(resources FILES ResourceUtil.cpp)

View file

@ -2,7 +2,7 @@
#include "Resources.h"
const size_t res2hNrOfFiles = 20;
const size_t res2hNrOfFiles = 21;
const Res2hEntry res2hFiles[res2hNrOfFiles] = {
{":/arrow.png", arrow_png_size, arrow_png_data},
{":/button.png", button_png_size, button_png_data},
@ -13,6 +13,7 @@ const Res2hEntry res2hFiles[res2hNrOfFiles] = {
{":/frame.png", frame_png_size, frame_png_data},
{":/opensans_hebrew_condensed_regular.ttf", opensans_hebrew_condensed_regular_ttf_size, opensans_hebrew_condensed_regular_ttf_data},
{":/scroll_gradient.png", scroll_gradient_png_size, scroll_gradient_png_data},
{":/slider_knob.png", slider_knob_png_size, slider_knob_png_data},
{":/sq_bracket.png", sq_bracket_png_size, sq_bracket_png_data},
{":/star_filled.png", star_filled_png_size, star_filled_png_data},
{":/star_unfilled.png", star_unfilled_png_size, star_unfilled_png_data},
@ -36,17 +37,18 @@ res2hMapType::value_type mapTemp[] = {
std::make_pair(":/frame.png", res2hFiles[6]),
std::make_pair(":/opensans_hebrew_condensed_regular.ttf", res2hFiles[7]),
std::make_pair(":/scroll_gradient.png", res2hFiles[8]),
std::make_pair(":/sq_bracket.png", res2hFiles[9]),
std::make_pair(":/star_filled.png", res2hFiles[10]),
std::make_pair(":/star_unfilled.png", res2hFiles[11]),
std::make_pair(":/textbox.png", res2hFiles[12]),
std::make_pair(":/textbox_glow.png", res2hFiles[13]),
std::make_pair(":/help/a.png", res2hFiles[14]),
std::make_pair(":/help/b.png", res2hFiles[15]),
std::make_pair(":/help/dpad.png", res2hFiles[16]),
std::make_pair(":/help/left_right.png", res2hFiles[17]),
std::make_pair(":/help/menu.png", res2hFiles[18]),
std::make_pair(":/help/up_down.png", res2hFiles[19])
std::make_pair(":/slider_knob.png", res2hFiles[9]),
std::make_pair(":/sq_bracket.png", res2hFiles[10]),
std::make_pair(":/star_filled.png", res2hFiles[11]),
std::make_pair(":/star_unfilled.png", res2hFiles[12]),
std::make_pair(":/textbox.png", res2hFiles[13]),
std::make_pair(":/textbox_glow.png", res2hFiles[14]),
std::make_pair(":/help/a.png", res2hFiles[15]),
std::make_pair(":/help/b.png", res2hFiles[16]),
std::make_pair(":/help/dpad.png", res2hFiles[17]),
std::make_pair(":/help/left_right.png", res2hFiles[18]),
std::make_pair(":/help/menu.png", res2hFiles[19]),
std::make_pair(":/help/up_down.png", res2hFiles[20])
};
res2hMapType res2hMap(mapTemp, mapTemp + sizeof mapTemp / sizeof mapTemp[0]);

View file

@ -32,6 +32,9 @@ extern const unsigned char opensans_hebrew_condensed_regular_ttf_data[];
extern const size_t scroll_gradient_png_size;
extern const unsigned char scroll_gradient_png_data[];
extern const size_t slider_knob_png_size;
extern const unsigned char slider_knob_png_data[];
extern const size_t sq_bracket_png_size;
extern const unsigned char sq_bracket_png_data[];

View file

@ -0,0 +1,121 @@
//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
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -5,7 +5,7 @@
#include "../Log.h"
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)
mMin(min), mMax(max), mIncrement(increment), mMoveRate(0), mRepeatWaitTimer(0), mKnob(window), mSuffix(suffix)
{
assert((min - max) != 0);
@ -14,6 +14,9 @@ SliderComponent::SliderComponent(Window* window, float min, float max, float inc
//calculate move scale
mMoveScale = ((max - min) * 0.0007f) / increment;
mKnob.setOrigin(0.5f, 0.5f);
mKnob.setImage(":/slider_knob.png");
setSize(196, 32);
}
@ -74,26 +77,18 @@ 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 suffix
if(mValueCache)
mFont->renderTextCache(mValueCache.get());
float width = mSize.x() - mKnob.getSize().x() - (mValueCache ? mValueCache->metrics.size.x() + 4 : 0);
//render line
const int lineWidth = 2;
Renderer::drawRect(0, (int)mSize.y() / 2 - lineWidth / 2, (int)width, lineWidth, 0x000000CC);
Renderer::drawRect((int)mKnob.getSize().x() / 2, (int)mSize.y() / 2 - lineWidth / 2, (int)width, lineWidth, 0x777777FF);
//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)width - capWidth, 0, capWidth, (int)mSize.y(), 0x000000CC);
//render our value
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());
//render knob
mKnob.render(trans);
GuiComponent::renderChildren(trans);
}
@ -112,14 +107,14 @@ float SliderComponent::getValue()
void SliderComponent::onSizeChanged()
{
if(!mSuffix.empty())
{
mFont = Font::get((int)(mSize.y() * 0.7f));
onValueChanged();
}
onValueChanged();
}
void SliderComponent::onValueChanged()
{
// update suffix textcache
if(mFont)
{
std::stringstream ss;
@ -138,9 +133,18 @@ void SliderComponent::onValueChanged()
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 = std::shared_ptr<TextCache>(mFont->buildTextCache(val, mSize.x() - w, 0, 0x777777FF));
mValueCache->metrics.size[0] = w; // fudge the width
}
// update knob position/size
if(mKnob.getTextureSize().y() > mSize.y()) // only downscale
mKnob.setResize(0, mSize.y());
else
mKnob.setResize(0, 0);
float lineLength = mSize.x() - mKnob.getSize().x() - (mValueCache ? mValueCache->metrics.size.x() + 4 : 0);
mKnob.setPosition(((mValue + mMin) / mMax) * lineLength + mKnob.getSize().x()/2, mSize.y() / 2);
}
std::vector<HelpPrompt> SliderComponent::getHelpPrompts()

View file

@ -1,6 +1,7 @@
#pragma once
#include "../GuiComponent.h"
#include "ImageComponent.h"
class TextCache;
class Font;
@ -32,6 +33,8 @@ private:
float mMoveScale;
int mRepeatWaitTimer;
ImageComponent mKnob;
std::string mSuffix;
std::shared_ptr<Font> mFont;
std::shared_ptr<TextCache> mValueCache;