Scoop API

scoop:scoop.ui:0.1.0

src/scroll/input_geometry.scoop

Selected production source · src/scroll/input_geometry.scoop

1package scoop.ui
3import scoop.graphics.Point
4import scoop.graphics.Rect
5import scoop.surface.InputScope
7internal fun inputWindowPoint(scope: InputScope, point: Point): Point? =
8 when (scope.area) {
9 case Some(val area) -> when (area.toWindow(Rect(point.x, point.y, 0.0, 0.0))) {
10 case Some(val bounds) -> Some(Point(bounds.x, bounds.y))
11 case None -> None
12 }
13 case None -> Some(point)
14 }
16internal fun inputLocalPoint(scope: InputScope, point: Point): Point? =
17 when (scope.area) {
18 case Some(val area) -> area.toLocal(point)
19 case None -> Some(point)
20 }
22internal fun inputLocalVector(scope: InputScope, origin: Point, amount: Point): Point? {
23 val first = inputLocalPoint(scope, origin) ?: return None
24 val last =
25 inputLocalPoint(scope, Point(origin.x + amount.x, origin.y + amount.y)) ?: return None
26 return Some(Point(last.x - first.x, last.y - first.y))
29internal fun inputWindowVector(scope: InputScope, origin: Point, amount: Point): Point? {
30 val local = inputLocalPoint(scope, origin) ?: return None
31 val first = inputWindowPoint(scope, local) ?: return None
32 val last = inputWindowPoint(scope, Point(local.x + amount.x, local.y + amount.y)) ?: return None
33 return Some(Point(last.x - first.x, last.y - first.y))