mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-01-13 12:56:35 -05:00
d2input made the move to immutable events. (ex. MouseMove) but d2gui was using "local events" for its recursive layouts. Meaning when entering a sub-layout, the original event was modified to have the cursor relative to the x, and y of the parent layout. After tossing ideas with Grav, we considered (1) making events modifiable, (2) having an event constructor, (3) changing sub-Layout to use screen layout. We choose (3), and this is the relevant commit.
This commit is contained in:
parent
38213e749a
commit
f7e0912f5f
@ -241,10 +241,8 @@ func (l *Layout) getSize() (int, int) {
|
||||
|
||||
func (l *Layout) onMouseButtonDown(event d2interface.MouseEvent) bool {
|
||||
for _, entry := range l.entries {
|
||||
eventLocal := event
|
||||
|
||||
if l.adjustEntryEvent(entry, eventLocal.X(), eventLocal.Y()) {
|
||||
entry.widget.onMouseButtonDown(eventLocal)
|
||||
if entry.IsIn(event) {
|
||||
entry.widget.onMouseButtonDown(event)
|
||||
entry.mouseDown[event.Button()] = true
|
||||
}
|
||||
}
|
||||
@ -254,12 +252,10 @@ func (l *Layout) onMouseButtonDown(event d2interface.MouseEvent) bool {
|
||||
|
||||
func (l *Layout) onMouseButtonUp(event d2interface.MouseEvent) bool {
|
||||
for _, entry := range l.entries {
|
||||
eventLocal := event
|
||||
|
||||
if l.adjustEntryEvent(entry, eventLocal.X(), eventLocal.Y()) {
|
||||
if entry.IsIn(event) {
|
||||
if entry.mouseDown[event.Button()] {
|
||||
entry.widget.onMouseButtonClick(eventLocal)
|
||||
entry.widget.onMouseButtonUp(eventLocal)
|
||||
entry.widget.onMouseButtonClick(event)
|
||||
entry.widget.onMouseButtonUp(event)
|
||||
}
|
||||
}
|
||||
|
||||
@ -271,18 +267,18 @@ func (l *Layout) onMouseButtonUp(event d2interface.MouseEvent) bool {
|
||||
|
||||
func (l *Layout) onMouseMove(event d2interface.MouseMoveEvent) bool {
|
||||
for _, entry := range l.entries {
|
||||
eventLocal := event
|
||||
if entry.IsIn(event) {
|
||||
entry.widget.onMouseMove(event)
|
||||
|
||||
if l.adjustEntryEvent(entry, eventLocal.X(), eventLocal.Y()) {
|
||||
entry.widget.onMouseMove(eventLocal)
|
||||
if entry.mouseOver {
|
||||
entry.widget.onMouseOver(eventLocal)
|
||||
entry.widget.onMouseOver(event)
|
||||
} else {
|
||||
entry.widget.onMouseEnter(eventLocal)
|
||||
entry.widget.onMouseEnter(event)
|
||||
}
|
||||
|
||||
entry.mouseOver = true
|
||||
} else if entry.mouseOver {
|
||||
entry.widget.onMouseLeave(eventLocal)
|
||||
entry.widget.onMouseLeave(event)
|
||||
entry.mouseOver = false
|
||||
}
|
||||
}
|
||||
@ -290,17 +286,6 @@ func (l *Layout) onMouseMove(event d2interface.MouseMoveEvent) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (l *Layout) adjustEntryEvent(entry *layoutEntry, eventX, eventY int) bool {
|
||||
eventX -= entry.x
|
||||
eventY -= entry.y
|
||||
|
||||
if eventX < 0 || eventY < 0 || eventX >= entry.width || eventY >= entry.height {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (l *Layout) AdjustEntryPlacement() {
|
||||
width, height := l.getSize()
|
||||
|
||||
@ -365,6 +350,15 @@ func (l *Layout) AdjustEntryPlacement() {
|
||||
entry.x, entry.y = entry.widget.getPosition()
|
||||
}
|
||||
|
||||
sx, sy := l.ScreenPos()
|
||||
entry.widget.SetScreenPos(entry.x + sx, entry.y + sy)
|
||||
entry.widget.setOffset(offsetX, offsetY)
|
||||
}
|
||||
}
|
||||
|
||||
// IsIn layout entry, spc. of an event.
|
||||
func (l *layoutEntry) IsIn(event d2interface.HandlerEvent) bool {
|
||||
sx, sy := l.widget.ScreenPos()
|
||||
rect := d2common.Rectangle{Left: sx, Top: sy, Width: l.width, Height: l.height}
|
||||
return rect.IsInRect(event.X(), event.Y())
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ type widget interface {
|
||||
|
||||
getPosition() (int, int)
|
||||
setOffset(x, y int)
|
||||
SetScreenPos(x, y int)
|
||||
ScreenPos() (x, y int)
|
||||
getSize() (int, int)
|
||||
getLayer() int
|
||||
isVisible() bool
|
||||
@ -30,6 +32,8 @@ type widget interface {
|
||||
type widgetBase struct {
|
||||
x int
|
||||
y int
|
||||
Sx int
|
||||
Sy int
|
||||
layer int
|
||||
visible bool
|
||||
expanding bool
|
||||
@ -55,6 +59,16 @@ func (w *widgetBase) GetOffset() (int, int) {
|
||||
return w.offsetX, w.offsetY
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
func (w *widgetBase) setOffset(x, y int) {
|
||||
w.offsetX = x
|
||||
w.offsetY = y
|
||||
|
Loading…
Reference in New Issue
Block a user