コード例 #1
0
ファイル: uidoc.go プロジェクト: duckbrain/uidoc
func (r *measureHandler) Draw(a *ui.Area, dp *ui.AreaDrawParams) {
	if r.parent.width != dp.AreaWidth {
		fmt.Sprintf("Size changed: %v\n", dp.AreaWidth)
		r.parent.layout(dp.AreaWidth)
	}

	//Fill background
	p := ui.NewPath(ui.Winding)
	p.AddRectangle(0, 0, dp.AreaWidth, dp.AreaHeight)
	p.End()
	dp.Context.Fill(p, &ui.Brush{
		A: 1,
	})
}
コード例 #2
0
ファイル: uidoc.go プロジェクト: duckbrain/uidoc
func (r *drawHandler) Draw(a *ui.Area, dp *ui.AreaDrawParams) {
	if r.parent.doc == nil {
		return
	}
	f := r.parent.doc.Fill()
	if f == nil {
		f = &ui.Brush{A: 1, R: 1, G: 1, B: 1}
	}
	p := ui.NewPath(ui.Winding)
	p.AddRectangle(dp.ClipX, dp.ClipY, dp.ClipWidth, dp.ClipHeight)
	p.End()
	dp.Context.Fill(p, f)
	r.parent.doc.Render(dp, 0, 0)
}
コード例 #3
0
ファイル: group.go プロジェクト: duckbrain/uidoc
func (g *Group) Render(dp *ui.AreaDrawParams, x, y float64) {
	for _, l := range g.layouts {
		if b := l.e.Fill(); b != nil {
			l.path = ui.NewPath(ui.Winding)
			pTop, pRight, pBottom, pLeft := l.e.Padding()
			l.path.AddRectangle(x+l.x-pLeft, y+l.y-pTop, l.w+pLeft+pRight, l.h+pTop+pBottom)
			l.path.End()
			dp.Context.Fill(l.path, l.e.Fill())
			if stroke, thickness := l.e.Stroke(); stroke != nil {
				dp.Context.Stroke(l.path, stroke, &ui.StrokeParams{Thickness: thickness})
			}
		}
		l.e.Render(dp, x+l.x, y+l.y)
	}
}
コード例 #4
0
ファイル: histogram.go プロジェクト: plumbum/go-samples
func (a HistogramAreaHandler) Draw(area *ui.Area, dp *ui.AreaDrawParams) {

	fntNum := ui.LoadClosestFont(&ui.FontDescriptor{Family: "Droid Sans", Size: 10, Weight: ui.TextWeightBold})
	fntVolume := ui.LoadClosestFont(&ui.FontDescriptor{Family: "Droid Sans", Size: 12, Italic: ui.TextItalicItalic})

	brush := &ui.Brush{Type: ui.Solid, R: 0.1, G: 0.5, B: 0.7, A: 1}

	columnWidth := dp.AreaWidth / float64(len(a.Data))
	barWidth := columnWidth * 0.8

	for i, volume := range a.Data {

		x1 := (float64(i) + 0.1) * columnWidth
		x2 := x1 + barWidth
		y1 := dp.AreaHeight - 16
		y2 := y1 - (dp.AreaHeight-32.0)*float64(volume)/100.0

		layoutNum := ui.NewTextLayout(strconv.Itoa(i), fntNum, columnWidth)
		w1, _ := layoutNum.Extents()
		dp.Context.Text(x1+(barWidth-w1)/2, y1, layoutNum)

		layoutVolume := ui.NewTextLayout(strconv.Itoa(volume), fntVolume, columnWidth)
		w2, h2 := layoutVolume.Extents()
		dp.Context.Text(x1+(barWidth-w2)/2, y2-h2, layoutVolume)

		dp.Context.Save()
		p := ui.NewPath(ui.Winding)
		p.NewFigure(x1, y1)
		p.LineTo(x2, y1)
		p.LineTo(x2, y2)
		p.LineTo(x1, y2)
		p.CloseFigure()
		p.End()
		dp.Context.Fill(p, brush)
		dp.Context.Restore()
	}

}