-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircleImageSprite.java
More file actions
148 lines (135 loc) · 5.1 KB
/
CircleImageSprite.java
File metadata and controls
148 lines (135 loc) · 5.1 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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package cn.colintree.aix.CanvasAddons;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.DesignerProperty;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.common.PropertyTypeConstants;
import com.google.appinventor.components.runtime.Ball;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.ImageSprite;
import com.google.appinventor.components.runtime.Sprite;
@DesignerComponent(version = CanvasAddons.VERSION,
iconName = "aiwebres/icon-CircleImageSprite.png",
description = "",
category = ComponentCategory.EXTENSION,
nonVisible = true)
@SimpleObject(external = true)
public final class CircleImageSprite extends AbstractImageSprite {
public CircleImageSprite(ComponentContainer container) {
super(container);
}
@Override
@DesignerProperty(
editorType = PropertyTypeConstants.PROPERTY_TYPE_COMPONENT + ":com.google.appinventor.components.runtime.Ball")
@SimpleProperty(userVisible = false)
public void AA_PlaceHolder(Sprite placeHolder) {
super.AA_PlaceHolder(placeHolder);
}
@Override
protected void inheritProperties(Sprite sprite) {
if (sprite instanceof Ball) {
Ball ball = (Ball) sprite;
Enabled(ball.Enabled());
Heading(ball.Heading());
Interval(ball.Interval());
Height(ball.Height());
Width(ball.Width());
Speed(ball.Speed());
Visible(ball.Visible());
X(ball.X());
Y(ball.Y());
Z(ball.Z());
}
}
@Override
protected void createSprite() {
sprite = new ImageSprite(canvas){
@Override
public boolean containsPoint(double qx, double qy) {
double radius = Width() / 2;
double centerX = xLeft + radius;
double centerY = yTop + radius;
return Math.hypot(qx - centerX, qy - centerY) <= radius;
}
@Override
protected void postEvent(final Sprite sprite, final String eventName, final Object... args) {
if (eventName.equals("CollidedWith")) {
CircleImageSprite.this.CollidedWith((Sprite)args[0]);
} else if (eventName.equals("EdgeReached")) {
CircleImageSprite.this.EdgeReached((Integer)args[0]);
} else if (eventName.equals("NoLongerCollidingWith")) {
CircleImageSprite.this.NoLongerCollidingWith((Sprite)args[0]);
}
}
@Override
public void Dragged(float startX, float startY, float prevX, float prevY, float currentX, float currentY) {
CircleImageSprite.this.Dragged(startX, startY, prevX, prevY, currentX, currentY);
}
@Override
public void Touched(float x, float y) {
CircleImageSprite.this.Touched(x, y);
}
@Override
public void Flung(float x, float y, float speed, float heading, float xvel, float yvel) {
CircleImageSprite.this.Flung(x, y, speed, heading, xvel, yvel);
}
@Override
public void TouchDown(float x, float y) {
CircleImageSprite.this.TouchDown(x, y);
}
@Override
public void TouchUp(float x, float y) {
CircleImageSprite.this.TouchUp(x, y);
}
};
}
@Override
@SimpleEvent
public void CollidedWith(Sprite other) {
postEvent("CollidedWith", other);
}
@Override
@SimpleEvent
public void Dragged(float startX, float startY, float prevX, float prevY, float currentX, float currentY) {
postEvent("Dragged", startX, startY, prevX, prevY, currentX, currentY);
}
@Override
@SimpleEvent
public void EdgeReached(int edge) {
postEvent("EdgeReached", edge);
}
@Override
@SimpleEvent
public void NoLongerCollidingWith(Sprite other) {
postEvent("NoLongerCollidingWith", other);
}
@Override
@SimpleEvent
public void Touched(float x, float y) {
postEvent("Touched", x, y);
}
@Override
@SimpleEvent
public void Flung(float x, float y, float speed, float heading, float xvel, float yvel) {
postEvent("Flung", x, y, speed, heading, xvel, yvel);
}
@Override
@SimpleEvent
public void TouchDown(float x, float y) {
postEvent("TouchDown", x, y);
}
@Override
@SimpleEvent
public void TouchUp(float x, float y) {
postEvent("TouchUp", x, y);
}
@DesignerProperty(
editorType = PropertyTypeConstants.PROPERTY_TYPE_ASSET,
defaultValue = "")
@SimpleProperty
public void Picture(String path) {
super.Picture(path);
}
}