Lower case error strings.
Added Position and SetAsTarget method to Display. Display resize is automatically acknowledged.
This commit is contained in:
parent
ca64417bb8
commit
0652c02caf
@ -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))
|
||||
|
@ -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))
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user