-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCrosshairTexture.java
More file actions
75 lines (63 loc) · 2.17 KB
/
CrosshairTexture.java
File metadata and controls
75 lines (63 loc) · 2.17 KB
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
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.imageio.ImageIO;
import java.awt.Color;
public class CrosshairTexture {
private int[] pixels;
private String loc;
private int imgWidth;
private int imgHeight;
private BufferedImage image;
private int magnification; // increase size of crosshair
/*
Color RGB Values:
yellow - (255, 255, 0)
*/
private int color = new Color(255, 255, 0).getRGB();
public CrosshairTexture(String location, int magnification) {
loc = location;
this.magnification = magnification;
load();
}
private void load() {
try {
image = ImageIO.read(new File(loc));
imgWidth = image.getWidth();
imgHeight = image.getHeight();
pixels = new int[imgWidth * imgHeight];
//pixels = image.getRGB(0, 0, w, h, pixels, 0, w);
} catch (IOException e) {
e.printStackTrace();
}
for(int y = 0; y < imgHeight; y++) {
for(int x = 0; x < imgWidth; x++) {
pixels[x + (y * imgWidth)] = image.getRGB(x, y);
}
}
}
public int[] applyCrosshair(int[] pixels, int frameWidth) {
for(int crosshairPosCount=0; crosshairPosCount<this.getPixels().length; crosshairPosCount++) {
if(!this.getPixelColor(crosshairPosCount).equals(this.getPixelColor(0, 0))) {
pixels[((pixels.length - this.getImgWidth())/2)+(crosshairPosCount % this.getImgWidth())+((int)(crosshairPosCount / this.getImgWidth())*frameWidth)] = color; //crosshairColor
}
}
return pixels;
}
public int getImgWidth() {
return imgWidth;
}
public int getImgHeight() {
return imgHeight;
}
public int[] getPixels() {
return pixels;
}
public Color getPixelColor(int x, int y) {
return new Color(pixels[x + (y * imgWidth)]);
}
public Color getPixelColor(int pos) {
return new Color(pixels[pos]);
}
}