Add support for MoveTo.

This commit is contained in:
Jason Sams
2009-10-19 14:45:45 -07:00
parent 37e7c2b6e4
commit c1c521edf4
2 changed files with 43 additions and 0 deletions
+33
View File
@@ -22,6 +22,10 @@ float g_Zoom;
float g_OldPosPage;
float g_OldPosVelocity;
float g_OldZoom;
float g_MoveToTotalTime;
float g_MoveToTime;
float g_MoveToOldPos;
// Drawing constants, should be parameters ======
#define VIEW_ANGLE 1.28700222f
@@ -79,6 +83,9 @@ void init() {
g_LastPositionX = 0;
g_Zoom = 0;
g_SpecialHWWar = 1;
g_MoveToTime = 0;
g_MoveToOldPos = 0;
g_MoveToTotalTime = 0.5f;
}
void resetHWWar() {
@@ -97,9 +104,16 @@ void move() {
}
g_LastTouchDown = state->newTouchDown;
g_LastPositionX = state->newPositionX;
g_MoveToTime = 0;
//debugF("Move P", g_PosPage);
}
void moveTo() {
g_MoveToTime = g_MoveToTotalTime;
g_PosVelocity = 0;
g_MoveToOldPos = g_PosPage;
}
void fling() {
g_LastTouchDown = 0;
g_PosVelocity = -state->flingVelocity * 4;
@@ -145,6 +159,25 @@ void updatePos() {
tablePosFrac) * g_DT;
float friction = 4.f * g_DT;
if (g_MoveToTime) {
float a = 2.f * (state->targetPos - g_MoveToOldPos) /
(g_MoveToTotalTime * g_MoveToTotalTime);
if (g_MoveToTime > (g_MoveToTotalTime * 0.5f)) {
// slowing
g_PosPage = state->targetPos - 0.5f * a * (g_MoveToTime * g_MoveToTime);
} else {
// accelerating.
float t = g_MoveToTotalTime - g_MoveToTime;
g_PosPage = g_MoveToOldPos + 0.5f * a * (t * t);
}
g_MoveToTime -= g_DT;
if (g_MoveToTime <= 0) {
g_MoveToTime = 0;
g_PosPage = state->targetPos;
}
return;
}
if (g_PosPage < -0.5f) {
accel = g_AttractionTable[0] * g_DT;
outOfRange = 1;
@@ -482,9 +482,11 @@ public class AllAppsView extends RSSurfaceView
private Resources mRes;
private Script mScript;
private Script.Invokable mInvokeMove;
private Script.Invokable mInvokeMoveTo;
private Script.Invokable mInvokeFling;
private Script.Invokable mInvokeResetWAR;
private ProgramStore mPSIcons;
private ProgramStore mPSText;
private ProgramFragment mPFColor;
@@ -570,6 +572,7 @@ public class AllAppsView extends RSSurfaceView
public int selectedIconTexture;
public float zoomTarget;
public int homeButtonId;
public float targetPos;
State() {
mType = Type.createFromClass(mRS, State.class, 1, "StateClass");
@@ -743,6 +746,7 @@ public class AllAppsView extends RSSurfaceView
sb.setType(mState.mType, "state", Defines.ALLOC_STATE);
mInvokeMove = sb.addInvokable("move");
mInvokeFling = sb.addInvokable("fling");
mInvokeMoveTo = sb.addInvokable("moveTo");
mInvokeResetWAR = sb.addInvokable("resetHWWar");
mScript = sb.create();
mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
@@ -937,6 +941,12 @@ public class AllAppsView extends RSSurfaceView
mInvokeMove.execute();
}
void moveTo(float row) {
mState.targetPos = row;
mState.save();
mInvokeMoveTo.execute();
}
/**
* You need to call save() on mState on your own after calling this.
*