twitchapon-anim

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

drawer.go (1258B)


      1 // Copyright 2016 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 // Package drawer provides functions that help implement screen.Drawer methods.
      6 package drawer // import "golang.org/x/exp/shiny/driver/internal/drawer"
      7 
      8 import (
      9 	"image"
     10 	"image/draw"
     11 
     12 	"golang.org/x/exp/shiny/screen"
     13 	"golang.org/x/image/math/f64"
     14 )
     15 
     16 // Copy implements the Copy method of the screen.Drawer interface by calling
     17 // the Draw method of that same interface.
     18 func Copy(dst screen.Drawer, dp image.Point, src screen.Texture, sr image.Rectangle, op draw.Op, opts *screen.DrawOptions) {
     19 	dst.Draw(f64.Aff3{
     20 		1, 0, float64(dp.X - sr.Min.X),
     21 		0, 1, float64(dp.Y - sr.Min.Y),
     22 	}, src, sr, op, opts)
     23 }
     24 
     25 // Scale implements the Scale method of the screen.Drawer interface by calling
     26 // the Draw method of that same interface.
     27 func Scale(dst screen.Drawer, dr image.Rectangle, src screen.Texture, sr image.Rectangle, op draw.Op, opts *screen.DrawOptions) {
     28 	rx := float64(dr.Dx()) / float64(sr.Dx())
     29 	ry := float64(dr.Dy()) / float64(sr.Dy())
     30 	dst.Draw(f64.Aff3{
     31 		rx, 0, float64(dr.Min.X) - rx*float64(sr.Min.X),
     32 		0, ry, float64(dr.Min.Y) - ry*float64(sr.Min.Y),
     33 	}, src, sr, op, opts)
     34 }