diff options
| author | 8o7wer <8o7wermobile@gmail.com> | 2019-05-10 17:50:15 -0800 |
|---|---|---|
| committer | 8o7wer <8o7wermobile@gmail.com> | 2019-05-10 17:50:15 -0800 |
| commit | dc5d91b238e9260b2e61224fc8b8cabbb3440323 (patch) | |
| tree | 8722d5a9f25b2eae465cf6cda0db86965e6d0e89 | |
| parent | 51a4ff230c3d19426e051a8317310f3fa0343386 (diff) | |
| download | gui-dc5d91b238e9260b2e61224fc8b8cabbb3440323.zip | |
Added the ability to get width, height, and refresh rate from the monitor through win.GetPrimaryMonitor().
Added the borderless and maximized options.
| -rw-r--r-- | win/monitor.go | 42 | ||||
| -rw-r--r-- | win/win.go | 30 |
2 files changed, 72 insertions, 0 deletions
diff --git a/win/monitor.go b/win/monitor.go new file mode 100644 index 0000000..931484a --- /dev/null +++ b/win/monitor.go @@ -0,0 +1,42 @@ +package win + +import ( + "github.com/faiface/mainthread" + "github.com/go-gl/glfw/v3.2/glfw" +) + + +// Holds information on a monitor +type Monitor struct { + Width, Height int + RefreshRate int +} + +// Returns a struct containing information about the primary monitor +func GetPrimaryMonitor() (Monitor, error) { + returns := mainthread.CallVal( func() interface{} { + err := glfw.Init() + if err != nil { + return err + } + + return glfw.GetPrimaryMonitor().GetVideoMode() + }) + + monitor := Monitor{0, 0, 0} + var err error = nil + + switch v := returns.(type) { + case *glfw.VidMode: + videoMode := v + + width := videoMode.Width + height := videoMode.Height + refreshRate := videoMode.RefreshRate + monitor = Monitor{width, height, refreshRate} + case error: + err = v + } + + return monitor, err +} @@ -20,6 +20,8 @@ type options struct { title string width, height int resizable bool + borderless bool + maximized bool } // Title option sets the title (caption) of the window. @@ -44,6 +46,20 @@ func Resizable() Option { } } +//Borderless option makes the window borderless +func Borderless() Option { + return func(o *options) { + o.borderless = true + } +} + +//Maximized option makes the window start maximized +func Maximized() Option { + return func(o *options) { + o.maximized = true + } +} + // New creates a new window with all the supplied options. // // The default title is empty and the default size is 640x480. @@ -53,6 +69,8 @@ func New(opts ...Option) (*Win, error) { width: 640, height: 480, resizable: false, + borderless: false, + maximized: false, } for _, opt := range opts { opt(&o) @@ -80,6 +98,9 @@ func New(opts ...Option) (*Win, error) { // hiDPI hack width, _ := w.w.GetFramebufferSize() w.ratio = width / o.width + if w.ratio < 1 { + w.ratio = 1 + } if w.ratio != 1 { o.width /= w.ratio o.height /= w.ratio @@ -115,7 +136,16 @@ func makeGLFWWin(o *options) (*glfw.Window, error) { } else { glfw.WindowHint(glfw.Resizable, glfw.False) } + if o.borderless { + glfw.WindowHint(glfw.Decorated, glfw.False) + } + if o.maximized { + glfw.WindowHint(glfw.Maximized, glfw.True) + } w, err := glfw.CreateWindow(o.width, o.height, o.title, nil, nil) + if o.maximized { + o.width, o.height = w.GetFramebufferSize() // set o.width and o.height to the window size due to the window being maximized + } if err != nil { return nil, err } |