Ejemplo n.º 1
0
func (mw *MainWindow) drawStuff(canvas *walk.Canvas, updateBounds walk.Rectangle) os.Error {
	bmp := createBitmap()
	defer bmp.Dispose()

	bounds := mw.paintWidget.ClientBounds()

	rectPen, _ := walk.NewCosmeticPen(walk.PenSolid, walk.RGB(255, 0, 0))
	defer rectPen.Dispose()

	canvas.DrawRectangle(rectPen, bounds)

	ellipseBrush, _ := walk.NewHatchBrush(walk.RGB(0, 255, 0), walk.HatchCross)
	defer ellipseBrush.Dispose()

	canvas.FillEllipse(ellipseBrush, bounds)

	linesBrush, _ := walk.NewSolidColorBrush(walk.RGB(0, 0, 255))
	defer linesBrush.Dispose()

	linesPen, _ := walk.NewGeometricPen(walk.PenDash, 8, linesBrush)
	defer linesPen.Dispose()

	canvas.DrawLine(linesPen, walk.Point{bounds.X, bounds.Y}, walk.Point{bounds.Width, bounds.Height})
	canvas.DrawLine(linesPen, walk.Point{bounds.X, bounds.Height}, walk.Point{bounds.Width, bounds.Y})

	bmpSize := bmp.Size()
	canvas.DrawImage(bmp, walk.Point{(bounds.Width - bmpSize.Width) / 2, (bounds.Height - bmpSize.Height) / 2})

	return nil
}
Ejemplo n.º 2
0
func createBitmap() *walk.Bitmap {
	bounds := walk.Rectangle{Width: 200, Height: 200}

	bmp, _ := walk.NewBitmap(bounds.Size())

	succeeded := false
	defer func() {
		if !succeeded {
			bmp.Dispose()
		}
	}()

	canvas, _ := walk.NewCanvasFromImage(bmp)
	defer canvas.Dispose()

	brushBmp, _ := walk.NewBitmapFromFile("../img/plus.png")
	defer brushBmp.Dispose()

	brush, _ := walk.NewBitmapBrush(brushBmp)
	defer brush.Dispose()

	canvas.FillRectangle(brush, bounds)

	font, _ := walk.NewFont("Times New Roman", 40, walk.FontBold|walk.FontItalic)
	defer font.Dispose()

	canvas.DrawText("Walk Drawing Example", font, walk.RGB(0, 0, 0), bounds, walk.TextWordbreak)

	succeeded = true
	return bmp
}
Ejemplo n.º 3
0
func main() {
	walk.Initialize(walk.InitParams{PanicOnError: true})
	defer walk.Shutdown()

	doc := walk.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, _ := walk.NewFont("Times New Roman", 12, 0)
	color := walk.RGB(0, 0, 0)
	preferredSize := walk.Size{1000, 0}
	format := walk.TextWordbreak

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

	doc.Print()
}