blob: 7eb670a68b3f8e359f397351e9f9f75e8029054e [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;
63static int g_LastTime;
64static 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.
85 int ret = g_DrawLastFrame | draw;
Jason Sams0f505e52009-10-13 17:18:35 -070086 g_DrawLastFrame = draw;
Jason Sams5c1417a2010-05-18 17:06:04 -070087 return ret;//draw;
Jason Sams0f505e52009-10-13 17:18:35 -070088}
89
Jason Sams14f67ed2010-05-11 14:02:43 -070090static void updateReadback() {
Jason Samsad1bdf02010-05-14 17:54:50 -070091 if ((g_OldPosPage != g_PosPage) ||
92 (g_OldPosVelocity != g_PosVelocity) ||
93 (g_OldZoom != g_Zoom)) {
Jason Sams0f505e52009-10-13 17:18:35 -070094
95 g_OldPosPage = g_PosPage;
96 g_OldPosVelocity = g_PosVelocity;
97 g_OldZoom = g_Zoom;
98
99 int i[3];
100 i[0] = g_PosPage * (1 << 16);
101 i[1] = g_PosVelocity * (1 << 16);
102 i[2] = g_OldZoom * (1 << 16);
103 sendToClient(&i[0], 1, 12, 1);
Jason Samsad1bdf02010-05-14 17:54:50 -0700104 }
Jason Sams0f505e52009-10-13 17:18:35 -0700105}
106
Jason Samsad1bdf02010-05-14 17:54:50 -0700107void setColor(float r, float g, float b, float a) {
Jason Sams41b61c82009-10-15 15:40:54 -0700108}
Jason Sams0f505e52009-10-13 17:18:35 -0700109
110void init() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700111 //debugPi(99, 10);
Jason Sams41b61c82009-10-15 15:40:54 -0700112}
113
114void resetHWWar() {
Jason Sams0f505e52009-10-13 17:18:35 -0700115}
116
117void move() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700118 //debugPi(99, 8);
Jason Sams0f505e52009-10-13 17:18:35 -0700119 if (g_LastTouchDown) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700120 float dx = -(gNewPositionX - g_LastPositionX);
Jason Sams0f505e52009-10-13 17:18:35 -0700121 g_PosVelocity = 0;
Jason Sams6ec11bc2010-01-19 17:56:52 -0800122 g_PosPage += dx * 5.2f;
Jason Sams0f505e52009-10-13 17:18:35 -0700123
Jason Samsc8514792009-10-29 14:27:29 -0700124 float pmin = -0.49f;
125 float pmax = g_PosMax + 0.49f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700126 g_PosPage = clamp(g_PosPage, pmin, pmax);
Jason Sams0f505e52009-10-13 17:18:35 -0700127 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700128 g_LastTouchDown = gNewTouchDown;
129 g_LastPositionX = gNewPositionX;
Jason Samsc1c521e2009-10-19 14:45:45 -0700130 g_MoveToTime = 0;
Jason Sams0f505e52009-10-13 17:18:35 -0700131 //debugF("Move P", g_PosPage);
132}
133
Jason Samsc1c521e2009-10-19 14:45:45 -0700134void moveTo() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700135 //debugPi(99, 7);
Jason Samsc1c521e2009-10-19 14:45:45 -0700136 g_MoveToTime = g_MoveToTotalTime;
137 g_PosVelocity = 0;
138 g_MoveToOldPos = g_PosPage;
Jason Sams2e19c052009-10-20 18:19:55 -0700139
Mike Cleron7d5d7462009-10-20 14:06:00 -0700140 // debugF("======= moveTo", state->targetPos);
Jason Samsc1c521e2009-10-19 14:45:45 -0700141}
142
Joe Onorato3a8820b2009-11-10 15:06:42 -0800143void setZoom() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700144 //debugPi(99, 6);
145 g_Zoom = gZoomTarget;
Joe Onorato3a8820b2009-11-10 15:06:42 -0800146 g_DrawLastFrame = 1;
147 updateReadback();
148}
149
Jason Sams0f505e52009-10-13 17:18:35 -0700150void fling() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700151 //debugPi(99, 5);
Jason Sams0f505e52009-10-13 17:18:35 -0700152 g_LastTouchDown = 0;
Jason Sams14f67ed2010-05-11 14:02:43 -0700153 g_PosVelocity = -gFlingVelocity * 4;
154 float av = fabs(g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700155 float minVel = 3.5f;
156
Jason Sams14f67ed2010-05-11 14:02:43 -0700157 minVel *= 1.f - (fabs(frac(g_PosPage + 0.5f) - 0.5f) * 0.45f);
Jason Sams0f505e52009-10-13 17:18:35 -0700158
159 if (av < minVel && av > 0.2f) {
160 if (g_PosVelocity > 0) {
161 g_PosVelocity = minVel;
162 } else {
163 g_PosVelocity = -minVel;
164 }
165 }
166
167 if (g_PosPage <= 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700168 g_PosVelocity = max(0.f, g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700169 }
170 if (g_PosPage > g_PosMax) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700171 g_PosVelocity = min(0.f, g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700172 }
173}
174
Jason Sams14f67ed2010-05-11 14:02:43 -0700175// Interpolates values in the range 0..1 to a curve that eases in
176// and out.
177static float getInterpolation(float input) {
178 //debugPi(99, 4);
179 return (cos((input + 1) * PI) * 0.5f) + 0.5f;
Jason Sams0f505e52009-10-13 17:18:35 -0700180}
181
Mike Cleron7d5d7462009-10-20 14:06:00 -0700182
Jason Sams14f67ed2010-05-11 14:02:43 -0700183static void updatePos() {
184 //debugPi(99, 3);
Jason Sams0f505e52009-10-13 17:18:35 -0700185 if (g_LastTouchDown) {
186 return;
187 }
188
Jason Sams14f67ed2010-05-11 14:02:43 -0700189 float tablePosNorm = frac(g_PosPage + 0.5f);
Jason Sams0f505e52009-10-13 17:18:35 -0700190 float tablePosF = tablePosNorm * g_PhysicsTableSize;
191 int tablePosI = tablePosF;
192 float tablePosFrac = tablePosF - tablePosI;
Jason Sams14f67ed2010-05-11 14:02:43 -0700193 float accel = mix(g_AttractionTable[tablePosI],
Jason Sams0f505e52009-10-13 17:18:35 -0700194 g_AttractionTable[tablePosI + 1],
195 tablePosFrac) * g_DT;
Jason Sams14f67ed2010-05-11 14:02:43 -0700196 float friction = mix(g_FrictionTable[tablePosI],
Jason Sams2e19c052009-10-20 18:19:55 -0700197 g_FrictionTable[tablePosI + 1],
198 tablePosFrac) * g_DT;
Jason Sams0f505e52009-10-13 17:18:35 -0700199
Jason Samsc1c521e2009-10-19 14:45:45 -0700200 if (g_MoveToTime) {
Jason Samsc8514792009-10-29 14:27:29 -0700201 // New position is old posiition + (total distance) * (interpolated time)
Jason Sams14f67ed2010-05-11 14:02:43 -0700202 g_PosPage = g_MoveToOldPos + (gTargetPos - g_MoveToOldPos) * getInterpolation((g_MoveToTotalTime - g_MoveToTime) / g_MoveToTotalTime);
Jason Samsc1c521e2009-10-19 14:45:45 -0700203 g_MoveToTime -= g_DT;
204 if (g_MoveToTime <= 0) {
205 g_MoveToTime = 0;
Jason Sams14f67ed2010-05-11 14:02:43 -0700206 g_PosPage = gTargetPos;
Jason Samsc1c521e2009-10-19 14:45:45 -0700207 }
208 return;
209 }
210
Jason Sams0f505e52009-10-13 17:18:35 -0700211 // If our velocity is low OR acceleration is opposing it, apply it.
Jason Sams14f67ed2010-05-11 14:02:43 -0700212 if (fabs(g_PosVelocity) < 4.0f || (g_PosVelocity * accel) < 0) {
Jason Sams0f505e52009-10-13 17:18:35 -0700213 g_PosVelocity += accel;
214 }
Jason Samsc8514792009-10-29 14:27:29 -0700215 //debugF("g_PosPage", g_PosPage);
216 //debugF(" g_PosVelocity", g_PosVelocity);
217 //debugF(" friction", friction);
218 //debugF(" accel", accel);
Jason Sams0f505e52009-10-13 17:18:35 -0700219
Jason Samsc8514792009-10-29 14:27:29 -0700220 // Normal physics
221 if (g_PosVelocity > 0) {
222 g_PosVelocity -= friction;
Jason Sams14f67ed2010-05-11 14:02:43 -0700223 g_PosVelocity = max(g_PosVelocity, 0.f);
Jason Samsc8514792009-10-29 14:27:29 -0700224 } else {
225 g_PosVelocity += friction;
Jason Sams14f67ed2010-05-11 14:02:43 -0700226 g_PosVelocity = min(g_PosVelocity, 0.f);
Jason Samsc8514792009-10-29 14:27:29 -0700227 }
228
Jason Sams14f67ed2010-05-11 14:02:43 -0700229 if ((friction > fabs(g_PosVelocity)) && (friction > fabs(accel))) {
Jason Sams0f505e52009-10-13 17:18:35 -0700230 // Special get back to center and overcome friction physics.
231 float t = tablePosNorm - 0.5f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700232 if (fabs(t) < (friction * g_DT)) {
Jason Sams0f505e52009-10-13 17:18:35 -0700233 // really close, just snap
Jason Sams14f67ed2010-05-11 14:02:43 -0700234 g_PosPage = round(g_PosPage);
Jason Sams0f505e52009-10-13 17:18:35 -0700235 g_PosVelocity = 0;
236 } else {
237 if (t > 0) {
238 g_PosVelocity = -friction;
239 } else {
240 g_PosVelocity = friction;
241 }
242 }
Jason Sams0f505e52009-10-13 17:18:35 -0700243 }
Jason Sams0f505e52009-10-13 17:18:35 -0700244
245 // Check for out of boundry conditions.
246 if (g_PosPage < 0 && g_PosVelocity < 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700247 float damp = 1.0f + (g_PosPage * 4);
248 damp = clamp(damp, 0.f, 0.9f);
Jason Sams0f505e52009-10-13 17:18:35 -0700249 g_PosVelocity *= damp;
250 }
251 if (g_PosPage > g_PosMax && g_PosVelocity > 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700252 float damp = 1.0f - ((g_PosPage - g_PosMax) * 4);
253 damp = clamp(damp, 0.f, 0.9f);
Jason Sams0f505e52009-10-13 17:18:35 -0700254 g_PosVelocity *= damp;
255 }
Jason Samsc8514792009-10-29 14:27:29 -0700256
257 g_PosPage += g_PosVelocity * g_DT;
Jason Sams14f67ed2010-05-11 14:02:43 -0700258 g_PosPage = clamp(g_PosPage, -0.49f, g_PosMax + 0.49f);
Jason Sams0f505e52009-10-13 17:18:35 -0700259}
260
Jason Sams14f67ed2010-05-11 14:02:43 -0700261static void
Jason Sams0f505e52009-10-13 17:18:35 -0700262draw_home_button()
263{
Jason Sams14f67ed2010-05-11 14:02:43 -0700264 //debugPi(99, 2);
Jason Samsad1bdf02010-05-14 17:54:50 -0700265 color(1.0f, 1.0f, 1.0f, 1.0f);
Jason Sams14f67ed2010-05-11 14:02:43 -0700266 bindTexture(gPFTexNearest, 0, gHomeButton);
Jason Sams0f505e52009-10-13 17:18:35 -0700267
Jason Sams76512482010-02-04 16:31:35 -0800268 float w = getWidth();
269 float h = getHeight();
Jason Sams14f67ed2010-05-11 14:02:43 -0700270 float tw = allocGetDimX(gHomeButton);
271 float th = allocGetDimY(gHomeButton);
Jason Sams76512482010-02-04 16:31:35 -0800272
273 float x;
274 float y;
275 if (getWidth() > getHeight()) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700276 x = w - (tw * (1 - g_Animation)) + 20;
277 y = (h - th) * 0.5f;
Jason Sams76512482010-02-04 16:31:35 -0800278 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700279 x = (w - tw) / 2;
280 y = -g_Animation * th;
Jason Sams76512482010-02-04 16:31:35 -0800281 y -= 30; // move the house to the edge of the screen as it doesn't fill the texture.
282 }
283
Jason Sams14f67ed2010-05-11 14:02:43 -0700284 drawSpriteScreenspace(x, y, 0, tw, th);
Jason Sams0f505e52009-10-13 17:18:35 -0700285}
286
Jason Sams14f67ed2010-05-11 14:02:43 -0700287static void drawFrontGrid(float rowOffset, float p)
Jason Sams0f505e52009-10-13 17:18:35 -0700288{
Jason Sams14f67ed2010-05-11 14:02:43 -0700289 //debugPi(99, 1);
Jason Sams0f505e52009-10-13 17:18:35 -0700290 float h = getHeight();
291 float w = getWidth();
292
293 int intRowOffset = rowOffset;
294 float rowFrac = rowOffset - intRowOffset;
Jason Sams76512482010-02-04 16:31:35 -0800295 float colWidth = 120.f;//getWidth() / 4;
Jason Sams0f505e52009-10-13 17:18:35 -0700296 float rowHeight = colWidth + 25.f;
Jason Samsb4ecab22010-01-19 16:43:26 -0800297 float yoff = 0.5f * h + 1.5f * rowHeight;
Jason Sams0f505e52009-10-13 17:18:35 -0700298
299 int row, col;
Jason Sams76512482010-02-04 16:31:35 -0800300 int colCount = 4;
301 if (w > h) {
302 colCount = 6;
303 rowHeight -= 12.f;
304 yoff = 0.47f * h + 1.0f * rowHeight;
305 }
306
307 int iconNum = (intRowOffset - 5) * colCount;
308
Jason Sams14f67ed2010-05-11 14:02:43 -0700309 bindProgramVertex(gPVCurve);
Jason Samsb4ecab22010-01-19 16:43:26 -0800310
Jason Sams76512482010-02-04 16:31:35 -0800311 vpConstants->Position.z = p;
Jason Samsb4ecab22010-01-19 16:43:26 -0800312
Jason Samsad1bdf02010-05-14 17:54:50 -0700313 color(1.0f, 1.0f, 1.0f, 1.0f);
Jason Samsb4ecab22010-01-19 16:43:26 -0800314 for (row = -5; row < 15; row++) {
Jason Sams0f505e52009-10-13 17:18:35 -0700315 float y = yoff - ((-rowFrac + row) * rowHeight);
316
Jason Sams76512482010-02-04 16:31:35 -0800317 for (col=0; col < colCount; col++) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700318 if (iconNum >= gIconCount) {
Jason Sams0f505e52009-10-13 17:18:35 -0700319 return;
320 }
321
322 if (iconNum >= 0) {
Jason Samsb4ecab22010-01-19 16:43:26 -0800323 float x = colWidth * col + (colWidth / 2);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800324 vpConstants->Position.x = x + 0.2f;
Jason Sams1a94ee32010-01-20 13:34:30 -0800325
Jason Sams14f67ed2010-05-11 14:02:43 -0700326 if (gSelectedIconIndex == iconNum && !p && gSelectedIconTexture) {
327 bindProgramFragment(gPFTexNearest);
328 bindTexture(gPFTexNearest, 0, gSelectedIconTexture);
329 vpConstants->ImgSize.x = allocGetDimX(gSelectedIconTexture);
330 vpConstants->ImgSize.y = allocGetDimY(gSelectedIconTexture);
331 vpConstants->Position.y = y - (allocGetDimY(gSelectedIconTexture) - allocGetDimY(gIconIDs[iconNum])) * 0.5f;
332 drawSimpleMesh(gSMCell);
Jason Sams37f262d2010-01-20 11:19:51 -0800333 }
334
Jason Sams14f67ed2010-05-11 14:02:43 -0700335 bindProgramFragment(gPFTexMip);
336 vpConstants->ImgSize.x = allocGetDimX(gIconIDs[iconNum]);
337 vpConstants->ImgSize.y = allocGetDimY(gIconIDs[iconNum]);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800338 vpConstants->Position.y = y - 0.2f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700339 bindTexture(gPFTexMip, 0, gIconIDs[iconNum]);
340 drawSimpleMesh(gSMCell);
Joe Onorato742d7fc2009-10-15 19:48:16 -0700341
Jason Sams14f67ed2010-05-11 14:02:43 -0700342 bindProgramFragment(gPFTexMipAlpha);
343 vpConstants->ImgSize.x = allocGetDimX(gLabelIDs[iconNum]);
344 vpConstants->ImgSize.y = allocGetDimY(gLabelIDs[iconNum]);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800345 vpConstants->Position.y = y - 64.f - 0.2f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700346 bindTexture(gPFTexMipAlpha, 0, gLabelIDs[iconNum]);
347 drawSimpleMesh(gSMCell);
Jason Sams0f505e52009-10-13 17:18:35 -0700348 }
349 iconNum++;
350 }
351 }
352}
353
Jason Sams0f505e52009-10-13 17:18:35 -0700354
Jason Sams14f67ed2010-05-11 14:02:43 -0700355int root()
Jason Sams0f505e52009-10-13 17:18:35 -0700356{
Jason Sams14f67ed2010-05-11 14:02:43 -0700357 //debugAll();
358 bindProgramStore(gPS);
359
Jason Sams0f505e52009-10-13 17:18:35 -0700360 // Compute dt in seconds.
361 int newTime = uptimeMillis();
Jason Sams14f67ed2010-05-11 14:02:43 -0700362 g_DT = (newTime - g_LastTime) * 0.001f;
Jason Sams0f505e52009-10-13 17:18:35 -0700363 g_LastTime = newTime;
Jason Sams2e19c052009-10-20 18:19:55 -0700364
Jason Sams0f505e52009-10-13 17:18:35 -0700365 if (!g_DrawLastFrame) {
366 // If we stopped rendering we cannot use DT.
367 // assume 30fps in this case.
368 g_DT = 0.033f;
369 }
Jason Samsb52dfa02009-10-14 20:16:14 -0700370 // physics may break if DT is large.
Jason Sams14f67ed2010-05-11 14:02:43 -0700371 g_DT = min(g_DT, 0.2f);
Jason Sams0f505e52009-10-13 17:18:35 -0700372
Jason Sams14f67ed2010-05-11 14:02:43 -0700373 if (g_Zoom != gZoomTarget) {
Jason Sams6471c8b2010-01-20 14:15:22 -0800374 float dz = g_DT * 1.7f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700375 if (gZoomTarget < 0.5f) {
Jason Sams6471c8b2010-01-20 14:15:22 -0800376 dz = -dz;
Jason Sams0f505e52009-10-13 17:18:35 -0700377 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700378 if (fabs(g_Zoom - gZoomTarget) < fabs(dz)) {
379 g_Zoom = gZoomTarget;
Jason Sams0f505e52009-10-13 17:18:35 -0700380 } else {
381 g_Zoom += dz;
382 }
383 updateReadback();
384 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700385 g_Animation = pow(1.f - g_Zoom, 3.f);
Jason Sams0f505e52009-10-13 17:18:35 -0700386
Jason Sams14f67ed2010-05-11 14:02:43 -0700387 //debugPf(100, g_Zoom);
Jason Sams0f505e52009-10-13 17:18:35 -0700388 // Set clear value to dim the background based on the zoom position.
Jason Samsad1bdf02010-05-14 17:54:50 -0700389 if ((g_Zoom < 0.001f) && (gZoomTarget < 0.001f)) {
Jason Sams0f505e52009-10-13 17:18:35 -0700390 pfClearColor(0.0f, 0.0f, 0.0f, 0.0f);
391 // When we're zoomed out and not tracking motion events, reset the pos to 0.
392 if (!g_LastTouchDown) {
393 g_PosPage = 0;
394 }
395 return lastFrame(0);
Jason Sams0f505e52009-10-13 17:18:35 -0700396 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700397 //debugPf(101, g_Zoom);
Jason Sams0f505e52009-10-13 17:18:35 -0700398 pfClearColor(0.0f, 0.0f, 0.0f, g_Zoom);
399 }
400
401 // icons & labels
Jason Samscc903492010-03-12 12:46:04 -0800402 if (getWidth() > getHeight()) {
Jason Samsad1bdf02010-05-14 17:54:50 -0700403 g_Cols = COLUMNS_PER_PAGE_LANDSCAPE;
404 g_Rows = ROWS_PER_PAGE_LANDSCAPE;
Joe Onorato20e7a562010-03-18 17:12:52 -0700405 } else {
Jason Samsad1bdf02010-05-14 17:54:50 -0700406 g_Cols = COLUMNS_PER_PAGE_PORTRAIT;
407 g_Rows = ROWS_PER_PAGE_PORTRAIT;
Jason Samscc903492010-03-12 12:46:04 -0800408 }
Jason Samsad1bdf02010-05-14 17:54:50 -0700409
Jason Sams14f67ed2010-05-11 14:02:43 -0700410 g_PosMax = ((gIconCount + (g_Cols-1)) / g_Cols) - g_Rows;
Jason Sams0f505e52009-10-13 17:18:35 -0700411 if (g_PosMax < 0) g_PosMax = 0;
412
Jason Samscc903492010-03-12 12:46:04 -0800413 updatePos();
Jason Sams0f505e52009-10-13 17:18:35 -0700414 updateReadback();
415
416 //debugF(" draw g_PosPage", g_PosPage);
417
418 // Draw the icons ========================================
Jason Sams6471c8b2010-01-20 14:15:22 -0800419 drawFrontGrid(g_PosPage, g_Animation);
Jason Samsc8514792009-10-29 14:27:29 -0700420
Jason Sams14f67ed2010-05-11 14:02:43 -0700421 bindProgramFragment(gPFTexNearest);
Jason Samsb52dfa02009-10-14 20:16:14 -0700422 draw_home_button();
Jason Sams14f67ed2010-05-11 14:02:43 -0700423 return lastFrame((g_PosVelocity != 0) || frac(g_PosPage) || g_Zoom != gZoomTarget || (g_MoveToTime != 0));
Jason Sams0f505e52009-10-13 17:18:35 -0700424}
425
Jason Sams14f67ed2010-05-11 14:02:43 -0700426