74 lines
1.4 KiB
Go
74 lines
1.4 KiB
Go
|
package allegro5
|
||
|
|
||
|
// #include <allegro5/allegro.h>
|
||
|
import "C"
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"unsafe"
|
||
|
)
|
||
|
|
||
|
// Display represents a display
|
||
|
type Display struct {
|
||
|
display *C.ALLEGRO_DISPLAY
|
||
|
}
|
||
|
|
||
|
type NewDisplayOptions struct {
|
||
|
Width int
|
||
|
Height int
|
||
|
Fullscreen bool
|
||
|
Resizable bool
|
||
|
Windowed bool
|
||
|
}
|
||
|
|
||
|
// NewDisplay creates a display
|
||
|
func NewDisplay(options NewDisplayOptions) (*Display, error) {
|
||
|
var flags C.int = C.ALLEGRO_WINDOWED
|
||
|
if options.Fullscreen {
|
||
|
if options.Windowed {
|
||
|
flags |= C.ALLEGRO_FULLSCREEN_WINDOW
|
||
|
} else {
|
||
|
flags = C.ALLEGRO_FULLSCREEN
|
||
|
}
|
||
|
}
|
||
|
if options.Resizable {
|
||
|
flags |= C.ALLEGRO_RESIZABLE
|
||
|
}
|
||
|
C.al_set_new_display_flags(flags)
|
||
|
d := C.al_create_display(C.int(options.Width), C.int(options.Height))
|
||
|
if nil == d {
|
||
|
return nil, fmt.Errorf("Error creating display")
|
||
|
}
|
||
|
return &Display{d}, nil
|
||
|
}
|
||
|
|
||
|
// Flips flips the buffer to the display
|
||
|
func (d *Display) Flip() {
|
||
|
C.al_flip_display()
|
||
|
}
|
||
|
|
||
|
func (d *Display) Width() int {
|
||
|
return int(C.al_get_display_width(d.display))
|
||
|
}
|
||
|
|
||
|
func (d *Display) Height() int {
|
||
|
return int(C.al_get_display_height(d.display))
|
||
|
}
|
||
|
|
||
|
func (d *Display) SetWindowTitle(title string) {
|
||
|
t := C.CString(title)
|
||
|
defer C.free(unsafe.Pointer(t))
|
||
|
C.al_set_window_title(d.display, t)
|
||
|
}
|
||
|
|
||
|
// Destroy destroys the display
|
||
|
func (d *Display) Destroy() {
|
||
|
C.al_destroy_display(d.display)
|
||
|
}
|
||
|
|
||
|
func SetNewWindowTitle(title string) {
|
||
|
t := C.CString(title)
|
||
|
defer C.free(unsafe.Pointer(t))
|
||
|
C.al_set_new_window_title(t)
|
||
|
}
|