forked from faiface/pixel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
128 lines (107 loc) · 4.5 KB
/
interface.go
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package pixel
import "image/color"
// Target is something that can be drawn onto, such as a window, a canvas, and so on.
//
// You can notice, that there are no "drawing" methods in a Target. That's because all drawing
// happens indirectly through Triangles instance generated via MakeTriangles method.
//
// If no transforms are applied, the drawing area of a Target is the rectangle (-1, -1, +1, +1).
type Target interface {
// MakeTriangles generates a specialized copy of the provided Triangles.
//
// When calling Draw method on the returned TargetTriangles, the TargetTriangles will be
// drawn onto the Target that generated them.
//
// Note, that not every Target has to recognize all possible types of Triangles. Some may
// only recognize TrianglesPosition and TrianglesColor and ignore all other properties (if
// present) when making new TargetTriangles. This varies from Target to Target.
MakeTriangles(Triangles) TargetTriangles
//TODO: doc
MakePicture(Picture) TargetPicture
}
// BasicTarget is a Target with additional basic "adjustment" methods.
type BasicTarget interface {
Target
// SetTransform sets a Transform that transforms the TrianglesPosition property of all
// Triangles.
SetTransform(...Transform)
// SetMColorMask sets a color that will be multiplied with the TrianglesColor property of all
// Triangles.
SetColorMask(color.Color)
}
// Triangles represents a list of vertices, where each three vertices form a triangle. (First,
// second and third is the first triangle, fourth, fifth and sixth is the second triangle, etc.)
type Triangles interface {
// Len returns the number of vertices. The number of triangles is the number of vertices
// divided by 3.
Len() int
// SetLen resizes Triangles to len vertices. If Triangles B were obtained by calling Slice
// method on Triangles A, the relationship between A and B is undefined after calling SetLen
// on either one of them.
SetLen(len int)
// Slice returns a sub-Triangles of this Triangles, covering vertices in range [i, j).
//
// If Triangles B were obtained by calling Slice(4, 9) on Triangles A, then A and B must
// share the same underlying data. Modifying B must change the contents of A in range
// [4, 9). The vertex with index 0 at B is the vertex with index 4 in A, and so on.
//
// Returned Triangles must have the same underlying type.
Slice(i, j int) Triangles
// Update copies vertex properties from the supplied Triangles into this Triangles.
//
// Properies not supported by these Triangles should be ignored. Properties not supported by
// the supplied Triangles should be left untouched.
//
// The two Triangles need to have the same Len.
Update(Triangles)
// Copy creates an exact independent copy of this Triangles (with the same underlying type).
Copy() Triangles
}
// TargetTriangles are Triangles generated by a Target with MakeTriangles method. They can be drawn
// onto that (no other) Target.
type TargetTriangles interface {
Triangles
// Draw draws Triangles onto an associated Target.
Draw()
}
// TrianglesPosition specifies Triangles with Position property.
type TrianglesPosition interface {
Triangles
Position(i int) Vec
}
// TrianglesColor specifies Triangles with Color property.
type TrianglesColor interface {
Triangles
Color(i int) NRGBA
}
// TrianglesPicture specifies Triangles with Picture propery.
//
// Note that this represents picture coordinates, not an actual picture.
type TrianglesPicture interface {
Triangles
Picture(i int) Vec
}
// Picture represents a rectangular area of raster data, such as a color. It has Bounds which
// specify the rectangle where data is located.
type Picture interface {
// Bounds returns the rectangle of the Picture. All data is located witih this rectangle.
// Querying properties outside the rectangle should return default value of that property.
Bounds() Rect
// Slice returns a sub-Picture with specified Bounds.
Slice(Rect) Picture
}
// TargetPicture is a Picture generated by a Target using MakePicture method. This Picture can be drawn onto
// that (no other) Target together with a TargetTriangles generated by the same Target.
//
// The TargetTriangles specify where, shape and how the Picture should be drawn.
type TargetPicture interface {
Picture
Draw(TargetTriangles)
}
// PictureColor specifies Picture with Color property, so that every position inside the Picture's
// Bounds has a color.
//
// Positions outside the Picture's Bounds must return opaque white (NRGBA{R: 1, G: 1, B:1, A: 1}).
type PictureColor interface {
Color(at Vec) NRGBA
}