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 } 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 }
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 }