summaryrefslogtreecommitdiff
path: root/libs/revolution/src/homebuttonLib/HBMFrameController.cpp
blob: dccaf1599645a1d6cc052eee8ec1e028fe7de16c (plain)
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

#include "HBMFrameController.h"

namespace homebutton {

    void FrameController::init(int anm_type, f32 max_frame, f32 min_frame, f32 delta) {
        mAnmType = anm_type;
        mMaxFrame = max_frame;
        mMinFrame = min_frame;

        mDelta = delta;
        mState = ANIM_STATE_STOP;
        mbAlternateBack = false;

        initFrame();
    }

    void FrameController::initFrame() {
        mFrame = mAnmType == ANIM_TYPE_BACKWARD ? mMaxFrame : mMinFrame;
    }

    void FrameController::calc() {
        if (mState != ANIM_STATE_PLAY) {
            return;
        }

        switch (mAnmType) {
        case ANIM_TYPE_FORWARD:
            if ((mFrame += mDelta) >= getLastFrame()) {
                mFrame = getLastFrame();
                stop();
            }

            break;

        case ANIM_TYPE_BACKWARD:
            if ((mFrame -= mDelta) <= mMinFrame) {
                mFrame = mMinFrame;
                stop();
            }

            break;

        case ANIM_TYPE_LOOP:
            if ((mFrame += mDelta) >= mMaxFrame) {
                mFrame -= mMaxFrame - mMinFrame;
            }

            break;

        case ANIM_TYPE_ALTERNATE:
            if (!mbAlternateBack) {
                if ((mFrame += mDelta) >= getLastFrame()) {
                    mFrame = getLastFrame();
                    mbAlternateBack = true;
                }
            } else {
                if ((mFrame -= mDelta) <= mMinFrame) {
                    mFrame = mMinFrame;
                    mbAlternateBack = false;
                }
            }

            break;
        }
    }

}  // namespace homebutton