diff --git a/shiny.go b/shiny.go index 067cd88..11c0af6 100644 --- a/shiny.go +++ b/shiny.go @@ -6,6 +6,7 @@ import ( "fmt" "image" "image/draw" + "image/png" "io" "os" "sync" @@ -31,6 +32,9 @@ import ( //go:generate go-bindata -o internal/assets/assets.go -pkg assets DroidSansMono.ttf const perfUpdate = false +const dumpFrame = false + +var frameCnt = 0 var UnknownCommandErr = errors.New("unknown command") @@ -313,8 +317,13 @@ func (ctx *context) processKeyEvent(e key.Event, textbuffer *bytes.Buffer) { } func (w *masterWindow) updater() { + var down bool for { - time.Sleep(20 * time.Millisecond) + if down { + time.Sleep(10 * time.Millisecond) + } else { + time.Sleep(20 * time.Millisecond) + } func() { w.uilock.Lock() defer w.uilock.Unlock() @@ -326,7 +335,7 @@ func (w *masterWindow) updater() { atomic.AddInt32(&w.ctx.changed, -1) w.updateLocked() } else { - down := false + down = false for _, btn := range w.ctx.Input.Mouse.Buttons { if btn.Down { down = true @@ -357,6 +366,10 @@ func (w *masterWindow) updateLocked() { t0 = time.Now() } + if dumpFrame && !perfUpdate { + panic("dumpFrame") + } + w.ctx.Update() if perfUpdate || w.Perf { @@ -391,6 +404,20 @@ func (w *masterWindow) updateLocked() { d.Dot = fixed.P(bounds.Min.X, bounds.Min.Y+w.ctx.Style.Font.Metrics().Ascent.Ceil()) d.DrawString(s) } + if dumpFrame && frameCnt < 1000 && nprimitives > 0 { + wimg := w.wndb.RGBA() + + bounds := image.Rect(w.ctx.Input.Mouse.Pos.X, w.ctx.Input.Mouse.Pos.Y, w.ctx.Input.Mouse.Pos.X+10, w.ctx.Input.Mouse.Pos.Y+10) + + draw.Draw(wimg, bounds, image.White, bounds.Min, draw.Src) + + fh, err := os.Create(fmt.Sprintf("framedump/frame%d.png", frameCnt)) + if err == nil { + png.Encode(fh, wimg) + fh.Close() + } + frameCnt++ + } if nprimitives > 0 { w.wnd.Upload(w.bounds.Min, w.wndb, w.bounds) w.wnd.Publish()