From dc5d91b238e9260b2e61224fc8b8cabbb3440323 Mon Sep 17 00:00:00 2001 From: 8o7wer <8o7wermobile@gmail.com> Date: Fri, 10 May 2019 17:50:15 -0800 Subject: Added the ability to get width, height, and refresh rate from the monitor through win.GetPrimaryMonitor(). Added the borderless and maximized options. --- win/monitor.go | 42 ++++++++++++++++++++++++++++++++++++++++++ win/win.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 win/monitor.go 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 +} diff --git a/win/win.go b/win/win.go index f624f35..519db84 100644 --- a/win/win.go +++ b/win/win.go @@ -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 } -- cgit v1.2.3 From f8fde9e8d0b8270f082b778b44627a03dd59c57c Mon Sep 17 00:00:00 2001 From: 8o7wer <8o7wermobile@gmail.com> Date: Fri, 10 May 2019 17:56:35 -0800 Subject: Revert "Added the ability to get width, height, and refresh rate from the monitor through win.GetPrimaryMonitor()." This reverts commit dc5d91b238e9260b2e61224fc8b8cabbb3440323. --- win/monitor.go | 42 ------------------------------------------ win/win.go | 30 ------------------------------ 2 files changed, 72 deletions(-) delete mode 100644 win/monitor.go diff --git a/win/monitor.go b/win/monitor.go deleted file mode 100644 index 931484a..0000000 --- a/win/monitor.go +++ /dev/null @@ -1,42 +0,0 @@ -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 -} diff --git a/win/win.go b/win/win.go index 519db84..f624f35 100644 --- a/win/win.go +++ b/win/win.go @@ -20,8 +20,6 @@ type options struct { title string width, height int resizable bool - borderless bool - maximized bool } // Title option sets the title (caption) of the window. @@ -46,20 +44,6 @@ 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. @@ -69,8 +53,6 @@ func New(opts ...Option) (*Win, error) { width: 640, height: 480, resizable: false, - borderless: false, - maximized: false, } for _, opt := range opts { opt(&o) @@ -98,9 +80,6 @@ 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 @@ -136,16 +115,7 @@ 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 } -- cgit v1.2.3 From 4d2d435b65f660ff4acf99fc043f75c8d04db6ae Mon Sep 17 00:00:00 2001 From: 8o7wer <8o7wermobile@gmail.com> Date: Fri, 10 May 2019 20:50:07 -0800 Subject: Adds the ability to get monitor information through win.GetPrimaryMonitor() --- win/monitor.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 win/monitor.go 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 +} -- cgit v1.2.3 From 8b2b10d1d4a09fb436580c598379182ddf3d2c25 Mon Sep 17 00:00:00 2001 From: 8o7wer <8o7wermobile@gmail.com> Date: Fri, 10 May 2019 20:51:08 -0800 Subject: Fixing w.ratio going under zero and causing a divide by zero exception Adds Borderless and Maximized options --- win/win.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/win/win.go b/win/win.go index f624f35..519db84 100644 --- a/win/win.go +++ b/win/win.go @@ -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 } -- cgit v1.2.3 From 1393e8c733ccefb687d588d53627878147190b1c Mon Sep 17 00:00:00 2001 From: Id405 <8o7wermobile@gmail.com> Date: Fri, 10 May 2019 21:02:54 -0800 Subject: Delete monitor.go --- win/monitor.go | 42 ------------------------------------------ 1 file changed, 42 deletions(-) delete mode 100644 win/monitor.go diff --git a/win/monitor.go b/win/monitor.go deleted file mode 100644 index 931484a..0000000 --- a/win/monitor.go +++ /dev/null @@ -1,42 +0,0 @@ -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 -} -- cgit v1.2.3 From 750e8c7d3cd011f298c528c81efe63b1dd53ec90 Mon Sep 17 00:00:00 2001 From: Id405 <8o7wermobile@gmail.com> Date: Fri, 10 May 2019 21:04:47 -0800 Subject: Update win.go --- win/win.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/win/win.go b/win/win.go index 519db84..ef6c832 100644 --- a/win/win.go +++ b/win/win.go @@ -20,8 +20,8 @@ type options struct { title string width, height int resizable bool - borderless bool - maximized bool + borderless bool + maximized bool } // Title option sets the title (caption) of the window. -- cgit v1.2.3 From ee835029b4c84dfb868dc70b4e31003dec0033f2 Mon Sep 17 00:00:00 2001 From: Id405 <8o7wermobile@gmail.com> Date: Fri, 10 May 2019 21:05:39 -0800 Subject: Update win.go --- win/win.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/win/win.go b/win/win.go index ef6c832..3a06ea9 100644 --- a/win/win.go +++ b/win/win.go @@ -143,12 +143,12 @@ func makeGLFWWin(o *options) (*glfw.Window, error) { 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 } + 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 + } return w, nil } -- cgit v1.2.3 From 101b8b1005041de522252306465b534c37576403 Mon Sep 17 00:00:00 2001 From: 8o7wer <8o7wermobile@gmail.com> Date: Mon, 20 May 2019 20:41:00 -0800 Subject: fixed formatting --- win/win.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/win/win.go b/win/win.go index 3a06ea9..1741549 100644 --- a/win/win.go +++ b/win/win.go @@ -46,14 +46,14 @@ func Resizable() Option { } } -//Borderless option makes the window borderless +// Borderless option makes the window borderless. func Borderless() Option { return func(o *options) { o.borderless = true } } -//Maximized option makes the window start maximized +// Maximized option makes the window start maximized. func Maximized() Option { return func(o *options) { o.maximized = true @@ -65,12 +65,12 @@ func Maximized() Option { // The default title is empty and the default size is 640x480. func New(opts ...Option) (*Win, error) { o := options{ - title: "", - width: 640, - height: 480, - resizable: false, + title: "", + width: 640, + height: 480, + resizable: false, borderless: false, - maximized: false, + maximized: false, } for _, opt := range opts { opt(&o) -- cgit v1.2.3