00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "CAUGuiSlider.h"
00011
00012 #include "CAUGuiMoreImages.h"
00013
00014 CAUGuiSlider::CAUGuiSlider ( CAUGuiMan* theChief,
00015 CAAUParameter &theAuvp,
00016 eRect* theWhere,
00017 UInt32 theOrientation,
00018 CAUGuiResolution theRes,
00019 CAUGuiGraphic* theForeGround,
00020 CAUGuiGraphic* theBackground)
00021
00022 : CAUGuiCtrl ( theChief, theAuvp, theWhere, theRes )
00023
00024 {
00025
00026 ForeGround = theForeGround;
00027 BackGround = theBackground;
00028
00029 orientation = theOrientation;
00030
00031 if ( theWhere->w == 0 )
00032 {
00033 if ( BackGround != NULL )
00034 {
00035 theWhere->w = BackGround->getWidth();
00036 setBounds(theWhere);
00037 }
00038 else
00039 {
00040 if ( theForeGround != NULL )
00041 {
00042 theWhere->w = theForeGround->getWidth();
00043 setBounds(theWhere);
00044 }
00045
00046 }
00047
00048 }
00049
00050 if ( theWhere->h == 0 )
00051 {
00052 if ( BackGround != NULL )
00053 {
00054 theWhere->h = BackGround->getHeight();
00055 setBounds(theWhere);
00056 }
00057 else
00058 {
00059 if ( theForeGround != NULL )
00060 {
00061 theWhere->h = theForeGround->getHeight();
00062 setBounds(theWhere);
00063 }
00064
00065 }
00066
00067 }
00068
00069 setType( kCAUGui_Slider );
00070
00071 setTolerance ( (SInt32) theRes );
00072
00073
00074
00075 }
00076
00077 CAUGuiSlider::~CAUGuiSlider ()
00078 {
00079
00080 ForeGround = NULL;
00081 BackGround = NULL;
00082
00083
00084
00085
00086
00087 }
00088
00089 void CAUGuiSlider::draw(CGContextRef context, UInt32 portHeight )
00090 {
00091 ControlRef carbonControl = getCarbonControl();
00092
00093 UInt32 max = GetControl32BitMaximum(carbonControl);
00094 UInt32 val = GetControl32BitValue( carbonControl );
00095
00096 CGImageRef theBack = NULL;
00097
00098 CGRect bounds;
00099
00100 getBounds()->to( &bounds, portHeight );
00101
00102 if ( BackGround != NULL )
00103 theBack = BackGround->getImage();
00104
00105
00106 if ( theBack != NULL )
00107 CGContextDrawImage( context, bounds, theBack );
00108
00109 if ( ForeGround != NULL )
00110 {
00111 float valNorm = (float) val / (float) max;
00112
00113 ForeGround->draw ( context, portHeight, getForeBounds(), valNorm );
00114 }
00115 }
00116
00117 SInt32 sldr_X;
00118 SInt32 sldr_Y;
00119
00120 void CAUGuiSlider::mouseDown(Point *P, bool with_option, bool with_shift)
00121 {
00122
00123 sldr_X = P->h;
00124 sldr_Y = P->v;
00125
00126 if ( !with_shift )
00127 mouseTrack ( P, with_option, with_shift );
00128
00129 }
00130
00131 void CAUGuiSlider::mouseTrack(Point *P, bool with_option, bool with_shift)
00132 {
00133
00134 ControlRef carbonControl = getCarbonControl();
00135
00136 SInt32 max = (SInt32) GetControl32BitMaximum(carbonControl);
00137
00138 SInt32 val = -1;
00139
00140 eRect fore;
00141 fore.set( getForeBounds() );
00142
00143 eRect back;
00144 back.set( getBounds() );
00145
00146 SInt32 o_X = fore.x - back.x;
00147 SInt32 o_Y = fore.y - back.y;
00148
00149
00150
00151
00152
00153 if ( !with_shift )
00154 {
00155 SInt32 max_X = fore.w + o_X;
00156 SInt32 max_Y = fore.h + o_Y;
00157
00158 if ( orientation != 0 )
00159 {
00160 if ( P->h <= o_X ) val = 0;
00161 if ( P->h >= max_X ) val = max;
00162 if ( val == -1 )
00163 {
00164 float fract = (float)(P->h - o_X) / (float)fore.w;
00165 val = (SInt32)((float)max * fract);
00166 }
00167 }
00168 else
00169 {
00170 if ( P->v >= max_Y ) val = 0;
00171 if ( P->v <= o_Y ) val = max;
00172 if ( val == -1 )
00173 {
00174 float fract = (float)(P->v - o_Y) / (float)fore.h;
00175 val = (SInt32)((float)max * (1.f - fract));
00176 }
00177 }
00178 }
00179 else
00180 {
00181 val = (SInt32) GetControl32BitValue( carbonControl );
00182
00183 if ( orientation != 0 )
00184 {
00185
00186 SInt32 diff = P->h - sldr_X;
00187
00188 if ( diff < -1 || diff > 1 )
00189 {
00190 diff /= 2;
00191 val += diff;
00192 sldr_X += diff * 2;
00193 }
00194 }
00195 else
00196 {
00197 SInt32 diff = sldr_Y - P->v;
00198
00199 if ( diff < -1 || diff > 1 )
00200 {
00201 diff /= 2;
00202 val += diff;
00203 sldr_Y -= diff * 2;
00204 }
00205 }
00206
00207
00208
00209 }
00210
00211 if ( val > max ) val = max;
00212 if ( val < 0 ) val = 0;
00213 SetControl32BitValue ( carbonControl, (UInt32) val );
00214
00215
00216 }
00217
00218 void CAUGuiSlider::mouseUp(Point *P, bool with_option, bool with_shift)
00219 {
00220 mouseTrack ( P, with_option, with_shift );
00221 }
00222
00223
00224