Zoom And Edit

Progress on the Zoom feature: when you zoom in and out, you can draw
shapes accurately onto the level. Seems a little buggy if you edit
while scrolling (as in drawing a very long line).

The title screen buttons are now more colorful.
zoom-hell
Noah 2021-09-11 16:52:22 -07:00
parent 13ae66e1fa
commit ecdfc46358
7 changed files with 58 additions and 28 deletions

2
go.sum
View File

@ -193,6 +193,8 @@ github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/X
github.com/veandco/go-sdl2 v0.4.1/go.mod h1:FB+kTpX9YTE+urhYiClnRzpOXbiWgaU3+5F2AB78DPg=
github.com/veandco/go-sdl2 v0.4.8 h1:A26KeX6R1CGt/BQGEov6oxYmVGMMEWDVqTvK1tXvahE=
github.com/veandco/go-sdl2 v0.4.8/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY=
github.com/veandco/go-sdl2 v0.4.10 h1:8QoD2bhWl7SbQDflIAUYWfl9Vq+mT8/boJFAUzAScgY=
github.com/veandco/go-sdl2 v0.4.10/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY=
github.com/vmihailenco/msgpack v3.3.3+incompatible h1:wapg9xDUZDzGCNFlwc5SqI1rvcciqcxEHac4CYj89xI=
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=

View File

@ -165,22 +165,24 @@ var (
ButtonLightRed = style.DefaultButton
)
// Customize the various button styles.
func init() {
// Customize button styles.
// Primary: white on rich blue color
ButtonPrimary.Background = render.RGBA(0, 60, 153, 255)
ButtonPrimary.Foreground = render.RGBA(255, 255, 254, 255)
ButtonPrimary.HoverBackground = render.RGBA(0, 153, 255, 255)
ButtonPrimary.HoverForeground = ButtonPrimary.Foreground
// Danger: white on red
ButtonDanger.Background = render.RGBA(153, 30, 30, 255)
ButtonDanger.Foreground = render.RGBA(255, 255, 254, 255)
ButtonDanger.HoverBackground = render.RGBA(255, 30, 30, 255)
ButtonDanger.HoverForeground = ButtonPrimary.Foreground
ButtonBabyBlue.Background = render.RGBA(0, 153, 255, 255)
ButtonBabyBlue.Foreground = render.White
ButtonBabyBlue.Background = render.RGBA(40, 200, 255, 255)
ButtonBabyBlue.Foreground = render.Black
ButtonBabyBlue.HoverBackground = render.RGBA(0, 220, 255, 255)
ButtonBabyBlue.HoverForeground = render.White
ButtonBabyBlue.HoverForeground = render.Black
ButtonPink.Background = render.RGBA(255, 153, 255, 255)
ButtonPink.HoverBackground = render.RGBA(255, 220, 255, 255)

View File

@ -3,6 +3,7 @@ package doodle
import (
"fmt"
"path/filepath"
"strconv"
"strings"
"time"
@ -259,7 +260,29 @@ func (d *Doodle) NewMap() {
}
// NewDoodad loads a new Doodad in Edit Mode.
// If size is zero, it prompts the user to select a size or accept the default size.
func (d *Doodle) NewDoodad(size int) {
if size == 0 {
d.Prompt(fmt.Sprintf("Doodad size or %d>", balance.DoodadSize), func(answer string) {
size := balance.DoodadSize
if answer != "" {
i, err := strconv.Atoi(answer)
if err != nil {
d.Flash("Error: Doodad size must be a number.")
return
}
size = i
}
// Recurse with the proper answer.
if size <= 0 {
d.Flash("Error: Doodad size must be a positive number.")
}
d.NewDoodad(size)
})
return
}
log.Info("Starting a new doodad")
scene := &EditorScene{
DrawingType: enum.DoodadDrawing,

View File

@ -5,8 +5,6 @@ package doodle
// The rest of it is controlled in editor_ui.go
import (
"strconv"
"git.kirsle.net/apps/doodle/pkg/balance"
"git.kirsle.net/apps/doodle/pkg/drawtool"
"git.kirsle.net/apps/doodle/pkg/enum"
@ -56,18 +54,8 @@ func (u *EditorUI) SetupMenuBar(d *Doodle) *ui.MenuBar {
fileMenu.AddItemAccel("New level", "Ctrl-N", u.Scene.MenuNewLevel)
fileMenu.AddItem("New doodad", func() {
u.Scene.ConfirmUnload(func() {
d.Prompt("Doodad size [100]>", func(answer string) {
size := balance.DoodadSize
if answer != "" {
i, err := strconv.Atoi(answer)
if err != nil {
d.Flash("Error: Doodad size must be a number.")
return
}
size = i
}
d.NewDoodad(size)
})
// New doodad size with prompt.
d.NewDoodad(0)
})
})
fileMenu.AddItemAccel("Save", "Ctrl-S", u.Scene.MenuSave(false))

View File

@ -17,6 +17,7 @@ import (
"git.kirsle.net/go/render"
"git.kirsle.net/go/render/event"
"git.kirsle.net/go/ui"
"git.kirsle.net/go/ui/style"
)
// MainScene implements the main menu of Doodle.
@ -155,24 +156,35 @@ func (s *MainScene) Setup(d *Doodle) error {
s.frame = frame
var buttons = []struct {
Name string
Func func()
Name string
Func func()
Style *style.Button
}{
// {
// Name: "Story Mode",
// Func: d.GotoStoryMenu,
// },
{
Name: "Play a Level",
Func: d.GotoPlayMenu,
Name: "Play a Level",
Func: d.GotoPlayMenu,
Style: &balance.ButtonBabyBlue,
},
{
Name: "Create a New Level",
Func: d.GotoNewMenu,
Name: "Create a Level",
Func: d.GotoNewMenu,
Style: &balance.ButtonPink,
},
{
Name: "Edit a Level",
Func: d.GotoLoadMenu,
Name: "Create a Doodad",
Func: func() {
d.NewDoodad(0)
},
Style: &balance.ButtonPink,
},
{
Name: "Edit a Drawing",
Func: d.GotoLoadMenu,
Style: &balance.ButtonPrimary,
},
{
Name: "Settings",
@ -194,6 +206,9 @@ func (s *MainScene) Setup(d *Doodle) error {
button.Func()
return nil
})
if button.Style != nil {
btn.SetStyle(button.Style)
}
s.Supervisor.Add(btn)
frame.Pack(btn, ui.Pack{
Side: ui.N,

View File

@ -28,7 +28,8 @@ func (w *Canvas) commitStroke(tool drawtool.Tool, addHistory bool) {
return
}
// Zoom the stroke coordinates (this modifies the pointer)
// Zoom the stroke coordinates (this modifies the pointer).
// Note: all the points on the stroke were mouse cursor coordinates on the screen.
w.currentStroke = w.ZoomStroke(w.currentStroke)
// Mark the canvas as modified.

View File

@ -117,7 +117,6 @@ func (w *Canvas) ZoomStroke(stroke *drawtool.Stroke) *drawtool.Stroke {
Points: stroke.Points,
OriginalPoints: stroke.OriginalPoints,
}
return copy
// Multiply all coordinates in this stroke, which should be World
// Coordinates in the level data, by the zoom multiplier.