8#ifndef W_GRAPHICS_ENTITY_HPP
9#define W_GRAPHICS_ENTITY_HPP
23#pragma GCC diagnostic push
24#pragma GCC diagnostic ignored "-Wfloat-equal"
25#pragma GCC diagnostic ignored "-Wswitch-default"
26#include <SFML/Graphics.hpp>
27#pragma GCC diagnostic pop
78 const std::string& windowTitle =
"wPlot2D",
79 const sf::Vector2u& windowSize = { 1600, 1600 },
80 const sf::Vector2f& originFactor = { 0.5f, 0.5f },
81 const sf::Vector2f& scaleFactor = { 0.1f, 0.1f } );
92 [[nodiscard]] sf::RenderWindow&
getWindow( );
123 void addFont(
const std::string& name,
const std::string& fileName );
131 sf::Font&
getFont(
const std::string name );
138 [[nodiscard]] sf::Vector2f
getOrigin( )
const;
145 void setOrigin( sf::Vector2f originFactor );
152 [[nodiscard]] sf::Vector2f
getScale( )
const;
158 void setScale( sf::Vector2f scaleFactor );
165 [[nodiscard]] sf::Vector2f
getOffset( )
const;
206 double startX,
double endX,
size_t nbPoints = 1000 );
237 [[nodiscard]]
TitleEntity*
addText(
const std::wstring& text, sf::Vector2f position );
246 [[nodiscard]]
LineEntity*
addLine(
const sf::Vector2f& start,
const sf::Vector2f& end,
bool withArrow =
false );
253 void saveToFile(
const std::string& filename );
255 sf::RenderWindow mWindow;
257 std::unique_ptr< AxisEntity > mAxisX;
258 std::unique_ptr< AxisEntity > mAxisY;
259 std::unique_ptr< TitleEntity > mTitle;
262 template <
typename T >
265 template <
typename T >
266 TitleEntity* initText(
const T& title, sf::Vector2f position );
270 std::unique_ptr< FunctionEntity > entity;
275 std::vector< FunctionData > mFunctions;
279 std::unique_ptr< DataPlotEntity > entity;
281 std::vector< DataPlotData > mDataPlots;
283 std::unique_ptr< LegendEntity > mLegend;
287 std::unique_ptr< TitleEntity > entity;
289 std::vector< TextData > mTexts;
293 std::unique_ptr< LineEntity > entity;
295 std::vector< LineData > mLines;
325 void validateNormalizedFactor(
const sf::Vector2f& factor )
const;
338 [[nodiscard]] sf::Vector2f convertNormalizedToPixels(
const sf::Vector2f& factor )
const;
Manages graphical assets such as fonts for reuse across the application.
Definition wAssetManager.hpp:50
Represents an entity in the ECS (Entity-Component System) architecture.
Definition wEntity.hpp:60
Represents a visual axis (X or Y) in a 2D plot with optional notches and title.
Definition wAxisEntity.hpp:67
Entity for plotting raw data points as a connected polyline.
Definition wDataPlotEntity.hpp:42
Represents a mathematical function as a drawable entity in a 2D plot.
Definition wFunctionEntity.hpp:43
sf::Vector2f getOrigin() const
Returns the current logical origin (in pixels).
Definition wGraphicsEntity.cpp:102
void setWindowTitle(const std::string &title)
Updates the window title.
Definition wGraphicsEntity.cpp:70
LegendEntity * addLegend(const sf::Vector2f &position, bool hasFrame=true)
Adds a legend box at a given position.
Definition wGraphicsEntity.cpp:248
sf::RenderWindow & getWindow()
Gives access to the internal SFML window.
Definition wGraphicsEntity.cpp:53
void setScale(sf::Vector2f scaleFactor)
Sets new scale factors (normalized).
Definition wGraphicsEntity.cpp:122
LineEntity * addLine(const sf::Vector2f &start, const sf::Vector2f &end, bool withArrow=false)
Adds a line segment to the scene.
Definition wGraphicsEntity.cpp:295
void setOrigin(sf::Vector2f originFactor)
Sets a new logical origin (normalized).
Definition wGraphicsEntity.cpp:108
virtual ~GraphicsEntity()=default
Virtual destructor.
AxisEntity * addAxis(AxisType type, sf::Vector2f axisRange)
Adds an axis (X or Y) to the scene.
Definition wGraphicsEntity.cpp:146
sf::Vector2f getOffset() const
Returns the current logical offset.
Definition wGraphicsEntity.cpp:128
void setWindowSize(const sf::Vector2u &newSize)
Sets a new window size.
Definition wGraphicsEntity.cpp:63
void addFont(const std::string &name, const std::string &fileName)
Adds a font to the AssetManager.
Definition wGraphicsEntity.cpp:82
void setBackgroundColor(const sf::Color &color)
Clears the window with a background color.
Definition wGraphicsEntity.cpp:75
DataPlotEntity * addDataPlot(const std::vector< sf::Vector2f > &dataPoints)
Adds a raw data plot (connected points).
Definition wGraphicsEntity.cpp:231
void saveToFile(const std::string &filename)
Saves a screenshot of the current window.
Definition wGraphicsEntity.cpp:313
FunctionEntity * addFunction(std::function< double(double)> func, double startX, double endX, size_t nbPoints=1000)
Adds a mathematical function to the scene.
Definition wGraphicsEntity.cpp:214
sf::Vector2f getScale() const
Returns the scale factors (pixels per logical unit).
Definition wGraphicsEntity.cpp:116
TitleEntity * addTitle(const std::string &title, TitleAlignment alignment=TitleAlignment::Bottom)
Adds a main plot title (top or bottom).
Definition wGraphicsEntity.cpp:166
void setOffset(sf::Vector2f offset)
Sets the logical offset applied to the axes.
Definition wGraphicsEntity.cpp:134
sf::Font & getFont(const std::string name)
Retrieves a previously loaded font.
Definition wGraphicsEntity.cpp:88
GraphicsEntity(const std::string &windowTitle="wPlot2D", const sf::Vector2u &windowSize={ 1600, 1600 }, const sf::Vector2f &originFactor={ 0.5f, 0.5f }, const sf::Vector2f &scaleFactor={ 0.1f, 0.1f })
Constructs the graphics entity and initializes the rendering window and components.
Definition wGraphicsEntity.cpp:26
sf::Vector2u getWindowSize() const
Retrieves the current window size.
Definition wGraphicsEntity.cpp:58
TitleEntity * addText(const std::string &text, sf::Vector2f position)
Adds arbitrary text to the scene.
Definition wGraphicsEntity.cpp:264
Represents a legend box that describes functions and data plots.
Definition wLegendEntity.hpp:56
Entity representing a straight line segment with optional arrowhead.
Definition wLineEntity.hpp:43
Represents a textual label (typically an axis title or main plot title) in a 2D plot.
Definition wTitleEntity.hpp:45
Definition wAxisEntity.cpp:17
AxisType
Enum representing the type of axis to render.
Definition wAxisEntity.hpp:35
TitleAlignment
Defines the vertical placement of the main plot title.
Definition wGraphicsEntity.hpp:37
@ Bottom
Definition wGraphicsEntity.hpp:39
@ Top
Definition wGraphicsEntity.hpp:38