From e8ff8c35fe8ef58805423ae5dbbb22d316785c77 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Mon, 12 Feb 2018 19:49:10 +0100 Subject: [PATCH] Added Maximized flag to new display options. Added display resize & orientation event. --- allegro5/display.go | 4 ++++ allegro5/event.go | 50 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/allegro5/display.go b/allegro5/display.go index 3f73ff2..cd2c5cb 100644 --- a/allegro5/display.go +++ b/allegro5/display.go @@ -19,6 +19,7 @@ type NewDisplayOptions struct { Fullscreen bool Resizable bool Windowed bool + Maximized bool } // NewDisplay creates a display @@ -33,6 +34,9 @@ func NewDisplay(options NewDisplayOptions) (*Display, error) { } if options.Resizable { flags |= C.ALLEGRO_RESIZABLE + if options.Maximized { + flags |= C.ALLEGRO_MAXIMIZED + } } C.al_set_new_display_flags(flags) d := C.al_create_display(C.int(options.Width), C.int(options.Height)) diff --git a/allegro5/event.go b/allegro5/event.go index 8aaf11f..8501c13 100644 --- a/allegro5/event.go +++ b/allegro5/event.go @@ -28,6 +28,48 @@ type DisplayCloseEvent struct { EventBase } +type DisplayResizeEvent struct { + EventBase + X, Y int + Width int + Height int +} + +type DisplayOrientation int + +const ( + DisplayOrientation0Degrees DisplayOrientation = iota + DisplayOrientation90Degrees + DisplayOrientation180Degrees + DisplayOrientation270Degrees + DisplayOrientationFaceUp + DisplayOrientationFaceDown +) + +func toDisplayOrientation(o C.int) DisplayOrientation { + switch o { + case C.ALLEGRO_DISPLAY_ORIENTATION_0_DEGREES: + return DisplayOrientation0Degrees + case C.ALLEGRO_DISPLAY_ORIENTATION_90_DEGREES: + return DisplayOrientation90Degrees + case C.ALLEGRO_DISPLAY_ORIENTATION_180_DEGREES: + return DisplayOrientation180Degrees + case C.ALLEGRO_DISPLAY_ORIENTATION_270_DEGREES: + return DisplayOrientation270Degrees + case C.ALLEGRO_DISPLAY_ORIENTATION_FACE_UP: + return DisplayOrientationFaceUp + case C.ALLEGRO_DISPLAY_ORIENTATION_FACE_DOWN: + return DisplayOrientationFaceDown + default: + panic("not supported") + } +} + +type DisplayOrientationEvent struct { + EventBase + Orientation DisplayOrientation +} + type KeyEvent struct { EventBase KeyCode int @@ -104,7 +146,13 @@ func (eq *EventQueue) mapEvent(e *C.ALLEGRO_EVENT) Event { eb := EventBase{float64(any.timestamp)} switch any._type { case C.ALLEGRO_EVENT_DISPLAY_CLOSE: - return &DisplayCloseEvent{EventBase{float64(any.timestamp)}} + return &DisplayCloseEvent{eb} + case C.ALLEGRO_EVENT_DISPLAY_ORIENTATION: + display := (*C.ALLEGRO_DISPLAY_EVENT)(unsafe.Pointer(e)) + return &DisplayOrientationEvent{eb, toDisplayOrientation(display.orientation)} + case C.ALLEGRO_EVENT_DISPLAY_RESIZE: + display := (*C.ALLEGRO_DISPLAY_EVENT)(unsafe.Pointer(e)) + 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)) return &MouseMoveEvent{MouseEvent{eb, int(mouse.x), int(mouse.y), int(mouse.z), int(mouse.w), nil}, int(mouse.dx), int(mouse.dy), int(mouse.dz), int(mouse.dw), float32(mouse.pressure)}