From 1eb8cf4ca2e49575ce93412ca535becea1fb8f11 Mon Sep 17 00:00:00 2001 From: Matthew Campbell Date: Thu, 4 May 2017 01:50:57 +0900 Subject: [PATCH] Add fullscreen support, cmdline and toggle --- README.md | 4 +++- main.go | 25 +++++++++++++++++++++---- ui/director.go | 2 +- ui/gameview.go | 19 ++++++++++++++++++- ui/menuview.go | 2 +- ui/run.go | 16 +++++++++++++--- ui/util.go | 2 +- 7 files changed, 58 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 62a6bdc..f9c0536 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ http://www.michaelfogleman.com/static/nes/ ### Dependencies github.com/go-gl/gl/v2.1/gl - github.com/go-gl/glfw/v3.1/glfw + github.com/go-gl/glfw/v3.2/glfw github.com/gordonklaus/portaudio The portaudio-go dependency requires PortAudio on your system: @@ -68,6 +68,8 @@ Keyboard controls are indicated below. | B (Turbo) | S | | Reset | R | +Full Screen Mode - CRTL + F + ### Mappers The following mappers have been implemented: diff --git a/main.go b/main.go index 81dcd80..8a7132a 100644 --- a/main.go +++ b/main.go @@ -6,22 +6,39 @@ import ( "os" "path" "strings" + "fmt" "github.com/fogleman/nes/ui" ) func main() { log.SetFlags(0) - paths := getPaths() + args, fullscreen := extractFlags() + paths := getPaths(args) if len(paths) == 0 { log.Fatalln("no rom files specified or found") } - ui.Run(paths) + ui.Run(paths, fullscreen) } -func getPaths() []string { +func extractFlags() ([]string, bool) { + args := os.Args + + for i, x := range args { + //Probably should add a keyboard shortcut for this also + if x == "--fullscreen" { + a := append(args[:i], args[i+1:]...) + fmt.Printf("fullscreen - args - %v -- a %b", args, a) + return a, true + } + } + + return args, false +} + +func getPaths(argsv []string ) []string { var arg string - args := os.Args[1:] + args := argsv[1:] if len(args) == 1 { arg = args[0] } else { diff --git a/ui/director.go b/ui/director.go index eb4d730..2cf45cf 100644 --- a/ui/director.go +++ b/ui/director.go @@ -5,7 +5,7 @@ import ( "github.com/fogleman/nes/nes" "github.com/go-gl/gl/v2.1/gl" - "github.com/go-gl/glfw/v3.1/glfw" + "github.com/go-gl/glfw/v3.2/glfw" ) type View interface { diff --git a/ui/gameview.go b/ui/gameview.go index 7d17575..b7a87f9 100644 --- a/ui/gameview.go +++ b/ui/gameview.go @@ -5,7 +5,7 @@ import ( "github.com/fogleman/nes/nes" "github.com/go-gl/gl/v2.1/gl" - "github.com/go-gl/glfw/v3.1/glfw" + "github.com/go-gl/glfw/v3.2/glfw" ) const padding = 0 @@ -93,6 +93,10 @@ func (view *GameView) onKey(window *glfw.Window, screenshot(view.console.Buffer()) case glfw.KeyR: view.console.Reset() + case glfw.KeyF: + if mods == glfw.ModControl { + view.ToggleFullScreen(window) + } case glfw.KeyTab: if view.record { view.record = false @@ -105,6 +109,19 @@ func (view *GameView) onKey(window *glfw.Window, } } +func (view *GameView) ToggleFullScreen(window *glfw.Window) { + if window.GetMonitor() == nil { + monitor := glfw.GetPrimaryMonitor() + vid := monitor.GetVideoMode() + window.SetMonitor(monitor, 0, 0, vid.Width, vid.Height, 60) + } else { + //This actually requires glfw 3.3 to work perfectly on osx + //otherwise the window is not the right size + window.SetMonitor(nil, 0, 0, width*scale, height*scale, 0) + } +} + + func drawBuffer(window *glfw.Window) { w, h := window.GetFramebufferSize() s1 := float32(w) / 256 diff --git a/ui/menuview.go b/ui/menuview.go index 9099662..9df8869 100644 --- a/ui/menuview.go +++ b/ui/menuview.go @@ -6,7 +6,7 @@ import ( "github.com/fogleman/nes/nes" "github.com/go-gl/gl/v2.1/gl" - "github.com/go-gl/glfw/v3.1/glfw" + "github.com/go-gl/glfw/v3.2/glfw" ) const ( diff --git a/ui/run.go b/ui/run.go index 45cb424..fd8987f 100644 --- a/ui/run.go +++ b/ui/run.go @@ -5,7 +5,7 @@ import ( "runtime" "github.com/go-gl/gl/v2.1/gl" - "github.com/go-gl/glfw/v3.1/glfw" + "github.com/go-gl/glfw/v3.2/glfw" "github.com/gordonklaus/portaudio" ) @@ -24,7 +24,7 @@ func init() { runtime.LockOSThread() } -func Run(paths []string) { +func Run(paths []string, fullscreen bool) { // initialize audio portaudio.Initialize() defer portaudio.Terminate() @@ -44,10 +44,20 @@ func Run(paths []string) { // create window glfw.WindowHint(glfw.ContextVersionMajor, 2) glfw.WindowHint(glfw.ContextVersionMinor, 1) - window, err := glfw.CreateWindow(width*scale, height*scale, title, nil, nil) + + var err error + var window *glfw.Window + if fullscreen == false { + window, err = glfw.CreateWindow(width*scale, height*scale, title, nil, nil) + } else { + monitor := glfw.GetPrimaryMonitor() + vid := monitor.GetVideoMode() + window, err = glfw.CreateWindow(vid.Width, vid.Height, title, monitor, nil) + } if err != nil { log.Fatalln(err) } + window.MakeContextCurrent() // initialize gl diff --git a/ui/util.go b/ui/util.go index 4423c4e..9d87e48 100644 --- a/ui/util.go +++ b/ui/util.go @@ -17,7 +17,7 @@ import ( "github.com/fogleman/nes/nes" "github.com/go-gl/gl/v2.1/gl" - "github.com/go-gl/glfw/v3.1/glfw" + "github.com/go-gl/glfw/v3.2/glfw" ) var homeDir string