blob: 6fa28e268cf192a61018d480fb2d5b2230bb2e3c [file] [log] [blame]
Jason Sams0f505e52009-10-13 17:18:35 -07001#pragma version(1)
Jason Sams14f67ed2010-05-11 14:02:43 -07002
3#include "../../../../../frameworks/base/libs/rs/scriptc/rs_types.rsh"
4#include "../../../../../frameworks/base/libs/rs/scriptc/rs_math.rsh"
5#include "../../../../../frameworks/base/libs/rs/scriptc/rs_graphics.rsh"
Jason Sams0f505e52009-10-13 17:18:35 -07006
7#define PI 3.14159f
8
Jason Sams14f67ed2010-05-11 14:02:43 -07009// Constants from Java
10int COLUMNS_PER_PAGE_PORTRAIT;
11int ROWS_PER_PAGE_PORTRAIT;
12int COLUMNS_PER_PAGE_LANDSCAPE;
13int ROWS_PER_PAGE_LANDSCAPE;
14
15float gNewPositionX;
16int gNewTouchDown;
17float gFlingVelocity;
18int gIconCount;
19int gSelectedIconIndex;
20rs_allocation gSelectedIconTexture;
21float gZoomTarget;
22rs_allocation gHomeButton;
23float gTargetPos;
24
25rs_program_fragment gPFTexNearest;
26rs_program_fragment gPFTexMip;
27rs_program_fragment gPFTexMipAlpha;
28rs_program_vertex gPVCurve;
29rs_program_store gPS;
30rs_mesh gSMCell;
31
32rs_allocation *gIconIDs;
33rs_allocation *gLabelIDs;
34
35typedef struct VpConsts_s {
36 float4 Position;
37 float4 ScaleOffset;
38 float2 BendPos;
39 float2 ImgSize;
40} VpConsts_t;
41VpConsts_t *vpConstants;
42
43
44#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)
45#pragma rs export_func(resetHWWar, move, moveTo, setZoom, fling)
46
47
48void debugAll()
49{
Jason Sams14f67ed2010-05-11 14:02:43 -070050}
51
Jason Sams0f505e52009-10-13 17:18:35 -070052
53// Attraction to center values from page edge to page center.
Jason Samsad1bdf02010-05-14 17:54:50 -070054static float g_AttractionTable[9] = {20.f, 20.f, 20.f, 10.f, -10.f, -20.f, -20.f, -20.f, -20.f};
55static float g_FrictionTable[9] = {10.f, 10.f, 11.f, 15.f, 15.f, 11.f, 10.f, 10.f, 10.f};
56static float g_PhysicsTableSize = 7;
Jason Sams0f505e52009-10-13 17:18:35 -070057
Jason Samsad1bdf02010-05-14 17:54:50 -070058static float g_PosPage = 0.f;
59static float g_PosVelocity = 0.f;
60static float g_LastPositionX = 0.f;
61static int g_LastTouchDown = 0;
Jason Sams14f67ed2010-05-11 14:02:43 -070062static float g_DT;
Jason Sams13a75d52010-05-19 16:38:04 -070063static int64_t g_LastTime;
Jason Sams14f67ed2010-05-11 14:02:43 -070064static int g_PosMax;
Jason Samsad1bdf02010-05-14 17:54:50 -070065static float g_Zoom = 0.f;
66static float g_Animation = 1.f;
Jason Sams14f67ed2010-05-11 14:02:43 -070067static float g_OldPosPage;
68static float g_OldPosVelocity;
69static float g_OldZoom;
Jason Samsad1bdf02010-05-14 17:54:50 -070070static float g_MoveToTotalTime = 0.2f;
71static float g_MoveToTime = 0.f;
72static float g_MoveToOldPos = 0.f;
Jason Samsc1c521e2009-10-19 14:45:45 -070073
Jason Sams14f67ed2010-05-11 14:02:43 -070074static int g_Cols;
75static int g_Rows;
Jason Sams0f505e52009-10-13 17:18:35 -070076
77// Drawing constants, should be parameters ======
78#define VIEW_ANGLE 1.28700222f
79
Jason Sams14f67ed2010-05-11 14:02:43 -070080static int g_DrawLastFrame;
81static int lastFrame(int draw) {
Jason Sams5c1417a2010-05-18 17:06:04 -070082 // We draw one extra frame to work around the last frame post bug.
83 // We also need to track if we drew the last frame to deal with large DT
84 // in the physics.
Jason Sams0f505e52009-10-13 17:18:35 -070085 g_DrawLastFrame = draw;
Jason Sams13a75d52010-05-19 16:38:04 -070086 return draw;
Jason Sams0f505e52009-10-13 17:18:35 -070087}
88
Jason Sams14f67ed2010-05-11 14:02:43 -070089static void updateReadback() {
Jason Samsad1bdf02010-05-14 17:54:50 -070090 if ((g_OldPosPage != g_PosPage) ||
91 (g_OldPosVelocity != g_PosVelocity) ||
92 (g_OldZoom != g_Zoom)) {
Jason Sams0f505e52009-10-13 17:18:35 -070093
94 g_OldPosPage = g_PosPage;
95 g_OldPosVelocity = g_PosVelocity;
96 g_OldZoom = g_Zoom;
97
98 int i[3];
99 i[0] = g_PosPage * (1 << 16);
100 i[1] = g_PosVelocity * (1 << 16);
101 i[2] = g_OldZoom * (1 << 16);
Jason Sams13a75d52010-05-19 16:38:04 -0700102 rsSendToClient(&i[0], 1, 12, 1);
Jason Samsad1bdf02010-05-14 17:54:50 -0700103 }
Jason Sams0f505e52009-10-13 17:18:35 -0700104}
105
Jason Samsad1bdf02010-05-14 17:54:50 -0700106void setColor(float r, float g, float b, float a) {
Jason Sams41b61c82009-10-15 15:40:54 -0700107}
Jason Sams0f505e52009-10-13 17:18:35 -0700108void init() {
Jason Sams41b61c82009-10-15 15:40:54 -0700109}
Jason Sams41b61c82009-10-15 15:40:54 -0700110void resetHWWar() {
Jason Sams0f505e52009-10-13 17:18:35 -0700111}
112
113void move() {
114 if (g_LastTouchDown) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700115 float dx = -(gNewPositionX - g_LastPositionX);
Jason Sams0f505e52009-10-13 17:18:35 -0700116 g_PosVelocity = 0;
Jason Sams6ec11bc2010-01-19 17:56:52 -0800117 g_PosPage += dx * 5.2f;
Jason Sams0f505e52009-10-13 17:18:35 -0700118
Jason Samsc8514792009-10-29 14:27:29 -0700119 float pmin = -0.49f;
120 float pmax = g_PosMax + 0.49f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700121 g_PosPage = clamp(g_PosPage, pmin, pmax);
Jason Sams0f505e52009-10-13 17:18:35 -0700122 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700123 g_LastTouchDown = gNewTouchDown;
124 g_LastPositionX = gNewPositionX;
Jason Samsc1c521e2009-10-19 14:45:45 -0700125 g_MoveToTime = 0;
Jason Sams0f505e52009-10-13 17:18:35 -0700126}
127
Jason Samsc1c521e2009-10-19 14:45:45 -0700128void moveTo() {
129 g_MoveToTime = g_MoveToTotalTime;
130 g_PosVelocity = 0;
131 g_MoveToOldPos = g_PosPage;
132}
133
Joe Onorato3a8820b2009-11-10 15:06:42 -0800134void setZoom() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700135 g_Zoom = gZoomTarget;
Joe Onorato3a8820b2009-11-10 15:06:42 -0800136 g_DrawLastFrame = 1;
137 updateReadback();
138}
139
Jason Sams0f505e52009-10-13 17:18:35 -0700140void fling() {
141 g_LastTouchDown = 0;
Jason Sams14f67ed2010-05-11 14:02:43 -0700142 g_PosVelocity = -gFlingVelocity * 4;
143 float av = fabs(g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700144 float minVel = 3.5f;
145
Jason Sams13a75d52010-05-19 16:38:04 -0700146 minVel *= 1.f - (fabs(rsFrac(g_PosPage + 0.5f) - 0.5f) * 0.45f);
Jason Sams0f505e52009-10-13 17:18:35 -0700147
148 if (av < minVel && av > 0.2f) {
149 if (g_PosVelocity > 0) {
150 g_PosVelocity = minVel;
151 } else {
152 g_PosVelocity = -minVel;
153 }
154 }
155
156 if (g_PosPage <= 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700157 g_PosVelocity = max(0.f, g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700158 }
159 if (g_PosPage > g_PosMax) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700160 g_PosVelocity = min(0.f, g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700161 }
162}
163
Jason Sams14f67ed2010-05-11 14:02:43 -0700164// Interpolates values in the range 0..1 to a curve that eases in
165// and out.
166static float getInterpolation(float input) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700167 return (cos((input + 1) * PI) * 0.5f) + 0.5f;
Jason Sams0f505e52009-10-13 17:18:35 -0700168}
169
Mike Cleron7d5d7462009-10-20 14:06:00 -0700170
Jason Sams14f67ed2010-05-11 14:02:43 -0700171static void updatePos() {
Jason Sams0f505e52009-10-13 17:18:35 -0700172 if (g_LastTouchDown) {
173 return;
174 }
175
Jason Sams13a75d52010-05-19 16:38:04 -0700176 float tablePosNorm = rsFrac(g_PosPage + 0.5f);
Jason Sams0f505e52009-10-13 17:18:35 -0700177 float tablePosF = tablePosNorm * g_PhysicsTableSize;
178 int tablePosI = tablePosF;
179 float tablePosFrac = tablePosF - tablePosI;
Jason Sams14f67ed2010-05-11 14:02:43 -0700180 float accel = mix(g_AttractionTable[tablePosI],
Jason Sams0f505e52009-10-13 17:18:35 -0700181 g_AttractionTable[tablePosI + 1],
182 tablePosFrac) * g_DT;
Jason Sams14f67ed2010-05-11 14:02:43 -0700183 float friction = mix(g_FrictionTable[tablePosI],
Jason Sams2e19c052009-10-20 18:19:55 -0700184 g_FrictionTable[tablePosI + 1],
185 tablePosFrac) * g_DT;
Jason Sams0f505e52009-10-13 17:18:35 -0700186
Jason Samsc1c521e2009-10-19 14:45:45 -0700187 if (g_MoveToTime) {
Jason Samsc8514792009-10-29 14:27:29 -0700188 // New position is old posiition + (total distance) * (interpolated time)
Jason Sams14f67ed2010-05-11 14:02:43 -0700189 g_PosPage = g_MoveToOldPos + (gTargetPos - g_MoveToOldPos) * getInterpolation((g_MoveToTotalTime - g_MoveToTime) / g_MoveToTotalTime);
Jason Samsc1c521e2009-10-19 14:45:45 -0700190 g_MoveToTime -= g_DT;
191 if (g_MoveToTime <= 0) {
192 g_MoveToTime = 0;
Jason Sams14f67ed2010-05-11 14:02:43 -0700193 g_PosPage = gTargetPos;
Jason Samsc1c521e2009-10-19 14:45:45 -0700194 }
195 return;
196 }
197
Jason Sams0f505e52009-10-13 17:18:35 -0700198 // If our velocity is low OR acceleration is opposing it, apply it.
Jason Sams14f67ed2010-05-11 14:02:43 -0700199 if (fabs(g_PosVelocity) < 4.0f || (g_PosVelocity * accel) < 0) {
Jason Sams0f505e52009-10-13 17:18:35 -0700200 g_PosVelocity += accel;
201 }
Jason Sams13a75d52010-05-19 16:38:04 -0700202 //RS_DEBUG(g_PosPage);
203 //RS_DEBUG(g_PosVelocity);
204 //RS_DEBUG(friction);
205 //RS_DEBUG(accel);
Jason Sams0f505e52009-10-13 17:18:35 -0700206
Jason Samsc8514792009-10-29 14:27:29 -0700207 // Normal physics
208 if (g_PosVelocity > 0) {
209 g_PosVelocity -= friction;
Jason Sams14f67ed2010-05-11 14:02:43 -0700210 g_PosVelocity = max(g_PosVelocity, 0.f);
Jason Samsc8514792009-10-29 14:27:29 -0700211 } else {
212 g_PosVelocity += friction;
Jason Sams14f67ed2010-05-11 14:02:43 -0700213 g_PosVelocity = min(g_PosVelocity, 0.f);
Jason Samsc8514792009-10-29 14:27:29 -0700214 }
215
Jason Sams14f67ed2010-05-11 14:02:43 -0700216 if ((friction > fabs(g_PosVelocity)) && (friction > fabs(accel))) {
Jason Sams0f505e52009-10-13 17:18:35 -0700217 // Special get back to center and overcome friction physics.
218 float t = tablePosNorm - 0.5f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700219 if (fabs(t) < (friction * g_DT)) {
Jason Sams0f505e52009-10-13 17:18:35 -0700220 // really close, just snap
Jason Sams14f67ed2010-05-11 14:02:43 -0700221 g_PosPage = round(g_PosPage);
Jason Sams0f505e52009-10-13 17:18:35 -0700222 g_PosVelocity = 0;
223 } else {
224 if (t > 0) {
225 g_PosVelocity = -friction;
226 } else {
227 g_PosVelocity = friction;
228 }
229 }
Jason Sams0f505e52009-10-13 17:18:35 -0700230 }
Jason Sams0f505e52009-10-13 17:18:35 -0700231
232 // Check for out of boundry conditions.
233 if (g_PosPage < 0 && g_PosVelocity < 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700234 float damp = 1.0f + (g_PosPage * 4);
235 damp = clamp(damp, 0.f, 0.9f);
Jason Sams0f505e52009-10-13 17:18:35 -0700236 g_PosVelocity *= damp;
237 }
238 if (g_PosPage > g_PosMax && g_PosVelocity > 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700239 float damp = 1.0f - ((g_PosPage - g_PosMax) * 4);
240 damp = clamp(damp, 0.f, 0.9f);
Jason Sams0f505e52009-10-13 17:18:35 -0700241 g_PosVelocity *= damp;
242 }
Jason Samsc8514792009-10-29 14:27:29 -0700243
244 g_PosPage += g_PosVelocity * g_DT;
Jason Sams14f67ed2010-05-11 14:02:43 -0700245 g_PosPage = clamp(g_PosPage, -0.49f, g_PosMax + 0.49f);
Jason Sams0f505e52009-10-13 17:18:35 -0700246}
247
Jason Sams14f67ed2010-05-11 14:02:43 -0700248static void
Jason Sams0f505e52009-10-13 17:18:35 -0700249draw_home_button()
250{
Jason Samsad1bdf02010-05-14 17:54:50 -0700251 color(1.0f, 1.0f, 1.0f, 1.0f);
Jason Sams13a75d52010-05-19 16:38:04 -0700252 rsgBindTexture(gPFTexNearest, 0, gHomeButton);
Jason Sams0f505e52009-10-13 17:18:35 -0700253
Jason Sams13a75d52010-05-19 16:38:04 -0700254 float w = rsgGetWidth();
255 float h = rsgGetHeight();
256 float tw = rsAllocationGetDimX(gHomeButton);
257 float th = rsAllocationGetDimY(gHomeButton);
Jason Sams76512482010-02-04 16:31:35 -0800258
259 float x;
260 float y;
Jason Sams13a75d52010-05-19 16:38:04 -0700261 if (w > h) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700262 x = w - (tw * (1 - g_Animation)) + 20;
263 y = (h - th) * 0.5f;
Jason Sams76512482010-02-04 16:31:35 -0800264 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700265 x = (w - tw) / 2;
266 y = -g_Animation * th;
Jason Sams76512482010-02-04 16:31:35 -0800267 y -= 30; // move the house to the edge of the screen as it doesn't fill the texture.
268 }
269
Jason Sams13a75d52010-05-19 16:38:04 -0700270 rsgDrawSpriteScreenspace(x, y, 0, tw, th);
Jason Sams0f505e52009-10-13 17:18:35 -0700271}
272
Jason Sams14f67ed2010-05-11 14:02:43 -0700273static void drawFrontGrid(float rowOffset, float p)
Jason Sams0f505e52009-10-13 17:18:35 -0700274{
Jason Sams13a75d52010-05-19 16:38:04 -0700275 float h = rsgGetHeight();
276 float w = rsgGetWidth();
Jason Sams0f505e52009-10-13 17:18:35 -0700277
278 int intRowOffset = rowOffset;
279 float rowFrac = rowOffset - intRowOffset;
Jason Sams13a75d52010-05-19 16:38:04 -0700280 float colWidth = 120.f;//w / 4;
Jason Sams0f505e52009-10-13 17:18:35 -0700281 float rowHeight = colWidth + 25.f;
Jason Samsb4ecab22010-01-19 16:43:26 -0800282 float yoff = 0.5f * h + 1.5f * rowHeight;
Jason Sams0f505e52009-10-13 17:18:35 -0700283
284 int row, col;
Jason Sams76512482010-02-04 16:31:35 -0800285 int colCount = 4;
286 if (w > h) {
287 colCount = 6;
288 rowHeight -= 12.f;
289 yoff = 0.47f * h + 1.0f * rowHeight;
290 }
291
292 int iconNum = (intRowOffset - 5) * colCount;
293
Jason Sams13a75d52010-05-19 16:38:04 -0700294 rsgBindProgramVertex(gPVCurve);
Jason Samsb4ecab22010-01-19 16:43:26 -0800295
Jason Sams76512482010-02-04 16:31:35 -0800296 vpConstants->Position.z = p;
Jason Samsb4ecab22010-01-19 16:43:26 -0800297
Jason Samsad1bdf02010-05-14 17:54:50 -0700298 color(1.0f, 1.0f, 1.0f, 1.0f);
Jason Samsb4ecab22010-01-19 16:43:26 -0800299 for (row = -5; row < 15; row++) {
Jason Sams0f505e52009-10-13 17:18:35 -0700300 float y = yoff - ((-rowFrac + row) * rowHeight);
301
Jason Sams76512482010-02-04 16:31:35 -0800302 for (col=0; col < colCount; col++) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700303 if (iconNum >= gIconCount) {
Jason Sams0f505e52009-10-13 17:18:35 -0700304 return;
305 }
306
307 if (iconNum >= 0) {
Jason Samsb4ecab22010-01-19 16:43:26 -0800308 float x = colWidth * col + (colWidth / 2);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800309 vpConstants->Position.x = x + 0.2f;
Jason Sams1a94ee32010-01-20 13:34:30 -0800310
Jason Sams14f67ed2010-05-11 14:02:43 -0700311 if (gSelectedIconIndex == iconNum && !p && gSelectedIconTexture) {
Jason Sams13a75d52010-05-19 16:38:04 -0700312 rsgBindProgramFragment(gPFTexNearest);
313 rsgBindTexture(gPFTexNearest, 0, gSelectedIconTexture);
314 vpConstants->ImgSize.x = rsAllocationGetDimX(gSelectedIconTexture);
315 vpConstants->ImgSize.y = rsAllocationGetDimY(gSelectedIconTexture);
316 vpConstants->Position.y = y - (rsAllocationGetDimY(gSelectedIconTexture)
317 - rsAllocationGetDimY(gIconIDs[iconNum])) * 0.5f;
318 rsgDrawSimpleMesh(gSMCell);
Jason Sams37f262d2010-01-20 11:19:51 -0800319 }
320
Jason Sams13a75d52010-05-19 16:38:04 -0700321 rsgBindProgramFragment(gPFTexMip);
322 vpConstants->ImgSize.x = rsAllocationGetDimX(gIconIDs[iconNum]);
323 vpConstants->ImgSize.y = rsAllocationGetDimY(gIconIDs[iconNum]);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800324 vpConstants->Position.y = y - 0.2f;
Jason Sams13a75d52010-05-19 16:38:04 -0700325 rsgBindTexture(gPFTexMip, 0, gIconIDs[iconNum]);
326 rsgDrawSimpleMesh(gSMCell);
Joe Onorato742d7fc2009-10-15 19:48:16 -0700327
Jason Sams13a75d52010-05-19 16:38:04 -0700328 rsgBindProgramFragment(gPFTexMipAlpha);
329 vpConstants->ImgSize.x = rsAllocationGetDimX(gLabelIDs[iconNum]);
330 vpConstants->ImgSize.y = rsAllocationGetDimY(gLabelIDs[iconNum]);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800331 vpConstants->Position.y = y - 64.f - 0.2f;
Jason Sams13a75d52010-05-19 16:38:04 -0700332 rsgBindTexture(gPFTexMipAlpha, 0, gLabelIDs[iconNum]);
333 rsgDrawSimpleMesh(gSMCell);
Jason Sams0f505e52009-10-13 17:18:35 -0700334 }
335 iconNum++;
336 }
337 }
338}
339
Jason Sams0f505e52009-10-13 17:18:35 -0700340
Jason Sams14f67ed2010-05-11 14:02:43 -0700341int root()
Jason Sams0f505e52009-10-13 17:18:35 -0700342{
343 // Compute dt in seconds.
Jason Sams13a75d52010-05-19 16:38:04 -0700344 int64_t newTime = rsUptimeMillis();
Jason Sams14f67ed2010-05-11 14:02:43 -0700345 g_DT = (newTime - g_LastTime) * 0.001f;
Jason Sams0f505e52009-10-13 17:18:35 -0700346 g_LastTime = newTime;
Jason Sams2e19c052009-10-20 18:19:55 -0700347
Jason Sams0f505e52009-10-13 17:18:35 -0700348 if (!g_DrawLastFrame) {
349 // If we stopped rendering we cannot use DT.
350 // assume 30fps in this case.
351 g_DT = 0.033f;
352 }
Jason Samsb52dfa02009-10-14 20:16:14 -0700353 // physics may break if DT is large.
Jason Sams14f67ed2010-05-11 14:02:43 -0700354 g_DT = min(g_DT, 0.2f);
Jason Sams0f505e52009-10-13 17:18:35 -0700355
Jason Sams14f67ed2010-05-11 14:02:43 -0700356 if (g_Zoom != gZoomTarget) {
Jason Sams6471c8b2010-01-20 14:15:22 -0800357 float dz = g_DT * 1.7f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700358 if (gZoomTarget < 0.5f) {
Jason Sams6471c8b2010-01-20 14:15:22 -0800359 dz = -dz;
Jason Sams0f505e52009-10-13 17:18:35 -0700360 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700361 if (fabs(g_Zoom - gZoomTarget) < fabs(dz)) {
362 g_Zoom = gZoomTarget;
Jason Sams0f505e52009-10-13 17:18:35 -0700363 } else {
364 g_Zoom += dz;
365 }
366 updateReadback();
367 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700368 g_Animation = pow(1.f - g_Zoom, 3.f);
Jason Sams0f505e52009-10-13 17:18:35 -0700369
370 // Set clear value to dim the background based on the zoom position.
Jason Samsad1bdf02010-05-14 17:54:50 -0700371 if ((g_Zoom < 0.001f) && (gZoomTarget < 0.001f)) {
Jason Sams13a75d52010-05-19 16:38:04 -0700372 rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
Jason Sams0f505e52009-10-13 17:18:35 -0700373 // When we're zoomed out and not tracking motion events, reset the pos to 0.
374 if (!g_LastTouchDown) {
375 g_PosPage = 0;
376 }
377 return lastFrame(0);
Jason Sams0f505e52009-10-13 17:18:35 -0700378 } else {
Jason Sams13a75d52010-05-19 16:38:04 -0700379 rsgClearColor(0.0f, 0.0f, 0.0f, g_Zoom);
Jason Sams0f505e52009-10-13 17:18:35 -0700380 }
381
Jason Sams13a75d52010-05-19 16:38:04 -0700382 rsgBindProgramStore(gPS);
383
Jason Sams0f505e52009-10-13 17:18:35 -0700384 // icons & labels
Jason Sams13a75d52010-05-19 16:38:04 -0700385 if (rsgGetWidth() > rsgGetHeight()) {
Jason Samsad1bdf02010-05-14 17:54:50 -0700386 g_Cols = COLUMNS_PER_PAGE_LANDSCAPE;
387 g_Rows = ROWS_PER_PAGE_LANDSCAPE;
Joe Onorato20e7a562010-03-18 17:12:52 -0700388 } else {
Jason Samsad1bdf02010-05-14 17:54:50 -0700389 g_Cols = COLUMNS_PER_PAGE_PORTRAIT;
390 g_Rows = ROWS_PER_PAGE_PORTRAIT;
Jason Samscc903492010-03-12 12:46:04 -0800391 }
Jason Samsad1bdf02010-05-14 17:54:50 -0700392
Jason Sams14f67ed2010-05-11 14:02:43 -0700393 g_PosMax = ((gIconCount + (g_Cols-1)) / g_Cols) - g_Rows;
Jason Sams0f505e52009-10-13 17:18:35 -0700394 if (g_PosMax < 0) g_PosMax = 0;
395
Jason Samscc903492010-03-12 12:46:04 -0800396 updatePos();
Jason Sams0f505e52009-10-13 17:18:35 -0700397 updateReadback();
398
Jason Sams0f505e52009-10-13 17:18:35 -0700399 // Draw the icons ========================================
Jason Sams6471c8b2010-01-20 14:15:22 -0800400 drawFrontGrid(g_PosPage, g_Animation);
Jason Samsc8514792009-10-29 14:27:29 -0700401
Jason Sams13a75d52010-05-19 16:38:04 -0700402 rsgBindProgramFragment(gPFTexNearest);
Jason Samsb52dfa02009-10-14 20:16:14 -0700403 draw_home_button();
Jason Sams13a75d52010-05-19 16:38:04 -0700404 return lastFrame((g_PosVelocity != 0) || rsFrac(g_PosPage) || g_Zoom != gZoomTarget || (g_MoveToTime != 0));
Jason Sams0f505e52009-10-13 17:18:35 -0700405}
406
Jason Sams14f67ed2010-05-11 14:02:43 -0700407