Browse Source

Add support for retina mouse cursors on OS X

tags/2021-05-28
hogliux 9 years ago
parent
commit
6d56e488dc
2 changed files with 11 additions and 12 deletions
  1. +10
    -11
      modules/juce_gui_basics/native/juce_mac_MouseCursor.mm
  2. +1
    -1
      modules/juce_gui_extra/native/juce_mac_SystemTrayIcon.cpp

+ 10
- 11
modules/juce_gui_basics/native/juce_mac_MouseCursor.mm View File

@@ -27,25 +27,24 @@
//==============================================================================
namespace MouseCursorHelpers
{
NSImage* createNSImage (const Image&);
NSImage* createNSImage (const Image& image)
NSImage* createNSImage (const Image&, float scaleFactor = 1.f);
NSImage* createNSImage (const Image& image, float scaleFactor)
{
JUCE_AUTORELEASEPOOL
{
NSImage* im = [[NSImage alloc] init];
[im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
[im lockFocus];
const NSSize requiredSize = NSMakeSize (image.getWidth() / scaleFactor, image.getHeight() / scaleFactor);
[im setSize: requiredSize];
CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
CGImageRef imageRef = juce_createCoreGraphicsImage (image, colourSpace, false);
CGImageRef imageRef = juce_createCoreGraphicsImage (image, colourSpace, true);
CGColorSpaceRelease (colourSpace);
CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
CGContextDrawImage (cg, convertToCGRect (image.getBounds()), imageRef);
NSBitmapImageRep* imageRep = [[NSBitmapImageRep alloc] initWithCGImage: imageRef];
[imageRep setSize: requiredSize];
[im addRepresentation: imageRep];
[imageRep release];
CGImageRelease (imageRef);
[im unlockFocus];
return im;
}
}
@@ -104,7 +103,7 @@ namespace MouseCursorHelpers
void* CustomMouseCursorInfo::create() const
{
return MouseCursorHelpers::fromNSImage (MouseCursorHelpers::createNSImage (image),
return MouseCursorHelpers::fromNSImage (MouseCursorHelpers::createNSImage (image, scaleFactor),
NSMakePoint (hotspot.x, hotspot.y));
}


+ 1
- 1
modules/juce_gui_extra/native/juce_mac_SystemTrayIcon.cpp View File

@@ -24,7 +24,7 @@
namespace MouseCursorHelpers
{
extern NSImage* createNSImage (const Image&);
extern NSImage* createNSImage (const Image&, float scaleFactor = 1.f);
}
extern NSMenu* createNSMenu (const PopupMenu&, const String& name, int topLevelMenuId,


Loading…
Cancel
Save