-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicGraphs.java
More file actions
136 lines (133 loc) · 4.12 KB
/
DynamicGraphs.java
File metadata and controls
136 lines (133 loc) · 4.12 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
package awpsoft.gamemodule;
import java.util.*;
import java.awt.Image;
public class DynamicGraphs extends TimeVariantObject implements Cloneable
{
protected boolean Loop;
protected int CurrentPos;
protected float SwitchSpeed, Remnant;
protected Vector<Image> ThisClip;
@SuppressWarnings("unchecked")
@Override public DynamicGraphs clone() throws CloneNotSupportedException
{
DynamicGraphs temp = (DynamicGraphs)super.clone();
temp.ThisClip = (Vector<Image>)ThisClip.clone();
return temp;
}
public DynamicGraphs()
{
CurrentPos = 0;
SwitchSpeed = 0.0f;
Remnant = 0.0f;
Loop = true;
}
public DynamicGraphs(Vector<Image> clip)
{
CurrentPos = 0;
SwitchSpeed = 0.0f;
Remnant = 0.0f;
Loop = true;
setClip(clip);
}
public void setClip(Vector<Image> clip)
{
setClip(clip, true);
}
public void setClip(Vector<Image> clip, boolean resetPos)
{
if (resetPos)
{
Remnant = 0.0f;
CurrentPos = 0;
}
else if (clip == null || clip.isEmpty())
{
CurrentPos = 0;
}
else if (Loop)
{
CurrentPos %= clip.size();
}
else if (CurrentPos > (int)clip.size())
{
CurrentPos = (int)clip.size() - 1;
}
ThisClip = clip;
}
public void setSwitchParams(float speed, boolean enableLoop)
{
SwitchSpeed = speed;
Loop = enableLoop;
}
public void setSwitchSpeed(float speed)
{
SwitchSpeed = speed;
}
public void setEnableLoop(boolean enableLoop)
{
Loop = enableLoop;
}
public void resetCurrentPos()
{
Remnant = 0.0f;
CurrentPos = 0;
}
public Image getCurrentFrame()
{
if (ThisClip == null || ThisClip.isEmpty()) return null;
else return ThisClip.get(CurrentPos);
}
public Image getLastFrame()
{
if (ThisClip == null || ThisClip.isEmpty()) return null;
else return ThisClip.get(ThisClip.size() - 1);
}
public Image getFirstFrame()
{
if (ThisClip == null || ThisClip.isEmpty()) return null;
else return ThisClip.firstElement();
}
public Image getFrame(int index)
{
if (ThisClip == null || ThisClip.isEmpty()) return null;
else if (index >= ThisClip.size()) return ThisClip.lastElement();
else if (index < 0) return ThisClip.firstElement();
else return ThisClip.get(index);
}
public @Override boolean giveTime(int timeGived)
{
if (DisableTimeVariant) return false;
else if (SwitchSpeed == 0.0f) return true;
else if (!Loop)
{
if (ThisClip == null || ThisClip.isEmpty()) return true;
if (SwitchSpeed > 0.0f && CurrentPos == ThisClip.size() - 1)return true;
if (SwitchSpeed < 0.0f && CurrentPos == 0) return true;
}
float temp1;
int temp2;
temp1 = SwitchSpeed * (float)timeGived + Remnant;
Remnant = temp1 - (float)((int)temp1);
temp2 = CurrentPos + (int)temp1;
int frames;
if (ThisClip == null || ThisClip.isEmpty()) frames = 0;
else frames = ThisClip.size();
if (Loop)
{
if (frames == 0)
{
CurrentPos = 0;
return true;
}
temp2 = temp2 % frames;
if (temp2 < 0) temp2 += frames;
CurrentPos = temp2;
return true;
}
if (temp2 < 0) temp2 = 0;
if (temp2 >= frames) temp2 = frames - 1;
if (temp2 < 0) temp2 = 0;
CurrentPos = temp2;
return true;
}
};