This repository has been archived by the owner on Apr 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLineBrush.hpp
103 lines (84 loc) · 2.91 KB
/
LineBrush.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
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
#if !defined(__LINE_BRUSH_H__)
#define __LINE_BRUSH_H__
#include "ImageUtils.hpp"
#include "ImpBrush.h"
#include "gl_helper.h"
#include "impressionistDoc.h"
#include "impressionistUI.h"
#include <cmath>
using namespace GLHelper;
class LineBrush : public ImpBrush {
Point last;
public:
LineBrush(ImpressionistDoc *pDoc = NULL, char *name = NULL)
: ImpBrush(pDoc, name) {}
void BrushBegin(const Point source, const Point target, int rad, GLubyte* color) {
ImpressionistDoc *pDoc = GetDocument();
ImpressionistUI *dlg = pDoc->m_pUI;
last = target;
int size = pDoc->getSize();
int width = pDoc->getWidth();
glLineWidth(width);
BrushMove(source, target);
}
void BrushMove(const Point source, const Point target, GLubyte* color = nullptr, bool randomize = false) {
ImpressionistDoc *pDoc = GetDocument();
if (source.x <= 0 || source.x >= pDoc->m_nPaintWidth || source.y <= 0 ||
source.y >= pDoc->m_nPaintHeight) {
return;
}
const int half = pDoc->m_pUI->getSize() / 2;
float r = pDoc->getRad();
switch (pDoc->m_pUI->get_direction()) {
case GRADIENT_DIRECTION: {
bool use_another_img = pDoc->m_pUI->m_another_gradient_checkbox->value();
Image &img = use_another_img ? pDoc->another_image
: pDoc->m_pUI->m_origView->original_img;
auto result = ImageUtils::sobel(img, target.y, target.x);
r = get<2>(result) + 3.1415926 / 2;
} break;
case BRUSH_DIRECTION: {
r = target / last;
} break;
}
if (isnan(r))
return;
if (randomize && frand() >= 0.75)
RandomizeAttributes();
gl_draw_shape(GL_LINES, [&] {
SetColor(source);
Point p1 = target + Point::zero().shift_x(-half).rotate(r);
Point p2 = target + Point::zero().shift_x(half).rotate(r);
pDoc->clip(p1);
pDoc->clip(p2);
auto enable = pDoc->m_pUI->m_edge_clipping_checkbox->value();
if (enable) {
debugger("clipping");
p1 = ImageUtils::check_if_hit_edge(target, p1, pDoc->edge_image);
p2 = ImageUtils::check_if_hit_edge(target, p2, pDoc->edge_image);
}
gl_set_point(p1);
gl_set_point(p2);
});
pDoc->force_update_canvas();
last = target;
}
void BrushEnd(const Point source, const Point target) {}
void select() {
ImpressionistDoc *pDoc = GetDocument();
pDoc->m_pUI->m_BrushWidthSlider->activate();
pDoc->m_pUI->m_BrushAngleSlider->activate();
pDoc->m_pUI->m_StrokeDirection->activate();
pDoc->m_pUI->m_BrushSizeSlider->activate();
pDoc->m_pUI->m_BrushAlphaSlider->activate();
pDoc->m_pUI->m_BrushBlurSlider->deactivate();
pDoc->m_pUI->m_ColorBlending->activate();
pDoc->m_pUI->m_MultiResPaint->deactivate();
}
void RandomizeAttributes() {
ImpressionistDoc* pDoc = GetDocument();
int width = pDoc->getWidth();
glLineWidth(irand(width + 5));
}
};
#endif // __LINE_BRUSH_H__