twitchapon-anim

Basic Twitchapon Receiver/Visuals
git clone git://bsandro.tech/twitchapon-anim
Log | Files | Refs | README | LICENSE

shiny.go (1344B)


      1 // Copyright 2015 The Go Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 // +build windows
      6 
      7 package app
      8 
      9 import (
     10 	"log"
     11 
     12 	"golang.org/x/exp/shiny/driver/gldriver"
     13 	"golang.org/x/exp/shiny/screen"
     14 	"golang.org/x/mobile/event/lifecycle"
     15 	"golang.org/x/mobile/event/mouse"
     16 	"golang.org/x/mobile/event/touch"
     17 	"golang.org/x/mobile/gl"
     18 )
     19 
     20 func main(f func(a App)) {
     21 	gldriver.Main(func(s screen.Screen) {
     22 		w, err := s.NewWindow(nil)
     23 		if err != nil {
     24 			log.Fatal(err)
     25 		}
     26 		defer w.Release()
     27 
     28 		theApp.glctx = nil
     29 		theApp.worker = nil // handled by shiny
     30 
     31 		go func() {
     32 			for range theApp.publish {
     33 				res := w.Publish()
     34 				theApp.publishResult <- PublishResult{
     35 					BackBufferPreserved: res.BackBufferPreserved,
     36 				}
     37 			}
     38 		}()
     39 
     40 		go f(theApp)
     41 
     42 		for {
     43 			theApp.Send(convertEvent(w.NextEvent()))
     44 		}
     45 	})
     46 }
     47 
     48 func convertEvent(e interface{}) interface{} {
     49 	switch e := e.(type) {
     50 	case lifecycle.Event:
     51 		if theApp.glctx == nil {
     52 			theApp.glctx = e.DrawContext.(gl.Context)
     53 		}
     54 	case mouse.Event:
     55 		te := touch.Event{
     56 			X: e.X,
     57 			Y: e.Y,
     58 		}
     59 		switch e.Direction {
     60 		case mouse.DirNone:
     61 			te.Type = touch.TypeMove
     62 		case mouse.DirPress:
     63 			te.Type = touch.TypeBegin
     64 		case mouse.DirRelease:
     65 			te.Type = touch.TypeEnd
     66 		}
     67 		return te
     68 	}
     69 	return e
     70 }