Example #1
0
func (mw *MainWindow) drawStuff(surface *drawing.Surface, updateBounds drawing.Rectangle) os.Error {
	bmp := createBitmap()
	defer bmp.Dispose()

	bounds, err := mw.paintWidget.ClientBounds()
	panicIfErr(err)

	rectPen, err := drawing.NewCosmeticPen(drawing.PenSolid, drawing.RGB(255, 0, 0))
	panicIfErr(err)
	defer rectPen.Dispose()

	panicIfErr(surface.DrawRectangle(rectPen, bounds))

	ellipseBrush, err := drawing.NewHatchBrush(drawing.RGB(0, 255, 0), drawing.HatchCross)
	panicIfErr(err)
	defer ellipseBrush.Dispose()

	panicIfErr(surface.FillEllipse(ellipseBrush, bounds))

	linesBrush, err := drawing.NewSolidColorBrush(drawing.RGB(0, 0, 255))
	panicIfErr(err)
	defer linesBrush.Dispose()

	linesPen, err := drawing.NewGeometricPen(drawing.PenDash, 8, linesBrush)
	panicIfErr(err)
	defer linesPen.Dispose()

	panicIfErr(surface.DrawLine(linesPen, drawing.Point{bounds.X, bounds.Y}, drawing.Point{bounds.Width, bounds.Height}))
	panicIfErr(surface.DrawLine(linesPen, drawing.Point{bounds.X, bounds.Height}, drawing.Point{bounds.Width, bounds.Y}))

	bmpSize := bmp.Size()
	panicIfErr(surface.DrawImage(bmp, drawing.Point{bounds.Width/2 - bmpSize.Width/2, bounds.Height/2 - bmpSize.Height/2}))

	return nil
}
Example #2
0
func createBitmap() *drawing.Bitmap {
	bounds := drawing.Rectangle{Width: 200, Height: 200}

	bmp, err := drawing.NewBitmap(bounds.Size())
	panicIfErr(err)

	surface, err := drawing.NewSurfaceFromImage(bmp)
	panicIfErr(err)
	defer surface.Dispose()

	brushBmp, err := drawing.NewBitmapFromFile("img/plus.png")
	panicIfErr(err)
	defer brushBmp.Dispose()

	brush, err := drawing.NewBitmapBrush(brushBmp)
	panicIfErr(err)
	defer brush.Dispose()

	panicIfErr(surface.FillRectangle(brush, bounds))

	font, err := drawing.NewFont("Times New Roman", 40, drawing.FontBold|drawing.FontItalic)
	panicIfErr(err)
	defer font.Dispose()

	panicIfErr(surface.DrawText("Runtime Created Bitmap", font, drawing.RGB(0, 0, 0), bounds, drawing.TextWordbreak))

	return bmp
}
Example #3
0
func main() {
	runtime.LockOSThread()

	doc := printing.NewDocument("Walk Printing Example")
	defer doc.Dispose()

	doc.InsertPageBreak()

	text := "Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua."
	font, err := drawing.NewFont("Times New Roman", 12, 0)
	panicIfErr(err)
	color := drawing.RGB(0, 0, 0)
	preferredSize := drawing.Size{1000, 0}
	format := drawing.TextWordbreak

	for i := 0; i < 20; i++ {
		panicIfErr(doc.AddText(fmt.Sprintf("%d) %s", i, text), font, color, preferredSize, format))
	}

	panicIfErr(doc.Print())
}