-
Notifications
You must be signed in to change notification settings - Fork 1
/
CairoWidget.hpp
54 lines (38 loc) · 982 Bytes
/
CairoWidget.hpp
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
#ifndef CAIROWIDGET_HPP
# define CAIROWIDGET_HPP
# pragma once
#include <QWidget>
#include <functional>
struct _cairo;
class CairoWidget: public QWidget
{
struct S;
_cairo* cr_{};
int w_{}, h_;
unsigned char* d_;
int stride_;
using draw_t = std::function<void(_cairo*, int, int)>;
draw_t df_;
draw_t if_;
public:
explicit CairoWidget(QWidget* = {}, Qt::WindowFlags = {});
~CairoWidget() override;
//
template <class U>
void init(U&& u) noexcept(noexcept(if_ = std::forward<U>(u)))
{
if_ = std::forward<U>(u);
}
auto& draw() const noexcept;
template <class U>
void draw(U&& u) noexcept(noexcept(df_ = std::forward<U>(u)))
{
df_ = std::forward<U>(u);
}
void reinit() { if (cr_) if_(cr_, w_, h_); }
private:
void paintEvent(QPaintEvent*) final;
};
//////////////////////////////////////////////////////////////////////////////
inline auto& CairoWidget::draw() const noexcept { return df_; }
#endif // CAIROWIDGET_HPP