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

CAUGuiPane.cpp

Go to the documentation of this file.
00001 /*
00002  *  CAUGuiPane.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 "CAUGuiPane.h"
00011 
00012 CAUGuiPane::CAUGuiPane (    CAUGuiMan*          theChief,
00013                             eRect*              theWhere,
00014                             CAUGuiGraphic*      theBackground)
00015                         
00016                         :   CAUGuiCtrl ( theChief, theWhere )
00017                             
00018 {
00019     
00020     BackGround = theBackground;
00021     
00022     upperLeft = NULL;
00023     lowerRight = NULL;
00024     
00025     //printf ("ctor CAUGuiPane\n");
00026     
00027     setType ( kCAUGui_Pane );
00028     
00029     setTolerance ( 0 );
00030 
00031 }
00032 
00033 CAUGuiPane::~CAUGuiPane ()
00034 {
00035     //printf ("dtor CAUGuiPane\n");
00036 
00037 
00038 }
00039 
00040 bool CAUGuiPane::isControlRef ( ControlRef theControl ) 
00041 {
00042 
00043     if (upperLeft == theControl || lowerRight == theControl)
00044         return true;
00045         
00046     return CAUGuiCtrl::isControlRef (theControl);
00047     
00048 }
00049 
00050 CAUGuiCtrl* CAUGuiPane::getChild(ControlRef theControl)
00051 {
00052     if (upperLeft == theControl || lowerRight == theControl)
00053         return this;
00054 
00055     return CAUGuiCtrl::getChild (theControl);
00056 
00057 }
00058 
00059 void CAUGuiPane::initForeignControls ( ControlDefSpec &ControlSpec )
00060 {
00061     // if the pane has a Background image, it gets two Carbon controls to receive events
00062         
00063     if ( BackGround != NULL )
00064     {
00065         
00066         ControlRef newControl;
00067         
00068         Rect r;
00069     
00070         getBounds ( &r );
00071     
00072         r.right = r.left + 1;
00073         r.bottom = r.top + 1;
00074         
00075         verify_noerr(CreateCustomControl( getCAUGuiMan()->getAUCarbonViewBase()->GetCarbonWindow(), &r, &ControlSpec, NULL, &newControl));
00076         
00077         upperLeft = newControl;
00078         
00079         getBounds ( &r );
00080     
00081         r.left = r.right - 1;
00082         r.top = r.bottom - 1;
00083         
00084         verify_noerr(CreateCustomControl( getCAUGuiMan()->getAUCarbonViewBase()->GetCarbonWindow(), &r, &ControlSpec, NULL, &newControl));
00085         
00086         lowerRight = newControl;
00087     
00088         getCAUGuiMan()->getAUCarbonViewBase()->EmbedControl ( upperLeft );
00089         getCAUGuiMan()->getAUCarbonViewBase()->EmbedControl ( lowerRight );
00090     
00091     }
00092     else
00093         setOpaque( false );
00094 }
00095 
00096 
00097 void CAUGuiPane::draw(CGContextRef context, UInt32 portHeight )
00098 {
00099     //printf ( "drawing this pane!\n");
00100     
00101     CGImageRef theBack = NULL;
00102     
00103     if ( BackGround != NULL )
00104         theBack = BackGround->getImage();
00105         
00106     if ( theBack != NULL )
00107         CGContextDrawImage( context, CGRectMake( getBounds()->x, portHeight - getBounds()->h - getBounds()->y, getBounds()->w, getBounds()->h), theBack );
00108 
00109 
00110 }
00111 
00112 
00113 CAUGuiLayeredPane::CAUGuiLayeredPane (  CAUGuiMan*          theChief,
00114                                         eRect*              theWhere,
00115                                         CAUGuiGraphic*      theBackground)
00116                         
00117                         :   CAUGuiPane ( theChief, theWhere, theBackground )
00118                             
00119 {
00120     
00121     for ( int i = 0; i < CAUGUI_PANE_MAX_LAYERS; i++ )
00122     {
00123         layerBackGround[ i ] = NULL;
00124         Layered[ i ] = NULL;
00125     }
00126     
00127     for ( int i = 0; i < CAUGUI_PANE_MAX_GROUPS; i++ )
00128     {
00129         Grouped[ i ] = NULL;
00130         GroupLabels[ i ] = NULL;
00131         GroupState[ i ] = 0;
00132     }
00133     
00134     currentLayer = 0;
00135     
00136     //printf ("ctor CAUGuiPane\n");
00137     
00138     setType ( kCAUGui_LayeredPane );
00139 
00140 }
00141 
00142 CAUGuiLayeredPane::~CAUGuiLayeredPane ()
00143 {
00144     for ( int i = 0; i < CAUGUI_PANE_MAX_LAYERS; i++ )
00145     {
00146         if ( Layered[ i ] != NULL ) delete Layered[ i ];
00147         if ( layerBackGround[ i ] != NULL ) layerBackGround[ i ] = NULL;
00148     }
00149     
00150     for ( int i = 0; i < CAUGUI_PANE_MAX_GROUPS; i++ )
00151     {
00152         if ( Grouped[ i ] != NULL ) delete Grouped[ i ];
00153         if ( GroupLabels[ i ] != NULL ) delete GroupLabels[ i ];
00154         
00155     }
00156     
00157     //printf ("dtor CAUGuiLayeredPane\n");
00158 
00159 
00160 }
00161 
00162 
00163 CAUGuiCtrl* CAUGuiLayeredPane::getChild(ControlRef theControl)
00164 {       
00165     if ( Layered[ currentLayer ] != NULL )
00166     {
00167         CAUGuiCtrl* current = Layered[ currentLayer ];
00168         while( current != NULL )
00169         {
00170             if ( current->isControlRef ( theControl ) )
00171                 return current->getChild( theControl );
00172         
00173             current = (CAUGuiCtrl*)current->getNext();
00174         }
00175     }
00176 
00177     for ( int i = 0; i < CAUGUI_PANE_MAX_GROUPS; i++ )
00178     {
00179         if ( GroupState[ i ] != 0 )
00180         {
00181             CAUGuiCtrl* current = Grouped[ i ];
00182             while( current != NULL )
00183             {
00184                 if ( current->isControlRef ( theControl ) )
00185                     return current->getChild( theControl );
00186             
00187                 current = (CAUGuiCtrl*)current->getNext();
00188             }
00189         
00190         
00191         }
00192         
00193     }
00194 
00195     return CAUGuiPane::getChild (theControl);
00196 
00197 }
00198 
00199 bool CAUGuiLayeredPane::isControlRef ( ControlRef theControl )
00200 {
00201     if ( Layered[ currentLayer ] != NULL )
00202     {
00203         CAUGuiCtrl* current = Layered[ currentLayer ];
00204         while( current != NULL )
00205         {
00206             if ( current->isControlRef ( theControl ) ) return true;
00207             current = (CAUGuiCtrl*)current->getNext();
00208         }
00209     }
00210     
00211     for ( int i = 0; i < CAUGUI_PANE_MAX_GROUPS; i++ )
00212     {
00213         if ( GroupState[ i ] != 0 )
00214         {
00215             CAUGuiCtrl* current = Grouped[ i ];
00216             while( current != NULL )
00217             {
00218                 if ( current->isControlRef ( theControl ) )
00219                     return true;
00220             
00221                 current = (CAUGuiCtrl*)current->getNext();
00222             }
00223         
00224         
00225         }
00226         
00227     }
00228 
00229     
00230     
00231     return CAUGuiPane::isControlRef (theControl);
00232 }
00233 
00234 
00235 
00236 void CAUGuiLayeredPane::draw(CGContextRef context, UInt32 portHeight )
00237 {
00238     //printf ( "drawing this pane!\n");
00239     
00240     CGImageRef theBack = NULL;
00241     
00242     if ( layerBackGround[ currentLayer ] != NULL )
00243         theBack = layerBackGround[ currentLayer ]->getImage();
00244     else
00245     {
00246         if ( BackGround != NULL )
00247         theBack = BackGround->getImage();
00248     
00249     }
00250         
00251     if ( theBack != NULL )
00252         CGContextDrawImage( context, CGRectMake( getBounds()->x, portHeight - getBounds()->h - getBounds()->y, getBounds()->w, getBounds()->h), theBack );
00253 
00254     eRect where;
00255     where.set (getBounds());
00256     
00257     for ( int i = 0; i < CAUGUI_PANE_MAX_GROUPS; i++ )
00258     {
00259         if ( GroupState[ i ] != 0 )
00260         {
00261             CAUGuiLabel* current = GroupLabels[ i ];
00262             while( current != NULL )
00263             {
00264                 current->draw ( context, portHeight, &where, 1.f );
00265             
00266                 current = (CAUGuiLabel*)current->getNext();
00267             }
00268         
00269         
00270         }
00271         
00272     }
00273 
00274 
00275 }
00276 
00277 void    CAUGuiLayeredPane::clip ( bool drawing )
00278 {
00279     if ( getOpaque() )
00280     {
00281         Rect r;
00282         getBounds()->to ( &r );
00283         FrameRect( &r );
00284         //printf ( "clipping opaque %d %d %d %d\n", r.left, r.top, r.right, r.bottom );
00285     }
00286     
00287     if ( !getOpaque() || drawing )
00288     {       
00289         CAUGuiCtrl* current = children;
00290         while( current != NULL )
00291         {
00292             //printf ( "clipping child %d\n", (int) current->getID() );
00293             current->clip( false );
00294             current = (CAUGuiCtrl*)current->getNext();
00295         }
00296         
00297         current = Layered[ currentLayer ];
00298         while( current != NULL )
00299         {
00300             //printf ( "clipping layered %d %d\n", currentLayer, (int) current->getID() );
00301             current->clip( false );
00302             current = (CAUGuiCtrl*)current->getNext();
00303         }
00304         
00305         for ( int i = 0; i < CAUGUI_PANE_MAX_GROUPS; i++ )
00306         {
00307             if ( GroupState[ i ] != 0 )
00308             {
00309                 current = Grouped[ i ];
00310                 while( current != NULL )
00311                 {
00312                     current->clip( false );
00313                 
00314                     current = (CAUGuiCtrl*)current->getNext();
00315                 }
00316             
00317             
00318             }
00319             
00320         }
00321     }
00322 
00323 
00324 }
00325 
00326 void    CAUGuiLayeredPane::idle ( )
00327 {
00328     CAUGuiPane::idle();
00329 
00330     if ( Layered[ currentLayer ] != NULL )
00331         Layered[ currentLayer ]->idle();
00332         
00333     for ( int i = 0; i < CAUGUI_PANE_MAX_GROUPS; i++ )
00334     {
00335         if ( GroupState[ i ] == 1 )
00336         {
00337             if ( Grouped[ i ] != NULL )
00338             {
00339                 Grouped[ i ]->idle();
00340             }
00341         }
00342     }
00343 }
00344 
00345 void    CAUGuiLayeredPane::setLayer ( int l )
00346 {
00347     if ( Layered[ currentLayer ] != NULL )
00348     {
00349         CAUGuiCtrl* current = Layered[ currentLayer ];
00350         while( current != NULL )
00351         {
00352             current->setVisible( false );
00353             current = (CAUGuiCtrl*)current->getNext();
00354         }
00355     }
00356     
00357     if ( l >= CAUGUI_PANE_MAX_LAYERS || l < 0 ) l = 0;
00358     
00359     currentLayer = l;
00360     
00361     if ( Layered[ currentLayer ] != NULL )
00362     {
00363         CAUGuiCtrl* current = Layered[ currentLayer ];
00364         while( current != NULL )
00365         {
00366             current->setVisible( true );
00367             current = (CAUGuiCtrl*)current->getNext();
00368         }
00369     }
00370     
00371     if ( upperLeft != NULL )
00372     {
00373         becameVisible = true; // too much drawing while mousing prevention workaround
00374         Draw1Control ( upperLeft );
00375     }
00376 }
00377 
00378 
00379 void    CAUGuiLayeredPane::showGroup ( int l, bool visible )
00380 {
00381     if ( Grouped[ l ] != NULL )
00382     {
00383         if ( visible )
00384         {
00385             if ( GroupState[ l ] == 0 )
00386             {
00387                 GroupState[ l ] = 1;
00388             
00389                 CAUGuiCtrl* current = Grouped[ l ];
00390                 while( current != NULL )
00391                 {
00392                     current->setVisible( true );
00393                     current = (CAUGuiCtrl*)current->getNext();
00394                 }
00395             
00396             }
00397         
00398         
00399         }
00400         else
00401         {
00402             if ( GroupState[ l ] != 0 )
00403             {
00404                 GroupState[ l ] = 0;
00405             
00406                 CAUGuiCtrl* current = Grouped[ l ];
00407                 while( current != NULL )
00408                 {
00409                     current->setVisible( false );
00410                     current = (CAUGuiCtrl*)current->getNext();
00411                 }
00412             
00413             }
00414         
00415         
00416         }
00417     }
00418 
00419 }
00420 
00421 
00422 
00423 void    CAUGuiLayeredPane::addCtrl( CAUGuiCtrl* theCtrl, int theLayer )
00424 {
00425 
00426     if ( theLayer >= CAUGUI_PANE_MAX_LAYERS || theLayer < 0 ) theLayer = 0;
00427 
00428     if ( Layered[ theLayer ] == NULL )
00429             Layered[ theLayer ] = theCtrl;
00430         else
00431             Layered[ theLayer ]->append( theCtrl );
00432             
00433     theCtrl->setDaddy ( this );
00434     theCtrl->setOffset ( where.x, where.y );
00435     
00436     Chief->addCtrl( theCtrl );
00437 
00438     if ( theLayer != currentLayer )
00439         theCtrl->setVisible( false );
00440 
00441 
00442 }
00443 
00444 void    CAUGuiLayeredPane::addCtrlToGroup( CAUGuiCtrl* theCtrl, int theGroup )
00445 {
00446 
00447     if ( theGroup >= CAUGUI_PANE_MAX_GROUPS || theGroup < 0 ) theGroup = 0;
00448 
00449     if ( Grouped[ theGroup ] == NULL )
00450             Grouped[ theGroup ] = theCtrl;
00451         else
00452             Grouped[ theGroup ]->append( theCtrl );
00453             
00454     theCtrl->setDaddy ( this );
00455     theCtrl->setOffset ( where.x, where.y );
00456     
00457     Chief->addCtrl( theCtrl );
00458 
00459     theCtrl->setVisible( false );
00460 
00461 
00462 }
00463 
00464 
00465 void CAUGuiLayeredPane::setOffset ( SInt32 x, SInt32 y )
00466 {
00467     CAUGuiPane::setOffset ( x, y );
00468 
00469 
00470     for ( int i = 0; i < CAUGUI_PANE_MAX_LAYERS; i++ )
00471     {
00472         if ( Layered[ i ] != NULL )
00473         {
00474             CAUGuiCtrl* current = Layered[ i ];
00475             while ( current != NULL )
00476             {
00477                 current->setOffset ( x, y );
00478                 current = (CAUGuiCtrl*)(current->getNext());
00479             }
00480         }
00481     }
00482 }
00483 
00484 void    CAUGuiLayeredPane::addBackground( CAUGuiGraphic* theBG, int theLayer )
00485 {
00486 
00487     if ( theLayer >= CAUGUI_PANE_MAX_LAYERS || theLayer < 0 ) theLayer = 0;
00488     
00489     layerBackGround[ theLayer ] = theBG;
00490 
00491 
00492 }
00493 
00494 void    CAUGuiLayeredPane::placeGroupLabel ( CAUGuiGraphic* label, int group, int x, int y )
00495 {
00496     eRect where ( x, y, 0, 0 );
00497     
00498     CAUGuiLabel* aLabel = new CAUGuiLabel( label, &where );
00499 
00500     if ( GroupLabels[ group ] == NULL )
00501         GroupLabels[ group ] = aLabel;
00502     else
00503         GroupLabels[ group ]->append( aLabel );
00504 
00505 
00506 }
00507 
00508 
00509 
00510 
00511 
00512 

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