NSCursor: Using high-resolution cursors with cursor zoom (or retina)

前端 未结 1 1093
盖世英雄少女心
盖世英雄少女心 2021-02-07 05:33

In OSX the user can zoom the mouse cursor using the accessibility system preferences. Since Lion (I think) OSX stores the cursors as PDFs and is able to resize them smoothly. I

1条回答
  •  死守一世寂寞
    2021-02-07 05:56

    I just got the solution told to me by @kongtomorrow. Here's the snippet he sent me:

    NSImage *   theImage = [NSImage imageNamed: @"CURS_128.pdf"];
    
    NSImage *resultImage = [[NSImage alloc] initWithSize:[theImage size]];
    
    for (int scale = 1; scale <= 4; scale++) {
        NSAffineTransform *xform = [[NSAffineTransform alloc] init];
        [xform scaleBy:scale];
        id hints = @{ NSImageHintCTM: xform };
        CGImageRef rasterCGImage = [theImage CGImageForProposedRect:NULL context:nil hints:hints];
        NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithCGImage:rasterCGImage];
        [rep setSize:[theImage size]];
        [resultImage addRepresentation:rep];
    }
    
    NSCursor*   theCursor = [[NSCursor alloc] initWithImage: resultImage hotSpot: NSMakePoint(12,8)];
    [self.scrollView setDocumentCursor: theCursor];
    

    So essentially what this does is generate several image representations at the appropriate scale factors in the image, based on the original PDF. This works for me, my cursor is nice and smooth.

    0 讨论(0)
提交回复
热议问题