2020-02-17 22:11:52 -05:00
|
|
|
package d2gui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MouseHandler func(d2input.MouseEvent)
|
|
|
|
type MouseMoveHandler func(d2input.MouseMoveEvent)
|
|
|
|
|
|
|
|
type widget interface {
|
|
|
|
render(target d2render.Surface) error
|
|
|
|
advance(elapsed float64) error
|
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
onMouseMove(event d2input.MouseMoveEvent) bool
|
|
|
|
onMouseEnter(event d2input.MouseMoveEvent) bool
|
|
|
|
onMouseLeave(event d2input.MouseMoveEvent) bool
|
|
|
|
onMouseOver(event d2input.MouseMoveEvent) bool
|
|
|
|
onMouseButtonDown(event d2input.MouseEvent) bool
|
|
|
|
onMouseButtonUp(event d2input.MouseEvent) bool
|
|
|
|
onMouseButtonClick(event d2input.MouseEvent) bool
|
2020-02-17 22:11:52 -05:00
|
|
|
|
|
|
|
getPosition() (int, int)
|
2020-06-25 16:27:16 -04:00
|
|
|
setOffset(x, y int)
|
2020-02-17 22:11:52 -05:00
|
|
|
getSize() (int, int)
|
|
|
|
getLayer() int
|
|
|
|
isVisible() bool
|
2020-02-24 22:35:21 -05:00
|
|
|
isExpanding() bool
|
2020-02-17 22:11:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type widgetBase struct {
|
2020-02-24 22:35:21 -05:00
|
|
|
x int
|
|
|
|
y int
|
|
|
|
layer int
|
|
|
|
visible bool
|
|
|
|
expanding bool
|
2020-02-17 22:11:52 -05:00
|
|
|
|
2020-06-25 16:27:16 -04:00
|
|
|
offsetX int
|
|
|
|
offsetY int
|
|
|
|
|
2020-02-17 22:11:52 -05:00
|
|
|
mouseEnterHandler MouseMoveHandler
|
|
|
|
mouseLeaveHandler MouseMoveHandler
|
|
|
|
mouseClickHandler MouseHandler
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *widgetBase) SetPosition(x, y int) {
|
|
|
|
w.x = x
|
|
|
|
w.y = y
|
|
|
|
}
|
|
|
|
|
2020-06-25 16:27:16 -04:00
|
|
|
func (w *widgetBase) GetPosition() (int, int) {
|
|
|
|
return w.x, w.y
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *widgetBase) GetOffset() (int, int) {
|
|
|
|
return w.offsetX, w.offsetY
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *widgetBase) setOffset(x, y int) {
|
|
|
|
w.offsetX = x
|
|
|
|
w.offsetY = y
|
|
|
|
}
|
|
|
|
|
2020-02-17 22:11:52 -05:00
|
|
|
func (w *widgetBase) SetLayer(layer int) {
|
|
|
|
w.layer = layer
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *widgetBase) SetVisible(visible bool) {
|
|
|
|
w.visible = visible
|
|
|
|
}
|
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
func (w *widgetBase) SetExpanding(expanding bool) {
|
|
|
|
w.expanding = expanding
|
|
|
|
}
|
|
|
|
|
2020-02-17 22:11:52 -05:00
|
|
|
func (w *widgetBase) SetMouseEnterHandler(handler MouseMoveHandler) {
|
|
|
|
w.mouseEnterHandler = handler
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *widgetBase) SetMouseLeaveHandler(handler MouseMoveHandler) {
|
|
|
|
w.mouseLeaveHandler = handler
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *widgetBase) SetMouseClickHandler(handler MouseHandler) {
|
|
|
|
w.mouseClickHandler = handler
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *widgetBase) getPosition() (int, int) {
|
|
|
|
return w.x, w.y
|
|
|
|
}
|
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
func (w *widgetBase) getSize() (int, int) {
|
|
|
|
return 0, 0
|
|
|
|
}
|
|
|
|
|
2020-02-17 22:11:52 -05:00
|
|
|
func (w *widgetBase) getLayer() int {
|
|
|
|
return w.layer
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *widgetBase) isVisible() bool {
|
|
|
|
return w.visible
|
|
|
|
}
|
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
func (w *widgetBase) isExpanding() bool {
|
|
|
|
return w.expanding
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *widgetBase) render(target d2render.Surface) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-02-17 22:11:52 -05:00
|
|
|
func (w *widgetBase) advance(elapsed float64) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
func (w *widgetBase) onMouseEnter(event d2input.MouseMoveEvent) bool {
|
2020-02-17 22:11:52 -05:00
|
|
|
if w.mouseEnterHandler != nil {
|
|
|
|
w.mouseEnterHandler(event)
|
|
|
|
}
|
2020-02-24 22:35:21 -05:00
|
|
|
|
|
|
|
return false
|
2020-02-17 22:11:52 -05:00
|
|
|
}
|
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
func (w *widgetBase) onMouseLeave(event d2input.MouseMoveEvent) bool {
|
2020-02-17 22:11:52 -05:00
|
|
|
if w.mouseLeaveHandler != nil {
|
|
|
|
w.mouseLeaveHandler(event)
|
|
|
|
}
|
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
return false
|
2020-02-17 22:11:52 -05:00
|
|
|
}
|
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
func (w *widgetBase) onMouseButtonClick(event d2input.MouseEvent) bool {
|
2020-02-17 22:11:52 -05:00
|
|
|
if w.mouseClickHandler != nil {
|
|
|
|
w.mouseClickHandler(event)
|
|
|
|
}
|
2020-02-24 22:35:21 -05:00
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *widgetBase) onMouseMove(event d2input.MouseMoveEvent) bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *widgetBase) onMouseOver(event d2input.MouseMoveEvent) bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *widgetBase) onMouseButtonDown(event d2input.MouseEvent) bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *widgetBase) onMouseButtonUp(event d2input.MouseEvent) bool {
|
|
|
|
return false
|
2020-02-17 22:11:52 -05:00
|
|
|
}
|