An update will be applied January 25th, between 12PM and 1:00PM EST (UTC -5:00). The site may be slow during that time.

Commit 86c8a394 authored by Sean McBride's avatar Sean McBride
Browse files

Implement viewWillMoveToWindow: and viewDidChangeBackingProperties for Retina

In them, call SetDPI on the vtkRenderWindow to scale things so that vtkTextActors have the correct apparent size, per the display's scaling factor.

Updated both OpenGL2 and old OpenGL versions of the class.
parent 3431344f
......@@ -158,7 +158,7 @@ public:
/**
* Attempt to detect and set the DPI of the display device by querying the
* system. Note that this is not supported on all backends, and this method
* system. Note that this is not supported on most backends, and this method
* will return false if the DPI could not be detected. Use GetDPI() to
* inspect the detected value.
*/
......
......@@ -34,6 +34,9 @@
* but starting with VTK 5.0 is now a subclass of NSView.
* - starting with VTK 6.3 this class overrides the more modern
* updateTrackingAreas instead of resetCursorRects.
* - starting with VTK 8.1 this class properly supports Retina
* displays and implements viewWillMoveToWindow: and
* viewDidChangeBackingProperties to do so.
*
* @sa
* vtkCocoaRenderWindow vtkCocoaRenderWindowInteractor
......
......@@ -509,4 +509,43 @@ static const char *vtkMacKeyCodeToKeySymTable[128] = {
cocoaEvent:theEvent];
}
//----------------------------------------------------------------------------
// Private
- (void)modifyDPIForBackingScaleFactorOfWindow:(/*nullable*/ NSWindow *)window
{
if (window)
{
CGFloat backingScaleFactor = [window backingScaleFactor];
assert(backingScaleFactor >= 1.0);
vtkCocoaRenderWindow *renderWindow = [self getVTKRenderWindow];
if (renderWindow)
{
// Ordinarily, DPI is hardcoded to 72, but in order for vtkTextActors
// to have the correct apparent size, we adjust it per the NSWindow's
// scaling factor.
renderWindow->SetDPI(lround(72.0 * backingScaleFactor));
}
}
}
//----------------------------------------------------------------------------
// Overridden (from NSView).
- (void)viewWillMoveToWindow:(/*nullable*/ NSWindow*)inNewWindow
{
[super viewWillMoveToWindow:inNewWindow];
[self modifyDPIForBackingScaleFactorOfWindow:inNewWindow];
}
//----------------------------------------------------------------------------
// Overridden (from NSView).
- (void)viewDidChangeBackingProperties
{
[super viewDidChangeBackingProperties];
NSWindow *window = [self window];
[self modifyDPIForBackingScaleFactorOfWindow:window];
}
@end
......@@ -34,6 +34,9 @@
* but starting with VTK 5.0 is now a subclass of NSView.
* - starting with VTK 6.3 this class overrides the more modern
* updateTrackingAreas instead of resetCursorRects.
* - starting with VTK 8.1 this class properly supports Retina
* displays and implements viewWillMoveToWindow: and
* viewDidChangeBackingProperties to do so.
*
* @sa
* vtkCocoaRenderWindow vtkCocoaRenderWindowInteractor
......
......@@ -509,4 +509,43 @@ static const char *vtkMacKeyCodeToKeySymTable[128] = {
cocoaEvent:theEvent];
}
//----------------------------------------------------------------------------
// Private
- (void)modifyDPIForBackingScaleFactorOfWindow:(/*nullable*/ NSWindow *)window
{
if (window)
{
CGFloat backingScaleFactor = [window backingScaleFactor];
assert(backingScaleFactor >= 1.0);
vtkCocoaRenderWindow *renderWindow = [self getVTKRenderWindow];
if (renderWindow)
{
// Ordinarily, DPI is hardcoded to 72, but in order for vtkTextActors
// to have the correct apparent size, we adjust it per the NSWindow's
// scaling factor.
renderWindow->SetDPI(lround(72.0 * backingScaleFactor));
}
}
}
//----------------------------------------------------------------------------
// Overridden (from NSView).
- (void)viewWillMoveToWindow:(/*nullable*/ NSWindow*)inNewWindow
{
[super viewWillMoveToWindow:inNewWindow];
[self modifyDPIForBackingScaleFactorOfWindow:inNewWindow];
}
//----------------------------------------------------------------------------
// Overridden (from NSView).
- (void)viewDidChangeBackingProperties
{
[super viewDidChangeBackingProperties];
NSWindow *window = [self window];
[self modifyDPIForBackingScaleFactorOfWindow:window];
}
@end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment