mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-21 21:55:38 +00:00
Work on RatingComponent
This commit is contained in:
parent
08048945ba
commit
964d5afc56
|
@ -161,6 +161,7 @@ set(ES_HEADERS
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ComponentListComponent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ImageComponent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/NinePatchComponent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/RatingComponent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ScrollableContainer.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/SliderComponent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/SwitchComponent.h
|
||||
|
@ -213,6 +214,7 @@ set(ES_SOURCES
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ComponentListComponent.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ImageComponent.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/NinePatchComponent.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/RatingComponent.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ScrollableContainer.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/SliderComponent.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/components/SwitchComponent.cpp
|
||||
|
|
|
@ -28,6 +28,7 @@ GuiGameList::GuiGameList(Window* window) : GuiComponent(window),
|
|||
mList(window, 0.0f, 0.0f, Font::get(*window->getResourceManager(), Font::getDefaultPath(), FONT_SIZE_MEDIUM)),
|
||||
mScreenshot(window),
|
||||
mDescription(window),
|
||||
mRating(window),
|
||||
mDescContainer(window),
|
||||
mTransitionImage(window, 0.0f, 0.0f, "", (float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight(), true),
|
||||
mHeaderText(mWindow),
|
||||
|
@ -50,7 +51,8 @@ GuiGameList::GuiGameList(Window* window) : GuiComponent(window),
|
|||
}
|
||||
|
||||
mImageAnimation.addChild(&mScreenshot);
|
||||
mDescContainer.addChild(&mDescription);
|
||||
mDescContainer.addChild(&mRating);
|
||||
//mDescContainer.addChild(&mDescription);
|
||||
|
||||
//scale delay with screen width (higher width = more text per line)
|
||||
//the scroll speed is automatically scaled by component size
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "../GameData.h"
|
||||
#include "../FolderData.h"
|
||||
#include "ScrollableContainer.h"
|
||||
#include "RatingComponent.h"
|
||||
|
||||
//This is where the magic happens - GuiGameList is the parent of almost every graphical element in ES at the moment.
|
||||
//It has a TextListComponent child that handles the game list, a ThemeComponent that handles the theming system, and an ImageComponent for game images.
|
||||
|
@ -60,6 +61,7 @@ private:
|
|||
TextListComponent<FileData*> mList;
|
||||
ImageComponent mScreenshot;
|
||||
TextComponent mDescription;
|
||||
RatingComponent mRating;
|
||||
ScrollableContainer mDescContainer;
|
||||
AnimationComponent mImageAnimation;
|
||||
ThemeComponent* mTheme;
|
||||
|
|
93
src/components/RatingComponent.cpp
Normal file
93
src/components/RatingComponent.cpp
Normal file
|
@ -0,0 +1,93 @@
|
|||
#include "RatingComponent.h"
|
||||
#include "../Renderer.h"
|
||||
#include "../Window.h"
|
||||
|
||||
RatingComponent::RatingComponent(Window* window) : GuiComponent(window)
|
||||
{
|
||||
mFilledTexture = TextureResource::get(*window->getResourceManager(), ":/button.png");
|
||||
mUnfilledTexture = TextureResource::get(*window->getResourceManager(), ":/button.png");
|
||||
mValue = 0.5f;
|
||||
mSize << 64 * 5.0f, 64;
|
||||
updateVertices();
|
||||
}
|
||||
|
||||
void RatingComponent::setValue(const std::string& value)
|
||||
{
|
||||
mValue = stof(value);
|
||||
updateVertices();
|
||||
}
|
||||
|
||||
std::string RatingComponent::getValue() const
|
||||
{
|
||||
return std::to_string(mValue);
|
||||
}
|
||||
|
||||
void RatingComponent::onSizeChanged()
|
||||
{
|
||||
updateVertices();
|
||||
}
|
||||
|
||||
void RatingComponent::updateVertices()
|
||||
{
|
||||
const float numStars = 5.0f;
|
||||
|
||||
float h = getSize().y();
|
||||
float w = h * mValue * numStars;
|
||||
float fw = h * numStars;
|
||||
|
||||
mVertices[0].pos << 0, 0;
|
||||
mVertices[0].tex << 0, 0;
|
||||
mVertices[1].pos << w, h;
|
||||
mVertices[1].tex << mValue * numStars, 1.0f;
|
||||
mVertices[2].pos << 0, h;
|
||||
mVertices[2].tex << 0, 1.0f;
|
||||
|
||||
mVertices[3] = mVertices[0];
|
||||
mVertices[4].pos << w, 0;
|
||||
mVertices[5].tex << mValue * numStars, 0;
|
||||
mVertices[5] = mVertices[1];
|
||||
|
||||
mVertices[6] = mVertices[4];
|
||||
mVertices[7].pos << fw, h;
|
||||
mVertices[7].tex << numStars, 1.0f;
|
||||
mVertices[8] = mVertices[1];
|
||||
|
||||
mVertices[9] = mVertices[6];
|
||||
mVertices[10].pos << fw, 0;
|
||||
mVertices[10].tex << numStars, 0;
|
||||
mVertices[11] = mVertices[7];
|
||||
}
|
||||
|
||||
void RatingComponent::render(const Eigen::Affine3f& parentTrans)
|
||||
{
|
||||
Eigen::Affine3f trans = parentTrans * getTransform();
|
||||
Renderer::setMatrix(trans);
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
//glEnableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vertex), &mVertices[0].pos);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &mVertices[0].tex);
|
||||
//glColorPointer(4, GL_UNSIGNED_BYTE, 0, mColors);
|
||||
|
||||
mFilledTexture->bind();
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
mUnfilledTexture->bind();
|
||||
glDrawArrays(GL_TRIANGLES, 6, 6);
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
//glDisableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
renderChildren(trans);
|
||||
}
|
||||
|
31
src/components/RatingComponent.h
Normal file
31
src/components/RatingComponent.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
#include "../GuiComponent.h"
|
||||
#include "../resources/TextureResource.h"
|
||||
|
||||
class RatingComponent : public GuiComponent
|
||||
{
|
||||
public:
|
||||
RatingComponent(Window* window);
|
||||
|
||||
std::string getValue() const override;
|
||||
void setValue(const std::string& value) override;
|
||||
|
||||
void render(const Eigen::Affine3f& parentTrans);
|
||||
|
||||
void onSizeChanged() override;
|
||||
private:
|
||||
void updateVertices();
|
||||
|
||||
float mValue;
|
||||
|
||||
struct Vertex
|
||||
{
|
||||
Eigen::Vector2f pos;
|
||||
Eigen::Vector2f tex;
|
||||
} mVertices[12];
|
||||
|
||||
std::shared_ptr<TextureResource> mFilledTexture;
|
||||
std::shared_ptr<TextureResource> mUnfilledTexture;
|
||||
};
|
||||
|
Loading…
Reference in a new issue