Better commenting throughout
This commit is contained in:
@@ -17,6 +17,8 @@ var (
|
||||
rectPixel = newRectPixel()
|
||||
)
|
||||
|
||||
// Drawing helpers
|
||||
|
||||
func newRectPixel() *ebiten.Image {
|
||||
img := ebiten.NewImage(1, 1)
|
||||
img.Fill(color.White)
|
||||
@@ -33,12 +35,12 @@ func drawHUDText(screen *ebiten.Image, txt string, clr color.Color, x, y int) {
|
||||
text.Draw(screen, txt, basicFace, op)
|
||||
}
|
||||
|
||||
// Drawable HUD chunk.
|
||||
// HUD elements
|
||||
|
||||
type Element interface {
|
||||
Draw(screen *ebiten.Image, x, y int) (width, height int)
|
||||
}
|
||||
|
||||
// Plain text node.
|
||||
type Label struct {
|
||||
Text string
|
||||
Color color.Color
|
||||
@@ -53,7 +55,6 @@ func (l Label) Draw(screen *ebiten.Image, x, y int) (int, int) {
|
||||
return width, 13
|
||||
}
|
||||
|
||||
// Percent readout node.
|
||||
type PercentageDisplay struct {
|
||||
Meter status.Meter
|
||||
Color color.Color
|
||||
@@ -68,7 +69,6 @@ func (p PercentageDisplay) Draw(screen *ebiten.Image, x, y int) (int, int) {
|
||||
return len(txt) * 7, 13
|
||||
}
|
||||
|
||||
// Combined label and percent.
|
||||
type MeterLabel struct {
|
||||
Meter status.Meter
|
||||
Color color.Color
|
||||
@@ -80,17 +80,14 @@ func (m MeterLabel) Draw(screen *ebiten.Image, x, y int) (int, int) {
|
||||
}
|
||||
var txt string
|
||||
if m.Meter.Base < 0 {
|
||||
// Text-only display without percentage.
|
||||
txt = m.Meter.Label
|
||||
} else {
|
||||
// Standard meter with percentage.
|
||||
txt = fmt.Sprintf("%s: %3.0f%%", m.Meter.Label, m.Meter.Level)
|
||||
}
|
||||
drawHUDText(screen, txt, m.Meter.Color, x, y)
|
||||
return len(txt) * 7, 13
|
||||
}
|
||||
|
||||
// Horizontal meter bar.
|
||||
type Bar struct {
|
||||
Meter status.Meter
|
||||
MaxWidth int
|
||||
@@ -117,23 +114,17 @@ func (b Bar) Draw(screen *ebiten.Image, x, y int) (int, int) {
|
||||
fillWidth = maxWidth
|
||||
}
|
||||
|
||||
// Draw border if requested
|
||||
if b.ShowBorder {
|
||||
borderColor := b.BorderColor
|
||||
if borderColor == nil {
|
||||
borderColor = color.RGBA{R: 80, G: 80, B: 80, A: 255}
|
||||
}
|
||||
// Top border
|
||||
drawRect(screen, x, y, maxWidth, 1, borderColor)
|
||||
// Bottom border
|
||||
drawRect(screen, x, y+height-1, maxWidth, 1, borderColor)
|
||||
// Left border
|
||||
drawRect(screen, x, y, 1, height, borderColor)
|
||||
// Right border
|
||||
drawRect(screen, x+maxWidth-1, y, 1, height, borderColor)
|
||||
}
|
||||
|
||||
// Draw filled portion
|
||||
if fillWidth > 0 {
|
||||
drawRect(screen, x, y, fillWidth, height, b.Meter.Color)
|
||||
}
|
||||
@@ -141,7 +132,8 @@ func (b Bar) Draw(screen *ebiten.Image, x, y int) (int, int) {
|
||||
return maxWidth, height
|
||||
}
|
||||
|
||||
// Helper for filled rectangles.
|
||||
// Rectangle drawing
|
||||
|
||||
func drawRect(screen *ebiten.Image, x, y, width, height int, clr color.Color) {
|
||||
if width <= 0 || height <= 0 {
|
||||
return
|
||||
@@ -158,7 +150,8 @@ func drawRect(screen *ebiten.Image, x, y, width, height int, clr color.Color) {
|
||||
screen.DrawImage(rectPixel, op)
|
||||
}
|
||||
|
||||
// Empty padding block.
|
||||
// Layout elements
|
||||
|
||||
type Spacer struct {
|
||||
Width int
|
||||
Height int
|
||||
@@ -168,7 +161,6 @@ func (s Spacer) Draw(screen *ebiten.Image, x, y int) (int, int) {
|
||||
return s.Width, s.Height
|
||||
}
|
||||
|
||||
// Horizontal layout row.
|
||||
type Row struct {
|
||||
Elements []Element
|
||||
Spacing int
|
||||
@@ -195,7 +187,6 @@ func (r Row) Draw(screen *ebiten.Image, x, y int) (int, int) {
|
||||
return totalWidth, maxHeight
|
||||
}
|
||||
|
||||
// Vertical stack layout.
|
||||
type Column struct {
|
||||
Elements []Element
|
||||
Spacing int
|
||||
|
||||
Reference in New Issue
Block a user