Lower case error strings.

Added Position and SetAsTarget method to Display.
Display resize is automatically acknowledged.
This commit is contained in:
Sander Schobers 2018-02-13 20:59:55 +01:00
parent ca64417bb8
commit 0652c02caf
5 changed files with 26 additions and 16 deletions

View File

@ -6,7 +6,6 @@ import "C"
import ( import (
"errors" "errors"
"fmt"
"image" "image"
"image/color" "image/color"
"unsafe" "unsafe"
@ -56,7 +55,7 @@ type Rotation struct {
func NewBitmap(width, height int) (*Bitmap, error) { func NewBitmap(width, height int) (*Bitmap, error) {
b := C.al_create_bitmap(C.int(width), C.int(height)) b := C.al_create_bitmap(C.int(width), C.int(height))
if nil == b { if nil == b {
return nil, fmt.Errorf("Error creating bitmap") return nil, errors.New("error creating bitmap")
} }
return &Bitmap{b, width, height}, nil return &Bitmap{b, width, height}, nil
} }
@ -98,7 +97,7 @@ func LoadBitmap(path string) (*Bitmap, error) {
defer C.free(unsafe.Pointer(p)) defer C.free(unsafe.Pointer(p))
b := C.al_load_bitmap(p) b := C.al_load_bitmap(p)
if nil == b { 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)) width := int(C.al_get_bitmap_width(b))
height := int(C.al_get_bitmap_height(b)) height := int(C.al_get_bitmap_height(b))

View File

@ -4,7 +4,7 @@ package allegro5
import "C" import "C"
import ( import (
"fmt" "errors"
"unsafe" "unsafe"
) )
@ -41,7 +41,7 @@ func NewDisplay(width, height int, options NewDisplayOptions) (*Display, error)
C.al_set_new_display_flags(flags) C.al_set_new_display_flags(flags)
d := C.al_create_display(C.int(width), C.int(height)) d := C.al_create_display(C.int(width), C.int(height))
if nil == d { if nil == d {
return nil, fmt.Errorf("Error creating display") return nil, errors.New("error creating display")
} }
return &Display{d}, nil return &Display{d}, nil
} }
@ -59,6 +59,16 @@ func (d *Display) Height() int {
return int(C.al_get_display_height(d.display)) 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) { func (d *Display) SetWindowTitle(title string) {
t := C.CString(title) t := C.CString(title)
defer C.free(unsafe.Pointer(t)) defer C.free(unsafe.Pointer(t))

View File

@ -4,7 +4,7 @@ package allegro5
import "C" import "C"
import ( import (
"fmt" "errors"
"unsafe" "unsafe"
) )
@ -120,7 +120,7 @@ type MouseMoveEvent struct {
func NewEventQueue() (*EventQueue, error) { func NewEventQueue() (*EventQueue, error) {
q := C.al_create_event_queue() q := C.al_create_event_queue()
if nil == q { 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 return &EventQueue{q}, nil
} }
@ -152,6 +152,7 @@ func (eq *EventQueue) mapEvent(e *C.ALLEGRO_EVENT) Event {
return &DisplayOrientationEvent{eb, toDisplayOrientation(display.orientation)} return &DisplayOrientationEvent{eb, toDisplayOrientation(display.orientation)}
case C.ALLEGRO_EVENT_DISPLAY_RESIZE: case C.ALLEGRO_EVENT_DISPLAY_RESIZE:
display := (*C.ALLEGRO_DISPLAY_EVENT)(unsafe.Pointer(e)) 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)} return &DisplayResizeEvent{eb, int(display.x), int(display.y), int(display.width), int(display.height)}
case C.ALLEGRO_EVENT_MOUSE_AXES: case C.ALLEGRO_EVENT_MOUSE_AXES:
mouse := (*C.ALLEGRO_MOUSE_EVENT)(unsafe.Pointer(e)) mouse := (*C.ALLEGRO_MOUSE_EVENT)(unsafe.Pointer(e))

View File

@ -28,7 +28,7 @@ func LoadTTFFont(path string, size int) (*Font, error) {
f := C.al_load_ttf_font(p, C.int(size), 0) f := C.al_load_ttf_font(p, C.int(size), 0)
if nil == f { 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 return &Font{f}, nil
} }

View File

@ -11,7 +11,7 @@ package allegro5
import "C" import "C"
import ( import (
"fmt" "errors"
) )
type InitConfig struct { type InitConfig struct {
@ -27,25 +27,25 @@ var InitAll = InitConfig{true, true, true, true, true}
// Init initializes the Allegro system // Init initializes the Allegro system
func Init(config InitConfig) error { func Init(config InitConfig) error {
if !bool(C.init()) { 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()) { 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()) { 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()) { 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()) { 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()) { 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()) { if config.Mouse && !bool(C.al_install_mouse()) {
return fmt.Errorf("Failed to install mouse") return errors.New("failed to install mouse")
} }
return nil return nil
} }