1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-17 18:06:03 -05:00
OpenDiablo2/d2core/d2gui/button.go
gravestench 6e31cfb52a
migrate to ebiten v2.0 API (#860)
* migrate to ebiten v2.0 API

* fixed lint errors
2020-10-28 14:17:42 -04:00

54 lines
923 B
Go

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) {
target.Render(b.surfaces[b.state])
}
func (b *Button) getSize() (width, height int) {
return b.width, b.height
}