Smolgui
Immediate gui library based on SFML
Loading...
Searching...
No Matches
GuiRender.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4#include <SFML/Graphics/Font.hpp>
5#include <SFML/Graphics/View.hpp>
6#include <SFML/Graphics/Text.hpp>
7#include <SFML/Graphics/Drawable.hpp>
8#include <SFML/Graphics/VertexArray.hpp>
9#include <SFML/Graphics/Transformable.hpp>
10
11#include "sgui/Core/Shapes.h"
17
18namespace sgui
19{
20
24class GuiRender : public sf::Drawable, public sf::Transformable
25{
26public:
31 void setResources (sf::Texture& sprite);
35 void updateView (const sf::View& newView);
41 uint32_t setCurrentClippingLayer (const sf::FloatRect& mask);
46 void setTextureAtlas (const TextureAtlas& atlas);
50 void clear ();
56 void draw (
57 const sf::FloatRect& box,
58 const WidgetDrawOptions& options = {});
65 void draw (
66 const std::string& text,
67 const sf::Font& font,
68 const TextDrawOptions& options = {});
76 sf::Vector2f textSize (
77 const std::string& text,
78 const sf::Font& font,
79 const uint32_t fontSize) const;
83 void setTooltipMode ();
87 void unsetTooltipMode ();
93 sf::Vector2f textureSize (const std::string& texture) const;
94public:
99private:
103 void initializeClippingLayers ();
108 void addThreeSlices (const sf::FloatRect& box, const std::string& widgetState, const bool horizontal = true, const float percentToDraw = 1.f);
113 void addNineSlices (const sf::FloatRect& box, const std::string& widgetState);
117 void appendMesh (Mesh&& mesh, const sf::FloatRect& box, const bool horizontal = true, const float percentToDraw = 1.f);
121 void computeMeshFilling (Mesh& mesh, const float percentToDraw, const bool horizontal = true);
125 void draw (sf::RenderTarget& target, sf::RenderStates states) const override;
129 void drawLayer (sf::RenderTarget& target, sf::RenderStates states, uint32_t layer) const;
133 std::string toString (const Widget widget) const;
134 std::string toString (const ItemState state) const;
135private:
136 // define on which render we work
137 bool mTooltipMode;
138 std::vector <uint32_t> mWidgetLayers;
139 std::vector <uint32_t> mTooltipLayers;
140 // font and texture
141 sf::Texture* mGuiTexture;
142 // widget mesh
143 std::vector <sf::VertexArray> mWidgets;
144 std::vector <std::vector <sf::Text>> mTexts;
145 TextureMeshes mTexturesUV;
146};
147
148} // namespace sgui
Handle clipping layers to only draw things in a given box.
Definition ClippingLayers.h:15
Handle rendering for the gui.
Definition GuiRender.h:25
void clear()
Clear all widgets and text.
Definition GuiRender.cpp:48
uint32_t setCurrentClippingLayer(const sf::FloatRect &mask)
Set current clipping layer used to render UI. Every call will create a new layer with its own indepen...
Definition GuiRender.cpp:23
void updateView(const sf::View &newView)
Update view on which the gui is drawn.
Definition GuiRender.cpp:17
void setResources(sf::Texture &sprite)
Set resources used in render. It should be called before any draw call.
Definition GuiRender.cpp:9
sf::Vector2f textureSize(const std::string &texture) const
allow access to a texture size, as stored in the atlas
Definition GuiRender.cpp:93
sf::Vector2f textSize(const std::string &text, const sf::Font &font, const uint32_t fontSize) const
Get text size as if it was drawn on screen.
Definition GuiRender.cpp:69
void draw(const sf::FloatRect &box, const WidgetDrawOptions &options={})
interface to draw Gui standard element
Definition GuiRender.cpp:102
void setTooltipMode()
set specific render for tooltip
Definition GuiRender.cpp:81
ClippingLayers clipping
to handle clipping layers
Definition GuiRender.h:98
void setTextureAtlas(const TextureAtlas &atlas)
Set texture atlas used in render. It should be called before any draw call.
Definition GuiRender.cpp:41
void unsetTooltipMode()
unset specific render for tooltip
Definition GuiRender.cpp:87
Contains texture position and sub-box of all sprites for a given sprite sheet. Animations ca be handl...
Definition TextureAtlas.h:28
Compute texture meshes for a given texture map.
Definition TextureMeshes.h:18
Definition Interpolation.h:16
ItemState
List gui elements states.
Definition ItemStates.h:11
Widget
List widget textures available in gui.
Definition Widgets.h:11
std::array< sf::Vertex, 6 > Mesh
Definition MeshFunctions.h:9
Store options for drawing text.
Definition DrawOptions.h:21
Store options for drawing widgets.
Definition DrawOptions.h:12