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-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.
|
|
|
|
//
|
|
|
|
// When calling Draw method on the returned Triangles, the Triangles 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 Triangles. This varies from Target to Target.
|
|
|
|
MakeTriangles(Triangles) Triangles
|
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
|
|
|
|
|
|
|
|
// Draw draws Triangles onto an associated Target (if any).
|
|
|
|
//
|
|
|
|
// Note, that this method does not have to be implemented, however it is always implemented
|
|
|
|
// for Triangles generated by a Target.
|
|
|
|
Draw()
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// If these Triangles and supplied Triangles have different lengths, these Triangles should
|
|
|
|
// be resized.
|
|
|
|
Update(Triangles)
|
2017-01-11 16:17:42 -06:00
|
|
|
|
|
|
|
// Append adds supplied Triangles to the end of these Triangles.
|
|
|
|
//
|
|
|
|
// Behavior regarding unsupported properties should be same as with Update.
|
|
|
|
Append(Triangles)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// Drawer is something that can be drawn onto any Target.
|
2017-01-01 15:12:12 -06:00
|
|
|
type Drawer interface {
|
2017-01-04 17:19:45 -06:00
|
|
|
Draw(Target)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
Color(i int) color.Color
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|