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

CAUGuiSelector.cpp

Go to the documentation of this file.
00001 /*
00002  *  CAUGuiSelector.cpp
00003  *  CAUGuiDemo
00004  *
00005  *  Created by Urs Heckmann on Fri Dec 13 2002.
00006  *  Copyright (c) 2002 __MyCompanyName__. All rights reserved.
00007  *
00008  */
00009 
00010 #include "CAUGuiSelector.h"
00011 
00012 #include "CAUGuiMoreImages.h"
00013 
00014 CAUGuiSelector::CAUGuiSelector (    CAUGuiMan*          theChief,
00015                             
00016                             eRect*              theWhere,
00017                             UInt32              theRange, 
00018                             UInt32              theOrientation,
00019                             CAUGuiGraphic*      theForeGround, 
00020                             CAUGuiGraphic*      theBackground)
00021                         
00022                         :   CAUGuiCtrl ( theChief, theWhere, theRange )
00023                             
00024 {
00025         
00026     ForeGround = theForeGround;
00027     BackGround = theBackground;
00028     
00029     orientation = theOrientation;
00030     
00031     userProcedure = NULL;
00032     userData = NULL;
00033     
00034     if ( theWhere->w == 0 )
00035     {
00036         if ( BackGround != NULL )
00037         {
00038             theWhere->w = BackGround->getWidth();
00039             setBounds(theWhere); 
00040         }
00041     
00042     }
00043     
00044     if ( theWhere->h == 0 )
00045     {
00046         if ( BackGround != NULL )
00047         {
00048             theWhere->h = BackGround->getHeight();
00049             setBounds(theWhere);
00050         }
00051     
00052     }
00053         
00054     setType( kCAUGui_Selector );
00055     
00056     setTolerance ( 0 );
00057     
00058 }
00059 
00060 CAUGuiSelector::~CAUGuiSelector ()
00061 {
00062 
00063     ForeGround = NULL;
00064     BackGround = NULL;
00065 
00066 
00067 }
00068 
00069 void CAUGuiSelector::draw(CGContextRef context, UInt32 portHeight )
00070 {
00071     ControlRef carbonControl = getCarbonControl();
00072     
00073     UInt32 max = GetControl32BitMaximum(carbonControl);
00074     UInt32 val = GetControl32BitValue( carbonControl );
00075     
00076     CGImageRef theBack = NULL;
00077     
00078     CGRect bounds;
00079     
00080     getBounds()->to( &bounds, portHeight );
00081     
00082     if ( BackGround != NULL )
00083         theBack = BackGround->getImage();
00084     
00085                 
00086     if ( theBack != NULL )
00087         CGContextDrawImage( context, bounds, theBack );
00088     
00089     if ( ForeGround != NULL )
00090     {
00091         float valNorm = (float) val / (float)( max - 1 );
00092         
00093         if ( valNorm >= 1.f ) valNorm = 1.f;
00094             
00095         ForeGround->draw ( context, portHeight, getForeBounds(), valNorm );
00096     }
00097 }
00098 
00099 
00100 
00101 void CAUGuiSelector::mouseDown(Point *P, bool with_option, bool with_shift)
00102 {
00103 
00104     ControlRef carbonControl = getCarbonControl();
00105 
00106     SInt32 max = (SInt32) GetControl32BitMaximum(carbonControl);
00107 
00108     SInt32 val = -1;
00109 
00110     eRect fore;
00111     fore.set( getForeBounds() );
00112     
00113     eRect back;
00114     back.set( getBounds() );
00115     
00116     SInt32 o_X = fore.x - back.x;
00117     SInt32 o_Y = fore.y - back.y;
00118 
00119 
00120     float s = 0.f;
00121 
00122     val = (SInt32) GetControl32BitValue( carbonControl );
00123 
00124     if ( orientation != 0 ) // horizontal mode
00125     {
00126         s = (float)(P->h - o_X) / (float)fore.w;
00127         val = (SInt32)( s * (float) max );
00128     }
00129     else    // vertical mode
00130     {
00131         s = (float)(P->v - o_Y) / (float)fore.h;
00132         val = (SInt32)( s * (float) max );
00133     }
00134 
00135     
00136     if ( val > max ) val = max;
00137     if ( val < 0 ) val = 0;
00138     SetControl32BitValue ( carbonControl, (UInt32) val );
00139 
00140     //printf ( "selector says: val %d, s %f, max %f\n", (int)val, s, (float) max );
00141     
00142     if ( userProcedure != NULL )
00143     {
00144         userProcedure ( val, this, userData );
00145     
00146     }
00147 
00148 
00149 }
00150 
00151 void CAUGuiSelector::mouseTrack(Point *P, bool with_option, bool with_shift)
00152 {
00153 
00154         
00155 }
00156 
00157 void CAUGuiSelector::mouseUp(Point *P, bool with_option, bool with_shift)
00158 {
00159 
00160 }
00161 
00162 
00163 void CAUGuiSelector::setUserProcedure ( selectorUserProcedure theProc, void* theUserData )
00164 {
00165     userProcedure = theProc;
00166     userData = theUserData;
00167 }

(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