src/gui/controlgrab.cpp

Go to the documentation of this file.
00001 #include <sstream>
00002 #include "keyman.h"
00003 #include "controls.h"
00004 #include "globals.h"
00005 #include "gui/controlgrab.h"
00006 using namespace VGUI;
00007 
00008 ControlGrab::ControlGrab( Widget* w )
00009 {
00010         setting = "";
00011         center = w->GetCenter();
00012         name = w->GetName();
00013         text = w->GetText();
00014         type = w->GetType();
00015         tip = w->GetTip();
00016         rel_width = w->GetRelWidth();
00017         rel_height = w->GetRelHeight();
00018         enabled = w->GetEnabled();
00019         selected = w->GetSelected();
00020         is_default = w->GetDefault();
00021         is_cancel = w->GetCancel();
00022         has_icon = w->GetHasIcon();
00023         width_auto = w->GetWidthAuto();
00024         height_auto = w->GetHeightAuto();
00025         font_size = w->GetFontSize();
00026         color_r = w->GetColorR();
00027         color_g = w->GetColorG();
00028         color_b = w->GetColorB();
00029         spacing = 0.3;
00030         selected_icon = 0;
00031         pressed_icon = clicked_icon = 10000;
00032         only_one = false;
00033 
00034         string skin_path = settings.GetSkinPath();
00035         add_tex.Load( skin_path + "/textures/widgets/controls/add.png", false );
00036         add_tex_sel.Load( skin_path + "/textures/widgets/controls/add_sel.png", false );
00037         key_tex.Load( skin_path + "/textures/widgets/controls/key.png", false );
00038         key_tex_x.Load( skin_path + "/textures/widgets/controls/key_x.png", false );
00039         joy_axis_tex.Load( skin_path + "/textures/widgets/controls/joy_axis.png", false );
00040         joy_axis_tex_x.Load( skin_path + "/textures/widgets/controls/joy_axis_x.png", false );
00041         joy_btn_tex.Load( skin_path + "/textures/widgets/controls/joy_btn.png", false );
00042         joy_btn_tex_x.Load( skin_path + "/textures/widgets/controls/joy_btn_x.png", false );
00043         mouse_btn_tex.Load( skin_path + "/textures/widgets/controls/mouse.png", false );
00044         mouse_btn_tex_x.Load( skin_path + "/textures/widgets/controls/mouse_x.png", false );
00045         mouse_move_tex.Load( skin_path + "/textures/widgets/controls/mouse.png", false );
00046         mouse_move_tex_x.Load( skin_path + "/textures/widgets/controls/mouse_x.png", false );
00047 /*
00048         tex_width = 0.0277;
00049         tex_height = 0.0370;
00050 */
00051         // width = dist from left of text to wheel + width of wheel + texture width
00052         if( width_auto )
00053         {
00054                 rel_width = spacing + ( 0.03 * 3 );
00055         }
00056 
00057         // height = button texture height
00058         if( height_auto )
00059         {
00060                 rel_height = 0.04;
00061         }
00062         
00063         analog=adding=l_down=r_down=mbtn_down = false;
00064 }
00065 
00066 ControlGrab::~ControlGrab()
00067 {
00068 }
00069 
00070 void ControlGrab::BuildControlVectors()
00071 {
00072         local_controls.clear();
00073         for( gamecontrols.ControlIteratorReset(); gamecontrols.ControlIteratorGetControl() != NULL; gamecontrols.ControlIteratorIncrement() )
00074         {
00075                 ControlSet ctrl_set;
00076                 CONTROL & ctrls = *(gamecontrols.ControlIteratorGetControl());
00077                 CONTROL new_ctrl;
00078                 TEXTURE_HANDLE * icon_tex, * icon_tex_x;
00079                 icon_tex = &key_tex;
00080                 icon_tex_x = &key_tex_x;
00081                 std::ostringstream ctrl_desc;
00082 
00083                 if( ctrls.GetName() == setting )
00084                 {
00085                         new_ctrl.SetName( setting );
00086 
00087                         if( ctrls.GetType() == Joy )
00088                         {
00089                                 int joy_idx = ctrls.GetJoyNum();
00090 
00091                                 std::ostringstream joy_desc;
00092                                 ctrl_desc << "Joy" << joy_idx;
00093 
00094                                 new_ctrl.SetType( "joy" );
00095                                 new_ctrl.SetJoyNum( joy_idx );
00096 
00097                                 if( ctrls.GetJoyType() == Axis )
00098                                 {
00099                                         string joy_type;
00100                                         int joy_axis = ctrls.GetJoyAxis();
00101 
00102                                         new_ctrl.SetJoyType( "axis" );
00103                                         new_ctrl.SetJoyAxis( joy_axis );
00104 
00105                                         if( ctrls.GetJoyAxisType() == Positive )
00106                                         {
00107                                                 joy_type = "(+)";
00108                                                 new_ctrl.SetJoyAxisType( Positive );
00109                                         }
00110                                         else
00111                                         {
00112                                                 joy_type = "(-)";
00113                                                 new_ctrl.SetJoyAxisType( Negative );
00114                                         }
00115 
00116                                         ctrl_desc << " Axis" << joy_axis << " " << joy_type;
00117                                         icon_tex = &joy_axis_tex;
00118                                         icon_tex_x = &joy_axis_tex_x;
00119                                 }
00120                                 else if( ctrls.GetJoyType() == Button )
00121                                 {
00122                                         string joy_once, joy_btnup;
00123                                         int joy_btn = ctrls.GetJoyButton();
00124 
00125                                         new_ctrl.SetJoyType( "button" );
00126                                         new_ctrl.SetJoyButton( joy_btn );
00127 
00128                                         if( ctrls.GetOneTime() )
00129                                         {
00130                                                 joy_once = "(once)";
00131                                                 new_ctrl.SetOneTime( true );
00132                                         }
00133                                         else
00134                                         {
00135                                                 joy_once = "(held)";
00136                                                 new_ctrl.SetOneTime( false );
00137                                         }
00138                                         
00139                                         if( ctrls.GetJoyPushDown() )
00140                                         {
00141                                                 joy_btnup = "press";
00142                                                 new_ctrl.SetJoyPushDown( true );
00143                                         }
00144                                         else
00145                                         {
00146                                                 joy_btnup = "release";
00147                                                 new_ctrl.SetJoyPushDown( false );
00148                                         }
00149 
00150                                         ctrl_desc << " Btn" << joy_btn << " " << joy_btnup << " " << joy_once;
00151                                         icon_tex = &joy_btn_tex;
00152                                         icon_tex_x = &joy_btn_tex_x;
00153                                 }
00154                         }
00155                         else if( ctrls.GetType() == Key )
00156                         {
00157                                 int key_code = ctrls.GetKeyCode();
00158                                 ctrl_desc << "Key " << keyman.GetKeyName( (int)key_code ) << " ";
00159 
00160                                 new_ctrl.SetType( "key" );
00161                                 new_ctrl.SetKeyCode( key_code );
00162 
00163                                 if( ctrls.GetKeyPushDown() )
00164                                 {
00165                                         ctrl_desc << "press";
00166                                         new_ctrl.SetKeyPushDown( true );
00167                                 }
00168                                 else
00169                                 {
00170                                         ctrl_desc << "release";
00171                                         new_ctrl.SetKeyPushDown( false );
00172                                 }
00173                                 if( ctrls.GetOneTime() )
00174                                 {
00175                                         ctrl_desc << " (once)";
00176                                         new_ctrl.SetOneTime( true );
00177                                 }
00178                                 else
00179                                 {
00180                                         ctrl_desc << " (held)";
00181                                         new_ctrl.SetOneTime( false );
00182                                 }
00183                                 
00184                                 icon_tex = &key_tex;
00185                                 icon_tex_x = &key_tex_x;
00186                         }
00187                         else if( ctrls.GetType() == Mouse )
00188                         {
00189                                 ctrl_desc << "Mouse";
00190                                 new_ctrl.SetType( "mouse" );
00191                                 if( ctrls.GetMouseType() == MButton )
00192                                 {
00193                                         new_ctrl.SetMouseType( "button" );
00194                                         int mbtn = ctrls.GetMouseButton();
00195                                         new_ctrl.SetMouseButton( mbtn );
00196                                         ctrl_desc << " button " << mbtn << " ";
00197 
00198                                         if( ctrls.GetMousePushDown() )
00199                                         {
00200                                                 ctrl_desc << "press";
00201                                                 new_ctrl.SetMousePushDown( true );
00202                                         }
00203                                         else
00204                                         {
00205                                                 ctrl_desc << "release";
00206                                                 new_ctrl.SetMousePushDown( false );
00207                                         }
00208                                         if( ctrls.GetOneTime() )
00209                                         {
00210                                                 ctrl_desc << " (once)";
00211                                                 new_ctrl.SetOneTime( true );
00212                                         }
00213                                         else
00214                                         {
00215                                                 ctrl_desc << " (held)";
00216                                                 new_ctrl.SetOneTime( false );
00217                                         }
00218 
00219                                         icon_tex = &mouse_btn_tex;
00220                                         icon_tex_x = &mouse_btn_tex_x;
00221                                 }
00222                                 else if( ctrls.GetMouseType() == Motion )
00223                                 {
00224                                         new_ctrl.SetMouseType( "motion" );
00225                                         ctrl_desc << " move";
00226                                         string mdir;
00227                                         switch( ctrls.GetMouseDirection() )
00228                                         {
00229                                         case Up:
00230                                                 mdir = "up";
00231                                                 break;
00232                                         case Down:
00233                                                 mdir = "down";
00234                                                 break;
00235                                         case Left:
00236                                                 mdir = "left";
00237                                                 break;
00238                                         case Right:
00239                                                 mdir = "right";
00240                                                 break;
00241                                         default:
00242                                                 mdir = "error!";
00243                                                 break;
00244                                         }
00245                                         ctrl_desc << " " << mdir;
00246                                         new_ctrl.SetMouseDirection( mdir );
00247 
00248                                         icon_tex = &mouse_move_tex;
00249                                         icon_tex_x = &mouse_move_tex_x;
00250                                 }
00251                         }
00252                         ctrl_set.SetTex( icon_tex );
00253                         ctrl_set.SetTexX( icon_tex_x );
00254                         ctrl_set.SetName( ctrl_desc.str() );
00255                         ctrl_set.SetControl( new_ctrl );
00256 
00257                         local_controls.push_back( ctrl_set );
00258                 }
00259         }               
00260 }
00261 
00262 void ControlGrab::SetSpacing( float new_spacing )
00263 {
00264         spacing = new_spacing;
00265         if( width_auto )
00266         {
00267                 rel_width = spacing + 0.03 * 3;
00268         }
00269 }
00270 
00271 void ControlGrab::Save()
00272 {
00273         gamecontrols.DeleteControlsWithAction( setting );
00274 
00275         for( unsigned int i = 0; i < local_controls.size(); i++ )
00276         {
00277                 gamecontrols.AddControl( local_controls[i].GetControl() );
00278         }
00279 }
00280 
00281 void ControlGrab::ResetValue()
00282 {
00283         BuildControlVectors();
00284 }
00285 
00286 void ControlGrab::Draw()
00287 {
00288         Draw( 1.0 );
00289 }
00290 
00291 void ControlGrab::Draw( float opacity )
00292 {
00293         float center_x = center.GetXPercent();
00294         float center_y = center.GetYPercent();
00295         float rel_width_half = rel_width / 2.0f;
00296         float rel_height_half = 0.0370 / 2.0f;
00297         float opacity_txt = selected ? 0.9 : enabled ? 0.75 : 0.4;
00298         unsigned int i = 0;
00299         TEXTURE_HANDLE * cur_tex;
00300         TEXTURE_HANDLE * add_icon_tex = selected && ( 0 == selected_icon ) ? &add_tex_sel : &add_tex;
00301 
00302         // draw the add control button
00303         utility.DrawButton( center_x - rel_width_half + spacing,
00304                             center_y - rel_height_half,
00305                             center_x - rel_width_half + spacing,
00306                             center_y + rel_height_half,
00307                             0.0138888, add_icon_tex, opacity * opacity_txt );
00308 
00309         // draw the individual controls' icons
00310         for( i = 0; i < local_controls.size(); i++ )
00311         {
00312                 cur_tex = selected && ( ( i + 1 ) == selected_icon ) ?
00313                           local_controls[i].GetTexX() :
00314                           local_controls[i].GetTex();
00315 
00316                 utility.DrawButton( center_x - rel_width_half + spacing + ( ( i + 1 ) * 0.03 ),
00317                                     center_y - rel_height_half,
00318                                     center_x - rel_width_half + spacing + ( ( i + 1 ) * 0.03 ),
00319                                     center_y + rel_height_half,
00320                                     0.0138888, cur_tex, opacity * opacity_txt );
00321         }
00322 
00323         // draw text
00324         font.Print( center_x - rel_width_half,
00325                     center_y - ( font.Height( text.c_str(), 1, font_size ) / 2.0f ),
00326                     text.c_str(), 1, font_size, color_r, color_g, color_b, opacity_txt * opacity );
00327 
00328         if( selected )
00329         {
00330                 if( adding )
00331                 {
00332                         // when a user wants to add a control to this action, put a message
00333                         // at the bottom of the screen reminding them to give their input
00334                         string t1 = "Enter the input you wish to bind to " + text + ".";
00335                         string t2 = "Press Escape to cancel.";
00336                         float w1 = 0.5 - ( font.Width( t1.c_str(), 1, 6 ) / 2.0f );
00337                         float w2 = 0.5 - ( font.Width( t2.c_str(), 1, 6 ) / 2.0f );
00338                         font.Print( w1, 0.90, t1.c_str(), 1, 6, 0.0, 0.8, 0.0, 0.9 );
00339                         font.Print( w2, 0.925, t2.c_str(), 1, 6, 1.0, 0.0, 0.0, 0.9 );
00340                 }
00341                 else
00342                 {
00343                         // draw this controlgrab's tip
00344                         if( tip != "" )
00345                         {
00346                                 float w = 0.5 - ( font.Width( tip.c_str(), 1, 6 ) / 2.0f );
00347                                 font.Print( w, 0.90, tip.c_str(), 1, 6, 0.7, 0.7, 0.7, 0.9 );
00348                         }
00349 
00350                         // draw selected icon's tip
00351                         if( selected_icon == 0 )
00352                         {
00353                                 string t = "Add a new control";
00354                                 float w = 0.5 - ( font.Width( t.c_str(), 1, 6 ) / 2.0f );
00355                                 font.Print( w, 0.925, t.c_str(), 1, 6, 0.0, 0.8, 0.0, 0.9 );
00356                         }
00357                         else if( ( selected_icon > 0 ) && ( selected_icon <= local_controls.size() ) &&
00358                                 ( local_controls[selected_icon-1].GetName() != "" ) )
00359                         {
00360                                 string t = "Delete " + local_controls[selected_icon-1].GetName();
00361                                 float w = 0.5 - ( font.Width( t.c_str(), 1, 6 ) / 2.0f );
00362                                 font.Print( w, 0.925, t.c_str(), 1, 6, 0.8, 0.0, 0.0, 0.9 );
00363                         }
00364                 }
00365         }
00366 }
00367 
00368 void ControlGrab::IncValuePress()
00369 {
00370         Release();
00371         r_down = true;
00372 }
00373 
00374 void ControlGrab::IncValueRelease()
00375 {
00376         if( r_down && ( selected_icon < local_controls.size() ) )
00377         {
00378                 selected_icon++;
00379         }
00380         else if( selected_icon == 10000 )
00381         {
00382                 selected_icon = 0;
00383         }
00384         Release();
00385 }
00386 
00387 void ControlGrab::DecValuePress()
00388 {
00389         Release();
00390         l_down = true;
00391 }
00392 
00393 void ControlGrab::DecValueRelease()
00394 {
00395         if( l_down && ( selected_icon > 0 ) && ( selected_icon <= local_controls.size() ) )
00396         {
00397                 selected_icon--;
00398         }
00399         else if( selected_icon > local_controls.size() )
00400         {
00401                 selected_icon = 0;
00402         }
00403         Release();
00404 }
00405 
00406 void ControlGrab::Press()
00407 {
00408         pressed = true;
00409         pressed_icon = selected_icon;
00410 }
00411 
00412 void ControlGrab::Release()
00413 {
00414         if( pressed && ( pressed_icon == selected_icon ) )
00415         {
00416                 if( selected_icon == 0 )
00417                 {
00418                         adding = true;
00419                         add_start = SDL_GetTicks();
00420                 }
00421                 else if( selected_icon <= local_controls.size() )
00422                 {
00423                         local_controls.erase( local_controls.begin() + ( selected_icon - 1 ) );
00424                 }
00425         }
00426 
00427         pressed = r_down = l_down = false;
00428 }
00429 
00430 void ControlGrab::GrabKey( SDLKey key )
00431 {
00432         if( key != SDLK_ESCAPE )
00433         {
00434                 string analog_str;
00435                 string press_str;
00436                 ControlSet cs;
00437                 CONTROL ctrl_new;
00438                 ctrl_new.SetType( "key" );
00439                 ctrl_new.SetKeyCode( (int)key );
00440                 analog_str = analog ? "(held)" : "(once)";
00441                 ctrl_new.SetOneTime( !analog );
00442                 ctrl_new.SetKeyPushDown( setting != "engage" );
00443                 press_str = setting != "engage" ? "press" : "release";
00444                 ctrl_new.SetName( setting );
00445 
00446                 string ctrl_desc = "Key " + keyman.GetKeyName( (int)key ) + " " + press_str  + " " + analog_str;
00447 
00448                 cs.SetControl( ctrl_new );
00449                 cs.SetName( ctrl_desc );
00450                 cs.SetTex( &key_tex );
00451                 cs.SetTexX( &key_tex_x );
00452                 if( only_one ) local_controls.clear();
00453                 local_controls.push_back( cs );
00454         }
00455         adding = false;
00456 }
00457 
00458 void ControlGrab::GrabMouseMovement( string direction )
00459 {
00460         ControlSet cs;
00461         std::ostringstream ctrl_desc;
00462         CONTROL ctrl_new;
00463         ctrl_new.SetType( "mouse" );
00464         ctrl_new.SetName( setting );
00465         ctrl_new.SetMouseType( "motion" );
00466         ctrl_new.SetMouseDirection( direction );
00467         ctrl_desc << "Mouse move " << direction;
00468         cs.SetControl( ctrl_new );
00469         cs.SetName( ctrl_desc.str() );
00470         cs.SetTex( &mouse_move_tex );
00471         cs.SetTexX( &mouse_move_tex_x );
00472         if( only_one ) local_controls.clear();
00473         local_controls.push_back( cs );
00474         adding = false;
00475 }
00476 
00477 void ControlGrab::GrabMouseButton( int button_idx )
00478 {
00479         ControlSet cs;
00480         string button_str;
00481         string analog_str;
00482         string press_str;
00483         std::ostringstream ctrl_desc;
00484         CONTROL ctrl_new;
00485         ctrl_new.SetType( "mouse" );
00486         ctrl_new.SetName( setting );
00487         ctrl_new.SetMouseType( "button" );
00488         analog_str = analog ? "(held)" : "(once)";
00489         ctrl_new.SetOneTime( !analog );
00490         ctrl_new.SetMousePushDown( setting != "engage" );
00491         press_str = setting != "engage" ? "press" : "release";
00492         ctrl_new.SetMouseButton( button_idx );
00493         if( button_idx == 1 )
00494                 button_str = "left click";
00495         else if( button_idx == 2 )
00496                 button_str = "middle click";
00497         else if( button_idx == 3 )
00498                 button_str = "right click";
00499         else if( button_idx == 4 )
00500                 button_str = "scroll up";
00501         else if( button_idx == 5 )
00502                 button_str = "scroll down";
00503         else if( button_idx == 6 )
00504                 button_str = "scroll up";
00505         else if( button_idx == 7 )
00506                 button_str = "scroll down";
00507         else
00508                 button_str = button_idx;
00509 
00510         ctrl_desc << "Mouse button " << button_str << " " << press_str << " " << analog_str;
00511         cs.SetControl( ctrl_new );
00512         cs.SetName( ctrl_desc.str() );
00513         cs.SetTex( &mouse_btn_tex );
00514         cs.SetTexX( &mouse_btn_tex_x );
00515         if( only_one ) local_controls.clear();
00516         local_controls.push_back( cs );
00517         adding = false;
00518 }
00519 
00520 void ControlGrab::GrabJoyButton( Uint8 joy_idx, Uint8 joy_btn )
00521 {
00522         ControlSet cs;
00523         string analog_str;
00524         string press_str;
00525         CONTROL ctrl_new;
00526         ctrl_new.SetType( "joy" );
00527         ctrl_new.SetJoyType( "button" );
00528         ctrl_new.SetJoyNum( (int)joy_idx );
00529         analog_str = analog ? "(held)" : "(once)";
00530         ctrl_new.SetOneTime( !analog );
00531         ctrl_new.SetJoyPushDown( setting != "engage" );
00532         press_str = setting != "engage" ? "press" : "release";
00533         ctrl_new.SetJoyButton( (int)joy_btn );
00534         ctrl_new.SetName( setting );
00535 
00536         std::ostringstream ctrl_desc;
00537         int ji = (int)joy_idx;
00538         int jb = (int)joy_btn;
00539         ctrl_desc << "Joy" << ji << " Btn" << jb << " " << press_str << " " << analog_str;
00540 
00541         cs.SetControl( ctrl_new );
00542         cs.SetName( ctrl_desc.str() );
00543         cs.SetTex( &joy_btn_tex );
00544         cs.SetTexX( &joy_btn_tex_x );
00545         if( only_one ) local_controls.clear();
00546         local_controls.push_back( cs );
00547 
00548         adding = false;
00549 }
00550 
00551 void ControlGrab::GrabJoyMove( Uint8 joy_idx, Uint8 joy_axis, bool joy_positive, float joy_value )
00552 {
00553         ControlSet cs;
00554         CONTROL ctrl_new;
00555         string joy_type;
00556         std::ostringstream ctrl_desc;
00557         int ji = (int)joy_idx;
00558         int ja = (int)joy_axis;
00559 
00560         ctrl_new.SetType( "joy" );
00561         ctrl_new.SetJoyType( "axis" );
00562         ctrl_new.SetJoyNum( (int)joy_idx );
00563         ctrl_new.SetJoyAxis( (int)joy_axis );
00564         ctrl_new.SetName( setting );
00565         if( joy_positive )
00566         {
00567                 joy_type = "(+)";
00568                 ctrl_new.SetJoyAxisType( Positive );
00569         }
00570         else
00571         {
00572                 joy_type = "(-)";
00573                 ctrl_new.SetJoyAxisType( Negative );
00574         }
00575 
00576         ctrl_desc << "Joy" << ji << " Axis" << ja << " " << joy_type;
00577 
00578         cs.SetControl( ctrl_new );
00579         cs.SetName( ctrl_desc.str() );
00580         cs.SetTex( &joy_axis_tex );
00581         cs.SetTexX( &joy_axis_tex_x );
00582         if( only_one ) local_controls.clear();
00583         local_controls.push_back( cs );
00584 
00585         adding = false;
00586 }
00587 
00588 bool ControlGrab::MouseOver( float x, float y )
00589 {
00590         float min_x, min_y, max_x, max_y;
00591         float center_x = center.GetXPercent();
00592         float center_y = center.GetYPercent();
00593         float rel_width_half = rel_width / 2.0f;
00594         float rel_height_half = rel_height / 2.0f;
00595         min_x = center_x - rel_width_half;
00596         min_y = center_y - rel_height_half;
00597         max_x = min_x + spacing + ( (float)( local_controls.size() + 1 ) * 0.03f );
00598         max_y = center_y + rel_height_half;
00599         float icon_min_x, icon_max_x;
00600 
00601         if( ( x > min_x ) && ( x < max_x ) && ( y > min_y ) && ( y < max_y ) )
00602         {
00603                 bool found = false;
00604                 for( unsigned int i = 0; i <= local_controls.size(); i++ )
00605                 {
00606                         icon_min_x = min_x + spacing - 0.0138888 + ( 0.03 * i );
00607                         icon_max_x = icon_min_x + 0.03;
00608                         if( ( x > icon_min_x ) && ( x < icon_max_x ) )
00609                         {
00610                                 selected_icon = i;
00611                                 found = true;
00612                                 break;
00613                         }
00614                 }
00615                 if( !found ) selected_icon = 10000;
00616         }
00617 
00618         return ( x > min_x ) && ( x < max_x ) && ( y > min_y ) && ( y < max_y );
00619 }
00620 
00621 string ControlGrab::MousePress( float x, float y )
00622 {
00623         string action = "";
00624         float min_x, min_y, max_x, max_y;
00625         float center_x = center.GetXPercent();
00626         float center_y = center.GetYPercent();
00627         float rel_width_half = rel_width / 2.0f;
00628         float rel_height_half = rel_height / 2.0f;
00629         min_x = center_x - rel_width_half;
00630         min_y = center_y - rel_height_half;
00631         max_x = min_x + spacing + ( (float)( local_controls.size() + 1 ) * 0.03f );
00632         max_y = center_y + rel_height_half;
00633         float icon_min_x, icon_max_x;
00634 
00635         if( ( x > min_x ) && ( x < max_x ) && ( y > min_y ) && ( y < max_y ) )
00636         {
00637                 for( unsigned int i = 0; i <= local_controls.size(); i++ )
00638                 {
00639                         icon_min_x = min_x + spacing - 0.0138888 + ( 0.03 * i );
00640                         icon_max_x = icon_min_x + 0.03;
00641                         if( ( x > icon_min_x ) && ( x < icon_max_x ) )
00642                         {
00643                                 clicked_icon = i;
00644                                 mbtn_down = true;
00645                                 break;
00646                         }
00647                 }
00648         }
00649 
00650         return action;
00651 }
00652 
00653 string ControlGrab::MouseRelease( float x, float y )
00654 {
00655         string action = "";
00656         float min_x, min_y, max_x, max_y;
00657         float center_x = center.GetXPercent();
00658         float center_y = center.GetYPercent();
00659         float rel_width_half = rel_width / 2.0f;
00660         float rel_height_half = rel_height / 2.0f;
00661         min_x = center_x - rel_width_half;
00662         min_y = center_y - rel_height_half;
00663         max_x = min_x + spacing + ( (float)( local_controls.size() + 1 ) * 0.03f );
00664         max_y = center_y + rel_height_half;
00665         float icon_min_x, icon_max_x;
00666 
00667         if( ( x > min_x ) && ( x < max_x ) && ( y > min_y ) && ( y < max_y ) )
00668         {
00669                 for( unsigned int i = 0; i <= local_controls.size(); i++ )
00670                 {
00671                         icon_min_x = min_x + spacing - 0.0138888 + ( 0.03 * i );
00672                         icon_max_x = icon_min_x + 0.03;
00673                         if( mbtn_down && ( x > icon_min_x ) && ( x < icon_max_x ) && ( clicked_icon == i ) )
00674                         {
00675                                 if( selected_icon == 0 )
00676                                 {
00677                                         adding = true;
00678                                         add_start = SDL_GetTicks();
00679                                 }
00680                                 else if( selected_icon <= local_controls.size() )
00681                                 {
00682                                         local_controls.erase( local_controls.begin() + ( selected_icon - 1 ) );
00683                                 }
00684                                 mbtn_down = false;
00685                                 break;
00686                         }
00687                 }
00688         }
00689         mbtn_down = false;
00690         clicked_icon = 10000;
00691 
00692         return action;
00693 }

Generated on Thu Oct 19 04:05:48 2006 by  doxygen 1.4.6