Skip to content

Commit

Permalink
Fixes an issue where Pointer Click was never fired
Browse files Browse the repository at this point in the history
  • Loading branch information
hobnob committed Nov 4, 2024
1 parent 65b37b3 commit 78ca3c6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ final case class Button(
def update(pointer: PointerState): Outcome[Button] = {
val pointerInBounds = pointer.positions.exists(p => bounds.isPointWithin(p))

println(
s"Pointer in bounds: $pointerInBounds released: ${pointer.isReleased} clicked: ${pointer.isClicked} pressed: ${pointer.isPressed}"
)
val upEvents: Batch[GlobalEvent] =
if pointerInBounds && pointer.released then onUp()
else Batch.empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,25 +329,27 @@ final class WorldEvents:
// Check to see if this button is up within the clickTimeMs, and if so fire a click event
pointerButtons.getOrElse(e.pointerId, Batch.empty).find(_._1 == e.button) match {
case Some((btn, downTime)) if btn == e.button && Date.now() - downTime.getTime() <= clickTimeMs =>
PointerClick(
position,
buttons,
e.altKey,
e.ctrlKey,
e.metaKey,
e.shiftKey,
movementPosition,
PointerId(e.pointerId),
e.width(magnification),
e.height(magnification),
e.pressure,
e.tangentialPressure,
Radians.fromDegrees(e.tiltX),
Radians.fromDegrees(e.tiltY),
Radians.fromDegrees(e.twist),
pointerType,
e.isPrimary,
MouseButton.fromOrdinalOpt(e.button)
globalEventStream.pushGlobalEvent(
PointerClick(
position,
buttons,
e.altKey,
e.ctrlKey,
e.metaKey,
e.shiftKey,
movementPosition,
PointerId(e.pointerId),
e.width(magnification),
e.height(magnification),
e.pressure,
e.tangentialPressure,
Radians.fromDegrees(e.tiltX),
Radians.fromDegrees(e.tiltY),
Radians.fromDegrees(e.twist),
pointerType,
e.isPrimary,
MouseButton.fromOrdinalOpt(e.button)
)
)
case _ => ()
}
Expand Down
115 changes: 11 additions & 104 deletions indigo/indigo/src/main/scala/indigo/shared/events/GlobalEvent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -570,47 +570,11 @@ object PointerEvent:
) extends PointerEvent
object PointerDown:
def apply(position: Point, pointerType: PointerType): PointerDown =
PointerDown(
position = position,
buttons = Batch.empty,
isAltKeyDown = false,
isCtrlKeyDown = false,
isMetaKeyDown = false,
isShiftKeyDown = false,
movementPosition = Point.zero,
button = Some(MouseButton.LeftMouseButton),
pointerId = 0,
width = 0,
height = 0,
pressure = 0,
tangentialPressure = 0,
tiltX = Radians.zero,
tiltY = Radians.zero,
twist = Radians.zero,
pointerType = pointerType,
isPrimary = true
)
PointerDown(position, MouseButton.LeftMouseButton, pointerType)
def apply(x: Int, y: Int, pointerType: PointerType): PointerDown =
PointerDown(
position = Point(x, y),
buttons = Batch.empty,
isAltKeyDown = false,
isCtrlKeyDown = false,
isMetaKeyDown = false,
isShiftKeyDown = false,
movementPosition = Point.zero,
button = Some(MouseButton.LeftMouseButton),
pointerId = 0,
width = 0,
height = 0,
pressure = 0,
tangentialPressure = 0,
tiltX = Radians.zero,
tiltY = Radians.zero,
twist = Radians.zero,
pointerType = pointerType,
isPrimary = true
)
PointerDown(Point(x, y), MouseButton.LeftMouseButton, pointerType)
def apply(x: Int, y: Int, button: MouseButton, pointerType: PointerType): PointerDown =
PointerDown(Point(x, y), button, pointerType)
def apply(position: Point, button: MouseButton, pointerType: PointerType): PointerDown =
PointerDown(
position = position,
Expand All @@ -620,28 +584,7 @@ object PointerEvent:
isMetaKeyDown = false,
isShiftKeyDown = false,
movementPosition = Point.zero,
button = Some(MouseButton.LeftMouseButton),
pointerId = 0,
width = 0,
height = 0,
pressure = 0,
tangentialPressure = 0,
tiltX = Radians.zero,
tiltY = Radians.zero,
twist = Radians.zero,
pointerType = pointerType,
isPrimary = true
)
def apply(x: Int, y: Int, button: MouseButton, pointerType: PointerType): PointerDown =
PointerDown(
position = Point(x, y),
buttons = Batch.empty,
isAltKeyDown = false,
isCtrlKeyDown = false,
isMetaKeyDown = false,
isShiftKeyDown = false,
movementPosition = Point.zero,
button = Some(MouseButton.LeftMouseButton),
button = Some(button),
pointerId = 0,
width = 0,
height = 0,
Expand Down Expand Up @@ -681,57 +624,21 @@ object PointerEvent:
) extends PointerEvent
object PointerUp:
def apply(position: Point, pointerType: PointerType): PointerUp =
PointerUp(
position = position,
buttons = Batch.empty,
isAltKeyDown = false,
isCtrlKeyDown = false,
isMetaKeyDown = false,
isShiftKeyDown = false,
movementPosition = Point.zero,
button = Some(MouseButton.LeftMouseButton),
pointerId = 0,
width = 0,
height = 0,
pressure = 0,
tangentialPressure = 0,
tiltX = Radians.zero,
tiltY = Radians.zero,
twist = Radians.zero,
pointerType = pointerType,
isPrimary = true
)
PointerUp(position, MouseButton.LeftMouseButton, pointerType)
def apply(x: Int, y: Int, pointerType: PointerType): PointerUp =
PointerUp(
position = Point(x, y),
buttons = Batch.empty,
isAltKeyDown = false,
isCtrlKeyDown = false,
isMetaKeyDown = false,
isShiftKeyDown = false,
movementPosition = Point.zero,
button = Some(MouseButton.LeftMouseButton),
pointerId = 0,
width = 0,
height = 0,
pressure = 0,
tangentialPressure = 0,
tiltX = Radians.zero,
tiltY = Radians.zero,
twist = Radians.zero,
pointerType = pointerType,
isPrimary = true
)
PointerUp(Point(x, y), MouseButton.LeftMouseButton, pointerType)
def apply(x: Int, y: Int, button: MouseButton, pointerType: PointerType): PointerUp =
PointerUp(Point(x, y), button, pointerType)
def apply(position: Point, button: MouseButton, pointerType: PointerType): PointerUp =
PointerUp(
position = Point(x, y),
position = position,
buttons = Batch.empty,
isAltKeyDown = false,
isCtrlKeyDown = false,
isMetaKeyDown = false,
isShiftKeyDown = false,
movementPosition = Point.zero,
button = Some(MouseButton.LeftMouseButton),
button = Some(button),
pointerId = 0,
width = 0,
height = 0,
Expand Down

0 comments on commit 78ca3c6

Please sign in to comment.