Draw over screen with Quartz

大憨熊 提交于 2019-12-08 03:29:48

问题


I'm trying to work out what the best way to draw over the top of all other items on the screen on OS X. I don't want to impede the user's ability to interact with their applications, but want to 'annotate' them. I want to be able to draw up to 20 different annotations. The top half of this screenshot from Gizmodo happens to nicely show the kind of thing I want to do. http://gizmodo.com/assets/resources/2006/07/04%20Safari.jpg (sorry, I'm too new to post it as an image)

The questions I think I need to answer are:

  1. Should I create a single window for each drawing and draw to that? If so, how do I minimise overhead?
  2. What kind of window or other context should I use given that I don't want any window decoration?

I don't think I want the overhead of creating 20 windows, but I also don't know that I want to create a full-screen, invisible window that contains my context (I presume a subclassed NSView), because I fear that will a) cause problems interacting with what's below and b) break the niceties of only redrawing when necessary (my actual drawing will likely only cover 10% of the screen)

I've not worked with Quartz2d before, so I just can't get my head around how to get the 'right' context to draw on from the documentation. Any help would be appreciated.

Thanks,

Who


回答1:


You can only draw into a window. You can make a transparent, borderless window but it will need to be at the front.

You could set it's level to something like NSPopUpMenuWindowLevel to make it draw above other windows (this will be very annoying to users) but clicking on it will:

a) activate and bring to the front your app

b) Prevent the app underneath receiving mouse events

Is that what you want?



来源:https://stackoverflow.com/questions/3081204/draw-over-screen-with-quartz

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!