-
Notifications
You must be signed in to change notification settings - Fork 0
/
CircleBrush.cpp
70 lines (57 loc) · 1.79 KB
/
CircleBrush.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
//
// CircleBrush.cpp
//
// The implementation of Circle Brush. It is a kind of ImpBrush. All your brush implementations
// will look like the file with the different GL primitive calls.
//
#include "impressionistDoc.h"
#include "impressionistUI.h"
#include "circlebrush.h"
#include <math.h>
extern float frand();
CircleBrush::CircleBrush(ImpressionistDoc* pDoc, char* name) :
ImpBrush(pDoc, name)
{
}
void CircleBrush::BrushBegin(const Point source, const Point target)
{
ImpressionistDoc* pDoc = GetDocument();
ImpressionistUI* dlg = pDoc->m_pUI;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
BrushMove(source, target);
}
void CircleBrush::BrushMove(const Point source, const Point target)
{
ImpressionistDoc* pDoc = GetDocument();
ImpressionistUI* dlg = pDoc->m_pUI;
int size = pDoc->getSize(); // size of circle
double alpha = pDoc->getAlpha();
GLubyte alphaColor[4];
if (pDoc == NULL) {
printf("CircleBrush::BrushMove document is NULL\n");
return;
}
//glBegin(GL_LINE_LOOP);
glBegin(GL_POLYGON); // best
//glBegin(GL_POINTS);
//SetColor(source);
//while(size>=0) // works with points
//{
// setting alpha and color
memcpy(alphaColor, pDoc->GetOriginalPixel(source), 3); // copying the RGB values of the pixel to the first 3 indicies of alphaColor
alphaColor[3] = static_cast<GLubyte>(alpha * 255.0); // setting the last index of alphaColor to the alpha value, casted as a ubyte
glColor4ubv(alphaColor);
for (int radius = 0; radius < 720; radius++) // 720 allows for a nice round circle
{
double area = 3.14 * (radius * radius); // pi * r^2
glVertex2d(target.x + size * cos(area), target.y + size * sin(area));
}
//size--; // works with points
//}
glEnd();
}
void CircleBrush::BrushEnd(const Point source, const Point target)
{
// do nothing so far
}