blob: aaf7c10d7d470afb879d8c257d1081a39d8fd900 [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
Jason Sams14f67ed2010-05-11 14:02:43 -070017int gIconCount;
Jason Sams1aa4ff02010-06-15 14:59:57 -070018int gSelectedIconIndex = -1;
Jason Sams14f67ed2010-05-11 14:02:43 -070019rs_allocation gSelectedIconTexture;
Jason Sams14f67ed2010-05-11 14:02:43 -070020rs_allocation gHomeButton;
Jason Sams14f67ed2010-05-11 14:02:43 -070021
22rs_program_fragment gPFTexNearest;
23rs_program_fragment gPFTexMip;
24rs_program_fragment gPFTexMipAlpha;
25rs_program_vertex gPVCurve;
26rs_program_store gPS;
27rs_mesh gSMCell;
28
29rs_allocation *gIconIDs;
30rs_allocation *gLabelIDs;
31
Jason Sams1aa4ff02010-06-15 14:59:57 -070032typedef struct VpConsts {
Jason Sams14f67ed2010-05-11 14:02:43 -070033 float4 Position;
34 float4 ScaleOffset;
35 float2 BendPos;
36 float2 ImgSize;
37} VpConsts_t;
38VpConsts_t *vpConstants;
39
40
Jason Sams60a55bb2010-06-18 15:11:19 -070041#pragma rs export_var(COLUMNS_PER_PAGE_PORTRAIT, ROWS_PER_PAGE_PORTRAIT, COLUMNS_PER_PAGE_LANDSCAPE, ROWS_PER_PAGE_LANDSCAPE, gIconCount, gSelectedIconIndex, gSelectedIconTexture, gHomeButton, gTargetPos, gPFTexNearest, gPFTexMip, gPFTexMipAlpha, gPVCurve, gPS, gSMCell, gIconIDs, gLabelIDs, vpConstants)
42#pragma rs export_func(move, moveTo, setZoom, fling)
Jason Sams14f67ed2010-05-11 14:02:43 -070043
Jason Sams0f505e52009-10-13 17:18:35 -070044
45// Attraction to center values from page edge to page center.
Jason Samsad1bdf02010-05-14 17:54:50 -070046static float g_AttractionTable[9] = {20.f, 20.f, 20.f, 10.f, -10.f, -20.f, -20.f, -20.f, -20.f};
47static float g_FrictionTable[9] = {10.f, 10.f, 11.f, 15.f, 15.f, 11.f, 10.f, 10.f, 10.f};
48static float g_PhysicsTableSize = 7;
Jason Sams0f505e52009-10-13 17:18:35 -070049
Jason Sams60a55bb2010-06-18 15:11:19 -070050static float gZoomTarget;
51static float gTargetPos;
Jason Samsad1bdf02010-05-14 17:54:50 -070052static float g_PosPage = 0.f;
53static float g_PosVelocity = 0.f;
54static float g_LastPositionX = 0.f;
Jason Sams60a55bb2010-06-18 15:11:19 -070055static bool g_LastTouchDown = false;
Jason Sams14f67ed2010-05-11 14:02:43 -070056static float g_DT;
Jason Sams13a75d52010-05-19 16:38:04 -070057static int64_t g_LastTime;
Jason Sams14f67ed2010-05-11 14:02:43 -070058static int g_PosMax;
Jason Samsad1bdf02010-05-14 17:54:50 -070059static float g_Zoom = 0.f;
60static float g_Animation = 1.f;
Jason Sams14f67ed2010-05-11 14:02:43 -070061static float g_OldPosPage;
62static float g_OldPosVelocity;
63static float g_OldZoom;
Jason Samsad1bdf02010-05-14 17:54:50 -070064static float g_MoveToTotalTime = 0.2f;
65static float g_MoveToTime = 0.f;
66static float g_MoveToOldPos = 0.f;
Jason Samsc1c521e2009-10-19 14:45:45 -070067
Jason Sams14f67ed2010-05-11 14:02:43 -070068static int g_Cols;
69static int g_Rows;
Jason Sams0f505e52009-10-13 17:18:35 -070070
71// Drawing constants, should be parameters ======
72#define VIEW_ANGLE 1.28700222f
73
Jason Sams0f505e52009-10-13 17:18:35 -070074
Jason Sams14f67ed2010-05-11 14:02:43 -070075static void updateReadback() {
Jason Samsad1bdf02010-05-14 17:54:50 -070076 if ((g_OldPosPage != g_PosPage) ||
77 (g_OldPosVelocity != g_PosVelocity) ||
78 (g_OldZoom != g_Zoom)) {
Jason Sams0f505e52009-10-13 17:18:35 -070079
80 g_OldPosPage = g_PosPage;
81 g_OldPosVelocity = g_PosVelocity;
82 g_OldZoom = g_Zoom;
83
84 int i[3];
85 i[0] = g_PosPage * (1 << 16);
86 i[1] = g_PosVelocity * (1 << 16);
87 i[2] = g_OldZoom * (1 << 16);
Jason Sams13a75d52010-05-19 16:38:04 -070088 rsSendToClient(&i[0], 1, 12, 1);
Jason Samsad1bdf02010-05-14 17:54:50 -070089 }
Jason Sams0f505e52009-10-13 17:18:35 -070090}
91
Jason Sams0f505e52009-10-13 17:18:35 -070092void init() {
Jason Sams41b61c82009-10-15 15:40:54 -070093}
Jason Sams0f505e52009-10-13 17:18:35 -070094
Jason Sams60a55bb2010-06-18 15:11:19 -070095void move(float newPos) {
Jason Sams0f505e52009-10-13 17:18:35 -070096 if (g_LastTouchDown) {
Jason Sams60a55bb2010-06-18 15:11:19 -070097 float dx = -(newPos - g_LastPositionX);
Jason Sams0f505e52009-10-13 17:18:35 -070098 g_PosVelocity = 0;
Jason Sams6ec11bc2010-01-19 17:56:52 -080099 g_PosPage += dx * 5.2f;
Jason Sams0f505e52009-10-13 17:18:35 -0700100
Jason Samsc8514792009-10-29 14:27:29 -0700101 float pmin = -0.49f;
102 float pmax = g_PosMax + 0.49f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700103 g_PosPage = clamp(g_PosPage, pmin, pmax);
Jason Sams0f505e52009-10-13 17:18:35 -0700104 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700105 g_LastTouchDown = true;
106 g_LastPositionX = newPos;
Jason Samsc1c521e2009-10-19 14:45:45 -0700107 g_MoveToTime = 0;
Jason Sams0f505e52009-10-13 17:18:35 -0700108}
109
Jason Sams60a55bb2010-06-18 15:11:19 -0700110void moveTo(float targetPos) {
111 gTargetPos = targetPos;
Jason Samsc1c521e2009-10-19 14:45:45 -0700112 g_MoveToTime = g_MoveToTotalTime;
113 g_PosVelocity = 0;
114 g_MoveToOldPos = g_PosPage;
115}
116
Jason Sams60a55bb2010-06-18 15:11:19 -0700117void setZoom(float z, /*bool*/ int animate) {
118 gZoomTarget = z;
119 if (gZoomTarget < 0.001f) {
120 gZoomTarget = 0;
121 }
122 if (!animate) {
123 g_Zoom = gZoomTarget;
124 }
Joe Onorato3a8820b2009-11-10 15:06:42 -0800125 updateReadback();
126}
127
Jason Sams60a55bb2010-06-18 15:11:19 -0700128void fling(float newPos, float vel) {
129 move(newPos);
130
131 g_LastTouchDown = false;
132 g_PosVelocity = -vel * 4;
Jason Sams14f67ed2010-05-11 14:02:43 -0700133 float av = fabs(g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700134 float minVel = 3.5f;
135
Jason Sams13a75d52010-05-19 16:38:04 -0700136 minVel *= 1.f - (fabs(rsFrac(g_PosPage + 0.5f) - 0.5f) * 0.45f);
Jason Sams0f505e52009-10-13 17:18:35 -0700137
138 if (av < minVel && av > 0.2f) {
139 if (g_PosVelocity > 0) {
140 g_PosVelocity = minVel;
141 } else {
142 g_PosVelocity = -minVel;
143 }
144 }
145
146 if (g_PosPage <= 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700147 g_PosVelocity = max(0.f, g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700148 }
149 if (g_PosPage > g_PosMax) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700150 g_PosVelocity = min(0.f, g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700151 }
152}
153
Jason Sams14f67ed2010-05-11 14:02:43 -0700154// Interpolates values in the range 0..1 to a curve that eases in
155// and out.
156static float getInterpolation(float input) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700157 return (cos((input + 1) * PI) * 0.5f) + 0.5f;
Jason Sams0f505e52009-10-13 17:18:35 -0700158}
159
Mike Cleron7d5d7462009-10-20 14:06:00 -0700160
Jason Sams14f67ed2010-05-11 14:02:43 -0700161static void updatePos() {
Jason Sams0f505e52009-10-13 17:18:35 -0700162 if (g_LastTouchDown) {
163 return;
164 }
165
Jason Sams13a75d52010-05-19 16:38:04 -0700166 float tablePosNorm = rsFrac(g_PosPage + 0.5f);
Jason Sams0f505e52009-10-13 17:18:35 -0700167 float tablePosF = tablePosNorm * g_PhysicsTableSize;
168 int tablePosI = tablePosF;
169 float tablePosFrac = tablePosF - tablePosI;
Jason Sams14f67ed2010-05-11 14:02:43 -0700170 float accel = mix(g_AttractionTable[tablePosI],
Jason Sams0f505e52009-10-13 17:18:35 -0700171 g_AttractionTable[tablePosI + 1],
172 tablePosFrac) * g_DT;
Jason Sams14f67ed2010-05-11 14:02:43 -0700173 float friction = mix(g_FrictionTable[tablePosI],
Jason Sams2e19c052009-10-20 18:19:55 -0700174 g_FrictionTable[tablePosI + 1],
175 tablePosFrac) * g_DT;
Jason Sams0f505e52009-10-13 17:18:35 -0700176
Jason Samsc1c521e2009-10-19 14:45:45 -0700177 if (g_MoveToTime) {
Jason Samsc8514792009-10-29 14:27:29 -0700178 // New position is old posiition + (total distance) * (interpolated time)
Jason Sams14f67ed2010-05-11 14:02:43 -0700179 g_PosPage = g_MoveToOldPos + (gTargetPos - g_MoveToOldPos) * getInterpolation((g_MoveToTotalTime - g_MoveToTime) / g_MoveToTotalTime);
Jason Samsc1c521e2009-10-19 14:45:45 -0700180 g_MoveToTime -= g_DT;
181 if (g_MoveToTime <= 0) {
182 g_MoveToTime = 0;
Jason Sams14f67ed2010-05-11 14:02:43 -0700183 g_PosPage = gTargetPos;
Jason Samsc1c521e2009-10-19 14:45:45 -0700184 }
185 return;
186 }
187
Jason Sams0f505e52009-10-13 17:18:35 -0700188 // If our velocity is low OR acceleration is opposing it, apply it.
Jason Sams14f67ed2010-05-11 14:02:43 -0700189 if (fabs(g_PosVelocity) < 4.0f || (g_PosVelocity * accel) < 0) {
Jason Sams0f505e52009-10-13 17:18:35 -0700190 g_PosVelocity += accel;
191 }
Jason Sams13a75d52010-05-19 16:38:04 -0700192 //RS_DEBUG(g_PosPage);
193 //RS_DEBUG(g_PosVelocity);
194 //RS_DEBUG(friction);
195 //RS_DEBUG(accel);
Jason Sams0f505e52009-10-13 17:18:35 -0700196
Jason Samsc8514792009-10-29 14:27:29 -0700197 // Normal physics
198 if (g_PosVelocity > 0) {
199 g_PosVelocity -= friction;
Jason Sams14f67ed2010-05-11 14:02:43 -0700200 g_PosVelocity = max(g_PosVelocity, 0.f);
Jason Samsc8514792009-10-29 14:27:29 -0700201 } else {
202 g_PosVelocity += friction;
Jason Sams14f67ed2010-05-11 14:02:43 -0700203 g_PosVelocity = min(g_PosVelocity, 0.f);
Jason Samsc8514792009-10-29 14:27:29 -0700204 }
205
Jason Sams14f67ed2010-05-11 14:02:43 -0700206 if ((friction > fabs(g_PosVelocity)) && (friction > fabs(accel))) {
Jason Sams0f505e52009-10-13 17:18:35 -0700207 // Special get back to center and overcome friction physics.
208 float t = tablePosNorm - 0.5f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700209 if (fabs(t) < (friction * g_DT)) {
Jason Sams0f505e52009-10-13 17:18:35 -0700210 // really close, just snap
Jason Sams14f67ed2010-05-11 14:02:43 -0700211 g_PosPage = round(g_PosPage);
Jason Sams0f505e52009-10-13 17:18:35 -0700212 g_PosVelocity = 0;
213 } else {
214 if (t > 0) {
215 g_PosVelocity = -friction;
216 } else {
217 g_PosVelocity = friction;
218 }
219 }
Jason Sams0f505e52009-10-13 17:18:35 -0700220 }
Jason Sams0f505e52009-10-13 17:18:35 -0700221
222 // Check for out of boundry conditions.
223 if (g_PosPage < 0 && g_PosVelocity < 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700224 float damp = 1.0f + (g_PosPage * 4);
225 damp = clamp(damp, 0.f, 0.9f);
Jason Sams0f505e52009-10-13 17:18:35 -0700226 g_PosVelocity *= damp;
227 }
228 if (g_PosPage > g_PosMax && g_PosVelocity > 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700229 float damp = 1.0f - ((g_PosPage - g_PosMax) * 4);
230 damp = clamp(damp, 0.f, 0.9f);
Jason Sams0f505e52009-10-13 17:18:35 -0700231 g_PosVelocity *= damp;
232 }
Jason Samsc8514792009-10-29 14:27:29 -0700233
234 g_PosPage += g_PosVelocity * g_DT;
Jason Sams14f67ed2010-05-11 14:02:43 -0700235 g_PosPage = clamp(g_PosPage, -0.49f, g_PosMax + 0.49f);
Jason Sams0f505e52009-10-13 17:18:35 -0700236}
237
Jason Sams14f67ed2010-05-11 14:02:43 -0700238static void
Jason Sams0f505e52009-10-13 17:18:35 -0700239draw_home_button()
240{
Jason Samsad1bdf02010-05-14 17:54:50 -0700241 color(1.0f, 1.0f, 1.0f, 1.0f);
Jason Sams13a75d52010-05-19 16:38:04 -0700242 rsgBindTexture(gPFTexNearest, 0, gHomeButton);
Jason Sams0f505e52009-10-13 17:18:35 -0700243
Jason Sams13a75d52010-05-19 16:38:04 -0700244 float w = rsgGetWidth();
245 float h = rsgGetHeight();
246 float tw = rsAllocationGetDimX(gHomeButton);
247 float th = rsAllocationGetDimY(gHomeButton);
Jason Sams76512482010-02-04 16:31:35 -0800248
249 float x;
250 float y;
Jason Sams13a75d52010-05-19 16:38:04 -0700251 if (w > h) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700252 x = w - (tw * (1 - g_Animation)) + 20;
253 y = (h - th) * 0.5f;
Jason Sams76512482010-02-04 16:31:35 -0800254 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700255 x = (w - tw) / 2;
256 y = -g_Animation * th;
Jason Sams76512482010-02-04 16:31:35 -0800257 y -= 30; // move the house to the edge of the screen as it doesn't fill the texture.
258 }
259
Jason Sams13a75d52010-05-19 16:38:04 -0700260 rsgDrawSpriteScreenspace(x, y, 0, tw, th);
Jason Sams0f505e52009-10-13 17:18:35 -0700261}
262
Jason Sams14f67ed2010-05-11 14:02:43 -0700263static void drawFrontGrid(float rowOffset, float p)
Jason Sams0f505e52009-10-13 17:18:35 -0700264{
Jason Sams13a75d52010-05-19 16:38:04 -0700265 float h = rsgGetHeight();
266 float w = rsgGetWidth();
Jason Sams0f505e52009-10-13 17:18:35 -0700267
268 int intRowOffset = rowOffset;
269 float rowFrac = rowOffset - intRowOffset;
Jason Sams13a75d52010-05-19 16:38:04 -0700270 float colWidth = 120.f;//w / 4;
Jason Sams0f505e52009-10-13 17:18:35 -0700271 float rowHeight = colWidth + 25.f;
Jason Samsb4ecab22010-01-19 16:43:26 -0800272 float yoff = 0.5f * h + 1.5f * rowHeight;
Jason Sams0f505e52009-10-13 17:18:35 -0700273
274 int row, col;
Jason Sams76512482010-02-04 16:31:35 -0800275 int colCount = 4;
276 if (w > h) {
277 colCount = 6;
278 rowHeight -= 12.f;
279 yoff = 0.47f * h + 1.0f * rowHeight;
280 }
281
282 int iconNum = (intRowOffset - 5) * colCount;
283
Jason Sams13a75d52010-05-19 16:38:04 -0700284 rsgBindProgramVertex(gPVCurve);
Jason Samsb4ecab22010-01-19 16:43:26 -0800285
Jason Sams76512482010-02-04 16:31:35 -0800286 vpConstants->Position.z = p;
Jason Samsb4ecab22010-01-19 16:43:26 -0800287
Jason Samsad1bdf02010-05-14 17:54:50 -0700288 color(1.0f, 1.0f, 1.0f, 1.0f);
Jason Samsb4ecab22010-01-19 16:43:26 -0800289 for (row = -5; row < 15; row++) {
Jason Sams0f505e52009-10-13 17:18:35 -0700290 float y = yoff - ((-rowFrac + row) * rowHeight);
291
Jason Sams76512482010-02-04 16:31:35 -0800292 for (col=0; col < colCount; col++) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700293 if (iconNum >= gIconCount) {
Jason Sams0f505e52009-10-13 17:18:35 -0700294 return;
295 }
296
297 if (iconNum >= 0) {
Jason Samsb4ecab22010-01-19 16:43:26 -0800298 float x = colWidth * col + (colWidth / 2);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800299 vpConstants->Position.x = x + 0.2f;
Jason Sams1a94ee32010-01-20 13:34:30 -0800300
Jason Sams1aa4ff02010-06-15 14:59:57 -0700301 if (gSelectedIconIndex == iconNum && !p && gSelectedIconTexture.p) {
Jason Sams13a75d52010-05-19 16:38:04 -0700302 rsgBindProgramFragment(gPFTexNearest);
303 rsgBindTexture(gPFTexNearest, 0, gSelectedIconTexture);
304 vpConstants->ImgSize.x = rsAllocationGetDimX(gSelectedIconTexture);
305 vpConstants->ImgSize.y = rsAllocationGetDimY(gSelectedIconTexture);
306 vpConstants->Position.y = y - (rsAllocationGetDimY(gSelectedIconTexture)
307 - rsAllocationGetDimY(gIconIDs[iconNum])) * 0.5f;
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -0700308 rsgDrawMesh(gSMCell);
Jason Sams37f262d2010-01-20 11:19:51 -0800309 }
310
Jason Sams13a75d52010-05-19 16:38:04 -0700311 rsgBindProgramFragment(gPFTexMip);
312 vpConstants->ImgSize.x = rsAllocationGetDimX(gIconIDs[iconNum]);
313 vpConstants->ImgSize.y = rsAllocationGetDimY(gIconIDs[iconNum]);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800314 vpConstants->Position.y = y - 0.2f;
Jason Sams13a75d52010-05-19 16:38:04 -0700315 rsgBindTexture(gPFTexMip, 0, gIconIDs[iconNum]);
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -0700316 rsgDrawMesh(gSMCell);
Joe Onorato742d7fc2009-10-15 19:48:16 -0700317
Jason Sams13a75d52010-05-19 16:38:04 -0700318 rsgBindProgramFragment(gPFTexMipAlpha);
319 vpConstants->ImgSize.x = rsAllocationGetDimX(gLabelIDs[iconNum]);
320 vpConstants->ImgSize.y = rsAllocationGetDimY(gLabelIDs[iconNum]);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800321 vpConstants->Position.y = y - 64.f - 0.2f;
Jason Sams13a75d52010-05-19 16:38:04 -0700322 rsgBindTexture(gPFTexMipAlpha, 0, gLabelIDs[iconNum]);
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -0700323 rsgDrawMesh(gSMCell);
Jason Sams0f505e52009-10-13 17:18:35 -0700324 }
325 iconNum++;
326 }
327 }
328}
329
Jason Sams0f505e52009-10-13 17:18:35 -0700330
Jason Sams14f67ed2010-05-11 14:02:43 -0700331int root()
Jason Sams0f505e52009-10-13 17:18:35 -0700332{
333 // Compute dt in seconds.
Jason Sams13a75d52010-05-19 16:38:04 -0700334 int64_t newTime = rsUptimeMillis();
Jason Sams14f67ed2010-05-11 14:02:43 -0700335 g_DT = (newTime - g_LastTime) * 0.001f;
Jason Sams0f505e52009-10-13 17:18:35 -0700336 g_LastTime = newTime;
Jason Sams2e19c052009-10-20 18:19:55 -0700337
Jason Samsb52dfa02009-10-14 20:16:14 -0700338 // physics may break if DT is large.
Jason Sams60a55bb2010-06-18 15:11:19 -0700339 g_DT = min(g_DT, 0.1f);
Jason Sams0f505e52009-10-13 17:18:35 -0700340
Jason Sams14f67ed2010-05-11 14:02:43 -0700341 if (g_Zoom != gZoomTarget) {
Jason Sams6471c8b2010-01-20 14:15:22 -0800342 float dz = g_DT * 1.7f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700343 if (gZoomTarget < 0.5f) {
Jason Sams6471c8b2010-01-20 14:15:22 -0800344 dz = -dz;
Jason Sams0f505e52009-10-13 17:18:35 -0700345 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700346 if (fabs(g_Zoom - gZoomTarget) < fabs(dz)) {
347 g_Zoom = gZoomTarget;
Jason Sams0f505e52009-10-13 17:18:35 -0700348 } else {
349 g_Zoom += dz;
350 }
351 updateReadback();
352 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700353 g_Animation = pow(1.f - g_Zoom, 3.f);
Jason Sams0f505e52009-10-13 17:18:35 -0700354
355 // Set clear value to dim the background based on the zoom position.
Jason Samsad1bdf02010-05-14 17:54:50 -0700356 if ((g_Zoom < 0.001f) && (gZoomTarget < 0.001f)) {
Jason Sams13a75d52010-05-19 16:38:04 -0700357 rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
Jason Sams0f505e52009-10-13 17:18:35 -0700358 // When we're zoomed out and not tracking motion events, reset the pos to 0.
359 if (!g_LastTouchDown) {
360 g_PosPage = 0;
361 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700362 return 0;
Jason Sams0f505e52009-10-13 17:18:35 -0700363 } else {
Jason Sams13a75d52010-05-19 16:38:04 -0700364 rsgClearColor(0.0f, 0.0f, 0.0f, g_Zoom);
Jason Sams0f505e52009-10-13 17:18:35 -0700365 }
366
Jason Sams13a75d52010-05-19 16:38:04 -0700367 rsgBindProgramStore(gPS);
368
Jason Sams0f505e52009-10-13 17:18:35 -0700369 // icons & labels
Jason Sams13a75d52010-05-19 16:38:04 -0700370 if (rsgGetWidth() > rsgGetHeight()) {
Jason Samsad1bdf02010-05-14 17:54:50 -0700371 g_Cols = COLUMNS_PER_PAGE_LANDSCAPE;
372 g_Rows = ROWS_PER_PAGE_LANDSCAPE;
Joe Onorato20e7a562010-03-18 17:12:52 -0700373 } else {
Jason Samsad1bdf02010-05-14 17:54:50 -0700374 g_Cols = COLUMNS_PER_PAGE_PORTRAIT;
375 g_Rows = ROWS_PER_PAGE_PORTRAIT;
Jason Samscc903492010-03-12 12:46:04 -0800376 }
Jason Samsad1bdf02010-05-14 17:54:50 -0700377
Jason Sams14f67ed2010-05-11 14:02:43 -0700378 g_PosMax = ((gIconCount + (g_Cols-1)) / g_Cols) - g_Rows;
Jason Sams0f505e52009-10-13 17:18:35 -0700379 if (g_PosMax < 0) g_PosMax = 0;
380
Jason Samscc903492010-03-12 12:46:04 -0800381 updatePos();
Jason Sams0f505e52009-10-13 17:18:35 -0700382 updateReadback();
383
Jason Sams0f505e52009-10-13 17:18:35 -0700384 // Draw the icons ========================================
Jason Sams6471c8b2010-01-20 14:15:22 -0800385 drawFrontGrid(g_PosPage, g_Animation);
Jason Samsc8514792009-10-29 14:27:29 -0700386
Jason Sams13a75d52010-05-19 16:38:04 -0700387 rsgBindProgramFragment(gPFTexNearest);
Jason Samsb52dfa02009-10-14 20:16:14 -0700388 draw_home_button();
Jason Sams60a55bb2010-06-18 15:11:19 -0700389 return (g_PosVelocity != 0) || rsFrac(g_PosPage) || g_Zoom != gZoomTarget || (g_MoveToTime != 0);
Jason Sams0f505e52009-10-13 17:18:35 -0700390}
391
Jason Sams14f67ed2010-05-11 14:02:43 -0700392