handle l2 and r2

This commit is contained in:
2026-01-20 09:01:41 +00:00
parent 9962232f83
commit e2454b1093

View File

@@ -8,12 +8,9 @@ struct
fun axisToDir (x, y, l2, r2) = fun axisToDir (x, y, l2, r2) =
if isInDeadZone (x, y) then if isInDeadZone (x, y) then
(* analogue is in dead zone, so only query L2 and R2 *) (* analogue is in dead zone, so only query L2 and R2 *)
if r2 < 0.3 andalso l2 < 0.3 then if r2 < 0.3 andalso l2 < 0.3 then CENTRE
CENTRE else if abs r2 > abs l2 then R2
else if abs r2 > abs l2 then else L2
R2
else
L2
else else
let let
val ax = abs x val ax = abs x
@@ -22,15 +19,9 @@ struct
val ar2 = abs r2 val ar2 = abs r2
in in
if ax > ay andalso ax > al2 andalso ax > ar2 then if ax > ay andalso ax > al2 andalso ax > ar2 then
if x > 0.0 then if x > 0.0 then RIGHT else LEFT
RIGHT
else
LEFT
else if ay > ax andalso ay > al2 andalso ay > ar2 then else if ay > ax andalso ay > al2 andalso ay > ar2 then
if y > 0.0 then if y > 0.0 then DOWN else UP
DOWN
else
UP
else if al2 > ax andalso al2 > ay andalso al2 > ar2 then else if al2 > ax andalso al2 > ay andalso al2 > ar2 then
L2 L2
else else
@@ -55,9 +46,11 @@ struct
, trianglePressed = ref false , trianglePressed = ref false
, r1Pressed = ref false , r1Pressed = ref false
, l1Pressed = ref false , l1Pressed = ref false
, shiftChr = ref false
} }
open InputMsg fun appendChr chr =
(InputMailbox.append (InputMsg.CHAR_EVENT chr); #shiftChr state := false)
fun handleTrianglePressed (x, y, l2, r2) = fun handleTrianglePressed (x, y, l2, r2) =
if !(#trianglePressed state) then if !(#trianglePressed state) then
@@ -66,6 +59,16 @@ struct
let let
val () = #trianglePressed state := true val () = #trianglePressed state := true
val chr = val chr =
if !(#shiftChr state) then
case axisToDir (x, y, l2, r2) of
CENTRE => #"A"
| UP => #"E"
| RIGHT => #"I"
| DOWN => #"M"
| LEFT => #"Q"
| L2 => #"U"
| R2 => #"Y"
else
case axisToDir (x, y, l2, r2) of case axisToDir (x, y, l2, r2) of
CENTRE => #"a" CENTRE => #"a"
| UP => #"e" | UP => #"e"
@@ -75,7 +78,7 @@ struct
| L2 => #"u" | L2 => #"u"
| R2 => #"y" | R2 => #"y"
in in
InputMailbox.append (CHAR_EVENT chr) appendChr chr
end end
fun handleCirclePressed (x, y, l2, r2) = fun handleCirclePressed (x, y, l2, r2) =
@@ -85,6 +88,16 @@ struct
let let
val () = #circlePressed state := true val () = #circlePressed state := true
val chr = val chr =
if !(#shiftChr state) then
case axisToDir (x, y, l2, r2) of
CENTRE => #"B"
| UP => #"F"
| RIGHT => #"J"
| DOWN => #"N"
| LEFT => #"R"
| L2 => #"V"
| R2 => #"Z"
else
case axisToDir (x, y, l2, r2) of case axisToDir (x, y, l2, r2) of
CENTRE => #"b" CENTRE => #"b"
| UP => #"f" | UP => #"f"
@@ -94,7 +107,7 @@ struct
| L2 => #"v" | L2 => #"v"
| R2 => #"z" | R2 => #"z"
in in
InputMailbox.append (CHAR_EVENT chr) appendChr chr
end end
fun handleCrossPressed (x, y, l2, r2) = fun handleCrossPressed (x, y, l2, r2) =
@@ -104,16 +117,24 @@ struct
let let
val () = #crossPressed state := true val () = #crossPressed state := true
in in
if !(#shiftChr state) then
case axisToDir (x, y, l2, r2) of case axisToDir (x, y, l2, r2) of
CENTRE => InputMailbox.append (CHAR_EVENT #"c") CENTRE => appendChr #"U"
| UP => InputMailbox.append (CHAR_EVENT #"g") | UP => appendChr #"U"
| RIGHT => InputMailbox.append (CHAR_EVENT #"k") | RIGHT => appendChr #"U"
| DOWN => InputMailbox.append (CHAR_EVENT #"o") | DOWN => appendChr #"U"
| LEFT => InputMailbox.append (CHAR_EVENT #"s") | LEFT => appendChr #"U"
| L2 => InputMailbox.append (CHAR_EVENT #"w") | L2 => appendChr #"U"
| R2 => | R2 => InputMailbox.append InputMsg.KEY_ENTER
(* todo: either shift or enter *) else
raise Fail "glfw-gamepad.sml: 77\n" case axisToDir (x, y, l2, r2) of
CENTRE => appendChr #"c"
| UP => appendChr #"g"
| RIGHT => appendChr #"k"
| DOWN => appendChr #"o"
| LEFT => appendChr #"s"
| L2 => appendChr #"w"
| R2 => InputMailbox.append InputMsg.KEY_ENTER
end end
fun handleSquarePressed (x, y, l2, r2) = fun handleSquarePressed (x, y, l2, r2) =
@@ -123,16 +144,24 @@ struct
let let
val () = #squarePressed state := true val () = #squarePressed state := true
in in
if !(#shiftChr state) then
case axisToDir (x, y, l2, r2) of case axisToDir (x, y, l2, r2) of
CENTRE => InputMailbox.append (CHAR_EVENT #"d") CENTRE => appendChr #"U"
| UP => InputMailbox.append (CHAR_EVENT #"h") | UP => appendChr #"U"
| RIGHT => InputMailbox.append (CHAR_EVENT #"l") | RIGHT => appendChr #"U"
| DOWN => InputMailbox.append (CHAR_EVENT #"p") | DOWN => appendChr #"U"
| LEFT => InputMailbox.append (CHAR_EVENT #"t") | LEFT => appendChr #"U"
| L2 => InputMailbox.append (CHAR_EVENT #"x") | L2 => appendChr #"U"
| R2 => | R2 => #shiftChr state := true
(* todo: either shift or enter *) else
raise Fail "glfw-gamepad.sml: 87\n" case axisToDir (x, y, l2, r2) of
CENTRE => appendChr #"d"
| UP => appendChr #"h"
| RIGHT => appendChr #"l"
| DOWN => appendChr #"p"
| LEFT => appendChr #"t"
| L2 => appendChr #"x"
| R2 => #shiftChr state := true
end end
in in
fun handleIfJoystickIsPresent () = fun handleIfJoystickIsPresent () =
@@ -167,7 +196,6 @@ struct
val () = val () =
if squarePressed = 0 then #squarePressed state := false if squarePressed = 0 then #squarePressed state := false
else if !(#squarePressed state) then ()
else handleSquarePressed (xAxis, yAxis, l2, r2) else handleSquarePressed (xAxis, yAxis, l2, r2)
val () = val () =
@@ -181,7 +209,7 @@ struct
else if !(#r1Pressed state) then else if !(#r1Pressed state) then
() ()
else else
let val () = InputMailbox.append (CHAR_EVENT #" ") let val () = InputMailbox.append (InputMsg.CHAR_EVENT #" ")
in #r1Pressed state := true in #r1Pressed state := true
end end