Exemplo n.º 1
0
func (ctxt *context) setFractal(f Fractal, centre draw.Point) {
	if ctxt.item != nil {
		ctxt.tiler.Stop()
		ctxt.cvs.Delete(ctxt.item)
	}
	ctxt.f = f
	ctxt.tiler = NewTiler(f, ctxt.cache, *tileSize)
	ctxt.item = canvas.Draggable(canvas.Moveable(ctxt.tiler))
	ctxt.item.SetCentre(centre)
	ctxt.cvs.AddItem(ctxt.item)
	ctxt.cvs.Flush()
}
Exemplo n.º 2
0
func main() {
	win, err := x11.NewWindow()
	if win == nil {
		log.Fatalf("no window: %v", err)
	}
	screen := win.Screen()

	bg := canvas.NewBackground(screen.(*image.RGBA), image.White, flushFunc(win))
	cvs = canvas.NewCanvas(nil, bg.Rect())
	bg.SetItem(cvs)

	item := canvas.Draggable(canvas.Moveable(
		canvas.NewText(
			image.ZP,
			0,
			"Hello, world",
			defaultFont(),
			30,
			nil)))
	item.SetCentre(image.Pt(cvs.Rect().Dx()/2, cvs.Rect().Dy()/3))
	cvs.AddItem(item)
	//	txtitem :=	canvas.NewText(
	//			image.Pt(100, 100),
	//			0,
	//			"Working?",
	//			defaultFont(),
	//			20,
	//			nil)

	//	img := canvas.ImageOf(txtitem)

	//	cvs.AddItem(canvas.NewImage(img, false, image.Pt(cvs.Width() / 2, cvs.Height()*2/3)))

	cvs.Flush()
	ec := win.EventChan()
	for {
		switch e := (<-ec).(type) {
		case nil:
			log.Fatal("quitting")
			return
		case draw.MouseEvent:
			if e.Buttons == 0 {
				break
			}
			cvs.HandleMouse(cvs, e, ec)
		}
	}
}