2020-02-17 22:11:52 -05:00
|
|
|
package d2gui
|
|
|
|
|
|
|
|
import (
|
2020-06-29 00:41:58 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
2020-02-17 22:11:52 -05:00
|
|
|
)
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
// MouseHandler is a handler function for mouse events
|
2020-07-03 15:09:16 -04:00
|
|
|
type MouseHandler func(d2interface.MouseEvent)
|
2020-07-18 18:06:36 -04:00
|
|
|
|
|
|
|
// MouseMoveHandler is a handler function for mouse movement events
|
2020-07-03 15:09:16 -04:00
|
|
|
type MouseMoveHandler func(d2interface.MouseMoveEvent)
|
2020-02-17 22:11:52 -05:00
|
|
|
|
|
|
|
type widget interface {
|
2020-10-28 14:17:42 -04:00
|
|
|
render(target d2interface.Surface)
|
2020-02-17 22:11:52 -05:00
|
|
|
advance(elapsed float64) error
|
|
|
|
|
2020-07-03 15:09:16 -04:00
|
|
|
onMouseMove(event d2interface.MouseMoveEvent) bool
|
|
|
|
onMouseEnter(event d2interface.MouseMoveEvent) bool
|
|
|
|
onMouseLeave(event d2interface.MouseMoveEvent) bool
|
|
|
|
onMouseOver(event d2interface.MouseMoveEvent) bool
|
|
|
|
onMouseButtonDown(event d2interface.MouseEvent) bool
|
|
|
|
onMouseButtonUp(event d2interface.MouseEvent) bool
|
|
|
|
onMouseButtonClick(event d2interface.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-07-08 09:15:20 -04:00
|
|
|
SetScreenPos(x, y int)
|
|
|
|
ScreenPos() (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
|
2020-07-18 18:06:36 -04:00
|
|
|
Sx int
|
2020-07-08 09:15:20 -04:00
|
|
|
Sy int
|
2020-02-24 22:35:21 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
// SetPosition sets the widget position
|
2020-02-17 22:11:52 -05:00
|
|
|
func (w *widgetBase) SetPosition(x, y int) {
|
|
|
|
w.x = x
|
|
|
|
w.y = y
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
// GetPosition returns the widget position
|
|
|
|
func (w *widgetBase) GetPosition() (x, y int) {
|
2020-06-25 16:27:16 -04:00
|
|
|
return w.x, w.y
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
// GetOffset gets the widget offset
|
|
|
|
func (w *widgetBase) GetOffset() (x, y int) {
|
2020-06-25 16:27:16 -04:00
|
|
|
return w.offsetX, w.offsetY
|
|
|
|
}
|
|
|
|
|
2020-07-08 09:15:20 -04:00
|
|
|
// SetScreenPos sets the screen position
|
|
|
|
func (w *widgetBase) SetScreenPos(x, y int) {
|
|
|
|
w.Sx, w.Sy = x, y
|
|
|
|
}
|
|
|
|
|
|
|
|
// ScreenPos returns the screen position
|
|
|
|
func (w *widgetBase) ScreenPos() (x, y int) {
|
|
|
|
return w.Sx, w.Sy
|
|
|
|
}
|
|
|
|
|
2020-06-25 16:27:16 -04:00
|
|
|
func (w *widgetBase) setOffset(x, y int) {
|
|
|
|
w.offsetX = x
|
|
|
|
w.offsetY = y
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
// SetLayer sets the widget layer (for rendering order)
|
2020-02-17 22:11:52 -05:00
|
|
|
func (w *widgetBase) SetLayer(layer int) {
|
|
|
|
w.layer = layer
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
// SetVisible sets the widget's visibility
|
2020-02-17 22:11:52 -05:00
|
|
|
func (w *widgetBase) SetVisible(visible bool) {
|
|
|
|
w.visible = visible
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
// SetExpanding tells the widget to expand (or not) when inside of a layout
|
2020-02-24 22:35:21 -05:00
|
|
|
func (w *widgetBase) SetExpanding(expanding bool) {
|
|
|
|
w.expanding = expanding
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
// SetMouseEnterHandler sets the handler function for mouse-enter events
|
2020-02-17 22:11:52 -05:00
|
|
|
func (w *widgetBase) SetMouseEnterHandler(handler MouseMoveHandler) {
|
|
|
|
w.mouseEnterHandler = handler
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
// SetMouseLeaveHandler sets the handler function for mouse-leave events
|
2020-02-17 22:11:52 -05:00
|
|
|
func (w *widgetBase) SetMouseLeaveHandler(handler MouseMoveHandler) {
|
|
|
|
w.mouseLeaveHandler = handler
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
// SetMouseClickHandler sets the handler function for mouse-click events
|
2020-02-17 22:11:52 -05:00
|
|
|
func (w *widgetBase) SetMouseClickHandler(handler MouseHandler) {
|
|
|
|
w.mouseClickHandler = handler
|
|
|
|
}
|
|
|
|
|
2020-08-05 13:51:19 -04:00
|
|
|
func (w *widgetBase) getPosition() (x, y int) {
|
2020-02-17 22:11:52 -05:00
|
|
|
return w.x, w.y
|
|
|
|
}
|
|
|
|
|
2020-08-05 13:51:19 -04:00
|
|
|
func (w *widgetBase) getSize() (width, height int) {
|
2020-02-24 22:35:21 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-10-28 14:17:42 -04:00
|
|
|
func (w *widgetBase) render(_ d2interface.Surface) { /* NOOP */ }
|
2020-02-24 22:35:21 -05:00
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
func (w *widgetBase) advance(_ float64) error {
|
2020-02-17 22:11:52 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-03 15:09:16 -04:00
|
|
|
func (w *widgetBase) onMouseEnter(event d2interface.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-07-03 15:09:16 -04:00
|
|
|
func (w *widgetBase) onMouseLeave(event d2interface.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-07-03 15:09:16 -04:00
|
|
|
func (w *widgetBase) onMouseButtonClick(event d2interface.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
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
func (w *widgetBase) onMouseMove(_ d2interface.MouseMoveEvent) bool {
|
2020-02-24 22:35:21 -05:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
func (w *widgetBase) onMouseOver(_ d2interface.MouseMoveEvent) bool {
|
2020-02-24 22:35:21 -05:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
func (w *widgetBase) onMouseButtonDown(_ d2interface.MouseEvent) bool {
|
2020-02-24 22:35:21 -05:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-07-18 18:06:36 -04:00
|
|
|
func (w *widgetBase) onMouseButtonUp(_ d2interface.MouseEvent) bool {
|
2020-02-24 22:35:21 -05:00
|
|
|
return false
|
2020-02-17 22:11:52 -05:00
|
|
|
}
|