Skip to content

Commit

Permalink
Improve detection of multiple presses with a single finger. (#19)
Browse files Browse the repository at this point in the history
Change the touch logic of CrossDial and PrimaryButtonDials. Now it's based on a weighted distance with some fixed points. This also clarifies where the dial detects pad diagonals or multiple buttons.
  • Loading branch information
Swordfish90 authored Aug 31, 2021
1 parent cd812b9 commit 0a0f4b1
Show file tree
Hide file tree
Showing 14 changed files with 445 additions and 275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ object SamplePadConfigs {
val REMOTE =
RadialGamePadConfig(
sockets = 6,
primaryDial = PrimaryDialConfig.Cross(0),
primaryDial = PrimaryDialConfig.Cross(0, useDiagonals = false),
secondaryDials = listOf(
SecondaryDialConfig.SingleButton(
1, 1, ButtonConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* along with RadialGamePad. If not, see <https://www.gnu.org/licenses/>.
*/

@file:Suppress("unused")

package com.swordfish.radialgamepad.library

import android.content.Context
Expand Down Expand Up @@ -318,8 +320,7 @@ class RadialGamePad @JvmOverloads constructor(
configuration.rightDrawableForegroundId,
configuration.supportsGestures,
configuration.contentDescription,
configuration.diagonalRatio,
configuration.distanceFromCenter,
configuration.useDiagonals,
configuration.theme ?: gamePadConfig.theme
)
is PrimaryDialConfig.Stick -> StickDial(
Expand Down Expand Up @@ -366,8 +367,7 @@ class RadialGamePad @JvmOverloads constructor(
config.rightDrawableForegroundId,
config.supportsGestures,
config.contentDescription,
config.diagonalRatio,
config.distanceFromCenter,
config.useDiagonals,
config.theme ?: gamePadConfig.theme
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ sealed class PrimaryDialConfig {
* @property id The control id. It is passed back to discriminate events.
* @property rightDrawableId A resource drawable id for the left arrow (other arrows are obtained by rotating it)
* @property supportsGestures The set of gestures that the button can emit. Defaults to empty.
* @property diagonalRatio Sets how smaller diagonal should be compared to primary direction. Defaults to 3, which corresponds to half.
* @property distanceFromCenter How much the drawable should be distanced from the center. Available in range [0.0, 1.0], defaults to 0.4.
* @property useDiagonals The controls will allow diagonal directions.
* @property theme A RadialGamePadTheme specific for this dial. If omitted the RadialGamePad one is used.
*/
data class Cross(
Expand All @@ -40,8 +39,7 @@ sealed class PrimaryDialConfig {
val rightDrawableForegroundId: Int? = null,
val contentDescription: CrossContentDescription = CrossContentDescription(),
val supportsGestures: Set<GestureType> = emptySet(),
val diagonalRatio: Int = 2,
val distanceFromCenter: Float = 0.4f,
val useDiagonals: Boolean = true,
val theme: RadialGamePadTheme? = null
) : PrimaryDialConfig()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import com.swordfish.radialgamepad.library.utils.Constants
* @property simulatedColor A color which is displayed when control movement is simulated programmatically
* @property textColor A color which is used to draw labels or icons on top of controls
* @property primaryDialBackground A color which is used to draw the circular background behind the primary dial
* @property secondaryDialBackground A color which is used to draw the circular background behind the secondary dials
* @property lightColor A color which is used for some light details
*/
data class RadialGamePadTheme(
val normalColor: Int = Constants.DEFAULT_COLOR_NORMAL,
val pressedColor: Int = Constants.DEFAULT_COLOR_PRESSED,
val simulatedColor: Int = Constants.DEFAULT_COLOR_NORMAL,
val textColor: Int = Constants.DEFAULT_COLOR_TEXT,
val primaryDialBackground: Int = Constants.DEFAULT_COLOR_BACKGROUND,
val secondaryDialBackground: Int = Constants.DEFAULT_COLOR_SECONDARY_BACKGROUND
val lightColor: Int = Constants.DEFAULT_COLOR_LIGHT
)
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ sealed class SecondaryDialConfig(val index: Int, val spread: Int, val scale: Flo
* @property rightDrawableId The optional drawable that define the shape of the right button.
* @property rightDrawableForegroundId The optional drawable that is drawn on top with text color.
* @property supportsGestures The set of gestures that the button can emit. Defaults to empty.
* @property diagonalRatio Sets how smaller diagonal should be compared to primary direction. Defaults to 2, which corresponds to a half.
* @property distanceFromCenter How much the drawable should be distanced from the center. Available in range [0.0, 1.0], defaults to 0.4.
* @property useDiagonals The controls will allow diagonal directions.
* @property contentDescription Content description read by the screen reader. Defaults to "D-Pad".
* @property theme A theme for this specific dial. By default it inherits the gamepad theme.
*/
Expand All @@ -87,8 +86,7 @@ sealed class SecondaryDialConfig(val index: Int, val spread: Int, val scale: Flo
val rightDrawableForegroundId: Int? = null,
val supportsGestures: Set<GestureType> = emptySet(),
val contentDescription: CrossContentDescription = CrossContentDescription(),
val diagonalRatio: Int = 2,
val distanceFromCenter: Float = 0.4f,
val useDiagonals: Boolean = true,
val theme: RadialGamePadTheme? = null
) : SecondaryDialConfig(index, scale.roundToInt(), scale)

Expand Down
Loading

0 comments on commit 0a0f4b1

Please sign in to comment.