2020-02-24 22:35:21 -05:00
|
|
|
package d2gui
|
|
|
|
|
|
|
|
import (
|
2020-06-29 00:41:58 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
2020-02-24 22:35:21 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type buttonState int
|
|
|
|
|
|
|
|
const (
|
|
|
|
buttonStateDefault buttonState = iota
|
|
|
|
buttonStatePressed
|
|
|
|
buttonStatePressedToggled
|
|
|
|
)
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
const (
|
|
|
|
grey = 0x404040ff
|
|
|
|
)
|
|
|
|
|
2020-07-07 20:16:22 -04:00
|
|
|
// Button is a user actionable drawable toggle switch
|
2020-02-24 22:35:21 -05:00
|
|
|
type Button struct {
|
|
|
|
widgetBase
|
|
|
|
|
|
|
|
width int
|
|
|
|
height int
|
|
|
|
state buttonState
|
2020-06-29 00:41:58 -04:00
|
|
|
surfaces []d2interface.Surface
|
2020-02-24 22:35:21 -05:00
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
func (b *Button) onMouseButtonDown(_ d2interface.MouseEvent) bool {
|
2020-02-24 22:35:21 -05:00
|
|
|
b.state = buttonStatePressed
|
2020-10-22 01:12:06 -04:00
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
func (b *Button) onMouseButtonUp(_ d2interface.MouseEvent) bool {
|
2020-02-24 22:35:21 -05:00
|
|
|
b.state = buttonStateDefault
|
2020-10-22 01:12:06 -04:00
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
func (b *Button) onMouseLeave(_ d2interface.MouseMoveEvent) bool {
|
2020-02-24 22:35:21 -05:00
|
|
|
b.state = buttonStateDefault
|
2020-10-22 01:12:06 -04:00
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-10-28 14:17:42 -04:00
|
|
|
func (b *Button) render(target d2interface.Surface) {
|
|
|
|
target.Render(b.surfaces[b.state])
|
2020-02-24 22:35:21 -05:00
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
func (b *Button) getSize() (width, height int) {
|
2020-02-24 22:35:21 -05:00
|
|
|
return b.width, b.height
|
|
|
|
}
|