ichigo/engine/misc.go

70 lines
1.6 KiB
Go
Raw Normal View History

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-09-13 16:50:35 +10:00
// Disables implements Disabler directly (as a bool).
type Disables bool
2021-08-23 11:10:46 +10:00
2021-09-13 16:50:35 +10:00
// Disabled returns d as a bool.
func (d Disables) Disabled() bool { return bool(d) }
2021-08-23 11:10:46 +10:00
2021-09-13 16:50:35 +10:00
// Disable sets d to true.
func (d *Disables) Disable() { *d = true }
2021-08-23 11:10:46 +10:00
2021-09-13 16:50:35 +10:00
// Enable sets d to false.
func (d *Disables) Enable() { *d = false }
2021-08-23 11:10:46 +10:00
2021-09-13 16:50:35 +10:00
// Hides implements Hider directly (as a bool).
type Hides bool
2021-08-23 10:34:56 +10:00
2021-09-13 16:50:35 +10:00
// Hidden returns h as a bool.
func (h Hides) Hidden() bool { return bool(h) }
2021-08-23 10:34:56 +10:00
// Hide sets h to true.
2021-09-13 16:50:35 +10:00
func (h *Hides) Hide() { *h = true }
2021-08-23 10:34:56 +10:00
// Show sets h to false.
2021-09-13 16:50:35 +10:00
func (h *Hides) Show() { *h = false }
2021-08-23 10:34:56 +10:00
2021-09-11 17:53:31 +10:00
// ZPosition implements DrawAfter and DrawBefore using only Z information.
2021-09-10 17:18:20 +10:00
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 {
2021-09-11 17:53:31 +10:00
switch x := x.(type) {
2021-09-10 17:18:20 +10:00
case BoundingBoxer:
2021-09-11 17:53:31 +10:00
return int(z) >= x.BoundingBox().Max.Z
case ZPositioner:
return z.ZPos() > x.ZPos()
2021-09-10 17:18:20 +10:00
}
return false
}
2021-09-11 13:00:23 +10:00
// DrawBefore reports if z < x.Min.Z.
func (z ZPosition) DrawBefore(x Drawer) bool {
2021-09-11 17:53:31 +10:00
switch x := x.(type) {
2021-09-11 13:00:23 +10:00
case BoundingBoxer:
2021-09-11 17:53:31 +10:00
return int(z) < x.BoundingBox().Min.Z
case ZPositioner:
return z.ZPos() < x.ZPos()
2021-09-11 13:00:23 +10:00
}
return false
}
2021-09-11 17:53:31 +10:00
// ZPos returns itself.
func (z ZPosition) ZPos() int { return int(z) }