blob: 3021f467b6de0f2330282af72bae338daec6feb0 [file] [log] [blame]
Dees_Troy51a0e822012-09-05 15:24:24 -04001// animation.cpp - GUIAnimation object
2
3#include <stdarg.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7#include <fcntl.h>
8#include <sys/reboot.h>
9#include <sys/stat.h>
10#include <sys/time.h>
11#include <sys/mman.h>
12#include <sys/types.h>
13#include <sys/ioctl.h>
14#include <time.h>
15#include <unistd.h>
16#include <stdlib.h>
17
18#include <string>
19
20extern "C" {
21#include "../common.h"
22#include "../minuitwrp/minui.h"
23#include "../recovery_ui.h"
24}
25
26#include "rapidxml.hpp"
27#include "objects.hpp"
28
29
30GUIAnimation::GUIAnimation(xml_node<>* node)
31{
32 xml_node<>* child;
33 xml_attribute<>* attr;
34
35 mAnimation = NULL;
36 mFrame = 1;
37 mFPS = 1;
38 mLoop = -1;
39 mRender = 1;
40 mUpdateCount = 0;
41
42 if (!node) return;
43
44 child = node->first_node("resource");
45 if (child)
46 {
47 attr = child->first_attribute("name");
48 if (attr)
49 mAnimation = (AnimationResource*) PageManager::FindResource(attr->value());
50 }
51
52 // Load the placement
53 LoadPlacement(node->first_node("placement"), &mRenderX, &mRenderY, NULL, NULL, &mPlacement);
54
55 child = node->first_node("speed");
56 if (child)
57 {
58 attr = child->first_attribute("fps");
59 if (attr)
60 mFPS = atoi(attr->value());
61 attr = child->first_attribute("render");
62 if (attr)
63 mRender = atoi(attr->value());
64 }
65 if (mFPS > 30) mFPS = 30;
66
67 child = node->first_node("loop");
68 if (child)
69 {
70 attr = child->first_attribute("frame");
71 if (attr)
72 mLoop = atoi(attr->value()) - 1;
73 attr = child->first_attribute("start");
74 if (attr)
75 mFrame = atoi(attr->value());
76 }
77
78 // Fetch the render sizes
79 if (mAnimation && mAnimation->GetResource())
80 {
81 mRenderW = gr_get_width(mAnimation->GetResource());
82 mRenderH = gr_get_height(mAnimation->GetResource());
83
84 // Adjust for placement
85 if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
86 {
87 if (mPlacement == CENTER)
88 mRenderX -= (mRenderW / 2);
89 else
90 mRenderX -= mRenderW;
91 }
92 if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT)
93 {
94 if (mPlacement == CENTER)
95 mRenderY -= (mRenderH / 2);
96 else
97 mRenderY -= mRenderH;
98 }
99 SetPlacement(TOP_LEFT);
100 }
101}
102
103int GUIAnimation::Render(void)
104{
105 if (!mAnimation || !mAnimation->GetResource(mFrame)) return -1;
106
107 gr_blit(mAnimation->GetResource(mFrame), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
108 return 0;
109}
110
111int GUIAnimation::Update(void)
112{
113 if (!mAnimation) return -1;
114
115 // Handle the "end-of-animation" state
116 if (mLoop == -2) return 0;
117
118 // Determine if we need the next frame yet...
119 if (++mUpdateCount > 30 / mFPS)
120 {
121 mUpdateCount = 0;
122 if (++mFrame >= mAnimation->GetResourceCount())
123 {
124 if (mLoop < 0)
125 {
126 mFrame = mAnimation->GetResourceCount() - 1;
127 mLoop = -2;
128 }
129 else
130 mFrame = mLoop;
131 }
132 if (mRender == 2) return 2;
133 return (Render() == 0 ? 1 : -1);
134 }
135 return 0;
136}
137