void GuiIconCarousel::OnTouchRelease(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { if(!controller->lastData.validPointer) return; for(size_t i = 0; i < gameIcons.size(); ++i) { if(gameIcons[i]->isStateSet(STATE_CLICKED)) { gameIcons[i]->setEffect(EFFECT_SCALE, -4, 100); gameIcons[i]->clearState(STATE_CLICKED); } } f32 degreeAdd = lastTouchDifference * 0.128f; if(touchClickDelay || fabsf(degreeAdd) < 2.0f) { updateDrawMap(); if(bWasDragging && selectedGameOnDragStart != selectedGame) { setSelectedGame(selectedGame); gameSelectionChanged(this, selectedGame); } return; } circlePosition = ((int)(circlePosition + 0.5f)) % 360; if(circlePosition < 0.0f) circlePosition += 360.0f; f32 partDegree = 360.0f / (radiusScale * gameIcons.size()); circleTargetPosition = circlePosition - 0.5f * degreeAdd * partDegree; //! round to nearest game position at the target position circleTargetPosition = ((int)(circleTargetPosition / partDegree + 0.5f)) * partDegree; circleSpeedLimit = 10.0f; int iItem = 0; f32 zMax = -9999.9f; for(u32 i = 0; i < gameIcons.size(); i++) { float currDegree = DegToRad(360.0f / (radiusScale * gameIcons.size()) * i + circleTargetPosition + 90.0f); float posZ = radiusScale * circleRadius * sinf(currDegree) + RADIUS - gameIcons.size() * (RADIUS / 12.0f); if(zMax < posZ) { iItem = i; zMax = posZ; } } selectedGame = iItem; gameSelectionChanged(this, selectedGame); }
void GuiIconCarousel::draw(CVideo *pVideo, const glm::mat4 & modelView) { if(!this->isVisible()) return; if(bUpdateMap) { bUpdateMap = false; updateDrawMap(); } if(bgNewImageDataAsync && bgNewImageDataAsync->getImageData() && !bgFadingImageDataAsync) { if(bgUsedImageDataAsync) { bgFadingImageDataAsync = bgUsedImageDataAsync; bgFadingImageDataAsync->setEffect(EFFECT_FADE, -10, 0); bgFadingImageDataAsync->effectFinished.connect(this, &GuiIconCarousel::OnBgEffectFinished); } bgUsedImageDataAsync = bgNewImageDataAsync; bgNewImageDataAsync = NULL; bgUsedImageDataAsync->setEffect(EFFECT_FADE, 5, 255); append(bgUsedImageDataAsync); } pVideo->setStencilRender(true); if(bgUsedImageDataAsync) bgUsedImageDataAsync->draw(pVideo); if(bgFadingImageDataAsync) bgFadingImageDataAsync->draw(pVideo); bgGrid.draw(pVideo, modelView); pVideo->setStencilRender(false); for(size_t i = 0; i < drawOrder.size(); ++i) { size_t idx = drawOrder[i]; gameIcons[idx]->draw(pVideo, pVideo->getProjectionMtx(), pVideo->getViewMtx(), modelView); } gameTitle.draw(pVideo); if(touchClickDelay) { touchClickDelay--; } gameLaunchTimer++; }
void GuiGameCarousel::OnTouchRelease(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { f32 degreeAdd = lastTouchDifference * 0.04f; if(touchClickDelay || fabsf(degreeAdd) < 2.0f) { updateDrawMap(); if(bWasDragging && selectedGameOnDragStart != selectedGame) { setSelectedGame(selectedGame); gameSelectionChanged(this, selectedGame); } return; } currDegree = ((int)(currDegree + 0.5f)) % 360; if(currDegree < 0.0f) currDegree += 360.0f; f32 partDegree = DEG_OFFSET; destDegree = currDegree - degreeAdd * partDegree; //! round to nearest game position at the target position destDegree = ((int)(destDegree / partDegree + 0.5f)) * partDegree; circleSpeedLimit = 10.0f; int iMin = 0; int iDegreeMin = destDegree; for(int i = 0; i < pagesize; i++) { f32 setDegree = (destDegree - DEG_OFFSET * i); int degree = labs(((int)setDegree - 90) % 360); if(degree < iDegreeMin) { iDegreeMin = degree; iMin = i; } } selectedGame = iMin; gameSelectionChanged(this, selectedGame); loadBgImage(selectedGame); refreshDrawMap = true; }
/** * Draw the button on screen */ void GuiGameCarousel::draw(CVideo *v) { if(bgNewImageDataAsync && bgNewImageDataAsync->getImageData() && !bgFadingImageDataAsync) { if(bgUsedImageDataAsync) { bgFadingImageDataAsync = bgUsedImageDataAsync; bgFadingImageDataAsync->setEffect(EFFECT_FADE, -10, 0); bgFadingImageDataAsync->effectFinished.connect(this, &GuiGameCarousel::OnBgEffectFinished); } bgUsedImageDataAsync = bgNewImageDataAsync; bgNewImageDataAsync = NULL; bgUsedImageDataAsync->setColorIntensity(glm::vec4(0.5f, 0.5f, 0.5f, 1.0f)); bgUsedImageDataAsync->setParent(this); bgUsedImageDataAsync->setEffect(EFFECT_FADE, 5, 255); insert(bgUsedImageDataAsync, 0); } if((currDegree - 0.5f) > destDegree) { if(startRotationDistance == 0.0f) startRotationDistance = fabsf(destDegree - currDegree); currDegree -= circleRotationSpeed; f32 angleDistance = fabsf(destDegree - currDegree); circleRotationSpeed = 8.0f * angleDistance / startRotationDistance; if(circleRotationSpeed > circleSpeedLimit) circleRotationSpeed = circleSpeedLimit; if(angleDistance < circleRotationSpeed) currDegree = destDegree; refreshDrawMap = true; } else if((currDegree + 0.5f) < destDegree) { if(startRotationDistance == 0.0f) startRotationDistance = fabsf(destDegree - currDegree); currDegree += circleRotationSpeed; f32 angleDistance = fabsf(destDegree - currDegree); circleRotationSpeed = 8.0f * angleDistance / startRotationDistance; if(circleRotationSpeed > circleSpeedLimit) circleRotationSpeed = circleSpeedLimit; if(angleDistance < circleRotationSpeed) currDegree = destDegree; refreshDrawMap = true; } else { startRotationDistance = 0.0f; } if(refreshDrawMap) { refreshDrawMap = false; updateDrawMap(); } GuiGameBrowser::draw(v); for(u32 i = 0; i < drawOrder.size(); i++) { int idx = drawOrder[i]; game[idx]->draw(v); } }