Debian Codegraph @

vendor/github.com/xyproto/gfx/interfaces.go

raw
1 package gfx
2
3 import "image/color"
4
5 // Target is something that can be drawn onto, such as a window, a canvas, and so on.
6 //
7 // You can notice, that there are no "drawing" methods in a Target. That's because all drawing
8 // happens indirectly through Triangles and Picture instances generated via MakeTriangles and
9 // MakePicture method.
10 type Target interface {
11 // MakeTriangles generates a specialized copy of the provided Triangles.
12 //
13 // When calling Draw method on the returned TargetTriangles, the TargetTriangles will be
14 // drawn onto the Target that generated them.
15 //
16 // Note, that not every Target has to recognize all possible types of Triangles. Some may
17 // only recognize TrianglesPosition and TrianglesColor and ignore all other properties (if
18 // present) when making new TargetTriangles. This varies from Target to Target.
19 MakeTriangles(Triangles) TargetTriangles
20
21 // MakePicture generates a specialized copy of the provided Picture.
22 //
23 // When calling Draw method on the returned TargetPicture, the TargetPicture will be drawn
24 // onto the Target that generated it together with the TargetTriangles supplied to the Draw
25 // method.
26 MakePicture(Picture) TargetPicture
27 }
28
29 // BasicTarget is a Target with additional basic adjustment methods.
30 type BasicTarget interface {
31 Target
32
33 // SetMatrix sets a Matrix that every point will be projected by.
34 SetMatrix(Matrix)
35 }
36
37 // Triangles represents a list of vertices, where each three vertices form a triangle. (First,
38 // second and third is the first triangle, fourth, fifth and sixth is the second triangle, etc.)
39 type Triangles interface {
40 // Len returns the number of vertices. The number of triangles is the number of vertices
41 // divided by 3.
42 Len() int
43
44 // SetLen resizes Triangles to len vertices. If Triangles B were obtained by calling Slice
45 // method on Triangles A, the relationship between A and B is undefined after calling SetLen
46 // on either one of them.
47 SetLen(len int)
48
49 // Slice returns a sub-Triangles of this Triangles, covering vertices in range [i, j).
50 //
51 // If Triangles B were obtained by calling Slice(4, 9) on Triangles A, then A and B must
52 // share the same underlying data. Modifying B must change the contents of A in range
53 // [4, 9). The vertex with index 0 at B is the vertex with index 4 in A, and so on.
54 //
55 // Returned Triangles must have the same underlying type.
56 Slice(i, j int) Triangles
57
58 // Update copies vertex properties from the supplied Triangles into this Triangles.
59 //
60 // Properties not supported by these Triangles should be ignored. Properties not supported by
61 // the supplied Triangles should be left untouched.
62 //
63 // The two Triangles must have the same Len.
64 Update(Triangles)
65
66 // Copy creates an exact independent copy of this Triangles (with the same underlying type).
67 Copy() Triangles
68 }
69
70 // TargetTriangles are Triangles generated by a Target with MakeTriangles method. They can be drawn
71 // onto that (no other) Target.
72 type TargetTriangles interface {
73 Triangles
74
75 // Draw draws Triangles onto an associated Target.
76 Draw()
77 }
78
79 // TrianglesPosition specifies Triangles with Position property.
80 type TrianglesPosition interface {
81 Triangles
82 Position(i int) Vec
83 }
84
85 // TrianglesColor specifies Triangles with Color property.
86 type TrianglesColor interface {
87 Triangles
88 Color(i int) color.NRGBA
89 }
90
91 // TrianglesPicture specifies Triangles with Picture propery.
92 //
93 // The first value returned from Picture method is Picture coordinates. The second one specifies the
94 // weight of the Picture. Value of 0 means, that Picture should be completely ignored, 1 means that
95 // is should be fully included and anything in between means anything in between.
96 type TrianglesPicture interface {
97 Triangles
98 Picture(i int) (pic Vec, intensity float64)
99 }
100
101 // Picture represents a rectangular area of raster data, such as a color. It has Bounds which
102 // specify the rectangle where data is located.
103 type Picture interface {
104 // Bounds returns the rectangle of the Picture. All data is located witih this rectangle.
105 // Querying properties outside the rectangle should return default value of that property.
106 Bounds() Rect
107 }
108
109 // TargetPicture is a Picture generated by a Target using MakePicture method. This Picture can be drawn onto
110 // that (no other) Target together with a TargetTriangles generated by the same Target.
111 //
112 // The TargetTriangles specify where, shape and how the Picture should be drawn.
113 type TargetPicture interface {
114 Picture
115
116 // Draw draws the supplied TargetTriangles (which must be generated by the same Target as
117 // this TargetPicture) with this TargetPicture. The TargetTriangles should utilize the data
118 // from this TargetPicture in some way.
119 Draw(TargetTriangles)
120 }
121
122 // PictureColor specifies Picture with Color property, so that every position inside the Picture's
123 // Bounds has a color.
124 //
125 // Positions outside the Picture's Bounds must return full transparent (Alpha(0)).
126 type PictureColor interface {
127 Picture
128 Color(at Vec) color.NRGBA
129 }
130
131 // Float64Scaler can scale a float64 to another float64.
132 type Float64Scaler interface {
133 ScaleFloat64(float64) float64
134 }