Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 1 | #pragma version(1) |
| 2 | #pragma stateVertex(PV) |
| 3 | #pragma stateFragment(PF) |
| 4 | #pragma stateFragmentStore(PFS) |
| 5 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 6 | #define PI 3.14159f |
| 7 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 8 | float deceleration; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 9 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 10 | // Drawing constants, should be parameters ====== |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 11 | #define VIEW_ANGLE 1.28700222f |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 12 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 13 | void init() { |
| 14 | deceleration = 0; |
| 15 | } |
| 16 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 17 | int g_lastFrameTime = 0; |
| 18 | void print_frame_rate() |
| 19 | { |
| 20 | int now = uptimeMillis(); |
| 21 | if (g_lastFrameTime != 0) { |
| 22 | debugI32("frame_rate", 1000/(now-g_lastFrameTime)); |
| 23 | } |
| 24 | g_lastFrameTime = now; |
| 25 | } |
| 26 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 27 | int |
| 28 | count_pages(int iconCount) |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 29 | { |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 30 | int iconsPerPage = COLUMNS_PER_PAGE * ROWS_PER_PAGE; |
| 31 | int pages = iconCount / iconsPerPage; |
| 32 | if (pages*iconsPerPage != iconCount) { |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 33 | pages++; |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 34 | } |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 35 | return pages; |
| 36 | } |
| 37 | |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 38 | float |
| 39 | modf(float x, float y) |
| 40 | { |
| 41 | return x-(y*floorf(x/y)); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Joe Onorato | 0d1c563 | 2009-08-28 15:57:18 -0700 | [diff] [blame] | 44 | float |
| 45 | far_size(float sizeAt0) |
| 46 | { |
| 47 | return sizeAt0 * (RADIUS+2) / 2; // -2 is the camera z=(z-camZ)/z |
| 48 | } |
| 49 | |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 50 | void |
| 51 | draw_page(int icon, int lastIcon, float centerAngle) |
| 52 | { |
| 53 | int row; |
| 54 | int col; |
| 55 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 56 | float scale = 1.0f - state->zoom; |
Joe Onorato | 85a02a8 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 57 | |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 58 | float iconTextureWidth = ICON_WIDTH_PX / (float)ICON_TEXTURE_WIDTH_PX; |
| 59 | float iconTextureHeight = ICON_HEIGHT_PX / (float)ICON_TEXTURE_HEIGHT_PX; |
| 60 | |
| 61 | float iconWidthAngle = VIEW_ANGLE * ICON_WIDTH_PX / SCREEN_WIDTH_PX; |
Joe Onorato | 0d1c563 | 2009-08-28 15:57:18 -0700 | [diff] [blame] | 62 | float columnGutterAngle = iconWidthAngle * 0.70f; |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 63 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 64 | float farIconSize = FAR_ICON_SIZE; |
Joe Onorato | 0d1c563 | 2009-08-28 15:57:18 -0700 | [diff] [blame] | 65 | float iconGutterHeight = farIconSize * 1.1f; |
| 66 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 67 | float farIconTextureSize = far_size(2 * ICON_TEXTURE_WIDTH_PX / (float)SCREEN_WIDTH_PX); |
| 68 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 69 | float normalizedLabelWidth = 2 * params->bubbleWidth / (float)SCREEN_WIDTH_PX; |
Joe Onorato | 0d1c563 | 2009-08-28 15:57:18 -0700 | [diff] [blame] | 70 | float farLabelWidth = far_size(normalizedLabelWidth); |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 71 | float farLabelHeight = far_size(params->bubbleHeight * (normalizedLabelWidth / params->bubbleWidth)); |
| 72 | float labelTextureWidth = (float)params->bubbleWidth / params->bubbleBitmapWidth; |
| 73 | float labelTextureHeight = (float)params->bubbleHeight / params->bubbleBitmapHeight; |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 74 | |
| 75 | for (row=0; row<ROWS_PER_PAGE && icon<=lastIcon; row++) { |
| 76 | float angle = centerAngle; |
| 77 | angle -= (columnGutterAngle + iconWidthAngle) * 1.5f; |
| 78 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 79 | float iconTop = (farIconSize + iconGutterHeight) * (2.0f + ICON_TOP_OFFSET) |
Joe Onorato | 0d1c563 | 2009-08-28 15:57:18 -0700 | [diff] [blame] | 80 | - row * (farIconSize + iconGutterHeight); |
Joe Onorato | d40eec3 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 81 | iconTop -= 6 * scale; // make the zoom point below center |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 82 | float iconBottom = iconTop - farIconSize; |
| 83 | |
Joe Onorato | 0d1c563 | 2009-08-28 15:57:18 -0700 | [diff] [blame] | 84 | float labelTop = iconBottom - (.1 * farLabelHeight); |
| 85 | float labelBottom = labelTop - farLabelHeight; |
| 86 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 87 | float iconTextureTop = iconTop + (0.5f * (farIconTextureSize - farIconSize)); |
| 88 | float iconTextureBottom = iconTextureTop - farIconTextureSize; |
| 89 | |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 90 | for (col=0; col<COLUMNS_PER_PAGE && icon<=lastIcon; col++) { |
| 91 | // icon |
| 92 | float sine = sinf(angle); |
| 93 | float cosine = cosf(angle); |
| 94 | |
Joe Onorato | 0d1c563 | 2009-08-28 15:57:18 -0700 | [diff] [blame] | 95 | float centerX = sine * RADIUS; |
| 96 | float centerZ = cosine * RADIUS; |
Joe Onorato | d40eec3 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 97 | centerZ -= ((RADIUS+2+1)*scale); // 2 is camera loc, 1 put it slightly behind that. |
Joe Onorato | 0d1c563 | 2009-08-28 15:57:18 -0700 | [diff] [blame] | 98 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 99 | float iconLeftX = centerX - (cosine * farIconTextureSize * .5); |
| 100 | float iconRightX = centerX + (cosine * farIconTextureSize * .5); |
| 101 | float iconLeftZ = centerZ + (sine * farIconTextureSize * .5); |
| 102 | float iconRightZ = centerZ - (sine * farIconTextureSize * .5); |
| 103 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 104 | if (state->selectedIconIndex == icon) { |
| 105 | bindTexture(NAMED_PF, 0, state->selectedIconTexture); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 106 | drawQuadTexCoords( |
| 107 | iconLeftX, iconTextureTop, iconLeftZ, 0.0f, 0.0f, |
| 108 | iconRightX, iconTextureTop, iconRightZ, 1.0f, 0.0f, |
| 109 | iconRightX, iconTextureBottom, iconRightZ, 1.0f, 1.0f, |
| 110 | iconLeftX, iconTextureBottom, iconLeftZ, 0.0f, 1.0f); |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 111 | } else { |
| 112 | bindTexture(NAMED_PF, 0, loadI32(ALLOC_ICON_IDS, icon)); |
| 113 | drawQuadTexCoords( |
| 114 | iconLeftX, iconTextureTop, iconLeftZ, 0.0f, 0.0f, |
| 115 | iconRightX, iconTextureTop, iconRightZ, 1.0f, 0.0f, |
| 116 | iconRightX, iconTextureBottom, iconRightZ, 1.0f, 1.0f, |
| 117 | iconLeftX, iconTextureBottom, iconLeftZ, 0.0f, 1.0f); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 118 | } |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 119 | |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 120 | // label |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 121 | if (scale <= 0.1f) { |
Joe Onorato | 85a02a8 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 122 | float labelLeftX = centerX - farLabelWidth * 0.5f; |
| 123 | float labelRightX = centerX + farLabelWidth * 0.5f; |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 124 | |
Joe Onorato | 85a02a8 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 125 | bindTexture(NAMED_PF, 0, loadI32(ALLOC_LABEL_IDS, icon)); |
| 126 | drawQuadTexCoords( |
| 127 | labelLeftX, labelTop, centerZ, 0.0f, 0.0f, |
| 128 | labelRightX, labelTop, centerZ, labelTextureWidth, 0.0f, |
| 129 | labelRightX, labelBottom, centerZ, labelTextureWidth, labelTextureHeight, |
| 130 | labelLeftX, labelBottom, centerZ, 0.0f, labelTextureHeight); |
| 131 | } |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 132 | |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 133 | angle += columnGutterAngle + iconWidthAngle; |
| 134 | icon++; |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 139 | int |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 140 | main(int launchID) |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 141 | { |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 142 | // Clear to transparent |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 143 | pfClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 144 | |
Joe Onorato | 006b25f | 2009-09-03 11:38:43 -0700 | [diff] [blame] | 145 | // If we're not supposed to be showing, don't do anything. |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 146 | if (!state->visible) { |
Joe Onorato | 006b25f | 2009-09-03 11:38:43 -0700 | [diff] [blame] | 147 | return 0; |
| 148 | } |
| 149 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 150 | // icons & labels |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 151 | int iconCount = state->iconCount; |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 152 | int pageCount = count_pages(iconCount); |
| 153 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 154 | float scrollXPx = state->scrollX; |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 155 | float maxScrollXPx = -(pageCount-1) * SCREEN_WIDTH_PX; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 156 | int done = 0; |
| 157 | |
Joe Onorato | eb2c02e | 2009-08-12 21:40:52 -0700 | [diff] [blame] | 158 | // Clamp -- because java doesn't know how big the icons are |
| 159 | if (scrollXPx > 0) { |
| 160 | scrollXPx = 0; |
| 161 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 162 | if (scrollXPx < maxScrollXPx) { |
| 163 | scrollXPx = maxScrollXPx; |
Joe Onorato | eb2c02e | 2009-08-12 21:40:52 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 166 | // If we've been given a velocity, start a fling |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 167 | float flingVelocityPxMs = state->flingVelocityX; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 168 | if (flingVelocityPxMs != 0) { |
| 169 | // how many screens will this velocity do? TODO: use long |
| 170 | // G * ppi * friction // why G? // friction = 0.015 |
Joe Onorato | eb2c02e | 2009-08-12 21:40:52 -0700 | [diff] [blame] | 171 | float flingDurationMs; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 172 | if (deceleration == 0) { |
| 173 | // On the first frame, calculate which animation we're going to do. If it's |
| 174 | // going to end up less than halfway into a page, we'll bounce back the previous |
| 175 | // page. Otherwise, we'll adjust the deceleration so it just makes it to the |
| 176 | // page boundary. |
| 177 | if (flingVelocityPxMs > 0) { |
| 178 | deceleration = -1000; |
| 179 | } else { |
| 180 | deceleration = 1000; |
| 181 | } |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 182 | // minimum velocity |
| 183 | if (flingVelocityPxMs < 0) { |
| 184 | if (flingVelocityPxMs > -500) { |
| 185 | flingVelocityPxMs = -500; |
| 186 | } |
| 187 | } else { |
| 188 | if (flingVelocityPxMs < 500) { |
| 189 | flingVelocityPxMs = 500; |
| 190 | } |
| 191 | } |
| 192 | |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 193 | // v' = v + at --> t = -v / a |
Joe Onorato | eb2c02e | 2009-08-12 21:40:52 -0700 | [diff] [blame] | 194 | // x' = x + vt + .5 a t^2 |
| 195 | flingDurationMs = - flingVelocityPxMs / deceleration; |
| 196 | float endPos = scrollXPx + (flingVelocityPxMs*flingDurationMs) |
| 197 | + ((deceleration*flingDurationMs*flingDurationMs)/2); |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 198 | |
| 199 | if (endPos > 0) { |
| 200 | endPos = 0; |
| 201 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 202 | if (endPos < maxScrollXPx) { |
| 203 | endPos = maxScrollXPx; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 204 | } |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 205 | float scrollOnPage = modf(endPos, SCREEN_WIDTH_PX); |
| 206 | int endPage = -endPos/SCREEN_WIDTH_PX; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 207 | |
Joe Onorato | eb2c02e | 2009-08-12 21:40:52 -0700 | [diff] [blame] | 208 | if (flingVelocityPxMs < 0) { |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 209 | if (scrollOnPage < (SCREEN_WIDTH_PX/2)) { |
Joe Onorato | eb2c02e | 2009-08-12 21:40:52 -0700 | [diff] [blame] | 210 | // adjust the deceleration so we align on the page boundary |
| 211 | // a = 2(x-x0-v0t)/t^2 |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 212 | endPos = -(endPage+1) * SCREEN_WIDTH_PX; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 213 | debugI32("endPos case 1", endPos); |
Joe Onorato | eb2c02e | 2009-08-12 21:40:52 -0700 | [diff] [blame] | 214 | } else { |
| 215 | // TODO: bounce |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 216 | endPos = -(endPage+1) * SCREEN_WIDTH_PX; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 217 | debugI32("endPos case 2", endPos); |
Joe Onorato | eb2c02e | 2009-08-12 21:40:52 -0700 | [diff] [blame] | 218 | } |
| 219 | } else { |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 220 | if (scrollOnPage >= (SCREEN_WIDTH_PX/2)) { |
Joe Onorato | eb2c02e | 2009-08-12 21:40:52 -0700 | [diff] [blame] | 221 | // adjust the deceleration so we align on the page boundary |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 222 | endPos = -endPage * SCREEN_WIDTH_PX; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 223 | debugI32("endPos case 3", endPos); |
Joe Onorato | eb2c02e | 2009-08-12 21:40:52 -0700 | [diff] [blame] | 224 | } else { |
| 225 | // TODO: bounce |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 226 | endPos = -endPage * SCREEN_WIDTH_PX; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 227 | debugI32("endPos case 4", endPos); |
Joe Onorato | eb2c02e | 2009-08-12 21:40:52 -0700 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | // v = v0 + at --> (v - v0) / t |
| 231 | deceleration = 2*(endPos-scrollXPx-(flingVelocityPxMs*flingDurationMs)) |
| 232 | / (flingDurationMs*flingDurationMs); |
| 233 | endPos = scrollXPx + (flingVelocityPxMs*flingDurationMs) |
| 234 | + ((deceleration*flingDurationMs*flingDurationMs)/2); |
| 235 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 236 | state->flingDuration = flingDurationMs; |
| 237 | state->flingEndPos = endPos; |
Joe Onorato | eb2c02e | 2009-08-12 21:40:52 -0700 | [diff] [blame] | 238 | } else { |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 239 | flingDurationMs = state->flingDuration; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | // adjust the deceleration so we always hit a page boundary |
| 243 | |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 244 | int now = uptimeMillis(); |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 245 | float elapsedTime = (now - state->flingTimeMs) / 1000.0f; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 246 | int animEndTime = -flingVelocityPxMs / deceleration; |
| 247 | |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 248 | int flingOffsetPx = (flingVelocityPxMs * elapsedTime) |
| 249 | + (deceleration * elapsedTime * elapsedTime / 2.0f); |
| 250 | scrollXPx += flingOffsetPx; |
| 251 | |
Joe Onorato | eb2c02e | 2009-08-12 21:40:52 -0700 | [diff] [blame] | 252 | if (elapsedTime > flingDurationMs) { |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 253 | scrollXPx = state->flingEndPos; |
Joe Onorato | eb2c02e | 2009-08-12 21:40:52 -0700 | [diff] [blame] | 254 | done = 1; |
| 255 | } |
Joe Onorato | 85a02a8 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 256 | } else { |
| 257 | done = 1; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Joe Onorato | eb2c02e | 2009-08-12 21:40:52 -0700 | [diff] [blame] | 260 | // Clamp |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 261 | if (scrollXPx > 0) { |
| 262 | scrollXPx = 0; |
| 263 | } |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 264 | if (scrollXPx < maxScrollXPx) { |
| 265 | scrollXPx = maxScrollXPx; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 266 | } |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 267 | |
| 268 | state->currentScrollX = scrollXPx; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 269 | if (done) { |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 270 | state->scrollX = scrollXPx; |
| 271 | state->flingVelocityX = 0; |
| 272 | deceleration = 0.f; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 273 | } |
| 274 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 275 | // Draw the icons ======================================== |
| 276 | bindProgramVertex(NAMED_PV); |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 277 | bindProgramFragment(NAMED_PF); |
| 278 | bindProgramFragmentStore(NAMED_PFS); |
| 279 | |
| 280 | // Bug makes 1.0f alpha fail. |
| 281 | color(1.0f, 1.0f, 1.0f, 0.99f); |
| 282 | |
| 283 | int lastIcon = iconCount-1; |
| 284 | |
| 285 | float currentPage = -scrollXPx / (float)SCREEN_WIDTH_PX; |
| 286 | int page = currentPage; |
| 287 | float currentPagePosition = currentPage - page; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 288 | |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 289 | int iconsPerPage = COLUMNS_PER_PAGE * ROWS_PER_PAGE; |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 290 | int icon = clamp(iconsPerPage * page, 0, lastIcon); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 291 | |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 292 | draw_page(icon, lastIcon, -VIEW_ANGLE*currentPagePosition); |
| 293 | draw_page(icon+iconsPerPage, lastIcon, (-VIEW_ANGLE*currentPagePosition)+VIEW_ANGLE); |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 294 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 295 | // Draw the border lines for debugging ======================================== |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 296 | /* |
| 297 | bindProgramVertex(NAMED_PVOrtho); |
| 298 | bindProgramFragment(NAMED_PFText); |
| 299 | bindProgramFragmentStore(NAMED_PFSText); |
| 300 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 301 | color(1.0f, 1.0f, 0.0f, 0.99f); |
| 302 | int i; |
| 303 | for (i=0; i<ROWS_PER_PAGE+1; i++) { |
| 304 | int y = loadI32(ALLOC_Y_BORDERS, i); |
| 305 | drawRect(0, y, SCREEN_WIDTH_PX, y+1, 0.0f); |
| 306 | } |
| 307 | for (i=0; i<COLUMNS_PER_PAGE+1; i++) { |
| 308 | int x = loadI32(ALLOC_X_BORDERS, i); |
| 309 | drawRect(x, 0, x+1, SCREEN_HEIGHT_PX, 0.0f); |
| 310 | } |
| 311 | */ |
| 312 | |
| 313 | // Draw the scroll handle ======================================== |
| 314 | /* |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 315 | bindTexture(NAMED_PFText, 0, loadI32(ALLOC_PARAMS, PARAM_SCROLL_HANDLE_ID)); |
| 316 | float handleLeft = 40 + (320 * (scrollXPx/(float)(maxScrollXPx))); |
| 317 | float handleTop = 680; |
| 318 | float handleWidth = loadI32(ALLOC_PARAMS, PARAM_SCROLL_HANDLE_TEX_WIDTH); |
| 319 | float handleHeight = loadI32(ALLOC_PARAMS, PARAM_SCROLL_HANDLE_TEX_HEIGHT); |
| 320 | drawRect(handleLeft, handleTop, handleLeft+handleWidth, handleTop+handleHeight, 0.0f); |
| 321 | */ |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 322 | |
Joe Onorato | fb0ca67 | 2009-09-14 17:55:46 -0400 | [diff] [blame] | 323 | print_frame_rate(); |
| 324 | |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 325 | return !done; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 326 | } |
| 327 | |