Resize NSOpenGLView when resizing a window

I have a class called ModelView that inherits from NSOpenGLView. When my program starts, 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 that runs every time the window is resized

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

I want to get the width of the main window, so I can resize the ModelView, but I cannot find how to get the width of the window from the ModelView class

I'm new to cocoa / objective-c, so any help is appreciated

+3
source share
1 answer

window, [self window] , [[[self window] contentView] bounds].size.width , contentView [[self superview] bounds].size.width

+1

Source: https://habr.com/ru/post/1736828/


All Articles