/
DisplayBase.java
128 lines (109 loc) · 3.37 KB
/
DisplayBase.java
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
package com.daasuu.library;
import android.graphics.Canvas;
import android.support.annotation.NonNull;
import com.daasuu.library.animator.ParabolicAnimator;
import com.daasuu.library.animator.TweenAnimator;
/**
* Created by sudamasayuki on 16/01/26.
*/
public abstract class DisplayBase {
/**
* hold a parameter related to the drawing on the canvas.
*/
protected AnimParameter mAnimParameter;
protected Animator mAnimator;
protected Drawer mDrawer;
private boolean mIsEnable;
/**
* call from FPSTextureView or FPSSurfaceView when it is addChild.
*
* @param fps Set in FPSTextureView or FPSSurfaceView.
*/
void setUp(long fps) {
synchronized (this) {
mIsEnable = true;
}
mAnimator.setUp(fps);
}
/**
* Return Composer instance to setup this DisplayObject instance.
* This method is useful when you use only default class of animation.
*
* @param drawer drawing object
* @return composer
*/
protected DisplayComposer drawer(@NonNull Drawer drawer) {
mDrawer = drawer;
return new DisplayComposer();
}
/**
* Set animation class.
* Use this method only when there is need to your own custom class of animation,
*
* @param animator Animator instance
*/
public DisplayBase animator(@NonNull Animator animator) {
this.mAnimator = animator;
mAnimParameter = mAnimator.getInitialAnimParameter();
return this;
}
/**
* Draws the display object into the specified context ignoring its visible, alpha, shadow, and transform.
*
* @param canvas This Canvas acquired by lookCanvas in FPSTextureView or FPSSurfaceView.
*/
void draw(@NonNull Canvas canvas) {
synchronized (this) {
if (mIsEnable) {
mAnimator.setBaseLine(canvas, mDrawer.getWidth(), mDrawer.getHeight());
mAnimator.updateAnimParam(mAnimParameter);
mDrawer.draw(canvas, mAnimParameter.x, mAnimParameter.y, mAnimParameter.alpha, mAnimParameter.scaleX, mAnimParameter.scaleY, mAnimParameter.rotation);
}
}
}
public AnimParameter getAnimParameter() {
return mAnimParameter;
}
/**
* Setter status of pause Motion Animator
*
* @param pause indicates whether to start the motion animation paused.
*/
public void pause(boolean pause) {
mAnimator.pause(pause);
}
/**
* Getter status of pause Motion Animator
*
* @return indicates whether to start the motion animation paused.
*/
public boolean isPause() {
return mAnimator.isPause();
}
/**
* disable this display object.
* This call from FPSTextureView, FPSSurfaceView or Container when it is removeChild.
*/
void disable() {
synchronized (this) {
mIsEnable = false;
}
}
/**
* Composer provide simple composing interface.
*/
public class DisplayComposer {
/**
* @return tween composer
*/
public TweenAnimator.Composer tween() {
return TweenAnimator.composer(DisplayBase.this);
}
/**
* @return parabolic composer
*/
public ParabolicAnimator.Composer parabolic() {
return ParabolicAnimator.composer(DisplayBase.this);
}
}
}