2020-02-17 22:11:52 -05:00
|
|
|
package d2gui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Label struct {
|
|
|
|
widgetBase
|
|
|
|
|
|
|
|
surface d2render.Surface
|
|
|
|
}
|
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
func createLabel(text string, fontStyle FontStyle) (*Label, error) {
|
|
|
|
font, err := loadFont(fontStyle)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-02-17 22:11:52 -05:00
|
|
|
}
|
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
width, height := font.GetTextMetrics(text)
|
|
|
|
surface, err := d2render.NewSurface(width, height, d2render.FilterNearest)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-02-17 22:11:52 -05:00
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
if err := font.RenderText(text, surface); err != nil {
|
|
|
|
return nil, err
|
2020-02-17 22:11:52 -05:00
|
|
|
}
|
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
label := &Label{surface: surface}
|
|
|
|
label.SetVisible(true)
|
2020-02-17 22:11:52 -05:00
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
return label, nil
|
|
|
|
}
|
2020-02-17 22:11:52 -05:00
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
func (l *Label) render(target d2render.Surface) error {
|
|
|
|
return target.Render(l.surface)
|
2020-02-17 22:11:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Label) getSize() (int, int) {
|
|
|
|
return l.surface.GetSize()
|
|
|
|
}
|