开发者

Quartz code to create a button?

Cocoa/Carbon uses quartz underneath to create the UI. I am trying to get the quartz code generated when we create button in cocoa?

NSButton *myButton = [[NSButton alloc] initWithFrame:NSRectFromCGRect(CGRectMake(20,20,200, 44))];
[myButton setTitle:@"Click Me!"];
[myButton setBezelStyle:NSRoundedBezelStyle];
[[window contentView] addSubview:myButton];

Or please let me know a bit low level call to create Button in Cocoa something similar to

extern OSStatus 
HIThemeDrawButton(
  cons开发者_如何学Got HIRect *                 inBounds,
  const HIThemeButtonDrawInfo *  inDrawInfo,
  CGContextRef                   inContext,
  HIThemeOrientation             inOrientation,
  HIRect *                       outLabelRect)

Any help is highly appreciated.

Thank you.


I am trying to get the quartz code generated when we create button in cocoa?

You can't get that because there is no such thing to get.

Creating a button does not generate code, Quartz or otherwise. The code is already written; it is simply used by the new button object when that object is told to draw, with the button (with all of its properties) provided to the code as input. The same goes for your own drawRect: implementations.

It's a little more abstract in AppKit's case, though. In the last couple of versions of Mac OS X, Apple has switched to describing the standard views' appearances in XML files. A framework called Core UI implements the drawing by following these XML “recipes”; this, presumably, ultimately ends up calling Quartz functions (though this still doesn't necessarily mean any code is generated).

John Siracusa talks in broad strokes about Core UI in his Leopard review.

HITheme and Appearance Manager probably both call into Core UI the same way nowadays, though they only draw a button (or whatever). That's the only publicly-available way to do that without creating an actual button that can respond to events.

As a part of my research, I need to prove all the UI of Cocoa/Carbon frameworks makes use of Quartz …

otx may help you there: It lets you disassemble the frameworks to see what they actually do. Be warned that doing that violates the Mac OS X EULA.

… and its possible to render all of them using quartz.

It is. It may take a lot of work to get richly-designed fully-vector-based views just so (play with the scale factor in Quartz Debug and watch the vectorized controls fall apart), but it is possible. Even if you punt and just draw a raster image, you'd still be using Quartz to do that.

What AppKit almost certainly doesn't do, though, is draw using Quartz directly. That was HITheme's (and Appearance Manager's before that) job, and is now Core UI's. I'd expect to see AppKit using HITheme, HITheme using Core UI, and Core UI using Quartz.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜