[Cabi@net:work Top Page]
[Programming Snipettes]
[Colorizing Menu Items]
[Default Button Outline]
Haven't you met applications that use the button like this?
I feel this is not beautiful.
The better one is something like this.
There is few difference between these two buttons. However, I cannot trust the programmer who uses the former button. I'd rather trust the programmer that forgets DisposeHandle.
The reason that it is drawn like the former is that the programmer uses 16 as oval width/height.
This value (= 16) is valid only when the button height is just 20 pixel. Since ResEdit's 'DITL' editor creates 20 pixel height buttons as a default, usually 16 is valid. Althogh there is this fact, I recommend using the proper drawing method.
Here is a
sample code to draw the outline.
This is the simplest routine.
You had better to draw in more proper way when the port is a color port.
See 'Inside Macintosh : Maintosh Toolbox Essentials' Listing 6-17 for more information.
#define kButtonFrameInset -4 #define kButtonFrameSize 3 void DrawDefaultButtonOutline( ControlHandle inButtonH ) { Rect theButtonRect; PenState theSavedPenState; SInt16 theButtonOval; GrafPtr theSavedPortP; GetPort( &theSavedPortP ); SetPort( ( **inButtonH ).contrlOwner ); GetPenState( &theSavedPenState ); PenNormal(); theButtonRect = ( **inButtonH ).contrlRect; InsetRect( &theButtonRect, kButtonFrameInset, kButtonFrameInset ); // The proper oval width/height is following. Not 16. theButtonOval = ( theButtonRect.bottom - theButtonRect.top ) / 2 + 2; // Active or inactive. kControlNoPart is defined in Controls.h if( ( **inButtonH ).contrlHilite != kControlNoPart ) { PenPat( &qd.black ); } else { PenPat( &qd.gray ); } PenSize( kButtonFrameSize, kButtonFrameSize ); FrameRoundRect( &theItemRect, theButtonOval, theButtonOval ); SetPenState( &theSavedPenState ); SetPort( theSavedPortP ); } [Back]