Maded flower buttons smaller (less tall).

This commit is contained in:
Sander Schobers 2020-05-11 02:49:53 +02:00
parent 3a8ad733a4
commit e26de92f1d
3 changed files with 20 additions and 13 deletions

View File

@ -5,9 +5,10 @@ import "github.com/veandco/go-sdl2/sdl"
type ButtonBar struct { type ButtonBar struct {
Container Container
Background sdl.Color Background sdl.Color
Orientation Orientation ButtonLength int32
Buttons []Control Orientation Orientation
Buttons []Control
} }
const buttonBarWidth = 96 const buttonBarWidth = 96
@ -21,19 +22,24 @@ func (b *ButtonBar) Init(ctx *Context) error {
func (b *ButtonBar) Arrange(ctx *Context, bounds Rectangle) { func (b *ButtonBar) Arrange(ctx *Context, bounds Rectangle) {
b.Container.Arrange(ctx, bounds) b.Container.Arrange(ctx, bounds)
length := b.ButtonLength
switch b.Orientation { switch b.Orientation {
case OrientationHorizontal: case OrientationHorizontal:
length := bounds.H if length == 0 {
length = bounds.H
}
offset := bounds.X offset := bounds.X
for i := range b.Buttons { for i := range b.Buttons {
b.Buttons[i].Arrange(ctx, RectSize(offset, bounds.Y, length, length)) b.Buttons[i].Arrange(ctx, RectSize(offset, bounds.Y, length, bounds.H))
offset += length offset += length
} }
default: default:
length := bounds.W if length == 0 {
length = bounds.W
}
offset := bounds.Y offset := bounds.Y
for i := range b.Buttons { for i := range b.Buttons {
b.Buttons[i].Arrange(ctx, RectSize(bounds.X, offset, length, length)) b.Buttons[i].Arrange(ctx, RectSize(bounds.X, offset, bounds.W, length))
offset += length offset += length
} }
} }

View File

@ -76,9 +76,9 @@ func (b *BuyFlowerButton) Render(ctx *Context) {
mouseOverTexture := ctx.Textures.Texture("control-hover") mouseOverTexture := ctx.Textures.Texture("control-hover")
pos := Pt(b.Bounds.X, b.Bounds.Y) pos := Pt(b.Bounds.X, b.Bounds.Y)
iconTexture.CopyResize(ctx.Renderer, RectSize(pos.X, pos.Y-40, buttonBarWidth, 120)) iconTexture.CopyResize(ctx.Renderer, RectSize(pos.X, pos.Y-60, b.Bounds.W, 120))
if (b.IsMouseOver && !b.IsDisabled) || b.IsActive { if (b.IsMouseOver && !b.IsDisabled) || b.IsActive {
mouseOverTexture.Copy(ctx.Renderer, pos) mouseOverTexture.CopyResize(ctx.Renderer, b.Bounds)
} }
if b.hoverAnimation != nil { if b.hoverAnimation != nil {
@ -86,8 +86,8 @@ func (b *BuyFlowerButton) Render(ctx *Context) {
} }
if b.IsMouseOver { if b.IsMouseOver {
left := buttonBarWidth - 8 - b.hoverOffset left := b.Bounds.W - 8 - b.hoverOffset
top := pos.Y + buttonBarWidth - 20 top := pos.Y + b.Bounds.H - 20
if left < 0 { if left < 0 {
part := Rect(-left, 0, b.hoverTexture.Size().X, b.hoverTexture.Size().Y) part := Rect(-left, 0, b.hoverTexture.Size().X, b.hoverTexture.Size().Y)
b.hoverTexture.CopyPart(ctx.Renderer, part, Pt(pos.X, top)) b.hoverTexture.CopyPart(ctx.Renderer, part, Pt(pos.X, top))
@ -95,6 +95,6 @@ func (b *BuyFlowerButton) Render(ctx *Context) {
b.hoverTexture.Copy(ctx.Renderer, Pt(pos.X+left, top)) b.hoverTexture.Copy(ctx.Renderer, Pt(pos.X+left, top))
} }
} else { } else {
b.priceTexture.Copy(ctx.Renderer, Pt(pos.X+buttonBarWidth-8-b.priceTexture.Size().X, pos.Y+buttonBarWidth-20)) b.priceTexture.Copy(ctx.Renderer, Pt(pos.X+b.Bounds.W-8-b.priceTexture.Size().X, pos.Y+b.Bounds.H-20))
} }
} }

View File

@ -75,7 +75,8 @@ func (c *GameControls) Init(ctx *Context) error {
c.game.SpeedChanged().RegisterItf(c.speedChanged) c.game.SpeedChanged().RegisterItf(c.speedChanged)
c.game.ToolChanged().RegisterItf(c.toolChanged) c.game.ToolChanged().RegisterItf(c.toolChanged)
c.flowers.Background = MustHexColor("#356dad") // brown alternative? #4ac69a c.flowers.Background = MustHexColor("#356dad")
c.flowers.ButtonLength = 64
for _, id := range c.game.Herbarium.Flowers() { for _, id := range c.game.Herbarium.Flowers() {
c.flowers.Buttons = append(c.flowers.Buttons, c.createBuyFlowerButton(id)) c.flowers.Buttons = append(c.flowers.Buttons, c.createBuyFlowerButton(id))