示例#1
0
文件: openvg.go 项目: xranby/openvg
// Image places the image in s image at (x,y) with dimensions (w,h)
func Image(x, y float64, w, h int, s string) {
	f, ferr := os.Open(s)
	if ferr != nil {
		fakeimage(x, y, w, h, s)
		return
	}
	defer f.Close()
	img, _, err := image.Decode(f)
	if err != nil {
		fakeimage(x, y, w, h, s)
		return
	}
	bounds := img.Bounds()
	minx := bounds.Min.X
	maxx := bounds.Max.X
	miny := bounds.Min.Y
	maxy := bounds.Max.Y
	data := make([]C.VGubyte, w*h*4)
	n := 0
	// println("minx", minx, "maxx", maxx, "miny", miny, "maxy", maxy)
	for y := miny; y < maxy; y++ {
		for x := minx; x < maxx; x++ {
			r, g, b, a := img.At(x, (maxy-1)-y).RGBA() // OpenVG has origin at lower left, y increasing up
			data[n] = C.VGubyte(r)
			n++
			data[n] = C.VGubyte(g)
			n++
			data[n] = C.VGubyte(b)
			n++
			data[n] = C.VGubyte(a)
			n++
		}
	}
	C.makeimage(C.VGfloat(x), C.VGfloat(y), C.int(w), C.int(h), &data[0])
}
示例#2
0
文件: openvg.go 项目: xranby/openvg
// poly converts coordinate slices
func poly(x, y []float64) (*C.VGfloat, *C.VGfloat, C.VGint) {
	size := len(x)
	if size != len(y) {
		return nil, nil, 0
	}
	px := make([]C.VGfloat, size)
	py := make([]C.VGfloat, size)
	for i := 0; i < size; i++ {
		px[i] = C.VGfloat(x[i])
		py[i] = C.VGfloat(y[i])
	}
	return &px[0], &py[0], C.VGint(size)
}
示例#3
0
// makestops prepares the color/stop vector
func makeramp(r []Offcolor) (*C.VGfloat, C.int) {
	lr := len(r)
	nr := lr * 5
	cs := make([]C.VGfloat, nr)
	j := 0
	for i := 0; i < lr; i++ {
		cs[j] = C.VGfloat(r[i].Offset)
		j++
		cs[j] = C.VGfloat(VGfloat(r[i].Red) / 255.0)
		j++
		cs[j] = C.VGfloat(VGfloat(r[i].Green) / 255.0)
		j++
		cs[j] = C.VGfloat(VGfloat(r[i].Blue) / 255.0)
		j++
		cs[j] = C.VGfloat(r[i].Alpha)
		j++
	}
	return &cs[0], C.int(lr)
}
示例#4
0
// Image places the named image at (x,y) with dimensions (w,h)
func Image(x, y float64, w, h int, s string) {
	var img image.Image
	var derr error
	f, err := os.Open(s)
	if err != nil {
		fakeimage(x, y, w, h, s)
		return
	}
	img, _, derr = image.Decode(f)
	defer f.Close()
	if derr != nil {
		fakeimage(x, y, w, h, s)
		return
	}
	bounds := img.Bounds()
	minx := bounds.Min.X
	maxx := bounds.Max.X
	miny := bounds.Min.Y
	maxy := bounds.Max.Y
	data := make([]C.VGubyte, w*h*4)
	n := 0
	var r, g, b, a uint32
	for yp := miny; yp < maxy; yp++ {
		for xp := minx; xp < maxx; xp++ {
			r, g, b, a = img.At(xp, (maxy-1)-yp).RGBA() // OpenVG has origin at lower left, y increasing up
			data[n] = C.VGubyte(r)
			n++
			data[n] = C.VGubyte(g)
			n++
			data[n] = C.VGubyte(b)
			n++
			data[n] = C.VGubyte(a)
			n++
		}
	}
	C.makeimage(C.VGfloat(x), C.VGfloat(y), C.int(w), C.int(h), &data[0])
}
示例#5
0
// Img places an image object at (x,y)
func Img(x, y VGfloat, im image.Image) {
	bounds := im.Bounds()
	minx := bounds.Min.X
	maxx := bounds.Max.X
	miny := bounds.Min.Y
	maxy := bounds.Max.Y
	data := make([]C.VGubyte, bounds.Dx()*bounds.Dy()*4)
	n := 0
	var r, g, b, a uint32
	for yp := miny; yp < maxy; yp++ {
		for xp := minx; xp < maxx; xp++ {
			r, g, b, a = im.At(xp, (maxy-1)-yp).RGBA() // OpenVG has origin at lower left, y increasing up
			data[n] = C.VGubyte(r >> 8)
			n++
			data[n] = C.VGubyte(g >> 8)
			n++
			data[n] = C.VGubyte(b >> 8)
			n++
			data[n] = C.VGubyte(a >> 8)
			n++
		}
	}
	C.makeimage(C.VGfloat(x), C.VGfloat(y), C.int(bounds.Dx()), C.int(bounds.Dy()), &data[0])
}
示例#6
0
文件: openvg.go 项目: xranby/openvg
// Ellipse draws an ellipse at (x,y) with dimensions (w,h)
func Ellipse(x, y, w, h float64, style ...string) {
	C.Ellipse(C.VGfloat(x), C.VGfloat(y), C.VGfloat(w), C.VGfloat(h))
}
示例#7
0
文件: openvg.go 项目: xranby/openvg
// Rect draws a rounded rectangle at (x,y) with dimensions (w,h).
// the corner radii are at (rw, rh)
func Roundrect(x, y, w, h, rw, rh float64, style ...string) {
	C.Roundrect(C.VGfloat(x), C.VGfloat(y), C.VGfloat(w), C.VGfloat(h), C.VGfloat(rw), C.VGfloat(rh))
}
示例#8
0
// Arc draws an arc at (x,y) with dimensions (w,h).
// the arc starts at the angle sa, extended to aext
func Arc(x, y, w, h, sa, aext VGfloat) {
	C.Arc(C.VGfloat(x), C.VGfloat(y), C.VGfloat(w), C.VGfloat(h), C.VGfloat(sa), C.VGfloat(aext))
}
示例#9
0
文件: openvg.go 项目: xranby/openvg
// Shear warps the coordinate system by (x,y)
func Shear(x, y float64) {
	C.Shear(C.VGfloat(x), C.VGfloat(y))
}
示例#10
0
文件: openvg.go 项目: xranby/openvg
// Translate translates the coordinate system to (x,y)
func Translate(x, y float64) {
	C.Translate(C.VGfloat(x), C.VGfloat(y))
}
示例#11
0
文件: openvg.go 项目: xranby/openvg
// Cbezier draws a cubic bezier curve with extrema (sx, sy) and (ex, ey).
// Control points at (cx, cy) and (px, py)
func Cbezier(sx, sy, cx, cy, px, py, ex, ey float64, style ...string) {
	C.Cbezier(C.VGfloat(sx), C.VGfloat(sy), C.VGfloat(cx), C.VGfloat(cy), C.VGfloat(px), C.VGfloat(py), C.VGfloat(ex), C.VGfloat(ey))
}
示例#12
0
文件: openvg.go 项目: xranby/openvg
// BackgroundRGB clears the screen with the specified background color using a RGBA quad
func BackgroundRGB(r, g, b uint8, alpha float64) {
	C.BackgroundRGB(C.uint(r), C.uint(g), C.uint(b), C.VGfloat(alpha))
}
示例#13
0
文件: openvg.go 项目: xranby/openvg
// FillRGB sets the fill color, using RGB triples
func FillRGB(r, g, b uint8, alpha float64) {
	C.Fill(C.uint(r), C.uint(g), C.uint(b), C.VGfloat(alpha))
}
示例#14
0
// Shear warps the coordinate system by (x,y)
func Shear(x, y VGfloat) {
	C.Shear(C.VGfloat(x), C.VGfloat(y))
}
示例#15
0
// Scale scales the coordinate system by (x,y)
func Scale(x, y VGfloat) {
	C.Scale(C.VGfloat(x), C.VGfloat(y))
}
示例#16
0
// Rotate rotates the coordinate system around the specifed angle
func Rotate(r VGfloat) {
	C.Rotate(C.VGfloat(r))
}
示例#17
0
// Translate translates the coordinate system to (x,y)
func Translate(x, y VGfloat) {
	C.Translate(C.VGfloat(x), C.VGfloat(y))
}
示例#18
0
// TextEnd draws text end-aligned at (x,y)
func TextEnd(x, y VGfloat, s string, font string, size int) {
	t := C.CString(s)
	C.TextEnd(C.VGfloat(x), C.VGfloat(y), t, selectfont(font), C.int(size))
	C.free(unsafe.Pointer(t))
}
示例#19
0
文件: openvg.go 项目: xranby/openvg
// Circle draws a circle centered at (x,y), with radius r
func Circle(x, y, r float64, style ...string) {
	C.Circle(C.VGfloat(x), C.VGfloat(y), C.VGfloat(r))
}
示例#20
0
文件: openvg.go 项目: xranby/openvg
// StrokeRGB sets the stroke color, using RGB triples
func StrokeRGB(r, g, b uint8, alpha float64) {
	C.Stroke(C.uint(r), C.uint(g), C.uint(b), C.VGfloat(alpha))
}
示例#21
0
文件: openvg.go 项目: xranby/openvg
// Qbezier draws a quadratic bezier curve with extrema (sx, sy) and (ex, ey)
// Control points are at (cx, cy)
func Qbezier(sx, sy, cx, cy, ex, ey float64, style ...string) {
	C.Qbezier(C.VGfloat(sx), C.VGfloat(sy), C.VGfloat(cx), C.VGfloat(cy), C.VGfloat(ex), C.VGfloat(ey))
}
示例#22
0
文件: openvg.go 项目: xranby/openvg
// StrokeWidth sets the stroke width
func StrokeWidth(w float64) {
	C.StrokeWidth(C.VGfloat(w))
}
示例#23
0
文件: openvg.go 项目: xranby/openvg
// Arc draws an arc at (x,y) with dimensions (w,h).
// the arc starts at the angle sa, extended to aext
func Arc(x, y, w, h, sa, aext float64, style ...string) {
	C.Arc(C.VGfloat(x), C.VGfloat(y), C.VGfloat(w), C.VGfloat(h), C.VGfloat(sa), C.VGfloat(aext))
}
示例#24
0
// Qbezier draws a quadratic bezier curve with extrema (sx, sy) and (ex, ey)
// Control points are at (cx, cy)
func Qbezier(sx, sy, cx, cy, ex, ey VGfloat) {
	C.Qbezier(C.VGfloat(sx), C.VGfloat(sy), C.VGfloat(cx), C.VGfloat(cy), C.VGfloat(ex), C.VGfloat(ey))
}
示例#25
0
文件: openvg.go 项目: xranby/openvg
// TextEnd draws text end-aligned at (x,y)
func TextEnd(x, y float64, s string, font string, size int, style ...string) {
	t := C.CString(s)
	defer C.free(unsafe.Pointer(t))
	C.TextEnd(C.VGfloat(x), C.VGfloat(y), t, selectfont(font), C.int(size))
}
示例#26
0
文件: openvg.go 项目: xranby/openvg
// Line draws a line between two points
func Line(x1, y1, x2, y2 float64, style ...string) {
	C.Line(C.VGfloat(x1), C.VGfloat(y1), C.VGfloat(x2), C.VGfloat(y2))
}
示例#27
0
文件: openvg.go 项目: xranby/openvg
// Rotate rotates the coordinate system around the specifed angle
func Rotate(r float64) {
	C.Rotate(C.VGfloat(r))
}
示例#28
0
文件: openvg.go 项目: xranby/openvg
// Rect draws a rectangle at (x,y) with dimensions (w,h)
func Rect(x, y, w, h float64, style ...string) {
	C.Rect(C.VGfloat(x), C.VGfloat(y), C.VGfloat(w), C.VGfloat(h))
}
示例#29
0
文件: openvg.go 项目: xranby/openvg
// Scale scales the coordinate system by (x,y)
func Scale(x, y float64) {
	C.Scale(C.VGfloat(x), C.VGfloat(y))
}
示例#30
0
// Cbezier draws a cubic bezier curve with extrema (sx, sy) and (ex, ey).
// Control points at (cx, cy) and (px, py)
func Cbezier(sx, sy, cx, cy, px, py, ex, ey VGfloat) {
	C.Cbezier(C.VGfloat(sx), C.VGfloat(sy), C.VGfloat(cx), C.VGfloat(cy), C.VGfloat(px), C.VGfloat(py), C.VGfloat(ex), C.VGfloat(ey))
}