-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLinesBrush.cpp
179 lines (144 loc) · 4.59 KB
/
LinesBrush.cpp
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include "LinesBrush.h"
#include "impressionistDoc.h"
#include "impressionistUI.h"
#include <cmath>
#include "PaintView.h"
extern float frand();
LinesBrush::LinesBrush(ImpressionistDoc* pDoc, char* name) :
ImpBrush(pDoc, name)
{
}
void LinesBrush::BrushBegin(const Point source, const Point target , int DirectionType)
{
ImpressionistDoc* pDoc = GetDocument();
ImpressionistUI* dlg = pDoc->m_pUI;
int size = pDoc->getSize();
int lineWidth = pDoc->getLineWidth();
int lineAngle = pDoc->getLineAngle();
glLineWidth((float)lineWidth);
//glRotatef(lineAngle, 0.0, 0.0, 1.0);
BrushMove(source, target, DirectionType);
}
void LinesBrush::BrushMove(const Point source, const Point target, int DirectionType)
{
ImpressionistDoc* pDoc = GetDocument();
ImpressionistUI* dlg = pDoc->m_pUI;
Blend();
if (pDoc == NULL) {
printf("LineBrush::BrushMove document is NULL\n");
return;
}
int size;
int lineAngle;
int* temp = getGradient(source);
/*
if (DirectionType == 0 || DirectionType == 1 || pDoc->m_pDirectionType == 0 || pDoc->m_pDirectionType == 1) {
switch (pDoc->m_pDirectionType) {
case 0://right mouse
size = pDoc->getSize();
lineAngle = pDoc->getLineAngle();
break;
case 1://gradient
size = pDoc->getSize();
int dx = temp[0];
int dy = temp[1];
lineAngle = atan2(-dy, dx) * 180 / M_PI;
if (lineAngle < 0)
lineAngle += 360;
break;
}
}
*/
if (DirectionType == 0 || pDoc->m_pDirectionType == 0) {
size = pDoc->getSize();
lineAngle = pDoc->getLineAngle();
glBegin(GL_LINES);
SetColor(source);
glVertex2d(source.x - size / 2 * cos(lineAngle * M_PI / 180), source.y - size / 2 * sin(lineAngle * M_PI / 180));
glVertex2d(target.x + size / 2 * cos(lineAngle * M_PI / 180), target.y + size / 2 * sin(lineAngle * M_PI / 180));
glEnd();
delete[] temp;
return;
}
if (DirectionType == 1 || pDoc->m_pDirectionType == 1) {
size = pDoc->getSize();
int dx = temp[0];
int dy = temp[1];
lineAngle = atan2(-dy, dx) * 180 / M_PI;
if (lineAngle < 0)
lineAngle += 360;
glBegin(GL_LINES);
SetColor(source);
glVertex2d(source.x - size / 2 * cos(lineAngle * M_PI / 180), source.y - size / 2 * sin(lineAngle * M_PI / 180));
glVertex2d(target.x + size / 2 * cos(lineAngle * M_PI / 180), target.y + size / 2 * sin(lineAngle * M_PI / 180));
glEnd();
delete[] temp;
return;
}
if (DirectionType == 2) //brush direction choice
{
DirectionBrush(source, target);
}
else
{
if (pDoc == NULL) {
printf("LineBrush::BrushMove document is NULL\n");
return;
}
int size = pDoc->getSize();
int lineAngle = pDoc->getLineAngle();
glBegin(GL_LINES);
SetColor(source);
glVertex2d(source.x - size / 2 * cos(lineAngle * M_PI / 180), source.y - size / 2 * sin(lineAngle * M_PI / 180));
glVertex2d(target.x + size / 2 * cos(lineAngle * M_PI / 180), target.y + size / 2 * sin(lineAngle * M_PI / 180));
glEnd();
}
}
void LinesBrush::BrushEnd(const Point source, const Point target)
{
// do nothing so far
}
void LinesBrush::DirectionBrush(const Point source, const Point target)
{
ImpressionistDoc* pDoc = GetDocument();
ImpressionistUI* dlg = pDoc->m_pUI;
if (pDoc == NULL) {
printf("LineBrush::BrushMove document is NULL\n");
return;
}
int size = pDoc->getSize();
int lineAngle = pDoc->getLineAngle();
glBegin(GL_LINES);
while (flag)
{
pre_x = target.x;
pre_y = target.y;
flag = false;
glVertex2d(source.x - size / 2, source.y);
glVertex2d(source.x+ size / 2, source.y);
}
SetColor(source);
if (target.y - pre_y == 0)
{
glVertex2d(source.x - size / 2, source.y);
glVertex2d(source.x + size / 2, source.y);
}
else if (target.x - pre_x == 0)
{
glVertex2d(source.x, source.y - size / 2);
glVertex2d(source.x, source.y + size / 2);
}
else if ((target.y - pre_y) / (target.x - pre_x) < 0)
{
glVertex2d(source.x + size / 2 * (cos(atan(abs((target.y - pre_y) / (target.x - pre_x))))) , source.y - size / 2 * (sin(atan(abs((target.y - pre_y) / (target.x - pre_x))))) );
glVertex2d(source.x - size / 2 * (cos(atan(abs((target.y - pre_y) / (target.x - pre_x))))) , source.y + size / 2 * (sin(atan(abs((target.y - pre_y) / (target.x - pre_x))))) );
}
else if ((target.y - pre_y) / (target.x - pre_x) > 0)
{
glVertex2d(source.x - size / 2 * (cos(atan(abs((target.y - pre_y) / (target.x - pre_x))))) , source.y - size / 2 * (sin(atan(abs((target.y - pre_y) / (target.x - pre_x))))) );
glVertex2d(source.x + size / 2 * (cos(atan(abs((target.y - pre_y) / (target.x - pre_x))))) , source.y + size / 2 * (sin(atan(abs((target.y - pre_y) / (target.x - pre_x))))) );
}
pre_x = target.x;
pre_y = target.y;
glEnd();
}