-
Notifications
You must be signed in to change notification settings - Fork 1
/
cairowidget.hpp
54 lines (37 loc) · 967 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 "FL/Fl_Widget.H"
#include <functional>
struct _cairo;
class CairoWidget: public Fl_Widget
{
struct S;
_cairo* cr_{};
int w_{}, h_;
unsigned char* d_;
unsigned pixels_;
using draw_t = std::function<void(_cairo*, int, int)>;
draw_t df_;
draw_t if_;
void draw() final;
public:
CairoWidget(int, int, int, int, const char* = nullptr);
~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_); }
};
//////////////////////////////////////////////////////////////////////////////
inline auto& CairoWidget::draw() const noexcept { return df_; }
#endif // CAIROWIDGET_HPP