src/gui/multi_image.cpp

Go to the documentation of this file.
00001 #include "gui/gui.h"
00002 #include "gui/multi_image.h"
00003 using namespace VGUI;
00004 
00005 
00006 MultiImage::MultiImage( Widget* w )
00007 {
00008         center = w->GetCenter();
00009         name = w->GetName();
00010         text = w->GetText();
00011         type = w->GetType();
00012         tip = w->GetTip();
00013         rel_width = w->GetRelWidth();
00014         rel_height = w->GetRelHeight();
00015         enabled = w->GetEnabled();
00016         selected = w->GetSelected();
00017         is_default = w->GetDefault();
00018         is_cancel = w->GetCancel();
00019         has_icon = w->GetHasIcon();
00020         width_auto = w->GetWidthAuto();
00021         height_auto = w->GetHeightAuto();
00022         font_size = w->GetFontSize();
00023         color_r = w->GetColorR();
00024         color_g = w->GetColorG();
00025         color_b = w->GetColorB();
00026         cur_option = 0;
00027         last_option = 10000;
00028 }
00029 
00030 MultiImage::~MultiImage()
00031 {
00032 }
00033 
00034 void MultiImage::Load()
00035 {
00036         //img_tex_list.reserve(256);
00037         string filename;
00038         int img_width, img_height;
00039         for( unsigned int i = 0; i < filename_list.size(); i++ )
00040         {
00041                 filename = settings.GetDataDir() + "/tracks/" + filename_list[i] + "/trackshot.png";
00042                 //img_tex.Load( filename.c_str(), false, img_width, img_height );
00043                 TEXTURE_HANDLE img_tex;
00044                 //img_tex.Load( filename.c_str(), false, img_width, img_height );
00045                 img_tex_list.push_back( img_tex );
00046                 img_tex_list.back().Load( filename.c_str(), false, img_width, img_height );
00047                 
00048                 //cout << "cur_option: " << cur_option << ", filename_list[i]: " << filename_list[i] << ", img_tex_list[i]: " << img_tex_list[i] << ", value_list[i]: " << value_list[i] << endl;
00049                 //if( width_auto )
00050                 //{
00051                         //rel_width = (float)img_width / 1280.0f;
00052                 //}
00053 
00054                 //if( height_auto )
00055                 //{
00056                         //rel_height = (float)img_height / 1024.0f;
00057                 //}
00058         }
00059                         //rel_width = (float)img_width / 1280.0f;
00060                         //rel_height = (float)img_height / 1024.0f;
00061 }
00062 
00063 void MultiImage::ResetValue()
00064 {
00065         string default_val;
00066         settings.Get( setting, default_val );
00067         SetValue( default_val );
00068 }
00069 
00070 void MultiImage::Draw()
00071 {
00072         Draw( 1.0 );
00073 }
00074 
00075 void MultiImage::Draw( float opacity )
00076 {
00077         float cur_opacity = 1.0;
00078         float center_x = center.GetXPercent();
00079         float center_y = center.GetYPercent();
00080         float rel_width_half = rel_width / 2.0f;
00081         float rel_height_half = rel_height / 2.0f;
00082         //cout << "cur_option: " << cur_option << ", filename_list[cur_option]: " << filename_list[cur_option] << ", img_tex_list[cur_option]: " << img_tex_list[cur_option] << ", value_list[cur_option]: " << value_list[cur_option] << endl;
00083         //cout << "rel_width: " << rel_width << ", rel_height: " << rel_height << endl;
00084         TEXTURE_HANDLE * img1 = &(img_tex_list[cur_option]);
00085 
00086         if( last_option != 10000 )
00087         {
00088                 float elapsed_time = ( (float)( SDL_GetTicks() - press_time ) / 1000.0 );
00089                 if( elapsed_time <= 0.2 )
00090                 {
00091                         TEXTURE_HANDLE * img2 = &(img_tex_list[last_option]);
00092                         cur_opacity = ( elapsed_time / 0.2 );
00093                         float last_opacity = 1.0 - cur_opacity;
00094                         utility.Draw2D( center_x - rel_width_half, center_y - rel_height_half, center_x + rel_width_half, center_y + rel_height_half, img2, 0.0, 0, last_opacity * opacity );
00095                 }
00096                 else
00097                 {
00098                         last_option = 10000;
00099                 }
00100         }
00101         utility.Draw2D( center_x - rel_width_half, center_y - rel_height_half, center_x + rel_width_half, center_y + rel_height_half, img1, 0.0, 0, cur_opacity * opacity );
00102 }
00103 
00104 void MultiImage::HookIncValuePress()
00105 {
00106         Release();
00107         r_down = true;
00108 }
00109 
00110 void MultiImage::HookIncValueRelease()
00111 {
00112         Release();
00113         if( cur_option < filename_list.size() - 1 )
00114         {
00115                 press_time = SDL_GetTicks();
00116                 last_option = cur_option;
00117                 cur_option++;
00118         }
00119 }
00120 
00121 void MultiImage::HookDecValuePress()
00122 {
00123         Release();
00124         l_down = true;
00125         press_time = SDL_GetTicks();
00126 }
00127 
00128 void MultiImage::HookDecValueRelease()
00129 {
00130         Release();
00131         if( cur_option > 0 )
00132         {
00133                 press_time = SDL_GetTicks();
00134                 last_option = cur_option;
00135                 cur_option--;
00136         }
00137 }
00138 
00139 void MultiImage::Release()
00140 {
00141         r_down = l_down = false;
00142 }
00143 
00144 bool MultiImage::MouseOver( float x, float y )
00145 {
00146 /*      float min_x, min_y, max_x, max_y;
00147         min_x = center.GetXPercent() - ( rel_width / 2.0f );
00148         min_y = center.GetYPercent() - ( rel_height / 2.0f );
00149         max_x = center.GetXPercent() + ( rel_width / 2.0f );
00150         max_y = center.GetYPercent() + ( rel_height / 2.0f );
00151 
00152         return ( x > min_x ) && ( x < max_x ) && ( y > min_y ) && ( y < max_y );
00153 */      return false;
00154 }
00155 
00156 string MultiImage::MousePress( float x, float y )
00157 {
00158 /*      float l_min_x, l_min_y, l_max_x, l_max_y;
00159         float r_min_x, r_min_y, r_max_x, r_max_y;
00160         l_min_x = center.GetXPercent() - ( rel_width / 2.0f ) + spacing;
00161         l_min_y = center.GetYPercent() - ( rel_height / 2.0f );
00162         l_max_x = center.GetXPercent() - ( rel_width / 2.0f ) + spacing + tex_width;
00163         l_max_y = center.GetYPercent() + ( rel_height / 2.0f );
00164         r_min_x = center.GetXPercent() - ( rel_width / 2.0f ) + spacing  + 0.15;
00165         r_min_y = center.GetYPercent() - ( rel_height / 2.0f );
00166         r_max_x = center.GetXPercent() - ( rel_width / 2.0f ) + spacing  + 0.15 + tex_width;
00167         r_max_y = center.GetYPercent() + ( rel_height / 2.0f );
00168 
00169         if( ( x > l_min_x ) && ( x < l_max_x ) && ( y > l_min_y ) && ( y < l_max_y ) )
00170         {
00171                 l_down = true;
00172         }
00173         else if( ( x > r_min_x ) && ( x < r_max_x ) && ( y > r_min_y ) && ( y < r_max_y ) )
00174         {
00175                 r_down = true;
00176         }
00177 */
00178         return "";
00179 }
00180 
00181 string MultiImage::MouseRelease( float x, float y )
00182 {
00183 /*      float l_min_x, l_min_y, l_max_x, l_max_y;
00184         float r_min_x, r_min_y, r_max_x, r_max_y;
00185         l_min_x = center.GetXPercent() - ( rel_width / 2.0f ) + spacing;
00186         l_min_y = center.GetYPercent() - ( rel_height / 2.0f );
00187         l_max_x = center.GetXPercent() - ( rel_width / 2.0f ) + spacing + tex_width;
00188         l_max_y = center.GetYPercent() + ( rel_height / 2.0f );
00189         r_min_x = center.GetXPercent() - ( rel_width / 2.0f ) + spacing  + 0.15;
00190         r_min_y = center.GetYPercent() - ( rel_height / 2.0f );
00191         r_max_x = center.GetXPercent() - ( rel_width / 2.0f ) + spacing  + 0.15 + tex_width;
00192         r_max_y = center.GetYPercent() + ( rel_height / 2.0f );
00193 
00194 
00195         if( ( x > l_min_x ) && ( x < l_max_x ) && ( y > l_min_y ) && ( y < l_max_y ) && l_down )
00196         {
00197                 DecValueRelease();
00198         }
00199         else if( ( x > r_min_x ) && ( x < r_max_x ) && ( y > r_min_y ) && ( y < r_max_y ) && r_down )
00200         {
00201                 IncValueRelease();
00202         }
00203         else
00204         {
00205                 Release();
00206         }
00207 */
00208         return "";
00209 }

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