Exemplo n.º 1
0
Arquivo: main.go Projeto: rdterner/exp
func main() {
	driver.Main(func(s screen.Screen) {
		w, err := s.NewWindow(nil)
		if err != nil {
			log.Fatal(err)
		}
		defer w.Release()

		winSize := image.Point{256, 256}
		b, err := s.NewBuffer(winSize)
		if err != nil {
			log.Fatal(err)
		}
		defer b.Release()
		drawGradient(b.RGBA())

		t, err := s.NewTexture(winSize)
		if err != nil {
			log.Fatal(err)
		}
		defer t.Release()
		t.Upload(image.Point{}, b, b.Bounds(), w)

		var sz size.Event
		for e := range w.Events() {
			switch e := e.(type) {
			default:
				// TODO: be more interesting.
				fmt.Printf("got %#v\n", e)

			case key.Event:
				fmt.Printf("got %v\n", e)
				if e.Code == key.CodeEscape {
					return
				}

			case paint.Event:
				w.Fill(sz.Bounds(), blue0, draw.Src)
				w.Fill(sz.Bounds().Inset(10), blue1, draw.Src)
				w.Upload(image.Point{}, b, b.Bounds(), w)
				c := math.Cos(math.Pi / 6)
				s := math.Sin(math.Pi / 6)
				w.Draw(f64.Aff3{
					+c, -s, 100,
					+s, +c, 200,
				}, t, t.Bounds(), screen.Over, nil)
				w.Publish()

			case screen.UploadedEvent:
				// No-op.

			case size.Event:
				sz = e

			case error:
				log.Print(e)
			}
		}
	})
}
Exemplo n.º 2
0
Arquivo: win.go Projeto: s2607/mbrot
func main() {
	driver.Main(func(s screen.Screen) {
		w, err := s.NewWindow(nil)
		if err != nil {
			log.Fatal(err)
		}
		defer w.Release()
		winSize := image.Point{1000, 1000}
		b, err := s.NewBuffer(winSize)
		if err != nil {
			log.Fatal(err)
		}
		defer b.Release()
		drawGradient(b.RGBA())
		t, err := s.NewTexture(winSize)
		if err != nil {
			log.Fatal(err)
		}
		defer t.Release()
		t.Upload(image.Point{}, b, b.Bounds())
		var sz size.Event
		for e := range w.Events() {
			// This print message is to help programmers learn what events this
			// example program generates. A real program shouldn't print such
			// messages; they're not important to end users.
			format := "got %#v\n"
			if _, ok := e.(fmt.Stringer); ok {
				format = "got %v\n"
			}
			fmt.Printf(format, e)
			switch e := e.(type) {
			case lifecycle.Event:
				if e.To == lifecycle.StageDead {
					return
				}
			case key.Event:
				if e.Code == key.CodeEscape {
					return
				}
			case paint.Event:
				w.Fill(sz.Bounds(), blue0, draw.Src)
				w.Fill(sz.Bounds().Inset(10), blue1, draw.Src)
				w.Upload(image.Point{}, b, b.Bounds())
				w.Publish()
			case size.Event:
				sz = e
			case error:
				log.Print(e)
			}
		}
	})
}
Exemplo n.º 3
0
func (m *Module) Display(display Display, sz size.Event, glctx gl.Context, images *glutil.Images) {
	im := images.NewImage(sz.WidthPx, sz.HeightPx)

	switch {
	case m.err != nil:
		// There was an error of some kind. We should display the error indication until the error
		// is removed from the module by a timeout.
		m.renderInformation(im.RGBA, sz.Size(), errorBackground, "T_T", "T_T")
	case !display.Loaded:
		// We haven't loaded any predictions yet. Dislay the loading screen.
		loadingStr := "Loading" + strings.Repeat(".", int(time.Now().Unix()%4))
		m.renderInformation(im.RGBA, sz.Size(), loadingBackground, loadingStr, "Loading...")
	case !display.NextOK:
		// We don't have a prediction for the next train. This is probably because there are no
		// trains coming for a while (ex., after nightly shutdown).
		m.renderInformation(im.RGBA, sz.Size(), loadingBackground, "No trains :(", "No trains :(")
	default:
		// If everything else is ok, then we have at least 1 prediction. Display it.
		m.render(im.RGBA, display, sz.Size())
	}

	if display.TransitRouteName != "" {
		m.renderTransitRouteName(im.RGBA, sz.Size(), display.TransitRouteName)
	}

	im.Upload()
	im.Draw(
		sz,
		geom.Point{},
		geom.Point{X: sz.WidthPt},
		geom.Point{Y: sz.HeightPt},
		sz.Bounds())
	im.Release()
}
Exemplo n.º 4
0
Arquivo: main.go Projeto: sbinet/iview
func main() {
	// Run the CPU profile if we're instructed to.
	if len(flagProfile) > 0 {
		f, err := os.Create(flagProfile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	// Whoops!
	if flag.NArg() == 0 {
		fmt.Fprint(os.Stderr, "\n")
		log.Print("No images specified.\n\n")
		usage()
	}

	driver.Main(func(s screen.Screen) {
		// Decode all images (in parallel).
		names, imgs := decodeImages(findFiles(flag.Args()))

		// Die now if we don't have any images!
		if len(imgs) == 0 {
			log.Fatal("No images specified could be shown. Quitting...")
		}

		winSize := image.Point{flagWidth, flagHeight}
		// Auto-size the window if appropriate.
		if flagAutoResize {
			log.Printf(">>> img[%s]...\n", names[0])
			b := imgs[0].Bounds()
			winSize = image.Point{b.Dx(), b.Dy()}
		}

		w, err := s.NewWindow(&screen.NewWindowOptions{
			Width:  winSize.X,
			Height: winSize.Y,
		})
		if err != nil {
			log.Fatal(err)
		}
		defer w.Release()

		b, err := s.NewBuffer(winSize)
		if err != nil {
			log.Fatal(err)
		}
		defer b.Release()

		w.Fill(b.Bounds(), color.White, draw.Src)
		w.Publish()

		var sz size.Event
		var i int // index of image to display
		for {
			e := w.NextEvent()
			switch e := e.(type) {
			default:

			case mouse.Event:

			case key.Event:
				repaint := false
				switch e.Code {
				case key.CodeEscape, key.CodeQ:
					return
				case key.CodeRightArrow:
					if e.Direction == key.DirPress {
						if i == len(imgs)-1 {
							i = -1
						}
						i++
						repaint = true
						b.Release()
						b, err = s.NewBuffer(sz.Size())
						if err != nil {
							log.Fatal(err)
						}
					}

				case key.CodeLeftArrow:
					if e.Direction == key.DirPress {
						if i == 0 {
							i = len(imgs)
						}
						i--
						repaint = true
						b, err = s.NewBuffer(sz.Size())
						if err != nil {
							log.Fatal(err)
						}
					}

				case key.CodeR:
					if e.Direction == key.DirPress {
						// resize to current image
						r := imgs[i].Bounds()
						sz.HeightPx = r.Dy()
						sz.WidthPx = r.Dx()
						repaint = true
						b, err = s.NewBuffer(sz.Size())
						if err != nil {
							log.Fatal(err)
						}
						w.Publish()

					}
				}
				if repaint {
					w.Send(paint.Event{})
				}

			case paint.Event:
				img := imgs[i]
				draw.Draw(b.RGBA(), b.Bounds(), img, image.Point{}, draw.Src)
				dp := vpCenter(img, sz.WidthPx, sz.HeightPx)
				zero := image.Point{}
				if dp != zero {
					w.Fill(sz.Bounds(), color.Black, draw.Src)
				}
				w.Upload(dp, b, b.Bounds())

			case size.Event:
				sz = e

			case error:
				log.Print(e)
			}
		}
	})
}