Graphics Reference
In-Depth Information
delegate to the
AppDelegate
. This enables the
AppDelegate
to receive
mouseUp
and
mouseDown
events from
contentView
.
After launching, the application builds the interface layers before presenting the window
to the user. The best way to do this is to implement the
-awakeFromNib
method in the
AppDelegate
class, as shown in Listing 11-7. This method is called before the application
renders anything onscreen and is processed as the application starts up. We want to set
up everything before display to avoid an ugly redraw as the application appears on screen.
LISTING 11-7
AppDelegate -awakeFromNib implementation
- (
void
)awakeFromNib
{
NSView
*contentView = [
window contentView
];
[contentView
setWantsLayer
:
YES
];
CALayer
*contentLayer = [contentView
layer
];
[contentLayer
setBackgroundColor
:
kBlackColor
];
redButton
= [
LZButtonLayer layer
];
[
redButton setString
:
@”Red”
];
[
redButton setPosition
:
CGPointMake
(60, 22)];
[
redButton setMyColor
:
kRedColor
];
[contentLayer
addSublayer
:
redButton
];
greenButton
= [
LZButtonLayer layer
];
[
greenButton setString
:
@”Green”
];
[
greenButton setPosition
:
CGPointMake
(200, 22)];
[
greenButton setMyColor
:
kGreenColor
];
[contentLayer
addSublayer
:
greenButton
];
blueButton
= [
LZButtonLayer layer
];
[
blueButton setString
:
@”Blue”
];
[
blueButton setPosition
:
CGPointMake
(340, 22)];
[
blueButton setMyColor
:
kBlueColor
];
[contentLayer
addSublayer
:
blueButton
];
colorBar
= [
CALayer layer
];
[
colorBar setBounds
:
CGRectMake
(0, 0, 380, 20)];
[
colorBar setPosition
:
CGPointMake
(200, 100)];