TGUI 1.10
Loading...
Searching...
No Matches
CanvasSFML.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2025 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#ifndef TGUI_CANVAS_SFML_HPP
26#define TGUI_CANVAS_SFML_HPP
27
28#include <TGUI/Backend/Renderer/SFML-Graphics/BackendTextureSFML.hpp>
29
30#if !TGUI_BUILD_AS_CXX_MODULE
31 #include <TGUI/Backend/Renderer/BackendRenderTarget.hpp>
32 #include <TGUI/Widgets/CanvasBase.hpp>
33#endif
34
35#include <SFML/Graphics/RenderTexture.hpp>
36#include <SFML/Graphics/Sprite.hpp>
37
39
40TGUI_MODULE_EXPORT namespace tgui
41{
68 class TGUI_API CanvasSFML : public CanvasBase
69 {
70 public:
71
72 using Ptr = std::shared_ptr<CanvasSFML>;
73 using ConstPtr = std::shared_ptr<const CanvasSFML>;
74
75 static constexpr const char StaticWidgetType[] = "CanvasSFML";
76
84 CanvasSFML(const char* typeName = StaticWidgetType, bool initRenderer = true);
85
89 CanvasSFML(const CanvasSFML& copy);
90
94 CanvasSFML(CanvasSFML&& copy) noexcept;
95
99 CanvasSFML& operator= (const CanvasSFML& right);
100
104 CanvasSFML& operator= (CanvasSFML&& right) noexcept;
105
113 TGUI_NODISCARD static CanvasSFML::Ptr create(const Layout2d& size = {"100%", "100%"});
114
122 TGUI_NODISCARD static CanvasSFML::Ptr copy(const CanvasSFML::ConstPtr& canvas);
123
131 void setSize(const Layout2d& size) override;
132 using Widget::setSize;
133
149 void setView(const sf::View& view);
150
156 TGUI_NODISCARD const sf::View& getView() const;
157
166 void resetView();
167
175 TGUI_NODISCARD sf::View getDefaultView() const;
176
185 TGUI_NODISCARD IntRect getViewport() const;
186
193 TGUI_NODISCARD Vector2f mapPixelToCoords(Vector2f point) const;
194
201 TGUI_NODISCARD Vector2f mapCoordsToPixel(Vector2f coord) const;
202
212 void setSmooth(bool smooth);
213
221 TGUI_NODISCARD bool isSmooth() const;
222
230 void clear(Color color = Color::Black);
231
238 void draw(const sf::Drawable& drawable, const sf::RenderStates& states = {});
239
248 void draw(const sf::Vertex* vertices, std::size_t vertexCount,
249 sf::PrimitiveType type, const sf::RenderStates& states = {});
250
259 void draw(const Sprite& sprite, const RenderStates& states = {});
260
267 void display();
268
275 void draw(BackendRenderTarget& target, RenderStates states) const override;
276
284 TGUI_NODISCARD sf::RenderTexture& getRenderTexture()
285 {
286 return m_renderTexture;
287 }
288
290 protected:
291
293 // Makes a copy of the widget
295 TGUI_NODISCARD Widget::Ptr clone() const override;
296
298 protected:
299
300 sf::RenderTexture m_renderTexture;
301 Optional<sf::View> m_customView;
302 };
303}
304
306
307#endif // TGUI_CANVAS_SFML_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:46
static CanvasSFML::Ptr create(const Layout2d &size={"100%", "100%"})
Creates a new canvas widget.
IntRect getViewport() const
Get the viewport of the currently applied view, applied to this canvas.
void draw(const Sprite &sprite, const RenderStates &states={})
Draws a TGUI sprite to the canvas.
CanvasSFML(const CanvasSFML &copy)
Copy constructor.
Vector2f mapCoordsToPixel(Vector2f coord) const
Converts a position within the canvas view to the corresponding point on the canvas.
void resetView()
Changes the current active view back to the default value.
void setView(const sf::View &view)
Change the current active view.
static CanvasSFML::Ptr copy(const CanvasSFML::ConstPtr &canvas)
Makes a copy of another canvas.
void setSize(const Layout2d &size) override
Changes the size of the widget.
sf::View getDefaultView() const
Get the default view of the canvas.
sf::RenderTexture & getRenderTexture()
Access the internal render texture that the canvas widget uses to draw on.
Definition CanvasSFML.hpp:284
std::shared_ptr< CanvasSFML > Ptr
Shared widget pointer.
Definition CanvasSFML.hpp:72
void setSmooth(bool smooth)
Enable or disable texture smoothing.
void draw(const sf::Vertex *vertices, std::size_t vertexCount, sf::PrimitiveType type, const sf::RenderStates &states={})
Draws primitives defined by an array of vertices.
const sf::View & getView() const
Get the view currently in use in the canvas.
void draw(const sf::Drawable &drawable, const sf::RenderStates &states={})
Draws a drawable object to the canvas.
void clear(Color color=Color::Black)
Clears the entire canvas with a single color.
void display()
Updates the contents of the canvas.
bool isSmooth() const
Tell whether the smooth filtering is enabled or not.
CanvasSFML(CanvasSFML &&copy) noexcept
Move constructor.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
std::shared_ptr< const CanvasSFML > ConstPtr
Shared constant widget pointer.
Definition CanvasSFML.hpp:73
Vector2f mapPixelToCoords(Vector2f point) const
Converts a point on the canvas to a position within the canvas view.
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
static constexpr const char StaticWidgetType[]
Type name of the widget.
Definition CanvasSFML.hpp:75
Wrapper for colors.
Definition Color.hpp:73
static const Color Black
Black predefined color.
Definition Color.hpp:259
Class to store the position or size of a widget.
Definition Layout.hpp:323
Definition Sprite.hpp:47
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:86
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
States used for drawing.
Definition RenderStates.hpp:38