-
Notifications
You must be signed in to change notification settings - Fork 3
/
ImpBrush.cpp
102 lines (86 loc) · 2.31 KB
/
ImpBrush.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
//
// ImpBrush.cpp
//
// The implementation of virtual brush. All the other brushes inherit from it.
//
#include "impressionistDoc.h"
#include "impressionistUI.h"
#include "ImpBrush.h"
// Static class member initializations
int ImpBrush::c_nBrushCount = 0;
ImpBrush** ImpBrush::c_pBrushes = NULL;
const ::Point& Point::operator+=(const Point& point)
{
this->x += point.x;
this->y += point.y;
return *this;
}
ImpBrush::ImpBrush(ImpressionistDoc* pDoc,
char* name) :
m_pDoc(pDoc),
m_pBrushName(name),
m_DirectionType(SLIDER_RIGHT_CLICK)
{
}
//---------------------------------------------------
// Return m_pDoc, which connects the UI and brushes
//---------------------------------------------------
ImpressionistDoc* ImpBrush::GetDocument(void)
{
return m_pDoc;
}
//---------------------------------------------------
// Return the name of the current brush
//---------------------------------------------------
char* ImpBrush::BrushName(void)
{
return m_pBrushName;
}
void ImpBrush::setDirectionType(int type)
{
m_DirectionType = type;
}
//----------------------------------------------------
// Set the color to paint with to the color at source,
// which is the coord at the original window to sample
// the color from
//----------------------------------------------------
void ImpBrush::SetColor (const Point source)
{
ImpressionistDoc* pDoc = GetDocument();
GLubyte color[4];
memcpy ( color, pDoc->GetOriginalPixel( source ), 3 );
auto* color_chooser = pDoc->m_pUI->m_colorChooser;
auto mul_r = 0.0;
auto mul_g = 0.0;
auto mul_b = 0.0;
const auto mode = color_chooser->mode();
switch (mode)
{
case 0: //RGB
case 1: //Byte
case 2: //Hex
mul_r = color_chooser->r();
mul_g = color_chooser->g();
mul_b = color_chooser->b();
case 3: //HSV
Fl_Color_Chooser::hsv2rgb(
color_chooser->hue(),
color_chooser->saturation(),
color_chooser->value(),
mul_r,
mul_g,
mul_b
);
default: {}
}
color[0] = static_cast<unsigned char>(color[0] * mul_r);
color[1] = static_cast<unsigned char>(color[1] * mul_g);
color[2] = static_cast<unsigned char>(color[2] * mul_b);
color[3] = GLubyte(255 * pDoc->getAlpha());
glColor4ubv( color );
}
void ImpBrush::BrushBegin(int x0, int y0, int R, unsigned char* refImg, unsigned char* canvas)
{
BrushBegin(Point(x0, y0), Point(x0, y0));
}