Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 1 | #pragma version(1) |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 2 | |
| 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 Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 6 | |
| 7 | #define PI 3.14159f |
| 8 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 9 | // Constants from Java |
| 10 | int COLUMNS_PER_PAGE_PORTRAIT; |
| 11 | int ROWS_PER_PAGE_PORTRAIT; |
| 12 | int COLUMNS_PER_PAGE_LANDSCAPE; |
| 13 | int ROWS_PER_PAGE_LANDSCAPE; |
| 14 | |
| 15 | float gNewPositionX; |
| 16 | int gNewTouchDown; |
| 17 | float gFlingVelocity; |
| 18 | int gIconCount; |
| 19 | int gSelectedIconIndex; |
| 20 | rs_allocation gSelectedIconTexture; |
| 21 | float gZoomTarget; |
| 22 | rs_allocation gHomeButton; |
| 23 | float gTargetPos; |
| 24 | |
| 25 | rs_program_fragment gPFTexNearest; |
| 26 | rs_program_fragment gPFTexMip; |
| 27 | rs_program_fragment gPFTexMipAlpha; |
| 28 | rs_program_vertex gPVCurve; |
| 29 | rs_program_store gPS; |
| 30 | rs_mesh gSMCell; |
| 31 | |
| 32 | rs_allocation *gIconIDs; |
| 33 | rs_allocation *gLabelIDs; |
| 34 | |
| 35 | typedef struct VpConsts_s { |
| 36 | float4 Position; |
| 37 | float4 ScaleOffset; |
| 38 | float2 BendPos; |
| 39 | float2 ImgSize; |
| 40 | } VpConsts_t; |
| 41 | VpConsts_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 | |
| 48 | void debugAll() |
| 49 | { |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 52 | |
| 53 | // Attraction to center values from page edge to page center. |
Jason Sams | ad1bdf0 | 2010-05-14 17:54:50 -0700 | [diff] [blame^] | 54 | static float g_AttractionTable[9] = {20.f, 20.f, 20.f, 10.f, -10.f, -20.f, -20.f, -20.f, -20.f}; |
| 55 | static float g_FrictionTable[9] = {10.f, 10.f, 11.f, 15.f, 15.f, 11.f, 10.f, 10.f, 10.f}; |
| 56 | static float g_PhysicsTableSize = 7; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 57 | |
Jason Sams | ad1bdf0 | 2010-05-14 17:54:50 -0700 | [diff] [blame^] | 58 | static float g_PosPage = 0.f; |
| 59 | static float g_PosVelocity = 0.f; |
| 60 | static float g_LastPositionX = 0.f; |
| 61 | static int g_LastTouchDown = 0; |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 62 | static float g_DT; |
| 63 | static int g_LastTime; |
| 64 | static int g_PosMax; |
Jason Sams | ad1bdf0 | 2010-05-14 17:54:50 -0700 | [diff] [blame^] | 65 | static float g_Zoom = 0.f; |
| 66 | static float g_Animation = 1.f; |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 67 | static float g_OldPosPage; |
| 68 | static float g_OldPosVelocity; |
| 69 | static float g_OldZoom; |
Jason Sams | ad1bdf0 | 2010-05-14 17:54:50 -0700 | [diff] [blame^] | 70 | static float g_MoveToTotalTime = 0.2f; |
| 71 | static float g_MoveToTime = 0.f; |
| 72 | static float g_MoveToOldPos = 0.f; |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 73 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 74 | static int g_Cols; |
| 75 | static int g_Rows; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 76 | |
| 77 | // Drawing constants, should be parameters ====== |
| 78 | #define VIEW_ANGLE 1.28700222f |
| 79 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 80 | static int g_DrawLastFrame; |
| 81 | static int lastFrame(int draw) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 82 | g_DrawLastFrame = draw; |
Jason Sams | ad1bdf0 | 2010-05-14 17:54:50 -0700 | [diff] [blame^] | 83 | return draw; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 86 | static void updateReadback() { |
Jason Sams | ad1bdf0 | 2010-05-14 17:54:50 -0700 | [diff] [blame^] | 87 | if ((g_OldPosPage != g_PosPage) || |
| 88 | (g_OldPosVelocity != g_PosVelocity) || |
| 89 | (g_OldZoom != g_Zoom)) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 90 | |
| 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 Sams | ad1bdf0 | 2010-05-14 17:54:50 -0700 | [diff] [blame^] | 100 | } |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Jason Sams | ad1bdf0 | 2010-05-14 17:54:50 -0700 | [diff] [blame^] | 103 | void setColor(float r, float g, float b, float a) { |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 104 | } |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 105 | |
| 106 | void init() { |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 107 | //debugPi(99, 10); |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | void resetHWWar() { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | void move() { |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 114 | //debugPi(99, 8); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 115 | if (g_LastTouchDown) { |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 116 | float dx = -(gNewPositionX - g_LastPositionX); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 117 | g_PosVelocity = 0; |
Jason Sams | 6ec11bc | 2010-01-19 17:56:52 -0800 | [diff] [blame] | 118 | g_PosPage += dx * 5.2f; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 119 | |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 120 | float pmin = -0.49f; |
| 121 | float pmax = g_PosMax + 0.49f; |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 122 | g_PosPage = clamp(g_PosPage, pmin, pmax); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 123 | } |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 124 | g_LastTouchDown = gNewTouchDown; |
| 125 | g_LastPositionX = gNewPositionX; |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 126 | g_MoveToTime = 0; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 127 | //debugF("Move P", g_PosPage); |
| 128 | } |
| 129 | |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 130 | void moveTo() { |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 131 | //debugPi(99, 7); |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 132 | g_MoveToTime = g_MoveToTotalTime; |
| 133 | g_PosVelocity = 0; |
| 134 | g_MoveToOldPos = g_PosPage; |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 135 | |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 136 | // debugF("======= moveTo", state->targetPos); |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 139 | void setZoom() { |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 140 | //debugPi(99, 6); |
| 141 | g_Zoom = gZoomTarget; |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 142 | g_DrawLastFrame = 1; |
| 143 | updateReadback(); |
| 144 | } |
| 145 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 146 | void fling() { |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 147 | //debugPi(99, 5); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 148 | g_LastTouchDown = 0; |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 149 | g_PosVelocity = -gFlingVelocity * 4; |
| 150 | float av = fabs(g_PosVelocity); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 151 | float minVel = 3.5f; |
| 152 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 153 | minVel *= 1.f - (fabs(frac(g_PosPage + 0.5f) - 0.5f) * 0.45f); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 154 | |
| 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 Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 164 | g_PosVelocity = max(0.f, g_PosVelocity); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 165 | } |
| 166 | if (g_PosPage > g_PosMax) { |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 167 | g_PosVelocity = min(0.f, g_PosVelocity); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 171 | // Interpolates values in the range 0..1 to a curve that eases in |
| 172 | // and out. |
| 173 | static float getInterpolation(float input) { |
| 174 | //debugPi(99, 4); |
| 175 | return (cos((input + 1) * PI) * 0.5f) + 0.5f; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 178 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 179 | static void updatePos() { |
| 180 | //debugPi(99, 3); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 181 | if (g_LastTouchDown) { |
| 182 | return; |
| 183 | } |
| 184 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 185 | float tablePosNorm = frac(g_PosPage + 0.5f); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 186 | float tablePosF = tablePosNorm * g_PhysicsTableSize; |
| 187 | int tablePosI = tablePosF; |
| 188 | float tablePosFrac = tablePosF - tablePosI; |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 189 | float accel = mix(g_AttractionTable[tablePosI], |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 190 | g_AttractionTable[tablePosI + 1], |
| 191 | tablePosFrac) * g_DT; |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 192 | float friction = mix(g_FrictionTable[tablePosI], |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 193 | g_FrictionTable[tablePosI + 1], |
| 194 | tablePosFrac) * g_DT; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 195 | |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 196 | if (g_MoveToTime) { |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 197 | // New position is old posiition + (total distance) * (interpolated time) |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 198 | g_PosPage = g_MoveToOldPos + (gTargetPos - g_MoveToOldPos) * getInterpolation((g_MoveToTotalTime - g_MoveToTime) / g_MoveToTotalTime); |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 199 | g_MoveToTime -= g_DT; |
| 200 | if (g_MoveToTime <= 0) { |
| 201 | g_MoveToTime = 0; |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 202 | g_PosPage = gTargetPos; |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 203 | } |
| 204 | return; |
| 205 | } |
| 206 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 207 | // If our velocity is low OR acceleration is opposing it, apply it. |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 208 | if (fabs(g_PosVelocity) < 4.0f || (g_PosVelocity * accel) < 0) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 209 | g_PosVelocity += accel; |
| 210 | } |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 211 | //debugF("g_PosPage", g_PosPage); |
| 212 | //debugF(" g_PosVelocity", g_PosVelocity); |
| 213 | //debugF(" friction", friction); |
| 214 | //debugF(" accel", accel); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 215 | |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 216 | // Normal physics |
| 217 | if (g_PosVelocity > 0) { |
| 218 | g_PosVelocity -= friction; |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 219 | g_PosVelocity = max(g_PosVelocity, 0.f); |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 220 | } else { |
| 221 | g_PosVelocity += friction; |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 222 | g_PosVelocity = min(g_PosVelocity, 0.f); |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 225 | if ((friction > fabs(g_PosVelocity)) && (friction > fabs(accel))) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 226 | // Special get back to center and overcome friction physics. |
| 227 | float t = tablePosNorm - 0.5f; |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 228 | if (fabs(t) < (friction * g_DT)) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 229 | // really close, just snap |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 230 | g_PosPage = round(g_PosPage); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 231 | g_PosVelocity = 0; |
| 232 | } else { |
| 233 | if (t > 0) { |
| 234 | g_PosVelocity = -friction; |
| 235 | } else { |
| 236 | g_PosVelocity = friction; |
| 237 | } |
| 238 | } |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 239 | } |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 240 | |
| 241 | // Check for out of boundry conditions. |
| 242 | if (g_PosPage < 0 && g_PosVelocity < 0) { |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 243 | float damp = 1.0f + (g_PosPage * 4); |
| 244 | damp = clamp(damp, 0.f, 0.9f); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 245 | g_PosVelocity *= damp; |
| 246 | } |
| 247 | if (g_PosPage > g_PosMax && g_PosVelocity > 0) { |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 248 | float damp = 1.0f - ((g_PosPage - g_PosMax) * 4); |
| 249 | damp = clamp(damp, 0.f, 0.9f); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 250 | g_PosVelocity *= damp; |
| 251 | } |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 252 | |
| 253 | g_PosPage += g_PosVelocity * g_DT; |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 254 | g_PosPage = clamp(g_PosPage, -0.49f, g_PosMax + 0.49f); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 257 | static void |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 258 | draw_home_button() |
| 259 | { |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 260 | //debugPi(99, 2); |
Jason Sams | ad1bdf0 | 2010-05-14 17:54:50 -0700 | [diff] [blame^] | 261 | color(1.0f, 1.0f, 1.0f, 1.0f); |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 262 | bindTexture(gPFTexNearest, 0, gHomeButton); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 263 | |
Jason Sams | 7651248 | 2010-02-04 16:31:35 -0800 | [diff] [blame] | 264 | float w = getWidth(); |
| 265 | float h = getHeight(); |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 266 | float tw = allocGetDimX(gHomeButton); |
| 267 | float th = allocGetDimY(gHomeButton); |
Jason Sams | 7651248 | 2010-02-04 16:31:35 -0800 | [diff] [blame] | 268 | |
| 269 | float x; |
| 270 | float y; |
| 271 | if (getWidth() > getHeight()) { |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 272 | x = w - (tw * (1 - g_Animation)) + 20; |
| 273 | y = (h - th) * 0.5f; |
Jason Sams | 7651248 | 2010-02-04 16:31:35 -0800 | [diff] [blame] | 274 | } else { |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 275 | x = (w - tw) / 2; |
| 276 | y = -g_Animation * th; |
Jason Sams | 7651248 | 2010-02-04 16:31:35 -0800 | [diff] [blame] | 277 | y -= 30; // move the house to the edge of the screen as it doesn't fill the texture. |
| 278 | } |
| 279 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 280 | drawSpriteScreenspace(x, y, 0, tw, th); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 283 | static void drawFrontGrid(float rowOffset, float p) |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 284 | { |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 285 | //debugPi(99, 1); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 286 | float h = getHeight(); |
| 287 | float w = getWidth(); |
| 288 | |
| 289 | int intRowOffset = rowOffset; |
| 290 | float rowFrac = rowOffset - intRowOffset; |
Jason Sams | 7651248 | 2010-02-04 16:31:35 -0800 | [diff] [blame] | 291 | float colWidth = 120.f;//getWidth() / 4; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 292 | float rowHeight = colWidth + 25.f; |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 293 | float yoff = 0.5f * h + 1.5f * rowHeight; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 294 | |
| 295 | int row, col; |
Jason Sams | 7651248 | 2010-02-04 16:31:35 -0800 | [diff] [blame] | 296 | 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 Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 305 | bindProgramVertex(gPVCurve); |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 306 | |
Jason Sams | 7651248 | 2010-02-04 16:31:35 -0800 | [diff] [blame] | 307 | vpConstants->Position.z = p; |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 308 | |
Jason Sams | ad1bdf0 | 2010-05-14 17:54:50 -0700 | [diff] [blame^] | 309 | color(1.0f, 1.0f, 1.0f, 1.0f); |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 310 | for (row = -5; row < 15; row++) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 311 | float y = yoff - ((-rowFrac + row) * rowHeight); |
| 312 | |
Jason Sams | 7651248 | 2010-02-04 16:31:35 -0800 | [diff] [blame] | 313 | for (col=0; col < colCount; col++) { |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 314 | if (iconNum >= gIconCount) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 315 | return; |
| 316 | } |
| 317 | |
| 318 | if (iconNum >= 0) { |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 319 | float x = colWidth * col + (colWidth / 2); |
Jason Sams | 6b08ffe | 2010-02-22 15:41:30 -0800 | [diff] [blame] | 320 | vpConstants->Position.x = x + 0.2f; |
Jason Sams | 1a94ee3 | 2010-01-20 13:34:30 -0800 | [diff] [blame] | 321 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 322 | 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 Sams | 37f262d | 2010-01-20 11:19:51 -0800 | [diff] [blame] | 329 | } |
| 330 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 331 | bindProgramFragment(gPFTexMip); |
| 332 | vpConstants->ImgSize.x = allocGetDimX(gIconIDs[iconNum]); |
| 333 | vpConstants->ImgSize.y = allocGetDimY(gIconIDs[iconNum]); |
Jason Sams | 6b08ffe | 2010-02-22 15:41:30 -0800 | [diff] [blame] | 334 | vpConstants->Position.y = y - 0.2f; |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 335 | bindTexture(gPFTexMip, 0, gIconIDs[iconNum]); |
| 336 | drawSimpleMesh(gSMCell); |
Joe Onorato | 742d7fc | 2009-10-15 19:48:16 -0700 | [diff] [blame] | 337 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 338 | bindProgramFragment(gPFTexMipAlpha); |
| 339 | vpConstants->ImgSize.x = allocGetDimX(gLabelIDs[iconNum]); |
| 340 | vpConstants->ImgSize.y = allocGetDimY(gLabelIDs[iconNum]); |
Jason Sams | 6b08ffe | 2010-02-22 15:41:30 -0800 | [diff] [blame] | 341 | vpConstants->Position.y = y - 64.f - 0.2f; |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 342 | bindTexture(gPFTexMipAlpha, 0, gLabelIDs[iconNum]); |
| 343 | drawSimpleMesh(gSMCell); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 344 | } |
| 345 | iconNum++; |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 350 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 351 | int root() |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 352 | { |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 353 | //debugAll(); |
| 354 | bindProgramStore(gPS); |
| 355 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 356 | // Compute dt in seconds. |
| 357 | int newTime = uptimeMillis(); |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 358 | g_DT = (newTime - g_LastTime) * 0.001f; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 359 | g_LastTime = newTime; |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 360 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 361 | 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 Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 366 | // physics may break if DT is large. |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 367 | g_DT = min(g_DT, 0.2f); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 368 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 369 | if (g_Zoom != gZoomTarget) { |
Jason Sams | 6471c8b | 2010-01-20 14:15:22 -0800 | [diff] [blame] | 370 | float dz = g_DT * 1.7f; |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 371 | if (gZoomTarget < 0.5f) { |
Jason Sams | 6471c8b | 2010-01-20 14:15:22 -0800 | [diff] [blame] | 372 | dz = -dz; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 373 | } |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 374 | if (fabs(g_Zoom - gZoomTarget) < fabs(dz)) { |
| 375 | g_Zoom = gZoomTarget; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 376 | } else { |
| 377 | g_Zoom += dz; |
| 378 | } |
| 379 | updateReadback(); |
| 380 | } |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 381 | g_Animation = pow(1.f - g_Zoom, 3.f); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 382 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 383 | //debugPf(100, g_Zoom); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 384 | // Set clear value to dim the background based on the zoom position. |
Jason Sams | ad1bdf0 | 2010-05-14 17:54:50 -0700 | [diff] [blame^] | 385 | if ((g_Zoom < 0.001f) && (gZoomTarget < 0.001f)) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 386 | 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 Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 392 | } else { |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 393 | //debugPf(101, g_Zoom); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 394 | pfClearColor(0.0f, 0.0f, 0.0f, g_Zoom); |
| 395 | } |
| 396 | |
| 397 | // icons & labels |
Jason Sams | cc90349 | 2010-03-12 12:46:04 -0800 | [diff] [blame] | 398 | if (getWidth() > getHeight()) { |
Jason Sams | ad1bdf0 | 2010-05-14 17:54:50 -0700 | [diff] [blame^] | 399 | g_Cols = COLUMNS_PER_PAGE_LANDSCAPE; |
| 400 | g_Rows = ROWS_PER_PAGE_LANDSCAPE; |
Joe Onorato | 20e7a56 | 2010-03-18 17:12:52 -0700 | [diff] [blame] | 401 | } else { |
Jason Sams | ad1bdf0 | 2010-05-14 17:54:50 -0700 | [diff] [blame^] | 402 | g_Cols = COLUMNS_PER_PAGE_PORTRAIT; |
| 403 | g_Rows = ROWS_PER_PAGE_PORTRAIT; |
Jason Sams | cc90349 | 2010-03-12 12:46:04 -0800 | [diff] [blame] | 404 | } |
Jason Sams | ad1bdf0 | 2010-05-14 17:54:50 -0700 | [diff] [blame^] | 405 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 406 | g_PosMax = ((gIconCount + (g_Cols-1)) / g_Cols) - g_Rows; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 407 | if (g_PosMax < 0) g_PosMax = 0; |
| 408 | |
Jason Sams | cc90349 | 2010-03-12 12:46:04 -0800 | [diff] [blame] | 409 | updatePos(); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 410 | updateReadback(); |
| 411 | |
| 412 | //debugF(" draw g_PosPage", g_PosPage); |
| 413 | |
| 414 | // Draw the icons ======================================== |
Jason Sams | 6471c8b | 2010-01-20 14:15:22 -0800 | [diff] [blame] | 415 | drawFrontGrid(g_PosPage, g_Animation); |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 416 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 417 | bindProgramFragment(gPFTexNearest); |
Jason Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 418 | draw_home_button(); |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 419 | return lastFrame((g_PosVelocity != 0) || frac(g_PosPage) || g_Zoom != gZoomTarget || (g_MoveToTime != 0)); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Jason Sams | 14f67ed | 2010-05-11 14:02:43 -0700 | [diff] [blame] | 422 | |