wPlot2D version: 0.1.0
A lightweight C++ library for clear and customizable 2D scientific plots.
Loading...
Searching...
No Matches
wAxisEntity.hpp
Go to the documentation of this file.
1/*
2+---------------------------------------------------------------------------------------------------------------------------------------------------+
3Created by Wilfried Koch.
4Copyright @ 2025 Wilfried Koch. All rights reserved.
5+---------------------------------------------------------------------------------------------------------------------------------------------------+
6*/
7
8#ifndef W_AXIS_ENTITY_HPP
9#define W_AXIS_ENTITY_HPP
10
13
14#include "wLineEntity.hpp"
15#include "wNotchEntity.hpp"
16#include "wTitleEntity.hpp"
17#include "wLabelEntity.hpp"
18
19#pragma GCC diagnostic push
20#pragma GCC diagnostic ignored "-Wfloat-equal"
21#pragma GCC diagnostic ignored "-Wswitch-default"
22#include <SFML/Graphics.hpp>
23#pragma GCC diagnostic pop
24
25#include <vector>
26
27namespace wPlot2D
28{
29
34 enum class AxisType
35 {
38 };
39
44 enum class NotchPosition
45 {
49 };
50
67 {
68 public:
78 AxisEntity( sf::Font& font, sf::Vector2f origin, sf::Vector2f scale, sf::Vector2f offset, AxisType type, sf::Vector2f axisRange );
79
83 virtual ~AxisEntity( ) = default;
84
90 void setColor( sf::Color color );
91
98 void setThickness( float thickness );
99
104 void setArrowSize( float arrowSize );
105
110 void addTitle( const std::string& title );
111
116 void addTitle( const std::wstring& title );
117
122 void setTitleFont( const sf::Font& font );
123
128 void setTitleCharacterSize( unsigned int size );
129
134 void setTitleColor( sf::Color newColor );
135
140 void setTitleOffset( sf::Vector2f titleOffset );
141
146 [[nodiscard]] sf::Vector2f getTitleOffset( ) const;
147
154 void addNotches( float interval, NotchPosition position, bool hasLabels = false );
155
160 void setNotchesColor( const sf::Color& color );
161
166 void setNotchesThickness( float thickness );
167
172 void setNotchesLength( float newLength );
173
178 void setLabelsFont( const sf::Font& font );
179
184 void setLabelsColor( const sf::Color& color );
185
190 [[nodiscard]] std::vector< sf::Vector2f > getLabelsOffset( ) const;
191
196 void setLabelsOffset( sf::Vector2f offset );
197
202 void addLabelsOffset( sf::Vector2f delta );
203
208 void setLabelsCharacterSize( unsigned int newSize );
209
214 void setLabelsDecimalPlaces( int places );
215
220 void setCustomLabels( const std::vector< std::string >& labels );
221
226 void render( sf::RenderWindow& window );
227 private:
228 sf::Font& mTitleFont;
229 sf::Font& mLabelsFont;
230 AxisType mAxisType;
231 sf::Vector2f mAxisRange;
232 std::unique_ptr< LineEntity > mAxisLine;
233 float mArrowSize;
234
235 std::vector< std::unique_ptr< NotchEntity > > mNotches;
236 NotchPosition mNotchPosition;
237
238 std::unique_ptr< TitleEntity > mTitle;
239
240 bool mHasLabels;
241 std::vector< std::unique_ptr< LabelEntity > > mLabels;
242
246 void construct( );
247
251 template < typename T >
252 void initTitle( const T& title );
253
257 void initNotches( );
258 };
259
260}//End of namespace wPlot2D
261
262#endif
Represents an entity in the ECS (Entity-Component System) architecture.
Definition wEntity.hpp:60
void setTitleOffset(sf::Vector2f titleOffset)
Sets a manual offset for the title position.
Definition wAxisEntity.cpp:72
void setLabelsCharacterSize(unsigned int newSize)
Sets the character size of all labels.
Definition wAxisEntity.cpp:261
void setTitleFont(const sf::Font &font)
Sets the font of the axis title.
Definition wAxisEntity.cpp:89
void addLabelsOffset(sf::Vector2f delta)
Applies an additional offset to all labels.
Definition wAxisEntity.cpp:252
void render(sf::RenderWindow &window)
Renders the axis (line, arrow, title, notches, labels).
Definition wAxisEntity.cpp:302
void setColor(sf::Color color)
Sets the color of the axis line.
Definition wAxisEntity.cpp:49
void setLabelsColor(const sf::Color &color)
Sets the color of all labels.
Definition wAxisEntity.cpp:221
std::vector< sf::Vector2f > getLabelsOffset() const
Gets the current offset of all labels.
Definition wAxisEntity.cpp:230
void setThickness(float thickness)
Sets the thickness of the axis line (in pixels).
Definition wAxisEntity.cpp:55
void setLabelsDecimalPlaces(int places)
Sets the number of decimal places for numeric labels.
Definition wAxisEntity.cpp:269
void setNotchesThickness(float thickness)
Sets the thickness of all notches.
Definition wAxisEntity.cpp:125
void setLabelsOffset(sf::Vector2f offset)
Sets a new offset for all labels.
Definition wAxisEntity.cpp:243
void setNotchesLength(float newLength)
Sets the length of all notches.
Definition wAxisEntity.cpp:150
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.
Definition wAxisEntity.cpp:25
void setArrowSize(float arrowSize)
Sets the size of the arrowhead at the end of the axis.
Definition wAxisEntity.cpp:61
void setTitleColor(sf::Color newColor)
Sets the color of the axis title.
Definition wAxisEntity.cpp:94
void setCustomLabels(const std::vector< std::string > &labels)
Replaces numeric labels with a custom set of strings.
Definition wAxisEntity.cpp:277
sf::Vector2f getTitleOffset() const
Gets the current title offset.
Definition wAxisEntity.cpp:78
void setLabelsFont(const sf::Font &font)
Sets the font of all labels.
Definition wAxisEntity.cpp:213
virtual ~AxisEntity()=default
Virtual destructor.
void addTitle(const std::string &title)
Adds a title to the axis.
Definition wAxisEntity.cpp:372
void setTitleCharacterSize(unsigned int size)
Sets the character size of the axis title.
Definition wAxisEntity.cpp:84
void addNotches(float interval, NotchPosition position, bool hasLabels=false)
Adds notches along the axis.
Definition wAxisEntity.cpp:106
void setNotchesColor(const sf::Color &color)
Sets the color of all notches.
Definition wAxisEntity.cpp:116
Definition wAxisEntity.cpp:17
AxisType
Enum representing the type of axis to render.
Definition wAxisEntity.hpp:35
@ X_AXIS
Definition wAxisEntity.hpp:36
@ Y_AXIS
Definition wAxisEntity.hpp:37
NotchPosition
Enum controlling the visual placement of notches relative to the axis.
Definition wAxisEntity.hpp:45
@ Center
Definition wAxisEntity.hpp:46
@ Above
Definition wAxisEntity.hpp:47
@ Below
Definition wAxisEntity.hpp:48