Question

I have zoom method for my NSOpenGLView. If image is zoomed in, NSOpenGLView frame size, view port and etc. is being increased. Same thing is happening if NSOpenGLView is being zoomed out (the frame size, view port and etc. is being decreased). So I need that if image is zoomed in so that, NSOpenGLView is bigger than my window, scrollbar should appear. So I thought that putting NSOpenGLView to NSScrollView would be my solution. But it doesn't. It doesn't works. How then I could do it?

Was it helpful?

Solution

When you placed NSOpenGLView into NSScrollView in Interface Builder, you must redefine methods of your custom view:

  • - (void)awakeFromNib - here are OpenGL and other initialisations.
  • - (void)drawRect: (NSRect) dirtyRect - here is rendering.
  • - (void)setFrame:(NSRect)frame - here is reaction on changing of frame's size.

As viewport use visibleRect's size:

glViewport(0,
           0,
           self.visibleRect.size.width,
           self.visibleRect.size.height);

If your view is blinking, redefine method resizeWithOldSuperviewSize too:

- (void)resizeWithOldSuperviewSize:(NSSize)oldSize {
};

But it's hack and it would be better to do custom realisation of Clip view, if it's used.

If you want zoom your OpenGL view, just change its frame size.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top