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
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
00043 TEXTURE_HANDLE img_tex;
00044
00045 img_tex_list.push_back( img_tex );
00046 img_tex_list.back().Load( filename.c_str(), false, img_width, img_height );
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 }
00059
00060
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
00083
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
00147
00148
00149
00150
00151
00152
00153 return false;
00154 }
00155
00156 string MultiImage::MousePress( float x, float y )
00157 {
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178 return "";
00179 }
00180
00181 string MultiImage::MouseRelease( float x, float y )
00182 {
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 return "";
00209 }