dymokomi/luced-3d
Source of release 0.11.8
## Space over the viewport: a tap (pressed and let go with nothing else
## pressed meanwhile, within half a second) shows the pane alone or the four
## again, as Maya's Space does; held with F it makes the viewport fill the
## window. Anything else pressed while it is held (a key, a mouse button)
## spends the tap. Times are in nanoseconds.
## The longest press that is still a tap.
pub let tap_nanoseconds = 500000000
pub class SpaceTap:
## Whether Space is down, since when, and whether something else was
## pressed meanwhile.
pub var held: bool = false
var since: int = 0
var spent: bool = false
## Space went down at `now` (a repeat while held changes nothing).
pub func press(self, now: int):
if self.held:
return
self.held = true
self.since = now
self.spent = false
## Another key or a mouse button went down while Space is held.
pub func other(self):
if self.held:
self.spent = true
## Space went up at `now`: whether that was a tap.
pub func release(self, now: int) -> bool:
if not self.held:
return false
self.held = false
return not self.spent and now - self.since <= tap_nanoseconds
## The viewport lost the keyboard: Space's press is forgotten.
pub func cancel(self):
self.held = false
self.spent = false