blob: 9342943e43b35e0e34e13599f65723735d455223 [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 Sams0f505e52009-10-13 17:18:35 -070082 g_DrawLastFrame = draw;
Jason Samsad1bdf02010-05-14 17:54:50 -070083 return draw;
Jason Sams0f505e52009-10-13 17:18:35 -070084}
85
Jason Sams14f67ed2010-05-11 14:02:43 -070086static void updateReadback() {
Jason Samsad1bdf02010-05-14 17:54:50 -070087 if ((g_OldPosPage != g_PosPage) ||
88 (g_OldPosVelocity != g_PosVelocity) ||
89 (g_OldZoom != g_Zoom)) {
Jason Sams0f505e52009-10-13 17:18:35 -070090
91 g_OldPosPage = g_PosPage;
92 g_OldPosVelocity = g_PosVelocity;
93 g_OldZoom = g_Zoom;
94
95 int i[3];
96 i[0] = g_PosPage * (1 << 16);
97 i[1] = g_PosVelocity * (1 << 16);
98 i[2] = g_OldZoom * (1 << 16);
99 sendToClient(&i[0], 1, 12, 1);
Jason Samsad1bdf02010-05-14 17:54:50 -0700100 }
Jason Sams0f505e52009-10-13 17:18:35 -0700101}
102
Jason Samsad1bdf02010-05-14 17:54:50 -0700103void setColor(float r, float g, float b, float a) {
Jason Sams41b61c82009-10-15 15:40:54 -0700104}
Jason Sams0f505e52009-10-13 17:18:35 -0700105
106void init() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700107 //debugPi(99, 10);
Jason Sams41b61c82009-10-15 15:40:54 -0700108}
109
110void resetHWWar() {
Jason Sams0f505e52009-10-13 17:18:35 -0700111}
112
113void move() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700114 //debugPi(99, 8);
Jason Sams0f505e52009-10-13 17:18:35 -0700115 if (g_LastTouchDown) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700116 float dx = -(gNewPositionX - g_LastPositionX);
Jason Sams0f505e52009-10-13 17:18:35 -0700117 g_PosVelocity = 0;
Jason Sams6ec11bc2010-01-19 17:56:52 -0800118 g_PosPage += dx * 5.2f;
Jason Sams0f505e52009-10-13 17:18:35 -0700119
Jason Samsc8514792009-10-29 14:27:29 -0700120 float pmin = -0.49f;
121 float pmax = g_PosMax + 0.49f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700122 g_PosPage = clamp(g_PosPage, pmin, pmax);
Jason Sams0f505e52009-10-13 17:18:35 -0700123 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700124 g_LastTouchDown = gNewTouchDown;
125 g_LastPositionX = gNewPositionX;
Jason Samsc1c521e2009-10-19 14:45:45 -0700126 g_MoveToTime = 0;
Jason Sams0f505e52009-10-13 17:18:35 -0700127 //debugF("Move P", g_PosPage);
128}
129
Jason Samsc1c521e2009-10-19 14:45:45 -0700130void moveTo() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700131 //debugPi(99, 7);
Jason Samsc1c521e2009-10-19 14:45:45 -0700132 g_MoveToTime = g_MoveToTotalTime;
133 g_PosVelocity = 0;
134 g_MoveToOldPos = g_PosPage;
Jason Sams2e19c052009-10-20 18:19:55 -0700135
Mike Cleron7d5d7462009-10-20 14:06:00 -0700136 // debugF("======= moveTo", state->targetPos);
Jason Samsc1c521e2009-10-19 14:45:45 -0700137}
138
Joe Onorato3a8820b2009-11-10 15:06:42 -0800139void setZoom() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700140 //debugPi(99, 6);
141 g_Zoom = gZoomTarget;
Joe Onorato3a8820b2009-11-10 15:06:42 -0800142 g_DrawLastFrame = 1;
143 updateReadback();
144}
145
Jason Sams0f505e52009-10-13 17:18:35 -0700146void fling() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700147 //debugPi(99, 5);
Jason Sams0f505e52009-10-13 17:18:35 -0700148 g_LastTouchDown = 0;
Jason Sams14f67ed2010-05-11 14:02:43 -0700149 g_PosVelocity = -gFlingVelocity * 4;
150 float av = fabs(g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700151 float minVel = 3.5f;
152
Jason Sams14f67ed2010-05-11 14:02:43 -0700153 minVel *= 1.f - (fabs(frac(g_PosPage + 0.5f) - 0.5f) * 0.45f);
Jason Sams0f505e52009-10-13 17:18:35 -0700154
155 if (av < minVel && av > 0.2f) {
156 if (g_PosVelocity > 0) {
157 g_PosVelocity = minVel;
158 } else {
159 g_PosVelocity = -minVel;
160 }
161 }
162
163 if (g_PosPage <= 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700164 g_PosVelocity = max(0.f, g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700165 }
166 if (g_PosPage > g_PosMax) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700167 g_PosVelocity = min(0.f, g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700168 }
169}
170
Jason Sams14f67ed2010-05-11 14:02:43 -0700171// Interpolates values in the range 0..1 to a curve that eases in
172// and out.
173static float getInterpolation(float input) {
174 //debugPi(99, 4);
175 return (cos((input + 1) * PI) * 0.5f) + 0.5f;
Jason Sams0f505e52009-10-13 17:18:35 -0700176}
177
Mike Cleron7d5d7462009-10-20 14:06:00 -0700178
Jason Sams14f67ed2010-05-11 14:02:43 -0700179static void updatePos() {
180 //debugPi(99, 3);
Jason Sams0f505e52009-10-13 17:18:35 -0700181 if (g_LastTouchDown) {
182 return;
183 }
184
Jason Sams14f67ed2010-05-11 14:02:43 -0700185 float tablePosNorm = frac(g_PosPage + 0.5f);
Jason Sams0f505e52009-10-13 17:18:35 -0700186 float tablePosF = tablePosNorm * g_PhysicsTableSize;
187 int tablePosI = tablePosF;
188 float tablePosFrac = tablePosF - tablePosI;
Jason Sams14f67ed2010-05-11 14:02:43 -0700189 float accel = mix(g_AttractionTable[tablePosI],
Jason Sams0f505e52009-10-13 17:18:35 -0700190 g_AttractionTable[tablePosI + 1],
191 tablePosFrac) * g_DT;
Jason Sams14f67ed2010-05-11 14:02:43 -0700192 float friction = mix(g_FrictionTable[tablePosI],
Jason Sams2e19c052009-10-20 18:19:55 -0700193 g_FrictionTable[tablePosI + 1],
194 tablePosFrac) * g_DT;
Jason Sams0f505e52009-10-13 17:18:35 -0700195
Jason Samsc1c521e2009-10-19 14:45:45 -0700196 if (g_MoveToTime) {
Jason Samsc8514792009-10-29 14:27:29 -0700197 // New position is old posiition + (total distance) * (interpolated time)
Jason Sams14f67ed2010-05-11 14:02:43 -0700198 g_PosPage = g_MoveToOldPos + (gTargetPos - g_MoveToOldPos) * getInterpolation((g_MoveToTotalTime - g_MoveToTime) / g_MoveToTotalTime);
Jason Samsc1c521e2009-10-19 14:45:45 -0700199 g_MoveToTime -= g_DT;
200 if (g_MoveToTime <= 0) {
201 g_MoveToTime = 0;
Jason Sams14f67ed2010-05-11 14:02:43 -0700202 g_PosPage = gTargetPos;
Jason Samsc1c521e2009-10-19 14:45:45 -0700203 }
204 return;
205 }
206
Jason Sams0f505e52009-10-13 17:18:35 -0700207 // If our velocity is low OR acceleration is opposing it, apply it.
Jason Sams14f67ed2010-05-11 14:02:43 -0700208 if (fabs(g_PosVelocity) < 4.0f || (g_PosVelocity * accel) < 0) {
Jason Sams0f505e52009-10-13 17:18:35 -0700209 g_PosVelocity += accel;
210 }
Jason Samsc8514792009-10-29 14:27:29 -0700211 //debugF("g_PosPage", g_PosPage);
212 //debugF(" g_PosVelocity", g_PosVelocity);
213 //debugF(" friction", friction);
214 //debugF(" accel", accel);
Jason Sams0f505e52009-10-13 17:18:35 -0700215
Jason Samsc8514792009-10-29 14:27:29 -0700216 // Normal physics
217 if (g_PosVelocity > 0) {
218 g_PosVelocity -= friction;
Jason Sams14f67ed2010-05-11 14:02:43 -0700219 g_PosVelocity = max(g_PosVelocity, 0.f);
Jason Samsc8514792009-10-29 14:27:29 -0700220 } else {
221 g_PosVelocity += friction;
Jason Sams14f67ed2010-05-11 14:02:43 -0700222 g_PosVelocity = min(g_PosVelocity, 0.f);
Jason Samsc8514792009-10-29 14:27:29 -0700223 }
224
Jason Sams14f67ed2010-05-11 14:02:43 -0700225 if ((friction > fabs(g_PosVelocity)) && (friction > fabs(accel))) {
Jason Sams0f505e52009-10-13 17:18:35 -0700226 // Special get back to center and overcome friction physics.
227 float t = tablePosNorm - 0.5f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700228 if (fabs(t) < (friction * g_DT)) {
Jason Sams0f505e52009-10-13 17:18:35 -0700229 // really close, just snap
Jason Sams14f67ed2010-05-11 14:02:43 -0700230 g_PosPage = round(g_PosPage);
Jason Sams0f505e52009-10-13 17:18:35 -0700231 g_PosVelocity = 0;
232 } else {
233 if (t > 0) {
234 g_PosVelocity = -friction;
235 } else {
236 g_PosVelocity = friction;
237 }
238 }
Jason Sams0f505e52009-10-13 17:18:35 -0700239 }
Jason Sams0f505e52009-10-13 17:18:35 -0700240
241 // Check for out of boundry conditions.
242 if (g_PosPage < 0 && g_PosVelocity < 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700243 float damp = 1.0f + (g_PosPage * 4);
244 damp = clamp(damp, 0.f, 0.9f);
Jason Sams0f505e52009-10-13 17:18:35 -0700245 g_PosVelocity *= damp;
246 }
247 if (g_PosPage > g_PosMax && g_PosVelocity > 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700248 float damp = 1.0f - ((g_PosPage - g_PosMax) * 4);
249 damp = clamp(damp, 0.f, 0.9f);
Jason Sams0f505e52009-10-13 17:18:35 -0700250 g_PosVelocity *= damp;
251 }
Jason Samsc8514792009-10-29 14:27:29 -0700252
253 g_PosPage += g_PosVelocity * g_DT;
Jason Sams14f67ed2010-05-11 14:02:43 -0700254 g_PosPage = clamp(g_PosPage, -0.49f, g_PosMax + 0.49f);
Jason Sams0f505e52009-10-13 17:18:35 -0700255}
256
Jason Sams14f67ed2010-05-11 14:02:43 -0700257static void
Jason Sams0f505e52009-10-13 17:18:35 -0700258draw_home_button()
259{
Jason Sams14f67ed2010-05-11 14:02:43 -0700260 //debugPi(99, 2);
Jason Samsad1bdf02010-05-14 17:54:50 -0700261 color(1.0f, 1.0f, 1.0f, 1.0f);
Jason Sams14f67ed2010-05-11 14:02:43 -0700262 bindTexture(gPFTexNearest, 0, gHomeButton);
Jason Sams0f505e52009-10-13 17:18:35 -0700263
Jason Sams76512482010-02-04 16:31:35 -0800264 float w = getWidth();
265 float h = getHeight();
Jason Sams14f67ed2010-05-11 14:02:43 -0700266 float tw = allocGetDimX(gHomeButton);
267 float th = allocGetDimY(gHomeButton);
Jason Sams76512482010-02-04 16:31:35 -0800268
269 float x;
270 float y;
271 if (getWidth() > getHeight()) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700272 x = w - (tw * (1 - g_Animation)) + 20;
273 y = (h - th) * 0.5f;
Jason Sams76512482010-02-04 16:31:35 -0800274 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700275 x = (w - tw) / 2;
276 y = -g_Animation * th;
Jason Sams76512482010-02-04 16:31:35 -0800277 y -= 30; // move the house to the edge of the screen as it doesn't fill the texture.
278 }
279
Jason Sams14f67ed2010-05-11 14:02:43 -0700280 drawSpriteScreenspace(x, y, 0, tw, th);
Jason Sams0f505e52009-10-13 17:18:35 -0700281}
282
Jason Sams14f67ed2010-05-11 14:02:43 -0700283static void drawFrontGrid(float rowOffset, float p)
Jason Sams0f505e52009-10-13 17:18:35 -0700284{
Jason Sams14f67ed2010-05-11 14:02:43 -0700285 //debugPi(99, 1);
Jason Sams0f505e52009-10-13 17:18:35 -0700286 float h = getHeight();
287 float w = getWidth();
288
289 int intRowOffset = rowOffset;
290 float rowFrac = rowOffset - intRowOffset;
Jason Sams76512482010-02-04 16:31:35 -0800291 float colWidth = 120.f;//getWidth() / 4;
Jason Sams0f505e52009-10-13 17:18:35 -0700292 float rowHeight = colWidth + 25.f;
Jason Samsb4ecab22010-01-19 16:43:26 -0800293 float yoff = 0.5f * h + 1.5f * rowHeight;
Jason Sams0f505e52009-10-13 17:18:35 -0700294
295 int row, col;
Jason Sams76512482010-02-04 16:31:35 -0800296 int colCount = 4;
297 if (w > h) {
298 colCount = 6;
299 rowHeight -= 12.f;
300 yoff = 0.47f * h + 1.0f * rowHeight;
301 }
302
303 int iconNum = (intRowOffset - 5) * colCount;
304
Jason Sams14f67ed2010-05-11 14:02:43 -0700305 bindProgramVertex(gPVCurve);
Jason Samsb4ecab22010-01-19 16:43:26 -0800306
Jason Sams76512482010-02-04 16:31:35 -0800307 vpConstants->Position.z = p;
Jason Samsb4ecab22010-01-19 16:43:26 -0800308
Jason Samsad1bdf02010-05-14 17:54:50 -0700309 color(1.0f, 1.0f, 1.0f, 1.0f);
Jason Samsb4ecab22010-01-19 16:43:26 -0800310 for (row = -5; row < 15; row++) {
Jason Sams0f505e52009-10-13 17:18:35 -0700311 float y = yoff - ((-rowFrac + row) * rowHeight);
312
Jason Sams76512482010-02-04 16:31:35 -0800313 for (col=0; col < colCount; col++) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700314 if (iconNum >= gIconCount) {
Jason Sams0f505e52009-10-13 17:18:35 -0700315 return;
316 }
317
318 if (iconNum >= 0) {
Jason Samsb4ecab22010-01-19 16:43:26 -0800319 float x = colWidth * col + (colWidth / 2);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800320 vpConstants->Position.x = x + 0.2f;
Jason Sams1a94ee32010-01-20 13:34:30 -0800321
Jason Sams14f67ed2010-05-11 14:02:43 -0700322 if (gSelectedIconIndex == iconNum && !p && gSelectedIconTexture) {
323 bindProgramFragment(gPFTexNearest);
324 bindTexture(gPFTexNearest, 0, gSelectedIconTexture);
325 vpConstants->ImgSize.x = allocGetDimX(gSelectedIconTexture);
326 vpConstants->ImgSize.y = allocGetDimY(gSelectedIconTexture);
327 vpConstants->Position.y = y - (allocGetDimY(gSelectedIconTexture) - allocGetDimY(gIconIDs[iconNum])) * 0.5f;
328 drawSimpleMesh(gSMCell);
Jason Sams37f262d2010-01-20 11:19:51 -0800329 }
330
Jason Sams14f67ed2010-05-11 14:02:43 -0700331 bindProgramFragment(gPFTexMip);
332 vpConstants->ImgSize.x = allocGetDimX(gIconIDs[iconNum]);
333 vpConstants->ImgSize.y = allocGetDimY(gIconIDs[iconNum]);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800334 vpConstants->Position.y = y - 0.2f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700335 bindTexture(gPFTexMip, 0, gIconIDs[iconNum]);
336 drawSimpleMesh(gSMCell);
Joe Onorato742d7fc2009-10-15 19:48:16 -0700337
Jason Sams14f67ed2010-05-11 14:02:43 -0700338 bindProgramFragment(gPFTexMipAlpha);
339 vpConstants->ImgSize.x = allocGetDimX(gLabelIDs[iconNum]);
340 vpConstants->ImgSize.y = allocGetDimY(gLabelIDs[iconNum]);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800341 vpConstants->Position.y = y - 64.f - 0.2f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700342 bindTexture(gPFTexMipAlpha, 0, gLabelIDs[iconNum]);
343 drawSimpleMesh(gSMCell);
Jason Sams0f505e52009-10-13 17:18:35 -0700344 }
345 iconNum++;
346 }
347 }
348}
349
Jason Sams0f505e52009-10-13 17:18:35 -0700350
Jason Sams14f67ed2010-05-11 14:02:43 -0700351int root()
Jason Sams0f505e52009-10-13 17:18:35 -0700352{
Jason Sams14f67ed2010-05-11 14:02:43 -0700353 //debugAll();
354 bindProgramStore(gPS);
355
Jason Sams0f505e52009-10-13 17:18:35 -0700356 // Compute dt in seconds.
357 int newTime = uptimeMillis();
Jason Sams14f67ed2010-05-11 14:02:43 -0700358 g_DT = (newTime - g_LastTime) * 0.001f;
Jason Sams0f505e52009-10-13 17:18:35 -0700359 g_LastTime = newTime;
Jason Sams2e19c052009-10-20 18:19:55 -0700360
Jason Sams0f505e52009-10-13 17:18:35 -0700361 if (!g_DrawLastFrame) {
362 // If we stopped rendering we cannot use DT.
363 // assume 30fps in this case.
364 g_DT = 0.033f;
365 }
Jason Samsb52dfa02009-10-14 20:16:14 -0700366 // physics may break if DT is large.
Jason Sams14f67ed2010-05-11 14:02:43 -0700367 g_DT = min(g_DT, 0.2f);
Jason Sams0f505e52009-10-13 17:18:35 -0700368
Jason Sams14f67ed2010-05-11 14:02:43 -0700369 if (g_Zoom != gZoomTarget) {
Jason Sams6471c8b2010-01-20 14:15:22 -0800370 float dz = g_DT * 1.7f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700371 if (gZoomTarget < 0.5f) {
Jason Sams6471c8b2010-01-20 14:15:22 -0800372 dz = -dz;
Jason Sams0f505e52009-10-13 17:18:35 -0700373 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700374 if (fabs(g_Zoom - gZoomTarget) < fabs(dz)) {
375 g_Zoom = gZoomTarget;
Jason Sams0f505e52009-10-13 17:18:35 -0700376 } else {
377 g_Zoom += dz;
378 }
379 updateReadback();
380 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700381 g_Animation = pow(1.f - g_Zoom, 3.f);
Jason Sams0f505e52009-10-13 17:18:35 -0700382
Jason Sams14f67ed2010-05-11 14:02:43 -0700383 //debugPf(100, g_Zoom);
Jason Sams0f505e52009-10-13 17:18:35 -0700384 // Set clear value to dim the background based on the zoom position.
Jason Samsad1bdf02010-05-14 17:54:50 -0700385 if ((g_Zoom < 0.001f) && (gZoomTarget < 0.001f)) {
Jason Sams0f505e52009-10-13 17:18:35 -0700386 pfClearColor(0.0f, 0.0f, 0.0f, 0.0f);
387 // When we're zoomed out and not tracking motion events, reset the pos to 0.
388 if (!g_LastTouchDown) {
389 g_PosPage = 0;
390 }
391 return lastFrame(0);
Jason Sams0f505e52009-10-13 17:18:35 -0700392 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700393 //debugPf(101, g_Zoom);
Jason Sams0f505e52009-10-13 17:18:35 -0700394 pfClearColor(0.0f, 0.0f, 0.0f, g_Zoom);
395 }
396
397 // icons & labels
Jason Samscc903492010-03-12 12:46:04 -0800398 if (getWidth() > getHeight()) {
Jason Samsad1bdf02010-05-14 17:54:50 -0700399 g_Cols = COLUMNS_PER_PAGE_LANDSCAPE;
400 g_Rows = ROWS_PER_PAGE_LANDSCAPE;
Joe Onorato20e7a562010-03-18 17:12:52 -0700401 } else {
Jason Samsad1bdf02010-05-14 17:54:50 -0700402 g_Cols = COLUMNS_PER_PAGE_PORTRAIT;
403 g_Rows = ROWS_PER_PAGE_PORTRAIT;
Jason Samscc903492010-03-12 12:46:04 -0800404 }
Jason Samsad1bdf02010-05-14 17:54:50 -0700405
Jason Sams14f67ed2010-05-11 14:02:43 -0700406 g_PosMax = ((gIconCount + (g_Cols-1)) / g_Cols) - g_Rows;
Jason Sams0f505e52009-10-13 17:18:35 -0700407 if (g_PosMax < 0) g_PosMax = 0;
408
Jason Samscc903492010-03-12 12:46:04 -0800409 updatePos();
Jason Sams0f505e52009-10-13 17:18:35 -0700410 updateReadback();
411
412 //debugF(" draw g_PosPage", g_PosPage);
413
414 // Draw the icons ========================================
Jason Sams6471c8b2010-01-20 14:15:22 -0800415 drawFrontGrid(g_PosPage, g_Animation);
Jason Samsc8514792009-10-29 14:27:29 -0700416
Jason Sams14f67ed2010-05-11 14:02:43 -0700417 bindProgramFragment(gPFTexNearest);
Jason Samsb52dfa02009-10-14 20:16:14 -0700418 draw_home_button();
Jason Sams14f67ed2010-05-11 14:02:43 -0700419 return lastFrame((g_PosVelocity != 0) || frac(g_PosPage) || g_Zoom != gZoomTarget || (g_MoveToTime != 0));
Jason Sams0f505e52009-10-13 17:18:35 -0700420}
421
Jason Sams14f67ed2010-05-11 14:02:43 -0700422