![]() |
wPlot2D version: 0.1.0
A lightweight C++ library for clear and customizable 2D scientific plots.
|
Represents a visual axis (X or Y) in a 2D plot with optional notches and title. More...
#include <wAxisEntity.hpp>
Public Member Functions | |
AxisEntity (sf::Font &font, sf::Vector2f origin, sf::Vector2f scale, sf::Vector2f offset, AxisType type, sf::Vector2f axisRange) | |
Constructs an AxisEntity with a given orientation, origin, scale, and range. | |
virtual | ~AxisEntity ()=default |
Virtual destructor. | |
void | setColor (sf::Color color) |
Sets the color of the axis line. | |
void | setThickness (float thickness) |
Sets the thickness of the axis line (in pixels). | |
void | setArrowSize (float arrowSize) |
Sets the size of the arrowhead at the end of the axis. | |
void | addTitle (const std::string &title) |
Adds a title to the axis. | |
void | addTitle (const std::wstring &title) |
Adds a title to the axis. | |
void | setTitleFont (const sf::Font &font) |
Sets the font of the axis title. | |
void | setTitleCharacterSize (unsigned int size) |
Sets the character size of the axis title. | |
void | setTitleColor (sf::Color newColor) |
Sets the color of the axis title. | |
void | setTitleOffset (sf::Vector2f titleOffset) |
Sets a manual offset for the title position. | |
sf::Vector2f | getTitleOffset () const |
Gets the current title offset. | |
void | addNotches (float interval, NotchPosition position, bool hasLabels=false) |
Adds notches along the axis. | |
void | setNotchesColor (const sf::Color &color) |
Sets the color of all notches. | |
void | setNotchesThickness (float thickness) |
Sets the thickness of all notches. | |
void | setNotchesLength (float newLength) |
Sets the length of all notches. | |
void | setLabelsFont (const sf::Font &font) |
Sets the font of all labels. | |
void | setLabelsColor (const sf::Color &color) |
Sets the color of all labels. | |
std::vector< sf::Vector2f > | getLabelsOffset () const |
Gets the current offset of all labels. | |
void | setLabelsOffset (sf::Vector2f offset) |
Sets a new offset for all labels. | |
void | addLabelsOffset (sf::Vector2f delta) |
Applies an additional offset to all labels. | |
void | setLabelsCharacterSize (unsigned int newSize) |
Sets the character size of all labels. | |
void | setLabelsDecimalPlaces (int places) |
Sets the number of decimal places for numeric labels. | |
void | setCustomLabels (const std::vector< std::string > &labels) |
Replaces numeric labels with a custom set of strings. | |
void | render (sf::RenderWindow &window) |
Renders the axis (line, arrow, title, notches, labels). | |
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. |
Represents a visual axis (X or Y) in a 2D plot with optional notches and title.
This class manages the rendering of a coordinate axis in a Cartesian 2D system. It supports:
wPlot2D::AxisEntity::AxisEntity | ( | sf::Font & | font, |
sf::Vector2f | origin, | ||
sf::Vector2f | scale, | ||
sf::Vector2f | offset, | ||
AxisType | type, | ||
sf::Vector2f | axisRange ) |
Constructs an AxisEntity with a given orientation, origin, scale, and range.
font | Reference to a font used for the title and labels. |
origin | Pixel position of the logical origin (typically from GraphicsEntity). |
scale | Scaling factor (pixels per logical unit). |
offset | Logical displacement of the axis system. |
type | Axis type (X_AXIS or Y_AXIS). |
axisRange | Logical range covered by the axis (e.g., [-5, 5]). |
|
virtualdefault |
Virtual destructor.
void wPlot2D::AxisEntity::setColor | ( | sf::Color | color | ) |
Sets the color of the axis line.
color | New axis color. |
std::runtime_error | if ColorComponent is missing. |
void wPlot2D::AxisEntity::setThickness | ( | float | thickness | ) |
Sets the thickness of the axis line (in pixels).
thickness | New thickness (must be > 0). |
std::invalid_argument | if thickness <= 0. |
std::runtime_error | if ThicknessComponent is missing. |
void wPlot2D::AxisEntity::setArrowSize | ( | float | arrowSize | ) |
Sets the size of the arrowhead at the end of the axis.
arrowSize | Arrowhead size in pixels. |
void wPlot2D::AxisEntity::addTitle | ( | const std::string & | title | ) |
Adds a title to the axis.
title | Title string (narrow string). |
void wPlot2D::AxisEntity::addTitle | ( | const std::wstring & | title | ) |
Adds a title to the axis.
title | Title string (wide string). |
void wPlot2D::AxisEntity::setTitleFont | ( | const sf::Font & | font | ) |
Sets the font of the axis title.
font | Reference to an SFML font. |
void wPlot2D::AxisEntity::setTitleCharacterSize | ( | unsigned int | size | ) |
Sets the character size of the axis title.
size | Character size in pixels. |
void wPlot2D::AxisEntity::setTitleColor | ( | sf::Color | newColor | ) |
Sets the color of the axis title.
newColor | New text color. |
void wPlot2D::AxisEntity::setTitleOffset | ( | sf::Vector2f | titleOffset | ) |
Sets a manual offset for the title position.
titleOffset | Pixel offset applied to the title position. |
|
nodiscard |
Gets the current title offset.
void wPlot2D::AxisEntity::addNotches | ( | float | interval, |
NotchPosition | position, | ||
bool | hasLabels = false ) |
Adds notches along the axis.
interval | Logical spacing between notches (> 0). |
position | Placement relative to axis (Center, Above, Below). |
hasLabels | If true, labels are displayed for each notch. |
void wPlot2D::AxisEntity::setNotchesColor | ( | const sf::Color & | color | ) |
Sets the color of all notches.
color | New notch color. |
void wPlot2D::AxisEntity::setNotchesThickness | ( | float | thickness | ) |
Sets the thickness of all notches.
thickness | New thickness in pixels. |
void wPlot2D::AxisEntity::setNotchesLength | ( | float | newLength | ) |
Sets the length of all notches.
newLength | New length in pixels. |
void wPlot2D::AxisEntity::setLabelsFont | ( | const sf::Font & | font | ) |
Sets the font of all labels.
font | Reference to an SFML font. |
void wPlot2D::AxisEntity::setLabelsColor | ( | const sf::Color & | color | ) |
Sets the color of all labels.
color | New text color. |
|
nodiscard |
Gets the current offset of all labels.
void wPlot2D::AxisEntity::setLabelsOffset | ( | sf::Vector2f | offset | ) |
Sets a new offset for all labels.
offset | Offset vector in pixels. |
void wPlot2D::AxisEntity::addLabelsOffset | ( | sf::Vector2f | delta | ) |
Applies an additional offset to all labels.
delta | Delta offset in pixels. |
void wPlot2D::AxisEntity::setLabelsCharacterSize | ( | unsigned int | newSize | ) |
Sets the character size of all labels.
newSize | Character size in pixels. |
void wPlot2D::AxisEntity::setLabelsDecimalPlaces | ( | int | places | ) |
Sets the number of decimal places for numeric labels.
places | Digits after decimal point (>= 0). |
void wPlot2D::AxisEntity::setCustomLabels | ( | const std::vector< std::string > & | labels | ) |
Replaces numeric labels with a custom set of strings.
labels | Vector of user-defined label strings. |
void wPlot2D::AxisEntity::render | ( | sf::RenderWindow & | window | ) |
Renders the axis (line, arrow, title, notches, labels).
window | Target render window. |