• 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: Preventing default drawing of slider bar in custom NSSlider class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Preventing default drawing of slider bar in custom NSSlider class


  • Subject: Re: Preventing default drawing of slider bar in custom NSSlider class
  • From: Mikael Gransell <email@hidden>
  • Date: Sun, 18 Mar 2007 00:55:06 +0100

I feel that the main problem here is that the name of that method and the documentation can easily be misinterpreted since they do their drawing somewhere else. In other words, the method - (BOOL)_usesCustomTrackImage should not need to be there.

/Micke

On Mar 17, 2007, at 11:10 PM, Ken Tozier wrote:

Thanks Micke that works

It seems really dumb though that Apple doesn't expose "- (BOOL)_usesCustomTrackImage" It's a very elegant way to override drawing of the default track bar. The alternative from that link (By Dominik Pich)

- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
{
  cellFrame = [self drawingRectForBounds: cellFrame];

  [super setTrackRect: cellFrame]; //need to access private member

  [self drawBarInside: cellFrame flipped: [controlView isFlipped]];
  [self drawKnob];
}

@interface NSSliderCell (SetTrackRect)
@end

@implementation NSSliderCell (SetTrackRect)

- (void) setTrackRect: (NSRect)theRect {
  _trackRect = theRect;
}

@end


May work but why force developers to write all that override code when they could just use "_usesCustomTrackImage"?


I can't think of a single good reason to hide this method. Apple overrides sliders all the time in their own apps. Why make it such a headache for everyone else?
/rant


-Ken


On Mar 17, 2007, at 4:16 PM, Mikael Gransell wrote:

Hi Ken

Check out this link for a solution and description of your problem.

http://www.cocoabuilder.com/archive/message/cocoa/2007/1/16/177288

Cheers,
Micke


On Mar 17, 2007, at 9:01 PM, Ken Tozier wrote:


Hi



I wrote a custom NSSlider and NSSliderCell, overrode the "drawKnob:" and "drawBarInside:flipped:" of the NSSliderCell and got the stuff I want to draw working correctly, but I'm still getting the default slider bar behind my slider bar. I intentionally don't call the NSSliderCell's superclass which I thought would do the trick, but no luck. How can I get rid of the default?



Thanks for any help



Ken



Here's the slider bar draw method



- (void) drawBarInside:(NSRect) inRect

flipped:(BOOL) inFlipped

{

NSRect adjustedRect = NSMakeRect(inRect.origin.x + 10, 0, inRect.size.width - 20, inRect.size.height);



float rectHeight = inRect.size.height,

leftWidth = [gSliderTrackLeft size].width,

rightWidth = [gSliderTrackRight size].width,

centerWidth = adjustedRect.size.width - leftWidth - rightWidth,

adjustedRight = adjustedRect.origin.x + adjustedRect.size.width,

yOffset = (rectHeight - DefaultSliderBarHeight) / 2;



NSRect leftRect = NSMakeRect(adjustedRect.origin.x, adjustedRect.origin.y + yOffset, leftWidth, DefaultSliderBarHeight),

rightRect = NSMakeRect(adjustedRight - rightWidth, adjustedRect.origin.y + yOffset, rightWidth, DefaultSliderBarHeight),

centerRect = NSMakeRect(leftRect.origin.x + leftRect.size.width, adjustedRect.origin.y + yOffset, centerWidth, DefaultSliderBarHeight);



minXOrigin = 10;

maxXOrigin = adjustedRight;



[gSliderTrackLeft drawInRect: leftRect

fromRect: NSZeroRect

operation: NSCompositeSourceOver

fraction: 1.0];



[gSliderTrackCenter drawInRect: centerRect

fromRect: NSZeroRect

operation: NSCompositeSourceOver

fraction: 1.0];



[gSliderTrackRight drawInRect: rightRect

fromRect: NSZeroRect

operation: NSCompositeSourceOver

fraction: 1.0];

}



_______________________________________________



Cocoa-dev mailing list (email@hidden)



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


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: Preventing default drawing of slider bar in custom NSSlider class
      • From: Ken Tozier <email@hidden>
References: 
 >Preventing default drawing of slider bar in custom NSSlider class (From: Ken Tozier <email@hidden>)
 >Re: Preventing default drawing of slider bar in custom NSSlider class (From: Mikael Gransell <email@hidden>)
 >Re: Preventing default drawing of slider bar in custom NSSlider class (From: Ken Tozier <email@hidden>)

  • Prev by Date: Re: Getting NSException on NSManagedObjectContext save:
  • Next by Date: Re: Does willChange:valuesAtIndexes:forKey: work correctly?
  • Previous by thread: Re: Preventing default drawing of slider bar in custom NSSlider class
  • Next by thread: Re: Preventing default drawing of slider bar in custom NSSlider class
  • Index(es):
    • Date
    • Thread