From 0652c02caf25a4694d49f41ed8becdbdb7408ee2 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Tue, 13 Feb 2018 20:59:55 +0100 Subject: [PATCH] Lower case error strings. Added Position and SetAsTarget method to Display. Display resize is automatically acknowledged. --- allegro5/bitmap.go | 5 ++--- allegro5/display.go | 14 ++++++++++++-- allegro5/event.go | 5 +++-- allegro5/font.go | 2 +- allegro5/system.go | 16 ++++++++-------- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/allegro5/bitmap.go b/allegro5/bitmap.go index f7aeebf..9d7a9af 100644 --- a/allegro5/bitmap.go +++ b/allegro5/bitmap.go @@ -6,7 +6,6 @@ import "C" import ( "errors" - "fmt" "image" "image/color" "unsafe" @@ -56,7 +55,7 @@ type Rotation struct { func NewBitmap(width, height int) (*Bitmap, error) { b := C.al_create_bitmap(C.int(width), C.int(height)) if nil == b { - return nil, fmt.Errorf("Error creating bitmap") + return nil, errors.New("error creating bitmap") } return &Bitmap{b, width, height}, nil } @@ -98,7 +97,7 @@ func LoadBitmap(path string) (*Bitmap, error) { defer C.free(unsafe.Pointer(p)) b := C.al_load_bitmap(p) if nil == b { - return nil, fmt.Errorf("Error loading bitmap") + return nil, errors.New("error loading bitmap") } width := int(C.al_get_bitmap_width(b)) height := int(C.al_get_bitmap_height(b)) diff --git a/allegro5/display.go b/allegro5/display.go index ead3879..3bcfb58 100644 --- a/allegro5/display.go +++ b/allegro5/display.go @@ -4,7 +4,7 @@ package allegro5 import "C" import ( - "fmt" + "errors" "unsafe" ) @@ -41,7 +41,7 @@ func NewDisplay(width, height int, options NewDisplayOptions) (*Display, error) C.al_set_new_display_flags(flags) d := C.al_create_display(C.int(width), C.int(height)) if nil == d { - return nil, fmt.Errorf("Error creating display") + return nil, errors.New("error creating display") } return &Display{d}, nil } @@ -59,6 +59,16 @@ func (d *Display) Height() int { return int(C.al_get_display_height(d.display)) } +func (d *Display) Position() (int, int) { + var x, y C.int + C.al_get_window_position(d.display, &x, &y) + return int(x), int(y) +} + +func (d *Display) SetAsTarget() { + C.al_set_target_backbuffer(d.display) +} + func (d *Display) SetWindowTitle(title string) { t := C.CString(title) defer C.free(unsafe.Pointer(t)) diff --git a/allegro5/event.go b/allegro5/event.go index 8501c13..013c9e8 100644 --- a/allegro5/event.go +++ b/allegro5/event.go @@ -4,7 +4,7 @@ package allegro5 import "C" import ( - "fmt" + "errors" "unsafe" ) @@ -120,7 +120,7 @@ type MouseMoveEvent struct { func NewEventQueue() (*EventQueue, error) { q := C.al_create_event_queue() if nil == q { - return nil, fmt.Errorf("Unable to create event queue") + return nil, errors.New("unable to create event queue") } return &EventQueue{q}, nil } @@ -152,6 +152,7 @@ func (eq *EventQueue) mapEvent(e *C.ALLEGRO_EVENT) Event { return &DisplayOrientationEvent{eb, toDisplayOrientation(display.orientation)} case C.ALLEGRO_EVENT_DISPLAY_RESIZE: display := (*C.ALLEGRO_DISPLAY_EVENT)(unsafe.Pointer(e)) + C.al_acknowledge_resize(display.source) return &DisplayResizeEvent{eb, int(display.x), int(display.y), int(display.width), int(display.height)} case C.ALLEGRO_EVENT_MOUSE_AXES: mouse := (*C.ALLEGRO_MOUSE_EVENT)(unsafe.Pointer(e)) diff --git a/allegro5/font.go b/allegro5/font.go index 3a88174..511fe71 100644 --- a/allegro5/font.go +++ b/allegro5/font.go @@ -28,7 +28,7 @@ func LoadTTFFont(path string, size int) (*Font, error) { f := C.al_load_ttf_font(p, C.int(size), 0) if nil == f { - return nil, fmt.Errorf("Unable to load TTF font '%s'", path) + return nil, fmt.Errorf("unable to load ttf font '%s'", path) } return &Font{f}, nil } diff --git a/allegro5/system.go b/allegro5/system.go index f95ea8f..653c8e1 100644 --- a/allegro5/system.go +++ b/allegro5/system.go @@ -11,7 +11,7 @@ package allegro5 import "C" import ( - "fmt" + "errors" ) type InitConfig struct { @@ -27,25 +27,25 @@ var InitAll = InitConfig{true, true, true, true, true} // Init initializes the Allegro system func Init(config InitConfig) error { if !bool(C.init()) { - return fmt.Errorf("Failed to initialize Allegro") + return errors.New("failed to initialize Allegro") } if config.Font && !bool(C.al_init_font_addon()) { - return fmt.Errorf("Failed to initialize font addon") + return errors.New("failed to initialize font addon") } if config.Font && !bool(C.al_init_ttf_addon()) { - return fmt.Errorf("Failed to initialize ttf addon") + return errors.New("failed to initialize ttf addon") } if config.Image && !bool(C.al_init_image_addon()) { - return fmt.Errorf("Failed to initialize image addon") + return errors.New("failed to initialize image addon") } if config.Primitives && !bool(C.al_init_primitives_addon()) { - return fmt.Errorf("Failed to initialize primitives addon") + return errors.New("failed to initialize primitives addon") } if config.Keyboard && !bool(C.al_install_keyboard()) { - return fmt.Errorf("Failed to install keyboard") + return errors.New("failed to install keyboard") } if config.Mouse && !bool(C.al_install_mouse()) { - return fmt.Errorf("Failed to install mouse") + return errors.New("failed to install mouse") } return nil }