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