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

CAUGuiMoreImages.cpp

Go to the documentation of this file.
00001 /*
00002  *  CAUGuiMoreImages.cpp
00003  *  CoreGraphics AudioUnit GUI framework
00004  *
00005  *  Created by Urs Heckmann on Sun Nov 03 2002.
00006  *  Copyright (c) 2002 __MyCompanyName__. All rights reserved.
00007  *
00008  */
00009 
00010 #include "CAUGuiMoreImages.h"
00011 
00012 CAUGuiSpinImage::CAUGuiSpinImage (
00013                                     char* pngFileName,
00014                                     float min,
00015                                     float max,
00016                                     SInt32 pivotOffsetX,
00017                                     SInt32 pivotOffsetY,
00018                                     bool fixed
00019                                 )
00020                                 :   CAUGuiGraphic ( pngFileName )
00021 {
00022 
00023     this->startRad = -2.0 * PI * min;
00024     this->allRad = 2.0 * PI * max + startRad;
00025     
00026     
00027     
00028     pivotX = 0.5 + (float)pivotOffsetX / (float)getWidth();
00029     pivotY = 0.5 + (float)pivotOffsetY / (float)getHeight();
00030 
00031     //printf ( "x = %f  y = %f \n", pivotX, pivotY );
00032 
00033     imageOrientationFixed = fixed;
00034     
00035     setType ( kCAUGui_SpinImage );
00036 
00037 
00038 }
00039     
00040 void CAUGuiSpinImage::draw( CGContextRef context, UInt32 portHeight, eRect* rect, float value )
00041 {
00042 
00043     CGRect bounds;
00044     
00045     rect->to( &bounds, portHeight );
00046     
00047     
00048     CGContextTranslateCTM( context, bounds.origin.x + bounds.size.width * pivotX, bounds.origin.y + bounds.size.height * pivotY);
00049         
00050     bounds.origin.x = -bounds.size.width/2;
00051     bounds.origin.y = -bounds.size.height/2;
00052         
00053     float angle;
00054         
00055     angle = value * allRad - startRad;
00056                 
00057     CGContextRotateCTM( context, -angle );
00058         
00059     CGContextTranslateCTM( context, bounds.size.width * ( 0.5f - pivotX ), bounds.size.height * ( pivotY - 0.5f ));
00060         
00061     if ( imageOrientationFixed )
00062         CGContextRotateCTM( context, angle );
00063         
00064     if ( getImage() != NULL )
00065     {
00066             CGContextDrawImage( context, bounds, getImage() );
00067     }
00068 
00069     
00070 }
00071 
00072 void CAUGuiSpinImage::draw( CGContextRef context, UInt32 portHeight, eRect* rect, float value, SInt32 pivotOffsetX, SInt32 pivotOffsetY )
00073 {
00074 
00075     CGRect bounds;
00076     
00077     rect->to( &bounds, portHeight );
00078     
00079     
00080     CGContextTranslateCTM( context, bounds.origin.x + bounds.size.width/2 + pivotOffsetX, bounds.origin.y + bounds.size.height/2 - pivotOffsetY);
00081         
00082     bounds.origin.x = -bounds.size.width/2;
00083     bounds.origin.y = -bounds.size.height/2;
00084         
00085     float angle;
00086         
00087     angle = value * allRad - startRad;
00088                 
00089     CGContextRotateCTM( context, -angle );
00090         
00091     CGContextTranslateCTM( context, -pivotOffsetX, pivotOffsetY);
00092         
00093     if ( imageOrientationFixed )
00094         CGContextRotateCTM( context, angle );
00095         
00096     if ( getImage() != NULL )
00097     {
00098             CGContextDrawImage( context, bounds, getImage() );
00099     }
00100 
00101 
00102 }
00103 
00104 
00105 
00106 
00107 CAUGuiHandleImage::CAUGuiHandleImage (
00108                                     char* pngFileName,
00109                                     SInt32 pivotOffsetX, 
00110                                     SInt32 pivotOffsetY 
00111                                 )
00112                                 :   CAUGuiGraphic ( pngFileName )
00113 {
00114 
00115     pivotX = pivotOffsetX;
00116     pivotY = pivotOffsetY;
00117 
00118 
00119 }
00120     
00121 void CAUGuiHandleImage::draw( CGContextRef context, UInt32 portHeight, eRect* rect, float value )
00122 {
00123 
00124     CGRect bounds;
00125     SInt32 offset;
00126     
00127     eRect fore;
00128     
00129     fore.set( rect );
00130     
00131     float scaleY = (float)fore.w  / (float)getWidth();
00132     float scaleX = (float)fore.h  / (float)getHeight();
00133     
00134     if ( getImage() != NULL )
00135     {
00136 
00137         if ( scaleX > scaleY )
00138         {
00139         
00140             SInt32 height = (SInt32)((float)getHeight() * scaleY );
00141         
00142             offset = (SInt32)((float)fore.h * (1.f - value)) - height/2 - pivotY;
00143             
00144             fore.offset ( -pivotX, offset );
00145             
00146             fore.h = height;
00147                         
00148         }
00149         else
00150         {
00151             SInt32 width = (SInt32)((float)getWidth() * scaleX );
00152         
00153             offset = (SInt32)((float)fore.w * value) - width/2 + pivotX;
00154             
00155             fore.offset ( offset, -pivotY );
00156             
00157             fore.w = width;
00158     
00159         }
00160         
00161         fore.to( &bounds, portHeight );
00162             
00163         CGContextDrawImage( context, bounds, getImage() );
00164     }
00165     
00166 }
00167 
00168 CAUGuiCroppingImage::CAUGuiCroppingImage (
00169                                     char* pngFileName,
00170                                     SInt32 pivotOffsetX, 
00171                                     SInt32 pivotOffsetY,
00172                                     SInt32 theOrientation,
00173                                     UInt32 theMode
00174                                 )
00175                                 :   CAUGuiGraphic ( pngFileName )
00176 {
00177 
00178     if ( theOrientation == 0 )
00179         theOrientation = 2; // default: vertical from top
00180         
00181     pivotX = pivotOffsetX;
00182     pivotY = pivotOffsetY;
00183     orientation = theOrientation;
00184     mode = theMode;
00185 
00186 
00187 }
00188     
00189 void CAUGuiCroppingImage::draw( CGContextRef context, UInt32 portHeight, eRect* rect, float value )
00190 {
00191 
00192     CGRect bounds;
00193     
00194     eRect fore;
00195     
00196     fore.set( rect );
00197     
00198     float sPivotX = ((float)fore.w  / (float)getWidth()) * (float)(getWidth()/2 + pivotX);
00199     float sPivotY = ((float)fore.h  / (float)getHeight()) * (float)(getHeight()/2 + pivotY);
00200     
00201     if ( getImage() != NULL )
00202     {
00203     
00204         switch ( mode )
00205         {
00206             case 1: // Shifting
00207             {
00208                 fore.to( &bounds, portHeight );
00209                 
00210                 CGContextSaveGState( context );
00211                 
00212                 CGContextClipToRect( context, bounds);
00213             
00214             
00215                 value = 1.f - value;
00216         
00217                 SInt32 shift_h = 0;
00218                 SInt32 shift_v = 0;
00219         
00220                 switch ( orientation & 5 )
00221                 {
00222                     case 1:
00223                             shift_h = (SInt32)(-value * (float)fore.w);
00224                             break;
00225                     case 4:
00226                             shift_h = (SInt32)(value * (float)fore.w);
00227                             break;
00228                 }
00229                 
00230                 switch ( orientation & 10 )
00231                 {
00232                     case 2:
00233                             shift_v = (SInt32)(value * (float)fore.h);
00234                             break;
00235                     case 8:
00236                             shift_v = (SInt32)(-value * (float)fore.h);
00237                             break;
00238                 }
00239         
00240                 fore.offset ( shift_h, shift_v );
00241                                 
00242                 fore.to( &bounds, portHeight );
00243             
00244                 CGContextDrawImage( context, bounds, getImage() );
00245                 
00246                 CGContextRestoreGState( context );
00247                 
00248                 break;
00249             }
00250             
00251             case 2: // Scaling
00252             {
00253                 value = 1.f - value;
00254         
00255                 if ( (orientation & 1) == 1 && sPivotX > 0.f )
00256                 {
00257                     fore.grow ( -(int)(sPivotX * value), 0, 0, 0 );
00258                 }
00259             
00260                 if ( (orientation & 2) == 2  && sPivotY > 0.f )
00261                 {
00262                     fore.grow ( 0, -(int)(sPivotY * value), 0, 0 );
00263                 }
00264             
00265                 if ( (orientation & 4) == 4  && sPivotX < (float)fore.w )
00266                 {
00267                     fore.grow ( 0, 0, -(int)((sPivotX - (float)fore.w ) * value), 0 );
00268                 }
00269             
00270                 if ( (orientation & 8) == 8  && sPivotY < (float)fore.h )
00271                 {
00272                     fore.grow ( 0, 0, 0, -(int)((sPivotY - (float)fore.h) * value) );
00273                 }
00274                 fore.to( &bounds, portHeight );
00275             
00276                 CGContextDrawImage( context, bounds, getImage() );
00277                 
00278                 break;
00279             }
00280             
00281             default: // Cropping
00282             {
00283                 value = 1.f - value;
00284         
00285                 if ( (orientation & 1) == 1 && sPivotX > 0.f )
00286                 {
00287                     fore.grow ( -(int)(sPivotX * value), 0, 0, 0 );
00288                 }
00289             
00290                 if ( (orientation & 2) == 2  && sPivotY > 0.f )
00291                 {
00292                     fore.grow ( 0, -(int)(sPivotY * value), 0, 0 );
00293                 }
00294             
00295                 if ( (orientation & 4) == 4  && sPivotX < (float)fore.w )
00296                 {
00297                     fore.grow ( 0, 0, -(int)((sPivotX - (float)fore.w ) * value), 0 );
00298                 }
00299             
00300                 if ( (orientation & 8) == 8  && sPivotY < (float)fore.h )
00301                 {
00302                     fore.grow ( 0, 0, 0, -(int)((sPivotY - (float)fore.h) * value) );
00303                 }
00304                 
00305                 fore.to( &bounds, portHeight );
00306                 
00307                 CGContextSaveGState( context );
00308                 
00309                 CGContextClipToRect( context, bounds);
00310                                 
00311                 rect->to( &bounds, portHeight );
00312             
00313                 CGContextDrawImage( context, bounds, getImage() );
00314                 
00315                 CGContextRestoreGState( context );
00316                 
00317                 break;
00318             }
00319         }       
00320     }
00321 }
00322 
00323 
00324 
00325 

(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