2017-01-01 15:12:12 -06:00
|
|
|
package pixel
|
|
|
|
|
2017-01-04 17:19:45 -06:00
|
|
|
import "image/color"
|
2017-01-01 15:12:12 -06:00
|
|
|
|
2017-01-04 17:19:45 -06:00
|
|
|
// 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.
|
2017-01-25 11:55:17 -06:00
|
|
|
//
|
2017-01-25 15:17:37 -06:00
|
|
|
// If no transforms are applied, the drawing area of a Target is the rectangle (-1, -1, +1, +1).
|
2017-01-01 15:12:12 -06:00
|
|
|
type Target interface {
|
2017-01-04 17:19:45 -06:00
|
|
|
// MakeTriangles generates a specialized copy of the provided Triangles.
|
|
|
|
//
|
2017-01-28 13:01:59 -06:00
|
|
|
// When calling Draw method on the returned TargetTriangles, the TargetTriangles will be
|
|
|
|
// drawn onto the Target that generated them.
|
2017-01-04 17:19:45 -06:00
|
|
|
//
|
2017-01-28 13:01:59 -06:00
|
|
|
// Note, that not every Target has to recognize all possible types of Triangles. Some may
|
2017-01-04 17:19:45 -06:00
|
|
|
// only recognize TrianglesPosition and TrianglesColor and ignore all other properties (if
|
2017-01-28 13:01:59 -06:00
|
|
|
// present) when making new TargetTriangles. This varies from Target to Target.
|
|
|
|
MakeTriangles(Triangles) TargetTriangles
|
2017-01-01 15:12:12 -06:00
|
|
|
|
2017-01-04 17:19:45 -06:00
|
|
|
// These are the most basic Target "adjustment" methods.
|
2017-01-05 08:13:59 -06:00
|
|
|
SetPicture(*Picture)
|
2017-01-04 17:19:45 -06:00
|
|
|
SetTransform(...Transform)
|
|
|
|
SetMaskColor(color.Color)
|
2017-01-01 15:12:12 -06:00
|
|
|
}
|
|
|
|
|
2017-01-04 17:19:45 -06:00
|
|
|
// 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
|
|
|
|
|
2017-01-28 13:01:59 -06:00
|
|
|
// 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).
|
2017-01-04 17:19:45 -06:00
|
|
|
//
|
2017-01-28 13:01:59 -06:00
|
|
|
// 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
|
2017-01-04 17:19:45 -06:00
|
|
|
|
|
|
|
// 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.
|
|
|
|
//
|
2017-01-28 13:01:59 -06:00
|
|
|
// The two Triangles need to have the same Len.
|
2017-01-04 17:19:45 -06:00
|
|
|
Update(Triangles)
|
2017-01-11 16:17:42 -06:00
|
|
|
|
2017-01-12 04:44:54 -06:00
|
|
|
// Copy creates an exact independent copy of this Triangles (with the same underlying type).
|
|
|
|
Copy() Triangles
|
2017-01-04 17:19:45 -06:00
|
|
|
}
|
|
|
|
|
2017-01-28 13:01:59 -06:00
|
|
|
// TargetTriangles are Triangles generated by a Target with MakeTriangles method. They can be drawn
|
|
|
|
// onto that Target.
|
|
|
|
type TargetTriangles interface {
|
|
|
|
Triangles
|
|
|
|
|
|
|
|
// Draw draws Triangles onto an associated Target.
|
|
|
|
Draw()
|
2017-01-04 17:19:45 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// TrianglesPosition specifies Triangles with Position property.
|
2017-01-12 06:50:06 -06:00
|
|
|
//
|
|
|
|
// Default value for a position is (0, 0).
|
2017-01-04 17:19:45 -06:00
|
|
|
type TrianglesPosition interface {
|
|
|
|
Triangles
|
|
|
|
Position(i int) Vec
|
|
|
|
}
|
|
|
|
|
|
|
|
// TrianglesColor specifies Triangles with Color property.
|
2017-01-12 06:50:06 -06:00
|
|
|
//
|
|
|
|
// Default value for a color is the white color.
|
2017-01-04 17:19:45 -06:00
|
|
|
type TrianglesColor interface {
|
|
|
|
Triangles
|
2017-01-12 18:07:04 -06:00
|
|
|
Color(i int) NRGBA
|
2017-01-04 17:19:45 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// TrianglesTexture specifies Triangles with Texture propery.
|
|
|
|
//
|
|
|
|
// Note that this represents texture coordinates, not an actual texture.
|
2017-01-12 06:50:06 -06:00
|
|
|
//
|
|
|
|
// Default value for a texture is (-1, -1), which means 'no texture'.
|
2017-01-04 17:19:45 -06:00
|
|
|
type TrianglesTexture interface {
|
|
|
|
Triangles
|
|
|
|
Texture(i int) Vec
|
2017-01-01 15:12:12 -06:00
|
|
|
}
|
2017-01-28 13:01:59 -06:00
|
|
|
|
|
|
|
// Drawer is something that can be drawn onto any Target.
|
|
|
|
type Drawer interface {
|
|
|
|
Draw(Target)
|
|
|
|
}
|