-
Notifications
You must be signed in to change notification settings - Fork 1
/
cairoglwindow.hpp
59 lines (43 loc) · 1.27 KB
/
cairoglwindow.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
55
56
57
58
59
#ifndef CAIROGLWINDOW_HPP
# define CAIROGLWINDOW_HPP
# pragma once
#include "cairo.h"
#include "FL/Fl_Gl_Window.H"
#include <functional>
class Cairo_Gl_Window: public Fl_Gl_Window
{
struct S;
cairo_t* cr_{};
cairo_surface_t* surf_;
using draw_t = std::function<void(cairo_t*, int, int)>;
draw_t d_{[](auto, auto, auto) noexcept {}};
draw_t i_{[](auto const cr, auto, auto) noexcept
{
cairo_set_line_width(cr, 1.);
cairo_translate(cr, .5, .5);
}
};
void draw() final;
public:
Cairo_Gl_Window(int, int, const char* = nullptr);
Cairo_Gl_Window(int, int, int, int, const char* = nullptr);
~Cairo_Gl_Window();
//
auto ctx() const noexcept;
template <class U>
void init(U&& u) noexcept(noexcept(i_ = std::forward<U>(u)))
{
i_ = std::forward<U>(u);
}
auto& draw() const noexcept;
template <class U>
void draw(U&& u) noexcept(noexcept(d_ = std::forward<U>(u)))
{
d_ = std::forward<U>(u);
}
};
//////////////////////////////////////////////////////////////////////////////
inline auto Cairo_Gl_Window::ctx() const noexcept { return cr_; }
//////////////////////////////////////////////////////////////////////////////
inline auto& Cairo_Gl_Window::draw() const noexcept { return d_; }
#endif // CAIROWINDOW_HPP