From 499dff7a96200f2203940c0b5d86384d72239e52 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Mon, 26 Feb 2018 19:46:53 +0100 Subject: [PATCH] Added New{Memory,Video}Bitmap functions to create memory/video bitmap directly. Added new bitmap flags to New{Memory,Bitmap,}Bitmap methods. --- allegro5/bitmap.go | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/allegro5/bitmap.go b/allegro5/bitmap.go index 20b96bc..00b621c 100644 --- a/allegro5/bitmap.go +++ b/allegro5/bitmap.go @@ -51,8 +51,17 @@ type Rotation struct { Center bool } -// NewBitmap creates a new bitmap of given width and height -func NewBitmap(width, height int) (*Bitmap, error) { +func newBitmap(width, height int, mut func(m FlagMutation), flags []NewBitmapFlag) (*Bitmap, error) { + var newBmpFlags = CaptureNewBitmapFlags() + defer newBmpFlags.Revert() + newBmpFlags.Mutate(func(m FlagMutation) { + if nil != mut { + mut(m) + } + for _, f := range flags { + m.Set(f) + } + }) b := C.al_create_bitmap(C.int(width), C.int(height)) if nil == b { return nil, errors.New("error creating bitmap") @@ -60,6 +69,27 @@ func NewBitmap(width, height int) (*Bitmap, error) { return &Bitmap{b, width, height}, nil } +// NewBitmap creates a new bitmap of given width and height and optional flags +func NewBitmap(width, height int, flags ...NewBitmapFlag) (*Bitmap, error) { + return newBitmap(width, height, nil, flags) +} + +// NewVideoBitmap creates a new video bitmap of given width and height and optional flags +func NewVideoBitmap(width, height int, flags ...NewBitmapFlag) (*Bitmap, error) { + return newBitmap(width, height, func(m FlagMutation) { + m.Unset(NewBitmapFlagMemoryBitmap) + m.Set(NewBitmapFlagVideoBitmap) + }, flags) +} + +// NewMemoryBitmap creates a new video bitmap of given width and height and optional flags +func NewMemoryBitmap(width, height int, flags ...NewBitmapFlag) (*Bitmap, error) { + return newBitmap(width, height, func(m FlagMutation) { + m.Unset(NewBitmapFlagVideoBitmap) + m.Set(NewBitmapFlagMemoryBitmap) + }, flags) +} + // NewBitmapFromImage creates a new bitmap starting from a Go native image (image.Image) func NewBitmapFromImage(im image.Image, video bool) (*Bitmap, error) { var newBmpFlags = CaptureNewBitmapFlags()