blob: e1a762dbd081b337f43cfba1c3718fd1a350e1e5 [file] [log] [blame]
Jason Sams0f505e52009-10-13 17:18:35 -07001#pragma version(1)
Jason Sams14f67ed2010-05-11 14:02:43 -07002
Shih-wei Liaoc8149652010-06-14 11:46:11 -07003#pragma rs java_package_name(com.android.launcher2)
4
Jason Sams14f67ed2010-05-11 14:02:43 -07005#include "../../../../../frameworks/base/libs/rs/scriptc/rs_types.rsh"
6#include "../../../../../frameworks/base/libs/rs/scriptc/rs_math.rsh"
7#include "../../../../../frameworks/base/libs/rs/scriptc/rs_graphics.rsh"
Jason Sams0f505e52009-10-13 17:18:35 -07008
9#define PI 3.14159f
10
Jason Sams14f67ed2010-05-11 14:02:43 -070011// Constants from Java
12int COLUMNS_PER_PAGE_PORTRAIT;
13int ROWS_PER_PAGE_PORTRAIT;
14int COLUMNS_PER_PAGE_LANDSCAPE;
15int ROWS_PER_PAGE_LANDSCAPE;
16
17float gNewPositionX;
18int gNewTouchDown;
19float gFlingVelocity;
20int gIconCount;
21int gSelectedIconIndex;
22rs_allocation gSelectedIconTexture;
23float gZoomTarget;
24rs_allocation gHomeButton;
25float gTargetPos;
26
27rs_program_fragment gPFTexNearest;
28rs_program_fragment gPFTexMip;
29rs_program_fragment gPFTexMipAlpha;
30rs_program_vertex gPVCurve;
31rs_program_store gPS;
32rs_mesh gSMCell;
33
34rs_allocation *gIconIDs;
35rs_allocation *gLabelIDs;
36
37typedef struct VpConsts_s {
38 float4 Position;
39 float4 ScaleOffset;
40 float2 BendPos;
41 float2 ImgSize;
42} VpConsts_t;
43VpConsts_t *vpConstants;
44
45
46#pragma rs export_var(COLUMNS_PER_PAGE_PORTRAIT, ROWS_PER_PAGE_PORTRAIT, COLUMNS_PER_PAGE_LANDSCAPE, ROWS_PER_PAGE_LANDSCAPE, gNewPositionX, gNewTouchDown, gFlingVelocity, gIconCount, gSelectedIconIndex, gSelectedIconTexture, gZoomTarget, gHomeButton, gTargetPos, gPFTexNearest, gPFTexMip, gPFTexMipAlpha, gPVCurve, gPS, gSMCell, gIconIDs, gLabelIDs, vpConstants)
47#pragma rs export_func(resetHWWar, move, moveTo, setZoom, fling)
48
49
50void debugAll()
51{
Jason Sams14f67ed2010-05-11 14:02:43 -070052}
53
Jason Sams0f505e52009-10-13 17:18:35 -070054
55// Attraction to center values from page edge to page center.
Jason Samsad1bdf02010-05-14 17:54:50 -070056static float g_AttractionTable[9] = {20.f, 20.f, 20.f, 10.f, -10.f, -20.f, -20.f, -20.f, -20.f};
57static float g_FrictionTable[9] = {10.f, 10.f, 11.f, 15.f, 15.f, 11.f, 10.f, 10.f, 10.f};
58static float g_PhysicsTableSize = 7;
Jason Sams0f505e52009-10-13 17:18:35 -070059
Jason Samsad1bdf02010-05-14 17:54:50 -070060static float g_PosPage = 0.f;
61static float g_PosVelocity = 0.f;
62static float g_LastPositionX = 0.f;
63static int g_LastTouchDown = 0;
Jason Sams14f67ed2010-05-11 14:02:43 -070064static float g_DT;
Jason Sams13a75d52010-05-19 16:38:04 -070065static int64_t g_LastTime;
Jason Sams14f67ed2010-05-11 14:02:43 -070066static int g_PosMax;
Jason Samsad1bdf02010-05-14 17:54:50 -070067static float g_Zoom = 0.f;
68static float g_Animation = 1.f;
Jason Sams14f67ed2010-05-11 14:02:43 -070069static float g_OldPosPage;
70static float g_OldPosVelocity;
71static float g_OldZoom;
Jason Samsad1bdf02010-05-14 17:54:50 -070072static float g_MoveToTotalTime = 0.2f;
73static float g_MoveToTime = 0.f;
74static float g_MoveToOldPos = 0.f;
Jason Samsc1c521e2009-10-19 14:45:45 -070075
Jason Sams14f67ed2010-05-11 14:02:43 -070076static int g_Cols;
77static int g_Rows;
Jason Sams0f505e52009-10-13 17:18:35 -070078
79// Drawing constants, should be parameters ======
80#define VIEW_ANGLE 1.28700222f
81
Jason Sams14f67ed2010-05-11 14:02:43 -070082static int g_DrawLastFrame;
83static int lastFrame(int draw) {
Jason Sams5c1417a2010-05-18 17:06:04 -070084 // We draw one extra frame to work around the last frame post bug.
85 // We also need to track if we drew the last frame to deal with large DT
86 // in the physics.
Jason Sams0f505e52009-10-13 17:18:35 -070087 g_DrawLastFrame = draw;
Jason Sams13a75d52010-05-19 16:38:04 -070088 return draw;
Jason Sams0f505e52009-10-13 17:18:35 -070089}
90
Jason Sams14f67ed2010-05-11 14:02:43 -070091static void updateReadback() {
Jason Samsad1bdf02010-05-14 17:54:50 -070092 if ((g_OldPosPage != g_PosPage) ||
93 (g_OldPosVelocity != g_PosVelocity) ||
94 (g_OldZoom != g_Zoom)) {
Jason Sams0f505e52009-10-13 17:18:35 -070095
96 g_OldPosPage = g_PosPage;
97 g_OldPosVelocity = g_PosVelocity;
98 g_OldZoom = g_Zoom;
99
100 int i[3];
101 i[0] = g_PosPage * (1 << 16);
102 i[1] = g_PosVelocity * (1 << 16);
103 i[2] = g_OldZoom * (1 << 16);
Jason Sams13a75d52010-05-19 16:38:04 -0700104 rsSendToClient(&i[0], 1, 12, 1);
Jason Samsad1bdf02010-05-14 17:54:50 -0700105 }
Jason Sams0f505e52009-10-13 17:18:35 -0700106}
107
Jason Samsad1bdf02010-05-14 17:54:50 -0700108void setColor(float r, float g, float b, float a) {
Jason Sams41b61c82009-10-15 15:40:54 -0700109}
Jason Sams0f505e52009-10-13 17:18:35 -0700110void init() {
Jason Sams41b61c82009-10-15 15:40:54 -0700111}
Jason Sams41b61c82009-10-15 15:40:54 -0700112void resetHWWar() {
Jason Sams0f505e52009-10-13 17:18:35 -0700113}
114
115void move() {
116 if (g_LastTouchDown) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700117 float dx = -(gNewPositionX - g_LastPositionX);
Jason Sams0f505e52009-10-13 17:18:35 -0700118 g_PosVelocity = 0;
Jason Sams6ec11bc2010-01-19 17:56:52 -0800119 g_PosPage += dx * 5.2f;
Jason Sams0f505e52009-10-13 17:18:35 -0700120
Jason Samsc8514792009-10-29 14:27:29 -0700121 float pmin = -0.49f;
122 float pmax = g_PosMax + 0.49f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700123 g_PosPage = clamp(g_PosPage, pmin, pmax);
Jason Sams0f505e52009-10-13 17:18:35 -0700124 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700125 g_LastTouchDown = gNewTouchDown;
126 g_LastPositionX = gNewPositionX;
Jason Samsc1c521e2009-10-19 14:45:45 -0700127 g_MoveToTime = 0;
Jason Sams0f505e52009-10-13 17:18:35 -0700128}
129
Jason Samsc1c521e2009-10-19 14:45:45 -0700130void moveTo() {
131 g_MoveToTime = g_MoveToTotalTime;
132 g_PosVelocity = 0;
133 g_MoveToOldPos = g_PosPage;
134}
135
Joe Onorato3a8820b2009-11-10 15:06:42 -0800136void setZoom() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700137 g_Zoom = gZoomTarget;
Joe Onorato3a8820b2009-11-10 15:06:42 -0800138 g_DrawLastFrame = 1;
139 updateReadback();
140}
141
Jason Sams0f505e52009-10-13 17:18:35 -0700142void fling() {
143 g_LastTouchDown = 0;
Jason Sams14f67ed2010-05-11 14:02:43 -0700144 g_PosVelocity = -gFlingVelocity * 4;
145 float av = fabs(g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700146 float minVel = 3.5f;
147
Jason Sams13a75d52010-05-19 16:38:04 -0700148 minVel *= 1.f - (fabs(rsFrac(g_PosPage + 0.5f) - 0.5f) * 0.45f);
Jason Sams0f505e52009-10-13 17:18:35 -0700149
150 if (av < minVel && av > 0.2f) {
151 if (g_PosVelocity > 0) {
152 g_PosVelocity = minVel;
153 } else {
154 g_PosVelocity = -minVel;
155 }
156 }
157
158 if (g_PosPage <= 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700159 g_PosVelocity = max(0.f, g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700160 }
161 if (g_PosPage > g_PosMax) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700162 g_PosVelocity = min(0.f, g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700163 }
164}
165
Jason Sams14f67ed2010-05-11 14:02:43 -0700166// Interpolates values in the range 0..1 to a curve that eases in
167// and out.
168static float getInterpolation(float input) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700169 return (cos((input + 1) * PI) * 0.5f) + 0.5f;
Jason Sams0f505e52009-10-13 17:18:35 -0700170}
171
Mike Cleron7d5d7462009-10-20 14:06:00 -0700172
Jason Sams14f67ed2010-05-11 14:02:43 -0700173static void updatePos() {
Jason Sams0f505e52009-10-13 17:18:35 -0700174 if (g_LastTouchDown) {
175 return;
176 }
177
Jason Sams13a75d52010-05-19 16:38:04 -0700178 float tablePosNorm = rsFrac(g_PosPage + 0.5f);
Jason Sams0f505e52009-10-13 17:18:35 -0700179 float tablePosF = tablePosNorm * g_PhysicsTableSize;
180 int tablePosI = tablePosF;
181 float tablePosFrac = tablePosF - tablePosI;
Jason Sams14f67ed2010-05-11 14:02:43 -0700182 float accel = mix(g_AttractionTable[tablePosI],
Jason Sams0f505e52009-10-13 17:18:35 -0700183 g_AttractionTable[tablePosI + 1],
184 tablePosFrac) * g_DT;
Jason Sams14f67ed2010-05-11 14:02:43 -0700185 float friction = mix(g_FrictionTable[tablePosI],
Jason Sams2e19c052009-10-20 18:19:55 -0700186 g_FrictionTable[tablePosI + 1],
187 tablePosFrac) * g_DT;
Jason Sams0f505e52009-10-13 17:18:35 -0700188
Jason Samsc1c521e2009-10-19 14:45:45 -0700189 if (g_MoveToTime) {
Jason Samsc8514792009-10-29 14:27:29 -0700190 // New position is old posiition + (total distance) * (interpolated time)
Jason Sams14f67ed2010-05-11 14:02:43 -0700191 g_PosPage = g_MoveToOldPos + (gTargetPos - g_MoveToOldPos) * getInterpolation((g_MoveToTotalTime - g_MoveToTime) / g_MoveToTotalTime);
Jason Samsc1c521e2009-10-19 14:45:45 -0700192 g_MoveToTime -= g_DT;
193 if (g_MoveToTime <= 0) {
194 g_MoveToTime = 0;
Jason Sams14f67ed2010-05-11 14:02:43 -0700195 g_PosPage = gTargetPos;
Jason Samsc1c521e2009-10-19 14:45:45 -0700196 }
197 return;
198 }
199
Jason Sams0f505e52009-10-13 17:18:35 -0700200 // If our velocity is low OR acceleration is opposing it, apply it.
Jason Sams14f67ed2010-05-11 14:02:43 -0700201 if (fabs(g_PosVelocity) < 4.0f || (g_PosVelocity * accel) < 0) {
Jason Sams0f505e52009-10-13 17:18:35 -0700202 g_PosVelocity += accel;
203 }
Jason Sams13a75d52010-05-19 16:38:04 -0700204 //RS_DEBUG(g_PosPage);
205 //RS_DEBUG(g_PosVelocity);
206 //RS_DEBUG(friction);
207 //RS_DEBUG(accel);
Jason Sams0f505e52009-10-13 17:18:35 -0700208
Jason Samsc8514792009-10-29 14:27:29 -0700209 // Normal physics
210 if (g_PosVelocity > 0) {
211 g_PosVelocity -= friction;
Jason Sams14f67ed2010-05-11 14:02:43 -0700212 g_PosVelocity = max(g_PosVelocity, 0.f);
Jason Samsc8514792009-10-29 14:27:29 -0700213 } else {
214 g_PosVelocity += friction;
Jason Sams14f67ed2010-05-11 14:02:43 -0700215 g_PosVelocity = min(g_PosVelocity, 0.f);
Jason Samsc8514792009-10-29 14:27:29 -0700216 }
217
Jason Sams14f67ed2010-05-11 14:02:43 -0700218 if ((friction > fabs(g_PosVelocity)) && (friction > fabs(accel))) {
Jason Sams0f505e52009-10-13 17:18:35 -0700219 // Special get back to center and overcome friction physics.
220 float t = tablePosNorm - 0.5f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700221 if (fabs(t) < (friction * g_DT)) {
Jason Sams0f505e52009-10-13 17:18:35 -0700222 // really close, just snap
Jason Sams14f67ed2010-05-11 14:02:43 -0700223 g_PosPage = round(g_PosPage);
Jason Sams0f505e52009-10-13 17:18:35 -0700224 g_PosVelocity = 0;
225 } else {
226 if (t > 0) {
227 g_PosVelocity = -friction;
228 } else {
229 g_PosVelocity = friction;
230 }
231 }
Jason Sams0f505e52009-10-13 17:18:35 -0700232 }
Jason Sams0f505e52009-10-13 17:18:35 -0700233
234 // Check for out of boundry conditions.
235 if (g_PosPage < 0 && g_PosVelocity < 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700236 float damp = 1.0f + (g_PosPage * 4);
237 damp = clamp(damp, 0.f, 0.9f);
Jason Sams0f505e52009-10-13 17:18:35 -0700238 g_PosVelocity *= damp;
239 }
240 if (g_PosPage > g_PosMax && g_PosVelocity > 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700241 float damp = 1.0f - ((g_PosPage - g_PosMax) * 4);
242 damp = clamp(damp, 0.f, 0.9f);
Jason Sams0f505e52009-10-13 17:18:35 -0700243 g_PosVelocity *= damp;
244 }
Jason Samsc8514792009-10-29 14:27:29 -0700245
246 g_PosPage += g_PosVelocity * g_DT;
Jason Sams14f67ed2010-05-11 14:02:43 -0700247 g_PosPage = clamp(g_PosPage, -0.49f, g_PosMax + 0.49f);
Jason Sams0f505e52009-10-13 17:18:35 -0700248}
249
Jason Sams14f67ed2010-05-11 14:02:43 -0700250static void
Jason Sams0f505e52009-10-13 17:18:35 -0700251draw_home_button()
252{
Jason Samsad1bdf02010-05-14 17:54:50 -0700253 color(1.0f, 1.0f, 1.0f, 1.0f);
Jason Sams13a75d52010-05-19 16:38:04 -0700254 rsgBindTexture(gPFTexNearest, 0, gHomeButton);
Jason Sams0f505e52009-10-13 17:18:35 -0700255
Jason Sams13a75d52010-05-19 16:38:04 -0700256 float w = rsgGetWidth();
257 float h = rsgGetHeight();
258 float tw = rsAllocationGetDimX(gHomeButton);
259 float th = rsAllocationGetDimY(gHomeButton);
Jason Sams76512482010-02-04 16:31:35 -0800260
261 float x;
262 float y;
Jason Sams13a75d52010-05-19 16:38:04 -0700263 if (w > h) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700264 x = w - (tw * (1 - g_Animation)) + 20;
265 y = (h - th) * 0.5f;
Jason Sams76512482010-02-04 16:31:35 -0800266 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700267 x = (w - tw) / 2;
268 y = -g_Animation * th;
Jason Sams76512482010-02-04 16:31:35 -0800269 y -= 30; // move the house to the edge of the screen as it doesn't fill the texture.
270 }
271
Jason Sams13a75d52010-05-19 16:38:04 -0700272 rsgDrawSpriteScreenspace(x, y, 0, tw, th);
Jason Sams0f505e52009-10-13 17:18:35 -0700273}
274
Jason Sams14f67ed2010-05-11 14:02:43 -0700275static void drawFrontGrid(float rowOffset, float p)
Jason Sams0f505e52009-10-13 17:18:35 -0700276{
Jason Sams13a75d52010-05-19 16:38:04 -0700277 float h = rsgGetHeight();
278 float w = rsgGetWidth();
Jason Sams0f505e52009-10-13 17:18:35 -0700279
280 int intRowOffset = rowOffset;
281 float rowFrac = rowOffset - intRowOffset;
Jason Sams13a75d52010-05-19 16:38:04 -0700282 float colWidth = 120.f;//w / 4;
Jason Sams0f505e52009-10-13 17:18:35 -0700283 float rowHeight = colWidth + 25.f;
Jason Samsb4ecab22010-01-19 16:43:26 -0800284 float yoff = 0.5f * h + 1.5f * rowHeight;
Jason Sams0f505e52009-10-13 17:18:35 -0700285
286 int row, col;
Jason Sams76512482010-02-04 16:31:35 -0800287 int colCount = 4;
288 if (w > h) {
289 colCount = 6;
290 rowHeight -= 12.f;
291 yoff = 0.47f * h + 1.0f * rowHeight;
292 }
293
294 int iconNum = (intRowOffset - 5) * colCount;
295
Jason Sams13a75d52010-05-19 16:38:04 -0700296 rsgBindProgramVertex(gPVCurve);
Jason Samsb4ecab22010-01-19 16:43:26 -0800297
Jason Sams76512482010-02-04 16:31:35 -0800298 vpConstants->Position.z = p;
Jason Samsb4ecab22010-01-19 16:43:26 -0800299
Jason Samsad1bdf02010-05-14 17:54:50 -0700300 color(1.0f, 1.0f, 1.0f, 1.0f);
Jason Samsb4ecab22010-01-19 16:43:26 -0800301 for (row = -5; row < 15; row++) {
Jason Sams0f505e52009-10-13 17:18:35 -0700302 float y = yoff - ((-rowFrac + row) * rowHeight);
303
Jason Sams76512482010-02-04 16:31:35 -0800304 for (col=0; col < colCount; col++) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700305 if (iconNum >= gIconCount) {
Jason Sams0f505e52009-10-13 17:18:35 -0700306 return;
307 }
308
309 if (iconNum >= 0) {
Jason Samsb4ecab22010-01-19 16:43:26 -0800310 float x = colWidth * col + (colWidth / 2);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800311 vpConstants->Position.x = x + 0.2f;
Jason Sams1a94ee32010-01-20 13:34:30 -0800312
Jason Sams14f67ed2010-05-11 14:02:43 -0700313 if (gSelectedIconIndex == iconNum && !p && gSelectedIconTexture) {
Jason Sams13a75d52010-05-19 16:38:04 -0700314 rsgBindProgramFragment(gPFTexNearest);
315 rsgBindTexture(gPFTexNearest, 0, gSelectedIconTexture);
316 vpConstants->ImgSize.x = rsAllocationGetDimX(gSelectedIconTexture);
317 vpConstants->ImgSize.y = rsAllocationGetDimY(gSelectedIconTexture);
318 vpConstants->Position.y = y - (rsAllocationGetDimY(gSelectedIconTexture)
319 - rsAllocationGetDimY(gIconIDs[iconNum])) * 0.5f;
320 rsgDrawSimpleMesh(gSMCell);
Jason Sams37f262d2010-01-20 11:19:51 -0800321 }
322
Jason Sams13a75d52010-05-19 16:38:04 -0700323 rsgBindProgramFragment(gPFTexMip);
324 vpConstants->ImgSize.x = rsAllocationGetDimX(gIconIDs[iconNum]);
325 vpConstants->ImgSize.y = rsAllocationGetDimY(gIconIDs[iconNum]);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800326 vpConstants->Position.y = y - 0.2f;
Jason Sams13a75d52010-05-19 16:38:04 -0700327 rsgBindTexture(gPFTexMip, 0, gIconIDs[iconNum]);
328 rsgDrawSimpleMesh(gSMCell);
Joe Onorato742d7fc2009-10-15 19:48:16 -0700329
Jason Sams13a75d52010-05-19 16:38:04 -0700330 rsgBindProgramFragment(gPFTexMipAlpha);
331 vpConstants->ImgSize.x = rsAllocationGetDimX(gLabelIDs[iconNum]);
332 vpConstants->ImgSize.y = rsAllocationGetDimY(gLabelIDs[iconNum]);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800333 vpConstants->Position.y = y - 64.f - 0.2f;
Jason Sams13a75d52010-05-19 16:38:04 -0700334 rsgBindTexture(gPFTexMipAlpha, 0, gLabelIDs[iconNum]);
335 rsgDrawSimpleMesh(gSMCell);
Jason Sams0f505e52009-10-13 17:18:35 -0700336 }
337 iconNum++;
338 }
339 }
340}
341
Jason Sams0f505e52009-10-13 17:18:35 -0700342
Jason Sams14f67ed2010-05-11 14:02:43 -0700343int root()
Jason Sams0f505e52009-10-13 17:18:35 -0700344{
345 // Compute dt in seconds.
Jason Sams13a75d52010-05-19 16:38:04 -0700346 int64_t newTime = rsUptimeMillis();
Jason Sams14f67ed2010-05-11 14:02:43 -0700347 g_DT = (newTime - g_LastTime) * 0.001f;
Jason Sams0f505e52009-10-13 17:18:35 -0700348 g_LastTime = newTime;
Jason Sams2e19c052009-10-20 18:19:55 -0700349
Jason Sams0f505e52009-10-13 17:18:35 -0700350 if (!g_DrawLastFrame) {
351 // If we stopped rendering we cannot use DT.
352 // assume 30fps in this case.
353 g_DT = 0.033f;
354 }
Jason Samsb52dfa02009-10-14 20:16:14 -0700355 // physics may break if DT is large.
Jason Sams14f67ed2010-05-11 14:02:43 -0700356 g_DT = min(g_DT, 0.2f);
Jason Sams0f505e52009-10-13 17:18:35 -0700357
Jason Sams14f67ed2010-05-11 14:02:43 -0700358 if (g_Zoom != gZoomTarget) {
Jason Sams6471c8b2010-01-20 14:15:22 -0800359 float dz = g_DT * 1.7f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700360 if (gZoomTarget < 0.5f) {
Jason Sams6471c8b2010-01-20 14:15:22 -0800361 dz = -dz;
Jason Sams0f505e52009-10-13 17:18:35 -0700362 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700363 if (fabs(g_Zoom - gZoomTarget) < fabs(dz)) {
364 g_Zoom = gZoomTarget;
Jason Sams0f505e52009-10-13 17:18:35 -0700365 } else {
366 g_Zoom += dz;
367 }
368 updateReadback();
369 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700370 g_Animation = pow(1.f - g_Zoom, 3.f);
Jason Sams0f505e52009-10-13 17:18:35 -0700371
372 // Set clear value to dim the background based on the zoom position.
Jason Samsad1bdf02010-05-14 17:54:50 -0700373 if ((g_Zoom < 0.001f) && (gZoomTarget < 0.001f)) {
Jason Sams13a75d52010-05-19 16:38:04 -0700374 rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
Jason Sams0f505e52009-10-13 17:18:35 -0700375 // When we're zoomed out and not tracking motion events, reset the pos to 0.
376 if (!g_LastTouchDown) {
377 g_PosPage = 0;
378 }
379 return lastFrame(0);
Jason Sams0f505e52009-10-13 17:18:35 -0700380 } else {
Jason Sams13a75d52010-05-19 16:38:04 -0700381 rsgClearColor(0.0f, 0.0f, 0.0f, g_Zoom);
Jason Sams0f505e52009-10-13 17:18:35 -0700382 }
383
Jason Sams13a75d52010-05-19 16:38:04 -0700384 rsgBindProgramStore(gPS);
385
Jason Sams0f505e52009-10-13 17:18:35 -0700386 // icons & labels
Jason Sams13a75d52010-05-19 16:38:04 -0700387 if (rsgGetWidth() > rsgGetHeight()) {
Jason Samsad1bdf02010-05-14 17:54:50 -0700388 g_Cols = COLUMNS_PER_PAGE_LANDSCAPE;
389 g_Rows = ROWS_PER_PAGE_LANDSCAPE;
Joe Onorato20e7a562010-03-18 17:12:52 -0700390 } else {
Jason Samsad1bdf02010-05-14 17:54:50 -0700391 g_Cols = COLUMNS_PER_PAGE_PORTRAIT;
392 g_Rows = ROWS_PER_PAGE_PORTRAIT;
Jason Samscc903492010-03-12 12:46:04 -0800393 }
Jason Samsad1bdf02010-05-14 17:54:50 -0700394
Jason Sams14f67ed2010-05-11 14:02:43 -0700395 g_PosMax = ((gIconCount + (g_Cols-1)) / g_Cols) - g_Rows;
Jason Sams0f505e52009-10-13 17:18:35 -0700396 if (g_PosMax < 0) g_PosMax = 0;
397
Jason Samscc903492010-03-12 12:46:04 -0800398 updatePos();
Jason Sams0f505e52009-10-13 17:18:35 -0700399 updateReadback();
400
Jason Sams0f505e52009-10-13 17:18:35 -0700401 // Draw the icons ========================================
Jason Sams6471c8b2010-01-20 14:15:22 -0800402 drawFrontGrid(g_PosPage, g_Animation);
Jason Samsc8514792009-10-29 14:27:29 -0700403
Jason Sams13a75d52010-05-19 16:38:04 -0700404 rsgBindProgramFragment(gPFTexNearest);
Jason Samsb52dfa02009-10-14 20:16:14 -0700405 draw_home_button();
Jason Sams13a75d52010-05-19 16:38:04 -0700406 return lastFrame((g_PosVelocity != 0) || rsFrac(g_PosPage) || g_Zoom != gZoomTarget || (g_MoveToTime != 0));
Jason Sams0f505e52009-10-13 17:18:35 -0700407}
408
Jason Sams14f67ed2010-05-11 14:02:43 -0700409