Esempio n. 1
0
func createBitmap() (*walk.Bitmap, error) {
	bounds := walk.Rectangle{Width: 200, Height: 200}

	bmp, err := walk.NewBitmap(bounds.Size())
	if err != nil {
		return nil, err
	}

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

	canvas, err := walk.NewCanvasFromImage(bmp)
	if err != nil {
		return nil, err
	}
	defer canvas.Dispose()

	brushBmp, err := walk.NewBitmapFromFile("../img/plus.png")
	if err != nil {
		return nil, err
	}
	defer brushBmp.Dispose()

	brush, err := walk.NewBitmapBrush(brushBmp)
	if err != nil {
		return nil, err
	}
	defer brush.Dispose()

	if err := canvas.FillRectangle(brush, bounds); err != nil {
		return nil, err
	}

	font, err := walk.NewFont("Times New Roman", 40, walk.FontBold|walk.FontItalic)
	if err != nil {
		return nil, err
	}
	defer font.Dispose()

	if err := canvas.DrawText("Walk Drawing Example", font, walk.RGB(0, 0, 0), bounds, walk.TextWordbreak); err != nil {
		return nil, err
	}

	succeeded = true

	return bmp, nil
}
Esempio n. 2
0
func (f Font) Create() (*walk.Font, error) {
	if f.Family == "" && f.PointSize == 0 {
		return nil, nil
	}

	var fs walk.FontStyle

	if f.Bold {
		fs |= walk.FontBold
	}
	if f.Italic {
		fs |= walk.FontItalic
	}
	if f.Underline {
		fs |= walk.FontUnderline
	}
	if f.StrikeOut {
		fs |= walk.FontStrikeOut
	}

	return walk.NewFont(f.Family, f.PointSize, fs)
}