![]() |
wPlot2D version: 0.1.0
A lightweight C++ library for clear and customizable 2D scientific plots.
|
Central entity responsible for graphical rendering in wPlot2D. More...
#include <wGraphicsEntity.hpp>
Public Member Functions | |
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. | |
virtual | ~GraphicsEntity ()=default |
Virtual destructor. | |
sf::RenderWindow & | getWindow () |
Gives access to the internal SFML window. | |
sf::Vector2u | getWindowSize () const |
Retrieves the current window size. | |
void | setWindowSize (const sf::Vector2u &newSize) |
Sets a new window size. | |
void | setWindowTitle (const std::string &title) |
Updates the window title. | |
void | setBackgroundColor (const sf::Color &color) |
Clears the window with a background color. | |
void | addFont (const std::string &name, const std::string &fileName) |
Adds a font to the AssetManager. | |
sf::Font & | getFont (const std::string name) |
Retrieves a previously loaded font. | |
sf::Vector2f | getOrigin () const |
Returns the current logical origin (in pixels). | |
void | setOrigin (sf::Vector2f originFactor) |
Sets a new logical origin (normalized). | |
sf::Vector2f | getScale () const |
Returns the scale factors (pixels per logical unit). | |
void | setScale (sf::Vector2f scaleFactor) |
Sets new scale factors (normalized). | |
sf::Vector2f | getOffset () const |
Returns the current logical offset. | |
void | setOffset (sf::Vector2f offset) |
Sets the logical offset applied to the axes. | |
AxisEntity * | addAxis (AxisType type, sf::Vector2f axisRange) |
Adds an axis (X or Y) to the scene. | |
TitleEntity * | addTitle (const std::string &title, TitleAlignment alignment=TitleAlignment::Bottom) |
Adds a main plot title (top or bottom). | |
TitleEntity * | addTitle (const std::wstring &title, TitleAlignment alignment=TitleAlignment::Bottom) |
Adds a main plot title (top or bottom). | |
FunctionEntity * | addFunction (std::function< double(double)> func, double startX, double endX, size_t nbPoints=1000) |
Adds a mathematical function to the scene. | |
DataPlotEntity * | addDataPlot (const std::vector< sf::Vector2f > &dataPoints) |
Adds a raw data plot (connected points). | |
LegendEntity * | addLegend (const sf::Vector2f &position, bool hasFrame=true) |
Adds a legend box at a given position. | |
TitleEntity * | addText (const std::string &text, sf::Vector2f position) |
Adds arbitrary text to the scene. | |
TitleEntity * | addText (const std::wstring &text, sf::Vector2f position) |
Adds arbitrary text to the scene. | |
LineEntity * | addLine (const sf::Vector2f &start, const sf::Vector2f &end, bool withArrow=false) |
Adds a line segment to the scene. | |
void | saveToFile (const std::string &filename) |
Saves a screenshot of the current window. | |
Public Member Functions inherited from wEngine::Entity | |
Entity () | |
virtual | ~Entity () |
unsigned int | getEntityID () const |
Returns the unique ID associated with this entity. | |
void | clearComponents () |
Removes all components currently attached to the entity. | |
template<typename T, typename... Args> | |
std::shared_ptr< T > | addComponent (Args &&... args) |
Adds a new component of type T to the entity. | |
template<typename T> | |
void | removeComponent () |
Removes the component of type T from the entity. | |
template<typename T> | |
bool | hasComponent () const noexcept |
Checks whether the entity has a component of type T. | |
template<typename T> | |
std::shared_ptr< T > | getComponent () const |
Retrieves the component of type T attached to the entity. | |
template<typename T> | |
std::shared_ptr< T > | requireComponent (const std::string &context="") const |
Retrieves the component of type T and throws if it's missing. | |
template<typename Interface> | |
std::shared_ptr< Interface > | getInterfaceComponent () const |
Returns the first component that implements the specified interface. |
Additional Inherited Members | |
Static Public Member Functions inherited from wEngine::Entity | |
static void | resetEntityIDCounter () |
Resets the global entity ID counter to zero. |
Central entity responsible for graphical rendering in wPlot2D.
The GraphicsEntity manages the creation and control of the SFML rendering window. It provides high-level methods to add and configure graphical entities:
It also handles window configuration (title, size, background color) and allows exporting the final rendering to an image file.
wPlot2D::GraphicsEntity::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.
windowTitle | The title displayed on the window (default: "wPlot2D"). |
windowSize | Window dimensions in pixels (default: 1600×1600). |
originFactor | Normalized factor in [0,1]x[0,1] specifying the origin’s relative position (default: ( 0.5f, 0.5f ). |
scaleFactor | Normalized factor specifying the size of one logical unit relative to window dimensions (default: ( 0.1f, 0.1f )). |
std::invalid_argument | if originFactor not in [0,1]. |
|
virtualdefault |
Virtual destructor.
|
nodiscard |
Gives access to the internal SFML window.
|
nodiscard |
Retrieves the current window size.
void wPlot2D::GraphicsEntity::setWindowSize | ( | const sf::Vector2u & | newSize | ) |
Sets a new window size.
newSize | Window dimensions in pixels. |
void wPlot2D::GraphicsEntity::setWindowTitle | ( | const std::string & | title | ) |
Updates the window title.
title | New window title. |
void wPlot2D::GraphicsEntity::setBackgroundColor | ( | const sf::Color & | color | ) |
Clears the window with a background color.
color | Background fill color. |
void wPlot2D::GraphicsEntity::addFont | ( | const std::string & | name, |
const std::string & | fileName ) |
Adds a font to the AssetManager.
name | Identifier string for the font. |
fileName | Path to the font file. |
sf::Font & wPlot2D::GraphicsEntity::getFont | ( | const std::string | name | ) |
Retrieves a previously loaded font.
name | Identifier of the font. |
std::runtime_error | if the font is not found. |
|
nodiscard |
Returns the current logical origin (in pixels).
std::runtime_error | if the PositionComponent is missing. |
void wPlot2D::GraphicsEntity::setOrigin | ( | sf::Vector2f | originFactor | ) |
Sets a new logical origin (normalized).
originFactor | in [0,1]×[0,1] new relative origin. |
std::invalid_argument | if originFactor is outside [0,1]. |
|
nodiscard |
Returns the scale factors (pixels per logical unit).
std::runtime_error | if the ScaleComponent is missing. |
void wPlot2D::GraphicsEntity::setScale | ( | sf::Vector2f | scaleFactor | ) |
Sets new scale factors (normalized).
scaleFactor | new scaling factor |
|
nodiscard |
Returns the current logical offset.
std::runtime_error | if the OffsetComponent is missing. |
void wPlot2D::GraphicsEntity::setOffset | ( | sf::Vector2f | offset | ) |
Sets the logical offset applied to the axes.
offset | Displacement in logical units. |
|
nodiscard |
Adds an axis (X or Y) to the scene.
type | Axis type. |
axisRange | Logical range for the axis. |
|
nodiscard |
Adds a main plot title (top or bottom).
title | Title text (UTF-8). |
alignment | Vertical alignment (default: bottom). |
|
nodiscard |
Adds a main plot title (top or bottom).
title | Title text (UTF-16/32). |
alignment | Vertical alignment (default: bottom). |
|
nodiscard |
Adds a mathematical function to the scene.
func | Function of type double(double). |
startX | Domain start (logical). |
endX | Domain end (logical). |
nbPoints | Sampling resolution (default 1000). |
|
nodiscard |
Adds a raw data plot (connected points).
dataPoints | Vector of (x,y) coordinates. |
|
nodiscard |
Adds a legend box at a given position.
position | Normalized position inside window [0,1]x[0,1]. |
hasFrame | Whether the legend frame is visible (default true). |
|
nodiscard |
Adds arbitrary text to the scene.
text | Text string (UTF-8). |
position | Normalized position in [0,1]x[0,1]. |
|
nodiscard |
Adds arbitrary text to the scene.
text | Text string (UTF-16/32). |
position | Normalized position in [0,1]x[0,1]. |
|
nodiscard |
Adds a line segment to the scene.
start | Start point in logical coordinates. |
end | End point in logical coordinates. |
withArrow | Whether to render an arrowhead at the end. |
void wPlot2D::GraphicsEntity::saveToFile | ( | const std::string & | filename | ) |
Saves a screenshot of the current window.
filename | Output file path (supported: png, bmp, tga, jpg). |
std::runtime_error | if saving fails. |