Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

CAUGuiButton.cpp

Go to the documentation of this file.
00001 /*
00002  *  CAUGuiButton.cpp
00003  *  CoreGraphics AudioUnit GUI framework
00004  *
00005  *  Created by Urs Heckmann on Sun Oct 27 2002.
00006  *  Copyright (c) 2002 __MyCompanyName__. All rights reserved.
00007  *
00008  */
00009 
00010 #include "CAUGuiButton.h"
00011 
00012 CAUGuiButton::CAUGuiButton (    CAUGuiMan*          theChief,
00013                                 CAAUParameter       &theAuvp, 
00014                                 eRect*              theWhere,
00015                                 CAUGuiGraphic*      theForeGround, 
00016                                 CAUGuiGraphic*      theBackground,
00017                                 CAUGuiBottonMode    theMode)
00018                         
00019                             :   CAUGuiCtrl ( theChief, theAuvp, theWhere, kCAUGui_res_1 )
00020                             
00021 {
00022         
00023     ForeGround = theForeGround;
00024     BackGround = theBackground;
00025     mode = theMode;
00026     
00027     userProcedure = NULL;
00028     userData = NULL;
00029     
00030     onValue = 0;
00031     hilite = false;
00032     alpha = 0.7f;
00033     //printf ("ctor CAUGuiButton\n");
00034 
00035 }
00036 
00037 CAUGuiButton::CAUGuiButton (    CAUGuiMan*          theChief,
00038                                 UInt32              theRange, 
00039                                 eRect*              theWhere,
00040                                 CAUGuiGraphic*      theForeGround, 
00041                                 CAUGuiGraphic*      theBackground,
00042                                 CAUGuiBottonMode    theMode)
00043                         
00044                             :   CAUGuiCtrl ( theChief, theWhere, theRange )
00045                             
00046 {
00047         
00048     ForeGround = theForeGround;
00049     BackGround = theBackground;
00050     mode = theMode;
00051     
00052     userProcedure = NULL;
00053     userData = NULL;
00054     
00055     onValue = 0;
00056     hilite = false;
00057     alpha = 0.7f;
00058     //printf ("ctor CAUGuiButton\n");
00059 
00060 }
00061 
00062 
00063 CAUGuiButton::~CAUGuiButton ()
00064 {
00065 
00066     ForeGround = NULL;
00067     BackGround = NULL;
00068 
00069 
00070     //printf ("dtor CAUGuiButton\n");
00071 
00072 
00073 }
00074 
00075 void CAUGuiButton::draw(CGContextRef context, UInt32 portHeight )
00076 {
00077         
00078     CGImageRef theBack = NULL;
00079     CGImageRef theButton = NULL;
00080     CGRect bounds;
00081     
00082     getBounds()->to( &bounds, portHeight );
00083     
00084     if ( BackGround != NULL )
00085         theBack = BackGround->getImage();
00086         
00087     if ( ForeGround != NULL )
00088         theButton = ForeGround->getImage();
00089     
00090     if ( theBack != NULL )
00091         CGContextDrawImage( context, bounds, theBack );
00092     
00093     if ( theButton != NULL )
00094     {
00095         switch ( mode )
00096         {
00097         
00098             case kPushButton:
00099             case kRadioButton:
00100             
00101                         if ( GetControl32BitValue( getCarbonControl() ) == (SInt32) onValue )
00102                             ForeGround->draw( context, portHeight, getBounds(), 1.f );
00103                         else
00104                             ForeGround->draw( context, portHeight, getBounds(), 0.f );
00105                         break;
00106                         
00107             case kOnOffButton:
00108                         if ( GetControl32BitValue( getCarbonControl() ) == 0 )
00109                             ForeGround->draw( context, portHeight, getBounds(), 0.f );
00110                         else
00111                             ForeGround->draw( context, portHeight, getBounds(), 1.f );
00112                         break;
00113                 
00114         
00115             default:
00116     
00117                         if ( hilite )
00118                             CGContextDrawImage( context, bounds, theButton );
00119                         else
00120                         {
00121                             if ( alpha != 0.0f )
00122                             {
00123                                 CGContextSetAlpha( context, alpha);
00124                                 CGContextDrawImage( context, bounds, theButton );
00125                             }
00126                         }
00127                         break;
00128         }
00129     }
00130 
00131 }
00132 
00133 
00134 void CAUGuiButton::mouseDown(Point *P, bool with_option, bool with_shift)
00135 {
00136     ControlRef carbonControl = getCarbonControl();
00137     
00138     UInt32 value = GetControl32BitValue( carbonControl );
00139     UInt32 max = GetControl32BitMaximum( carbonControl );
00140     
00141     hilite = true;
00142     
00143     switch ( mode )
00144     {
00145         case kPushButton:
00146             SetControl32BitValue ( carbonControl, max );
00147             break;
00148     
00149         case kIncButton:
00150             if ( value == max ) value = 0;
00151             else value++;
00152             SetControl32BitValue ( carbonControl, value );
00153             break;
00154             
00155         case kDecButton:
00156             if ( value == 0 ) value = max;
00157             else value--;
00158             SetControl32BitValue ( carbonControl, value );
00159             break;
00160         
00161         case kRadioButton:
00162             SetControl32BitValue ( carbonControl, onValue );
00163             value = onValue;
00164             break;
00165         
00166         case kOnOffButton:
00167             if ( value != 0 )
00168                 value = 0;
00169             else
00170                 value = max;
00171             
00172             SetControl32BitValue ( carbonControl, value );
00173             break;
00174             
00175     
00176     }
00177     
00178     if ( userProcedure != NULL )
00179     {
00180         userProcedure ( value, this, userData );
00181     
00182     }
00183     
00184 }
00185 
00186 void CAUGuiButton::mouseTrack(Point *P, bool with_option, bool with_shift)
00187 {
00188     ;
00189 }
00190 
00191 void CAUGuiButton::mouseUp(Point *P, bool with_option, bool with_shift)
00192 {
00193     ControlRef carbonControl = getCarbonControl();
00194     
00195     hilite = false;
00196     
00197     switch ( mode )
00198     {
00199         case kPushButton:
00200             SetControl32BitValue ( carbonControl, 0 );
00201             break;
00202     
00203         case kIncButton:
00204             Draw1Control ( carbonControl );
00205             break;
00206             
00207         case kDecButton:
00208             Draw1Control ( carbonControl );
00209             break;
00210         
00211         case kRadioButton:
00212             SetControl32BitValue ( carbonControl, onValue );
00213             break;
00214         
00215         default:
00216             Draw1Control ( carbonControl );
00217             break;
00218     }
00219 }
00220 
00221 void CAUGuiButton::setUserProcedure ( buttonUserProcedure theProc, void* theUserData )
00222 {
00223     userProcedure = theProc;
00224     userData = theUserData;
00225 }
00226 
00227 
00228 
00229 

(c) 2002 - 2003 by Urs Heckmann www.u-he.com
Generated on Thu May 6 15:13:13 2004 for CAUGui by doxygen 1.3.6