Updated/added comments.

This commit is contained in:
Aloshi 2014-01-24 16:21:10 -06:00
parent 8eb9800127
commit 3ceeca968f
17 changed files with 101 additions and 46 deletions

View file

@ -124,8 +124,6 @@ public:
BOOLEAN
};
void renderExtras(const std::string& view, Window* window, const Eigen::Affine3f& transform);
// If expectedType is an empty string, will do no type checking.
const ThemeElement* getElement(const std::string& view, const std::string& element, const std::string& expectedType) const;

View file

@ -2,6 +2,7 @@
#include "Animation.h"
// Useful for simple one-off animations, you can supply the animation's apply(t) method right in the constructor as a lambda.
class LambdaAnimation : public Animation
{
public:

View file

@ -5,7 +5,11 @@
#include <functional>
#include <memory>
/* Usage example:
/*
Used to asynchronously run an HTTP request.
Displays a simple animation on the UI to show the application hasn't frozen. Can be canceled by the user pressing B.
Usage example:
std::shared_ptr<HttpReq> httpreq = std::make_shared<HttpReq>("cdn.garcya.us", "/wp-content/uploads/2010/04/TD250.jpg");
AsyncReqComponent* req = new AsyncReqComponent(mWindow, httpreq,
[] (std::shared_ptr<HttpReq> r)

View file

@ -4,9 +4,11 @@
#include <boost/date_time.hpp>
#include "../resources/Font.h"
// Used to enter or display a specific point in time.
class DateTimeComponent : public GuiComponent
{
public:
// Display mode will initialize to DISP_DATE.
DateTimeComponent(Window* window);
void setValue(const std::string& val) override;
@ -23,10 +25,15 @@ public:
DISP_RELATIVE_TO_NOW
};
// Set how the point in time will be displayed:
// * DISP_DATE - only display the date.
// * DISP_DATE_TIME - display both the date and the time on that date.
// * DISP_RELATIVE_TO_NOW - intelligently display the point in time relative to right now (e.g. "5 secs ago", "3 minutes ago", "1 day ago". Automatically updates as time marches on.
// The initial value is DISP_DATE.
void setDisplayMode(DisplayMode mode);
void setColor(unsigned int color);
void setFont(std::shared_ptr<Font> font);
void setColor(unsigned int color); // Text color.
void setFont(std::shared_ptr<Font> font); // Font to display with. Default is Font::get(FONT_SIZE_MEDIUM).
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties) override;

View file

@ -20,13 +20,9 @@ Eigen::Vector2f ImageComponent::getCenter() const
mPosition.y() - (getSize().y() * mOrigin.y()) + getSize().y() / 2);
}
ImageComponent::ImageComponent(Window* window, const Eigen::Vector2f& pos, const std::string& path) : GuiComponent(window),
ImageComponent::ImageComponent(Window* window) : GuiComponent(window),
mTargetIsMax(false), mFlipX(false), mFlipY(false), mOrigin(0.0, 0.0), mTargetSize(0, 0), mColorShift(0xFFFFFFFF)
{
setPosition(pos.x(), pos.y());
if(!path.empty())
setImage(path);
}
ImageComponent::~ImageComponent()

View file

@ -12,29 +12,43 @@
class ImageComponent : public GuiComponent
{
public:
//Creates a new GuiImage at the given location. If given an image, it will be loaded. If maxWidth and/or maxHeight are nonzero, the image will be
//resized to fit. If only one axis is specified, the other will be set in accordance with the image's aspect ratio. If allowUpscale is false,
//the image will only be downscaled, never upscaled (the image's size must surpass at least one nonzero bound).
ImageComponent(Window* window, const Eigen::Vector2f& pos = Eigen::Vector2f::Zero(), const std::string& path = "");
ImageComponent(Window* window);
virtual ~ImageComponent();
void setImage(std::string path, bool tile = false); //Loads the image at the given filepath.
void setImage(const char* image, size_t length, bool tile = false); //Loads image from memory.
void setImage(const std::shared_ptr<TextureResource>& texture); //Use an already existing texture.
void setOrigin(float originX, float originY); //Sets the origin as a percentage of this image (e.g. (0, 0) is top left, (0.5, 0.5) is the center)
//Loads the image at the given filepath. Will tile if tile is true (retrieves texture as tiling, creates vertices accordingly).
void setImage(std::string path, bool tile = false);
//Loads an image from memory.
void setImage(const char* image, size_t length, bool tile = false);
//Use an already existing texture.
void setImage(const std::shared_ptr<TextureResource>& texture);
//Sets the origin as a percentage of this image (e.g. (0, 0) is top left, (0.5, 0.5) is the center)
void setOrigin(float originX, float originY);
inline void setOrigin(Eigen::Vector2f origin) { setOrigin(origin.x(), origin.y()); }
// Resize the image to fit this size. If one axis is zero, scale that axis to maintain aspect ratio.
// If both are non-zero, potentially break the aspect ratio. If both are zero, no resizing.
// Can be set before or after an image is loaded.
// setMaxSize() and setResize() are mutually exclusive.
void setResize(float width, float height);
inline void setResize(const Eigen::Vector2f& size) { setResize(size.x(), size.y()); }
// Resize the image to be as large as possible but fit within a box of this size.
// Can be set before or after an image is loaded.
// Never breaks the aspect ratio. setMaxSize() and setResize() are mutually exclusive.
void setMaxSize(float width, float height);
inline void setMaxSize(const Eigen::Vector2f& size) { setMaxSize(size.x(), size.y()); }
// Multiply all pixels in the image by this color when rendering.
void setColorShift(unsigned int color);
void setFlipX(bool flip);
void setFlipY(bool flip);
void setFlipX(bool flip); // Mirror on the X axis.
void setFlipY(bool flip); // Mirror on the Y axis.
//You can get the rendered size of the ImageComponent with getSize().
// Returns the size of the current texture, or (0, 0) if none is loaded. May be different than drawn size (use getSize() for that).
Eigen::Vector2i getTextureSize() const;
// Returns the center point of the image (takes origin into account).
Eigen::Vector2f getCenter() const;
bool hasImage();
@ -49,9 +63,14 @@ private:
bool mFlipX, mFlipY, mTargetIsMax;
// Calculates the correct mSize from our resizing information (set by setResize/setMaxSize).
// Used internally whenever the resizing parameters or texture change.
void resize();
void buildImageArray(int x, int y, GLfloat* points, GLfloat* texs, float percentageX = 1, float percentageY = 1); //writes 12 GLfloat points and 12 GLfloat texture coordinates to a given array at a given position
void drawImageArray(GLfloat* points, GLfloat* texs, GLubyte* colors, unsigned int count = 6); //draws the given set of points and texture coordinates, number of coordinate pairs may be specified (default 6)
// Writes 12 GLfloat points and 12 GLfloat texture coordinates to a given array at a given position.
void buildImageArray(int x, int y, GLfloat* points, GLfloat* texs, float percentageX = 1, float percentageY = 1);
// Draws the given set of points and texture coordinates, number of coordinate pairs may be specified.
void drawImageArray(GLfloat* points, GLfloat* texs, GLubyte* colors, unsigned int count = 6);
unsigned int mColorShift;

View file

@ -3,6 +3,17 @@
#include "../GuiComponent.h"
#include "../resources/TextureResource.h"
// Display an image in a way so that edges don't get too distorted no matter the final size. Useful for UI elements like backgrounds, buttons, etc.
// This is accomplished by splitting an image into 9 pieces:
// ___________
// |_1_|_2_|_3_|
// |_4_|_5_|_6_|
// |_7_|_8_|_9_|
// Corners (1, 3, 7, 9) will not be stretched at all.
// Borders (2, 4, 6, 8) will be stretched along one axis (2 and 8 horizontally, 4 and 6 vertically).
// The center (5) will be stretched.
class NinePatchComponent : public GuiComponent
{
public:
@ -15,8 +26,8 @@ public:
void fitTo(Eigen::Vector2f size, Eigen::Vector3f position = Eigen::Vector3f::Zero(), Eigen::Vector2f padding = Eigen::Vector2f::Zero());
void setImagePath(const std::string& path);
void setEdgeColor(unsigned int edgeColor);
void setCenterColor(unsigned int centerColor);
void setEdgeColor(unsigned int edgeColor); // Apply a color shift to the "edge" parts of the ninepatch.
void setCenterColor(unsigned int centerColor); // Apply a color shift to the "center" part of the ninepatch.
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties) override;

View file

@ -3,13 +3,18 @@
#include "../GuiComponent.h"
#include "../resources/TextureResource.h"
// Used to visually display/edit some sort of "score" - e.g. 5/10, 3/5, etc.
// setSize(x, y) works a little differently than you might expect:
// * (0, y != 0) - x will be automatically calculated (5*y).
// * (x != 0, 0) - y will be automatically calculated (x/5).
// * (x != 0, y != 0) - you better be sure x = y*5
class RatingComponent : public GuiComponent
{
public:
RatingComponent(Window* window);
std::string getValue() const override;
void setValue(const std::string& value) override;
void setValue(const std::string& value) override; // Should be a normalized float (in the range [0..1]) - if it's not, it will be clamped.
bool input(InputConfig* config, Input input) override;
void render(const Eigen::Affine3f& parentTrans);
@ -29,7 +34,7 @@ private:
Eigen::Vector2f tex;
} mVertices[12];
std::shared_ptr<TextureResource> mFilledTexture;
std::shared_ptr<TextureResource> mUnfilledTexture;
std::shared_ptr<TextureResource> mFilledTexture; // Must be square (width == height)!
std::shared_ptr<TextureResource> mUnfilledTexture; // Must be square (width == height)!
};

View file

@ -5,6 +5,7 @@
class TextCache;
class Font;
// Used to display/edit a value between some min and max values.
class SliderComponent : public GuiComponent
{
public:

View file

@ -2,6 +2,8 @@
#include "../GuiComponent.h"
// A very simple "on/off" switch.
// Should hopefully be switched to use images instead of text in the future.
class SwitchComponent : public GuiComponent
{
public:

View file

@ -6,6 +6,11 @@
class ThemeData;
// Used to display text.
// TextComponent::setSize(x, y) works a little differently than most components:
// * (0, 0) - will automatically calculate a size that fits the text on one line (expand horizontally)
// * (x != 0, 0) - wrap text so that it does not reach beyond x. Will automatically calculate a vertical size (expand vertically).
// * (x != 0, y <= fontHeight) - will truncate text so it fits within this box.
class TextComponent : public GuiComponent
{
public:
@ -16,7 +21,7 @@ public:
void onSizeChanged() override;
void setText(const std::string& text);
void setColor(unsigned int color);
void setCentered(bool center); //Default is uncentered.
void setCentered(bool center); // Will horizontally center text. Default is false.
void render(const Eigen::Affine3f& parentTrans) override;

View file

@ -6,6 +6,7 @@
class Font;
class TextCache;
// Used to enter text.
class TextEditComponent : public GuiComponent
{
public:

View file

@ -1,4 +1,4 @@
//the Makefiles define these via command line
//the Makefile defines one of these:
//#define USE_OPENGL_ES
//#define USE_OPENGL_DESKTOP

View file

@ -98,6 +98,10 @@ private:
const std::string mPath;
};
// Used to store a sort of "pre-rendered" string.
// When a TextCache is constructed (Font::buildTextCache()), the vertices and texture coordinates of the string are calculated and stored in the TextCache object.
// Rendering a TextCache (Font::renderTextCache) every frame is MUCH faster than calling Font::drawText() and its variants.
// Keep in mind you still need the Font object to render a TextCache (as the Font holds the OpenGL texture), and if a Font changes your TextCache may become invalid.
class TextCache
{
public:

View file

@ -7,6 +7,8 @@
#include "../platform.h"
#include GLHEADER
// An OpenGL texture.
// Automatically recreates the texture with renderer deinit/reinit.
class TextureResource : public IReloadable
{
public:
@ -21,6 +23,7 @@ public:
Eigen::Vector2i getSize() const;
void bind() const;
// Warning: will NOT correctly reinitialize when this texture is reloaded (e.g. ES starts/stops playing a game).
void initFromMemory(const char* image, size_t length);
private:

View file

@ -5,6 +5,7 @@
class SystemData;
// Used to smoothly transition the camera between multiple views (e.g. from system to system, from gamelist to gamelist).
class ViewController : public GuiComponent
{
public:

View file

@ -8,10 +8,7 @@ class GuiComponent;
class FileData;
class ThemeData;
//IGameListView needs to know:
// What theme data to use
// The root FileData for the tree it should explore
// This is an interface that defines the minimum for a GameListView.
class IGameListView : public GuiComponent
{
public: