TouchCPLib  1.0.0
A touch-enabled GUI interface based on SDL and libTS. It provides a simple desktop-free UI for your embedded Raspberry projects.
XYPlot.h
Go to the documentation of this file.
1 #pragma once
2 
13 #include <vector>
14 #include <cassert>
15 #include "Application.h"
17 #include "Point.h"
18 #include "Rect.h"
19 #include "Color.h"
20 #include "Optional.h"
21 
26 {
27 public:
28  XYPlot();
29  ~XYPlot();
35  void setData(const std::vector<float>& xValues, const std::vector<float>& yValues);
40  void setXMinMax(const Optional<std::pair<float, float>>& xMinMax);
45  void setYXMinMax(const Optional<std::pair<float, float>>& yMinMax);
50  void setGeometry(Rect r);
55  void setBackgroundColor(const Color bgColor);
60  void setLineColor(const Color lnColor);
61  void draw(uint32_t time) override;
62  int getX() const override;
63  int getY() const override;
64  int getWidth() const override;
65  int getHeight() const override;
66 private:
67  void buildPoints();
68  SDL_Renderer* renderer = nullptr;
69  std::vector<float> xValues, yValues;
70  std::vector<SDL_Point> renderedPoints;
71  Rect geometry = { 0, 0, 0, 0 };
72  Color backgroundColor, lineColor;
75 };
76 
void setYXMinMax(const Optional< std::pair< float, float >> &yMinMax)
Set the Y axis minimum and maximum. If unset, it will use the minimum and maximum from the dataset...
Definition: XYPlot.cpp:27
XYPlot()
Definition: XYPlot.cpp:3
The main application class header.
void setData(const std::vector< float > &xValues, const std::vector< float > &yValues)
Set the data points.
Definition: XYPlot.cpp:12
void setXMinMax(const Optional< std::pair< float, float >> &xMinMax)
Set the X axis minimum and maximum. If unset, it will use the minimum and maximum from the dataset...
Definition: XYPlot.cpp:21
Definition: Color.h:16
void setLineColor(const Color lnColor)
Set the points color (it will also be used for the chart outline)
Definition: XYPlot.cpp:44
int getY() const override
Definition: XYPlot.cpp:77
void draw(uint32_t time) override
The draw method. It will be called once per frame for each object in a scene.
Definition: XYPlot.cpp:49
void setBackgroundColor(const Color bgColor)
Set the background color.
Definition: XYPlot.cpp:39
An abstract class implementing both the GraphicsObject and the TouchEnabledObject, which gives an interactive graphic object as result.
Definition: InteractiveGraphicsObject.h:20
int getWidth() const override
Definition: XYPlot.cpp:82
~XYPlot()
Definition: XYPlot.cpp:8
A class that wraps a value that can be null.
Definition: Optional.h:21
int getX() const override
Definition: XYPlot.cpp:72
A color wrapper.
A chart displaying X,Y points, scaled to the object geomtry.
Definition: XYPlot.h:25
int getHeight() const override
Definition: XYPlot.cpp:87
Definition: Rect.h:17
void setGeometry(Rect r)
Set the chart geometry (position and size)
Definition: XYPlot.cpp:33