blob: fad8907a7197eaf1d479de903c978812d5992f7c [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
Shih-wei Liaoafb81d42010-07-19 16:20:03 -07005#include "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
Jason Sams14f67ed2010-05-11 14:02:43 -070015int gIconCount;
Jason Sams1aa4ff02010-06-15 14:59:57 -070016int gSelectedIconIndex = -1;
Jason Sams14f67ed2010-05-11 14:02:43 -070017rs_allocation gSelectedIconTexture;
Jason Sams14f67ed2010-05-11 14:02:43 -070018rs_allocation gHomeButton;
Jason Sams14f67ed2010-05-11 14:02:43 -070019
20rs_program_fragment gPFTexNearest;
21rs_program_fragment gPFTexMip;
22rs_program_fragment gPFTexMipAlpha;
23rs_program_vertex gPVCurve;
24rs_program_store gPS;
25rs_mesh gSMCell;
26
27rs_allocation *gIconIDs;
28rs_allocation *gLabelIDs;
29
Jason Sams1aa4ff02010-06-15 14:59:57 -070030typedef struct VpConsts {
Jason Sams14f67ed2010-05-11 14:02:43 -070031 float4 Position;
32 float4 ScaleOffset;
33 float2 BendPos;
34 float2 ImgSize;
35} VpConsts_t;
36VpConsts_t *vpConstants;
37
38
Jason Sams60a55bb2010-06-18 15:11:19 -070039#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)
40#pragma rs export_func(move, moveTo, setZoom, fling)
Jason Sams14f67ed2010-05-11 14:02:43 -070041
Jason Sams0f505e52009-10-13 17:18:35 -070042
43// Attraction to center values from page edge to page center.
Jason Samsad1bdf02010-05-14 17:54:50 -070044static float g_AttractionTable[9] = {20.f, 20.f, 20.f, 10.f, -10.f, -20.f, -20.f, -20.f, -20.f};
45static float g_FrictionTable[9] = {10.f, 10.f, 11.f, 15.f, 15.f, 11.f, 10.f, 10.f, 10.f};
46static float g_PhysicsTableSize = 7;
Jason Sams0f505e52009-10-13 17:18:35 -070047
Jason Sams60a55bb2010-06-18 15:11:19 -070048static float gZoomTarget;
49static float gTargetPos;
Jason Samsad1bdf02010-05-14 17:54:50 -070050static float g_PosPage = 0.f;
51static float g_PosVelocity = 0.f;
52static float g_LastPositionX = 0.f;
Jason Sams60a55bb2010-06-18 15:11:19 -070053static bool g_LastTouchDown = false;
Jason Sams14f67ed2010-05-11 14:02:43 -070054static float g_DT;
Jason Sams13a75d52010-05-19 16:38:04 -070055static int64_t g_LastTime;
Jason Sams14f67ed2010-05-11 14:02:43 -070056static int g_PosMax;
Jason Samsad1bdf02010-05-14 17:54:50 -070057static float g_Zoom = 0.f;
58static float g_Animation = 1.f;
Jason Sams14f67ed2010-05-11 14:02:43 -070059static float g_OldPosPage;
60static float g_OldPosVelocity;
61static float g_OldZoom;
Jason Samsad1bdf02010-05-14 17:54:50 -070062static float g_MoveToTotalTime = 0.2f;
63static float g_MoveToTime = 0.f;
64static float g_MoveToOldPos = 0.f;
Jason Samsc1c521e2009-10-19 14:45:45 -070065
Jason Sams14f67ed2010-05-11 14:02:43 -070066static int g_Cols;
67static int g_Rows;
Jason Sams0f505e52009-10-13 17:18:35 -070068
69// Drawing constants, should be parameters ======
70#define VIEW_ANGLE 1.28700222f
71
Jason Sams0f505e52009-10-13 17:18:35 -070072
Jason Sams14f67ed2010-05-11 14:02:43 -070073static void updateReadback() {
Jason Samsad1bdf02010-05-14 17:54:50 -070074 if ((g_OldPosPage != g_PosPage) ||
75 (g_OldPosVelocity != g_PosVelocity) ||
76 (g_OldZoom != g_Zoom)) {
Jason Sams0f505e52009-10-13 17:18:35 -070077
78 g_OldPosPage = g_PosPage;
79 g_OldPosVelocity = g_PosVelocity;
80 g_OldZoom = g_Zoom;
81
82 int i[3];
83 i[0] = g_PosPage * (1 << 16);
84 i[1] = g_PosVelocity * (1 << 16);
85 i[2] = g_OldZoom * (1 << 16);
Jason Sams13a75d52010-05-19 16:38:04 -070086 rsSendToClient(&i[0], 1, 12, 1);
Jason Samsad1bdf02010-05-14 17:54:50 -070087 }
Jason Sams0f505e52009-10-13 17:18:35 -070088}
89
Jason Sams0f505e52009-10-13 17:18:35 -070090void init() {
Jason Sams41b61c82009-10-15 15:40:54 -070091}
Jason Sams0f505e52009-10-13 17:18:35 -070092
Jason Sams60a55bb2010-06-18 15:11:19 -070093void move(float newPos) {
Jason Sams0f505e52009-10-13 17:18:35 -070094 if (g_LastTouchDown) {
Jason Sams60a55bb2010-06-18 15:11:19 -070095 float dx = -(newPos - g_LastPositionX);
Jason Sams0f505e52009-10-13 17:18:35 -070096 g_PosVelocity = 0;
Jason Sams6ec11bc2010-01-19 17:56:52 -080097 g_PosPage += dx * 5.2f;
Jason Sams0f505e52009-10-13 17:18:35 -070098
Jason Samsc8514792009-10-29 14:27:29 -070099 float pmin = -0.49f;
100 float pmax = g_PosMax + 0.49f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700101 g_PosPage = clamp(g_PosPage, pmin, pmax);
Jason Sams0f505e52009-10-13 17:18:35 -0700102 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700103 g_LastTouchDown = true;
104 g_LastPositionX = newPos;
Jason Samsc1c521e2009-10-19 14:45:45 -0700105 g_MoveToTime = 0;
Jason Sams0f505e52009-10-13 17:18:35 -0700106}
107
Jason Sams60a55bb2010-06-18 15:11:19 -0700108void moveTo(float targetPos) {
109 gTargetPos = targetPos;
Jason Samsc1c521e2009-10-19 14:45:45 -0700110 g_MoveToTime = g_MoveToTotalTime;
111 g_PosVelocity = 0;
112 g_MoveToOldPos = g_PosPage;
113}
114
Jason Sams60a55bb2010-06-18 15:11:19 -0700115void setZoom(float z, /*bool*/ int animate) {
116 gZoomTarget = z;
117 if (gZoomTarget < 0.001f) {
118 gZoomTarget = 0;
119 }
120 if (!animate) {
121 g_Zoom = gZoomTarget;
122 }
Joe Onorato3a8820b2009-11-10 15:06:42 -0800123 updateReadback();
124}
125
Jason Sams60a55bb2010-06-18 15:11:19 -0700126void fling(float newPos, float vel) {
127 move(newPos);
128
129 g_LastTouchDown = false;
130 g_PosVelocity = -vel * 4;
Jason Sams14f67ed2010-05-11 14:02:43 -0700131 float av = fabs(g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700132 float minVel = 3.5f;
133
Jason Sams13a75d52010-05-19 16:38:04 -0700134 minVel *= 1.f - (fabs(rsFrac(g_PosPage + 0.5f) - 0.5f) * 0.45f);
Jason Sams0f505e52009-10-13 17:18:35 -0700135
136 if (av < minVel && av > 0.2f) {
137 if (g_PosVelocity > 0) {
138 g_PosVelocity = minVel;
139 } else {
140 g_PosVelocity = -minVel;
141 }
142 }
143
144 if (g_PosPage <= 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700145 g_PosVelocity = max(0.f, g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700146 }
147 if (g_PosPage > g_PosMax) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700148 g_PosVelocity = min(0.f, g_PosVelocity);
Jason Sams0f505e52009-10-13 17:18:35 -0700149 }
150}
151
Jason Sams14f67ed2010-05-11 14:02:43 -0700152// Interpolates values in the range 0..1 to a curve that eases in
153// and out.
154static float getInterpolation(float input) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700155 return (cos((input + 1) * PI) * 0.5f) + 0.5f;
Jason Sams0f505e52009-10-13 17:18:35 -0700156}
157
Mike Cleron7d5d7462009-10-20 14:06:00 -0700158
Jason Sams14f67ed2010-05-11 14:02:43 -0700159static void updatePos() {
Jason Sams0f505e52009-10-13 17:18:35 -0700160 if (g_LastTouchDown) {
161 return;
162 }
163
Jason Sams13a75d52010-05-19 16:38:04 -0700164 float tablePosNorm = rsFrac(g_PosPage + 0.5f);
Jason Sams0f505e52009-10-13 17:18:35 -0700165 float tablePosF = tablePosNorm * g_PhysicsTableSize;
166 int tablePosI = tablePosF;
167 float tablePosFrac = tablePosF - tablePosI;
Jason Sams14f67ed2010-05-11 14:02:43 -0700168 float accel = mix(g_AttractionTable[tablePosI],
Jason Sams0f505e52009-10-13 17:18:35 -0700169 g_AttractionTable[tablePosI + 1],
170 tablePosFrac) * g_DT;
Jason Sams14f67ed2010-05-11 14:02:43 -0700171 float friction = mix(g_FrictionTable[tablePosI],
Jason Sams2e19c052009-10-20 18:19:55 -0700172 g_FrictionTable[tablePosI + 1],
173 tablePosFrac) * g_DT;
Jason Sams0f505e52009-10-13 17:18:35 -0700174
Jason Samsc1c521e2009-10-19 14:45:45 -0700175 if (g_MoveToTime) {
Jason Samsc8514792009-10-29 14:27:29 -0700176 // New position is old posiition + (total distance) * (interpolated time)
Jason Sams14f67ed2010-05-11 14:02:43 -0700177 g_PosPage = g_MoveToOldPos + (gTargetPos - g_MoveToOldPos) * getInterpolation((g_MoveToTotalTime - g_MoveToTime) / g_MoveToTotalTime);
Jason Samsc1c521e2009-10-19 14:45:45 -0700178 g_MoveToTime -= g_DT;
179 if (g_MoveToTime <= 0) {
180 g_MoveToTime = 0;
Jason Sams14f67ed2010-05-11 14:02:43 -0700181 g_PosPage = gTargetPos;
Jason Samsc1c521e2009-10-19 14:45:45 -0700182 }
183 return;
184 }
185
Jason Sams0f505e52009-10-13 17:18:35 -0700186 // If our velocity is low OR acceleration is opposing it, apply it.
Jason Sams14f67ed2010-05-11 14:02:43 -0700187 if (fabs(g_PosVelocity) < 4.0f || (g_PosVelocity * accel) < 0) {
Jason Sams0f505e52009-10-13 17:18:35 -0700188 g_PosVelocity += accel;
189 }
Jason Sams13a75d52010-05-19 16:38:04 -0700190 //RS_DEBUG(g_PosPage);
191 //RS_DEBUG(g_PosVelocity);
192 //RS_DEBUG(friction);
193 //RS_DEBUG(accel);
Jason Sams0f505e52009-10-13 17:18:35 -0700194
Jason Samsc8514792009-10-29 14:27:29 -0700195 // Normal physics
196 if (g_PosVelocity > 0) {
197 g_PosVelocity -= friction;
Jason Sams14f67ed2010-05-11 14:02:43 -0700198 g_PosVelocity = max(g_PosVelocity, 0.f);
Jason Samsc8514792009-10-29 14:27:29 -0700199 } else {
200 g_PosVelocity += friction;
Jason Sams14f67ed2010-05-11 14:02:43 -0700201 g_PosVelocity = min(g_PosVelocity, 0.f);
Jason Samsc8514792009-10-29 14:27:29 -0700202 }
203
Jason Sams14f67ed2010-05-11 14:02:43 -0700204 if ((friction > fabs(g_PosVelocity)) && (friction > fabs(accel))) {
Jason Sams0f505e52009-10-13 17:18:35 -0700205 // Special get back to center and overcome friction physics.
206 float t = tablePosNorm - 0.5f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700207 if (fabs(t) < (friction * g_DT)) {
Jason Sams0f505e52009-10-13 17:18:35 -0700208 // really close, just snap
Jason Sams14f67ed2010-05-11 14:02:43 -0700209 g_PosPage = round(g_PosPage);
Jason Sams0f505e52009-10-13 17:18:35 -0700210 g_PosVelocity = 0;
211 } else {
212 if (t > 0) {
213 g_PosVelocity = -friction;
214 } else {
215 g_PosVelocity = friction;
216 }
217 }
Jason Sams0f505e52009-10-13 17:18:35 -0700218 }
Jason Sams0f505e52009-10-13 17:18:35 -0700219
220 // Check for out of boundry conditions.
221 if (g_PosPage < 0 && g_PosVelocity < 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700222 float damp = 1.0f + (g_PosPage * 4);
223 damp = clamp(damp, 0.f, 0.9f);
Jason Sams0f505e52009-10-13 17:18:35 -0700224 g_PosVelocity *= damp;
225 }
226 if (g_PosPage > g_PosMax && g_PosVelocity > 0) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700227 float damp = 1.0f - ((g_PosPage - g_PosMax) * 4);
228 damp = clamp(damp, 0.f, 0.9f);
Jason Sams0f505e52009-10-13 17:18:35 -0700229 g_PosVelocity *= damp;
230 }
Jason Samsc8514792009-10-29 14:27:29 -0700231
232 g_PosPage += g_PosVelocity * g_DT;
Jason Sams14f67ed2010-05-11 14:02:43 -0700233 g_PosPage = clamp(g_PosPage, -0.49f, g_PosMax + 0.49f);
Jason Sams0f505e52009-10-13 17:18:35 -0700234}
235
Jason Sams14f67ed2010-05-11 14:02:43 -0700236static void
Jason Sams0f505e52009-10-13 17:18:35 -0700237draw_home_button()
238{
Jason Samsad1bdf02010-05-14 17:54:50 -0700239 color(1.0f, 1.0f, 1.0f, 1.0f);
Jason Sams13a75d52010-05-19 16:38:04 -0700240 rsgBindTexture(gPFTexNearest, 0, gHomeButton);
Jason Sams0f505e52009-10-13 17:18:35 -0700241
Jason Sams13a75d52010-05-19 16:38:04 -0700242 float w = rsgGetWidth();
243 float h = rsgGetHeight();
244 float tw = rsAllocationGetDimX(gHomeButton);
245 float th = rsAllocationGetDimY(gHomeButton);
Jason Sams76512482010-02-04 16:31:35 -0800246
247 float x;
248 float y;
Jason Sams13a75d52010-05-19 16:38:04 -0700249 if (w > h) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700250 x = w - (tw * (1 - g_Animation)) + 20;
251 y = (h - th) * 0.5f;
Jason Sams76512482010-02-04 16:31:35 -0800252 } else {
Jason Sams14f67ed2010-05-11 14:02:43 -0700253 x = (w - tw) / 2;
254 y = -g_Animation * th;
Jason Sams76512482010-02-04 16:31:35 -0800255 y -= 30; // move the house to the edge of the screen as it doesn't fill the texture.
256 }
257
Jason Sams13a75d52010-05-19 16:38:04 -0700258 rsgDrawSpriteScreenspace(x, y, 0, tw, th);
Jason Sams0f505e52009-10-13 17:18:35 -0700259}
260
Jason Sams14f67ed2010-05-11 14:02:43 -0700261static void drawFrontGrid(float rowOffset, float p)
Jason Sams0f505e52009-10-13 17:18:35 -0700262{
Jason Sams13a75d52010-05-19 16:38:04 -0700263 float h = rsgGetHeight();
264 float w = rsgGetWidth();
Jason Sams0f505e52009-10-13 17:18:35 -0700265
266 int intRowOffset = rowOffset;
267 float rowFrac = rowOffset - intRowOffset;
Jason Sams13a75d52010-05-19 16:38:04 -0700268 float colWidth = 120.f;//w / 4;
Jason Sams0f505e52009-10-13 17:18:35 -0700269 float rowHeight = colWidth + 25.f;
Jason Samsb4ecab22010-01-19 16:43:26 -0800270 float yoff = 0.5f * h + 1.5f * rowHeight;
Jason Sams0f505e52009-10-13 17:18:35 -0700271
272 int row, col;
Jason Sams76512482010-02-04 16:31:35 -0800273 int colCount = 4;
274 if (w > h) {
275 colCount = 6;
276 rowHeight -= 12.f;
277 yoff = 0.47f * h + 1.0f * rowHeight;
278 }
279
280 int iconNum = (intRowOffset - 5) * colCount;
281
Jason Sams13a75d52010-05-19 16:38:04 -0700282 rsgBindProgramVertex(gPVCurve);
Jason Samsb4ecab22010-01-19 16:43:26 -0800283
Jason Sams76512482010-02-04 16:31:35 -0800284 vpConstants->Position.z = p;
Jason Samsb4ecab22010-01-19 16:43:26 -0800285
Jason Samsad1bdf02010-05-14 17:54:50 -0700286 color(1.0f, 1.0f, 1.0f, 1.0f);
Jason Samsb4ecab22010-01-19 16:43:26 -0800287 for (row = -5; row < 15; row++) {
Jason Sams0f505e52009-10-13 17:18:35 -0700288 float y = yoff - ((-rowFrac + row) * rowHeight);
289
Jason Sams76512482010-02-04 16:31:35 -0800290 for (col=0; col < colCount; col++) {
Jason Sams14f67ed2010-05-11 14:02:43 -0700291 if (iconNum >= gIconCount) {
Jason Sams0f505e52009-10-13 17:18:35 -0700292 return;
293 }
294
295 if (iconNum >= 0) {
Jason Samsb4ecab22010-01-19 16:43:26 -0800296 float x = colWidth * col + (colWidth / 2);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800297 vpConstants->Position.x = x + 0.2f;
Jason Sams1a94ee32010-01-20 13:34:30 -0800298
Jason Sams1aa4ff02010-06-15 14:59:57 -0700299 if (gSelectedIconIndex == iconNum && !p && gSelectedIconTexture.p) {
Jason Sams13a75d52010-05-19 16:38:04 -0700300 rsgBindProgramFragment(gPFTexNearest);
301 rsgBindTexture(gPFTexNearest, 0, gSelectedIconTexture);
302 vpConstants->ImgSize.x = rsAllocationGetDimX(gSelectedIconTexture);
303 vpConstants->ImgSize.y = rsAllocationGetDimY(gSelectedIconTexture);
304 vpConstants->Position.y = y - (rsAllocationGetDimY(gSelectedIconTexture)
305 - rsAllocationGetDimY(gIconIDs[iconNum])) * 0.5f;
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -0700306 rsgDrawMesh(gSMCell);
Jason Sams37f262d2010-01-20 11:19:51 -0800307 }
308
Jason Sams13a75d52010-05-19 16:38:04 -0700309 rsgBindProgramFragment(gPFTexMip);
310 vpConstants->ImgSize.x = rsAllocationGetDimX(gIconIDs[iconNum]);
311 vpConstants->ImgSize.y = rsAllocationGetDimY(gIconIDs[iconNum]);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800312 vpConstants->Position.y = y - 0.2f;
Jason Sams13a75d52010-05-19 16:38:04 -0700313 rsgBindTexture(gPFTexMip, 0, gIconIDs[iconNum]);
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -0700314 rsgDrawMesh(gSMCell);
Joe Onorato742d7fc2009-10-15 19:48:16 -0700315
Jason Sams13a75d52010-05-19 16:38:04 -0700316 rsgBindProgramFragment(gPFTexMipAlpha);
317 vpConstants->ImgSize.x = rsAllocationGetDimX(gLabelIDs[iconNum]);
318 vpConstants->ImgSize.y = rsAllocationGetDimY(gLabelIDs[iconNum]);
Jason Sams6b08ffe2010-02-22 15:41:30 -0800319 vpConstants->Position.y = y - 64.f - 0.2f;
Jason Sams13a75d52010-05-19 16:38:04 -0700320 rsgBindTexture(gPFTexMipAlpha, 0, gLabelIDs[iconNum]);
Alex Sakhartchouk1bdb9d32010-07-01 16:08:19 -0700321 rsgDrawMesh(gSMCell);
Jason Sams0f505e52009-10-13 17:18:35 -0700322 }
323 iconNum++;
324 }
325 }
326}
327
Jason Sams0f505e52009-10-13 17:18:35 -0700328
Jason Sams14f67ed2010-05-11 14:02:43 -0700329int root()
Jason Sams0f505e52009-10-13 17:18:35 -0700330{
331 // Compute dt in seconds.
Jason Sams13a75d52010-05-19 16:38:04 -0700332 int64_t newTime = rsUptimeMillis();
Jason Sams14f67ed2010-05-11 14:02:43 -0700333 g_DT = (newTime - g_LastTime) * 0.001f;
Jason Sams0f505e52009-10-13 17:18:35 -0700334 g_LastTime = newTime;
Jason Sams2e19c052009-10-20 18:19:55 -0700335
Jason Samsb52dfa02009-10-14 20:16:14 -0700336 // physics may break if DT is large.
Jason Sams60a55bb2010-06-18 15:11:19 -0700337 g_DT = min(g_DT, 0.1f);
Jason Sams0f505e52009-10-13 17:18:35 -0700338
Jason Sams14f67ed2010-05-11 14:02:43 -0700339 if (g_Zoom != gZoomTarget) {
Jason Sams6471c8b2010-01-20 14:15:22 -0800340 float dz = g_DT * 1.7f;
Jason Sams14f67ed2010-05-11 14:02:43 -0700341 if (gZoomTarget < 0.5f) {
Jason Sams6471c8b2010-01-20 14:15:22 -0800342 dz = -dz;
Jason Sams0f505e52009-10-13 17:18:35 -0700343 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700344 if (fabs(g_Zoom - gZoomTarget) < fabs(dz)) {
345 g_Zoom = gZoomTarget;
Jason Sams0f505e52009-10-13 17:18:35 -0700346 } else {
347 g_Zoom += dz;
348 }
349 updateReadback();
350 }
Jason Sams14f67ed2010-05-11 14:02:43 -0700351 g_Animation = pow(1.f - g_Zoom, 3.f);
Jason Sams0f505e52009-10-13 17:18:35 -0700352
353 // Set clear value to dim the background based on the zoom position.
Jason Samsad1bdf02010-05-14 17:54:50 -0700354 if ((g_Zoom < 0.001f) && (gZoomTarget < 0.001f)) {
Jason Sams13a75d52010-05-19 16:38:04 -0700355 rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
Jason Sams0f505e52009-10-13 17:18:35 -0700356 // When we're zoomed out and not tracking motion events, reset the pos to 0.
357 if (!g_LastTouchDown) {
358 g_PosPage = 0;
359 }
Jason Sams60a55bb2010-06-18 15:11:19 -0700360 return 0;
Jason Sams0f505e52009-10-13 17:18:35 -0700361 } else {
Jason Sams13a75d52010-05-19 16:38:04 -0700362 rsgClearColor(0.0f, 0.0f, 0.0f, g_Zoom);
Jason Sams0f505e52009-10-13 17:18:35 -0700363 }
364
Jason Sams13a75d52010-05-19 16:38:04 -0700365 rsgBindProgramStore(gPS);
366
Jason Sams0f505e52009-10-13 17:18:35 -0700367 // icons & labels
Jason Sams13a75d52010-05-19 16:38:04 -0700368 if (rsgGetWidth() > rsgGetHeight()) {
Jason Samsad1bdf02010-05-14 17:54:50 -0700369 g_Cols = COLUMNS_PER_PAGE_LANDSCAPE;
370 g_Rows = ROWS_PER_PAGE_LANDSCAPE;
Joe Onorato20e7a562010-03-18 17:12:52 -0700371 } else {
Jason Samsad1bdf02010-05-14 17:54:50 -0700372 g_Cols = COLUMNS_PER_PAGE_PORTRAIT;
373 g_Rows = ROWS_PER_PAGE_PORTRAIT;
Jason Samscc903492010-03-12 12:46:04 -0800374 }
Jason Samsad1bdf02010-05-14 17:54:50 -0700375
Jason Sams14f67ed2010-05-11 14:02:43 -0700376 g_PosMax = ((gIconCount + (g_Cols-1)) / g_Cols) - g_Rows;
Jason Sams0f505e52009-10-13 17:18:35 -0700377 if (g_PosMax < 0) g_PosMax = 0;
378
Jason Samscc903492010-03-12 12:46:04 -0800379 updatePos();
Jason Sams0f505e52009-10-13 17:18:35 -0700380 updateReadback();
381
Jason Sams0f505e52009-10-13 17:18:35 -0700382 // Draw the icons ========================================
Jason Sams6471c8b2010-01-20 14:15:22 -0800383 drawFrontGrid(g_PosPage, g_Animation);
Jason Samsc8514792009-10-29 14:27:29 -0700384
Jason Sams13a75d52010-05-19 16:38:04 -0700385 rsgBindProgramFragment(gPFTexNearest);
Jason Samsb52dfa02009-10-14 20:16:14 -0700386 draw_home_button();
Jason Sams60a55bb2010-06-18 15:11:19 -0700387 return (g_PosVelocity != 0) || rsFrac(g_PosPage) || g_Zoom != gZoomTarget || (g_MoveToTime != 0);
Jason Sams0f505e52009-10-13 17:18:35 -0700388}
389
Jason Sams14f67ed2010-05-11 14:02:43 -0700390