-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWidget.hpp
More file actions
60 lines (50 loc) · 1.54 KB
/
Widget.hpp
File metadata and controls
60 lines (50 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef WIDGET
#define WIDGET
#include "graphics.h"
#include "led-matrix.h"
#include "nlohmann/json.hpp"
#include <ctime>
#include <SFML/System.hpp>
using json = nlohmann::json;
// Needs copy constructors and stuff
enum Size{
SMALL,
MEDIUM,
LARGE
};
enum WidgetID{
NONE,
TIMECLOCK
};
class Widget {
public:
Widget(sf::Vector2<size_t> &p);
Widget(size_t x, size_t y);
void ToggleActive(){_isActive = !_isActive;}
void SetPosition(sf::Vector2<size_t> &p) {_position = p;}
void SetPosition(size_t x, size_t y) {_position.x = x; _position.y = y;}
sf::Vector2<size_t>& GetPosition() {return _position;}
virtual void Draw(rgb_matrix::Canvas* c);
virtual void InitializeWidgetFromJson(json j, int index);
private:
sf::Vector2<size_t> _position; // Top left corner - Text doesn bottom left
bool _isActive;
};
class TimeClock: public Widget {
public:
TimeClock();
TimeClock(size_t x, size_t y);
TimeClock(size_t x, size_t y, rgb_matrix::Color& color);
TimeClock(size_t x, size_t y, uint r, uint g, uint b);
std::string GetHourMinute() const;
std::string GetMonthDayYear() const;
void SetSize(Size s);
void Draw(rgb_matrix::Canvas* c) override;
void InitializeWidgetFromJson(json j, int index) override;
private:
rgb_matrix::Color _color;
rgb_matrix::Font _font, _dateFont;
Size _clockSize = MEDIUM;
int _letterSpacing = 0, _dateLetterSpacing = 0;
};
#endif