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 pathArcBrush.hpp
96 lines (82 loc) · 2.66 KB
/
ArcBrush.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
#if !defined(__ARC_BRUSH__)
#define __ARC_BRUSH__
#include "ImageUtils.hpp"
#include "ImpBrush.h"
#include "gl_helper.h"
#include "impressionistDoc.h"
#include "impressionistUI.h"
using namespace GLHelper;
class ArcBrush : public ImpBrush {
Point last;
double radius;
public:
ArcBrush(ImpressionistDoc *pDoc = NULL, char *name = NULL)
: ImpBrush(pDoc, name) {}
void BrushBegin(const Point source, const Point target, int rad,
GLubyte *color) {
ImpressionistDoc *pDoc = GetDocument();
last = target;
const int width = pDoc->getWidth();
glPointSize(width);
BrushMove(source, target);
}
void BrushMove(const Point source, const Point target,
GLubyte *color = nullptr, bool randomize = false) {
ImpressionistDoc *pDoc = GetDocument();
auto &img = pDoc->m_pUI->m_paintView->cur;
if (source.x <= 0 || source.x >= img.width || source.y <= 0 ||
source.y >= img.height) {
printf("Go back in\n"); // TODO - Remove
return;
}
radius = pDoc->getSize();
float r = pDoc->getRad();
switch (pDoc->m_pUI->get_direction()) {
case GRADIENT_DIRECTION: {
auto result = ImageUtils::sobel(pDoc->m_pUI->m_origView->original_img,
target.y, target.x);
r = get<2>(result);
} break;
case BRUSH_DIRECTION: {
r = target / last;
} break;
}
if (isnan(r))
return;
if (randomize && frand() >= 0.75)
RandomizeAttributes();
float offset_x = cos(r) * radius;
float offset_y = sin(r) * radius;
Point center(target.x + offset_x, target.y + offset_y);
gl_draw_shape(GL_POINTS, [&] {
SetColor(source);
for (double i = 0; i <= M_PI / 2; i += 0.01) {
double angle = i + r;
double dx = cos(angle) * radius;
double dy = sin(angle) * radius;
Point cur(center.x + dx, center.y + dy);
cur = pDoc->clip(cur);
gl_set_point(cur.x, cur.y);
}
});
pDoc->force_update_canvas();
}
void BrushEnd(const Point source, const Point target) {}
void RandomizeAttributes() {
glPointSize(irand(20));
radius = irand(20);
}
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();
pDoc->m_pUI->m_BrushCurvatureSlider->deactivate();
}
};
#endif // __ARC_BRUSH__