func (mw *MainWindow) drawStuff(canvas *walk.Canvas, updateBounds walk.Rectangle) 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 }
func main() { var mw *walk.MainWindow var c1 *walk.Composite var c2 *walk.Composite bmp, err := walk.NewBitmapFromFile("../../img/plus.png") if err != nil { panic(err) } defer bmp.Dispose() MainWindow{ AssignTo: &mw, Title: "Background Example", Layout: VBox{MarginsZero: true}, MinSize: Size{300, 400}, Children: []Widget{ Composite{ AssignTo: &c1, Layout: VBox{}, Children: []Widget{ TextEdit{}, }, }, Composite{ AssignTo: &c2, Layout: VBox{}, Children: []Widget{ TextEdit{}, }, }, ImageView{ Image: bmp, }, }, }.Create() scb, err := walk.NewSolidColorBrush(walk.RGB(255, 0, 0)) if err != nil { panic(err) } defer scb.Dispose() c1.SetBackground(scb) bmb, err := walk.NewBitmapBrush(bmp) if err != nil { panic(err) } defer bmb.Dispose() c2.SetBackground(bmb) mw.Show() mw.Run() }
func NewMyWidget(parent walk.Container) (*MyWidget, error) { w := new(MyWidget) if err := walk.InitChildWidget( w, parent, myWidgetWindowClass, winapi.WS_VISIBLE, 0); err != nil { return nil, err } bg, err := walk.NewSolidColorBrush(walk.RGB(0, 255, 0)) if err != nil { return nil, err } w.SetBackground(bg) return w, nil }
func (mw *MyMainWindow) drawStuff(canvas *walk.Canvas, updateBounds walk.Rectangle) error { bmp, err := createBitmap() if err != nil { return err } defer bmp.Dispose() bounds := mw.paintWidget.ClientBounds() rectPen, err := walk.NewCosmeticPen(walk.PenSolid, walk.RGB(255, 0, 0)) if err != nil { return err } defer rectPen.Dispose() if err := canvas.DrawRectangle(rectPen, bounds); err != nil { return err } ellipseBrush, err := walk.NewHatchBrush(walk.RGB(0, 255, 0), walk.HatchCross) if err != nil { return err } defer ellipseBrush.Dispose() if err := canvas.FillEllipse(ellipseBrush, bounds); err != nil { return err } linesBrush, err := walk.NewSolidColorBrush(walk.RGB(0, 0, 255)) if err != nil { return err } defer linesBrush.Dispose() linesPen, err := walk.NewGeometricPen(walk.PenDash, 8, linesBrush) if err != nil { return err } defer linesPen.Dispose() if err := canvas.DrawLine(linesPen, walk.Point{bounds.X, bounds.Y}, walk.Point{bounds.Width, bounds.Height}); err != nil { return err } if err := canvas.DrawLine(linesPen, walk.Point{bounds.X, bounds.Height}, walk.Point{bounds.Width, bounds.Y}); err != nil { return err } points := make([]walk.Point, 10) dx := bounds.Width / (len(points) - 1) for i := range points { points[i].X = i * dx points[i].Y = int(float64(bounds.Height) / math.Pow(float64(bounds.Width/2), 2) * math.Pow(float64(i*dx-bounds.Width/2), 2)) } if err := canvas.DrawPolyline(linesPen, points); err != nil { return err } bmpSize := bmp.Size() if err := canvas.DrawImage(bmp, walk.Point{(bounds.Width - bmpSize.Width) / 2, (bounds.Height - bmpSize.Height) / 2}); err != nil { return err } return nil }