forked from CURTLab/LVGLBuilder
-
Notifications
You must be signed in to change notification settings - Fork 18
/
LVGLCore.h
165 lines (129 loc) · 4.41 KB
/
LVGLCore.h
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#ifndef LVGLCORE_HPP
#define LVGLCORE_HPP
#include <lvgl/lvgl.h>
#include <QElapsedTimer>
#include <QHash>
#include <QList>
#include <QObject>
#include <QPixmap>
#include <QTimer>
#include "LVGLImageData.h"
#include "widgets/LVGLWidget.h"
class LVGLObject;
class LVGLFontData;
class LVGLCore : public QObject {
Q_OBJECT
public:
LVGLCore(QObject *parent = nullptr);
~LVGLCore();
void init(int width, int height);
bool changeResolution(QSize size);
QPixmap framebuffer() const;
QPixmap grab(const QRect ®ion) const;
LVGLObject *findByName(const QString &name);
int width() const;
int height() const;
QSize size() const;
LVGLImageData *addImage(QImage image, QString name);
LVGLImageData *addImage(QString fileName, QString name = QString());
void addImage(LVGLImageData *image);
QStringList imageNames() const;
QList<LVGLImageData *> images() const;
lv_img_dsc_t *image(QString name);
lv_img_dsc_t *defaultImage() const;
QString nameByImage(const lv_img_dsc_t *img_dsc) const;
LVGLImageData *imageByDesc(const lv_img_dsc_t *img_dsc) const;
bool removeImage(LVGLImageData *img);
void removeAllImages();
QStringList symbolNames() const;
const char *symbol(const QString &name) const;
void poll();
void objsclear();
void sendMouseEvent(int x, int y, bool pressed);
QPoint get_absolute_position(const lv_obj_t *lv_obj) const;
QSize get_object_size(const lv_obj_t *lv_obj) const;
QRect get_object_rect(const lv_obj_t *lv_obj) const;
void addObject(LVGLObject *object);
void removeObject(LVGLObject *object);
void removeAllObjects();
void setAllObjects(QList<LVGLObject *> objs) { m_objects = objs; }
QList<LVGLObject *> allObjects() const;
QList<LVGLObject *> topLevelObjects() const;
QList<LVGLObject *> objectsByType(QString className) const;
LVGLObject *object(QString name) const;
LVGLObject *object(lv_obj_t *obj) const;
QColor toColor(lv_color_t c) const;
lv_color_t fromColor(QColor c) const;
lv_color_t fromColor(QVariant v) const;
QJsonObject colorToJson(lv_color_t c) const;
lv_color_t colorFromJson(QJsonObject obj) const;
LVGLFontData *addFont(const QString &fileName, uint8_t size);
void addFont(LVGLFontData *font);
bool removeFont(LVGLFontData *font);
QStringList fontNames() const;
QStringList fontCodeNames() const;
const lv_font_t *font(int index) const;
const lv_font_t *font(const QString &name,
Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
int indexOfFont(const lv_font_t *font) const;
QString fontName(const lv_font_t *font) const;
QString fontCodeName(const lv_font_t *font) const;
QList<const LVGLFontData *> customFonts() const;
void removeCustomFonts();
QString baseStyleName(const lv_style_t *style) const;
void setScreenColor(QColor color);
QColor screenColor() const;
bool screenColorChanged() const;
QList<const LVGLWidget *> widgets() const;
const LVGLWidget *widget(const QString &name) const;
static const char *DEFAULT_DAYS[7];
static const char *DEFAULT_MONTHS[12];
private slots:
void tick();
private:
void addWidget(LVGLWidget *w);
void flushHandler(lv_disp_drv_t *disp, const lv_area_t *area,
lv_color_t *color_p);
bool inputHandler(lv_indev_drv_t *indev_driver, lv_indev_data_t *data);
static void flushCb(lv_disp_drv_t *disp, const lv_area_t *area,
lv_color_t *color_p);
static bool inputCb(lv_indev_drv_t *indev_driver, lv_indev_data_t *data);
static void logCb(lv_log_level_t level, const char *file, uint32_t line,
const char *dsc);
QTimer m_timer;
QElapsedTimer m_time;
QHash<QString, LVGLImageData *> m_images;
QHash<QString, const LVGLWidget *> m_widgets;
LVGLImageData *m_default;
QList<LVGLObject *> m_objects;
QList<LVGLFontData *> m_fonts;
lv_style_t m_screenStyle;
const LVGLFontData *m_defaultFont;
std::vector<lv_color_t> m_dispFrameBuf;
std::vector<lv_color_t> m_buf1;
std::vector<lv_color_t> m_buf2;
lv_disp_buf_t m_dispBuf;
lv_disp_drv_t m_dispDrv;
lv_indev_data_t m_inputData;
struct FT_LibraryRec_ *m_ft;
friend class LVGLFontData;
};
extern LVGLCore lvgl;
// cast helpers for internal models
union LVGLImageDataCast {
LVGLImageData *ptr;
qintptr i;
};
union LVGLFontDataCast {
LVGLFontData *ptr;
qintptr i;
};
union LVGLWidgetCast {
LVGLWidget *ptr;
qintptr i;
};
union LVGLObjectCast {
LVGLObject *ptr;
qintptr i;
};
#endif // LVGLCORE_HPP