NSView fullscreen

Discussion in 'Mac Programming' started by hoschi, Nov 14, 2005.

  1. macrumors newbie

    Joined:
    Sep 20, 2005
    #1
    Hi:

    I have a program running which uses fullscreen mode also- that is I can go full screen as well. I have a custom view in this window (where I show some opengl stuff) and some buttons/controls..

    The problem is this..
    Once I go to the fullscreen and come back, my normal sized window cannot display the custom view but only displays the normal window with controls and without the custom view itself..

    I read somewhere that in order for any other views to be shown, they should be made subviews of the content view. I have no clue how to do that.

    Also if anyone thinks there is another way around this, it could be helpful...
    Below is the relevant part of the code...

    ---------

    -(IBAction)fullScreen:(id)sender
    {
    if (fullScreenMode)
    {
    [fullScreenWindow close];
    [startingWindow setAcceptsMouseMovedEvents:YES];
    // [startingWindow setContentView:];
    [startingWindow makeKeyAndOrderFront:nil];
    // [startingWindow makeFirstResponder:myGLView];
    fullScreenMode = NO;
    } else
    {
    unsigned int windowStyle;
    NSRect contentRect;
    startingWindow = [NSApp keyWindow];
    windowStyle = NSBorderlessWindowMask;
    contentRect = [[NSScreen mainScreen] frame];
    fullScreenWindow = [[NSWindow alloc] initWithContentRect:contentRect
    styleMask:windowStyle
    backing:NSBackingStoreBuffered
    defer:NO];
    [startingWindow setAcceptsMouseMovedEvents:NO];

    if(fullScreenWindow != nil)
    {
    [fullScreenWindow setTitle:mad:"GL Viewer"];
    [fullScreenWindow setReleasedWhenClosed:YES];
    [fullScreenWindow setAcceptsMouseMovedEvents:YES];
    [fullScreenWindow setContentView:myGLView];
    [fullScreenWindow makeKeyAndOrderFront:myGLView];
    [fullScreenWindow setLevel:NSScreenSaverWindowLevel -1];
    [fullScreenWindow makeFirstResponder:myGLView];
    fullScreenMode = YES;
    }
    }
    }
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    This is easy:
    Code:
    NSWindow *window = <code to get window>;
    NSView *view = <code to get view>;
    
    [[window contentView] addSubview:view];
    <set view frame etc>
    
    p.s. if you wrap you code in CODE tags it's a bit easier to read :)
     
  3. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #3
    Just use
    Code:
    [[myWindow contentView] addSubview:mySubview]
     
  4. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Beat you to it :p

    And it's addSubview: (I just checked to make sure)
     
  5. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #5
    Heh, I just changed that too!
     
  6. thread starter macrumors newbie

    Joined:
    Sep 20, 2005
    #6
    I added the line and added [[myWindow contentView] addSubview:myView]

    HoweverI am getting the same problem as before
     
  7. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #7
    Can you host the XCode project somewhere (as a zip or something). The code above is a bit difficult to understand on it's own...
     
  8. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #8
    Sorry, in the Mac world, when you see "my<Something>" if usually means "substitute the actual name of the object I'm using here". So in your case it sounds like it would be:
    Code:
    [[fullScreenWindow contentView] addSubview:myGLView];
    Whether that actually works to accomplish what you're going for, I don't know, I'm just going off what you said about adding subviews to a content view.

    EDIT: fixed typo...again! :p
     

Share This Page