forked from blackhole89/notekit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawing.h
69 lines (54 loc) · 1.8 KB
/
drawing.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
#ifndef DRAWING_H
#define DRAWING_H
#include <gtkmm.h>
#include <set>
#include <vector>
#include <unordered_map>
class CStroke {
public:
float r,g,b,a;
std::vector<float> xcoords;
std::vector<float> ycoords;
std::vector<float> pcoords;
void Reset();
void Append(float x, float y, float p);
void GetHead(float &x, float &y);
float GetHeadCurvatureWrt(float x, float y);
void Simplify();
void Render(const Cairo::RefPtr<Cairo::Context> &ctx, float basex, float basey, int start_index=1);
void GetBBox(float &x0, float &x1, float &y0, float &y1, int start_index=0);
};
class CBoundDrawing : public Gtk::DrawingArea
{
public:
CBoundDrawing(Glib::RefPtr<Gdk::Window> wnd);
std::vector<CStroke> strokes;
/* accelerator structure for quickly finding strokes e.g. when erasing */
static const int BUCKET_SIZE = 16;
static constexpr int BUCKET(int x,int y) {
return ((y/BUCKET_SIZE)<<16) + (x/BUCKET_SIZE);
}
struct strokeRef { int index; int offset; };
std::unordered_multimap<int, strokeRef> strokefinder;
int w,h;
bool selected;
Glib::RefPtr<Gdk::Window> target_window;
Cairo::RefPtr<Cairo::Surface> image;
Cairo::RefPtr<Cairo::Context> image_ctx;
void UpdateSize(int w, int h, int dx=0, int dy=0);
void Redraw();
void RebuildStrokefinder();
void RecalculateSize();
void AddStroke(CStroke &s, float dx, float dy);
void EraseAt(float x, float y, float radius, bool whole_stroke);
virtual bool on_button_press_event(GdkEventButton* event);
virtual bool on_button_release_event(GdkEventButton* event);
virtual bool on_motion_notify_event(GdkEventMotion* event);
virtual bool on_draw(const Cairo::RefPtr<Cairo::Context> &ctx);
virtual void on_unrealize();
virtual void destroy_notify_();
std::string Serialize();
std::string SerializePNG();
void Deserialize(std::string input);
};
#endif