// SideBar.cpp: implementation of the CSideBar class. // ////////////////////////////////////////////////////////////////////// #include "SideBar.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CSideBar::CSideBar(int ix,int iy,int iLayerWidth,int iLayerHeight,int iwidth,int iheight,UINT uiBG): CPanel(ix,iy,iwidth,iheight,uiBG){ iLayerX=0; iLayerY=0; CPanel::iLayerHeight=iLayerHeight; CPanel::iLayerWidth=iLayerWidth; HDC hDC=GetDC(GameEngine::GetEngine()->GetWindow()); bmpBackGround=new Bitmap(hDC,IDB_TREE_BG, GameEngine::GetEngine()->GetInstance()); CPanel::ShowPanel(true); canvas=new CCanvas(240,20,540,560,540,560,IDB_TREE_BG_LEFTTOP); enabled=true; textPanel=new CTextPanel(9,20,170,100,IDB_ORGANIC_OUT); textPanel->AddPanelElement("Add New"); textPanel->AddPanelElement("Edit"); textPanel->AddPanelElement("Delete"); imagePanel=new CImagePanel(9,100,170,370,IDB_INORGANIC_OUT); imagePanel->SetCollapse(); imagePanel->AddElements(IDB_CMPD_BR2,INORG_COMPOUNDS); conditionPanel=new CImagePanel(9,490,170,370,IDB_CONDITION_OUT); conditionPanel->SetCollapse(); conditionPanel->AddElements(IDB_CNDT_ACIDIC,ADDN_CONDITIONS); reactionPanel=new CTextPanel(9,880,170,120,IDB_REACTION_OUT); reactionPanel->AddPanelElement("Start"); reactionPanel->AddPanelElement("Clear Last Result set"); reactionPanel->AddPanelElement("Clear All Results"); reactionPanel->AddPanelElement("Clear All"); helpPanel=new CTextPanel(9,900,170,80,IDB_HELP_OUT); //helpPanel->SetCollapse(); helpPanel->AddPanelElement("Help"); helpPanel->AddPanelElement("About"); controlBox=new CControlBox(20,20,120,560,120,560,IDB_TREE_BG_LEFTTOP); controlBox->setEnable(false); //ReleaseDC(GameEngine::GetEngine()->GetWindow(),hDC); } CSideBar::~CSideBar() { } void CSideBar::DrawScreen(HDC hDC){ controlBox->DrawScreen(hDC); if(!enabled) return; canvas->DrawScreen(hDC); HDC _hLayerDC = CreateCompatibleDC(hDC); HBITMAP _hLayerBitmap = CreateCompatibleBitmap(hDC,iLayerWidth, iLayerHeight); SelectObject(_hLayerDC, _hLayerBitmap); //do painting int i=0; for(;i<=iLayerWidth/90;i++){ for(int j=0;j<=iLayerHeight/90;j++){ bmpBackGround->Draw(_hLayerDC,i*90,j*90); } } textPanel->DrawScreen(_hLayerDC); imagePanel->setLimit(textPanel->getLimit()+25); imagePanel->DrawScreen(_hLayerDC); conditionPanel->setLimit(imagePanel->getLimit()+25); conditionPanel->DrawScreen(_hLayerDC); reactionPanel->setLimit(conditionPanel->getLimit()+25); reactionPanel->DrawScreen(_hLayerDC); helpPanel->setLimit(reactionPanel->getLimit()+25); helpPanel->DrawScreen(_hLayerDC); int lowerLimit=helpPanel->getLimit(); lowerLimit>540?iLayerHeight=lowerLimit+20:iLayerHeight=560; if(iLayerHeight==560) iLayerY=0; CPanel::DrawScreen(_hLayerDC); DeleteObject(_hLayerBitmap); DeleteDC(_hLayerDC); } void CSideBar::MouseButtonDown(int x, int y, bool bLeft,WPARAM wParam) { if(controlBox->MouseButtonDown(x,y,bLeft,wParam)){ enabled=true; controlBox->setEnable(false); canvas->AddNewCompound(); } if(!enabled) return; canvas->MouseButtonDown(x,y,bLeft); textPanel->MouseButtonDown(x-GetX()+iLayerX,y-GetY()+iLayerY,bLeft); imagePanel->MouseButtonDown(x-GetX()+iLayerX,y-GetY()+iLayerY,bLeft); conditionPanel->MouseButtonDown(x-GetX()+iLayerX,y-GetY()+iLayerY,bLeft); reactionPanel->MouseButtonDown(x-GetX()+iLayerX,y-GetY()+iLayerY,bLeft); helpPanel->MouseButtonDown(x-GetX()+iLayerX,y-GetY()+iLayerY,bLeft); CPanel::MouseButtonDown(x,y,bLeft); } BOOL CALLBACK SetAboutProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: EndDialog(hwndDlg, wParam); return TRUE; } } return FALSE; } void CSideBar::MouseButtonUp(int x, int y, bool bLeft) { controlBox->MouseButtonUp(x,y,bLeft); if(!enabled) return; int index; if((index=textPanel->MouseButtonUp(x-GetX()+iLayerX,y-GetY()+iLayerY,bLeft))==0){ if(!canvas->IsEditable()){ MessageBox(GameEngine::GetEngine()->GetWindow(),"please clear the result. Reaction->Clear Results","Info",MB_OK); return; } int i=GameEngine::GetEngine()->getCountCompounds(); GameEngine::GetEngine()->setCountCompounds(i+1); enabled=false; controlBox->setEnable(true); } else if(index==1){ if(!canvas->IsEditable()){ MessageBox(GameEngine::GetEngine()->GetWindow(),"please clear the result before add compounds. Reaction->Clear Results","Info",MB_OK); return; } if(!canvas->deploySelected()){ //MessageBox(GameEngine::GetEngine()->GetWindow(),"Please select a compound to edit","Information",MB_OK); }else{ controlBox->getReadyForACompound(); enabled=false; controlBox->setEnable(true); } } else if(index==2){ canvas->deleteSelected(); } canvas->MouseButtonUp(x,y,bLeft); if((index=imagePanel->MouseButtonUp(x-GetX()+iLayerX,y-GetY()+iLayerY,bLeft))>=0){ if(!canvas->IsEditable()){ MessageBox(GameEngine::GetEngine()->GetWindow(),"please clear the result before add compounds. Reaction->Clear Results","Info",MB_OK); return; } canvas->addInorgCompound(index); } if((index=conditionPanel->MouseButtonUp(x-GetX()+iLayerX,y-GetY()+iLayerY,bLeft))>=0){ if(!canvas->IsEditable()){ MessageBox(GameEngine::GetEngine()->GetWindow(),"please clear the result before add condtions. Reaction->Clear Results","Info",MB_OK); return; } canvas->addCondition(index); } if((index=reactionPanel->MouseButtonUp(x-GetX()+iLayerX,y-GetY()+iLayerY,bLeft))>=0){ if(index==0){ if(!canvas->IsEditable()){ MessageBox(GameEngine::GetEngine()->GetWindow(),"please clear the result before further reactions. Reaction->Clear Results","Info",MB_OK); return; } canvas->startReaction(); } else if(index==1){ canvas->clearLastResult(); } else if(index==2){ canvas->clearResults(); } else if(index==3){ canvas->clearAll(); } } if((index=helpPanel->MouseButtonUp(x-GetX()+iLayerX,y-GetY()+iLayerY,bLeft))==0){ ShellExecute(GameEngine::GetEngine()->GetWindow(), "open", "Simulator.chm", NULL, NULL, SW_SHOWNORMAL); } else if(index==1){ if ((int)DialogBox(GameEngine::GetEngine()->GetInstance(), MAKEINTRESOURCE(IDD_DIALOG_ABOUT), GameEngine::GetEngine()->GetWindow(), (DLGPROC)SetAboutProc)==IDOK){ } } CPanel::MouseButtonUp(x,y,bLeft); } void CSideBar::MouseMove(int x, int y) { controlBox->MouseMove(x,y); if(!enabled) return; canvas->MouseMove(x,y); textPanel->MouseMove(x-GetX()+iLayerX,y-GetY()+iLayerY); imagePanel->MouseMove(x-GetX()+iLayerX,y-GetY()+iLayerY); conditionPanel->MouseMove(x-GetX()+iLayerX,y-GetY()+iLayerY); reactionPanel->MouseMove(x-GetX()+iLayerX,y-GetY()+iLayerY); helpPanel->MouseMove(x-GetX()+iLayerX,y-GetY()+iLayerY); CPanel::MouseMove(x,y); }