~eliasnaur/gio

fe20cde393f696f949f1f7dfde0a18c6c4307ac1 — Elias Naur 8 months ago 9be695c
ui: rename TransformOp.Mul to Multiply and split InvTransform

Multiply is a bit longer but more clear. InvTransform was really
two operations: Invert and Transform.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
3 files changed, 12 insertions(+), 8 deletions(-)

M ui/app/internal/gpu/gpu.go
M ui/app/internal/input/pointer.go
M ui/ui.go
M ui/app/internal/gpu/gpu.go => ui/app/internal/gpu/gpu.go +1 -1
@@ 650,7 650,7 @@ loop:
		case ops.TypeTransform:
			var op ui.TransformOp
			op.Decode(encOp.Data)
			state.t = state.t.Mul(op)
			state.t = state.t.Multiply(op)
		case ops.TypeAux:
			aux = encOp.Data[ops.TypeAuxLen:]
			auxKey = encOp.Key

M ui/app/internal/input/pointer.go => ui/app/internal/input/pointer.go +3 -3
@@ 88,7 88,7 @@ func (q *pointerQueue) collectHandlers(r *ui.OpsReader, events *handlerEvents, t
		case ops.TypeTransform:
			var op ui.TransformOp
			op.Decode(encOp.Data)
			t = t.Mul(op)
			t = t.Multiply(op)
		case ops.TypePointerHandler:
			var op pointer.HandlerOp
			op.Decode(encOp.Data, encOp.Refs)


@@ 150,7 150,7 @@ func (q *pointerQueue) hit(areaIdx int, p f32.Point) bool {
}

func (a *areaNode) hit(p f32.Point) bool {
	p = a.trans.InvTransform(p)
	p = a.trans.Invert().Transform(p)
	return a.area.Hit(p)
}



@@ 246,7 246,7 @@ func (q *pointerQueue) Push(e pointer.Event, events *handlerEvents) {
			e.Priority = pointer.Foremost
		}
		e.Hit = q.hit(h.area, e.Position)
		e.Position = h.transform.InvTransform(e.Position)
		e.Position = h.transform.Invert().Transform(e.Position)
		events.Add(k, e)
		if e.Type == pointer.Release {
			// Release grab when the number of grabs reaches zero.

M ui/ui.go => ui/ui.go +8 -4
@@ 56,19 56,23 @@ func (r *InvalidateOp) Decode(d []byte) {
	}
}

// Offset the transformation.
func (t TransformOp) Offset(o f32.Point) TransformOp {
	return t.Mul(TransformOp{o})
	return t.Multiply(TransformOp{o})
}

func (t TransformOp) InvTransform(p f32.Point) f32.Point {
	return p.Sub(t.offset)
// Invert the transformation.
func (t TransformOp) Invert() TransformOp {
	return TransformOp{offset: t.offset.Mul(-1)}
}

// Transform a point.
func (t TransformOp) Transform(p f32.Point) f32.Point {
	return p.Add(t.offset)
}

func (t TransformOp) Mul(t2 TransformOp) TransformOp {
// Multiply by a transformation.
func (t TransformOp) Multiply(t2 TransformOp) TransformOp {
	return TransformOp{
		offset: t.offset.Add(t2.offset),
	}