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

154 lines
3.1 KiB
Go
Raw Normal View History

package d2gui
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
)
type MouseHandler func(d2interface.MouseEvent)
type MouseMoveHandler func(d2interface.MouseMoveEvent)
type widget interface {
render(target d2interface.Surface) error
advance(elapsed float64) error
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
getPosition() (int, int)
Enhanced escape menu with options - d2gui bug remaining (#459) * First improvements Signed-off-by: William Claude <w.claude@thebeat.co> * Make the menu more generic Signed-off-by: William Claude <w.claude@thebeat.co> * Handle mouse events Signed-off-by: William Claude <w.claude@thebeat.co> * Remove debug statement Signed-off-by: William Claude <w.claude@thebeat.co> * Handle left clicks better Signed-off-by: William Claude <w.claude@thebeat.co> * Remove unused file Signed-off-by: William Claude <w.claude@thebeat.co> * Handle titles in screens Signed-off-by: William Claude <w.claude@thebeat.co> * Improve the menu using layouts Signed-off-by: William Claude <w.claude@thebeat.co> * Add support for onOff labels Signed-off-by: William Claude <w.claude@thebeat.co> * Mutualise title creation Signed-off-by: William Claude <w.claude@thebeat.co> * Add gutter and mutualise things Signed-off-by: William Claude <w.claude@thebeat.co> * Improve menu, mutualise a lot of things and support animated sprites Signed-off-by: William Claude <w.claude@thebeat.co> * Use a cfg struct instead of independent handlers Signed-off-by: William Claude <w.claude@thebeat.co> * Fix hardcoded value Signed-off-by: William Claude <w.claude@thebeat.co> * Clean things a bit Signed-off-by: William Claude <w.claude@thebeat.co> * Remove unused property Signed-off-by: William Claude <w.claude@thebeat.co> * First support for hoverable elements Signed-off-by: William Claude <w.claude@thebeat.co> * Add support for label selection feedback Signed-off-by: William Claude <w.claude@thebeat.co> * Add support options Signed-off-by: William Claude <w.claude@thebeat.co> * Update print statement Signed-off-by: William Claude <w.claude@thebeat.co> * Update rendering and clean code Signed-off-by: William Claude <w.claude@thebeat.co> * Remove debug things Signed-off-by: William Claude <w.claude@thebeat.co> * Handle hovering Signed-off-by: William Claude <w.claude@thebeat.co> * Support enter key for labels Signed-off-by: William Claude <w.claude@thebeat.co> * Attach methods to layout Signed-off-by: William Claude <w.claude@thebeat.co> * Move things under EscapeMenu Signed-off-by: William Claude <w.claude@thebeat.co> * Some renaming Signed-off-by: William Claude <w.claude@thebeat.co> * Clean Signed-off-by: William Claude <w.claude@thebeat.co> * Set hovered element ID when using the mouse Signed-off-by: William Claude <w.claude@thebeat.co> * Clean Signed-off-by: William Claude <w.claude@thebeat.co> * Delete unused file Signed-off-by: William Claude <w.claude@thebeat.co> * Wire save & exit with a nasty hack Signed-off-by: William Claude <w.claude@thebeat.co> * Remove unused file Signed-off-by: William Claude <w.claude@thebeat.co> * Remove dead code Signed-off-by: William Claude <w.claude@thebeat.co> * Reorder the code a bit Signed-off-by: William Claude <w.claude@thebeat.co> * Rename hoverableElement into actionableElement Signed-off-by: William Claude <w.claude@thebeat.co> * Prevent regenerating the label if the text didn't change Signed-off-by: William Claude <w.claude@thebeat.co>
2020-06-25 16:27:16 -04:00
setOffset(x, y int)
getSize() (int, int)
getLayer() int
isVisible() bool
isExpanding() bool
}
type widgetBase struct {
x int
y int
layer int
visible bool
expanding bool
Enhanced escape menu with options - d2gui bug remaining (#459) * First improvements Signed-off-by: William Claude <w.claude@thebeat.co> * Make the menu more generic Signed-off-by: William Claude <w.claude@thebeat.co> * Handle mouse events Signed-off-by: William Claude <w.claude@thebeat.co> * Remove debug statement Signed-off-by: William Claude <w.claude@thebeat.co> * Handle left clicks better Signed-off-by: William Claude <w.claude@thebeat.co> * Remove unused file Signed-off-by: William Claude <w.claude@thebeat.co> * Handle titles in screens Signed-off-by: William Claude <w.claude@thebeat.co> * Improve the menu using layouts Signed-off-by: William Claude <w.claude@thebeat.co> * Add support for onOff labels Signed-off-by: William Claude <w.claude@thebeat.co> * Mutualise title creation Signed-off-by: William Claude <w.claude@thebeat.co> * Add gutter and mutualise things Signed-off-by: William Claude <w.claude@thebeat.co> * Improve menu, mutualise a lot of things and support animated sprites Signed-off-by: William Claude <w.claude@thebeat.co> * Use a cfg struct instead of independent handlers Signed-off-by: William Claude <w.claude@thebeat.co> * Fix hardcoded value Signed-off-by: William Claude <w.claude@thebeat.co> * Clean things a bit Signed-off-by: William Claude <w.claude@thebeat.co> * Remove unused property Signed-off-by: William Claude <w.claude@thebeat.co> * First support for hoverable elements Signed-off-by: William Claude <w.claude@thebeat.co> * Add support for label selection feedback Signed-off-by: William Claude <w.claude@thebeat.co> * Add support options Signed-off-by: William Claude <w.claude@thebeat.co> * Update print statement Signed-off-by: William Claude <w.claude@thebeat.co> * Update rendering and clean code Signed-off-by: William Claude <w.claude@thebeat.co> * Remove debug things Signed-off-by: William Claude <w.claude@thebeat.co> * Handle hovering Signed-off-by: William Claude <w.claude@thebeat.co> * Support enter key for labels Signed-off-by: William Claude <w.claude@thebeat.co> * Attach methods to layout Signed-off-by: William Claude <w.claude@thebeat.co> * Move things under EscapeMenu Signed-off-by: William Claude <w.claude@thebeat.co> * Some renaming Signed-off-by: William Claude <w.claude@thebeat.co> * Clean Signed-off-by: William Claude <w.claude@thebeat.co> * Set hovered element ID when using the mouse Signed-off-by: William Claude <w.claude@thebeat.co> * Clean Signed-off-by: William Claude <w.claude@thebeat.co> * Delete unused file Signed-off-by: William Claude <w.claude@thebeat.co> * Wire save & exit with a nasty hack Signed-off-by: William Claude <w.claude@thebeat.co> * Remove unused file Signed-off-by: William Claude <w.claude@thebeat.co> * Remove dead code Signed-off-by: William Claude <w.claude@thebeat.co> * Reorder the code a bit Signed-off-by: William Claude <w.claude@thebeat.co> * Rename hoverableElement into actionableElement Signed-off-by: William Claude <w.claude@thebeat.co> * Prevent regenerating the label if the text didn't change Signed-off-by: William Claude <w.claude@thebeat.co>
2020-06-25 16:27:16 -04:00
offsetX int
offsetY int
mouseEnterHandler MouseMoveHandler
mouseLeaveHandler MouseMoveHandler
mouseClickHandler MouseHandler
}
func (w *widgetBase) SetPosition(x, y int) {
w.x = x
w.y = y
}
Enhanced escape menu with options - d2gui bug remaining (#459) * First improvements Signed-off-by: William Claude <w.claude@thebeat.co> * Make the menu more generic Signed-off-by: William Claude <w.claude@thebeat.co> * Handle mouse events Signed-off-by: William Claude <w.claude@thebeat.co> * Remove debug statement Signed-off-by: William Claude <w.claude@thebeat.co> * Handle left clicks better Signed-off-by: William Claude <w.claude@thebeat.co> * Remove unused file Signed-off-by: William Claude <w.claude@thebeat.co> * Handle titles in screens Signed-off-by: William Claude <w.claude@thebeat.co> * Improve the menu using layouts Signed-off-by: William Claude <w.claude@thebeat.co> * Add support for onOff labels Signed-off-by: William Claude <w.claude@thebeat.co> * Mutualise title creation Signed-off-by: William Claude <w.claude@thebeat.co> * Add gutter and mutualise things Signed-off-by: William Claude <w.claude@thebeat.co> * Improve menu, mutualise a lot of things and support animated sprites Signed-off-by: William Claude <w.claude@thebeat.co> * Use a cfg struct instead of independent handlers Signed-off-by: William Claude <w.claude@thebeat.co> * Fix hardcoded value Signed-off-by: William Claude <w.claude@thebeat.co> * Clean things a bit Signed-off-by: William Claude <w.claude@thebeat.co> * Remove unused property Signed-off-by: William Claude <w.claude@thebeat.co> * First support for hoverable elements Signed-off-by: William Claude <w.claude@thebeat.co> * Add support for label selection feedback Signed-off-by: William Claude <w.claude@thebeat.co> * Add support options Signed-off-by: William Claude <w.claude@thebeat.co> * Update print statement Signed-off-by: William Claude <w.claude@thebeat.co> * Update rendering and clean code Signed-off-by: William Claude <w.claude@thebeat.co> * Remove debug things Signed-off-by: William Claude <w.claude@thebeat.co> * Handle hovering Signed-off-by: William Claude <w.claude@thebeat.co> * Support enter key for labels Signed-off-by: William Claude <w.claude@thebeat.co> * Attach methods to layout Signed-off-by: William Claude <w.claude@thebeat.co> * Move things under EscapeMenu Signed-off-by: William Claude <w.claude@thebeat.co> * Some renaming Signed-off-by: William Claude <w.claude@thebeat.co> * Clean Signed-off-by: William Claude <w.claude@thebeat.co> * Set hovered element ID when using the mouse Signed-off-by: William Claude <w.claude@thebeat.co> * Clean Signed-off-by: William Claude <w.claude@thebeat.co> * Delete unused file Signed-off-by: William Claude <w.claude@thebeat.co> * Wire save & exit with a nasty hack Signed-off-by: William Claude <w.claude@thebeat.co> * Remove unused file Signed-off-by: William Claude <w.claude@thebeat.co> * Remove dead code Signed-off-by: William Claude <w.claude@thebeat.co> * Reorder the code a bit Signed-off-by: William Claude <w.claude@thebeat.co> * Rename hoverableElement into actionableElement Signed-off-by: William Claude <w.claude@thebeat.co> * Prevent regenerating the label if the text didn't change Signed-off-by: William Claude <w.claude@thebeat.co>
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
}
func (w *widgetBase) SetLayer(layer int) {
w.layer = layer
}
func (w *widgetBase) SetVisible(visible bool) {
w.visible = visible
}
func (w *widgetBase) SetExpanding(expanding bool) {
w.expanding = expanding
}
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
}
func (w *widgetBase) getSize() (int, int) {
return 0, 0
}
func (w *widgetBase) getLayer() int {
return w.layer
}
func (w *widgetBase) isVisible() bool {
return w.visible
}
func (w *widgetBase) isExpanding() bool {
return w.expanding
}
func (w *widgetBase) render(target d2interface.Surface) error {
return nil
}
func (w *widgetBase) advance(elapsed float64) error {
return nil
}
func (w *widgetBase) onMouseEnter(event d2interface.MouseMoveEvent) bool {
if w.mouseEnterHandler != nil {
w.mouseEnterHandler(event)
}
return false
}
func (w *widgetBase) onMouseLeave(event d2interface.MouseMoveEvent) bool {
if w.mouseLeaveHandler != nil {
w.mouseLeaveHandler(event)
}
return false
}
func (w *widgetBase) onMouseButtonClick(event d2interface.MouseEvent) bool {
if w.mouseClickHandler != nil {
w.mouseClickHandler(event)
}
return false
}
func (w *widgetBase) onMouseMove(event d2interface.MouseMoveEvent) bool {
return false
}
func (w *widgetBase) onMouseOver(event d2interface.MouseMoveEvent) bool {
return false
}
func (w *widgetBase) onMouseButtonDown(event d2interface.MouseEvent) bool {
return false
}
func (w *widgetBase) onMouseButtonUp(event d2interface.MouseEvent) bool {
return false
}