mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-07-03 11:55:22 +00:00
UI fixes (#461)
This commit is contained in:
parent
48a193579f
commit
226181ffcc
|
@ -138,7 +138,7 @@ func (l *Layout) Clear() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Layout) render(target d2render.Surface) error {
|
func (l *Layout) render(target d2render.Surface) error {
|
||||||
l.adjustEntryPlacement()
|
l.AdjustEntryPlacement()
|
||||||
|
|
||||||
for _, entry := range l.entries {
|
for _, entry := range l.entries {
|
||||||
if !entry.widget.isVisible() {
|
if !entry.widget.isVisible() {
|
||||||
|
@ -295,7 +295,7 @@ func (l *Layout) adjustEntryEvent(entry *layoutEntry, eventX, eventY *int) bool
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Layout) adjustEntryPlacement() {
|
func (l *Layout) AdjustEntryPlacement() {
|
||||||
width, height := l.getSize()
|
width, height := l.getSize()
|
||||||
|
|
||||||
var expanderCount int
|
var expanderCount int
|
||||||
|
|
|
@ -46,6 +46,9 @@ func createGuiManager() (*manager, error) {
|
||||||
|
|
||||||
func (m *manager) SetLayout(layout *Layout) {
|
func (m *manager) SetLayout(layout *Layout) {
|
||||||
m.layout = layout
|
m.layout = layout
|
||||||
|
if m.layout != nil {
|
||||||
|
m.layout.AdjustEntryPlacement()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *manager) OnMouseButtonDown(event d2input.MouseEvent) bool {
|
func (m *manager) OnMouseButtonDown(event d2input.MouseEvent) bool {
|
||||||
|
|
|
@ -21,7 +21,6 @@ type widget interface {
|
||||||
onMouseButtonClick(event d2input.MouseEvent) bool
|
onMouseButtonClick(event d2input.MouseEvent) bool
|
||||||
|
|
||||||
getPosition() (int, int)
|
getPosition() (int, int)
|
||||||
getOffset() (int, int)
|
|
||||||
setOffset(x, y int)
|
setOffset(x, y int)
|
||||||
getSize() (int, int)
|
getSize() (int, int)
|
||||||
getLayer() int
|
getLayer() int
|
||||||
|
@ -57,10 +56,6 @@ func (w *widgetBase) GetOffset() (int, int) {
|
||||||
return w.offsetX, w.offsetY
|
return w.offsetX, w.offsetY
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *widgetBase) getOffset() (int, int) {
|
|
||||||
return w.offsetX, w.offsetY
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *widgetBase) setOffset(x, y int) {
|
func (w *widgetBase) setOffset(x, y int) {
|
||||||
w.offsetX = x
|
w.offsetX = x
|
||||||
w.offsetY = y
|
w.offsetY = y
|
||||||
|
|
|
@ -27,7 +27,7 @@ type Label struct {
|
||||||
Height int
|
Height int
|
||||||
Alignment LabelAlignment
|
Alignment LabelAlignment
|
||||||
font *Font
|
font *Font
|
||||||
imageData d2render.Surface
|
imageData map[string]d2render.Surface
|
||||||
Color color.Color
|
Color color.Color
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,9 @@ func CreateLabel(fontPath, palettePath string) Label {
|
||||||
Alignment: LabelAlignLeft,
|
Alignment: LabelAlignLeft,
|
||||||
Color: color.White,
|
Color: color.White,
|
||||||
font: GetFont(fontPath, palettePath),
|
font: GetFont(fontPath, palettePath),
|
||||||
|
imageData: make(map[string]d2render.Surface),
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +62,7 @@ func (v *Label) Render(target d2render.Surface) {
|
||||||
target.PushTranslation(x, y)
|
target.PushTranslation(x, y)
|
||||||
defer target.PopN(3)
|
defer target.PopN(3)
|
||||||
|
|
||||||
target.Render(v.imageData)
|
target.Render(v.imageData[v.text])
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetPosition moves the label to the specified location
|
// SetPosition moves the label to the specified location
|
||||||
|
@ -74,14 +76,14 @@ func (v *Label) GetTextMetrics(text string) (width, height int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Label) cacheImage() {
|
func (v *Label) cacheImage() {
|
||||||
if v.imageData != nil {
|
if v.imageData[v.text] != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
width, height := v.font.GetTextMetrics(v.text)
|
width, height := v.font.GetTextMetrics(v.text)
|
||||||
v.Width = width
|
v.Width = width
|
||||||
v.Height = height
|
v.Height = height
|
||||||
v.imageData, _ = d2render.NewSurface(width, height, d2render.FilterNearest)
|
v.imageData[v.text], _ = d2render.NewSurface(width, height, d2render.FilterNearest)
|
||||||
surface, _ := d2render.CreateSurface(v.imageData)
|
surface, _ := d2render.CreateSurface(v.imageData[v.text])
|
||||||
v.font.Render(0, 0, v.text, v.Color, surface)
|
v.font.Render(0, 0, v.text, v.Color, surface)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +93,6 @@ func (v *Label) SetText(newText string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
v.text = newText
|
v.text = newText
|
||||||
v.imageData = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Size returns the size of the label
|
// Size returns the size of the label
|
||||||
|
|
|
@ -364,6 +364,7 @@ func (m *EscapeMenu) setLayout(id layoutID) {
|
||||||
m.currentLayout = id
|
m.currentLayout = id
|
||||||
m.layouts[id].currentEl = 0
|
m.layouts[id].currentEl = 0
|
||||||
d2gui.SetLayout(m.layouts[id].Layout)
|
d2gui.SetLayout(m.layouts[id].Layout)
|
||||||
|
m.onHoverElement(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *EscapeMenu) onUpKey() {
|
func (m *EscapeMenu) onUpKey() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user