2017-10-03 18:38:09 +00:00
|
|
|
package allegro5
|
|
|
|
|
|
|
|
// #include <allegro5/allegro.h>
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
2018-02-13 19:59:55 +00:00
|
|
|
"errors"
|
2017-10-03 18:38:09 +00:00
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Display represents a display
|
|
|
|
type Display struct {
|
|
|
|
display *C.ALLEGRO_DISPLAY
|
|
|
|
}
|
|
|
|
|
|
|
|
type NewDisplayOptions struct {
|
|
|
|
Fullscreen bool
|
|
|
|
Resizable bool
|
|
|
|
Windowed bool
|
2018-02-12 18:49:10 +00:00
|
|
|
Maximized bool
|
2018-06-04 19:15:53 +00:00
|
|
|
Frameless bool
|
2017-10-03 18:38:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewDisplay creates a display
|
2018-02-12 18:54:33 +00:00
|
|
|
func NewDisplay(width, height int, options NewDisplayOptions) (*Display, error) {
|
2017-10-03 18:38:09 +00:00
|
|
|
var flags C.int = C.ALLEGRO_WINDOWED
|
|
|
|
if options.Fullscreen {
|
|
|
|
if options.Windowed {
|
|
|
|
flags |= C.ALLEGRO_FULLSCREEN_WINDOW
|
|
|
|
} else {
|
|
|
|
flags = C.ALLEGRO_FULLSCREEN
|
|
|
|
}
|
2018-06-04 19:15:53 +00:00
|
|
|
} else if options.Frameless {
|
|
|
|
flags |= C.ALLEGRO_FRAMELESS
|
2017-10-03 18:38:09 +00:00
|
|
|
}
|
|
|
|
if options.Resizable {
|
|
|
|
flags |= C.ALLEGRO_RESIZABLE
|
2018-02-12 18:49:10 +00:00
|
|
|
if options.Maximized {
|
|
|
|
flags |= C.ALLEGRO_MAXIMIZED
|
|
|
|
}
|
2017-10-03 18:38:09 +00:00
|
|
|
}
|
|
|
|
C.al_set_new_display_flags(flags)
|
2018-02-12 18:54:33 +00:00
|
|
|
d := C.al_create_display(C.int(width), C.int(height))
|
2017-10-03 18:38:09 +00:00
|
|
|
if nil == d {
|
2018-02-13 19:59:55 +00:00
|
|
|
return nil, errors.New("error creating display")
|
2017-10-03 18:38:09 +00:00
|
|
|
}
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
|
2018-02-13 19:59:55 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2018-06-04 19:15:53 +00:00
|
|
|
func (d *Display) Resize(w, h int) {
|
|
|
|
C.al_resize_display(d.display, C.int(w), C.int(h))
|
|
|
|
}
|
|
|
|
|
2018-02-13 19:59:55 +00:00
|
|
|
func (d *Display) SetAsTarget() {
|
|
|
|
C.al_set_target_backbuffer(d.display)
|
|
|
|
}
|
|
|
|
|
2018-09-09 16:24:33 +00:00
|
|
|
func (d *Display) SetIcon(i *Bitmap) {
|
|
|
|
C.al_set_display_icon(d.display, i.bitmap)
|
|
|
|
}
|
|
|
|
|
2018-06-04 19:15:53 +00:00
|
|
|
func (d *Display) SetMousePosition(x, y int) {
|
|
|
|
C.al_set_mouse_xy(d.display, C.int(x), C.int(y))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Display) SetPosition(x, y int) {
|
|
|
|
C.al_set_window_position(d.display, C.int(x), C.int(y))
|
|
|
|
}
|
|
|
|
|
2017-10-03 18:38:09 +00:00
|
|
|
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)
|
|
|
|
}
|