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()