将给定点从窗口基坐标系转换为屏幕坐标系
我试图找出将给定点从窗口的基础坐标系转换为屏幕坐标系的方法。我的意思是类似 - (NSPoint)convertBaseToScreen:(NSPoint)point.
但我想要它来自石英/碳。
我有 CGContextRef 及其边界。但边界是相对于 CGContextRef 所属的 Window 而言的。例如,如果窗口相对于屏幕位于 (100, 100, 50, 50) 位置,则窗口的 contextRef 将是 (0,0, 50, 50)。即我位于位置 (0,0),但实际上在屏幕上我位于 (100,100)。我
任何建议表示赞赏。
谢谢。
I am trying to figure out the way to convert a given point from the window’s base coordinate system to the screen coordinate system. I mean something like - (NSPoint)convertBaseToScreen:(NSPoint)point.
But I want it from quartz/carbon.
I have CGContextRef and its Bounds with me. But the bounds are with respect to Window to which CGContextRef belongs. For Example, if window is at location (100, 100, 50, 50) with respect to screen the contextRef for window would be (0,0, 50, 50). i.e. I am at location (0,0) but actually on screen I am at (100,100). I
Any suggestion are appreciated.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
窗口在全局屏幕空间中保持自己的位置,并且合成器知道如何将该窗口的图像放置在屏幕空间中的正确位置。然而,上下文本身没有位置。
Quartz Compositor 知道窗口在屏幕上的位置,但 Quartz 2D 只知道它应该绘制的区域有多大。它不知道 Quartz Compositor 完成绘图后会将其放置在哪里。
类似地,当将窗口的内容放在一起时,框架提供了视图系统。视图系统允许操作系统创建用于绘制窗口各个部分的上下文,并管理这些视图中绘制结果的放置,通常是通过操纵上下文的转换或创建临时的屏幕外上下文。然而,上下文本身并不知道最终图形将在哪里呈现。
The window maintains its own position in global screen space and the compositor knows how to put that window's image at the correct location in screen space. The context itself, however doesn't have a location.
Quartz Compositor knows where the window is positioned on the screen, but Quartz 2D doesn't know anything more than how big the area it is supposed to draw in is. It has no idea where Quartz Compositor is going to put the drawing once it is done.
Similarly, when putting together the contents of a window, the frameworks provide the view system. The view system allows the OS to create contexts for drawing individual parts of a window and manages the placement of the results of drawing in those views, usually by manipulating the context's transform, or by creating temporary offscreen contexts. The context itself, however, doesn't know where the final graphic is going to be rendered.
我不确定您是否可以直接使用 CGContextRef,您需要窗口或视图引用或类似的转换。
我使用的代码执行相反的操作,将鼠标坐标从全局(屏幕)转换为本地视图,它是这样的:
所以我想您需要相反的操作(尚未测试它是否确实有效):
I'm not sure if you can use directly CGContextRef, you need window or view reference or something like do the conversion.
The code I use does the opposite convert mouse coordinates from global (screen) to view local and it goes something like this:
so I guess the opposite is needed for you (haven't tested if it actually works):