views:

167

answers:

1

I have a class called ModelView which inherits from NSOpenGLView. When my program runs i attach the ModelView as follows to the main window.

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application 
    ModelView *glView; 
    NSRect glViewRect = CGRectMake(0.0f, 0.0f, window.frame.size.width, window.frame.size.height);
    glView = [[ModelView alloc] initWithFrame: glViewRect];
    [[window contentView] addSubview:glView];           
}

In my ModelView class i have a reshape function which is firing every time the window resizes

- (void)reshape
{
    [super setNeedsDisplay:YES];
    [[self openGLContext] update];  
    NSLog(@"reshap function called");
}

I want to get the main window width so i can resize the ModelView but i cant find how to get the window width from the ModelView class

I am reasonably new to cocoa/objective-c so any help is appreciated

+1  A: 

every view has a window property, so [self window] will get the window, and [[[self window] contentView] bounds].size.width will give the width, although you can directly get to the contentView by using [[self superview] bounds].size.width

cobbal
Thanks however the [[self parentView] bounds].size.width gives me a warning ModelView may not respond to '-parentView', and the [[[self window] contentView] bounds].size.width is returning 0 . What am i doing wrong ??
ADAM
@ADAM ah, forgot that it's superview, edited.
cobbal