2020-02-24 19:35:21 -08:00
|
|
|
package d2gui
|
|
|
|
|
|
|
|
import (
|
2020-06-28 21:41:58 -07:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
2020-08-05 10:51:19 -07:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math"
|
2020-02-24 19:35:21 -08:00
|
|
|
)
|
|
|
|
|
2020-07-05 10:01:44 -07:00
|
|
|
func renderSegmented(animation d2interface.Animation, segmentsX, segmentsY, frameOffset int,
|
|
|
|
target d2interface.Surface) error {
|
2020-02-24 19:35:21 -08:00
|
|
|
var currentY int
|
2020-07-18 15:06:36 -07:00
|
|
|
|
2020-02-24 19:35:21 -08:00
|
|
|
for y := 0; y < segmentsY; y++ {
|
2020-07-18 15:06:36 -07:00
|
|
|
var currentX, maxHeight int
|
|
|
|
|
2020-02-24 19:35:21 -08:00
|
|
|
for x := 0; x < segmentsX; x++ {
|
|
|
|
if err := animation.SetCurrentFrame(x + y*segmentsX + frameOffset*segmentsX*segmentsY); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
target.PushTranslation(x+currentX, y+currentY)
|
2020-10-28 18:17:42 +00:00
|
|
|
animation.Render(target)
|
2020-02-24 19:35:21 -08:00
|
|
|
target.Pop()
|
2020-07-18 15:06:36 -07:00
|
|
|
|
2020-02-24 19:35:21 -08:00
|
|
|
width, height := animation.GetCurrentFrameSize()
|
2020-08-04 21:03:33 -07:00
|
|
|
maxHeight = d2math.MaxInt(maxHeight, height)
|
2020-02-24 19:35:21 -08:00
|
|
|
currentX += width
|
|
|
|
}
|
|
|
|
|
|
|
|
currentY += maxHeight
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2020-07-18 15:06:36 -07:00
|
|
|
|
|
|
|
func half(n int) int {
|
2021-02-02 12:00:31 +01:00
|
|
|
// nolint:gomnd // half is half
|
2020-07-18 15:06:36 -07:00
|
|
|
return n / 2
|
|
|
|
}
|