Пример #1
0
/*
  <img src="../test_results/TestFillStyle.png"/>
*/
func TestFillStyle() {
	i, gc := initGc(w, h)
	gc.SetLineWidth(6)

	draw2d.Rect(gc, 12, 12, 244, 70)

	wheel1 := new(draw2d.PathStorage)
	wheel1.ArcTo(64, 64, 40, 40, 0, 2*math.Pi)
	wheel2 := new(draw2d.PathStorage)
	wheel2.ArcTo(192, 64, 40, 40, 0, 2*math.Pi)

	gc.SetFillRule(draw2d.FillRuleEvenOdd)
	gc.SetFillColor(color.NRGBA{0, 0xB2, 0, 0xFF})

	gc.SetStrokeColor(image.Black)
	gc.FillStroke(wheel1, wheel2)

	draw2d.Rect(gc, 12, 140, 244, 198)
	wheel1 = new(draw2d.PathStorage)
	wheel1.ArcTo(64, 192, 40, 40, 0, 2*math.Pi)
	wheel2 = new(draw2d.PathStorage)
	wheel2.ArcTo(192, 192, 40, 40, 0, -2*math.Pi)

	gc.SetFillRule(draw2d.FillRuleWinding)
	gc.SetFillColor(color.NRGBA{0, 0, 0xE5, 0xFF})
	gc.FillStroke(wheel1, wheel2)
	saveToPngFile("TestFillStyle", i)
}
Пример #2
0
func SetupDisplay() (ctrlChan chan interface{}) {
	ctrlChan = make(chan interface{})
	X, err := xgbutil.NewConn()
	if err != nil {
		log.Fatal(err)
	}

	fontReader, err := os.Open(fontPath)
	if err != nil {
		log.Fatal(err)
	}

	// Now parse the font.
	font, err := xgraphics.ParseFont(fontReader)
	if err != nil {
		log.Fatal(err)
	}

	img, gc := initGc(width+border*2, height+heading+border*2)
	ximg := xgraphics.NewConvert(X, img)
	wid := ximg.XShowExtra("Regiment", true)

	circle := new(draw2d.PathStorage)

	ctr := 0
	fps := 0
	go func() {
		for {
			c := <-ctrlChan
			switch c := c.(type) {
			case *generals.Regiment:
				c.Step()
				rp := c.Position()
				gc.SetFillColor(image.Black)
				gc.SetStrokeColor(image.Black)

				for i := 0; i < len(rp.RowPath); i++ {
					x, y := rp.RowPath[i].X, rp.RowPath[i].Y
					circle = new(draw2d.PathStorage)
					circle.ArcTo(x+border, y+border+heading, 1, 1, 0, 2*math.Pi)
					gc.FillStroke(circle)
				}

				for i := 0; i < len(rp.ColPath); i++ {
					x, y := rp.ColPath[i].X, rp.ColPath[i].Y
					circle = new(draw2d.PathStorage)
					circle.ArcTo(x+border, y+border+heading, 1, 1, 0, 2*math.Pi)
					gc.FillStroke(circle)
				}

			case *Frame:
				for xp := border; xp < (width + border); xp++ {
					for yp := border; yp < (height + border + heading); yp++ {
						ximg.Set(xp, yp, img.At(xp, yp))
					}
				}
				_, _, err = ximg.Text(10, 0, fg, size, font, fmt.Sprintf("FPS: %v", fps))
				if err != nil {
					log.Fatal(err)
				}
				ximg.XDraw()
				ximg.XPaint(wid.Id)
				ctr++

				gc.SetFillColor(image.White)
				// fill the background
				gc.Clear()
			case *Timing:
				fps = ctr
				_, _, err = ximg.Text(10, 0, fg, size, font, fmt.Sprintf("FPS: %v", fps))
				ctr = 0
			default:
				fmt.Println(reflect.TypeOf(c))
			}
		}
	}()

	go func() {
		xevent.Main(X)
	}()
	return ctrlChan
}