Added Maximized flag to new display options.

Added display resize & orientation event.
This commit is contained in:
Sander Schobers 2018-02-12 19:49:10 +01:00
parent ab5572018d
commit e8ff8c35fe
2 changed files with 53 additions and 1 deletions

View File

@ -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))

View File

@ -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)}