viewer ui improvements
This commit is contained in:
parent
9eac33ef79
commit
188d824ca0
@ -20,7 +20,7 @@ var state struct {
|
||||
windows []*Window
|
||||
}
|
||||
|
||||
type Handle uint32
|
||||
type Handle uintptr
|
||||
|
||||
type Scene interface {
|
||||
Init(window *Window) error
|
||||
|
@ -26,7 +26,7 @@ func newTextureFromRgba(colors []color.RGBA, width, height int) (*Texture, error
|
||||
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(width), int32(height), 0, gl.RGBA, gl.UNSIGNED_BYTE, unsafe.Pointer(&colors[0]))
|
||||
|
||||
gl.BindTexture(gl.TEXTURE_2D, uint32(glHandleLast))
|
||||
return &Texture{math.Vec2i{width, height}, glHandle}, nil
|
||||
return &Texture{size: math.Vec2i{X: width, Y: height}, glHandle: glHandle}, nil
|
||||
}
|
||||
|
||||
func (t *Texture) Handle() Handle {
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
imgui "github.com/FooSoft/imgui-go"
|
||||
"github.com/FooSoft/lazarus/formats/dat"
|
||||
"github.com/FooSoft/lazarus/formats/dc6"
|
||||
"github.com/FooSoft/lazarus/math"
|
||||
"github.com/FooSoft/lazarus/platform"
|
||||
)
|
||||
|
||||
@ -60,18 +59,36 @@ func (s *scene) Advance(window *platform.Window) error {
|
||||
frameIndex = s.frameIndex
|
||||
)
|
||||
|
||||
if s.texture == nil {
|
||||
if err := s.updateTexture(window); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
imgui.Begin("DC6 Viewer")
|
||||
size := s.texture.Size()
|
||||
imgui.Image(imgui.TextureID(s.texture.Handle()), imgui.Vec2{X: float32(size.X), Y: float32(size.Y)})
|
||||
direction := s.sprite.Directions[directionIndex]
|
||||
if imgui.SliderInt("Direction", &directionIndex, 0, int32(len(s.sprite.Directions))-1) {
|
||||
frameIndex = 0
|
||||
}
|
||||
frame := direction.Frames[frameIndex]
|
||||
imgui.SliderInt("Frame", &frameIndex, 0, int32(len(direction.Frames))-1)
|
||||
imgui.Text(fmt.Sprintf("Height: %d", frame.Height))
|
||||
imgui.Text(fmt.Sprintf("Width: %d", frame.Width))
|
||||
imgui.Text(fmt.Sprintf("OffsetX: %d", frame.OffsetX))
|
||||
imgui.Text(fmt.Sprintf("OffsetY: %d", frame.OffsetY))
|
||||
imgui.Text(fmt.Sprintf("Size: %dx%d", frame.Width, frame.Height))
|
||||
imgui.Text(fmt.Sprintf("Offset: %dx%d", frame.OffsetX, frame.OffsetY))
|
||||
|
||||
if s.texture == nil || directionIndex != s.directionIndex || frameIndex != s.frameIndex {
|
||||
if directionIndex != s.directionIndex || frameIndex != s.frameIndex {
|
||||
s.directionIndex = directionIndex
|
||||
s.frameIndex = frameIndex
|
||||
s.updateTexture(window)
|
||||
}
|
||||
|
||||
imgui.End()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *scene) updateTexture(window *platform.Window) error {
|
||||
frame := s.sprite.Directions[s.directionIndex].Frames[s.frameIndex]
|
||||
colors := make([]color.RGBA, frame.Width*frame.Height)
|
||||
for y := 0; y < frame.Height; y++ {
|
||||
for x := 0; x < frame.Width; x++ {
|
||||
@ -79,17 +96,17 @@ func (s *scene) Advance(window *platform.Window) error {
|
||||
}
|
||||
}
|
||||
|
||||
if s.texture != nil {
|
||||
if err := s.texture.Destroy(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var err error
|
||||
s.texture, err = window.CreateTextureRgba(colors, frame.Width, frame.Height)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
window.RenderTexture(s.texture, math.Vec2i{X: 0, Y: 0})
|
||||
|
||||
s.directionIndex = directionIndex
|
||||
s.frameIndex = frameIndex
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user