home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-03-19 | 3.3 KB | 130 lines | [TEXT/CWIE] |
- //
- // CBevelAttachment.cp
- //
- // A Constructor-aware, PowerPlant Attachment for adding
- // an Apple Grayscale Appearance-like bevel to an LView.
- //
- // Copyright ©1996 by James Jennings. All rights reserved.
- // September 1, 1996
- //
-
- #include "CBevelAttachment.h"
-
- CGABaseAttachment::CGABaseAttachment( LStream *inStream )
- : LAttachment( inStream )
- { // we don't let Constructor specify any other kind of message
- mMessage = msg_DrawOrPrint;
- }
-
- void CGABaseAttachment::ExecuteSelf( MessageT inMessage, void *ioParam)
- { // Call the correct draw routine depending on the screen depth.
- #pragma unused(inMessage)
-
- Assert_( ioParam != nil );
-
- StColorState theSavedState;
-
- Rect theFrame = *(Rect *)ioParam;
-
- // The device loop sets the clip rect, so we need to tell it
- // the rect we plan to draw to.
- Rect clipRect = theFrame;
- AdjustClipRect( clipRect );
-
- StDeviceLoop devices(clipRect);
- Int16 depth;
-
- while (devices.NextDepth(depth)) {
- StColorPenState savePenState; // Will save and restore pen state
- savePenState.Normalize();
-
- if (depth > 3) {
- DrawColor( theFrame ); // we have at least 16 colors
- } else {
- DrawBlackAndWhite( theFrame );
- }
- }
-
- }
-
- #pragma mark === CBevelAttachment ===
- // a general attachement that can be entered in Constructor and then Reanimated
- CBevelAttachment * CBevelAttachment::CreateFromStream( LStream *inStream )
- {
- return new CBevelAttachment( inStream );
- }
-
- CBevelAttachment::CBevelAttachment( LStream *inStream )
- : CGABaseAttachment(inStream)
- {
- inStream->ReadData( &mBevelIn, sizeof( mBevelIn ) );
- inStream->ReadData( &mWidth, sizeof( mWidth ) );
- inStream->ReadData( &mErase, sizeof( mErase ) );
- }
-
- CBevelAttachment::CBevelAttachment( Boolean inBevelIn, Int16 inWidth, Boolean inErase )
- : mBevelIn( inBevelIn ), mWidth( inWidth ), mErase(inErase)
- {
- }
-
- void CBevelAttachment::DrawColor( Rect inFrame )
- {
- if (mErase) {
- SetBackColor(ga_White);
- ::EraseRect(&inFrame);
- }
-
- EGAColor tl, br, corners; // topleft, bottomright, and corner colors
- if ( mBevelIn ) {
- tl = ga_Shadow;
- br = ga_Hilite;
- corners = ga_Shadow;
- } else {
- tl = ga_Hilite;
- br = ga_Shadow;
- corners = ga_Hilite;
- }
-
- Int16 count;
- if (mWidth<0) {
- count = -mWidth;
- ::InsetRect( &inFrame, mWidth, mWidth );
- } else {
- count = mWidth;
- }
-
- for ( Int16 i=0; i<count; i++ ) {
- FrameRect( inFrame, tl, br, corners );
- ::InsetRect( &inFrame, 1, 1 );
-
- }
- // PaintRect( r, ga_Background );
- }
-
- #pragma mark === other attachments ===
-
- void CGAPaneAttachment::DrawColor( Rect inFrame )
- {
- FrameRect( inFrame, ga_Hilite, ga_Shadow, ga_Hilite );
- ::InsetRect( &inFrame, 1, 1 );
- PaintRect( inFrame, ga_Background );
- }
-
- void CGADeepPaneAttachment::DrawColor( Rect inFrame )
- { // The color scheme of a movable modal dialog. (Not counting the black outline.)
- FrameRect( inFrame, ga_2, ga_10, ga_2 );
- ::InsetRect( &inFrame, 1, 1 );
- FrameRect( inFrame, ga_White, ga_6, ga_2 );
- ::InsetRect( &inFrame, 1, 1 );
- PaintRect( inFrame, ga_Background );
- }
-
- void CGATextFieldAttachment::DrawColor( Rect inFrame )
- { // Note: Since we are drawing outside the panes boundaries, it is possible
- // that the edge will not get redrawn if the update region includes the bevel
- // but not the pane.
- EraseRect( inFrame, ga_White );
- ::InsetRect( &inFrame, -1, -1 );
- FrameRect( inFrame, ga_5, ga_White, ga_Background );
- }
-