Skip to content

Commit

Permalink
Add support for PressureEXT
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0ade committed Nov 20, 2015
1 parent cdf4707 commit 55640e3
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 5 deletions.
58 changes: 57 additions & 1 deletion src/Input/Touch/TouchLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ public TouchLocationState State
return state;
}
}

#endregion

#region Public Properties, FNA Extensions

public float PressureEXT
{
get
{
return pressure;
}
}

#endregion

Expand Down Expand Up @@ -110,6 +122,8 @@ internal Vector2 Velocity
private Vector2 previousPosition;
private TouchLocationState state;
private TouchLocationState previousState;
private float pressure;
private float previousPressure;

// Used for gesture recognition.
private Vector2 velocity;
Expand All @@ -129,8 +143,10 @@ Vector2 position
id,
state,
position,
1f,
TouchLocationState.Invalid,
Vector2.Zero,
0f,
TimeSpan.Zero
) {
}
Expand All @@ -145,8 +161,10 @@ Vector2 previousPosition
id,
state,
position,
1f,
previousState,
previousPosition,
0f,
TimeSpan.Zero
) {
}
Expand All @@ -164,8 +182,28 @@ TimeSpan timestamp
id,
state,
position,
1f,
TouchLocationState.Invalid,
Vector2.Zero,
0f,
timestamp
) {
}

internal TouchLocation(
int id,
TouchLocationState state,
Vector2 position,
float pressure,
TimeSpan timestamp
) : this(
id,
state,
position,
pressure,
TouchLocationState.Invalid,
Vector2.Zero,
0f,
timestamp
) {
}
Expand All @@ -174,16 +212,20 @@ TimeSpan timestamp
int id,
TouchLocationState state,
Vector2 position,
float pressure,
TouchLocationState previousState,
Vector2 previousPosition,
float previousPressure,
TimeSpan timestamp
) {
this.id = id;
this.state = state;
this.position = position;
this.pressure = pressure;

this.previousState = previousState;
this.previousPosition = previousPosition;
this.previousPressure = previousPressure;

this.timestamp = timestamp;
velocity = Vector2.Zero;
Expand Down Expand Up @@ -211,11 +253,19 @@ TimeSpan timestamp

public bool TryGetPreviousLocation(out TouchLocation aPreviousLocation)
{
//I wonder how this compiled without setting aPreviousLocation... --ade
aPreviousLocation = new TouchLocation(
id,
previousState,
previousPosition,
pressTimestamp
);
if (previousState == TouchLocationState.Invalid)
{
aPreviousLocation.id = -1;
aPreviousLocation.state = TouchLocationState.Invalid;
aPreviousLocation.position = Vector2.Zero;
aPreviousLocation.pressure = 0f;
aPreviousLocation.previousState = TouchLocationState.Invalid;
aPreviousLocation.previousPosition = Vector2.Zero;
aPreviousLocation.timestamp = TimeSpan.Zero;
Expand All @@ -229,6 +279,7 @@ public bool TryGetPreviousLocation(out TouchLocation aPreviousLocation)
aPreviousLocation.id = id;
aPreviousLocation.state = previousState;
aPreviousLocation.position = previousPosition;
aPreviousLocation.pressure = previousPressure;
aPreviousLocation.previousState = TouchLocationState.Invalid;
aPreviousLocation.previousPosition = Vector2.Zero;
aPreviousLocation.timestamp = timestamp;
Expand Down Expand Up @@ -290,8 +341,10 @@ public bool Equals(TouchLocation other)
return ( value1.id == value2.id &&
value1.state == value2.state &&
value1.position == value2.position &&
value1.pressure == value2.pressure &&
value1.previousState == value2.previousState &&
value1.previousPosition == value2.previousPosition );
value1.previousPosition == value2.previousPosition &&
value1.previousPressure == value2.previousPressure );
}

#endregion
Expand All @@ -309,6 +362,7 @@ internal TouchLocation AsMovedState()
// Store the current state as the previous.
touch.previousState = touch.state;
touch.previousPosition = touch.position;
touch.previousPressure = touch.pressure;

// Set the new state.
touch.state = TouchLocationState.Moved;
Expand Down Expand Up @@ -342,6 +396,7 @@ internal bool UpdateState(TouchLocation touchEvent)
// Store the current state as the previous one.
previousPosition = position;
previousState = state;
previousPressure = pressure;

// Set the new state.
position = touchEvent.position;
Expand Down Expand Up @@ -386,6 +441,7 @@ internal void AgeState()

previousState = state;
previousPosition = position;
previousPressure = pressure;

if (SameFrameReleased)
{
Expand Down
20 changes: 20 additions & 0 deletions src/Input/Touch/TouchPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,37 @@ Vector2 position
) {
AddEvent(id, state, position, false);
}

internal static void AddEvent(
int id,
TouchLocationState state,
Vector2 position,
float pressure
) {
AddEvent(id, state, position, pressure, false);
}

internal static void AddEvent(
int id,
TouchLocationState state,
Vector2 position,
bool isMouse
) {
AddEvent(id, state, position, 1f, isMouse);
}

internal static void AddEvent(
int id,
TouchLocationState state,
Vector2 position,
float pressure,
bool isMouse
) {
PrimaryWindow.TouchPanelState.AddEvent(
id,
state,
position,
pressure,
isMouse
);
}
Expand Down
13 changes: 13 additions & 0 deletions src/Input/Touch/TouchPanelState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,21 @@ Vector2 position
) {
AddEvent(id, state, position, false);
}

internal void AddEvent(
int id,
TouchLocationState state,
Vector2 position,
bool isMouse
) {
AddEvent(id, state, position, 1f, isMouse);
}

internal void AddEvent(
int id,
TouchLocationState state,
Vector2 position,
float pressure,
bool isMouse
) {
/* Different platforms return different touch identifiers
Expand Down Expand Up @@ -330,6 +340,7 @@ bool isMouse
touchId,
state,
position * touchScale,
pressure,
CurrentTimestamp
);

Expand Down Expand Up @@ -386,6 +397,7 @@ internal void ReleaseAllTouches()
touch.Id,
TouchLocationState.Released,
touch.Position,
0f,
CurrentTimestamp
)
);
Expand All @@ -404,6 +416,7 @@ internal void ReleaseAllTouches()
touch.Id,
TouchLocationState.Released,
touch.Position,
0f,
CurrentTimestamp
)
);
Expand Down
9 changes: 6 additions & 3 deletions src/SDL2/SDL2_GamePlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ public override void RunLoop()
new Vector2(
evt.tfinger.x,
evt.tfinger.y
)
),
evt.tfinger.pressure
);
}
else if (evt.type == SDL.SDL_EventType.SDL_FINGERUP)
Expand All @@ -356,7 +357,8 @@ public override void RunLoop()
new Vector2(
evt.tfinger.x,
evt.tfinger.y
)
),
evt.tfinger.pressure
);
}
else if (evt.type == SDL.SDL_EventType.SDL_FINGERMOTION)
Expand All @@ -367,7 +369,8 @@ public override void RunLoop()
new Vector2(
evt.tfinger.x,
evt.tfinger.y
)
),
evt.tfinger.pressure
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/TitleContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static internal ZipArchive Zip
//it's required to remove all references to the
//ZIP to allow the GC to call Finalize().
//-ade
static internal Object Zip
static internal object Zip
{
get;
private set;
Expand Down

0 comments on commit 55640e3

Please sign in to comment.