00001 #include "../../Library/SDK_Manila_Sense.h"
00002 int DirectDrawWarp::background_color=RGB565to32(29,58,29);
00003 GlobalInformations* DirectDrawWarp::gi=NULL;
00004
00005 #ifdef _DEBUG
00006 HANDLE _hFichierDebug = NULL;
00007 #endif
00008
00009 DirectDrawWarp::DirectDrawWarp()
00010 {
00011 gi=GlobalInformations::getInstance();
00012 #ifdef _DEBUG
00013 _hFichierDebug = CreateFile((gi->userDirectory+L"GeneralLog.txt").c_str(),GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL);
00014 #endif
00015 g_hWndMenuBar=NULL;
00016 sectionActiv=-1;
00017 hasBackground=false;
00018 isWindowInitialized=false;
00019 isTopMost=false;
00020 messageBox=NULL;
00021 mouse=MouseCtrl::getInstance();
00022 numRefreash=0;
00023 hMenuArea.top=hMenuArea.bottom=hMenuArea.left=hMenuArea.right=0;
00024 }
00025 DirectDrawWarp::DirectDrawWarp(HINSTANCE hInstance,const TCHAR* name,bool topmost,HMENU menuBottom)
00026 {
00027 gi=GlobalInformations::getInstance();
00028 #ifdef _DEBUG//L"\\storage card\\GeneralLog.txt"
00029 _hFichierDebug = CreateFile((gi->userDirectory+L"GeneralLog.txt").c_str(),GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL);
00030 #endif
00031 g_hWndMenuBar=NULL;
00032 numRefreash=0;
00033 this->sectionActiv=-1;
00034 hasBackground=false;
00035 isWindowInitialized=false;
00036 hMenuArea.top=hMenuArea.bottom=hMenuArea.left=hMenuArea.right=0;
00037 isTopMost=topmost;
00038 messageBox=NULL;
00039 gi->window=this;
00040 mouse=MouseCtrl::getInstance();
00041 gi->m_hInstance=hInstance;
00042
00043 gi->m_hWnd=NULL;
00044
00045 WNDCLASS wc;
00046 DDSURFACEDESC ddsd;
00047 HRESULT hRet;
00048 DWORD dwUpdateFlags = 0;
00049
00050
00051 this->name=name;
00052
00053
00054 wc.style = CS_HREDRAW | CS_VREDRAW;
00055 wc.lpfnWndProc = DirectDrawWarp::StaticWndProc;
00056 wc.cbClsExtra = 0;
00057 wc.cbWndExtra = 0;
00058 wc.hInstance = hInstance;
00059 wc.hIcon = LoadIcon(hInstance, NULL);
00060 wc.hCursor = LoadCursor(hInstance, IDC_ARROW);
00061 wc.hbrBackground = (HBRUSH )GetStockObject(WHITE_BRUSH);
00062 wc.lpszMenuName = NULL;
00063 wc.lpszClassName = this->name;
00064 RegisterClass(&wc);
00065
00066
00067 if(topmost){
00068 gi->m_hWnd = CreateWindowEx(WS_EX_TOPMOST,
00069 this->name,
00070 this->name,
00071 WS_POPUP,
00072 0,
00073 0,
00074 GetSystemMetrics(SM_CXSCREEN),
00075 GetSystemMetrics(SM_CYSCREEN),
00076 NULL,
00077 menuBottom,
00078 hInstance,
00079 this);
00080 if (!gi->m_hWnd)
00081 return;
00082 }else{
00083 gi->m_hWnd = CreateWindow(
00084 this->name,
00085 this->name,
00086 WS_SYSMENU,
00087 CW_USEDEFAULT,
00088 CW_USEDEFAULT,
00089 CW_USEDEFAULT,
00090 CW_USEDEFAULT,
00091 NULL,
00092 menuBottom,
00093 hInstance,
00094 this);
00095 if (!gi->m_hWnd)
00096 return;
00097 }
00098
00099 if(!SipShowIM(SIPF_OFF)){
00100 LocalisedString::explainFail( LocalisedString::szCreateInputText,L"SipShowIM(SIPF_ON)");
00101 }
00102 SHFullScreen(gi->m_hWnd,SHFS_HIDETASKBAR|SHFS_HIDESIPBUTTON);
00103
00104
00105 GetClientRect(gi->m_hWnd, &gi->rs);
00106 if(gi->ldDDraw==NULL){
00107 gi->ldDDraw=new LPDIRECTDRAW;
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 gi->rcUpdateRegion=gi->rs;
00122 gi->rcVisibleDesktopTOP=gi->rs;
00123
00124 gi->primaryBuffer=new DIRECTDRAW_GDI;
00125 gi->primaryBuffer->bitmap=0;
00126 gi->primaryBuffer->directDrawSurf=NULL;
00127 gi->primaryBuffer->deviceInterface=0;
00128 gi->primaryBuffer->height=GetSystemMetrics(SM_CYSCREEN)-gi->rcVisibleDesktopTOP.top;
00129 gi->primaryBuffer->width=GetSystemMetrics(SM_CXSCREEN);
00130 gi->primaryBuffer->nbBPP=16;
00131
00132
00134
00136 hRet = DirectDrawCreate(NULL, gi->ldDDraw, NULL);
00137 if (hRet != DD_OK){
00138 LocalisedString::explainFailDirectDraw(hRet, LocalisedString::szDDrawFailedMsg);
00139 return;
00140 }
00141
00142 hRet = (*gi->ldDDraw)->SetCooperativeLevel(gi->m_hWnd, DDSCL_NORMAL);
00143 if (hRet != DD_OK){
00144 LocalisedString::explainFail( LocalisedString::szSetCooperativeFailMsg,L"SetCooperativeLevel");
00145 return;
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 memset(&ddsd, 0, sizeof(ddsd));
00167 ddsd.dwSize = sizeof(ddsd);
00168 ddsd.dwHeight=1;
00169 ddsd.dwWidth=1;
00170 ddsd.dwFlags = DDSD_CAPS;
00171 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
00172
00173 hRet = (*gi->ldDDraw)->CreateSurface(&ddsd, &gi->primaryBuffer->directDrawSurf, NULL);
00174 if (hRet != DD_OK)
00175 {
00176 LocalisedString::explainFailDirectDraw(hRet,L"CreateSurface(Primary SglBuff)");
00177 return;
00178 }
00179 }
00180 gi->primaryBuffer->directDrawSurf->GetDC(&gi->primaryBuffer->deviceInterface);
00181
00182 ShowWindow(gi->m_hWnd, true);
00183 UpdateWindow(gi->m_hWnd);
00184 SetFocus(gi->m_hWnd);
00185
00186 DDSURFACEDESC DDSurfDesc;
00187 memset(&DDSurfDesc, 0, sizeof(DDSurfDesc));
00188 DDSurfDesc.dwSize = sizeof(DDSurfDesc);
00189 DDSurfDesc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
00190 DDSurfDesc.dwWidth = gi->rs.right;
00191 DDSurfDesc.dwHeight = gi->rs.bottom;
00192
00193 gi->background=new DIRECTDRAW_GDI;
00194
00195 HRESULT hret=createSurf(&DDSurfDesc, gi->background);
00196 if (hret != DD_OK)
00197 LocalisedString::explainFailDirectDraw(hret,L"DirectDrawWarp ctor CreateSurface1");
00198
00199 gi->backBuffer=new DIRECTDRAW_GDI;
00200
00201 hret=createSurf(&DDSurfDesc, gi->backBuffer);
00202 if (hret != DD_OK)
00203 LocalisedString::explainFailDirectDraw(hret,L"DirectDrawWarp ctor CreateSurface2");
00204
00205
00206
00207
00208
00209
00210 if(isTopMost){
00211 hRet = gi->window->BltFast(gi->background, NULL, gi->primaryBuffer, NULL, DDBLT_WAITNOTBUSY, NULL );
00212 if (hRet != DD_OK)
00213 LocalisedString::explainFailDirectDraw(hRet,L"DirectDrawWarp ctor Blt1");
00214 hRet = gi->window->BltFast(gi->backBuffer, NULL, gi->primaryBuffer, NULL, DDBLT_WAITNOTBUSY, NULL );
00215 if (hRet != DD_OK)
00216 LocalisedString::explainFailDirectDraw(hRet,L"DirectDrawWarp ctor Blt2");
00217 SetTimer(gi->m_hWnd, 3, 200,NULL);
00218 }else{
00219 DDBLTFX ddbltfx;
00220 memset(&ddbltfx, 0, sizeof(ddbltfx));
00221 ddbltfx.dwSize = sizeof(ddbltfx);
00222 ddbltfx.dwFillColor = DirectDrawWarp::background_color;
00223 gi->window->BltFast(gi->backBuffer,NULL, NULL,NULL, DDBLT_COLORFILL | DDBLT_WAITNOTBUSY, &ddbltfx);
00224 gi->window->BltFast(gi->background,NULL, NULL,NULL, DDBLT_COLORFILL | DDBLT_WAITNOTBUSY, &ddbltfx);
00225 }
00226 gi->primaryBuffer->directDrawSurf->ReleaseDC(gi->primaryBuffer->deviceInterface);
00227 gi->primaryBuffer->deviceInterface=0;
00228
00229 PostMessage(NULL,WM_USER,0,NULL);
00230
00231 if(!SipShowIM(SIPF_OFF)){
00232 LocalisedString::explainFail( LocalisedString::szCreateInputText,L"SipShowIM(SIPF_ON)");
00233 }
00234 SHFullScreen(gi->m_hWnd,SHFS_HIDETASKBAR|SHFS_HIDESIPBUTTON);
00235 SIPINFO si = {0};
00236 si.cbSize = sizeof(SIPINFO);
00237 SHSipInfo(SPI_GETSIPINFO, 0, &si, 0);
00238 si.fdwFlags = SIPF_OFF;
00239 SHSipInfo(SPI_SETSIPINFO, 0, &si, 0);
00240 }
00241 void DirectDrawWarp::add(Section* e){
00242 this->section.push_back(e);
00243 sectionActiv=0;
00244 };
00245
00246
00247 DirectDrawWarp::~DirectDrawWarp(void)
00248 {
00249 #ifdef _DEBUG
00250 DWORD NbrElemEcrits=0;
00251 WriteFile(_hFichierDebug,(LPCVOID)L"Bye",4*sizeof(WCHAR),&NbrElemEcrits,NULL);
00252 CloseHandle(_hFichierDebug);
00253 #endif
00254
00255 if(messageBox!=NULL)
00256 DestroyWindow(messageBox->hWnd);
00257 if(gi->m_hWnd!=NULL)
00258 DestroyWindow(gi->m_hWnd);
00259
00260 delete mouse;
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270 deleteSurf(&gi->backBuffer);
00271 deleteSurf(&gi->background);
00272
00273
00274 int taille=this->section.size();
00275 for(int i=0;i<taille;i++){
00276 if(this->section[i]!=NULL){
00277 delete this->section[i];
00278 this->section[i]=NULL;
00279 }
00280 }
00281 }
00282
00283
00284 long FAR PASCAL DirectDrawWarp::StaticWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
00285 {
00286 DirectDrawWarp* pParent;
00287
00288
00289 if(message == WM_CREATE)
00290 {
00291 pParent = (DirectDrawWarp*)((LPCREATESTRUCT)lParam)->lpCreateParams;
00292 SetWindowLong(hWnd,GWL_USERDATA,(LONG_PTR)pParent);
00293 }
00294 else
00295 {
00296 pParent = (DirectDrawWarp*)GetWindowLong(hWnd,GWL_USERDATA);
00297 if(!pParent)
00298 return DefWindowProc(hWnd,message,wParam,lParam);
00299 }
00300
00301 return pParent->WindowProc(message,wParam,lParam);
00302 }
00303
00304
00305
00306
00307
00308
00309 long DirectDrawWarp::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
00310 {
00311 switch (message)
00312 {
00313 #ifdef UNDER_CE
00314 case WM_ACTIVATE:
00315 #else
00316 case WM_ACTIVATEAPP:
00317 #endif
00318
00319 if(gi->isActiv==wParam!=0)
00320 return 0L;
00321 Element::sendMsg(WM_ACTIVATE,(void*)wParam);
00322 gi->isActiv = wParam!=0;
00323 if(wParam==WA_INACTIVE){
00324
00325
00326
00327 if(sectionActiv>=0&§ionActiv<section.size())
00328 this->section[sectionActiv]->overlayVisibility(false);
00329 ShowWindow(gi->m_hWnd, SW_MINIMIZED);
00330
00331
00332 }else{
00333 SetForegroundWindow((HWND)(((ULONG) gi->m_hWnd) | 0x01));
00334
00335 SetFocus(gi->m_hWnd);
00336 if(messageBox!=NULL){
00337 PostMessage(messageBox->hWnd, WM_ACTIVATE,WA_ACTIVE,NULL);
00338 }
00339
00340 if(!gi->hasMenuBar)
00341 SHFullScreen(gi->m_hWnd,SHFS_HIDETASKBAR|SHFS_HIDESIPBUTTON);
00342 gi->rcUpdateRegion=gi->rs;
00343 gi->rcUpdateRegion.top=0;
00344 addToRedraw(gi->rcUpdateRegion,true);
00345 }
00346 return 0L;
00347
00348 case WM_SETFOCUS:
00349
00350 gi->mustRender=true;
00351 gi->mustRedraw=true;
00352 ShowWindow(gi->m_hWnd, SW_SHOW);
00353 UpdateWindow(gi->m_hWnd);
00354
00355
00356 return 0L;
00357
00358 case WM_CANCELMODE:
00359 case WM_KILLFOCUS:
00360
00361
00362
00363
00364 break;
00365 case WM_USER:
00366 case WM_COMMAND:
00367 Element::sendMsg(wParam,(void*)lParam);
00368 break;
00369
00370 case WM_WINDOWPOSCHANGED:{
00371 DWORD dwWidth = GetSystemMetrics(SM_CXSCREEN);
00372 DWORD dwHeight = GetSystemMetrics(SM_CYSCREEN);
00373 bool change=false;
00374 if(gi->isLandscape&&(dwWidth < dwHeight)){
00375
00376 gi->isLandscape=!gi->isLandscape;
00377 change=true;
00378 }
00379 if(!gi->isLandscape&&(dwWidth > dwHeight)){
00380
00381 gi->isLandscape=!gi->isLandscape;
00382 change=true;
00383 }
00384 if(change){
00385
00386 gi->isActiv=false;
00387
00388 GetClientRect(gi->m_hWnd, &gi->rs);
00389 if(g_hWndMenuBar!=0){
00390 GetWindowRect(g_hWndMenuBar, &hMenuArea);
00391 int heightTmp=hMenuArea.bottom-hMenuArea.top;
00392 gi->rs.bottom=gi->rs.bottom-heightTmp;
00393 }
00394
00395
00396
00397 gi->rcUpdateRegion=gi->rs;
00398 gi->rcVisibleDesktopTOP=gi->rs;
00399
00400
00401
00402 EnterCriticalSection(&gi->criticPaint);
00403 Element::reloadAllSurface();
00404 LeaveCriticalSection(&gi->criticPaint);
00405 gi->rcUpdateRegion=gi->rs;
00406 gi->isActiv=true;
00407 Element* out=mouse->giveControlBack();
00408 gi->mustRedraw=true;
00409
00410
00411
00412
00413
00414
00415 if(messageBox!=NULL)
00416 messageBox->loadSurf();
00417
00418
00419 Element::sendMsg(WM_WINDOWPOSCHANGED,NULL);
00420
00421 addToRedraw(gi->rcVisibleDesktopTOP,true);
00422
00423 SHFullScreen(gi->m_hWnd,SHFS_HIDESIPBUTTON|SHFS_HIDETASKBAR);
00424 }
00425 }
00426 break;
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440 case WM_QUIT:
00441 case WM_CLOSE:
00442 case WM_DESTROY:
00443 if(gi->cantBeClosed){
00444 PostMessage(gi->m_hWnd,WM_QUIT,(WPARAM)1,(LPARAM)NULL);
00445 return 1;
00446 }else{
00447 break;
00448 }
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460 case WM_ERASEBKGND:{
00461 return 1;
00462 }
00463
00464 case MSG_USER_PAINT:
00465 doRepaintBuffered(0);
00466 break;
00467 case WM_PAINT:
00468 {
00469 HRGN update_rgn = CreateRectRgn( 0, 0, 0, 0 );
00470 int complexity=GetUpdateRgn(gi->m_hWnd,update_rgn,true);
00471 if(gi->isActiv&&messageBox==NULL&&
00472 complexity!=ERROR&&complexity!=NULLREGION){
00473
00474 DWORD dwSize;
00475 RECT *pRects;
00476 RGNDATA* pRgnData;
00477
00478
00479 dwSize = GetRegionData(update_rgn, 0, NULL);
00480 pRgnData = (RGNDATA*)malloc(dwSize);
00481
00482
00483 GetRegionData(update_rgn, dwSize, pRgnData);
00484 pRects = (RECT*)malloc(pRgnData->rdh.nRgnSize);
00485
00486
00487 memcpy(pRects, pRgnData->Buffer, pRgnData->rdh.nRgnSize);
00488
00489 bool redraw=true;
00490 int nbRect=pRgnData->rdh.nRgnSize/sizeof(RECT);
00491 for(int i=0;i<nbRect;i++){
00492 gi->rcUpdateRegion=pRects[i];
00493 gi->rcUpdateRegion.top+=gi->rcVisibleDesktopTOP.top;
00494 gi->rcUpdateRegion.bottom+=gi->rcVisibleDesktopTOP.top;
00495 gi->mustRedraw=true;
00496 if (MyEditControl::pEditCtrl!=NULL){
00497 if(gi->rcUpdateRegion.top>=gi->rcVisibleDesktopBOTTOM.top)
00498 redraw=false;
00499 else{
00500 if (gi->rcUpdateRegion.bottom>gi->rcVisibleDesktopBOTTOM.top)
00501 gi->rcUpdateRegion.bottom=gi->rcVisibleDesktopBOTTOM.top;
00502 }
00503 }
00504 if(redraw)
00505 UpdateFrame(true);
00506 }
00507 free(pRgnData);
00508 free(pRects);
00509 }
00510 DeleteObject(update_rgn);
00511 }
00512 PAINTSTRUCT ps;
00513 BeginPaint( gi->m_hWnd, &ps );
00514 EndPaint( gi->m_hWnd, &ps );
00515 return 1;
00516
00517 case WM_TIMER:
00518
00519 if (wParam==1)
00520 {
00521 if(gi->mustRender)
00522 gi->window->UpdateFrame();
00523 else
00524 gi->window->updateElements();
00525 break;
00526 }
00527 if (wParam==2)
00528 {
00529 MySlider::slideRunning->updatePosition();
00530 break;
00531 }
00532 if (wParam==3)
00533 {
00534 gi->window->UpdateFrame(true);
00535 numRefreash++;
00536 break;
00537 }
00538 break;
00539
00540 case WM_LBUTTONDOWN:{
00541 mouse->leftBtnDown(LOWORD(lParam),HIWORD(lParam));
00542 gi->mustRedraw=false;
00543 UpdateFrame();
00544
00545 SHRGINFO shrg;
00546
00547 shrg.cbSize = sizeof(shrg);
00548 shrg.hwndClient = gi->m_hWnd;
00549 shrg.ptDown.x = LOWORD(lParam);
00550 shrg.ptDown.y = HIWORD(lParam);
00551 shrg.dwFlags = SHRG_RETURNCMD;
00552 if (SHRecognizeGesture(&shrg) == GN_CONTEXTMENU) {
00553 mouse->rightBtnDown(LOWORD(lParam),HIWORD(lParam));
00554 }
00555 break;
00556 }
00557 case WM_LBUTTONUP:{
00558 mouse->leftBtnUp(LOWORD(lParam),HIWORD(lParam));
00559 gi->mustRedraw=false;
00560 UpdateFrame();
00561 break;
00562 }
00563 case WM_MOUSEMOVE:{
00564 mouse->leftBtnMove(LOWORD(lParam),HIWORD(lParam));
00565 gi->mustRedraw=false;
00566 UpdateFrame();
00567 break;
00568 }
00569
00570 case WM_KEYDOWN:{
00571 switch(wParam){
00572 case 0x1:
00573 UpdateFrame();
00574 break;
00575 }
00576 break;
00577 }
00578
00579 case WM_SETTINGCHANGE:
00580 {
00581 if(wParam==SETTINGCHANGE_RESET&&lParam==0){
00582
00583 }
00584
00585 SIPINFO pSipInfo;
00586 memset(&pSipInfo, 0, sizeof(pSipInfo));
00587 pSipInfo.cbSize=sizeof(pSipInfo);
00588 if(!SipGetInfo(&pSipInfo)){
00589 LocalisedString::explainFail(L"Internal Failure...",L"SipGetInfo(&pSipInfo)");
00590 }
00591
00592
00593
00594
00595
00596
00597
00598 }
00599
00600 }
00601 #ifdef _DEBUG
00602 DWORD NbrElemEcrits=0;
00603 ostringstream msgString;
00604 SYSTEMTIME time;
00605 GetLocalTime(&time);
00606 msgString<<time.wMinute<<" "<<time.wSecond<<" -- ";
00607 msgString<<"WindowProc MSG : "<<hex<<message<<", wParam : "<<wParam<<dec<<endl;
00608 WriteFile(_hFichierDebug,(LPCVOID)msgString.str().c_str(),msgString.str().length(),&NbrElemEcrits,NULL);
00609 #endif
00610 return DefWindowProc(gi->m_hWnd, message, wParam, lParam);
00611 }
00612
00613 void DirectDrawWarp::changeControl(MessageBoxSense* mb){
00614 messageBox=mb;
00615 }
00616
00617 void DirectDrawWarp::initWindow(){
00618 EnterCriticalSection(&gi->criticPaint);
00619 if(messageBox!=NULL){
00620 EnterCriticalSection(&gi->criticPaint);
00621 beginPaint();
00622 messageBox->updateFrame(gi->primaryBuffer);
00623 endPaint();
00624 LeaveCriticalSection(&gi->criticPaint);
00625 return;
00626 }
00627 isWindowInitialized=true;
00628 beginPaint();
00629 if(isTopMost){
00630 KillTimer(gi->m_hWnd,3);
00631 UCHAR red=0,green=0,blue=0;
00632 WORD* pixel;
00633 WORD* ScreenData = new WORD[gi->background->width*gi->background->height];
00634 HDC srcDC= gi->background->deviceInterface;
00635
00636 BITMAPINFOHEADER bmi = {0};
00637 bmi.biSize = sizeof(BITMAPINFOHEADER);
00638 bmi.biPlanes = 1;
00639 bmi.biBitCount = 16;
00640 bmi.biWidth = gi->background->width;
00641 bmi.biHeight = -gi->background->height;
00642 bmi.biCompression = BI_RGB;
00643
00644 BITMAPINFO bmInf;
00645 bmInf.bmiColors[0].rgbBlue=0;
00646 bmInf.bmiColors[0].rgbGreen=0;
00647 bmInf.bmiColors[0].rgbRed=0;
00648 bmInf.bmiColors[0].rgbReserved=0;
00649 bmInf.bmiHeader=bmi;
00650
00651 HBITMAP hbmp = CreateDIBSection( srcDC,&bmInf,
00652 DIB_RGB_COLORS,(void**) &ScreenData, NULL,0 );
00653
00654 HDC newDC = CreateCompatibleDC(srcDC);
00655 HGDIOBJ hObj=SelectObject( newDC, hbmp);
00656
00657 if(0==BitBlt( newDC, 0, 0, gi->background->width,
00658 gi->background->height, srcDC, 0, 0, SRCCOPY ))
00659 LocalisedString::explainFailWinAPI(L"background creation");
00660
00661 WORD * pPixelOffset = ScreenData;
00662 pixel=pPixelOffset;
00663 for(int j=0;j<gi->background->height;j++){
00664 for(int i=0;i<gi->background->width;i++){
00665
00666 green=((pixel[i]>>5)&0x001F);
00667 blue=(pixel[i]&0x001F);
00668
00669 red=(blue+green)/5;
00670
00671 pixel[i]=RGB555(red,red,red);
00672 }
00673 pPixelOffset=(pPixelOffset+gi->background->width);
00674 pixel=pPixelOffset;
00675 }
00676
00677
00678 if(0==BitBlt( gi->background->deviceInterface, 0, 0, gi->background->width,
00679 gi->background->height, newDC, 0, 0, SRCCOPY))
00680 LocalisedString::explainFailWinAPI(L"background creation");
00681
00682 delete[] ScreenData;
00683
00684 SelectObject( newDC, hObj);
00685 DeleteDC( newDC );
00686 if(DeleteObject(hbmp)==0)
00687 LocalisedString::explainFailWinAPI(L"Delete BmpTMP");
00688
00689 if(NB_FRAME_ANIM>1)
00690 SetTimer(gi->m_hWnd, 3, 200,NULL);
00691 else{
00692 numRefreash++;
00693 gi->window->BltFast(gi->backBuffer,NULL,gi->background,NULL, DDBLT_WAITNOTBUSY, NULL);
00694
00695 }
00696 }else{
00697 gi->window->BltFast(gi->backBuffer,&gi->rs, gi->background,&gi->rs, DDBLT_WAITNOTBUSY|DDBLT_WAITVSYNC,NULL);
00698 }
00699
00700 if(sectionActiv>=0||section.size()>0)
00701 section[sectionActiv]->paint(gi->backBuffer,0,0);
00702
00703 gi->window->BltFast(gi->primaryBuffer,&gi->rcUpdateRegion, gi->backBuffer,&gi->rcUpdateRegion, DDBLT_WAITNOTBUSY|DDBLT_WAITVSYNC,NULL);
00704 endPaint();
00705 LeaveCriticalSection(&gi->criticPaint);
00706 }
00707
00708 void DirectDrawWarp::doRepaintBuffered(int dy){
00709 if ((!gi->isActiv||sectionActiv<0||section.size()<=0)&&
00710 messageBox==NULL)
00711 return;
00712
00713 EnterCriticalSection(&gi->criticAddBufPaint);
00714 int bufSize=bufferPaint.size();
00715 LeaveCriticalSection(&gi->criticAddBufPaint);
00716 int nbBufferTreated=0;
00717 if(bufSize>0){
00718 bool eraseBack;
00719 while(nbBufferTreated<bufSize){
00720 nbBufferTreated++;
00721 gi->rcUpdateRegion=bufferPaint[0];
00722 eraseBack=bufferPaintBack[0];
00723 gi->rcUpdateRegion.bottom=gi->rcUpdateRegion.bottom+dy;
00724 if(gi->rcUpdateRegion.bottom>GetSystemMetrics(SM_CYSCREEN))
00725 gi->rcUpdateRegion.bottom=GetSystemMetrics(SM_CYSCREEN);
00726 else{
00727 if(gi->rcUpdateRegion.bottom<gi->rs.top)
00728 gi->rcUpdateRegion.bottom=gi->rs.top;
00729 }
00730 gi->rcUpdateRegion.top=gi->rcUpdateRegion.top+dy;
00731 if(gi->rcUpdateRegion.top>gi->rcUpdateRegion.bottom)
00732 gi->rcUpdateRegion.top=gi->rcUpdateRegion.bottom;
00733 else{
00734 if(gi->rcUpdateRegion.top<gi->rcVisibleDesktopTOP.top)
00735 gi->rcUpdateRegion.top=gi->rcVisibleDesktopTOP.top;
00736 }
00737 if(gi->rcUpdateRegion.top<gi->rcUpdateRegion.bottom){
00738 gi->mustRedraw=true;
00739 UpdateFramePriv(eraseBack);
00740 }
00741 EnterCriticalSection(&gi->criticAddBufPaint);
00742 bufferPaint.erase(bufferPaint.begin(),bufferPaint.begin()+1);
00743 bufferPaintBack.erase(bufferPaintBack.begin(),bufferPaintBack.begin()+1);
00744 LeaveCriticalSection(&gi->criticAddBufPaint);
00745 }
00746 }
00747 }
00748 void DirectDrawWarp::UpdateFrame(bool eraseBack){
00749 if(!isWindowInitialized){
00750
00751 return;
00752 }
00753 if(messageBox!=NULL){
00754 EnterCriticalSection(&gi->criticPaint);
00755 beginPaint();
00756 messageBox->updateFrame(gi->primaryBuffer);
00757 endPaint();
00758 LeaveCriticalSection(&gi->criticPaint);
00759 return;
00760 }
00761 if (!gi->isActiv||sectionActiv<0||section.size()<=0)
00762 return;
00763
00764 int dy=UpdateFramePriv(eraseBack);
00765
00766 doRepaintBuffered(dy);
00767 }
00768 int DirectDrawWarp::UpdateFramePriv(bool eraseBack){
00769 if(messageBox!=NULL){
00770 EnterCriticalSection(&gi->criticPaint);
00771 beginPaint();
00772 messageBox->updateFrame(gi->primaryBuffer);
00773 endPaint();
00774 LeaveCriticalSection(&gi->criticPaint);
00775 return 0;
00776 }
00777 int out=0;
00778 EnterCriticalSection(&gi->criticPaint);
00779 beginPaint();
00780 if(eraseBack){
00781 if(isTopMost){
00782 if(numRefreash<NB_FRAME_ANIM){
00783 KillTimer(gi->m_hWnd,3);
00784 HDC hdcDest,hdcSrc;
00785 hdcDest=gi->backBuffer->deviceInterface;
00786 hdcSrc=gi->background->deviceInterface;
00787 BLENDFUNCTION blendFunction;
00788 blendFunction.BlendOp=0;
00789 blendFunction.AlphaFormat=0;
00790 blendFunction.BlendFlags=0;
00791 blendFunction.SourceConstantAlpha=128.0;
00792 int width=gi->rs.right-gi->rs.left;
00793 int height=gi->rs.bottom-gi->rs.top;
00794 if(FALSE==AlphaBlend(hdcDest,gi->rs.left,gi->rs.top,width,height,
00795 hdcSrc,gi->rs.left,gi->rs.top,width,height,
00796 blendFunction
00797 )){
00798 LocalisedString::explainFailWinAPI(L"AlphaBlend Prob!");
00799 }
00800 gi->rcUpdateRegion=gi->rs;
00801 this->section[sectionActiv]->paint(gi->backBuffer,gi->rs.left,gi->rs.top);
00802 gi->window->BltFast(gi->primaryBuffer,&gi->rcUpdateRegion,gi->backBuffer,&gi->rcUpdateRegion, DDBLT_WAITNOTBUSY, NULL);
00803 SetTimer(gi->m_hWnd, 3, 200,NULL);
00804 }else{
00805 if(numRefreash==NB_FRAME_ANIM){
00806 numRefreash++;
00807 KillTimer(gi->m_hWnd,3);
00808 gi->rcUpdateRegion=gi->rs;
00809 gi->window->BltFast(gi->backBuffer,&gi->rcUpdateRegion,gi->background,&gi->rcUpdateRegion, DDBLT_WAITNOTBUSY, NULL);
00810 this->section[sectionActiv]->paint(gi->backBuffer,gi->rs.left,gi->rs.top);
00811 gi->window->BltFast(gi->primaryBuffer,&gi->rcUpdateRegion,gi->backBuffer,&gi->rcUpdateRegion, DDBLT_WAITNOTBUSY, NULL);
00812 }else
00813 gi->window->BltFast(gi->backBuffer,&gi->rcUpdateRegion,gi->background,&gi->rcUpdateRegion, DDBLT_WAITNOTBUSY, NULL);
00814 }
00815 }else{
00816 gi->window->BltFast(gi->backBuffer,&gi->rcUpdateRegion, gi->background,&gi->rcUpdateRegion, DDBLT_WAITNOTBUSY|DDBLT_WAITVSYNC,NULL);
00817 }
00818 }
00819 out=renderProc();
00820 endPaint();
00821 LeaveCriticalSection(&gi->criticPaint);
00822 return out;
00823 };
00824
00825 int DirectDrawWarp::renderProc(){
00826
00827 if(!gi->isActiv||sectionActiv<0)
00828 return 0;
00829
00830 if(gi->mustRedraw){
00831 gi->window->BltFast(gi->backBuffer,&gi->rcUpdateRegion,gi->background,&gi->rcUpdateRegion, DDBLT_WAITNOTBUSY, NULL);
00832 this->section[sectionActiv]->paint(gi->backBuffer,gi->rs.left,gi->rs.top);
00833 gi->window->BltFast(gi->primaryBuffer,&gi->rcUpdateRegion,gi->backBuffer,&gi->rcUpdateRegion, DDBLT_WAITNOTBUSY, NULL);
00834 return 0;
00835 }
00836
00837 int dy=this->mouse->updateElement();
00838
00839 if(dy==0&&gi->mustRender)
00840 return 0;
00841 if(dy==0){
00842 mouse->stopScroll();
00843 }
00844
00845 if(isTopMost||hasBackground){
00846 gi->rcUpdateRegion=gi->rs;
00847 gi->window->BltFast(gi->backBuffer,&gi->rcUpdateRegion,gi->background,&gi->rcUpdateRegion, DDBLT_WAITNOTBUSY, NULL);
00848 this->section[sectionActiv]->paint(gi->backBuffer,gi->rs.left,gi->rs.top);
00849 gi->window->BltFast(gi->primaryBuffer,&gi->rcUpdateRegion,gi->backBuffer,&gi->rcUpdateRegion, DDBLT_WAITNOTBUSY, NULL);
00850 return dy;
00851 }
00852 HRESULT hRet;
00853 RECT dest=gi->rs;
00854 RECT src=dest;
00855
00856
00857 if(dy!=0){
00858 gi->rcUpdateRegion=gi->rs;
00859 if(abs(dy)<gi->rs.bottom-gi->rs.top){
00860
00861 if(dy>0){
00862 dest.top+=dy;
00863 src.bottom-=dy;
00864 gi->rcUpdateRegion.top=gi->rs.top;
00865 gi->rcUpdateRegion.bottom=dest.top;
00866 }else{
00867 dest.bottom+=dy;
00868 src.top-=dy;
00869 gi->rcUpdateRegion.bottom=gi->rs.bottom;
00870 gi->rcUpdateRegion.top=dest.bottom;
00871 }
00872 if(dest.bottom-dest.top>0&&dest.right-dest.left>0)
00873 hRet = gi->window->BltFast(gi->primaryBuffer, &dest, gi->primaryBuffer, &src, DDBLT_WAITNOTBUSY, NULL );
00874 if (hRet != DD_OK){
00875 stringstream ss;
00876 ss<<"UpdateFrame "<<gi->rcUpdateRegion.bottom<<","<<gi->rcUpdateRegion.top;
00877 string s=ss.str();
00878 wstring msg(s.length(),L' ');
00879 std::copy(s.begin(), s.end(), msg.begin());
00880 LocalisedString::explainFailDirectDraw(hRet,msg);
00881 }
00882 hRet = gi->window->BltFast(gi->backBuffer,
00883 &gi->rcUpdateRegion, gi->background,&gi->rcUpdateRegion, DDBLT_WAITNOTBUSY,NULL);
00884
00885 if (hRet != DD_OK)
00886 LocalisedString::explainFailDirectDraw(hRet,L"Erase bckground");
00887 }else{
00888 hRet = gi->window->BltFast(gi->backBuffer,
00889 &gi->rs, gi->background,&gi->rs, DDBLT_WAITNOTBUSY,NULL);
00890 if (hRet != DD_OK)
00891 LocalisedString::explainFailDirectDraw(hRet,L"Erase bckground");
00892 }
00893 }
00894
00895
00896
00897 if(gi->mustRender){
00898
00899 this->section[sectionActiv]->paint(gi->backBuffer,gi->rs.left,gi->rs.top);
00900
00901 gi->window->BltFast(gi->primaryBuffer,
00902 &gi->rcUpdateRegion, gi->backBuffer,&gi->rcUpdateRegion, DDBLT_WAITNOTBUSY,NULL);
00903 }
00904 return dy;
00905 };
00906
00907
00908 void DirectDrawWarp::addToRedraw(RECT &rc,bool backErase){
00909 EnterCriticalSection(&gi->criticAddBufPaint);
00910 if(bufferPaint.size()<=1){
00911 bufferPaint.push_back(rc);
00912 bufferPaintBack.push_back(backErase);
00913 if(bufferPaint.size()==1)
00914 PostMessage(gi->m_hWnd,MSG_USER_PAINT,NULL,NULL);
00915 }else{
00916
00917 bool isInto=false;
00918 RECT tmp;
00919 int i=0,nbMax=bufferPaint.size();
00920 while (!isInto&&i<nbMax)
00921 {
00922 tmp=bufferPaint[i];
00923 isInto=tmp.top<=rc.top&&tmp.bottom>=rc.bottom&&tmp.left<=rc.left&&tmp.right>=rc.right;
00924 if (!isInto&&rc.top<=tmp.top&&rc.bottom>=tmp.bottom&&rc.left<=tmp.left&&rc.right>=tmp.right)
00925 {
00926
00927 bufferPaint.erase(bufferPaint.begin()+i,bufferPaint.begin()+i+1);
00928 bufferPaintBack.erase(bufferPaintBack.begin()+i,bufferPaintBack.begin()+i+1);
00929 nbMax--;
00930 }else
00931 i++;
00932 }
00933 if(!isInto){
00934 bufferPaint.push_back(rc);
00935 bufferPaintBack.push_back(backErase);
00936 }else{
00937 int i=0;
00938 i++;
00939 }
00940 }
00941 LeaveCriticalSection(&gi->criticAddBufPaint);
00942 }
00943
00944 HRESULT DirectDrawWarp::BltFast(DIRECTDRAW_GDI* out,RECT *dest,DIRECTDRAW_GDI* srcSur, RECT *src,DWORD flag,LPDDBLTFX param){
00945 #ifdef DRAWING_GDI
00946 if((out==gi->primaryBuffer||srcSur==gi->primaryBuffer)&&
00947 gi->primaryBuffer->deviceInterface==0)
00948 beginPaint();
00949
00950 static bool destCreated,srcCreated;
00951 destCreated=false;
00952 srcCreated=false;
00953 if (dest==NULL){
00954 destCreated=true;
00955 dest=new RECT;
00956 dest->left=0;dest->top=0;dest->right=out->width;dest->bottom=out->height;
00957 }
00958 if(srcSur!=NULL&&src==NULL){
00959 srcCreated=true;
00960 src=new RECT;
00961 src->left=0;src->top=0;src->right=srcSur->width;src->bottom=srcSur->height;
00962 }
00963 if(DDBLT_COLORFILL&flag){
00964 HBRUSH b=CreateSolidBrush(param->dwFillColor);
00965
00966
00967 if(FillRect(out->deviceInterface,dest,b)!=0){
00968 if (destCreated)
00969 delete dest;
00970 if (srcCreated)
00971 delete src;
00972 return S_OK;
00973 }else{
00974 LocalisedString::explainFailWinAPI(L"FillRect");
00975 }
00976 }else{
00977 if(srcSur!=NULL){
00978 bool paintAlpha=(param==NULL&&srcSur->bitmap!=NULL&&srcSur->nbBPP>=32);
00979 if(paintAlpha){
00980 BLENDFUNCTION blitAlpha;
00981 blitAlpha.BlendOp=AC_SRC_OVER;
00982 blitAlpha.BlendFlags=0;
00983 blitAlpha.AlphaFormat=AC_SRC_ALPHA;
00984 blitAlpha.SourceConstantAlpha=0xFF;
00985 if (AlphaBlend(out->deviceInterface,
00986 dest->left,dest->top,dest->right-dest->left,dest->bottom-dest->top,
00987 srcSur->deviceInterface,
00988 src->left,src->top,src->right-src->left,src->bottom-src->top,
00989 blitAlpha)!=0){
00990
00991 if (destCreated)
00992 delete dest;
00993 if (srcCreated)
00994 delete src;
00995 return S_OK;
00996 }else
00997 paintAlpha=false;
00998 }
00999 if(!paintAlpha)
01000 {
01001 if (StretchBlt(out->deviceInterface,
01002 dest->left,dest->top,dest->right-dest->left,dest->bottom-dest->top,
01003 srcSur->deviceInterface,
01004 src->left,src->top,src->right-src->left,src->bottom-src->top,
01005 SRCCOPY)!=0){
01006 if (destCreated)
01007 delete dest;
01008 if (srcCreated)
01009 delete src;
01010 return S_OK;
01011 }else
01012 LocalisedString::explainFailWinAPI(L"BltFast BitBlt");
01013 }
01014 }
01015 }
01016
01017 if (destCreated)
01018 delete dest;
01019 if (srcCreated)
01020 delete src;
01021
01022 return DDERR_INVALIDPARAMS;
01023 #endif
01024 #ifdef DRAWING_DDRAW
01025 if (srcSur==NULL)
01026 {
01027 return out->directDrawSurf->Blt(dest,NULL,NULL,flag,param);
01028 }
01029 else
01030 {
01031 return out->directDrawSurf->Blt(dest,srcSur->directDrawSurf,src,flag,param);
01032 }
01033 #endif
01034 }
01035 void DirectDrawWarp::BltMix(DIRECTDRAW_GDI* out,RECT *dest,DIRECTDRAW_GDI* srcSur, RECT *src,DWORD constantAlpha){
01036 if((out==gi->primaryBuffer||srcSur==gi->primaryBuffer)&&
01037 gi->primaryBuffer->deviceInterface==0)
01038 beginPaint();
01039
01040 static bool destCreated,srcCreated;
01041 destCreated=false;
01042 srcCreated=false;
01043 if (dest==NULL){
01044 destCreated=true;
01045 dest=new RECT;
01046 dest->left=0;dest->top=0;dest->right=out->width;dest->bottom=out->height;
01047 }
01048 if(srcSur!=NULL&&src==NULL){
01049 srcCreated=true;
01050 src=new RECT;
01051 src->left=0;src->top=0;src->right=srcSur->width;src->bottom=srcSur->height;
01052 }
01053 BLENDFUNCTION blendFunction;
01054 blendFunction.BlendOp=0;
01055 blendFunction.AlphaFormat=0;
01056 blendFunction.BlendFlags=0;
01057 blendFunction.SourceConstantAlpha=constantAlpha;
01058 if(FALSE==AlphaBlend(out->deviceInterface,
01059 dest->left,dest->top,dest->right-dest->left,dest->bottom-dest->top,
01060 srcSur->deviceInterface,
01061 src->left,src->top,src->right-src->left,src->bottom-src->top,
01062 blendFunction)){
01063 LocalisedString::explainFailWinAPI(L"AlphaBlend Prob!");
01064 }
01065 if (destCreated)
01066 delete dest;
01067 if (srcCreated)
01068 delete src;
01069 }
01070
01071 HRESULT DirectDrawWarp::BltMask(DIRECTDRAW_GDI* out,RECT *dest,DIRECTDRAW_GDI* srcSur,DIRECTDRAW_GDI* maskBlt, RECT *src){
01072 if(srcSur==NULL||maskBlt==NULL||maskBlt->bitmap==0)
01073 return DDERR_INVALIDPARAMS;
01074
01075 if((out==gi->primaryBuffer||srcSur==gi->primaryBuffer)&&
01076 gi->primaryBuffer->deviceInterface==0)
01077 beginPaint();
01078
01079 static bool destCreated,srcCreated;
01080 destCreated=false;
01081 srcCreated=false;
01082 if (dest==NULL){
01083 destCreated=true;
01084 dest=new RECT;
01085 dest->left=0;dest->top=0;dest->right=out->width;dest->bottom=out->height;
01086 }
01087 if(src==NULL){
01088 srcCreated=true;
01089 src=new RECT;
01090 src->left=0;src->top=0;src->right=srcSur->width;src->bottom=srcSur->height;
01091 }
01092 if(MaskBlt(out->deviceInterface,
01093 dest->left,dest->top, dest->right-dest->left, dest->bottom-dest->top,
01094 srcSur->deviceInterface,
01095 src->left, src->top,
01096 maskBlt->bitmap,
01097 src->left, src->top,
01098 MAKEROP4(0x00AA0029, SRCCOPY))==0){
01099 LocalisedString::explainFailWinAPI(L"MaskBlt");
01100 };
01101 return S_OK;
01102 }
01103
01104 GDI_OVERLAY* DirectDrawWarp::createOverlay(DDSURFACEDESC* desc)
01105 {
01106
01107 GDI_OVERLAY* surf=new GDI_OVERLAY;
01108 HRESULT hr=(*(gi->ldDDraw))->CreateSurface(desc,
01109 &surf->directDrawSurf, NULL );
01110 if(hr!=S_OK){
01111 delete surf;
01112 return NULL;
01113 }
01114 return surf;
01115 }
01116
01117 HRESULT DirectDrawWarp::createSurf(DDSURFACEDESC* desc,DIRECTDRAW_GDI* surf){
01118 if(surf==NULL)
01119 return DDERR_INVALIDPARAMS;
01120
01121 #ifdef DRAWING_GDI
01122
01123 bool wasPainting=true;
01124 if(gi->primaryBuffer->deviceInterface==0){
01125 beginPaint();
01126 wasPainting=false;
01127 }
01128
01129 surf->directDrawSurf=NULL;
01130 surf->deviceInterface=CreateCompatibleDC(NULL);
01131 if(surf->deviceInterface==0)
01132 LocalisedString::explainFailWinAPI(L"createSurf CreateCompatibleDC");
01133
01134
01135 surf->width=desc->dwWidth;
01136 surf->height=desc->dwHeight;
01137 uchar bpp=desc->dwBackBufferCount;
01138 if(bpp==0||bpp==1)
01139 bpp=16;
01140 surf->bitmap = CreateBitmap(surf->width, surf->height,1,bpp,NULL);
01141
01142 if(surf->bitmap==0)
01143 LocalisedString::explainFailWinAPI(L"CreateCompatibleBitmap");
01144
01145 surf->oldObj=SelectObject(surf->deviceInterface, surf->bitmap);
01146 if(!wasPainting)
01147 endPaint();
01148
01149 BITMAP bm;
01150 GetObject(surf->bitmap, sizeof(bm), &bm);
01151 surf->width=bm.bmWidth;
01152 surf->height=bm.bmHeight;
01153 surf->nbBPP=bm.bmBitsPixel;
01154
01155 return S_OK;
01156 #endif
01157 #ifdef DRAWING_DDRAW
01158 HRESULT hr=(*gi->ldDDraw)->CreateSurface(&desc, &surf->directDrawSurf, NULL );
01159 if(hr!=S_OK)
01160 return hr;
01161 surf->deviceInterface=surf->directDrawSurf->GetDC(&surf->deviceInterface);
01162 return S_OK;
01163 #endif
01164 }
01165
01166 void DirectDrawWarp::deleteSurf(DIRECTDRAW_GDI** surf){
01167 if(surf==NULL||(*surf)==NULL)
01168 return;
01169
01170 if((*surf)->directDrawSurf!=NULL){
01171 (*surf)->directDrawSurf->ReleaseDC((*surf)->deviceInterface);
01172 (*surf)->deviceInterface=NULL;
01173 (*surf)->directDrawSurf->Release();
01174 }
01175 if((*surf)->deviceInterface!=NULL){
01176 SelectObject((*surf)->deviceInterface, (*surf)->oldObj);
01177 if(DeleteObject ((*surf)->bitmap)==0)
01178 LocalisedString::explainFailWinAPI(L"DeleteObject");
01179 if(DeleteDC((*surf)->deviceInterface)==0)
01180 LocalisedString::explainFailWinAPI(L"DeleteDC");
01181 }
01182 delete (*surf);
01183 (*surf)=NULL;
01184 }
01185
01186 void DirectDrawWarp::beginPaint(){
01187 if(gi->primaryBuffer->deviceInterface!=0)
01188 return;
01189 #ifdef DRAWING_GDI
01190
01191 if(true){
01192 gi->primaryBuffer->deviceInterface=GetDC(gi->m_hWnd);
01193 if(gi->primaryBuffer->deviceInterface==0)
01194 LocalisedString::explainFailWinAPI(L"beginPaint");
01195 }else{
01196 HRESULT hr=gi->primaryBuffer->directDrawSurf->GetDC(&gi->primaryBuffer->deviceInterface);
01197 if(hr!=S_OK)
01198 LocalisedString::explainFailDirectDraw(hr,L"beginPaint GetDC");
01199 }
01200 #endif
01201 #ifdef DRAWING_DDRAW
01202 HRESULT hr=gi->primaryBuffer->directDrawSurf->GetDC(&gi->primaryBuffer->deviceInterface);
01203 if(hr!=S_OK)
01204 LocalisedString::explainFailDirectDraw(hr,L"beginPaint");
01205 #endif
01206 }
01207 void DirectDrawWarp::endPaint(){
01208 if(gi->primaryBuffer->deviceInterface==NULL)
01209 return;
01210 #ifdef DRAWING_GDI
01211
01212 if(true){
01213 if(ReleaseDC(gi->m_hWnd,gi->primaryBuffer->deviceInterface)==0)
01214 LocalisedString::explainFailWinAPI(L"endPaint");
01215 }else{
01216 HRESULT hr=gi->primaryBuffer->directDrawSurf->ReleaseDC(gi->primaryBuffer->deviceInterface);
01217 if(hr!=S_OK)
01218 LocalisedString::explainFailDirectDraw(hr,L"endPaint ReleaseDC");
01219 }
01220 gi->primaryBuffer->deviceInterface=0;
01221 #endif
01222 #ifdef DRAWING_DDRAW
01223 HRESULT hRes=gi->primaryBuffer->directDrawSurf->ReleaseDC(gi->primaryBuffer->deviceInterface);
01224 if(hRes!=S_OK)
01225 LocalisedString::explainFailDirectDraw(hRes,L"ReleaseDC Primary2");
01226 #endif
01227 }
01228
01229
01230 void DirectDrawWarp::setBackgroundImg( LPCWSTR imgSrc,bool forLandscape)
01231 {
01232 wstring *tmp=NULL;
01233 if(imgSrc!=NULL){
01234 if(forLandscape){
01235 imgBkgFileLand=imgSrc;
01236 tmp=&imgBkgFileLand;
01237 }else{
01238 imgBkgFile=imgSrc;
01239 tmp=&imgBkgFile;
01240 }
01241 if(gi->isLandscape==forLandscape){
01242 DIRECTDRAW_GDI* img=Element::loadImage(tmp);
01243 if(img!=NULL){
01244
01245 HRESULT hRet = gi->window->BltFast(gi->background, NULL, img, NULL,DDBLT_WAITNOTBUSY, NULL );
01246 if (hRet != DD_OK)
01247 LocalisedString::explainFailDirectDraw(hRet,L"setBackgroundImg Blt");
01248 gi->rcUpdateRegion=gi->rs;
01249 this->deleteSurf(&img);
01250 hasBackground=true;
01251 UpdateFrame(true);
01252 }
01253 }
01254
01255 }else{
01256 if(gi->isLandscape&&!imgBkgFileLand.empty())
01257 tmp=&imgBkgFileLand;
01258 else
01259 if(!gi->isLandscape&&!imgBkgFile.empty())
01260 tmp=&imgBkgFile;
01261 if(tmp!=NULL){
01262 DIRECTDRAW_GDI* img=Element::loadImage(tmp);
01263
01264 HRESULT hRet = gi->window->BltFast(gi->background, NULL, img, NULL,DDBLT_WAITNOTBUSY, NULL );
01265 if (hRet != DD_OK)
01266 LocalisedString::explainFailDirectDraw(hRet,L"setBackgroundImg Blt");
01267 gi->rcUpdateRegion=gi->rs;
01268 this->deleteSurf(&img);
01269 hasBackground=true;
01270 UpdateFrame(true);
01271 }
01272 }
01273 }
01274 void DirectDrawWarp::setBackgroundColor( COLORREF newColor)
01275 {
01276 background_color=newColor;
01277 DDBLTFX ddbltfx;
01278 memset(&ddbltfx, 0, sizeof(ddbltfx));
01279 ddbltfx.dwSize = sizeof(ddbltfx);
01280 ddbltfx.dwFillColor = background_color;
01281 gi->window->BltFast(gi->backBuffer,NULL, NULL,NULL, DDBLT_COLORFILL | DDBLT_WAITNOTBUSY, &ddbltfx);
01282 gi->window->BltFast(gi->background,NULL, NULL,NULL, DDBLT_COLORFILL | DDBLT_WAITNOTBUSY, &ddbltfx);
01283 addToRedraw(gi->rs,true);
01284 }
01285
01286 void DirectDrawWarp::setMenu( HMENU hMenu ){
01287
01288 int top=gi->rs.top;
01289 if(g_hWndMenuBar!=NULL){
01290 DestroyWindow(g_hWndMenuBar);
01291 DestroyMenu(myHMenu);
01292 g_hWndMenuBar=NULL;
01293 myHMenu=NULL;
01294 GetClientRect(gi->m_hWnd, &gi->rs);
01295 gi->hasMenuBar=false;
01296 SHFullScreen(gi->m_hWnd,SHFS_HIDETASKBAR|SHFS_HIDESIPBUTTON);
01297 GetClientRect(gi->m_hWnd, &gi->rs);
01298 gi->rs.top=top;
01299 addToRedraw(gi->rs,true);
01300 }
01301 myHMenu=hMenu;
01302 if(hMenu==NULL)
01303 return;
01304
01305 SHMENUBARINFO mbi;
01306 ZeroMemory(&mbi, sizeof(SHMENUBARINFO));
01307 mbi.cbSize = sizeof(SHMENUBARINFO);
01308 mbi.hwndParent = gi->m_hWnd;
01309 mbi.nToolBarId = (UINT_PTR)hMenu;
01310 mbi.hInstRes = gi->m_hInstance;
01311 mbi.dwFlags= SHCMBF_HMENU;
01312 mbi.nBmpId = 0;
01313 mbi.cBmpImages = 0;
01314
01315 if (!SHCreateMenuBar(&mbi)){
01316 g_hWndMenuBar = NULL;
01317 gi->hasMenuBar=false;
01318 }else{
01319 g_hWndMenuBar = mbi.hwndMB;
01320 gi->hasMenuBar=true;
01321 }
01322
01323 GetWindowRect(g_hWndMenuBar, &hMenuArea);
01324 int heightTmp=hMenuArea.bottom-hMenuArea.top;
01325 gi->rs.bottom=gi->rs.bottom-heightTmp;
01326 };
01327
01328 void DirectDrawWarp::changeMenu( UINT message,int idMenu, LPARAM info ){
01329 SendMessage(g_hWndMenuBar, message,idMenu, info);
01330 }