func NewDisplay(width, height, border, heading int, name string) (*Display, error) { d := new(Display) d.w = float64(width) d.h = float64(height) d.bord = float64(border) d.head = float64(heading) X, err := xgbutil.NewConn() if err != nil { return nil, err } keybind.Initialize(X) d.ximg = xgraphics.New(X, image.Rect( 0, 0, border*2+width, border*2+heading+height)) err = d.ximg.CreatePixmap() if err != nil { return nil, err } painter := NewXimgPainter(d.ximg) d.gc = draw2d.NewGraphicContextWithPainter(d.ximg, painter) d.gc.Save() d.gc.SetStrokeColor(color.White) d.gc.SetFillColor(color.White) d.gc.Clear() d.wid = d.ximg.XShowExtra(name, true) d.x = X go func() { xevent.Main(X) }() return d, nil }
// NewImage returns a new image canvas // that draws to the given image. The // minimum point of the given image // should probably be 0,0. func NewImage(img draw.Image, name string) (*XImgCanvas, error) { w := float64(img.Bounds().Max.X - img.Bounds().Min.X) h := float64(img.Bounds().Max.Y - img.Bounds().Min.Y) X, err := xgbutil.NewConn() if err != nil { return nil, err } keybind.Initialize(X) ximg := xgraphics.New(X, image.Rect(0, 0, int(w), int(h))) err = ximg.CreatePixmap() if err != nil { return nil, err } painter := NewXimgPainter(ximg) gc := draw2d.NewGraphicContextWithPainter(ximg, painter) gc.SetDPI(dpi) gc.Scale(1, -1) gc.Translate(0, -h) wid := ximg.XShowExtra(name, true) go func() { xevent.Main(X) }() c := &XImgCanvas{ gc: gc, w: vg.Inches(w / dpi), h: vg.Inches(h / dpi), color: []color.Color{color.Black}, x: X, ximg: ximg, wid: wid, } vg.Initialize(c) return c, nil }
func NewGraphicContext(img draw.Image) *draw2d.ImageGraphicContext { return draw2d.NewGraphicContextWithPainter(img, NewDIBPainter(img.(*win.DIB))) }