2023-02-17 23:51:40 +03:00
|
|
|
package gx
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
|
|
"image"
|
|
|
|
_ "image/png"
|
|
|
|
"io"
|
2023-05-22 23:39:01 +03:00
|
|
|
"math"
|
2023-02-17 23:51:40 +03:00
|
|
|
)
|
|
|
|
|
2023-05-22 23:39:01 +03:00
|
|
|
type ColorV uint32
|
2023-02-17 23:51:40 +03:00
|
|
|
type Image = ebiten.Image
|
2023-05-22 23:39:01 +03:00
|
|
|
type ColorM = ebiten.ColorM
|
|
|
|
type Color struct {
|
|
|
|
R, G, B, A ColorV
|
|
|
|
}
|
2023-02-17 23:51:40 +03:00
|
|
|
|
|
|
|
// The interface describes anything that can be
|
|
|
|
// drawn. It will be drew corresponding to
|
|
|
|
// the layers order.
|
|
|
|
type Drawer interface {
|
|
|
|
Draw(*Engine, *Image)
|
2023-06-03 10:39:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type Visibler interface {
|
2023-05-23 16:19:55 +03:00
|
|
|
IsVisible() bool
|
2023-02-17 23:51:40 +03:00
|
|
|
}
|
|
|
|
|
2023-05-22 23:39:01 +03:00
|
|
|
const (
|
|
|
|
MaxColorV = math.MaxUint32
|
|
|
|
)
|
|
|
|
|
2023-02-17 23:51:40 +03:00
|
|
|
func LoadImage(input io.Reader) (*Image, error) {
|
|
|
|
img, _, err := image.Decode(input)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ret := ebiten.NewImageFromImage(img)
|
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
|
2023-05-30 14:34:10 +03:00
|
|
|
func NewImage(w, h int) (*Image) {
|
|
|
|
return ebiten.NewImage(w, h)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-22 23:39:01 +03:00
|
|
|
func (c Color) RGBA() (r, g, b, a uint32) {
|
|
|
|
return uint32(c.R), uint32(c.G), uint32(c.B), uint32(c.A)
|
|
|
|
}
|
|
|
|
|