diff --git a/buttonbar.go b/buttonbar.go index 3fe82ee..6990526 100644 --- a/buttonbar.go +++ b/buttonbar.go @@ -5,9 +5,10 @@ import "github.com/veandco/go-sdl2/sdl" type ButtonBar struct { Container - Background sdl.Color - Orientation Orientation - Buttons []Control + Background sdl.Color + ButtonLength int32 + Orientation Orientation + Buttons []Control } const buttonBarWidth = 96 @@ -21,19 +22,24 @@ func (b *ButtonBar) Init(ctx *Context) error { func (b *ButtonBar) Arrange(ctx *Context, bounds Rectangle) { b.Container.Arrange(ctx, bounds) + length := b.ButtonLength switch b.Orientation { case OrientationHorizontal: - length := bounds.H + if length == 0 { + length = bounds.H + } offset := bounds.X 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 } default: - length := bounds.W + if length == 0 { + length = bounds.W + } offset := bounds.Y 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 } } diff --git a/buyflowerbutton.go b/buyflowerbutton.go index 76b8fad..46380c5 100644 --- a/buyflowerbutton.go +++ b/buyflowerbutton.go @@ -76,9 +76,9 @@ func (b *BuyFlowerButton) Render(ctx *Context) { mouseOverTexture := ctx.Textures.Texture("control-hover") 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 { - mouseOverTexture.Copy(ctx.Renderer, pos) + mouseOverTexture.CopyResize(ctx.Renderer, b.Bounds) } if b.hoverAnimation != nil { @@ -86,8 +86,8 @@ func (b *BuyFlowerButton) Render(ctx *Context) { } if b.IsMouseOver { - left := buttonBarWidth - 8 - b.hoverOffset - top := pos.Y + buttonBarWidth - 20 + left := b.Bounds.W - 8 - b.hoverOffset + top := pos.Y + b.Bounds.H - 20 if left < 0 { part := Rect(-left, 0, b.hoverTexture.Size().X, b.hoverTexture.Size().Y) 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)) } } 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)) } } diff --git a/gamecontrols.go b/gamecontrols.go index 6c7d29f..7259f0c 100644 --- a/gamecontrols.go +++ b/gamecontrols.go @@ -75,7 +75,8 @@ func (c *GameControls) Init(ctx *Context) error { c.game.SpeedChanged().RegisterItf(c.speedChanged) 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() { c.flowers.Buttons = append(c.flowers.Buttons, c.createBuyFlowerButton(id))