Drawing A Mutable String
Drawing A Mutable String
- Subject: Drawing A Mutable String
- From: Michael Craig <email@hidden>
- Date: Thu, 7 Jan 2010 15:29:09 -0500
Hi all,
This has me completely boggled.
I've got a GameController with some BOOL instance variables that it uses to
make certain gamestate information available to other objects. I've also got
a GameView that looks at those BOOLs and conditionally appends an
NSMutableString before it gets drawn. The relevant chunk of drawRect: looks
like this:
NSRect infoRect = NSMakeRect(hBuff,
vBuff,
cardSize.width,
[self
frame].size.height - vBuff * 4);
NSDictionary *infoAtts = [NSDictionary
dictionaryWithObjectsAndKeys: [NSFont labelFontOfSize:
infoFontSize],
NSFontAttributeName,
rightAligned,
NSParagraphStyleAttributeName, nil];
NSNumber *cardsInDeck = [NSNumber numberWithUnsignedInteger:
[theDeck.cardPile count]];
NSMutableString *infoStr = [NSMutableString stringWithString: @"Cards in
deck: "];
[infoStr appendString: [cardsInDeck stringValue]];
if ([theDeck.cardPile count] == 0) {
[infoStr appendString: @"\n\nThe deck is empty."]; //
*2*
}
if (gameCon.invalidStack) {
[infoStr appendString: @"\n\nThat's an invalid stack."]; //
*1*
}
[infoStr drawInRect: infoRect
withAttributes: infoAtts];
The number of cards in the deck is always displayed, and additional text
should be drawn if the deck is empty or if gameCon.invalidStack is YES. The
empty deck text is drawn as intended, but the invalidStack text is never
drawn. However, it IS being appended to infoStr at all the right times
(tested by printf'ing the contents of infoStr after the above chunk).
If I move the line marked *1* to come after the line marked *2*, then both
messages are drawn when the deck is empty, as one would expect.
If I move the line marked *1* one line down (so it's outside of the
invalidStack if statement and the if is empty), then invalidStack message is
drawn at all times, as one would expect.
So what is keeping it from drawing the appended text when it happens inside
the invalidStack if statement? Like I said above, the if statement itself
works fine.
Thanks,
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden