void GuiGameCarousel::OnTouchClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger)
{
    bWasDragging = false;
    selectedGameOnDragStart = getSelectedGame();
    lastPosition.x = controller->vpad.tpdata.x;
    lastPosition.y = controller->vpad.tpdata.y;
}
void GuiGameCarousel::OnRightClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger)
{
    int sel = getSelectedGame() + 1;
    if(sel >= (int)GameList::instance()->size())
        sel = 0;

    setSelectedGame(sel);
    gameSelectionChanged(this, sel);
}
void GuiGameCarousel::OnLeftClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger)
{
    int sel = getSelectedGame() - 1;
    if(sel < 0 && (GameList::instance()->size() > 1))
        sel = GameList::instance()->size() - 1;

    setSelectedGame(sel);
    gameSelectionChanged(this, sel);
}
void GuiIconCarousel::OnRightSkipClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger)
{
	if((int)GameList::instance()->size() > 5){
		int sel = getSelectedGame() - 5;
		if(sel < 0 && (GameList::instance()->size() > 5))
			sel += GameList::instance()->size();

		setSelectedGame(sel);
		gameSelectionChanged(this, sel);
	}
}
void GuiIconCarousel::OnTouchClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger)
{
    if(!controller->data.validPointer)
        return;

    bWasDragging = false;
    selectedGameOnDragStart = getSelectedGame();
    lastPosition.x = controller->data.x;
    lastPosition.y = controller->data.y;

    //! calculate ray origin and direction
    glm::vec3 rayOrigin;
    glm::vec3 rayDir;

    CVideo *video = Application::instance()->getVideo();
    video->screenPosToWorldRay(controller->data.x, controller->data.y, rayOrigin, rayDir);

    glm::vec3 rayDirFrac((rayDir.x != 0.0f) ? (1.0f / rayDir.x) : 0.0f, (rayDir.y != 0.0f) ? (1.0f / rayDir.y) : 0.0f, (rayDir.z != 0.0f) ? (1.0f / rayDir.z) : 0.0f);

    for(u32 i = 0; i < drawOrder.size(); ++i)
    {
        int idx = drawOrder[i];

        if(gameIcons[idx]->checkRayIntersection(rayOrigin, rayDirFrac))
        {
            if(buttonClickSound)
                buttonClickSound->Play();

            setSelectedGame(idx);
            gameSelectionChanged(this, idx);

            //! TODO: change this to a button assigned image
            gameIcons[idx]->setState(STATE_CLICKED);
            gameIcons[idx]->setEffect(EFFECT_SCALE, 4, 125);

            if(selectedGame == idx)
            {
                if(gameLaunchTimer < 30)
                    OnLaunchClick(button, controller, trigger);

                gameLaunchTimer = 0;
            }
        }
    }
}