вторник, 7 августа 2012 г.

Preparing applications for 10.8 (HiDPI)

All you need to make the developers, it is properly configured to work with the regime HiDPI.

If the application is actively using OpenGL.

When initializing the NS*View is bound to 3D-context, do check the retina.

  1. #if (defined(MAC_OS_X_VERSION_10_7)) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7  
  2.         if ( [ NSApplication usingLionOSX ] )  
  3.         {  
  4.           NSRect baseBounds = [ self bounds ];  
  5.           NSRect hdpiBounds = [ self convertRectToBacking : baseBounds ];  
  6.            
  7.           if (NO == NSEqualSizes(baseBounds.size, hdpiBounds.size))  
  8.           {            
  9.               [ self setWantsBestResolutionOpenGLSurface : YES ];  
  10.           }  
  11.         }  
  12. #endif  

If you change the size of the application recalculate dimensions.

  1. - (void) updateBounds  
  2. {  
  3.     NSRect  baseBounds  =   [ self bounds ];  
  4.       
  5. #if (defined(MAC_OS_X_VERSION_10_7)) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7  
  6.     if ( [ NSApplication usingLionOSX ] )  
  7.     {        
  8.         baseBounds      =   [ self convertRectToBacking : baseBounds ];  
  9.     }   
  10. #endif  
  11.   ....  
  12.    
  13.   glClearColor ( 0.0f, 0.0f, 0.0f, 1.0f );   
  14.   glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );   
  15.   glViewport (0.0f, 0.0f, baseBounds.size.width, baseBounds.size.height );  
  16.   ....  
  17.   
  18. }  

About the class NSImage.

All the work is not in pixels but in points. Released two QuartzCore used to work with all images or do a little fix-resize the output image.

  1. NSImageRep* rep = [[img representations] objectAtIndex:0];    // fix HDPI  
  2. if (rep)  
  3. {  
  4.        NSSize size = NSMakeSize ([rep pixelsWide], [rep pixelsHigh]);  
  5.        [img setSize : size];  
  6. }  


Resources and rewards.

All UI elements are presented in the form of bitmap images must be properly scaled up twice. XCode automatically to pick up, just add '* texture.name * @ 2x.tiff ' copy of your texture to the project. If you need to manually create bitmaps from the resource that is the method of [NSimage imageNamed: @ "* texture.name *"] correctly load the desired image.

Do not forget about the icon. This designer's work - painting the icons in the amount of 1024x1024px.