doodle/wasm/main_wasm.go
Noah Petherbridge 0c6c77a423 Lemon-shaped Ellipse Tool (WIP)
* Add initial Ellipse Tool to the Editor Mode. Currently there's
  something wrong with the algorithm and the ellipses have a sort of
  'lemon shape' to them.
* Refactor the IterLine/IterLine2 functions to be more consistent.
  IterLine used to be the raw algorithm that took a bunch of coordinate
  numbers and IterLine2 took two render.Point's and was the main one
  used throughout the app. Now, IterLine takes the two Points and the
  raw algorithm function removed.
2019-07-14 14:18:44 -07:00

94 lines
1.9 KiB
Go

// +build js,wasm
package main
import (
"fmt"
"syscall/js"
"git.kirsle.net/apps/doodle/lib/render"
"git.kirsle.net/apps/doodle/lib/render/canvas"
doodle "git.kirsle.net/apps/doodle/pkg"
"git.kirsle.net/apps/doodle/pkg/balance"
"git.kirsle.net/apps/doodle/pkg/branding"
"git.kirsle.net/apps/doodle/pkg/log"
)
func main() {
fmt.Printf("Hello world\n")
// testRawCanvas()
// Enable workarounds.
balance.DisableChunkTextureCache = true
js.Global().Get("sessionStorage").Call("clear")
// HTML5 Canvas engine.
engine, _ := canvas.New("canvas")
engine.AddEventListeners()
game := doodle.New(true, engine)
game.SetupEngine()
doodle.DebugOverlay = true
// Manually inform Doodle of the canvas size since it can't control
// the size on its own.
w, h := engine.WindowSize()
game.SetWindowSize(w, h)
// game.Goto(&doodle.GUITestScene{})
game.Goto(&doodle.EditorScene{})
game.Run()
}
func testRawCanvas() {
engine, _ := canvas.New("canvas")
engine.SetTitle(
fmt.Sprintf("%s v%s", branding.AppName, branding.Version),
)
fmt.Printf("Got engine: %+v\n", engine)
engine.Clear(render.Green)
for pt := range render.IterLine(render.NewPoint(20, 20), render.NewPoint(300, 300)) {
engine.DrawPoint(render.Red, pt)
}
engine.DrawLine(render.Blue, render.NewPoint(20, 300), render.NewPoint(300, 20))
engine.DrawRect(render.Black, render.Rect{
X: 5,
Y: 5,
W: 10,
H: 10,
})
engine.DrawBox(render.White, render.Rect{
X: 5,
Y: 5,
W: 10,
H: 10,
})
engine.DrawBox(render.Purple, render.Rect{
X: 25,
Y: 5,
W: 10,
H: 10,
})
engine.DrawText(render.Text{
Text: "Hello world!",
FontFilename: "DejaVuSans",
Size: 14,
}, render.NewPoint(400, 400))
size, _ := engine.ComputeTextRect(render.Text{
Text: "Hello world! blah blah",
FontFilename: "DejaVuSans",
Size: 14,
})
log.Info("text rect: %+v", size)
_ = engine
}