2021-07-23 17:05:05 +10:00
|
|
|
package engine
|
|
|
|
|
2021-08-23 10:34:56 +10:00
|
|
|
import "image"
|
|
|
|
|
2021-08-01 17:08:26 +10:00
|
|
|
// ID implements Identifier directly (as a string value).
|
|
|
|
type ID string
|
|
|
|
|
|
|
|
// Ident returns id as a string.
|
|
|
|
func (id ID) Ident() string { return string(id) }
|
|
|
|
|
2021-08-23 10:34:56 +10:00
|
|
|
// Bounds implements Bounder directly (as an image.Rectangle value).
|
|
|
|
type Bounds image.Rectangle
|
|
|
|
|
|
|
|
// BoundingRect returns b as an image.Rectangle.
|
|
|
|
func (b Bounds) BoundingRect() image.Rectangle { return image.Rectangle(b) }
|
|
|
|
|
2021-08-23 11:10:46 +10:00
|
|
|
// Disabled implements Disabler directly (as a bool).
|
|
|
|
type Disabled bool
|
|
|
|
|
|
|
|
// IsHidden returns h as a bool.
|
|
|
|
func (d Disabled) IsDisabled() bool { return bool(d) }
|
|
|
|
|
|
|
|
// Hide sets h to true.
|
|
|
|
func (d *Disabled) Disable() { *d = true }
|
|
|
|
|
|
|
|
// Show sets h to false.
|
|
|
|
func (d *Disabled) Enable() { *d = false }
|
|
|
|
|
2021-08-23 10:34:56 +10:00
|
|
|
// Hidden implements Hider directly (as a bool).
|
|
|
|
type Hidden bool
|
|
|
|
|
|
|
|
// IsHidden returns h as a bool.
|
|
|
|
func (h Hidden) IsHidden() bool { return bool(h) }
|
|
|
|
|
|
|
|
// Hide sets h to true.
|
|
|
|
func (h *Hidden) Hide() { *h = true }
|
|
|
|
|
|
|
|
// Show sets h to false.
|
|
|
|
func (h *Hidden) Show() { *h = false }
|
|
|
|
|
2021-09-02 15:55:38 +10:00
|
|
|
// ZOrder implements DrawOrder (in Drawer) directly (as an int value).
|
|
|
|
type ZOrder int
|
2021-07-23 17:05:05 +10:00
|
|
|
|
2021-09-02 15:55:38 +10:00
|
|
|
// DrawOrder returns z as a int with 0 bias.
|
|
|
|
func (z ZOrder) DrawOrder() (int, int) { return int(z), 0 }
|
2021-08-26 13:54:22 +10:00
|
|
|
|
2021-09-02 13:42:44 +10:00
|
|
|
// ---------- Some helpers for image.Point ----------
|
2021-08-26 13:54:22 +10:00
|
|
|
|
2021-09-02 13:42:44 +10:00
|
|
|
// cmul performs componentwise multiplication of two image.Points.
|
|
|
|
func cmul(p, q image.Point) image.Point {
|
|
|
|
return image.Point{p.X * q.X, p.Y * q.Y}
|
2021-08-26 13:54:22 +10:00
|
|
|
}
|
|
|
|
|
2021-09-02 13:42:44 +10:00
|
|
|
// cdiv performs componentwise division of two image.Points.
|
|
|
|
func cdiv(p, q image.Point) image.Point {
|
|
|
|
return image.Point{p.X / q.X, p.Y / q.Y}
|
2021-08-26 13:54:22 +10:00
|
|
|
}
|
|
|
|
|
2021-09-02 13:42:44 +10:00
|
|
|
// cfloat returns the components of an image.Point as two floats.
|
|
|
|
func cfloat(p image.Point) (x, y float64) {
|
2021-08-26 13:54:22 +10:00
|
|
|
return float64(p.X), float64(p.Y)
|
|
|
|
}
|
2021-09-02 15:55:38 +10:00
|
|
|
|
|
|
|
// dot returns the dot product of two image.Points.
|
|
|
|
func dot(p, q image.Point) int {
|
|
|
|
return p.X*q.X + p.Y*q.Y
|
|
|
|
}
|