Put easing code into Easing.h. Add easing to sliding
This commit is contained in:
@@ -2,83 +2,11 @@
|
|||||||
#define _GRID_DECK_VIEW_H
|
#define _GRID_DECK_VIEW_H
|
||||||
|
|
||||||
#include "DeckView.h"
|
#include "DeckView.h"
|
||||||
|
#include "Easing.h"
|
||||||
class Easing
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
float start_value;
|
|
||||||
float delta_value;
|
|
||||||
float value;
|
|
||||||
float duration;
|
|
||||||
float time_acc;
|
|
||||||
|
|
||||||
|
|
||||||
Easing(float val): start_value(val), delta_value(0), value(val), duration(0), time_acc(0)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void reset(){ value = start_value; time_acc = 0;}
|
|
||||||
void finish(){ value = start_value + delta_value; time_acc = 0; duration = 0;}
|
|
||||||
virtual void update(float dt) = 0;
|
|
||||||
|
|
||||||
void start(float targetValue, float _duration){
|
|
||||||
start_value = value;
|
|
||||||
delta_value = targetValue - start_value;
|
|
||||||
time_acc = 0;
|
|
||||||
duration = _duration;
|
|
||||||
}
|
|
||||||
|
|
||||||
void transpose(float delta_value){
|
|
||||||
start_value += delta_value;
|
|
||||||
value += delta_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool finished()
|
|
||||||
{
|
|
||||||
return time_acc >= duration;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class InOutQuadEasing : public Easing
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
InOutQuadEasing(float val): Easing(val) {}
|
|
||||||
|
|
||||||
void update(float dt){
|
|
||||||
if(duration > 0){
|
|
||||||
time_acc += dt;
|
|
||||||
|
|
||||||
if(time_acc > duration)
|
|
||||||
{
|
|
||||||
time_acc = duration;
|
|
||||||
value = start_value + delta_value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
float time_tmp = time_acc * 2 / duration;
|
|
||||||
if (time_tmp < 1)
|
|
||||||
{
|
|
||||||
value = delta_value/2*time_tmp*time_tmp + start_value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
time_tmp -= 1;
|
|
||||||
value = -delta_value/2 * (time_tmp*(time_tmp-2) - 1) + start_value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class GridDeckView : public DeckView
|
class GridDeckView : public DeckView
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
enum AnimationStage{
|
|
||||||
NONE = 0,
|
|
||||||
SLIDE_UP,
|
|
||||||
SLIDE_DOWN//,
|
|
||||||
//SCROLL_TO_SELECTED
|
|
||||||
};
|
|
||||||
|
|
||||||
static const float scroll_speed;
|
static const float scroll_speed;
|
||||||
static const float card_scale_small;
|
static const float card_scale_small;
|
||||||
static const float card_scale_big;
|
static const float card_scale_big;
|
||||||
@@ -97,11 +25,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
int mCols;
|
int mCols;
|
||||||
int mRows;
|
int mRows;
|
||||||
float mSlide; //[-1,1]. defines, the y-offset of the cards
|
InOutQuadEasing mSlide; //[-1,1]. defines the y-offset of the cards
|
||||||
InOutQuadEasing mScrollOffset;
|
InOutQuadEasing mScrollOffset; //[-1,1]. defines the x-offset of the cards
|
||||||
int mCurrentSelection; //0 <= mCurrentSelection < mCards.size(). defines the current selected and thus upscaled card
|
int mCurrentSelection; //0 <= mCurrentSelection < mCards.size(). defines the current selected and thus upscaled card
|
||||||
//int mColsToScroll; //the number of cols we need to scroll
|
|
||||||
AnimationStage mStage; // state machine state. for animation purposes
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //_GRID_DECK_VIEW_H
|
#endif //_GRID_DECK_VIEW_H
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ void DeckView::SwitchFilter(int delta)
|
|||||||
{
|
{
|
||||||
unsigned int FilterCount = Constants::NB_Colors + 1;
|
unsigned int FilterCount = Constants::NB_Colors + 1;
|
||||||
mFilter = (FilterCount + mFilter + delta) % FilterCount;
|
mFilter = (FilterCount + mFilter + delta) % FilterCount;
|
||||||
|
dirtyFilters = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DeckView::filter(){
|
int DeckView::filter(){
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const float GridDeckView::card_scale_small = 0.48f;
|
|||||||
const float GridDeckView::card_scale_big = 0.7f;
|
const float GridDeckView::card_scale_big = 0.7f;
|
||||||
|
|
||||||
GridDeckView::GridDeckView()
|
GridDeckView::GridDeckView()
|
||||||
: DeckView(16), mCols(8), mRows(2), mSlide(0), mScrollOffset(0), mCurrentSelection(-1)/*, mColsToScroll(0)*/, mStage(NONE)
|
: DeckView(16), mCols(8), mRows(2), mSlide(0), mScrollOffset(0), mCurrentSelection(-1)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -17,11 +17,10 @@ GridDeckView::~GridDeckView()
|
|||||||
|
|
||||||
void GridDeckView::Reset()
|
void GridDeckView::Reset()
|
||||||
{
|
{
|
||||||
mSlide = 0;
|
mSlide.finish();
|
||||||
mScrollOffset = 0;
|
mScrollOffset.finish();
|
||||||
|
|
||||||
mCurrentSelection = 0;
|
mCurrentSelection = 0;
|
||||||
//mColsToScroll = 0;
|
|
||||||
mStage = NONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridDeckView::UpdateViewState(float dt)
|
void GridDeckView::UpdateViewState(float dt)
|
||||||
@@ -51,39 +50,25 @@ void GridDeckView::UpdateViewState(float dt)
|
|||||||
dirtyCardPos = true;
|
dirtyCardPos = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(mStage)
|
if(!mSlide.finished())
|
||||||
{
|
{
|
||||||
case SLIDE_DOWN:
|
mSlide.update(dt);
|
||||||
mSlide -= 0.05f;
|
|
||||||
if (mSlide < -1.0f)
|
if(mSlide.value < mSlide.start_value){
|
||||||
{
|
//going downwards
|
||||||
dirtyFilters = true;
|
if(mSlide.value < -1.0f){
|
||||||
mSlide = 1;
|
mSlide.translate(2.0f);
|
||||||
}
|
SwitchFilter(1);
|
||||||
else if (mSlide > 0 && mSlide < 0.05)
|
}
|
||||||
{
|
} else if(mSlide.value > mSlide.start_value){
|
||||||
mStage = NONE;
|
//upwards
|
||||||
mSlide = 0;
|
if(mSlide.value > 1.0f){
|
||||||
|
mSlide.translate(-2.0f);
|
||||||
|
SwitchFilter(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dirtyCardPos = true;
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +80,7 @@ void GridDeckView::UpdateCardPosition(CardRep &rep, int index)
|
|||||||
float rowHeight = SCREEN_HEIGHT_F / mRows;
|
float rowHeight = SCREEN_HEIGHT_F / mRows;
|
||||||
|
|
||||||
rep.x = (col + mScrollOffset.value) * colWidth - colWidth;
|
rep.x = (col + mScrollOffset.value) * colWidth - colWidth;
|
||||||
rep.y = row * rowHeight + mSlide*SCREEN_HEIGHT + rowHeight/2;
|
rep.y = row * rowHeight + mSlide.value*SCREEN_HEIGHT + rowHeight/2;
|
||||||
|
|
||||||
if(mCurrentSelection == index)
|
if(mCurrentSelection == index)
|
||||||
{
|
{
|
||||||
@@ -130,26 +115,27 @@ void GridDeckView::Render()
|
|||||||
MTGCard * GridDeckView::Click(int x, int y)
|
MTGCard * GridDeckView::Click(int x, int y)
|
||||||
{
|
{
|
||||||
int n = getCardIndexNextTo(x, y);
|
int n = getCardIndexNextTo(x, y);
|
||||||
DebugTrace("Clicked: " << n);
|
|
||||||
last_user_activity = 0;
|
last_user_activity = 0;
|
||||||
|
|
||||||
//clicked active card, and no animation is running
|
if(mScrollOffset.finished() && mSlide.finished())
|
||||||
if(n == mCurrentSelection && mStage == NONE)
|
{ //clicked and no animations running
|
||||||
{
|
if(n == mCurrentSelection)
|
||||||
return getActiveCard();
|
{
|
||||||
}
|
return getActiveCard();
|
||||||
else if(n < 4 && mStage == NONE)
|
}
|
||||||
{
|
else if(n < 4)
|
||||||
mScrollOffset.start(1.0f, 0.3f);
|
{
|
||||||
}
|
mScrollOffset.start(1.0f, 0.3f);
|
||||||
else if(n >= 12 && mStage == NONE)
|
}
|
||||||
{
|
else if(n >= 12)
|
||||||
mScrollOffset.start(-1.0f, 0.3f);
|
{
|
||||||
}
|
mScrollOffset.start(-1.0f, 0.3f);
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
mCurrentSelection = n;
|
{
|
||||||
dirtyCardPos = true;
|
mCurrentSelection = n;
|
||||||
|
dirtyCardPos = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -159,22 +145,20 @@ bool GridDeckView::Button(Buttons button)
|
|||||||
{
|
{
|
||||||
switch(button)
|
switch(button)
|
||||||
{
|
{
|
||||||
case JGE_BTN_LEFT:
|
case JGE_BTN_RIGHT:
|
||||||
mScrollOffset.start(-1.0f, 0.3f);
|
mScrollOffset.start(-1.0f, 0.3f);
|
||||||
last_user_activity = 0;
|
last_user_activity = 0;
|
||||||
break;
|
break;
|
||||||
case JGE_BTN_RIGHT:
|
case JGE_BTN_LEFT:
|
||||||
mScrollOffset.start( 1.0f, 0.3f);
|
mScrollOffset.start( 1.0f, 0.3f);
|
||||||
last_user_activity = 0;
|
last_user_activity = 0;
|
||||||
break;
|
break;
|
||||||
case JGE_BTN_UP:
|
case JGE_BTN_UP:
|
||||||
mStage = SLIDE_UP;
|
mSlide.start(2.0f, 0.3f);
|
||||||
SwitchFilter(1);
|
|
||||||
last_user_activity = 0;
|
last_user_activity = 0;
|
||||||
break;
|
break;
|
||||||
case JGE_BTN_DOWN:
|
case JGE_BTN_DOWN:
|
||||||
mStage = SLIDE_DOWN;
|
mSlide.start(-2.0f, 0.3f);
|
||||||
SwitchFilter(-1);
|
|
||||||
last_user_activity = 0;
|
last_user_activity = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -271,7 +271,8 @@ HEADERS += \
|
|||||||
include/AIHints.h\
|
include/AIHints.h\
|
||||||
include/DeckView.h\
|
include/DeckView.h\
|
||||||
include/CarouselDeckView.h\
|
include/CarouselDeckView.h\
|
||||||
include/GridDeckView.h
|
include/GridDeckView.h\
|
||||||
|
include/Easing.h
|
||||||
|
|
||||||
# JGE, could probably be moved outside
|
# JGE, could probably be moved outside
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
|||||||
@@ -307,7 +307,8 @@ HEADERS += \
|
|||||||
include/ObjectAnalytics.h\
|
include/ObjectAnalytics.h\
|
||||||
include/DeckView.h\
|
include/DeckView.h\
|
||||||
include/CarouselDeckView.h\
|
include/CarouselDeckView.h\
|
||||||
include/GridDeckView.h
|
include/GridDeckView.h\
|
||||||
|
include/Easing.h
|
||||||
|
|
||||||
# JGE, could probably be moved outside
|
# JGE, could probably be moved outside
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
|||||||
Reference in New Issue
Block a user