34 lines
631 B
Go
34 lines
631 B
Go
package application
|
|
|
|
import (
|
|
"image"
|
|
"math"
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
)
|
|
|
|
type canvas struct {
|
|
w, h int
|
|
|
|
x, y float64 // View position
|
|
|
|
img *ebiten.Image
|
|
|
|
scale float64
|
|
}
|
|
|
|
func NewCanvas(w, h int) *canvas {
|
|
return &canvas{
|
|
w: w,
|
|
h: h,
|
|
img: ebiten.NewImage(w, h),
|
|
scale: 1,
|
|
}
|
|
}
|
|
|
|
func (c *canvas) pixelScreenRect(x, y int) image.Rectangle {
|
|
rx, ry := (float64(x)-c.x)*c.scale, (float64(y)-c.y)*c.scale
|
|
rxCorner, ryCorner := (float64(x+1)-c.x)*c.scale, (float64(y+1)-c.y)*c.scale
|
|
return image.Rect(int(math.Floor(rx)), int(math.Floor(ry)), int(math.Ceil(rxCorner)), int(math.Ceil(ryCorner)))
|
|
}
|