From nobody Tue Feb 23 21:23:16 2021 Authentication-Results: mail-b.sr.ht; dkim=none Received: from git.sr.ht (unknown [173.195.146.142]) by mail-b.sr.ht (Postfix) with ESMTPSA id E909711EFF8; Tue, 23 Feb 2021 21:23:15 +0000 (UTC) From: ~pierrec Date: Tue, 23 Feb 2021 22:22:35 +0100 Subject: [PATCH gio] io/router: use f32.Rectangle in areaOp Message-ID: <161411539567.28528.8411493416571596383-0@git.sr.ht> X-Mailer: git.sr.ht Reply-to: ~pierrec To: ~eliasnaur/gio-patches@lists.sr.ht Cc: mail@eliasnaur.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 From: pierre Also introduce a function to decode a float32 from ops. Signed-off-by: pierre --- io/router/pointer.go | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/io/router/pointer.go b/io/router/pointer.go index ab9348b..ef56841 100644 --- a/io/router/pointer.go +++ b/io/router/pointer.go @@ -4,7 +4,6 @@ package router =20 import ( "encoding/binary" - "image" =20 "gioui.org/f32" "gioui.org/internal/opconst" @@ -64,7 +63,7 @@ type pointerHandler struct { =20 type areaOp struct { kind areaKind - rect image.Rectangle + rect f32.Rectangle } =20 type areaNode struct { @@ -409,19 +408,22 @@ func searchTag(tags []event.Tag, tag event.Tag) (int, b= ool) { return 0, false } =20 +func opDecodeFloat32(d []byte) float32 { + return float32(binary.LittleEndian.Uint32(d)) +} + func (op *areaOp) Decode(d []byte) { if opconst.OpType(d[0]) !=3D opconst.TypeArea { panic("invalid op") } - bo :=3D binary.LittleEndian - rect :=3D image.Rectangle{ - Min: image.Point{ - X: int(int32(bo.Uint32(d[2:]))), - Y: int(int32(bo.Uint32(d[6:]))), + rect :=3D f32.Rectangle{ + Min: f32.Point{ + X: opDecodeFloat32(d[2:]), + Y: opDecodeFloat32(d[6:]), }, - Max: image.Point{ - X: int(int32(bo.Uint32(d[10:]))), - Y: int(int32(bo.Uint32(d[14:]))), + Max: f32.Point{ + X: opDecodeFloat32(d[10:]), + Y: opDecodeFloat32(d[14:]), }, } *op =3D areaOp{ @@ -431,19 +433,15 @@ func (op *areaOp) Decode(d []byte) { } =20 func (op *areaOp) Hit(pos f32.Point) bool { - min :=3D f32.Point{ - X: float32(op.rect.Min.X), - Y: float32(op.rect.Min.Y), - } - pos =3D pos.Sub(min) + pos =3D pos.Sub(op.rect.Min) size :=3D op.rect.Size() switch op.kind { case areaRect: - return 0 <=3D pos.X && pos.X < float32(size.X) && - 0 <=3D pos.Y && pos.Y < float32(size.Y) + return 0 <=3D pos.X && pos.X < size.X && + 0 <=3D pos.Y && pos.Y < size.Y case areaEllipse: - rx :=3D float32(size.X) / 2 - ry :=3D float32(size.Y) / 2 + rx :=3D size.X / 2 + ry :=3D size.Y / 2 xh :=3D pos.X - rx yk :=3D pos.Y - ry // The ellipse function works in all cases because --=20 2.30.1