Exemplo n.º 1
0
func main() {
	ui.Main(func() {
		w := ui.NewWidget()

		w.OnPaintEvent(func(e *ui.PaintEvent) {
			paint := ui.NewPainter()
			defer paint.Close()
			paint.Begin(w)
			pen := ui.NewPen()
			pen.SetColor(color.RGBA{255, 128, 0, 0})
			pen.SetWidth(2)
			fmt.Println(pen, pen.Color(), pen.Width())
			paint.SetPen(pen)
			brush := ui.NewBrush()
			brush.SetStyle(ui.SolidPattern)
			brush.SetColor(color.RGBA{128, 128, 0, 255})
			paint.SetBrush(brush)
			paint.DrawRect(ui.Rect{10, 10, 100, 100})
		})

		w.SetSize(ui.Size{400, 400})
		w.Show()

		ui.Run()
	})
}
Exemplo n.º 2
0
func drawPlace(e *ui.PaintEvent, w *ui.Widget) {
	p := ui.NewPainter()
	defer p.Close()
	p.Begin(w)

	pen := ui.NewPen()
	pen.SetColor(color.RGBA{0, 0, 0, 0})

	ft := p.Font()
	ft.SetPixelSize(CELL_WIDTH * 8 / 10)
	p.SetFont(ft)
	for i := 0; i <= len(placeCells); i++ {
		if i%3 == 0 {
			pen.SetWidth(3)
		} else {
			pen.SetWidth(1)
		}
		p.SetPen(pen)
		p.DrawLine(ui.Pt(0, i*CELL_WIDTH), ui.Pt(9*CELL_WIDTH, i*CELL_WIDTH))
		p.DrawLine(ui.Pt(i*CELL_WIDTH, 0), ui.Pt(i*CELL_WIDTH, 9*CELL_WIDTH))
	}

	var pt ui.Point
	for y := 0; y < 9; y++ {
		for x := 0; x < 9; x++ {
			if placeCells[y][x].num != 0 {
				pt.X = x*CELL_WIDTH + 4 // TODO display position adjustment
				pt.Y = (y+1)*CELL_WIDTH - 4
				if placeCells[y][x].kind == CELL_KIND_ERROR {
					pen.SetColor(color.RGBA{255, 0, 0, 0})
				} else if placeCells[y][x].kind == CELL_KIND_FIXED {
					pen.SetColor(color.RGBA{0, 0, 0, 0})
				} else {
					pen.SetColor(color.RGBA{0, 0, 255, 0})
				}
				p.SetPen(pen)
				p.DrawText(pt, fmt.Sprintf("%c", placeCells[y][x].num+'0'))
			}
		}
	}
	if cursorx != -1 {
		var rc ui.Rect
		pen.SetColor(color.RGBA{200, 0, 0, 0})
		pen.SetWidth(3)

		p.SetPen(pen)
		rc.X = cursorx * CELL_WIDTH
		rc.Y = cursory * CELL_WIDTH
		rc.Width = CELL_WIDTH
		rc.Height = CELL_WIDTH
		p.DrawRect(rc)
	}
	p.End()
}