From 2a1ab90ad58291bbbcfd5592033d060c69421d3f Mon Sep 17 00:00:00 2001 From: David Linus Briemann Date: Thu, 3 May 2018 20:52:42 +0200 Subject: [PATCH 1/2] adds a community example for the usage of video modes --- pixelgl/monitor.go | 24 ++++++++++++++++++++++++ pixelgl/window.go | 6 ++++++ 2 files changed, 30 insertions(+) diff --git a/pixelgl/monitor.go b/pixelgl/monitor.go index 7cf73a9..0d4a6d3 100644 --- a/pixelgl/monitor.go +++ b/pixelgl/monitor.go @@ -10,6 +10,15 @@ type Monitor struct { monitor *glfw.Monitor } +// VideoMode represents all properties of a video mode and is attached +// to a monitor if it is a fullscreen mode. +type VideoMode struct { + *glfw.VidMode + // Monitor is a pointer to the monitor that owns this video mode. + // If Monitor is nil the video mode is windowed. + Monitor *Monitor +} + // PrimaryMonitor returns the main monitor (usually the one with the taskbar and stuff). func PrimaryMonitor() *Monitor { var monitor *glfw.Monitor @@ -95,3 +104,18 @@ func (m *Monitor) RefreshRate() (rate float64) { rate = float64(mode.RefreshRate) return } + +// VideoModes returns all available video modes for the monitor. +func (m *Monitor) VideoModes() (vmodes []*VideoMode) { + var modes []*glfw.VidMode + mainthread.Call(func() { + modes = m.monitor.GetVideoModes() + }) + for _, mode := range modes { + vmodes = append(vmodes, &VideoMode{ + VidMode: mode, + Monitor: m, + }) + } + return +} diff --git a/pixelgl/window.go b/pixelgl/window.go index ddc5426..0668a9b 100644 --- a/pixelgl/window.go +++ b/pixelgl/window.go @@ -424,3 +424,9 @@ func (w *Window) Clear(c color.Color) { func (w *Window) Color(at pixel.Vec) pixel.RGBA { return w.canvas.Color(at) } + +// SetVideoMode applies the given video mode to this window. +func (w *Window) SetVideoMode(vm VideoMode) { + w.SetMonitor(vm.Monitor) + w.SetBounds(pixel.R(0, 0, float64(vm.Width), float64(vm.Height))) +} From 446247e369d51e7f6e2d8bd6271d0e5ed7f93cb3 Mon Sep 17 00:00:00 2001 From: David Linus Briemann Date: Fri, 4 May 2018 18:03:25 +0200 Subject: [PATCH 2/2] adjusts VideoMode and associated function to pull request change requests. --- pixelgl/monitor.go | 23 +++++++++++++---------- pixelgl/window.go | 6 ------ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/pixelgl/monitor.go b/pixelgl/monitor.go index 0d4a6d3..90ae7cc 100644 --- a/pixelgl/monitor.go +++ b/pixelgl/monitor.go @@ -10,13 +10,15 @@ type Monitor struct { monitor *glfw.Monitor } -// VideoMode represents all properties of a video mode and is attached -// to a monitor if it is a fullscreen mode. +// VideoMode represents all properties of a video mode and is +// associated with a monitor if it is used in fullscreen mode. type VideoMode struct { - *glfw.VidMode - // Monitor is a pointer to the monitor that owns this video mode. - // If Monitor is nil the video mode is windowed. - Monitor *Monitor + // Width is the width of the vide mode in pixels. + Width int + // Height is the height of the video mode in pixels. + Height int + // RefreshRate holds the refresh rate of the associated monitor in Hz. + RefreshRate int } // PrimaryMonitor returns the main monitor (usually the one with the taskbar and stuff). @@ -106,15 +108,16 @@ func (m *Monitor) RefreshRate() (rate float64) { } // VideoModes returns all available video modes for the monitor. -func (m *Monitor) VideoModes() (vmodes []*VideoMode) { +func (m *Monitor) VideoModes() (vmodes []VideoMode) { var modes []*glfw.VidMode mainthread.Call(func() { modes = m.monitor.GetVideoModes() }) for _, mode := range modes { - vmodes = append(vmodes, &VideoMode{ - VidMode: mode, - Monitor: m, + vmodes = append(vmodes, VideoMode{ + Width: mode.Width, + Height: mode.Height, + RefreshRate: mode.RefreshRate, }) } return diff --git a/pixelgl/window.go b/pixelgl/window.go index 0668a9b..ddc5426 100644 --- a/pixelgl/window.go +++ b/pixelgl/window.go @@ -424,9 +424,3 @@ func (w *Window) Clear(c color.Color) { func (w *Window) Color(at pixel.Vec) pixel.RGBA { return w.canvas.Color(at) } - -// SetVideoMode applies the given video mode to this window. -func (w *Window) SetVideoMode(vm VideoMode) { - w.SetMonitor(vm.Monitor) - w.SetBounds(pixel.R(0, 0, float64(vm.Width), float64(vm.Height))) -}