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

CAUGuiDisplay.cpp

Go to the documentation of this file.
00001 /*
00002  *  CAUGuiDisplay.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 "CAUGuiDisplay.h"
00011 
00012 CAUGuiDisplay::CAUGuiDisplay (  CAUGuiMan*          theChief,
00013                             CAAUParameter           &theAuvp, 
00014                             eRect*                  theWhere,
00015                             CAUGuiResolution        theRes, 
00016                             CAUGuiGraphic*          theForeGround, 
00017                             CAUGuiGraphic*          theBackground)
00018                         
00019                         :   CAUGuiCtrl ( theChief, theAuvp, theWhere, theRes )
00020                             
00021 {
00022         
00023     ForeGround = theForeGround;
00024     BackGround = theBackground;
00025     theTexter = NULL;
00026     theUserData = NULL;
00027     hasText = false;
00028     
00029     userProcedure = NULL;
00030     userData = NULL;
00031     
00032     textalign = CAUGUI_DEFAULT_FONT_ALIGN; 
00033     
00034     //printf ("ctor CAUGuiDisplay\n");
00035     
00036     setType ( kCAUGui_Display );
00037     
00038     popUp = NULL;
00039 
00040 }
00041 
00042 CAUGuiDisplay::CAUGuiDisplay (  CAUGuiMan*          theChief,
00043                             CAAUParameter           &theAuvp, 
00044                             eRect*                  theWhere,
00045                             CAUGuiResolution        theRes, 
00046                             displayTextProcedure    aTexter, 
00047                             void*                   userDData,
00048                             CAUGuiGraphic*          theBackground)
00049                         
00050                         :   CAUGuiCtrl ( theChief, theAuvp, theWhere, theRes )
00051                             
00052 {
00053         
00054     ForeGround = NULL;
00055     BackGround = theBackground;
00056     
00057     userProcedure = NULL;
00058     userData = NULL;
00059     
00060     theTexter = aTexter;
00061     
00062     if ( theTexter != NULL )
00063         hasText = true;
00064     else
00065         hasText = false;
00066         
00067     popUp = NULL;
00068     
00069     if ( userData != NULL )
00070         theUserData = userDData;
00071     else
00072         theUserData = this;
00073     
00074     textalign = CAUGUI_DEFAULT_FONT_ALIGN;
00075         
00076     //printf ("ctor CAUGuiDisplay\n");
00077     
00078     setType ( kCAUGui_Display );
00079 
00080 #if AUTO_POP_UP_MENUES
00081 
00082     if ( (int)auvp.ParamInfo().unit == kAudioUnitParameterUnit_Indexed )
00083     {
00084         if ( (int)auvp.ParamInfo().maxValue < 50 )
00085         {
00086             generatePopUpMenue ();
00087         }
00088     }
00089 
00090 #endif
00091 
00092 }
00093 
00094 
00095 CAUGuiDisplay::~CAUGuiDisplay ()
00096 {
00097     ForeGround = NULL;
00098     BackGround = NULL;
00099     theTexter = NULL;
00100     theUserData = NULL;
00101 
00102     //printf ("dtor CAUGuiDisplay\n");
00103 
00104     if ( popUp != NULL )
00105         ReleaseMenu( popUp );
00106 }
00107 
00108 
00109 void CAUGuiDisplay::generatePopUpMenue ()
00110 {
00111 
00112     MenuItemIndex outNewItem;
00113     
00114     //ControlRef carbonControl = getCarbonControl();
00115 
00116     //SInt32 max = (SInt32) GetControl32BitMaximum(carbonControl);
00117     
00118     CreateNewMenu ( 16383, 0, &popUp );
00119 
00120     SetMenuWidth( popUp, 0 );
00121     SetMenuHeight( popUp, 0 );
00122     
00123     if ( AUVPattached )
00124     {
00125         if ( auvp.HasNamedParams() )
00126         {
00127             for ( int i = 0; i <= Range; i++ )
00128             {
00129                 AppendMenuItemTextWithCFString( popUp, auvp.GetParamName( i ), 0, i+1, &outNewItem );       
00130             }
00131         }
00132         else
00133         {
00134             char text[24];
00135         
00136             if ( theTexter != NULL )
00137             {
00138                 for ( int i = 0; i <= Range; i++ )
00139                 {
00140                     theTexter( i, text, theUserData );
00141                     AppendMenuItemTextWithCFString( popUp,
00142                         CFStringCreateWithCString(NULL, text, kCFStringEncodingISOLatin1 ),
00143                         0, i+1, &outNewItem );
00144                     
00145                 }
00146             
00147             }
00148         
00149         }
00150     }
00151     wantsTrackingFlag = false;
00152 
00153 
00154 }
00155 
00156 
00157 
00158 SInt32 last_X;
00159 SInt32 last_Y;
00160 
00161 
00162 void CAUGuiDisplay::mouseDown(Point *P, bool, bool)
00163 {
00164     ControlRef carbonControl = getCarbonControl();
00165 
00166     SInt32 val = GetControl32BitValue( carbonControl );
00167 
00168     if ( carbonControl != NULL )
00169     {
00170         last_X = P->v;
00171         last_Y = P->h;
00172     }
00173     
00174     if ( popUp != NULL )
00175     {
00176         GetGlobalMouse ( P );
00177     
00178         long result;
00179     
00180         result = PopUpMenuSelect( popUp,  P->v, P->h, val+1 );
00181         
00182         result &= 0xFFFF;
00183                 
00184         if ( result != 0 )
00185         {
00186             SetControl32BitValue ( carbonControl, (UInt32) result - 1 );
00187             if ( userProcedure != NULL )
00188             {
00189                 userProcedure ( val, this, userData );
00190             }
00191 
00192         }
00193     }
00194 
00195     
00196 }
00197 
00198 void CAUGuiDisplay::mouseTrack(Point *P, bool with_option, bool with_shift)
00199 {
00200 
00201     ControlRef carbonControl = getCarbonControl();
00202 
00203     SInt32 max = (SInt32) GetControl32BitMaximum(carbonControl);
00204     SInt32 val = GetControl32BitValue( carbonControl );
00205 
00206     eRect* bounds = getBounds();
00207     
00208     SInt32 precision = 4;
00209     
00210     SInt32 subtle = (SInt32) getResolution ();
00211     
00212     if ( with_shift ) precision = 10;
00213 
00214     SInt32 dx = last_X - P->v;
00215 
00216     if ( carbonControl != NULL )
00217     {   
00218         if ( getResolution () == kCAUGui_res_1 )
00219         {
00220             
00221             precision *= 3;
00222             
00223             if ( dx > precision || dx < -precision )
00224             {
00225             
00226                 if ( dx < 0 )
00227                 {
00228                     val--;
00229                     if ( val < 0 ) val = max;
00230                 }
00231                 else
00232                 {
00233                     val++;
00234                     if ( val > max ) val = 0;
00235                 }
00236                 
00237                 SetControl32BitValue ( carbonControl, (UInt32) val );
00238                 
00239                 last_X -= dx;
00240                 
00241             }
00242         
00243         
00244         }
00245         else
00246         {
00247             
00248             if ( P->h > ( bounds->w / 2 ) ) subtle = 1;
00249                         
00250             if ( dx > precision || dx < -precision )
00251             {
00252                 dx /= precision;
00253                 
00254                 val += dx * subtle;
00255                 
00256                 if ( val > max ) val = max;
00257                 if ( val < 0 ) val = 0;
00258                 
00259                 SetControl32BitValue ( carbonControl, (UInt32) val );
00260                 
00261                 last_X -= dx * precision;
00262             }
00263         
00264         
00265         }
00266     }
00267 
00268 }
00269 
00270 void CAUGuiDisplay::mouseUp(Point *P, bool, bool)
00271 {
00272     // nothing to do here
00273 
00274 
00275 }
00276 
00277 void CAUGuiDisplay::mouseRight(Point *P)
00278 {
00279 
00280     ControlRef carbonControl = getCarbonControl();
00281     
00282     MenuRef ctmenu;
00283     MenuItemIndex outNewItem;
00284     
00285     SetMenuID( ctmenu, 16383 );
00286     SetMenuWidth( ctmenu, 300 );
00287     SetMenuHeight( ctmenu, 300 );
00288     
00289     AppendMenuItemTextWithCFString( ctmenu, CFSTR ("Hello World"), 0, 5, &outNewItem );
00290     /*
00291         MenuRef              inMenu,
00292         CFStringRef          inString,
00293         MenuItemAttributes   inAttributes,
00294         MenuCommand          inCommandID,
00295         MenuItemIndex *      outNewItem)
00296     */
00297     
00298     long result;
00299     
00300     result = PopUpMenuSelect( ctmenu, 0, 0, 0 );
00301 /*
00302         MenuRef   menu,
00303         short     top,
00304         short     left,
00305         short     popUpItem)
00306 */
00307 
00308     printf ( "selected %d\n", (int) result );
00309 
00310 }
00311 
00312 void CAUGuiDisplay::draw(CGContextRef context, UInt32 portHeight )
00313 {
00314 
00315     ControlRef carbonControl = getCarbonControl();
00316     
00317     UInt32 value = 0;
00318     
00319     if ( carbonControl != NULL )
00320         value = GetControl32BitValue( carbonControl );
00321     
00322     CGImageRef theBack = NULL;
00323     CGImageRef theDisplay = NULL;
00324     char text[32];
00325     text[0] = 0;
00326     CGRect bounds;
00327     
00328     getBounds()->to( &bounds, portHeight );
00329         
00330     if ( BackGround != NULL )
00331         theBack = BackGround->getImage();
00332         
00333     if ( ForeGround != NULL )
00334     {
00335         CAUGuiGraphic* current = ForeGround;
00336     
00337         for ( int i = 1; i <= (int)value; i++ ) // maximum inclusive + only when not current
00338         {
00339             if ( current == NULL ) break;
00340             current = (CAUGuiGraphic*)current->getNext();
00341         }
00342         
00343         if ( current != NULL )
00344             theDisplay = current->getImage();
00345         else
00346             printf ( "Shiiet, no Image there!\n" );
00347     }
00348             
00349     if ( theBack != NULL )
00350         CGContextDrawImage( context, bounds, theBack );
00351     else
00352         printf ( "Shiiet, no background Image there!\n" );
00353     
00354     getForeBounds()->to ( &bounds, portHeight );
00355         
00356     if ( theDisplay != NULL )
00357     {
00358         CGContextDrawImage( context, bounds, theDisplay );
00359     }
00360     else
00361     {
00362         if ( hasText )
00363         {
00364             theTexter( value, text, theUserData );
00365         }
00366         else
00367         {       
00368             // generic display
00369             CAAUParameter myParam = getAUVP();
00370                         
00371             switch ( (int)myParam.ParamInfo().unit )
00372             {
00373                 case kAudioUnitParameterUnit_Indexed:
00374                     if ( myParam.HasNamedParams() )
00375                     {
00376                         CFStringGetCString(myParam.GetParamName(value), text, 24, 0);
00377                     }
00378                     else
00379                     {
00380                         sprintf ( text, "%d", (int) myParam.GetValue() );
00381                     }
00382                     break;
00383                 
00384                 case kAudioUnitParameterUnit_Boolean:
00385                     if ( value == 0.f )
00386                         strcpy ( text, "no" );
00387                     else
00388                         strcpy ( text, "yes" );
00389                     break;
00390                     
00391                 default:
00392                     sprintf ( text,  "%.2f", (float) myParam.GetValue() );
00393                     break;
00394             }
00395 
00396         
00397         
00398         }
00399         
00400         CGContextSelectFont ( context, font_name, font_size, kCGEncodingMacRoman );
00401         CGContextSetRGBFillColor( context, col_red, col_green, col_blue, col_alpha );
00402         
00403         
00404         if ( textalign != 0 )
00405         {
00406             CGContextSetTextDrawingMode( context , kCGTextInvisible);
00407             CGContextShowTextAtPoint(context, 0, 0, text, strlen(text));
00408             CGPoint pt = CGContextGetTextPosition(context);
00409             
00410             if ( textalign == 1 )
00411             {
00412                 // center
00413                 bounds.origin.x += bounds.size.width / 2 - pt.x / 2;
00414             }
00415             else
00416             {
00417                 // right
00418                 bounds.origin.x += bounds.size.width - pt.x;
00419             
00420             }
00421         }
00422         CGContextSetTextDrawingMode ( context, kCGTextFill );
00423         CGContextShowTextAtPoint(context, bounds.origin.x, bounds.origin.y, text, strlen (text) );
00424     
00425     }
00426     
00427 }
00428 
00429 
00430 
00431 void CAUGuiDisplay::setUserProcedure ( displayUserProcedure theProc, void* theUserData )
00432 {
00433     userProcedure = theProc;
00434     userData = theUserData;
00435 }
00436 
00437 
00438 
00439 
00440 

(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