Use easing within the carousel view sliding
This commit is contained in:
@@ -7,13 +7,7 @@
|
||||
class CarouselDeckView : public DeckView
|
||||
{
|
||||
private:
|
||||
enum AnimationStage{
|
||||
NONE = 0,
|
||||
SLIDE_UP,
|
||||
SLIDE_DOWN
|
||||
};
|
||||
|
||||
static const float scroll_speed;
|
||||
static const float slide_animation_duration;
|
||||
|
||||
public:
|
||||
CarouselDeckView();
|
||||
@@ -40,9 +34,8 @@ public:
|
||||
//maintains the current rotation for fluid animations
|
||||
private:
|
||||
InOutQuadEasing mScrollOffset; //[-1,1]. defines the current rotation of the cards
|
||||
float mSlide; //[-1,1]. defines, the y-offset of the cards
|
||||
InOutQuadEasing mSlide; //[-1,1]. defines, the y-offset of the cards
|
||||
int mScrollTarget; //0 <= mScrollTarget < mCards.size(). defines where to scroll to if the current animation is a scroll animation
|
||||
AnimationStage mStage; // state machine state. for animation purposes
|
||||
};
|
||||
|
||||
#endif //_CAROUSEL_DECK_VIEW_H_
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "CarouselDeckView.h"
|
||||
|
||||
const float CarouselDeckView::scroll_speed = 5.0f;
|
||||
const float CarouselDeckView::slide_animation_duration = 0.6f;
|
||||
|
||||
CarouselDeckView::CarouselDeckView() :
|
||||
DeckView(10), mScrollOffset(0), mSlide(0), mScrollTarget(2), mStage(NONE)
|
||||
DeckView(10), mScrollOffset(0), mSlide(0), mScrollTarget(2)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -35,39 +35,30 @@ void CarouselDeckView::UpdateViewState(float dt)
|
||||
dirtyCardPos = true;
|
||||
}
|
||||
|
||||
switch(mStage)
|
||||
if(!mSlide.finished())
|
||||
{
|
||||
case SLIDE_DOWN:
|
||||
mSlide -= 0.05f;
|
||||
if (mSlide < -1.0f)
|
||||
mSlide.update(dt);
|
||||
|
||||
if(mSlide.value < mSlide.start_value)
|
||||
{
|
||||
dirtyFilters = true;
|
||||
mSlide = 1;
|
||||
//going downwards
|
||||
if(mSlide.value < -1.0f)
|
||||
{
|
||||
mSlide.translate(2.0f);
|
||||
SwitchFilter(1);
|
||||
}
|
||||
}
|
||||
else if (mSlide > 0 && mSlide < 0.05)
|
||||
else if(mSlide.value > mSlide.start_value)
|
||||
{
|
||||
mStage = NONE;
|
||||
mSlide = 0;
|
||||
//upwards
|
||||
if(mSlide.value > 1.0f)
|
||||
{
|
||||
mSlide.translate(-2.0f);
|
||||
SwitchFilter(-1);
|
||||
}
|
||||
}
|
||||
|
||||
dirtyCardPos = true;
|
||||
break;
|
||||
case SLIDE_UP:
|
||||
mSlide += 0.05f;
|
||||
if (mSlide > 1.0f)
|
||||
{
|
||||
dirtyFilters = true;
|
||||
mSlide = -1;
|
||||
}
|
||||
else if (mSlide < 0 && mSlide > -0.05)
|
||||
{
|
||||
mStage = NONE;
|
||||
mSlide = 0;
|
||||
}
|
||||
dirtyCardPos = true;
|
||||
break;
|
||||
default:
|
||||
mStage = NONE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +69,7 @@ void CarouselDeckView::UpdateCardPosition(CardRep &rep, int index)
|
||||
rep.x = x_center + cos((rotation) * M_PI / 12) * (right_border - x_center);
|
||||
rep.scale = max_scale / 1.12f * cos((rep.x - x_center) * 1.5f / (right_border - x_center)) + 0.2f * max_scale * cos(
|
||||
cos((rep.x - x_center) * 0.15f / (right_border - x_center)));
|
||||
rep.y = (SCREEN_HEIGHT_F) / 2.0f + SCREEN_HEIGHT_F * mSlide * (rep.scale + 0.2f);
|
||||
rep.y = (SCREEN_HEIGHT_F) / 2.0f + SCREEN_HEIGHT_F * mSlide.value * (rep.scale + 0.2f);
|
||||
}
|
||||
|
||||
void CarouselDeckView::Reset()
|
||||
@@ -86,7 +77,6 @@ void CarouselDeckView::Reset()
|
||||
mScrollOffset = 0;
|
||||
mSlide = 0;
|
||||
mScrollTarget = 2;
|
||||
mStage = NONE;
|
||||
DeckView::Reset();
|
||||
}
|
||||
|
||||
@@ -136,16 +126,17 @@ MTGCard * CarouselDeckView::Click(int x, int y)
|
||||
last_user_activity = 0;
|
||||
|
||||
//clicked active card, and no animation is running
|
||||
if(n == 2 && mStage == NONE)
|
||||
if(mSlide.finished() && mScrollOffset.finished())
|
||||
{
|
||||
return getActiveCard();
|
||||
}
|
||||
|
||||
//clicked not the active card, start animation:s
|
||||
if(n != 2 && mStage == NONE)
|
||||
{
|
||||
DebugTrace(">>>>> " << n);
|
||||
changePosition(n - 2);
|
||||
if(n == 2)
|
||||
{
|
||||
return getActiveCard();
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugTrace(">>>>> " << n);
|
||||
changePosition(n - 2);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -161,17 +152,14 @@ void CarouselDeckView::changePosition(int offset)
|
||||
|
||||
void CarouselDeckView::changeFilter(int offset)
|
||||
{
|
||||
if(offset > 0)
|
||||
if(offset < 0)
|
||||
{
|
||||
mStage = SLIDE_UP;
|
||||
SwitchFilter(1);
|
||||
mSlide.start(-2.0f, slide_animation_duration);
|
||||
}
|
||||
else if(offset < 0)
|
||||
else if(offset > 0)
|
||||
{
|
||||
mStage = SLIDE_DOWN;
|
||||
SwitchFilter(-1);
|
||||
mSlide.start(2.0f, slide_animation_duration);
|
||||
}
|
||||
|
||||
last_user_activity = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "GridDeckView.h"
|
||||
|
||||
const float GridDeckView::scroll_animation_duration = 0.3f;
|
||||
const float GridDeckView::slide_animation_duration = 0.4f;
|
||||
const float GridDeckView::slide_animation_duration = 0.6f;
|
||||
const float GridDeckView::card_scale_small = 0.48f;
|
||||
const float GridDeckView::card_scale_big = 0.7f;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user