Beispiel #1
0
func NewControlPoint(value, colValue values.Value) canvas.Item {
	cp := new(ControlPoint)
	cp.value = value
	cp.col = image.Black
	cp.colValue = colValue
	cp.backing = (*canvas.Canvas)(nil)
	go cp.listener()
	return canvas.Draggable(cp)
}
Beispiel #2
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()
}
Beispiel #3
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)
		}
	}
}
Beispiel #4
0
func monitor(mkball <-chan ball, delball <-chan bool, pause <-chan bool) {
	ballcountText := canvas.NewText(
		image.Pt(window.Rect().Max.X-5, 5), canvas.N|canvas.E, "0 balls", defaultFont(), 30, nil)
	window.AddItem(canvas.Draggable(ballcountText))
	ballcountText.SetFill(image.NewUniform(red))
	window.Flush()
	ctl := make(chan (chan<- bool))
	nballs := 0
	for {
		select {
		case b := <-mkball:
			go animateBall(ctl, b)
			nballs++
			ballcountText.SetText(fmt.Sprintf("%d balls", nballs))
			window.Flush()

		case <-pause:
			reply := make(chan bool)
			for i := 0; i < nballs; i++ {
				ctl <- reply
			}
			<-pause
			for i := 0; i < nballs; i++ {
				<-reply
			}
		case <-delball:
			// delete a random ball
			if nballs > 0 {
				ctl <- nil
				nballs--
				ballcountText.SetText(fmt.Sprintf("%d balls", nballs))
				window.Flush()
			}
		}
	}
}
Beispiel #5
0
func makeRect(r image.Rectangle, col color.Color) {
	img := canvas.Box(r.Dx(), r.Dy(), image.NewUniform(col), 1, image.Black)
	item := canvas.NewImage(img, opaqueColor(col), r.Min)
	window.AddItem(canvas.Draggable(item))
}