在 Quartz 插件中查找左上角

发布于 2024-07-19 18:51:28 字数 327 浏览 5 评论 0原文

我有一个用于查看图像的 Mac 插件。 它最初是用 Quickdraw 编写的,我正在尝试将其移至 Quartz。

我目前的问题是起源。 在 QD 中,原点(显然)是插件矩形的左上角。 在 Quartz 中,它似乎是插件矩形顶部下方的一个屏幕高度(不包括 Firefox 按钮等)。 这实际上是我的插件矩形中间随机的某个地方。

这也意味着我需要知道浏览器窗口的绘图部分的大小。 我确信我可以算出窗口有多大,但是如何算出选项卡等占用了多少空间? Mac 不知道这些事情,不是吗?

相关说明,有谁知道为什么苹果决定将原点放在左下角? 对我来说似乎有点愚蠢。

I have a Mac Plugin for viewing images. It's originally written in Quickdraw, and I'm trying to move it to Quartz.

My current problem is the origin. In QD, the origin is (sensibly) the upper left corner of the plugin rectangle. In Quartz, it appears to be one screen height below the top of the plugin rectangle (not including firefox buttons, etc). This is effectively somewhere random in the middle of my plugin rectangle.

It also means that I need to know the size of the drawing part of the browser window. I'm sure I can figure out how big a window is, but how do I figure out how much space is taken up by tabs, etc? the Mac doesn't know about those things, does it?

On a related note, does anyone know why Apple decided to put the origin in the lower left? seems kind of dumb to me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心凉 2024-07-26 18:51:28

如果您使用 NSView,则可以创建返回 YES 的 -isFlipped 函数的实现,这将允许您基于翻转的坐标系进行绘制。

或者,如果您不使用 NSView 但正在进行原始 CoreGraphics 绘图,则可以像这样修改 CTM:

CGContextScaleCTM( context, 1.0, -1.0 );

这来自 此 Apple 问答文档

如果您使用 CGContextRef 执行此操作,则应先保存现有的 CTM,并在完成后恢复它:

CGContextSaveGState( context );

// do your stuff here ...

CGContextRestoreGState( context );

哦,原点位于左下角,因为 Quartz 渲染系统基于 PDF 图形系统,本身基于 PostScript,其起源位于左下角。

If you're using NSView, you can create an implementation of the -isFlipped function returning YES which will allow you to draw based on a flipped coordinate system.

Alternatively, if you're not using NSView but are doing raw CoreGraphics drawing, you can modify the CTM like so:

CGContextScaleCTM( context, 1.0, -1.0 );

This comes from this Apple Q&A document.

If you're doing this with a CGContextRef you've been given by something else, you should save the existing CTM first and restore it when you're done:

CGContextSaveGState( context );

// do your stuff here ...

CGContextRestoreGState( context );

Oh, and the origin is in the lower-left because the Quartz rendering system is based on the PDF graphics system, itself based on PostScript, and which has an origin in the lower-left.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文