|
|
@@ -1,69 +1,96 @@
|
|
|
#ifndef ANKI_UI_UI_PAINTER_H
|
|
|
#define ANKI_UI_UI_PAINTER_H
|
|
|
|
|
|
-#include "anki/resource/Resource.h"
|
|
|
-#include "anki/math/Math.h"
|
|
|
-#include "anki/gl/Vbo.h"
|
|
|
-#include "anki/gl/Vao.h"
|
|
|
-#include "anki/resource/ShaderProgramResource.h"
|
|
|
+#include "anki/ui/UiCommon.h"
|
|
|
+#include "anki/gl/Gl.h"
|
|
|
|
|
|
namespace anki {
|
|
|
|
|
|
+// Forward
|
|
|
class UiFont;
|
|
|
|
|
|
-/// XXX
|
|
|
+/// Gradient type
|
|
|
+struct UiGrandient
|
|
|
+{
|
|
|
+ enum GradientType
|
|
|
+ {
|
|
|
+ GT_ANGULAR,
|
|
|
+ GT_RADIAL
|
|
|
+ };
|
|
|
+
|
|
|
+ GradientType type = GT_ANGULAR;
|
|
|
+ Array<UiColor, 3> colors = {{UiColor(1.0), UiColor(0.5), UiColor(0.0)}};
|
|
|
+ U8 colorsCount = 2;
|
|
|
+ F32 angle = 0.0; ///< In rad. Default is horizontal
|
|
|
+};
|
|
|
+
|
|
|
+/// UI painer
|
|
|
class UiPainter
|
|
|
{
|
|
|
public:
|
|
|
+ /// Method for coloring
|
|
|
+ enum ColoringMethod
|
|
|
+ {
|
|
|
+ CM_CONSTANT_COLOR,
|
|
|
+ CM_GRADIENT
|
|
|
+ };
|
|
|
+
|
|
|
UiPainter(const Vec2& deviceSize);
|
|
|
|
|
|
/// @name Accessors
|
|
|
/// @{
|
|
|
- const Vec2& getPosition() const
|
|
|
+ const UiPosition& getPosition() const
|
|
|
{
|
|
|
return pos;
|
|
|
}
|
|
|
- void setPosition(const Vec2& x)
|
|
|
+ void setPosition(const UiPosition& x)
|
|
|
{
|
|
|
pos = x;
|
|
|
}
|
|
|
|
|
|
- const Vec4& getColor() const
|
|
|
+ const UiColor& getColor() const
|
|
|
{
|
|
|
return col;
|
|
|
}
|
|
|
- void setColor(const Vec4& x)
|
|
|
+ void setColor(const UiColor& x)
|
|
|
{
|
|
|
col = x;
|
|
|
- sProg->bind();
|
|
|
- sProg->findUniformVariable("color").set(col);
|
|
|
}
|
|
|
+ /// @}
|
|
|
|
|
|
- void setFont(const char* fontFilename, uint nominalWidth,
|
|
|
- uint nominalHeight);
|
|
|
-
|
|
|
- const UiFont& getFont() const
|
|
|
- {
|
|
|
- return *font;
|
|
|
- }
|
|
|
+ /// @name Fill methods
|
|
|
+ /// @{
|
|
|
+ void fillRect(const UiRect& rect);
|
|
|
+ void fillEllipse(const UiRect& rect);
|
|
|
+ void fillRoundedRect(const UiRect& rect, F32 xRadius, F32 yRadius);
|
|
|
/// @}
|
|
|
|
|
|
+ /// @name Draw methods
|
|
|
+ /// @{
|
|
|
void drawText(const char* text);
|
|
|
- void drawText(const std::string& str)
|
|
|
- {
|
|
|
- drawText(str.c_str());
|
|
|
- }
|
|
|
void drawFormatedText(const char* format, ...);
|
|
|
|
|
|
+ void drawLines(const UiPosition* positions, U32 positionsCount);
|
|
|
+ void drawRect(const UiRect& rect);
|
|
|
+ void drawEllipse(const UiRect& rect);
|
|
|
+ void drawRoundedRect(const UiRect& rect, F32 xRadius, F32 yRadius);
|
|
|
+ /// @}
|
|
|
+
|
|
|
private:
|
|
|
+ enum Shader
|
|
|
+ {
|
|
|
+ S_FILL,
|
|
|
+ S_GRADIENT_ANGULAR_COLORS_2,
|
|
|
+ S_GRADIENT_ANGULAR_COLORS_3,
|
|
|
+ S_GRADIENT_RADIAL_COLORS_2,
|
|
|
+ S_GRADIENT_RADIAL_COLORS_3,
|
|
|
+ S_COUNT
|
|
|
+ };
|
|
|
+
|
|
|
/// @name Data
|
|
|
/// @{
|
|
|
- std::unique_ptr<UiFont> font;
|
|
|
- ShaderProgramResourcePointer sProg;
|
|
|
-
|
|
|
- Vec2 pos;
|
|
|
- Vec4 col;
|
|
|
- uint tabSize;
|
|
|
+ UiFont* font = nullptr;
|
|
|
+ Array<ShaderProgram, S_COUNT> progs;
|
|
|
|
|
|
Vbo qPositionsVbo;
|
|
|
Vbo qIndecesVbo;
|
|
|
@@ -72,6 +99,19 @@ private:
|
|
|
Vec2 deviceSize; ///< The size of the device in pixels
|
|
|
/// @}
|
|
|
|
|
|
+ /// @name State machine data
|
|
|
+ /// @{
|
|
|
+ UiPosition pos;
|
|
|
+ UiColor col;
|
|
|
+ Gradient grad;
|
|
|
+ ColoringMethod fillMethod;
|
|
|
+ ColoringMethod linesMethod;
|
|
|
+ /// @}
|
|
|
+
|
|
|
+ /// @name Oprtimizations
|
|
|
+ /// @{
|
|
|
+ /// @}
|
|
|
+
|
|
|
void init();
|
|
|
};
|
|
|
|