blob: 0e278d9e13de4ff777f83c76b23b4eadbf4ba513 [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"
6//#pragma stateVertex(PV)
7//#pragma stateFragment(PFTexNearest)
8//#pragma stateStore(PSIcons)
Jason Sams0f505e52009-10-13 17:18:35 -07009
10#define PI 3.14159f
11
Jason Sams14f67ed2010-05-11 14:02:43 -070012static int g_SpecialHWWar;
13
14
15// Constants from Java
16int COLUMNS_PER_PAGE_PORTRAIT;
17int ROWS_PER_PAGE_PORTRAIT;
18int COLUMNS_PER_PAGE_LANDSCAPE;
19int ROWS_PER_PAGE_LANDSCAPE;
20
21float gNewPositionX;
22int gNewTouchDown;
23float gFlingVelocity;
24int gIconCount;
25int gSelectedIconIndex;
26rs_allocation gSelectedIconTexture;
27float gZoomTarget;
28rs_allocation gHomeButton;
29float gTargetPos;
30
31rs_program_fragment gPFTexNearest;
32rs_program_fragment gPFTexMip;
33rs_program_fragment gPFTexMipAlpha;
34rs_program_vertex gPVCurve;
35rs_program_store gPS;
36rs_mesh gSMCell;
37
38rs_allocation *gIconIDs;
39rs_allocation *gLabelIDs;
40
41typedef struct VpConsts_s {
42 float4 Position;
43 float4 ScaleOffset;
44 float2 BendPos;
45 float2 ImgSize;
46} VpConsts_t;
47VpConsts_t *vpConstants;
48
49
50#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)
51#pragma rs export_func(resetHWWar, move, moveTo, setZoom, fling)
52
53
54void debugAll()
55{
56 debugPi(1000, COLUMNS_PER_PAGE_PORTRAIT);
57 debugPi(1001, ROWS_PER_PAGE_PORTRAIT);
58 debugPi(1002, COLUMNS_PER_PAGE_LANDSCAPE);
59 debugPi(1003, ROWS_PER_PAGE_LANDSCAPE);
60
61 debugPf(1018, gNewPositionX);
62 debugPi(1019, gNewTouchDown);
63 debugPf(1020, gFlingVelocity);
64 debugPi(1021, gIconCount);
65 debugPi(1022, gSelectedIconIndex);
66 debugPi(1023, gSelectedIconTexture);
67 debugPf(1024, gZoomTarget);
68 debugPi(1025, gHomeButton);
69 debugPf(1026, gTargetPos);
70
71 debugPi(1027, gPFTexNearest);
72 debugPi(1028, gPFTexMip);
73 debugPi(1029, gPFTexMipAlpha);
74 debugPi(1030, gPVCurve);
75 debugPi(1031, gSMCell);
76
77 debugP(1032, gIconIDs);
78 debugP(1033, gLabelIDs);
79 debugP(1034, vpConstants);
80}
81
Jason Sams0f505e52009-10-13 17:18:35 -070082
83// Attraction to center values from page edge to page center.
Jason Sams14f67ed2010-05-11 14:02:43 -070084static float g_AttractionTable[9];
85static float g_FrictionTable[9];
86static float g_PhysicsTableSize;
Jason Sams0f505e52009-10-13 17:18:35 -070087
Jason Sams14f67ed2010-05-11 14:02:43 -070088static float g_PosPage;
89static float g_PosVelocity;
90static float g_LastPositionX;
91static int g_LastTouchDown;
92static float g_DT;
93static int g_LastTime;
94static int g_PosMax;
95static float g_Zoom;
96static float g_Animation;
97static float g_OldPosPage;
98static float g_OldPosVelocity;
99static float g_OldZoom;
100static float g_MoveToTotalTime;
101static float g_MoveToTime;
102static float g_MoveToOldPos;
Jason Samsc1c521e2009-10-19 14:45:45 -0700103
Jason Sams14f67ed2010-05-11 14:02:43 -0700104static int g_Cols;
105static int g_Rows;
Jason Sams0f505e52009-10-13 17:18:35 -0700106
107// Drawing constants, should be parameters ======
108#define VIEW_ANGLE 1.28700222f
109
Jason Sams14f67ed2010-05-11 14:02:43 -0700110static int g_DrawLastFrame;
111static int lastFrame(int draw) {
112 //debugPi(99, 13);
Jason Sams0f505e52009-10-13 17:18:35 -0700113 // We draw one extra frame to work around the last frame post bug.
114 // We also need to track if we drew the last frame to deal with large DT
115 // in the physics.
116 int ret = g_DrawLastFrame | draw;
117 g_DrawLastFrame = draw;
118 return ret; // should return draw instead.
119}
120
Jason Sams14f67ed2010-05-11 14:02:43 -0700121static void updateReadback() {
122 //debugPi(99, 12);
123 //if ((g_OldPosPage != g_PosPage) ||
124 //(g_OldPosVelocity != g_PosVelocity) ||
125 //(g_OldZoom != g_Zoom)) {
Jason Sams0f505e52009-10-13 17:18:35 -0700126
Jason Sams14f67ed2010-05-11 14:02:43 -0700127 //debugPf(40, g_PosPage);
128 //debugPf(41, g_PosVelocity);
129 //debugPf(42, g_Zoom);
Jason Sams0f505e52009-10-13 17:18:35 -0700130 g_OldPosPage = g_PosPage;
131 g_OldPosVelocity = g_PosVelocity;
132 g_OldZoom = g_Zoom;
133
134 int i[3];
135 i[0] = g_PosPage * (1 << 16);
136 i[1] = g_PosVelocity * (1 << 16);
137 i[2] = g_OldZoom * (1 << 16);
138 sendToClient(&i[0], 1, 12, 1);
Jason Sams14f67ed2010-05-11 14:02:43 -0700139 //}
Jason Sams0f505e52009-10-13 17:18:35 -0700140}
141
Jason Sams14f67ed2010-05-11 14:02:43 -0700142static void setColor(float r, float g, float b, float a) {
143 //debugPi(99, 11);
Jason Sams41b61c82009-10-15 15:40:54 -0700144 if (g_SpecialHWWar) {
145 color(0, 0, 0, 0.001f);
146 } else {
147 color(r, g, b, a);
148 }
149}
Jason Sams0f505e52009-10-13 17:18:35 -0700150
151void init() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700152 //debugPi(99, 10);
Jason Sams2e19c052009-10-20 18:19:55 -0700153 g_AttractionTable[0] = 20.0f;
154 g_AttractionTable[1] = 20.0f;
Jason Samsc8514792009-10-29 14:27:29 -0700155 g_AttractionTable[2] = 20.0f;
Jason Sams2e19c052009-10-20 18:19:55 -0700156 g_AttractionTable[3] = 10.0f;
157 g_AttractionTable[4] = -10.0f;
Jason Samsc8514792009-10-29 14:27:29 -0700158 g_AttractionTable[5] = -20.0f;
159 g_AttractionTable[6] = -20.0f;
Jason Sams2e19c052009-10-20 18:19:55 -0700160 g_AttractionTable[7] = -20.0f;
161 g_AttractionTable[8] = -20.0f; // dup 7 to avoid a clamp later
162 g_FrictionTable[0] = 10.0f;
163 g_FrictionTable[1] = 10.0f;
164 g_FrictionTable[2] = 11.0f;
165 g_FrictionTable[3] = 15.0f;
166 g_FrictionTable[4] = 15.0f;
167 g_FrictionTable[5] = 11.0f;
168 g_FrictionTable[6] = 10.0f;
169 g_FrictionTable[7] = 10.0f;
170 g_FrictionTable[8] = 10.0f; // dup 7 to avoid a clamp later
Jason Sams0f505e52009-10-13 17:18:35 -0700171 g_PhysicsTableSize = 7;
172
173 g_PosVelocity = 0;
174 g_PosPage = 0;
175 g_LastTouchDown = 0;
176 g_LastPositionX = 0;
177 g_Zoom = 0;
Jason Sams2a131552010-02-26 13:50:31 -0800178 g_Animation = 1.f;
Jason Sams41b61c82009-10-15 15:40:54 -0700179 g_SpecialHWWar = 1;
Jason Samsc1c521e2009-10-19 14:45:45 -0700180 g_MoveToTime = 0;
181 g_MoveToOldPos = 0;
Mike Cleron7d5d7462009-10-20 14:06:00 -0700182 g_MoveToTotalTime = 0.2f; // Duration of scrolling 1 line
Jason Sams41b61c82009-10-15 15:40:54 -0700183}
184
185void resetHWWar() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700186 //debugPi(99, 9);
Jason Sams41b61c82009-10-15 15:40:54 -0700187 g_SpecialHWWar = 1;
Jason Sams0f505e52009-10-13 17:18:35 -0700188}
189
190void move() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700191 //debugPi(99, 8);
Jason Sams0f505e52009-10-13 17:18:35 -0700192 if (g_LastTouchDown) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700193 float dx = -(gNewPositionX - g_LastPositionX);
Jason Sams0f505e52009-10-13 17:18:35 -0700194 g_PosVelocity = 0;
Jason Sams6ec11bc2010-01-19 17:56:52 -0800195 g_PosPage += dx * 5.2f;
Jason Sams0f505e52009-10-13 17:18:35 -0700196
Jason Samsc8514792009-10-29 14:27:29 -0700197 float pmin = -0.49f;
198 float pmax = g_PosMax + 0.49f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700199 g_PosPage = clamp(g_PosPage, pmin, pmax);
Jason Sams0f505e52009-10-13 17:18:35 -0700200 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700201 g_LastTouchDown = gNewTouchDown;
202 g_LastPositionX = gNewPositionX;
Jason Samsc1c521e2009-10-19 14:45:45 -0700203 g_MoveToTime = 0;
Jason Sams0f505e52009-10-13 17:18:35 -0700204 //debugF("Move P", g_PosPage);
205}
206
Jason Samsc1c521e2009-10-19 14:45:45 -0700207void moveTo() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700208 //debugPi(99, 7);
Jason Samsc1c521e2009-10-19 14:45:45 -0700209 g_MoveToTime = g_MoveToTotalTime;
210 g_PosVelocity = 0;
211 g_MoveToOldPos = g_PosPage;
Jason Sams2e19c052009-10-20 18:19:55 -0700212
Mike Cleron7d5d7462009-10-20 14:06:00 -0700213 // debugF("======= moveTo", state->targetPos);
Jason Samsc1c521e2009-10-19 14:45:45 -0700214}
215
Joe Onorato3a8820b2009-11-10 15:06:42 -0800216void setZoom() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700217 //debugPi(99, 6);
218 g_Zoom = gZoomTarget;
Joe Onorato3a8820b2009-11-10 15:06:42 -0800219 g_DrawLastFrame = 1;
220 updateReadback();
221}
222
Jason Sams0f505e52009-10-13 17:18:35 -0700223void fling() {
Jason Sams14f67ed2010-05-11 14:02:43 -0700224 //debugPi(99, 5);
Jason Sams0f505e52009-10-13 17:18:35 -0700225 g_LastTouchDown = 0;
Jason Sams14f67ed2010-05-11 14:02:43 -0700226 g_PosVelocity = -gFlingVelocity * 4;
227 float av = fabs(g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700228 float minVel = 3.5f;
229
Jason Sams14f67ed2010-05-11 14:02:43 -0700230 minVel *= 1.f - (fabs(frac(g_PosPage + 0.5f) - 0.5f) * 0.45f);
Jason Sams0f505e52009-10-13 17:18:35 -0700231
232 if (av < minVel && av > 0.2f) {
233 if (g_PosVelocity > 0) {
234 g_PosVelocity = minVel;
235 } else {
236 g_PosVelocity = -minVel;
237 }
238 }
239
240 if (g_PosPage <= 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700241 g_PosVelocity = max(0.f, g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700242 }
243 if (g_PosPage > g_PosMax) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700244 g_PosVelocity = min(0.f, g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700245 }
246}
247
Jason Sams14f67ed2010-05-11 14:02:43 -0700248// Interpolates values in the range 0..1 to a curve that eases in
249// and out.
250static float getInterpolation(float input) {
251 //debugPi(99, 4);
252 return (cos((input + 1) * PI) * 0.5f) + 0.5f;
Jason Sams0f505e52009-10-13 17:18:35 -0700253}
254
Mike Cleron7d5d7462009-10-20 14:06:00 -0700255
Jason Sams14f67ed2010-05-11 14:02:43 -0700256static void updatePos() {
257 //debugPi(99, 3);
Jason Sams0f505e52009-10-13 17:18:35 -0700258 if (g_LastTouchDown) {
259 return;
260 }
261
Jason Sams14f67ed2010-05-11 14:02:43 -0700262 float tablePosNorm = frac(g_PosPage + 0.5f);
Jason Sams0f505e52009-10-13 17:18:35 -0700263 float tablePosF = tablePosNorm * g_PhysicsTableSize;
264 int tablePosI = tablePosF;
265 float tablePosFrac = tablePosF - tablePosI;
Jason Sams14f67ed2010-05-11 14:02:43 -0700266 float accel = mix(g_AttractionTable[tablePosI],
Jason Sams0f505e52009-10-13 17:18:35 -0700267 g_AttractionTable[tablePosI + 1],
268 tablePosFrac) * g_DT;
Jason Sams14f67ed2010-05-11 14:02:43 -0700269 float friction = mix(g_FrictionTable[tablePosI],
Jason Sams2e19c052009-10-20 18:19:55 -0700270 g_FrictionTable[tablePosI + 1],
271 tablePosFrac) * g_DT;
Jason Sams0f505e52009-10-13 17:18:35 -0700272
Jason Samsc1c521e2009-10-19 14:45:45 -0700273 if (g_MoveToTime) {
Jason Samsc8514792009-10-29 14:27:29 -0700274 // New position is old posiition + (total distance) * (interpolated time)
Jason Sams14f67ed2010-05-11 14:02:43 -0700275 g_PosPage = g_MoveToOldPos + (gTargetPos - g_MoveToOldPos) * getInterpolation((g_MoveToTotalTime - g_MoveToTime) / g_MoveToTotalTime);
Jason Samsc1c521e2009-10-19 14:45:45 -0700276 g_MoveToTime -= g_DT;
277 if (g_MoveToTime <= 0) {
278 g_MoveToTime = 0;
Jason Sams14f67ed2010-05-11 14:02:43 -0700279 g_PosPage = gTargetPos;
Jason Samsc1c521e2009-10-19 14:45:45 -0700280 }
281 return;
282 }
283
Jason Sams0f505e52009-10-13 17:18:35 -0700284 // If our velocity is low OR acceleration is opposing it, apply it.
Jason Sams14f67ed2010-05-11 14:02:43 -0700285 if (fabs(g_PosVelocity) < 4.0f || (g_PosVelocity * accel) < 0) {
Jason Sams0f505e52009-10-13 17:18:35 -0700286 g_PosVelocity += accel;
287 }
Jason Samsc8514792009-10-29 14:27:29 -0700288 //debugF("g_PosPage", g_PosPage);
289 //debugF(" g_PosVelocity", g_PosVelocity);
290 //debugF(" friction", friction);
291 //debugF(" accel", accel);
Jason Sams0f505e52009-10-13 17:18:35 -0700292
Jason Samsc8514792009-10-29 14:27:29 -0700293 // Normal physics
294 if (g_PosVelocity > 0) {
295 g_PosVelocity -= friction;
Jason Sams14f67ed2010-05-11 14:02:43 -0700296 g_PosVelocity = max(g_PosVelocity, 0.f);
Jason Samsc8514792009-10-29 14:27:29 -0700297 } else {
298 g_PosVelocity += friction;
Jason Sams14f67ed2010-05-11 14:02:43 -0700299 g_PosVelocity = min(g_PosVelocity, 0.f);
Jason Samsc8514792009-10-29 14:27:29 -0700300 }
301
Jason Sams14f67ed2010-05-11 14:02:43 -0700302 if ((friction > fabs(g_PosVelocity)) && (friction > fabs(accel))) {
Jason Sams0f505e52009-10-13 17:18:35 -0700303 // Special get back to center and overcome friction physics.
304 float t = tablePosNorm - 0.5f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700305 if (fabs(t) < (friction * g_DT)) {
Jason Sams0f505e52009-10-13 17:18:35 -0700306 // really close, just snap
Jason Sams14f67ed2010-05-11 14:02:43 -0700307 g_PosPage = round(g_PosPage);
Jason Sams0f505e52009-10-13 17:18:35 -0700308 g_PosVelocity = 0;
309 } else {
310 if (t > 0) {
311 g_PosVelocity = -friction;
312 } else {
313 g_PosVelocity = friction;
314 }
315 }
Jason Sams0f505e52009-10-13 17:18:35 -0700316 }
Jason Sams0f505e52009-10-13 17:18:35 -0700317
318 // Check for out of boundry conditions.
319 if (g_PosPage < 0 && g_PosVelocity < 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700320 float damp = 1.0f + (g_PosPage * 4);
321 damp = clamp(damp, 0.f, 0.9f);
Jason Sams0f505e52009-10-13 17:18:35 -0700322 g_PosVelocity *= damp;
323 }
324 if (g_PosPage > g_PosMax && g_PosVelocity > 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700325 float damp = 1.0f - ((g_PosPage - g_PosMax) * 4);
326 damp = clamp(damp, 0.f, 0.9f);
Jason Sams0f505e52009-10-13 17:18:35 -0700327 g_PosVelocity *= damp;
328 }
Jason Samsc8514792009-10-29 14:27:29 -0700329
330 g_PosPage += g_PosVelocity * g_DT;
Jason Sams14f67ed2010-05-11 14:02:43 -0700331 g_PosPage = clamp(g_PosPage, -0.49f, g_PosMax + 0.49f);
332
333 //debugPf(300, g_PosPage);
Jason Sams0f505e52009-10-13 17:18:35 -0700334}
335
Jason Sams14f67ed2010-05-11 14:02:43 -0700336static void
Jason Sams0f505e52009-10-13 17:18:35 -0700337draw_home_button()
338{
Jason Sams14f67ed2010-05-11 14:02:43 -0700339 //debugPi(99, 2);
Jason Sams41b61c82009-10-15 15:40:54 -0700340 setColor(1.0f, 1.0f, 1.0f, 1.0f);
Jason Sams14f67ed2010-05-11 14:02:43 -0700341 bindTexture(gPFTexNearest, 0, gHomeButton);
Jason Sams0f505e52009-10-13 17:18:35 -0700342
Jason Sams76512482010-02-04 16:31:35 -0800343 float w = getWidth();
344 float h = getHeight();
Jason Sams14f67ed2010-05-11 14:02:43 -0700345 float tw = allocGetDimX(gHomeButton);
346 float th = allocGetDimY(gHomeButton);
Jason Sams76512482010-02-04 16:31:35 -0800347
348 float x;
349 float y;
350 if (getWidth() > getHeight()) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700351 x = w - (tw * (1 - g_Animation)) + 20;
352 y = (h - th) * 0.5f;
Jason Sams76512482010-02-04 16:31:35 -0800353 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700354 x = (w - tw) / 2;
355 y = -g_Animation * th;
Jason Sams76512482010-02-04 16:31:35 -0800356 y -= 30; // move the house to the edge of the screen as it doesn't fill the texture.
357 }
358
Jason Sams14f67ed2010-05-11 14:02:43 -0700359 drawSpriteScreenspace(x, y, 0, tw, th);
Jason Sams0f505e52009-10-13 17:18:35 -0700360}
361
Jason Sams14f67ed2010-05-11 14:02:43 -0700362static void drawFrontGrid(float rowOffset, float p)
Jason Sams0f505e52009-10-13 17:18:35 -0700363{
Jason Sams14f67ed2010-05-11 14:02:43 -0700364 //debugPi(99, 1);
Jason Sams0f505e52009-10-13 17:18:35 -0700365 float h = getHeight();
366 float w = getWidth();
367
368 int intRowOffset = rowOffset;
369 float rowFrac = rowOffset - intRowOffset;
Jason Sams76512482010-02-04 16:31:35 -0800370 float colWidth = 120.f;//getWidth() / 4;
Jason Sams0f505e52009-10-13 17:18:35 -0700371 float rowHeight = colWidth + 25.f;
Jason Samsb4ecab22010-01-19 16:43:26 -0800372 float yoff = 0.5f * h + 1.5f * rowHeight;
Jason Sams0f505e52009-10-13 17:18:35 -0700373
Jason Sams14f67ed2010-05-11 14:02:43 -0700374 //debugPi(199, 1);
375
Jason Sams0f505e52009-10-13 17:18:35 -0700376 int row, col;
Jason Sams76512482010-02-04 16:31:35 -0800377 int colCount = 4;
378 if (w > h) {
379 colCount = 6;
380 rowHeight -= 12.f;
381 yoff = 0.47f * h + 1.0f * rowHeight;
382 }
383
384 int iconNum = (intRowOffset - 5) * colCount;
385
Jason Sams14f67ed2010-05-11 14:02:43 -0700386 bindProgramVertex(gPVCurve);
Jason Samsb4ecab22010-01-19 16:43:26 -0800387
Jason Sams76512482010-02-04 16:31:35 -0800388 vpConstants->Position.z = p;
Jason Samsb4ecab22010-01-19 16:43:26 -0800389
Jason Samse78ace92010-02-02 17:37:44 -0800390 setColor(1.0f, 1.0f, 1.0f, 1.0f);
Jason Samsb4ecab22010-01-19 16:43:26 -0800391 for (row = -5; row < 15; row++) {
Jason Sams0f505e52009-10-13 17:18:35 -0700392 float y = yoff - ((-rowFrac + row) * rowHeight);
393
Jason Sams76512482010-02-04 16:31:35 -0800394 for (col=0; col < colCount; col++) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700395 if (iconNum >= gIconCount) {
Jason Sams0f505e52009-10-13 17:18:35 -0700396 return;
397 }
398
399 if (iconNum >= 0) {
Jason Samsb4ecab22010-01-19 16:43:26 -0800400 float x = colWidth * col + (colWidth / 2);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800401 vpConstants->Position.x = x + 0.2f;
Jason Sams1a94ee32010-01-20 13:34:30 -0800402
Jason Sams14f67ed2010-05-11 14:02:43 -0700403 if (gSelectedIconIndex == iconNum && !p && gSelectedIconTexture) {
404 bindProgramFragment(gPFTexNearest);
405 bindTexture(gPFTexNearest, 0, gSelectedIconTexture);
406 vpConstants->ImgSize.x = allocGetDimX(gSelectedIconTexture);
407 vpConstants->ImgSize.y = allocGetDimY(gSelectedIconTexture);
408 vpConstants->Position.y = y - (allocGetDimY(gSelectedIconTexture) - allocGetDimY(gIconIDs[iconNum])) * 0.5f;
409 drawSimpleMesh(gSMCell);
Jason Sams37f262d2010-01-20 11:19:51 -0800410 }
411
Jason Sams14f67ed2010-05-11 14:02:43 -0700412 bindProgramFragment(gPFTexMip);
413 vpConstants->ImgSize.x = allocGetDimX(gIconIDs[iconNum]);
414 vpConstants->ImgSize.y = allocGetDimY(gIconIDs[iconNum]);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800415 vpConstants->Position.y = y - 0.2f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700416 bindTexture(gPFTexMip, 0, gIconIDs[iconNum]);
417 drawSimpleMesh(gSMCell);
Joe Onorato742d7fc2009-10-15 19:48:16 -0700418
Jason Sams14f67ed2010-05-11 14:02:43 -0700419 //debugPf(202, vpConstants->ImgSize.x);
420 //debugPf(203, vpConstants->ImgSize.y);
421 //debugPf(204, vpConstants->Position.y);
422 //debugPi(205, gIconIDs[iconNum]);
423 //debugPi(206, gLabelIDs[iconNum]);
424
425
426 bindProgramFragment(gPFTexMipAlpha);
427 vpConstants->ImgSize.x = allocGetDimX(gLabelIDs[iconNum]);
428 vpConstants->ImgSize.y = allocGetDimY(gLabelIDs[iconNum]);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800429 vpConstants->Position.y = y - 64.f - 0.2f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700430 bindTexture(gPFTexMipAlpha, 0, gLabelIDs[iconNum]);
431 drawSimpleMesh(gSMCell);
Jason Sams0f505e52009-10-13 17:18:35 -0700432 }
433 iconNum++;
434 }
435 }
436}
437
Jason Sams0f505e52009-10-13 17:18:35 -0700438
Jason Sams14f67ed2010-05-11 14:02:43 -0700439int root()
Jason Sams0f505e52009-10-13 17:18:35 -0700440{
Jason Sams14f67ed2010-05-11 14:02:43 -0700441 //debugAll();
442 bindProgramStore(gPS);
443
Jason Sams0f505e52009-10-13 17:18:35 -0700444 // Compute dt in seconds.
445 int newTime = uptimeMillis();
Jason Sams14f67ed2010-05-11 14:02:43 -0700446 g_DT = (newTime - g_LastTime) * 0.001f;
Jason Sams0f505e52009-10-13 17:18:35 -0700447 g_LastTime = newTime;
Jason Sams2e19c052009-10-20 18:19:55 -0700448
Jason Sams0f505e52009-10-13 17:18:35 -0700449 if (!g_DrawLastFrame) {
450 // If we stopped rendering we cannot use DT.
451 // assume 30fps in this case.
452 g_DT = 0.033f;
453 }
Jason Samsb52dfa02009-10-14 20:16:14 -0700454 // physics may break if DT is large.
Jason Sams14f67ed2010-05-11 14:02:43 -0700455 g_DT = min(g_DT, 0.2f);
Jason Sams0f505e52009-10-13 17:18:35 -0700456
Jason Sams14f67ed2010-05-11 14:02:43 -0700457 if (g_Zoom != gZoomTarget) {
Jason Sams6471c8b2010-01-20 14:15:22 -0800458 float dz = g_DT * 1.7f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700459 if (gZoomTarget < 0.5f) {
Jason Sams6471c8b2010-01-20 14:15:22 -0800460 dz = -dz;
Jason Sams0f505e52009-10-13 17:18:35 -0700461 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700462 if (fabs(g_Zoom - gZoomTarget) < fabs(dz)) {
463 g_Zoom = gZoomTarget;
Jason Sams0f505e52009-10-13 17:18:35 -0700464 } else {
465 g_Zoom += dz;
466 }
467 updateReadback();
468 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700469 g_Animation = pow(1.f - g_Zoom, 3.f);
Jason Sams0f505e52009-10-13 17:18:35 -0700470
Jason Sams14f67ed2010-05-11 14:02:43 -0700471 //debugPf(100, g_Zoom);
Jason Sams0f505e52009-10-13 17:18:35 -0700472 // Set clear value to dim the background based on the zoom position.
Jason Sams14f67ed2010-05-11 14:02:43 -0700473 if ((g_Zoom < 0.001f) && (gZoomTarget < 0.001f) && !g_SpecialHWWar) {
Jason Sams0f505e52009-10-13 17:18:35 -0700474 pfClearColor(0.0f, 0.0f, 0.0f, 0.0f);
475 // When we're zoomed out and not tracking motion events, reset the pos to 0.
476 if (!g_LastTouchDown) {
477 g_PosPage = 0;
478 }
479 return lastFrame(0);
Jason Sams0f505e52009-10-13 17:18:35 -0700480 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700481 //debugPf(101, g_Zoom);
Jason Sams0f505e52009-10-13 17:18:35 -0700482 pfClearColor(0.0f, 0.0f, 0.0f, g_Zoom);
483 }
484
485 // icons & labels
Jason Samscc903492010-03-12 12:46:04 -0800486 if (getWidth() > getHeight()) {
Joe Onorato20e7a562010-03-18 17:12:52 -0700487 g_Cols = 6;
488 g_Rows = 3;
489 } else {
490 g_Cols = 4;
491 g_Rows = 4;
Jason Samscc903492010-03-12 12:46:04 -0800492 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700493 g_PosMax = ((gIconCount + (g_Cols-1)) / g_Cols) - g_Rows;
Jason Sams0f505e52009-10-13 17:18:35 -0700494 if (g_PosMax < 0) g_PosMax = 0;
495
Jason Samscc903492010-03-12 12:46:04 -0800496 updatePos();
Jason Sams0f505e52009-10-13 17:18:35 -0700497 updateReadback();
498
499 //debugF(" draw g_PosPage", g_PosPage);
500
501 // Draw the icons ========================================
Jason Sams6471c8b2010-01-20 14:15:22 -0800502 drawFrontGrid(g_PosPage, g_Animation);
Jason Samsc8514792009-10-29 14:27:29 -0700503
Jason Sams14f67ed2010-05-11 14:02:43 -0700504 bindProgramFragment(gPFTexNearest);
Jason Samsb52dfa02009-10-14 20:16:14 -0700505 draw_home_button();
Jason Sams0f505e52009-10-13 17:18:35 -0700506
Jason Sams41b61c82009-10-15 15:40:54 -0700507 // This is a WAR to do a rendering pass without drawing during init to
508 // force the driver to preload and compile its shaders.
509 // Without this the first animation does not appear due to the time it
510 // takes to init the driver state.
511 if (g_SpecialHWWar) {
512 g_SpecialHWWar = 0;
513 return 1;
514 }
515
Jason Sams0f505e52009-10-13 17:18:35 -0700516 // Bug workaround where the last frame is not always displayed
517 // So we keep rendering until the bug is fixed.
Jason Sams14f67ed2010-05-11 14:02:43 -0700518 return lastFrame((g_PosVelocity != 0) || frac(g_PosPage) || g_Zoom != gZoomTarget || (g_MoveToTime != 0));
Jason Sams0f505e52009-10-13 17:18:35 -0700519}
520
Jason Sams14f67ed2010-05-11 14:02:43 -0700521