NSCursor:使用带光标缩放的高分辨率光标(或视网膜) [英] NSCursor: Using high-resolution cursors with cursor zoom (or retina)

查看:1173
本文介绍了NSCursor:使用带光标缩放的高分辨率光标(或视网膜)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OSX中,用户可以使用辅助功能系统首选项缩放鼠标光标。因为Lion(我认为)OSX将光标存储为PDF,并能够顺利调整它们的大小。我想要我的应用程序相同的功能,但使用PDF作为 NSImage 用于我的 NSCursor 只是放大渲染的位图



如何:




  • 为我的游标使用矢量图稿,并让它们像系统光标一样正确缩放?

  • 检测当前光标缩放级别。



  • 此外,当在我的屏幕上使用HiDPI模式并恢复光标变焦设置时,PDF光标

    解决方案

    我刚刚得到了解决方案告诉我的@kongtomorrow。以下是他寄给我的程式码片段:

      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 setsSize:[theImage size]];
    [resultImage addRepresentation:rep];
    }

    NSCursor * theCursor = [[NSCursor alloc] initWithImage:resultImage hotSpot:NSMakePoint(12,8)];
    [self.scrollView setDocumentCursor:theCursor];

    这样做基本上是在图像中的适当比例因子处生成几个图像表示,基于原始PDF。这对我工作,我的光标是好的和平滑。


    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 want the same functionality for my app but using PDFs as the NSImage used for my NSCursor just scales up the rendered bitmap when a cursor zoom level larger than 1.0 is set.

    How do I:

    • Use vector artwork for my cursors and have them scale correctly like the system cursors do?
    • Detect the current cursor zoom level.
    • Get notified when the cursor zoom level changes?

    Also, when using a HiDPI mode for my screen and revert the cursor zoom setting, the PDF cursor is blurred as well so how exactly do you guys retina-ify your cursors?

    解决方案

    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.

    这篇关于NSCursor:使用带光标缩放的高分辨率光标(或视网膜)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆