~eliasnaur/gio

ref: 48b6a73753e7ee567154297987f24a4d10485999 gio/ui/draw/draw.go -rw-r--r-- 885 bytes
48b6a737Elias Naur all: run goimports 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: Unlicense OR MIT

package draw

import (
	"image"
	"math"

	"gioui.org/ui"
	"gioui.org/ui/f32"
	"gioui.org/ui/internal/path"
)

type OpImage struct {
	Rect    f32.Rectangle
	Src     image.Image
	SrcRect image.Rectangle
}

func (OpImage) ImplementsOp() {}

// ClipRect returns a special case of OpClip
// that clips to a pixel aligned rectangular area.
func ClipRect(r image.Rectangle, op ui.Op) OpClip {
	return OpClip{
		Path: &Path{
			data: &path.Path{
				Bounds: toRectF(r),
			},
		},
		Op: op,
	}
}

func itof(i int) float32 {
	switch i {
	case ui.Inf:
		return float32(math.Inf(+1))
	case -ui.Inf:
		return float32(math.Inf(-1))
	default:
		return float32(i)
	}
}

func toRectF(r image.Rectangle) f32.Rectangle {
	return f32.Rectangle{
		Min: f32.Point{X: itof(r.Min.X), Y: itof(r.Min.Y)},
		Max: f32.Point{X: itof(r.Max.X), Y: itof(r.Max.Y)},
	}
}