// MenuItem.cpp: implementation of the CMenuItem class. // ////////////////////////////////////////////////////////////////////// #include "MenuItem.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CMenuItem::CMenuItem(UINT uiImage,char * szName,CMenuItem **pChilds,int iChilds) { CMenuItem::uiImage=uiImage; CMenuItem::szName=szName; CMenuItem::pChilds=pChilds; CMenuItem::iChilds=iChilds; HWND hWindow = GameEngine::GetEngine()->GetWindow(); HDC hDC = GetDC(hWindow); HINSTANCE hInstance=GameEngine::GetEngine()->GetInstance(); bmpImage[0][0]=new Bitmap(hDC,uiImage,hInstance); bmpImage[0][1]=new Bitmap(hDC,uiImage+1,hInstance); bmpImage[0][2]=new Bitmap(hDC,uiImage+2,hInstance); bmpImage[1][0]=new Bitmap(hDC,uiImage+3,hInstance); bmpImage[1][1]=new Bitmap(hDC,uiImage+4,hInstance); bmpImage[1][2]=new Bitmap(hDC,uiImage+5,hInstance); bmpImage[2][0]=new Bitmap(hDC,uiImage+6,hInstance); bmpImage[2][1]=new Bitmap(hDC,uiImage+7,hInstance); bmpImage[2][2]=new Bitmap(hDC,uiImage+8,hInstance); iCurrentImage=0; iBeforeMove=-1; bCollapsed=false; bOnceMoved=false; ReleaseDC(hWindow,hDC); } CMenuItem::~CMenuItem() { for(int i=0;i<3;i++) for(int j=0;j<3;j++) delete bmpImage[i][j]; for(int k=0;kIsSoundOn()) PlaySound((LPCSTR)IDW_OVER, GameEngine::GetEngine()->GetInstance(), SND_ASYNC | SND_RESOURCE); bOnceMoved=true; //bJustTouched=true; return true; } if(iBeforeMove>=0){ iCurrentImage=iBeforeMove; iBeforeMove=-1; } //bJustTouched=false; bOnceMoved=false; return false; } void CMenuItem::DrawScreen(HDC hDC){ HDC _hOffscreenDC = CreateCompatibleDC(hDC); HBITMAP _hOffscreenBitmap = CreateCompatibleBitmap(hDC,iwidth, iheight); SelectObject(_hOffscreenDC, _hOffscreenBitmap); int iLeft=ix; int iRight=ix+iwidth-30; bmpImage[iCurrentImage][0]->Draw(hDC,iLeft,iy,true); bmpImage[iCurrentImage][2]->Draw(hDC,iRight,iy,true); do{ iLeft+=30; iRight-=30; bmpImage[iCurrentImage][1]->Draw(hDC,iRight,iy,iCurrentImage==0?true:false); bmpImage[iCurrentImage][1]->Draw(hDC,iLeft,iy,iCurrentImage==0?true:false); }while(iLeft+30<=iRight); HBRUSH hWhiteBrush = CreateSolidBrush(RGB(255, 255, 255)); HBRUSH hBrush = (HBRUSH)SelectObject(_hOffscreenDC, hWhiteBrush); Rectangle(_hOffscreenDC,-1,-1,iwidth+1,iheight+1); SelectObject(_hOffscreenDC,hBrush); DeleteObject(hWhiteBrush); //COLORREF clfOld=(COLORREF)SetTextColor(_hOffscreenDC,RGB(0,0,0)); SetBkMode(_hOffscreenDC,TRANSPARENT); HFONT fntRoman; fntRoman=CreateFont(22, 0, 0,0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, GameEngine::GetEngine()->IsEnglish()?"Times New Roman":"DL-Paras."); HFONT fnt=(HFONT)SelectObject(_hOffscreenDC,fntRoman); TextOut(_hOffscreenDC,iheight/2,5,szName,strlen(szName)); //SetTextColor(_hOffscreenDC,clfOld); SelectObject(_hOffscreenDC,fnt); DeleteObject(fntRoman); //HDC hRealDC =hDC;// GameEngine::GetEngine()->getOffScreenDC(); COLORREF crTransColor = RGB(255, 255, 255); TransparentBlt(hDC, ix, iy, iwidth, iheight, _hOffscreenDC, 0, 0,iwidth,iheight, crTransColor); //BitBlt(hRealDC, ix, iy, iwidth, iheight, //_hOffscreenDC, 0, 0,SRCCOPY); DeleteObject(_hOffscreenBitmap); DeleteDC(_hOffscreenDC); //DrawText(hDC,szName,20,&lpRect,0); } bool CMenuItem::IsWithinItem(int x,int y){ if(x>ix && xiy && ySetCollapsed(false); } } }