Smolgui
Immediate gui library based on SFML
Loading...
Searching...
No Matches
Plotter.h
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include <SFML/Graphics/RenderTarget.hpp>
5#include <SFML/Graphics/RenderWindow.hpp>
6
8
9namespace sgui
10{
14struct PlotRange {
15 PlotRange () = default;
16 PlotRange (const float mi, const float ma)
17 : min (mi), max (ma) {}
18 float min = 0.f;
19 float max = 1.f;
20};
21
22
26class Plotter : public sf::Drawable, public sf::Transformable
27{
28public:
33 void setSample (const uint32_t sample);
37 void unsetBound ();
41 void setBound (const sf::Vector2f& plotBound);
46 void setBorderTick (const uint32_t count);
51 void setBorderWidth (const float thickness);
56 void setBorderColor (const sf::Color& color);
60 void clear ();
68 void plot (const std::function<float (float)>& slope, const sf::Vector2f& position, const sf::Color& lineColor, const float thickness = 1.f);
76 void plot (const std::function<sf::Vector2f (float)>& slope, const sf::Vector2f& position, const sf::Color& lineColor, const float thickness = 1.f);
84 void plot (const std::vector <sf::Vector2f>& points, const sf::Vector2f& position, const sf::Color& lineColor, const float thickness);
85public:
89private:
90 // to remap value in the draw area
91 sf::Vector2f toPlot (const float pointX, const float pointY) const;
92 sf::Vector2f toPlot (const sf::Vector2f& point) const;
93 // plot boundaries and axes for bounded plot
94 void drawBorderAndAxes (const sf::Vector2f& position);
95 // draw all function plotted
96 void draw (sf::RenderTarget& target, sf::RenderStates states) const override;
97private:
98 bool mBounded = false;
99 uint32_t mSample = 50;
100 uint32_t mBorderTick = 5;
101 float mBorderWidth = 4.f;
102 sf::Vector2f mBound = {};
103 sf::Color mBorderColor = sf::Color::White;
104};
105
106} // namespace sgui
plot function in a given range and level of sampling.
Definition Plotter.h:27
void setBorderTick(const uint32_t count)
set border rendering for bounded plot
Definition Plotter.cpp:26
void setBorderColor(const sf::Color &color)
set color of the border
Definition Plotter.cpp:38
void setSample(const uint32_t sample)
set points to sample function, default is 50 points.
Definition Plotter.cpp:7
PrimitiveShapeRender render
Render used.
Definition Plotter.h:88
PlotRange xRange
Plot range along x.
Definition Plotter.h:86
void setBound(const sf::Vector2f &plotBound)
set bound in which the function will be drawn
Definition Plotter.cpp:19
void unsetBound()
unset bound size of the plot
Definition Plotter.cpp:13
void clear()
clear all plotted function
Definition Plotter.cpp:44
PlotRange yRange
Plot range along y.
Definition Plotter.h:87
void setBorderWidth(const float thickness)
set border widtj
Definition Plotter.cpp:32
void plot(const std::function< float(float)> &slope, const sf::Vector2f &position, const sf::Color &lineColor, const float thickness=1.f)
plot a function y = f(x)
Definition Plotter.cpp:50
render primitive shapes using vertex array.
Definition PrimitiveShapeRender.h:16
Definition Interpolation.h:16
plot range for an axis
Definition Plotter.h:14
float max
Maximum of the range.
Definition Plotter.h:19
PlotRange()=default
PlotRange(const float mi, const float ma)
Definition Plotter.h:16
float min
Minimum of the range.
Definition Plotter.h:18