• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Where do these come from...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Where do these come from...


  • Subject: Re: Where do these come from...
  • From: Charlie Dickman <email@hidden>
  • Date: Wed, 15 Aug 2012 23:02:40 -0400

Here's the whole method... it is being called from within a view's drawRect method...

- (void) showDiceAtX: (float) x Y: (float) y {
	NSRect imageRect1, imageRect2;
	NSImage *die1 = nil, *die2 = nil;
	iDie = iRand(1, 6);
	switch (iDie) {
		case 1:
			die1 = [NSImage imageNamed: @"1 Die"];
			break;
		case 2:
			die1 = [NSImage imageNamed: @"2 Die"];
			break;
		case 3:
			die1 = [NSImage imageNamed: @"3 Die"];
			break;
		case 4:
			die1 = [NSImage imageNamed: @"4 Die"];
			break;
		case 5:
			die1 = [NSImage imageNamed: @"5 Die"];
			break;
		case 6:
			die1 = [NSImage imageNamed: @"6 Die"];
	}
	jDie = iRand(1, 6);
	switch (jDie) {
		case 1:
			die2 = [NSImage imageNamed: @"1 Die"];
			break;
		case 2:
			die2 = [NSImage imageNamed: @"2 Die"];
			break;
		case 3:
			die2 = [NSImage imageNamed: @"3 Die"];
			break;
		case 4:
			die2 = [NSImage imageNamed: @"4 Die"];
			break;
		case 5:
			die2 = [NSImage imageNamed: @"5 Die"];
			break;
		case 6:
			die2 = [NSImage imageNamed: @"6 Die"];
	}
	imageRect1.origin = imageRect2.origin = NSZeroPoint;
	imageRect1.size = [die1 size];
	imageRect2.size = [die2 size];
	/*
	 * NSRect NSMakeRect(float x, float y, float w, float h)
	 *
	 * Creates an NSRect having the specified origin of [x, y] and size of [w, h]
	 */
	iDieDrawRect = NSMakeRect(x - imageRect1.size.width - 2, y, imageRect1.size.width, imageRect1.size.height);
	jDieDrawRect = NSMakeRect(x + 2, y, imageRect2.size.width, imageRect2.size.height);

	while (![self lockFocusIfCanDraw]) RELQ(.1);
	[[NSColor whiteColor] set];
	[die1 drawInRect: iDieDrawRect
			  fromRect: imageRect1
			 operation: NSCompositeSourceOver
			  fraction: 1.0];
	[die2 drawInRect: jDieDrawRect
			  fromRect: imageRect2
			 operation: NSCompositeSourceOver
			  fraction: 1.0];
	[self unlockFocus];
	[[self window] flushWindow];
}

without the lockFocus the images never show.

On Aug 15, 2012, at 10:35 PM, Stephen J. Butler wrote:

> On Wed, Aug 15, 2012 at 10:20 AM, Charlie Dickman <email@hidden> wrote:
>>        [[NSColor whiteColor] set];
>>        [die1 drawInRect: iDieDrawRect
>>                          fromRect: imageRect1
>>                         operation: NSCompositeSourceOver
>>                          fraction: 1.0];
>>        [die2 drawInRect: jDieDrawRect
>>                          fromRect: imageRect2
>>                         operation: NSCompositeSourceOver
>>                          fraction: 1.0];
>
> Where are these being called from in your program? What's the context
> of the surrounding code in the method?

Charlie Dickman
email@hidden




_______________________________________________

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

  • Follow-Ups:
    • Re: Where do these come from...
      • From: Graham Cox <email@hidden>
    • Re: Where do these come from...
      • From: Mike Abdullah <email@hidden>
    • Re: Where do these come from...
      • From: "Stephen J. Butler" <email@hidden>
References: 
 >Where do these come from... (From: Charlie Dickman <email@hidden>)
 >Re: Where do these come from... (From: "Stephen J. Butler" <email@hidden>)

  • Prev by Date: Displaying a sheet immediately after a window is opened
  • Next by Date: Re: Mountain Lion crashes Simulator
  • Previous by thread: Re: Where do these come from...
  • Next by thread: Re: Where do these come from...
  • Index(es):
    • Date
    • Thread