~eliasnaur/gio

ref: fc7c5c13f4fb128f69bdd3c7c4b90d6801e809ba gio/ui/draw/draw.go -rw-r--r-- 885 bytes
fc7c5c13Elias Naur README.md: add EGL development package to Linux requirements 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/f32"
	"gioui.org/ui/internal/path"
	"gioui.org/ui"
)

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)},
	}
}