2021-07-23 17:05:05 +10:00
|
|
|
package engine
|
|
|
|
|
2021-09-08 17:08:21 +10:00
|
|
|
import (
|
|
|
|
"image"
|
|
|
|
)
|
2021-08-23 10:34:56 +10:00
|
|
|
|
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-10 17:18:20 +10:00
|
|
|
// ZPosition implements DrawAfter and DrawPosition as a simple Z coordinate.
|
|
|
|
type ZPosition int
|
|
|
|
|
2021-09-11 13:00:23 +10:00
|
|
|
// DrawAfter reports if z >= x.Max.Z.
|
2021-09-10 17:18:20 +10:00
|
|
|
func (z ZPosition) DrawAfter(x Drawer) bool {
|
|
|
|
switch d := x.(type) {
|
|
|
|
case BoundingBoxer:
|
2021-09-11 13:00:23 +10:00
|
|
|
return int(z) >= d.BoundingBox().Max.Z
|
2021-09-10 17:18:20 +10:00
|
|
|
case zpositioner:
|
|
|
|
return z.zposition() > d.zposition()
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-09-11 13:00:23 +10:00
|
|
|
// DrawBefore reports if z < x.Min.Z.
|
|
|
|
func (z ZPosition) DrawBefore(x Drawer) bool {
|
|
|
|
switch d := x.(type) {
|
|
|
|
case BoundingBoxer:
|
|
|
|
return int(z) < d.BoundingBox().Min.Z
|
|
|
|
case zpositioner:
|
|
|
|
return z.zposition() < d.zposition()
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-09-10 17:18:20 +10:00
|
|
|
func (z ZPosition) zposition() int { return int(z) }
|
|
|
|
|
|
|
|
type zpositioner interface {
|
|
|
|
zposition() int
|
|
|
|
}
|