2020-02-24 22:35:21 -05:00
|
|
|
package d2gui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2020-07-18 18:06:36 -04:00
|
|
|
"image/color"
|
2020-02-24 22:35:21 -05:00
|
|
|
|
2020-06-29 00:41:58 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
|
|
|
)
|
|
|
|
|
2020-07-05 15:56:48 -04:00
|
|
|
func loadFont(fontStyle FontStyle) (d2interface.Font, error) {
|
2020-02-24 22:35:21 -05:00
|
|
|
config, ok := fontStyleConfigs[fontStyle]
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("invalid font style")
|
|
|
|
}
|
|
|
|
|
|
|
|
return d2asset.LoadFont(config.fontBasePath+".tbl", config.fontBasePath+".dc6", config.palettePath)
|
|
|
|
}
|
|
|
|
|
2020-07-05 13:01:44 -04:00
|
|
|
func renderSegmented(animation d2interface.Animation, segmentsX, segmentsY, frameOffset int,
|
|
|
|
target d2interface.Surface) error {
|
2020-02-24 22:35:21 -05:00
|
|
|
var currentY int
|
2020-07-18 18:06:36 -04:00
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
for y := 0; y < segmentsY; y++ {
|
2020-07-18 18:06:36 -04:00
|
|
|
var currentX, maxHeight int
|
|
|
|
|
2020-02-24 22:35:21 -05: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)
|
|
|
|
err := animation.Render(target)
|
|
|
|
target.Pop()
|
2020-07-18 18:06:36 -04:00
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
width, height := animation.GetCurrentFrameSize()
|
|
|
|
maxHeight = d2common.MaxInt(maxHeight, height)
|
|
|
|
currentX += width
|
|
|
|
}
|
|
|
|
|
|
|
|
currentY += maxHeight
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2020-07-18 18:06:36 -04:00
|
|
|
|
|
|
|
func half(n int) int {
|
|
|
|
return n / 2
|
|
|
|
}
|
|
|
|
|
|
|
|
func rgbaColor(rgba uint32) color.RGBA {
|
|
|
|
result := color.RGBA{}
|
|
|
|
a, b, g, r := 0, 1, 2, 3
|
|
|
|
byteWidth := 8
|
|
|
|
byteMask := 0xff
|
|
|
|
|
|
|
|
for idx := 0; idx < 4; idx++ {
|
|
|
|
shift := idx * byteWidth
|
|
|
|
component := uint8(rgba>>shift) & uint8(byteMask)
|
|
|
|
|
|
|
|
switch idx {
|
|
|
|
case a:
|
|
|
|
result.A = component
|
|
|
|
case b:
|
|
|
|
result.B = component
|
|
|
|
case g:
|
|
|
|
result.G = component
|
|
|
|
case r:
|
|
|
|
result.R = component
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|