00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "CAUGuiMeter.h"
00011
00012 CAUGuiMeter::CAUGuiMeter ( CAUGuiMan* theChief,
00013 UInt32 internalIndex,
00014 eRect* theWhere,
00015 CAUGuiResolution theRes,
00016 CAUGuiGraphic* theForeGround,
00017 CAUGuiGraphic* theBackground)
00018
00019 : CAUGuiCtrl ( theChief, theWhere, theRes )
00020
00021 {
00022
00023 ForeGround = theForeGround;
00024 BackGround = theBackground;
00025 internalParamIndex = internalIndex;
00026 setType ( kCAUGui_Meter );
00027
00028 }
00029
00030
00031
00032 CAUGuiMeter::~CAUGuiMeter ()
00033 {
00034 ForeGround = NULL;
00035 BackGround = NULL;
00036
00037 }
00038
00039 void CAUGuiMeter::idle()
00040 {
00041 float fValue = Chief->getInternalParameter ( internalParamIndex );
00042
00043
00044
00045 if ( fValue > 1.f ) fValue = 1.f;
00046 if ( fValue < 0.f ) fValue = 0.f;
00047
00048 ControlRef carbonControl = getCarbonControl();
00049
00050 if ( carbonControl != NULL )
00051 {
00052 UInt32 max = GetControl32BitMaximum(carbonControl);
00053 UInt32 val = (UInt32)((float)max * fValue );
00054 SetControl32BitValue ( carbonControl, val );
00055 }
00056
00057
00058
00059 CAUGuiCtrl::idle();
00060 }
00061
00062 void CAUGuiMeter::draw(CGContextRef context, UInt32 portHeight )
00063 {
00064 ControlRef carbonControl = getCarbonControl();
00065
00066 UInt32 max = GetControl32BitMaximum(carbonControl);
00067 UInt32 val = GetControl32BitValue( carbonControl );
00068
00069 CGImageRef theBack = NULL;
00070
00071 CGRect bounds;
00072
00073 getBounds()->to( &bounds, portHeight );
00074
00075 if ( BackGround != NULL )
00076 theBack = BackGround->getImage();
00077
00078 if ( theBack != NULL )
00079 CGContextDrawImage( context, bounds, theBack );
00080
00081
00082 if ( ForeGround != NULL )
00083 {
00084 float valNorm = (float) val / (float) max;
00085
00086 ForeGround->draw ( context, portHeight, getForeBounds(), valNorm );
00087
00088 }
00089 }
00090