1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-05 17:57:17 -05:00
OpenDiablo2/d2core/d2gui/button.go

51 lines
933 B
Go
Raw Normal View History

package d2gui
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
)
type buttonState int
const (
buttonStateDefault buttonState = iota
buttonStatePressed
buttonStatePressedToggled
)
const (
grey = 0x404040ff
)
// Button is a user actionable drawable toggle switch
type Button struct {
widgetBase
width int
height int
state buttonState
surfaces []d2interface.Surface
}
func (b *Button) onMouseButtonDown(_ d2interface.MouseEvent) bool {
b.state = buttonStatePressed
return false
}
func (b *Button) onMouseButtonUp(_ d2interface.MouseEvent) bool {
b.state = buttonStateDefault
return false
}
func (b *Button) onMouseLeave(_ d2interface.MouseMoveEvent) bool {
b.state = buttonStateDefault
return false
}
func (b *Button) render(target d2interface.Surface) error {
return target.Render(b.surfaces[b.state])
}
func (b *Button) getSize() (width, height int) {
return b.width, b.height
}