• 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: Scaled image in NSButtonCell flipped - drawInRect:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scaled image in NSButtonCell flipped - drawInRect:


  • Subject: Re: Scaled image in NSButtonCell flipped - drawInRect:
  • From: Richard Salvatierra <email@hidden>
  • Date: Tue, 3 Jan 2006 21:22:24 -0500

Ricky - Thank you for the reply. I have submitted my code in hopes it will help explain my problem. When I apply the NSAffineTransform, the image does flip, but so do the rest of my drawings. I suppose I have to apply the NSAffineTransform just before I draw the image, then revert back. If so, how? Also, I am fairly new to cocoa so any other pointers/advice greatly appreciated.

#define CELL_MARGIN		 6
#define MIN_CELL_HEIGHT	 50

- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *) controlView
{
// controlView is flipped (in NSMatrix) so flip/transform
NSAffineTransform* theAffineTransform = [NSAffineTransform transform];
[theAffineTransform scaleXBy:1.0 yBy:-1.0];
[theAffineTransform translateXBy:0.0 yBy:-cellFrame.size.height];
[theAffineTransform concat];

// create margin for inside of cell
cellFrame.origin.x += (CELL_MARGIN);
cellFrame.origin.y += (CELL_MARGIN);
cellFrame.size.width -= (CELL_MARGIN*2);
cellFrame.size.height -= (CELL_MARGIN*2);


// if cell is large enough, draw title
if(cellFrame.size.height > MIN_CELL_HEIGHT){
// titleRect height equals font size, then place title origin below cell image
NSRect titleRect;
titleRect.size.height = 18;
titleRect.origin.y = cellFrame.origin.y+cellFrame.size.height- titleRect.size.height;
titleRect.origin.y += (CELL_MARGIN);
// reduce image hieght for title
cellFrame.size.height -= (CELL_MARGIN*2);
[attrs setValue:[NSColor whiteColor] forKey:@"NSColor"];
[[self title] drawInRect:titleRect withAttributes:attrs];
}


// main thumbnail
[image drawInRect: cellFrame fromRect: NSZeroRect operation: NSCompositeSourceIn fraction: 1];


// draw grey rect with icon over it ... simple icon removed for simplicity
}



I also do scaling and here's what I currently do in an NSActionCell subclass:

- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *) controlView
{
...
if ([controlView isFlipped])
{
NSAffineTransform* theAffineTransform = [NSAffineTransform transform];

[theAffineTransform scaleXBy:1.0 yBy:-1.0];
[theAffineTransform translateXBy:0.0 yBy:- cellFrame.size.height];

[theAffineTransform concat];
}
//draw image here
}

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Scaled image in NSButtonCell flipped - drawInRect:
      • From: Ricky Sharp <email@hidden>
References: 
 >Scaled image in NSButtonCell flipped - drawInRect: (From: Richard Salvatierra <email@hidden>)
 >Re: Scaled image in NSButtonCell flipped - drawInRect: (From: Ricky Sharp <email@hidden>)

  • Prev by Date: Re: Core Data Binding: Reading a binary image (TIFF)
  • Next by Date: Re: Embedding Flash in .app, Round Two
  • Previous by thread: Re: Scaled image in NSButtonCell flipped - drawInRect:
  • Next by thread: Re: Scaled image in NSButtonCell flipped - drawInRect:
  • Index(es):
    • Date
    • Thread