00001 #include "../../Library/SDK_Manila_Sense.h"
00002
00003 GlobalInformations* GlobalInformations::resources=NULL;
00004
00005 GlobalInformations* GlobalInformations::getInstance(){
00006 if (GlobalInformations::resources==NULL)
00007 MessageBox(NULL,L"Where is Directory?",L"appName is empty!\r\nPlease set the name of your application before doing anything !",MB_ICONERROR|MB_OK);
00008 return GlobalInformations::resources;
00009 }
00010
00011 void GlobalInformations::setName(wstring newName)
00012 {
00013 if (GlobalInformations::resources==NULL){
00014 new GlobalInformations(newName);
00015 }
00016 if(GlobalInformations::resources->appName.compare(newName)!=0){
00017 GlobalInformations::resources->appName=newName;
00018
00019 loadResources(GlobalInformations::resources,findUserDirectory(GlobalInformations::resources));
00020 }
00021 }
00022
00023 wstring GlobalInformations::findUserDirectory(GlobalInformations* gi){
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 wstring regKey=L"SOFTWARE\\Manila_";
00041 regKey=regKey+gi->appName;
00042
00043 HKEY myKey;
00044 DWORD disposition;
00045 RegCreateKeyEx(HKEY_LOCAL_MACHINE, regKey.c_str(), 0, 0, REG_OPTION_NON_VOLATILE,
00046 KEY_ALL_ACCESS, 0, &myKey, &disposition);
00047
00048 wstring myDirectory;
00049
00050 WCHAR myDir[MAX_PATH];
00051 DWORD sizeValue=MAX_PATH*sizeof(WCHAR);
00052 if(RegQueryValueEx(myKey,L"SourcesDirectory", 0, 0, (LPBYTE)myDir, &sizeValue)==ERROR_SUCCESS){
00053 myDirectory=myDir;
00054 }else{
00055 WCHAR wszDirectory[MAX_PATH] = L"\0";
00056
00057 GetModuleFileNameW(NULL,wszDirectory,MAX_PATH);
00058 WCHAR* lastChar = wcsrchr(wszDirectory,L'\\');
00059
00060 wcscpy(lastChar+1,L"\0");
00061 wstring dir=wszDirectory;
00062 WCHAR directoryImg[17]=L"resources\\VGA\\\0";
00063 wcscpy(lastChar+1,directoryImg);
00064 if((long)GetFileAttributes(wszDirectory)<0){
00065 return L"\\Windows\\";
00066 }else{
00067 RegSetValueEx(myKey, L"SourcesDirectory", 0, REG_SZ, (const BYTE*)wszDirectory, wcslen(wszDirectory)*sizeof(WCHAR));
00068 myDirectory=wszDirectory;
00069 }
00070 }
00071
00072 int deb=myDirectory.find(L"resources");
00073 if(deb!=wstring::npos)
00074 gi->userDirectory=myDirectory.substr(0,deb);
00075 else
00076 gi->userDirectory=myDirectory;
00077
00078 RegCloseKey(myKey);
00079
00080 return myDirectory;
00081 }
00082
00083 GlobalInformations::GlobalInformations(wstring name)
00084 {
00085 GlobalInformations::resources=this;
00087 appName=name;
00088 hasMenuBar=false;
00089 window=NULL;
00090 m_hInstance=NULL;
00091 m_hWnd=NULL;
00092 ldDDraw=NULL;
00093 primaryBuffer=NULL;
00094 backBuffer=NULL;
00095 background=NULL;
00096 mustRender=true;
00097 mustRedraw=true;
00098 isActiv=false;
00099 hFontTitle=NULL;
00100 percentOfVGA=0;
00101 cantBeClosed=false;
00102 waitForMSG=CreateEvent(NULL,true,true,NULL);
00103
00104 bg_common_dotline = NULL;
00105 bg_common_titlebar = NULL;
00106 bg_common_divider_section = NULL;
00107 btn_common_msgbox_large = NULL;
00108 btn_common_msgbox_small = NULL;
00109 btn_common_normal = NULL;
00110 btn_common_switch = NULL;
00111 btn_common_checkbox = NULL;
00112 btn_switch_thirdState = NULL;
00113 btn_checkbox_thirdState = NULL;
00114 btn_common_input = NULL;
00115 btn_common_listitem = NULL;
00116 pivot_leftarrow = NULL;
00117 pivot_rightarrow = NULL;
00118 btn_common_combo_down = NULL;
00119 btn_common_listitem_bottom = NULL;
00120 btn_common_listitem_middle = NULL;
00121 bg_msg_box = NULL;
00122 bg_dark = NULL;
00123 btn_common_slider = NULL;
00124 btn_slider = NULL;
00125
00126 lastTick1=0;
00127 lastTick2=0;
00128 lenght1=0;
00129 lenght2=0;
00130
00132 SHInitExtraControls();
00133 InitializeCriticalSection(&criticPaint);
00134 InitializeCriticalSection(&criticAddBufPaint);
00135
00136 DWORD dwWidth = GetSystemMetrics(SM_CXSCREEN);
00137 DWORD dwHeight = GetSystemMetrics(SM_CYSCREEN);
00138 DWORD realWidth=dwWidth;
00139 if(dwWidth>dwHeight){
00140 realWidth=dwHeight;
00141 }
00142 if(dwWidth<480){
00143 percentOfVGA=realWidth/480.0;
00144 }else{
00145 percentOfVGA=1.0;
00146 }
00147
00148 isLandscape=(dwWidth > dwHeight);
00149 cantBeClosed=false;
00150
00151 wstring myDirectory=findUserDirectory(this);
00152
00153 wstring regKey=L"SOFTWARE\\Manila_";
00154 regKey=regKey+appName;
00155
00156 HKEY myKey;
00157 DWORD disposition;
00158 RegCreateKeyEx(HKEY_LOCAL_MACHINE, regKey.c_str(), 0, 0, REG_OPTION_NON_VOLATILE,
00159 KEY_ALL_ACCESS, 0, &myKey, &disposition);
00160
00161 DWORD sizeValue=sizeof(DWORD);
00162 double manilaVersion=MANILA_SDK_VERSION;
00163 bool okVersion=RegQueryValueEx(myKey,L"manilaVersion", 0, 0, (LPBYTE)&manilaVersion, &sizeValue)==ERROR_SUCCESS;
00164 okVersion=okVersion&&manilaVersion==MANILA_SDK_VERSION;
00165 if(!okVersion){
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 wstring tmp=L"HelveticaNeue LT 35 Thin.ttf";
00183 CopyFile((myDirectory+tmp).c_str(),L"\\windows\\HelveticaNeue LT 35 Thin.ttf",true);
00184 tmp=L"Tahoma.ttf";
00185 CopyFile((myDirectory+tmp).c_str(),L"\\windows\\Tahoma.ttf",false);
00186
00187 manilaVersion=MANILA_SDK_VERSION;
00188 RegSetValueEx(myKey, L"manilaVersion", 0, REG_DWORD, (LPBYTE)&manilaVersion, sizeValue);
00189 }
00190 RegCloseKey(myKey);
00191 bool rescall=false;
00192 if(percentOfVGA!=1){
00193 wstring fileName=L"AlreadyScalled.txt";
00194 wstring fileTest=myDirectory+fileName;
00195 if((long)GetFileAttributes(fileTest.c_str())<0){
00196
00197 HANDLE hFichier = NULL;
00198
00199 hFichier = CreateFile(fileTest.c_str(),GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL);
00200 if(hFichier != INVALID_HANDLE_VALUE)
00201 {
00202 string valid="Your resources are already scalled!";
00203 DWORD NbrElemEcrits=0;
00204
00205 WriteFile(hFichier,(LPCVOID)valid.c_str(),valid.length(),&NbrElemEcrits,NULL);
00206
00207 CloseHandle(hFichier);
00208 rescall=true;
00209 }
00210 }
00211 }
00212
00213 loadResources(this,myDirectory);
00214
00215 if(rescall){
00216 Element::resizeIImage(bg_common_titlebar);
00217 Element::resizeIImage(bg_common_divider_section);
00218 Element::resizeIImage(btn_common_msgbox_large);
00219 Element::resizeIImage(btn_common_msgbox_small);
00220 Element::resizeIImage(btn_common_normal);
00221 Element::resizeIImage(btn_slider);
00222 Element::resizeIImage(btn_common_slider);
00223 Element::resizeIImage(btn_checkbox_thirdState);
00224 Element::resizeIImage(btn_switch_thirdState);
00225 Element::resizeIImage(bg_dark);
00226 Element::resizeIImage(bg_msg_box);
00227 Element::resizeIImage(bg_common_dotline);
00228 Element::resizeIImage(btn_common_listitem_middle);
00229 Element::resizeIImage(btn_common_listitem_bottom);
00230 Element::resizeIImage(btn_common_combo_down);
00231 Element::resizeIImage(pivot_rightarrow);
00232 Element::resizeIImage(pivot_leftarrow);
00233 Element::resizeIImage(btn_common_listitem);
00234 Element::resizeIImage(btn_common_switch);
00235 Element::resizeIImage(btn_common_checkbox);
00236 Element::resizeIImage(btn_common_input);
00237 }
00238
00239
00240 };
00241 void GlobalInformations::releaseLoadedVar(){
00242 delete bg_common_titlebar;
00243 delete bg_common_divider_section;
00244 delete btn_common_msgbox_large;
00245 delete btn_common_msgbox_small;
00246 delete btn_common_normal;
00247 delete btn_common_switch;
00248 delete btn_common_checkbox;
00249 delete btn_common_input;
00250 delete btn_common_listitem;
00251 delete pivot_leftarrow;
00252 delete pivot_rightarrow;
00253 delete btn_common_combo_down;
00254 delete btn_common_listitem_bottom;
00255 delete btn_common_listitem_middle;
00256 delete bg_common_dotline;
00257 delete bg_msg_box;
00258 delete bg_dark;
00259 delete btn_switch_thirdState;
00260 delete btn_checkbox_thirdState;
00261 delete btn_common_slider;
00262 delete btn_slider;
00263
00264 CloseHandle(GlobalInformations::waitForMSG);
00265 GlobalInformations::window=NULL;
00266 GlobalInformations::m_hInstance=NULL;
00267 GlobalInformations::m_hWnd=NULL;
00268
00269 GlobalInformations::mustRender=false;
00270 GlobalInformations::mustRedraw=false;
00271 GlobalInformations::isActiv=false;
00272 CloseHandle(GlobalInformations::hFontTitle);
00273 GlobalInformations::hFontTitle=NULL;
00274 GlobalInformations::percentOfVGA=0;
00275 GlobalInformations::isLandscape=false;
00276 DeleteCriticalSection(&criticPaint);
00277 DeleteCriticalSection(&criticAddBufPaint);
00278 };
00279
00280 void GlobalInformations::loadResources(GlobalInformations* gi,wstring myDirectory){
00281 wstring tmp;
00282
00283 tmp=L"bg_common_titlebar.png";
00284 gi->bg_common_titlebar=new wstring(myDirectory+tmp);
00285
00286 tmp=L"bg_common_divider_section.png";
00287 gi->bg_common_divider_section=new wstring(myDirectory+tmp);
00288
00289 tmp=L"btn_common_msgbox_large.png";
00290 gi->btn_common_msgbox_large=new wstring(myDirectory+tmp);
00291
00292 tmp=L"btn_common_msgbox_small.png";
00293 gi->btn_common_msgbox_small=new wstring(myDirectory+tmp);
00294
00295 tmp=L"btn_common_normal.png";
00296 gi->btn_common_normal=new wstring(myDirectory+tmp);
00297
00298 tmp=L"btn_common_switch.png";
00299 gi->btn_common_switch=new wstring(myDirectory+tmp);
00300
00301 tmp=L"btn_common_checkbox.png";
00302 gi->btn_common_checkbox=new wstring(myDirectory+tmp);
00303
00304 tmp=L"btn_common_input.png";
00305 gi->btn_common_input=new wstring(myDirectory+tmp);
00306
00307 tmp=L"btn_common_listitem.png";
00308 gi->btn_common_listitem=new wstring(myDirectory+tmp);
00309
00310 tmp=L"pivot_leftarrow.png";
00311 gi->pivot_leftarrow=new wstring(myDirectory+tmp);
00312
00313 tmp=L"pivot_rightarrow.png";
00314 gi->pivot_rightarrow=new wstring(myDirectory+tmp);
00315
00316 tmp=L"btn_common_combo_down.png";
00317 gi->btn_common_combo_down=new wstring(myDirectory+tmp);
00318
00319 tmp=L"btn_common_listitem_bottom.png";
00320 gi->btn_common_listitem_bottom=new wstring(myDirectory+tmp);
00321
00322 tmp=L"btn_common_listitem_middle.png";
00323 gi->btn_common_listitem_middle=new wstring(myDirectory+tmp);
00324
00325 tmp=L"bg_common_dotline.png";
00326 gi->bg_common_dotline=new wstring(myDirectory+tmp);
00327
00328 tmp=L"bg_common_msgbox.png";
00329 gi->bg_msg_box=new wstring(myDirectory+tmp);
00330
00331 tmp=L"background.png";
00332 gi->bg_dark=new wstring(myDirectory+tmp);
00333
00334 tmp=L"btn_switch_thirdState.png";
00335 gi->btn_switch_thirdState=new wstring(myDirectory+tmp);
00336
00337 tmp=L"btn_checkbox_thirdState.png";
00338 gi->btn_checkbox_thirdState=new wstring(myDirectory+tmp);
00339
00340 tmp=L"btn_common_slider.png";
00341 gi->btn_common_slider=new wstring(myDirectory+tmp);
00342
00343 tmp=L"sliderBtn.png";
00344 gi->btn_slider=new wstring(myDirectory+tmp);
00345 }
00346
00347 GlobalInformations::~GlobalInformations(void)
00348 {
00349 releaseLoadedVar();
00350 }