-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAlphaMapBrush.cpp
109 lines (86 loc) · 2.33 KB
/
AlphaMapBrush.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
//
// AlphaMapBrush.cpp
//
// The implementation of Alpha Map 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 "AlphaMapBrush.h"
#include <iostream>
using namespace std;
extern float frand();
AlphaMapBrush::AlphaMapBrush(ImpressionistDoc* pDoc, char* name) :
ImpBrush(pDoc, name)
{
}
void AlphaMapBrush::BrushBegin(const Point source, const Point target)
{
ImpressionistDoc* pDoc = GetDocument();
if (pDoc->m_ucAlphamap == NULL) {
fl_alert("Pleas load an alpha map first!!!!");
return;
}
ImpressionistUI* dlg = pDoc->m_pUI;
if (!dlg->getEnableAutoDraw())
saveState();
glPointSize(1);
BrushMove(source, target);
}
void AlphaMapBrush::BrushMove(const Point source, const Point target)
{
ImpressionistDoc* pDoc = GetDocument();
ImpressionistUI* dlg = pDoc->m_pUI;
if (pDoc == NULL) {
printf("AlphaMapBrush::BrushMove document is NULL\n");
return;
}
int x = target.x;
int y = target.y;
int startCol = dlg->m_paintView->getStartCol();
int startRow = dlg->m_paintView->getStartRow() + dlg->m_mainWindow->h() - dlg->m_paintView->getDrawHeight() - 25;
//int startRow = 0;
int endCol = dlg->m_paintView->getEndCol();
int endRow = startRow + dlg->m_paintView->getDrawHeight();
if (x < startCol) {
x = startCol;
}
if (x > endCol) {
x = endCol;
}
if (y < startRow) {
y = startRow;
}
if (y > endRow) {
y = endRow;
}
int height = pDoc->m_nAlphaMapHeight;
int width = pDoc->m_nAlphaMapWidth;
//cout << width << "," << height << endl;
unsigned char* alphaMap = pDoc->m_ucAlphamap;
int beginY = -(height / 2);
int beginX = -(width / 2);
int endY = beginY + height;
int endX = beginX + width;
GLubyte color[4];
memcpy(color, pDoc->GetOriginalPixel(source), 3);
glBegin(GL_POINTS);
for (int i = beginY; i < endY; i++) {
for (int j = beginX; j < endX; j++) {
color[3] = GLubyte(alphaMap[width*(i - beginY) + j - beginX])*pDoc->getAlpha();
glColor4ubv(color);
if ((x + j) > startCol && (x + j) < endCol) {
if((y+i)>startRow&&(y+i)<endRow)
glVertex2d(x + j, y + i);
}
}
}
glEnd();
}
void AlphaMapBrush::BrushEnd(const Point source, const Point target)
{
// do nothing so far
}
char* AlphaMapBrush::BrushName(void) {
return ImpBrush::BrushName();
}