// MenuGroup1.cpp: implementation of the CMenuGroup class. // ////////////////////////////////////////////////////////////////////// #include "MenuGroup1.h" #define IMGHEIGHT 30 ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CMenuGroup::CMenuGroup() { UINT uiBack=IDB_MBUT_NOR_LEFT; bmpBack=new Bitmap(); iStatebmpBack=0; for(int i=0;i<32;i++){ stMenuItem[i].bmpContent=new Bitmap(); } IsMouseOver=true; } CMenuGroup::~CMenuGroup() { } void CMenuGroup::SetMenuGroup(HDC _hOffDC,int iCols, int iRows,int ix,int iy, int iWidth, char *szContent) { CMenuGroup::_hOffDC=_hOffDC; CMenuGroup::iCols=iCols; CMenuGroup::iRows=iRows; CMenuGroup::ix=ix; CMenuGroup::iy=iy; CMenuGroup::iWidth=iWidth; HINSTANCE hInstance=GameEngine::GetEngine()->GetInstance(); iStatebmpBack=0; for(int i=0;iCreate(_hOffDC,szFile); stMenuItem[i*iCols+j].iState=0; } } bIsExpanded=false; GameEngine::GetEngine()->SetMenuExpanded(false); iSelectedAnswer=-1; HDC hDC =GameEngine::GetEngine()->getOffScreenDC(); DrawScreen(hDC); } bool CMenuGroup::MouseButtonDown(int x, int y, bool bLeft) { if(!bIsExpanded && GameEngine::GetEngine()->IsMenuExpanded()){ return false; } bool bIsWithinMenu=false; if(x>ix && xiy && ySetMenuExpanded(true); HDC hDC =GameEngine::GetEngine()->getOffScreenDC(); DrawScreen(hDC); } if(bIsExpanded){ int iIndex; for(int i=1;i<=iRows;i++){ for(int j=0;jCreate(hDC,5000+(stMenuItem[iIndex].iState)*3,hInstance); if(x>ix+j*iWidth && xiy+i*IMGHEIGHT && ySetCmdMenuMouseDown(true); stMenuItem[iIndex].iState=2; bIsWithinMenu=true; iStatebmpBack=0; } } } if(!bIsWithinMenu){ bIsExpanded=false; GameEngine::GetEngine()->SetMenuExpanded(false); } } return true; } bool CMenuGroup::MouseButtonUp(int x, int y, bool bLeft) { if(!bIsExpanded && GameEngine::GetEngine()->IsMenuExpanded()){ return false; } GameEngine::GetEngine()->SetCmdMenuMouseDown(false); if(x>ix && xiy && ygetOffScreenDC(); DrawScreen(hDC); return true; } if(bIsExpanded){ int iIndex; for(int i=1;i<=iRows;i++){ for(int j=0;jCreate(hDC,5000+(stMenuItem[iIndex].iState)*3,hInstance); if(x>ix+j*iWidth && xiy+i*IMGHEIGHT && ySetCmdMenuMouseDown(true); iSelectedAnswer=iIndex; bIsExpanded=false; GameEngine::GetEngine()->SetMenuExpanded(false); return true; } } } } return false; } bool CMenuGroup::MouseMove(int x, int y,bool bIsChecking) { if(!bIsExpanded && GameEngine::GetEngine()->IsMenuExpanded()){ return false; } if(x>ix && xiy && ygetOffScreenDC(); DrawScreen(hDC,0,0,0,0,bIsChecking); } } else if(IsMouseOver){ IsMouseOver=false; HDC hDC =GameEngine::GetEngine()->getOffScreenDC(); DrawScreen(hDC,0,0,0,0,bIsChecking); } /*bIsExpanded=false; GameEngine::GetEngine()->SetMenuExpanded(false);*/ //Check for the sub menus if(bIsExpanded){ int iIndex; for(int i=1;i<=iRows;i++){ for(int j=0;jCreate(hDC,5000+(stMenuItem[iIndex].iState)*3,hInstance); if(x>ix+j*iWidth && xiy+i*IMGHEIGHT && yIsCmdMenuMouseDown()) stMenuItem[iIndex].iState=2; else stMenuItem[iIndex].iState=1; return true; } else stMenuItem[iIndex].iState=0; } } } if(!bIsExpanded) iStatebmpBack=0; return false; } void CMenuGroup::DrawScreen(HDC hDC,int iPosX,int iPosY,int iLayerX,int iLayerY,bool bIsChecking) { if(!bIsExpanded && GameEngine::GetEngine()->IsMenuExpanded()){ return ; } HWND hWnd=GameEngine::GetEngine()->GetWindow(); HINSTANCE hInstance=GameEngine::GetEngine()->GetInstance(); bmpBack->Create(hDC,5000+iStatebmpBack*3,hInstance); bmpBack->Draw(_hOffDC,ix,iy); bmpBack->Create(hDC,5000+iStatebmpBack*3+1,hInstance); for(int i=5;i<=iWidth-5;i+=5){ bmpBack->Draw(_hOffDC,ix+i,iy); } bmpBack->Draw(_hOffDC,ix+iWidth-10,iy); bmpBack->Create(hDC,5000+iStatebmpBack*3+2,hInstance); bmpBack->Draw(_hOffDC,ix+iWidth-5,iy); if(bIsExpanded){ int iIndex; for(int i=1;i<=iRows;i++){ for(int j=0;jCreate(hDC,5000+(stMenuItem[iIndex].iState)*3,hInstance); bmpBack->Draw(hDC,ix+j*iWidth-iLayerX+iPosX,iy+i*(IMGHEIGHT+2)-iLayerY+iPosY); bmpBack->Create(hDC,5000+(stMenuItem[iIndex].iState)*3+1,hInstance); for(int k=5;k<=iWidth-5;k+=5){ bmpBack->Draw(hDC,ix+j*iWidth-iLayerX+iPosX+k,iy+i*(IMGHEIGHT+2)-iLayerY+iPosY); } bmpBack->Draw(hDC,ix+j*iWidth-iLayerX+iPosX+iWidth-10,iy+i*(IMGHEIGHT+2)-iLayerY+iPosY); bmpBack->Create(hDC,5000+(stMenuItem[iIndex].iState)*3+2,hInstance); bmpBack->Draw(hDC,ix+j*iWidth-iLayerX+iPosX+iWidth-5,iy+i*(IMGHEIGHT+2)-iLayerY+iPosY); DrawCompound(hDC,iIndex,ix+j*iWidth-iLayerX+iPosX,iy+i*(IMGHEIGHT+2)-iLayerY+iPosY); } } } if( bIsChecking && IsMouseOver){ for(int i = 0;iSetEmpty(); } void CMenuGroup::DrawCompound(HDC hDC,int iIndex, int x, int y) { int ibmpWidth=stMenuItem[iIndex].bmpContent->GetWidth(); int ibmpHeight=stMenuItem[iIndex].bmpContent->GetHeight(); HDC hTempDC = CreateCompatibleDC(hDC); HBITMAP _hLayerBitmap = CreateCompatibleBitmap(hDC,ibmpWidth, ibmpHeight); HBITMAP hOldBitmap = (HBITMAP)SelectObject(hTempDC,_hLayerBitmap); HBRUSH hPinkBrush = CreateSolidBrush(RGB(255, 0, 255)); HBRUSH hBrush = (HBRUSH)SelectObject(hTempDC, hPinkBrush); Rectangle(hTempDC,0,0,ibmpWidth, ibmpHeight); SelectObject(hTempDC,hBrush); DeleteObject(hPinkBrush); stMenuItem[iIndex].bmpContent->Draw(hTempDC,0,0,true,RGB(221,221,221)); TransparentBlt(hDC, x+iWidth/2-ibmpWidth/2, y+IMGHEIGHT/2-ibmpHeight/2,ibmpWidth, ibmpHeight, hTempDC, 0, 0, ibmpWidth, ibmpHeight,RGB(255,0,255)); SelectObject(hTempDC,hOldBitmap); DeleteObject(_hLayerBitmap); DeleteDC(hTempDC); } bool CMenuGroup::IsCorrectAnswerGiven() { if(iSelectedAnswer==-1) return false; return stMenuItem[iSelectedAnswer].bAnsw; } bool CMenuGroup::IsAttempted() { if(iSelectedAnswer==-1) return false; else return true; return true; } int CMenuGroup::GetSelectedIndex() { return iSelectedAnswer; } int CMenuGroup::GetCorrectIndex() { for(int i=0;i