cocoa - NSOpenGLView toggle to fullscreen from within the view -


i'm trying create method toggle between fullscreen , window. i'm trying within class inherited nsopenglview, essentially following this blogpost. works once, going windowed fullscreen; trying go fails in various ways: window screen doesn't updated, or don't manage switch window fullscreen blanks out. trying go , forth few times anyway (mapped 'f' key), program locks up, , in worst case, have restart computer. i've attached code method below; debugging purposes, i've set full frame rectangle smaller, if things freeze, application never @ full screen.

the fullscreen example in apple developer examples suggest using controller, , not go fullscreen within inherited nsopenglview.

my questions:

  • should use controller instead, , there switch between windowed , fullscreen (creating separate fullscreen view each time)? or should both methods work?
  • if both methods should work, 1 preferred?
  • if both methods can work, doing wrong in current way of implementing this?
  • or, there third, better, method?

note both references, i'll have assume things haven't changed 10.8 (both references seem apply 10.6).

code follows:

@implementation myopenglview  [...]  - (void)togglefullscreen {     mainwindow = [self window];      if (isfullscreen) {         [fullscreenwindow close];         [mainwindow setacceptsmousemovedevents:yes];         [mainwindow setcontentview: self];         [mainwindow makekeyandorderfront: self];         [mainwindow makefirstresponder: self];         isfullscreen = false;     } else {         [mainwindow setacceptsmousemovedevents:no];         //nsrect fullscreenframe = [[nsscreen mainscreen] frame];         nsrect fullscreenframe = { {300, 300}, {300, 300} };         fullscreenwindow = [[nswindow alloc] initwithcontentrect:fullscreenframe                                                        stylemask:nsborderlesswindowmask                                                          backing:nsbackingstorebuffered                                                            defer:no];         if (fullscreenwindow) {             [fullscreenwindow setacceptsmousemovedevents:yes];             [fullscreenwindow settitle:@"full screen"];             [fullscreenwindow setreleasedwhenclosed: yes];             [fullscreenwindow setcontentview: self];             [fullscreenwindow makekeyandorderfront: self];             //[fullscreenwindow setopaque:yes];             //[fullscreenwindow sethidesondeactivate:yes];             // set window level above menu bar             //[fullscreenwindow setlevel:nsmainmenuwindowlevel+1];             // set window level below screen saver             [fullscreenwindow setlevel:nsscreensaverwindowlevel-1];             [fullscreenwindow makefirstresponder:self];              isfullscreen = true;         } else {             nslog(@"error: not switch full screen.");         }    } }  [...]  @end 

i think can't done, , should not done. when windowed, rendering context window, different beast screen, when rendering fullscreen. thus, when switching between, things have re-setup everytime switch.

it possible use native fullscreen option in newest os x variants. (presumably) enlarge containg window full screen size while removing frame, borders , buttons. thus, you're still rendering window, though looks fullscreen.

i'm not sure if option makes things slower: there's window layer in between, make slower rendering directly screen.

for curious, implementing native fullscreen ridiculously easy (at least in 10.8 , 10.9): in xcode, select .xib file, select (main) window in editor's sidebar, select attributes selector on right. can find "full screen" selection between unsupported, primary window or auxiliary window. automatically add full screen toggle window. neater, select main menu -> view menu in sidebar, find "full screen menu item" in inspector @ bottom (there's search bar it), drag view menu in editor, , voilĂ , have shortcut , automatically connect full screen option window (select new view menu item , @ connections inspector it's connected you).

a nice way test grab full screen example linked in question, , edit suggested above. using default control-command f shortcut toggle , forth between fullscreen show opengl view and frame text below in full screen. using fullscreen option coded in example toggle openglview use fullscreen, without (cocoa) frames, buttons or text.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -