TGUI 1.11
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#include <TGUI/Backend/Renderer/BackendRenderTarget.hpp>
30#include <TGUI/Widgets/CanvasBase.hpp>
31
32#include <SFML/Graphics/RenderTexture.hpp>
33#include <SFML/Graphics/Sprite.hpp>
34
36
37namespace tgui
38{
65 class TGUI_API CanvasSFML : public CanvasBase
66 {
67 public:
68
69 using Ptr = std::shared_ptr<CanvasSFML>;
70 using ConstPtr = std::shared_ptr<const CanvasSFML>;
71
72 static constexpr const char StaticWidgetType[] = "CanvasSFML";
73
81 CanvasSFML(const char* typeName = StaticWidgetType, bool initRenderer = true);
82
86 CanvasSFML(const CanvasSFML& copy);
87
91 CanvasSFML(CanvasSFML&& copy) noexcept;
92
96 CanvasSFML& operator= (const CanvasSFML& right);
97
101 CanvasSFML& operator= (CanvasSFML&& right) noexcept;
102
110 TGUI_NODISCARD static CanvasSFML::Ptr create(const Layout2d& size = {"100%", "100%"});
111
119 TGUI_NODISCARD static CanvasSFML::Ptr copy(const CanvasSFML::ConstPtr& canvas);
120
128 void setSize(const Layout2d& size) override;
129 using Widget::setSize;
130
146 void setView(const sf::View& view);
147
153 TGUI_NODISCARD const sf::View& getView() const;
154
163 void resetView();
164
172 TGUI_NODISCARD sf::View getDefaultView() const;
173
182 TGUI_NODISCARD IntRect getViewport() const;
183
190 TGUI_NODISCARD Vector2f mapPixelToCoords(Vector2f point) const;
191
198 TGUI_NODISCARD Vector2f mapCoordsToPixel(Vector2f coord) const;
199
209 void setSmooth(bool smooth);
210
218 TGUI_NODISCARD bool isSmooth() const;
219
227 void clear(Color color = Color::Black);
228
235 void draw(const sf::Drawable& drawable, const sf::RenderStates& states = {});
236
245 void draw(const sf::Vertex* vertices, std::size_t vertexCount,
246 sf::PrimitiveType type, const sf::RenderStates& states = {});
247
256 void draw(const Sprite& sprite, const RenderStates& states = {});
257
264 void display();
265
272 void draw(BackendRenderTarget& target, RenderStates states) const override;
273
281 TGUI_NODISCARD sf::RenderTexture& getRenderTexture()
282 {
283 return m_renderTexture;
284 }
285
287 protected:
288
290 // Makes a copy of the widget
292 TGUI_NODISCARD Widget::Ptr clone() const override;
293
295 protected:
296
297 sf::RenderTexture m_renderTexture;
298 Optional<sf::View> m_customView;
299 };
300}
301
303
304#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:281
std::shared_ptr< CanvasSFML > Ptr
Shared widget pointer.
Definition CanvasSFML.hpp:69
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:70
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:72
Wrapper for colors.
Definition Color.hpp:71
static const Color Black
Black predefined color.
Definition Color.hpp:257
Class to store the position or size of a widget.
Definition Layout.hpp:321
Definition Sprite.hpp:45
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:87
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36
States used for drawing.
Definition RenderStates.hpp:38