-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdragImage.pde
68 lines (62 loc) · 1.42 KB
/
dragImage.pde
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
class dragImage {
int xPos = 0;
int yPos = 0;
int myValue = 0;
float myWidth = 0;
float myHeight = 0;
String imagePath;
boolean dragState = false;
boolean mask = false;
PImage img;
PImage BGmask;
PGraphics maskImage;
dragImage(int xPos, int yPos, float myWidth, float myHeight, String imagePath, boolean mask) {
this.xPos = xPos;
this.yPos = yPos;
this.myWidth = myWidth;
this.myHeight = myHeight;
this.imagePath = imagePath;
this.img = loadImage(imagePath);
this.mask = mask;
if (mask)
{
// maskimage same h/w as image
maskImage = createGraphics((int)myWidth,(int)myHeight);
maskImage.beginDraw();
maskImage.endDraw();
img.resize(100,100);
}
}
void draw() {
pushMatrix();
translate(xPos, yPos);
imageMode(CORNER);
if (mask)
{
pushStyle();
img.mask(maskImage);
BGmask.mask(circle);
noTint();
image(BGmask, 0, 0, myWidth, myHeight);
popStyle();
}
else
image(img, 0, 0, myWidth, myHeight);
popMatrix();
}
void mousePressed() {
if (insideRect(mouseX, mouseY, xPos, yPos, (int)myWidth, (int)myHeight)) {
dragState = true;
print(myWidth);
}
}
void mouseDragged() {
if (dragState) {
xPos = mouseX - (int)(myWidth/2);
yPos = mouseY - (int)(myHeight/2);
}
}
void mouseReleased() {
dragState = false;
}
}