handle l2 and r2
This commit is contained in:
@@ -6,15 +6,12 @@ struct
|
|||||||
x < 0.1 andalso x > ~0.1 andalso y < 0.1 andalso y > ~0.1
|
x < 0.1 andalso x > ~0.1 andalso y < 0.1 andalso y > ~0.1
|
||||||
|
|
||||||
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
|
||||||
else
|
|
||||||
L2
|
|
||||||
else
|
|
||||||
let
|
let
|
||||||
val ax = abs x
|
val ax = abs x
|
||||||
val ay = abs y
|
val ay = abs y
|
||||||
@@ -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,16 +59,26 @@ struct
|
|||||||
let
|
let
|
||||||
val () = #trianglePressed state := true
|
val () = #trianglePressed state := true
|
||||||
val chr =
|
val chr =
|
||||||
case axisToDir (x, y, l2, r2) of
|
if !(#shiftChr state) then
|
||||||
CENTRE => #"a"
|
case axisToDir (x, y, l2, r2) of
|
||||||
| UP => #"e"
|
CENTRE => #"A"
|
||||||
| RIGHT => #"i"
|
| UP => #"E"
|
||||||
| DOWN => #"m"
|
| RIGHT => #"I"
|
||||||
| LEFT => #"q"
|
| DOWN => #"M"
|
||||||
| L2 => #"u"
|
| LEFT => #"Q"
|
||||||
| R2 => #"y"
|
| L2 => #"U"
|
||||||
|
| R2 => #"Y"
|
||||||
|
else
|
||||||
|
case axisToDir (x, y, l2, r2) of
|
||||||
|
CENTRE => #"a"
|
||||||
|
| UP => #"e"
|
||||||
|
| RIGHT => #"i"
|
||||||
|
| DOWN => #"m"
|
||||||
|
| LEFT => #"q"
|
||||||
|
| L2 => #"u"
|
||||||
|
| 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,16 +88,26 @@ struct
|
|||||||
let
|
let
|
||||||
val () = #circlePressed state := true
|
val () = #circlePressed state := true
|
||||||
val chr =
|
val chr =
|
||||||
case axisToDir (x, y, l2, r2) of
|
if !(#shiftChr state) then
|
||||||
CENTRE => #"b"
|
case axisToDir (x, y, l2, r2) of
|
||||||
| UP => #"f"
|
CENTRE => #"B"
|
||||||
| RIGHT => #"j"
|
| UP => #"F"
|
||||||
| DOWN => #"n"
|
| RIGHT => #"J"
|
||||||
| LEFT => #"r"
|
| DOWN => #"N"
|
||||||
| L2 => #"v"
|
| LEFT => #"R"
|
||||||
| R2 => #"z"
|
| L2 => #"V"
|
||||||
|
| R2 => #"Z"
|
||||||
|
else
|
||||||
|
case axisToDir (x, y, l2, r2) of
|
||||||
|
CENTRE => #"b"
|
||||||
|
| UP => #"f"
|
||||||
|
| RIGHT => #"j"
|
||||||
|
| DOWN => #"n"
|
||||||
|
| LEFT => #"r"
|
||||||
|
| L2 => #"v"
|
||||||
|
| 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
|
||||||
case axisToDir (x, y, l2, r2) of
|
if !(#shiftChr state) then
|
||||||
CENTRE => InputMailbox.append (CHAR_EVENT #"c")
|
case axisToDir (x, y, l2, r2) of
|
||||||
| UP => InputMailbox.append (CHAR_EVENT #"g")
|
CENTRE => appendChr #"U"
|
||||||
| RIGHT => InputMailbox.append (CHAR_EVENT #"k")
|
| UP => appendChr #"U"
|
||||||
| DOWN => InputMailbox.append (CHAR_EVENT #"o")
|
| RIGHT => appendChr #"U"
|
||||||
| LEFT => InputMailbox.append (CHAR_EVENT #"s")
|
| DOWN => appendChr #"U"
|
||||||
| L2 => InputMailbox.append (CHAR_EVENT #"w")
|
| LEFT => appendChr #"U"
|
||||||
| R2 =>
|
| L2 => appendChr #"U"
|
||||||
(* todo: either shift or enter *)
|
| R2 => InputMailbox.append InputMsg.KEY_ENTER
|
||||||
raise Fail "glfw-gamepad.sml: 77\n"
|
else
|
||||||
|
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
|
||||||
case axisToDir (x, y, l2, r2) of
|
if !(#shiftChr state) then
|
||||||
CENTRE => InputMailbox.append (CHAR_EVENT #"d")
|
case axisToDir (x, y, l2, r2) of
|
||||||
| UP => InputMailbox.append (CHAR_EVENT #"h")
|
CENTRE => appendChr #"U"
|
||||||
| RIGHT => InputMailbox.append (CHAR_EVENT #"l")
|
| UP => appendChr #"U"
|
||||||
| DOWN => InputMailbox.append (CHAR_EVENT #"p")
|
| RIGHT => appendChr #"U"
|
||||||
| LEFT => InputMailbox.append (CHAR_EVENT #"t")
|
| DOWN => appendChr #"U"
|
||||||
| L2 => InputMailbox.append (CHAR_EVENT #"x")
|
| LEFT => appendChr #"U"
|
||||||
| R2 =>
|
| L2 => appendChr #"U"
|
||||||
(* todo: either shift or enter *)
|
| R2 => #shiftChr state := true
|
||||||
raise Fail "glfw-gamepad.sml: 87\n"
|
else
|
||||||
|
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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user