From dbcd09094f247792ddec9ae17d8886ecff9e5d02 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Mon, 4 Jun 2018 21:15:53 +0200 Subject: [PATCH] Added display & monitor functions --- allegro5/display.go | 17 +++++++++++++++-- allegro5/monitor.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 allegro5/monitor.go diff --git a/allegro5/display.go b/allegro5/display.go index 3bcfb58..8c92f21 100644 --- a/allegro5/display.go +++ b/allegro5/display.go @@ -14,12 +14,11 @@ type Display struct { } type NewDisplayOptions struct { - Width int - Height int Fullscreen bool Resizable bool Windowed bool Maximized bool + Frameless bool } // NewDisplay creates a display @@ -31,6 +30,8 @@ func NewDisplay(width, height int, options NewDisplayOptions) (*Display, error) } else { flags = C.ALLEGRO_FULLSCREEN } + } else if options.Frameless { + flags |= C.ALLEGRO_FRAMELESS } if options.Resizable { flags |= C.ALLEGRO_RESIZABLE @@ -65,10 +66,22 @@ func (d *Display) Position() (int, int) { return int(x), int(y) } +func (d *Display) Resize(w, h int) { + C.al_resize_display(d.display, C.int(w), C.int(h)) +} + func (d *Display) SetAsTarget() { C.al_set_target_backbuffer(d.display) } +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)) +} + func (d *Display) SetWindowTitle(title string) { t := C.CString(title) defer C.free(unsafe.Pointer(t)) diff --git a/allegro5/monitor.go b/allegro5/monitor.go new file mode 100644 index 0000000..be681de --- /dev/null +++ b/allegro5/monitor.go @@ -0,0 +1,34 @@ +package allegro5 + +// #include +import "C" + +type Monitor struct { + X1, Y1 int + X2, Y2 int +} + +func monitor(m *C.ALLEGRO_MONITOR_INFO) Monitor { + return Monitor{int(m.x1), int(m.y1), int(m.x2), int(m.y2)} +} + +func DefaultMonitor() Monitor { + var m C.ALLEGRO_MONITOR_INFO + C.al_get_monitor_info(C.ALLEGRO_DEFAULT_DISPLAY_ADAPTER, &m) + return monitor(&m) +} + +func Monitors() []Monitor { + var n = NumberOfVideoAdapters() + var mons []Monitor + var m C.ALLEGRO_MONITOR_INFO + for i := 0; i < n; i++ { + C.al_get_monitor_info(C.int(i), &m) + mons = append(mons, monitor(&m)) + } + return mons +} + +func NumberOfVideoAdapters() int { + return int(C.al_get_num_video_adapters()) +}