-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimatedChar.cpp
80 lines (67 loc) · 1.98 KB
/
AnimatedChar.cpp
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
/*
AnimatedChar.cpp - Library for animated characters.
Created by Pavel Milkevich, December 12, 2020.
Inspired by
https://github.com/lmirel/MorphingClockRemix/blob/master/Digit.cpp
*/
#include "Arduino.h"
#include "gfxfont.h"
#include "AnimatedChar.h"
#include "FlipAnimation.h"
#include "Debugger.h"
AnimatedChar::AnimatedChar() : AnimatedChar( nullptr ) {
Debugger::debug( "AnimatedChar constructor()\n" );
}
AnimatedChar::AnimatedChar( const GFXfont* font ) : AnimatedChar( font, '0' ) {
Debugger::debug( "AnimatedChar constructor(%p)\n", font );
}
AnimatedChar::AnimatedChar( const GFXfont* font, char ch ) {
Debugger::debug( "AnimatedChar constructor(%p, %c)\n", font, ch );
_font = (GFXfont*) font;
_char = ch;
Animation* anim = new FlipAnimation( 500 );
setAnimation( anim );
Debugger::debug( "Created AnimatedChar[%p]: %c\n", this, ch );
}
Animation* AnimatedChar::getAnimation() {
return _anim;
}
void AnimatedChar::setAnimation( Animation* anim ) {
if ( _anim != nullptr ) {
_anim->unbind( this );
}
_anim = anim;
if ( anim != nullptr ) {
_anim->bind( this );
}
}
char AnimatedChar::getChar() {
return _char;
}
void AnimatedChar::setPosition( int x, int y ) {
_x = x;
_y - y;
}
void AnimatedChar::animateTo( char to ) {
Debugger::debug( "AnimatedChar.animateTo [%c]->[%c]: animation [%p]\n", _char, to, _anim );
_anim->animate( _char, to, _font );
}
void AnimatedChar::stopAnimation() {
_anim->stop();
}
void AnimatedChar::setVisible( bool visible ) {
_visible = visible;
}
void AnimatedChar::next() {
if ( !_visible || !_anim->isRunning() ) {
return;
} else {
printFrame( _anim->next() );
}
}
void AnimatedChar::onAnimation( AnimationStatus status, char from, char to, byte progress ) {
if ( status == STOPPED && progress >= 100 ) {
_char = to;
Debugger::debug( "AnimatedChar.onAnimation: done animation from[%c] to[%c]\n", from, to );
}
}