-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tool.cpp
63 lines (54 loc) · 1.69 KB
/
Tool.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
//
// Project: BrushWorkApp
// Title: Tool.cpp
// Author: Jacob Grafenstein
// Author URI: https://github.com/Jake-Grafenstein
// Description: The base Tool class from which all Tools will inherit.
//
#include <iostream>
#include <cstring>
#include <cmath>
#include "Tool.h"
using std::cerr;
using std::endl;
using std::fill;
// Returns the mask
float** Tool::getMask() {
return mask;
}
// Returns the size of the mask, different for every tool
int Tool::getMaskSize() {
return maskSize;
}
// Calculates the distance between two points, used for SprayCan and Eraser
float Tool::calculateDistance(int x, int y, float mid) {
return sqrt(pow(((float) x - mid), 2) + pow(((float) y - mid), 2));
}
// Returns the mask at a given pixel
float Tool::getPixel(int x,int y) {
if (x>=0 && y>=0 && x<maskSize && y<maskSize) {
return mask[x][y];
}
else {
return -1;
}
}
// Default paintMask function, can be overwritten by tools
void Tool::paintMask(int x,int y,PixelBuffer **displayBuffer,ColorData color,ColorData backgroundColor) {
int i,j,bufferI,bufferJ,width,height;
width = (*displayBuffer)->getWidth();
height = (*displayBuffer)->getHeight();
ColorData tempPixel;
// Applies the mask to the display buffer
for (i=0;i<maskSize;i++) {
for (j=0;j<maskSize;j++) {
bufferI = x + i - (maskSize/2) - 1;
bufferJ = y + j - (maskSize/2) - 1;
// Make sure the width and length are correct, be prepared to swap if necessary
if ((bufferI > 0) && (bufferI < width) && (bufferJ > 0) && (bufferJ < height)) {
tempPixel = (**displayBuffer).getPixel(bufferI,height - bufferJ) * (1 - getPixel(i,j));
(**displayBuffer).setPixel(bufferI,height - bufferJ,tempPixel + (color * getPixel(i,j)));
}
}
}
}