// Content.cpp: implementation of the CContent class. // ////////////////////////////////////////////////////////////////////// #include "Content.h" //#include "Vfw.h" #include "Digitalv.h" #define MARGIN 50 #define RIGHTMARGIN 40 #define SUBTITILETEXT 25 #define IMGHEIGHT 32 #define CORRECTIONSIZE 20 ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CContent::CContent(int ix,int iy,int iwidth,int iheight,int iLayerWidth,int iLayerHeight,UINT uiBG): CPanel(ix,iy,iwidth,iheight,uiBG) { iLayerX=0; iLayerY=0; CContent::iLayerWidth=iLayerWidth; CContent::iLayerHeight=iLayerHeight; pElements=new Bitmap*[32]; pMenuGroups=new CMenuGroup*[32]; HWND hwnd=GameEngine::GetEngine()->GetWindow(); HDC hDC=GetDC(hwnd); for(int i=0;i<32;i++){ pElements[i]=new Bitmap(hDC,3000+i,GameEngine::GetEngine()->GetInstance()); } for(int i = 0;i<32;i++){ pMenuGroups[i]=new CMenuGroup(); } pAnswElements=(struct PosElements*)malloc(NUMBEROF_FILLS_PER_REACTION*sizeof(struct PosElements)); transQuestion=(struct TransformationQuestion*)malloc(NUMBEROF_TRANSFORMATION_QUESTION*sizeof(struct TransformationQuestion)); transMenu=(struct TransformationMenu*)malloc(NUMBEROF_TRANSFORMATION_QUESTION*sizeof(struct TransformationMenu)); //bUpNoAnsPnl=false; bmpBackGround=new Bitmap(hDC,IDB_TREE_BG,GameEngine::GetEngine()->GetInstance()); for(int i = 0;i<8;i++) pTglButton[i]=new CToggleButton(); iCurPosition[0]=0; iCurIndex=0; test=0; iElementCount=0; iShowingTextElement=0; _hOffDC = CreateCompatibleDC(hDC); SetBkMode(_hOffDC,TRANSPARENT); //hTextDC=CreateCompatibleDC(hDC); //HBITMAP _hTextBitmap = CreateCompatibleBitmap(hDC,200, 20); //SelectObject(_hOffDC,_hTextBitmap); //SetBkMode(hTextDC,TRANSPARENT); bmpRight1=new Bitmap(hDC,IDB_RIGHT1,GameEngine::GetEngine()->GetInstance()); bmpWrong1=new Bitmap(hDC,IDB_WRONG1,GameEngine::GetEngine()->GetInstance()); bmpArrow1=new Bitmap(hDC,IDB_ARROW1,GameEngine::GetEngine()->GetInstance()); bmpRight2=new Bitmap(hDC,IDB_RIGHT2,GameEngine::GetEngine()->GetInstance()); bmpWrong2=new Bitmap(hDC,IDB_WRONG2,GameEngine::GetEngine()->GetInstance()); bmpQues2=new Bitmap(hDC,IDB_QUES2,GameEngine::GetEngine()->GetInstance()); bUpNoAnsPnl=false; ReleaseDC(hwnd,hDC); for(int i = 0;i<2;i++){ buttonHome[i]=new CButton(); buttonHome[i]->SetImage(IDB_NAVIG_HOME_NORMAL); buttonNext[i]=new CButton(); buttonNext[i]->SetImage(IDB_NAVIG_NEXT_NORMAL); buttonPrev[i]=new CButton(); buttonPrev[i]->SetImage(IDB_NAVIG_PREV_NORMAL); } butPrevQ=new CButton(); butPrevQ->SetImage(IDB_NAVIG_PREVQ_NORMAL); butNextQ=new CButton(); butNextQ->SetImage(IDB_NAVIG_NEXTQ_NORMAL); butStart=new CButton(); butStart->SetImage(IDB_NAVIG_START_NORMAL); butCheck=new CButton(); butCheck->SetImage(IDB_NAVIG_CHECK_NORMAL); bmp=new Bitmap(); bmpAbove=new Bitmap(); bmpBelow=new Bitmap(); pPosElements=NULL; MouseOvAtAnsw=-1; isFromExercise=false; addToProfile=true; } CContent::~CContent() { for(int i=0;i<8;i++){ delete pElements[i]; } for(int i = 0;i<2;i++){ delete buttonHome[i]; delete buttonNext[i]; delete buttonPrev[i]; } delete bmpBackGround; DeleteDC(_hOffDC); delete bmpAbove; delete bmpBelow; delete bmp; free(pAnswElements); free(transQuestion); free(transMenu); } /**Check and read the file if it is new*/ void CContent::ChangeTo(char *szTopic,int iIndex,bool bUpdate){ //ClearLast(); char szFileName[32]; wsprintf(szFileName,"Data//%s%s.txt",szTopic,GameEngine::GetEngine()->IsEnglish()?"":"_sin"); if(strcmp(szTopic,CContent::szTopic)!=0 || bUpdate){ hFile = CreateFile(TEXT(szFileName), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL); bIsCheckingAnswers=false; DWORD dwBytesRead; int i=0; for(;szContent[i]!=(char)180 && i<32768;i++){ ReadFile(hFile,szContent+i,1,&dwBytesRead,NULL); } szContent[i++]='\0'; CloseHandle(hFile); strcpy(CContent::szTopic,szTopic); iSetCursor=iCurPosition[iIndex]; SetLayerY(iSetCursor); iNextToRead=0; IsEndPage=0; if(GameEngine::GetEngine()->IsExercise()) GameEngine::GetEngine()->SetExercise(false); GameEngine::GetEngine()->ReadingFile(szTopic); isFromExercise=false; addToProfile=true; Update(); } else{ iSetCursor=iCurPosition[iIndex]; SetLayerY(iSetCursor); } //SetLayerY(iSetCursor); /*char szText[64]; wsprintf(szText,"%d",iSetCursor); MessageBox(GameEngine::GetEngine()->GetWindow(),szText,"hi all",MB_OK);*/ } void CContent::Update(bool bSetCursor){ SetAllButtonNotReady(); ptCurPosition.x=MARGIN; ptCurPosition.y=10; iShowingTextElement=0; iCurIndex=0; iAnswCount=0; iMenuGroups=0; iElementCount=0; butCheck->SetReady(false); if(iNextToRead && IsQuesion||IsEndPage){ ptCurPosition.y=0; ptCurPosition.x=MARGIN; if(iQuesitions>0){ iNextToRead=iFlagPrevReactions[iQuesitions]; --iQuesitions; ContinueToNextQues(); } else{ iNextToRead=0; iQuesitions=0; iRightAnswers=0; Manager(); } } else{ iQuesitions=0; iRightAnswers=0; Manager(); } if(bSetCursor){ //SetLayerY(iSetCursor); } else{ SetLayerY(0); } char szText[64]; wsprintf(szText,"%d",iNextToRead); } void CContent::Manager(){ test++; char szCommand[8]; //szCommand=new char[5]; for(int i=0;i<4;i++){ szCommand[i]=GetChar(); } szCommand[4]='\0'; //MessageBox(GameEngine::GetEngine()->GetWindow(),szCommand,"hi all",MB_OK); if(!strcmp(szCommand,"CONF")){ ConfManager(); } else if(!strcmp(szCommand,"EXER")){ SimpleExerciseManager(); } else if(!strcmp(szCommand,"ANSW")){ AnswerManager(); } else if(!strcmp(szCommand,"QUES")){ QuestionManager(); } else if(!strcmp(szCommand,"TRNS")){ TransformationManager(); } else if(!strcmp(szCommand,"ENDQ")){ ManagerFinalizingAnswers(); } else if(!strcmp(szCommand,"TEXT")){ TextManager(); } else if(!strcmp(szCommand,"CMPD")){ earlierX=ptCurPosition.x; aboveElementHeight=10; CompoundManager(); } else if(!strcmp(szCommand,"RACT")){ ReactionManager(); } else if(!strcmp(szCommand,"TRGT")){ iCurIndex++; iCurPosition[iCurIndex]=ptCurPosition.y; Manager(); } else if(!strcmp(szCommand,"ENDP")){ iNextToRead=0; //if(iLayerHeight>800) //iLayerHeight=ptCurPosition.y+100; iShowingTextElement=0; SetNavigationButtons(); //just quit //break; char szText[64]; wsprintf(szText,"%d",GetX()); //MessageBox(GameEngine::GetEngine()->GetWindow(),szText,"hi all",MB_OK); } //MessageBox(GameEngine::GetEngine()->GetWindow(),szCommand,"hi all",MB_OK); //delete szCommand; } void CContent::ConfManager(){ GameEngine::GetEngine()->SetLast(); IsQuesion=false; char szHeight[8]; for(int i=0;i<5;i++){ szHeight[i]=GetChar(); } szHeight[5]='\0'; iLayerHeight= atoi(szHeight); CreateNewPage(); int i=0; while(true){ szPrevFile[i]=GetChar(); if(szPrevFile[i++]==(char)172) break; } szPrevFile[--i]='\0'; i=0; while(true){ szNextFile[i]=GetChar(); if(szNextFile[i++]==(char)172) break; } szNextFile[--i]='\0'; Manager(); } void CContent::TextManager(){ bool bKeepOnGoin=true; bool bBold=false; bool bItalic=false; bool bUnderline=false; COLORREF clrFont=RGB(0,0,0); HFONT fntRoman; while(bKeepOnGoin){ char chData=GetChar(); if(chData==(char)179){ Manager(); break; } char szSubCommand[5]; szSubCommand[0]=chData; for(int i=1;i<4;i++){ szSubCommand[i]=GetChar(); } szSubCommand[4]='\0'; if(!strcmp(szSubCommand,"HEAD")){ char szTitle[128]; int i=0; while(true){ szTitle[i]=GetChar(); if(szTitle[i++]==(char)172) break; } szTitle[--i]='\0'; fntRoman=CreateFont(30, 0, 0,0, FW_BOLD, FALSE, TRUE, 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(_hOffDC,fntRoman); TEXTMETRIC textMextrics; GetTextMetrics(_hOffDC,&textMextrics); //int iMaxCharAmount=GetWidth()/textMextrics.tmAveCharWidth; //int iOffset=(iMaxCharAmount-i)*textMextrics.tmAveCharWidth; ptCurPosition.y=10; SetTextColor(_hOffDC,RGB(0,0,0)); SetBkColor(_hOffDC,RGB(255,255,255)); TextOut(_hOffDC,/*iOffset/2-10*/iLayerWidth/3,ptCurPosition.y,szTitle,i); ptCurPosition.y+=textMextrics.tmHeight; //TextOut(_hOffDC,iOffset/2-10+(i+1)*textMextrics.tmAveCharWidth,ptCurPosition.y,szTitle,i); SelectObject(_hOffDC,fnt); DeleteObject(fntRoman); //MessageBox(GameEngine::GetEngine()->GetWindow(),szTitle,"hi all",MB_OK); } else if(!strcmp(szSubCommand,"TITL")){ char szTitle[128]; char szTab[8]; int iTab; int i=0; while(true){ szTitle[i]=GetChar(); if(szTitle[i++]==(char)172) break; } szTitle[--i]='\0'; for(int j=0;j<2;j++){ szTab[j]=GetChar(); } szTab[2]='\0'; iTab=atoi(szTab); fntRoman; fntRoman=CreateFont(SUBTITILETEXT, 0, 0,0, FW_MEDIUM, FALSE, TRUE, 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(_hOffDC,fntRoman); TextOut(_hOffDC,MARGIN+iTab,ptCurPosition.y,szTitle,i); NewLine(); //TextOut(_hOffDC,iOffset/2-10+(i+1)*textMextrics.tmAveCharWidth,ptCurPosition.y,szTitle,i); SelectObject(_hOffDC,fnt); DeleteObject(fntRoman); } else if(!strcmp(szSubCommand,"PLAN")){ bBold=false; bItalic=false; bUnderline=false; clrFont=RGB(0,0,0); GetChar(); //ptCurPosition.x=MARGIN; NewLine(); } else if(!strcmp(szSubCommand,"CIMG")){ char szName[1024]; int iCurOffset[2]; for(int i=0;i<2;i++){ for(int j=0;j<3;j++){ szName[j]=GetChar(); } szName[3]='\0'; iCurOffset[i]=atoi(szName); } int i=0; while(true){ szName[i]=GetChar(); if(szName[i++]==(char)172) break; } szName[--i]='\0'; char szFileName[64]; wsprintf(szFileName,"Images\\Compounds\\%s.bmp",szName); ptCurPosition.y+=iCurOffset[0]; bmp->Create(_hOffDC,szFileName); if(ptCurPosition.x+bmp->GetWidth()>(iLayerWidth-RIGHTMARGIN)){ NewLine(); } bmp->Draw(_hOffDC,ptCurPosition.x,ptCurPosition.y,true); ptCurPosition.x+=bmp->GetWidth(); ptCurPosition.y+=iCurOffset[1]; bmp->SetEmpty(); } else{ //This is the part seperate for the plane text if(!strcmp(szSubCommand,"BOLD")){ if(bBold){ bBold=false; //ptCurPosition.y+=1; } else{ bBold=true; //ptCurPosition.y-=1; } } else if(!strcmp(szSubCommand,"ITAL")){ bItalic?bItalic=false:bItalic=true; } else if(!strcmp(szSubCommand,"UNLN")){ bUnderline?bUnderline=false:bUnderline=true; } else if(!strcmp(szSubCommand,"COLR")){ int iColor[3]; for(int i=0;i<3;i++){ char szNo[4]; GetChar(); //skip one char for(int j=0;j<3;j++){ szNo[j]=GetChar(); } szNo[3]='\0'; iColor[i]=atoi(szNo); } clrFont=RGB(iColor[0],iColor[1],iColor[2]); SetTextColor(_hOffDC,clrFont); SetBkColor(_hOffDC,RGB(255,255,255)); } else if(!strcmp(szSubCommand,"LINE")){ fntRoman=CreateFont(20, 0, 0,0, bBold?FW_BOLD:FW_MEDIUM, bItalic, bUnderline, 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(_hOffDC,fntRoman); NewLine(); SelectObject(_hOffDC,fnt); DeleteObject(fntRoman); } else if(!strcmp(szSubCommand,"PINT")){ fntRoman=CreateFont(20, 0, 0,0, bBold?FW_BOLD:FW_MEDIUM, bItalic, bUnderline, 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(_hOffDC,fntRoman); NewLine(); ptCurPosition.x=MARGIN+20; SelectObject(_hOffDC,fnt); DeleteObject(fntRoman); } //This is the part that draw the plane text fntRoman=CreateFont(20, 0, 0,0, bBold?FW_BOLD:FW_MEDIUM, bItalic, bUnderline, 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(_hOffDC,fntRoman); TEXTMETRIC textMextrics; GetTextMetrics(_hOffDC,&textMextrics); int iStartFrom=0; char szLine[128]; bool bRunningForText=true; while(bRunningForText){ int iCharsOfLine=iStartFrom; int iAfterLastSpace=0; while(true){ char cNext=GetChar(); if(cNext==(char)172){ szLine[iCharsOfLine]='\0'; TextOut(_hOffDC,ptCurPosition.x,ptCurPosition.y,szLine,iCharsOfLine); ptCurPosition.x=ptCurPosition.x+(iCharsOfLine==0?0:iCharsOfLine+1)*textMextrics.tmAveCharWidth; bRunningForText=false; break; } szLine[iCharsOfLine]=cNext; if (szLine[iCharsOfLine]==' ') iAfterLastSpace=iCharsOfLine+1; if(iCharsOfLine*textMextrics.tmAveCharWidth>(iLayerWidth-RIGHTMARGIN-10-ptCurPosition.x)){ //at the end of the line char szBackUp[64]; int j=0; for(int i=iAfterLastSpace;i<=iCharsOfLine;i++){ szBackUp[j++]=szLine[i]; } szLine[iAfterLastSpace-1]='\0'; TextOut(_hOffDC,ptCurPosition.x,ptCurPosition.y,szLine,iAfterLastSpace-1); NewLine(); int i = 0; for(;iDraw(_hOffDC,iElement[1]+ptStartPos.x,iElement[2]+ptStartPos.y,true); } else if(chData=='B'){ ReadFile(hFileC,&chData,1,&dwBytesRead,NULL); //skip one //Read the Bond int iBonds[5]; char szNumber[8]; for(int i=0;i<5;i++){ int j=0; while(true){ ReadFile(hFileC,&chData,1,&dwBytesRead,NULL); if(chData==':') break; else szNumber[j++]=chData; } szNumber[j]='\0'; iBonds[i]=atoi(szNumber); } if(!bOnlyElements){ POINT ptStartLn; POINT ptEndLn; ptStartLn.x=iBonds[1]+ptStartPos.x; ptStartLn.y=iBonds[2]+ptStartPos.y; ptEndLn.x=iBonds[3]+ptStartPos.x; ptEndLn.y=iBonds[4]+ptStartPos.y; DrawBond(_hOffDC,iBonds[0],ptStartLn,ptEndLn); } } else if(chData=='S'){ ReadFile(hFileC,&chData,1,&dwBytesRead,NULL); //skip one //Read the size int iSizes[2]; char szSize[8]; for(int i=0;i<2;i++){ int j=0; while(true){ ReadFile(hFileC,&chData,1,&dwBytesRead,NULL); if(chData==':') break; else szSize[j++]=chData; } szSize[j]='\0'; iSizes[i]=atoi(szSize); } ptSize.x=iSizes[0]; ptSize.y=iSizes[1]; if(ptCurPosition.x+ptSize.x>iLayerWidth && !bOnlyElements){ NewLine(); if(bStartWithNewLine) ptCurPosition.x=MARGIN; else ptCurPosition.x=earlierX; if(ptCurPosition.x+ptSize.x>iLayerWidth) ptCurPosition.x=MARGIN; ptCurPosition.y+=aboveElementHeight/2+iSizes[1]/2; } ptStartPos.x=ptCurPosition.x; ptStartPos.y=ptCurPosition.y-iSizes[1]/2; int j=0; while(true){ ReadFile(hFileC,&chData,1,&dwBytesRead,NULL); if(chData==':') break; else szName[j++]=chData; } szName[j]='\0'; } } CloseHandle(hFileC); if(bOnlyElements){ aboveElementX=ptStartPos.x; aboveElementY=ptCurPosition.y; aboveElementWidth=ptSize.x; aboveElementHeight=ptSize.y; ptCurPosition.x+=ptSize.x; iElementCount++; pPosElements=(struct PosElements*)realloc(pPosElements,iElementCount*sizeof(struct PosElements)); struct PosElements *TempElements=&pPosElements[iElementCount-1]; strcpy(TempElements->szName,szName); TempElements->ptStart.x=ptStartPos.x; TempElements->ptStart.y=ptStartPos.y; TempElements->ptEnd.x=ptStartPos.x+ptSize.x; TempElements->ptEnd.y=ptStartPos.y+ptSize.y; } //Manager(); } void CContent::ReactionManager(){ bool bKeepOnGoin=true; bool bArrowForward=true; iNumberOfFills=0; iNumberOfOptions=0; iNumberOfCorrectFills=0; iMenuGroups=0; while(bKeepOnGoin){ char chData=GetChar(); if(chData==(char)179){ Manager(); break; } char szSubCommand[5]; szSubCommand[0]=chData; for(int i=1;i<4;i++){ szSubCommand[i]=GetChar(); } szSubCommand[4]='\0'; if(!strcmp(szSubCommand,"CMPD")){ char szName[1024]; int iCurOffset[2]; for(int i=0;i<2;i++){ for(int j=0;j<3;j++){ szName[j]=GetChar(); } szName[3]='\0'; iCurOffset[i]=atoi(szName); } int i=0; while(true){ szName[i]=GetChar(); if(szName[i++]==(char)172) break; } szName[--i]='\0'; ptCurPosition.y+=iCurOffset[0]; if(!strcmp(szName,"SQRE")){ int i=0; //read the offset int iOffSet[4]; for(int i = 0;i<4;i++){ char szOffSet[4]; for(int j=0;j<3;j++) szOffSet[j]=GetChar(); szOffSet[3]='\0'; iOffSet[i]=atoi(szOffSet); } i=0; while(true){ szName[i]=GetChar(); if(szName[i++]==(char)172) break; } szName[--i]='\0'; char szFileName[64]; wsprintf(szFileName,"Data\\CElements\\%s.txt",szName); HANDLE hFileC = CreateFile(TEXT(szFileName), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL); char chData; DWORD dwBytesRead; for(int i = 0;i<3;i++) ReadFile(hFileC,&chData,1,&dwBytesRead,NULL); //skip three //Read the size int iSizes[2]; char szSize[8]; for(int i=0;i<2;i++){ int j=0; while(true){ ReadFile(hFileC,&chData,1,&dwBytesRead,NULL); if(chData==':') break; else szSize[j++]=chData; } szSize[j]='\0'; iSizes[i]=atoi(szSize); iSizes[i]+=iOffSet[i+2]; } ptCurPosition.x+=iOffSet[0]; ptCurPosition.y+=iOffSet[1]; CloseHandle(hFileC); pAnswElements[iNumberOfFills].ptStart.x=ptCurPosition.x; pAnswElements[iNumberOfFills].ptStart.y=ptCurPosition.y-iSizes[1]/2; pAnswElements[iNumberOfFills].ptEnd.x=ptCurPosition.x+iSizes[0]; pAnswElements[iNumberOfFills].ptEnd.y=ptCurPosition.y+iSizes[1]/2; strcpy(pAnswElements[iNumberOfFills].szName,szName); //MessageBox(GameEngine::GetEngine()->GetWindow(),transQuestion[iQuesitions].szGivenAnswer[iNumberOfFills],"bye",MB_OK); if(MouseOvAtAnsw==iNumberOfFills){ HPEN hGridPen = CreatePen(PS_SOLID, 1, RGB(244,244,244));//(255, 204, 153)); HPEN hPen = (HPEN)SelectObject(_hOffDC, hGridPen); HBRUSH hAshBrush = CreateSolidBrush(RGB(222, 222, 222)); HBRUSH hBrush = (HBRUSH)SelectObject(_hOffDC, hAshBrush); Rectangle(_hOffDC,ptCurPosition.x,ptCurPosition.y-iSizes[1]/2, ptCurPosition.x+iSizes[0],ptCurPosition.y+iSizes[1]/2); SelectObject(_hOffDC,hBrush); DeleteObject(hAshBrush); MoveToEx(_hOffDC,pAnswElements[MouseOvAtAnsw].ptStart.x,pAnswElements[MouseOvAtAnsw].ptEnd.y,NULL); LineTo(_hOffDC,pAnswElements[MouseOvAtAnsw].ptStart.x,pAnswElements[MouseOvAtAnsw].ptStart.y); LineTo(_hOffDC,pAnswElements[MouseOvAtAnsw].ptEnd.x,pAnswElements[MouseOvAtAnsw].ptStart.y); HPEN hGridPen2 = CreatePen(PS_SOLID, 1, RGB(100,100,100));//(255, 204, 153)); SelectObject(_hOffDC, hGridPen2); DeleteObject(hGridPen); MoveToEx(_hOffDC,pAnswElements[MouseOvAtAnsw].ptEnd.x,pAnswElements[MouseOvAtAnsw].ptStart.y,NULL); LineTo(_hOffDC,pAnswElements[MouseOvAtAnsw].ptEnd.x,pAnswElements[MouseOvAtAnsw].ptEnd.y); LineTo(_hOffDC,pAnswElements[MouseOvAtAnsw].ptStart.x,pAnswElements[MouseOvAtAnsw].ptEnd.y); ; SelectObject(_hOffDC,hPen); DeleteObject(hGridPen2); POINT ptMiddle; ptMiddle.x=(pAnswElements[MouseOvAtAnsw].ptStart.x+pAnswElements[MouseOvAtAnsw].ptEnd.x)/2; ptMiddle.y=(pAnswElements[MouseOvAtAnsw].ptStart.y+pAnswElements[MouseOvAtAnsw].ptEnd.y)/2; char szFileName[64]; wsprintf(szFileName,"Data\\CElements\\%s.txt",pAnswElements[MouseOvAtAnsw].szName); SetAnswElements(szFileName,false,ptMiddle); SetAnswElements(szFileName,true,ptMiddle); } else{ if(bIsCheckingAnswers){ int xCors=ptCurPosition.x+iSizes[0]-CORRECTIONSIZE; int yCors=ptCurPosition.y+iSizes[1]/2-CORRECTIONSIZE; if(strcmp(transQuestion[iQuesitions].szGivenAnswer[iNumberOfFills], szName)==0) bmpRight2->Draw(_hOffDC,xCors,yCors,true); else if(transQuestion[iQuesitions].szGivenAnswer[iNumberOfFills][0]==0) bmpQues2->Draw(_hOffDC,xCors,yCors,true); else bmpWrong2->Draw(_hOffDC,xCors,yCors,true); } if(transQuestion[iQuesitions].szGivenAnswer[iNumberOfFills][0]!=0){ POINT ptMiddle; ptMiddle.x=(pAnswElements[iNumberOfFills].ptStart.x+pAnswElements[iNumberOfFills].ptEnd.x)/2; ptMiddle.y=(pAnswElements[iNumberOfFills].ptStart.y+pAnswElements[iNumberOfFills].ptEnd.y)/2; wsprintf(szFileName,"Data\\CElements\\%s.txt", transQuestion[iQuesitions].szGivenAnswer[iNumberOfFills]); SetAnswElements(szFileName,false,ptMiddle); SetAnswElements(szFileName,true,ptMiddle); } else{ HPEN hGridPen = CreatePen(PS_SOLID, 1, RGB(200,200,200));//(255, 204, 153)); HPEN hPen = (HPEN)SelectObject(_hOffDC, hGridPen); MoveToEx(_hOffDC,ptCurPosition.x,ptCurPosition.y-iSizes[1]/2,NULL); LineTo(_hOffDC,ptCurPosition.x+iSizes[0],ptCurPosition.y-iSizes[1]/2); LineTo(_hOffDC,ptCurPosition.x+iSizes[0],ptCurPosition.y+iSizes[1]/2); LineTo(_hOffDC,ptCurPosition.x,ptCurPosition.y+iSizes[1]/2); LineTo(_hOffDC,ptCurPosition.x,ptCurPosition.y-iSizes[1]/2); SelectObject(_hOffDC,hPen); DeleteObject(hGridPen); } } aboveElementX=ptCurPosition.x; aboveElementY=ptCurPosition.y; aboveElementWidth=iSizes[0]; aboveElementHeight=iSizes[1]; iNumberOfFills++; strcpy(szNamesOfOption[iNumberOfOptions],szName); iNumberOfOptions++; } else{ char szFileName[1024]; wsprintf(szFileName,"Data\\CElements\\%s.txt",szName); earlierX=aboveElementX; SetElements(szFileName,false); SetElements(szFileName,true); } ptCurPosition.y+=iCurOffset[1]; } else if(!strcmp(szSubCommand,"ADTN")){ char szName[1024]; int i=0; while(true){ szName[i]=GetChar(); if(szName[i++]==(char)172) break; } szName[--i]='\0'; strcpy(szNamesOfOption[iNumberOfOptions],szName); iNumberOfOptions++; } else if(!strcmp(szSubCommand,"CIMG")){ char szName[1024]; int iCurOffset[2]; for(int i=0;i<2;i++){ for(int j=0;j<3;j++){ szName[j]=GetChar(); } szName[3]='\0'; iCurOffset[i]=atoi(szName); } int i=0; while(true){ szName[i]=GetChar(); if(szName[i++]==(char)172) break; } szName[--i]='\0'; char szFileName[1024]; wsprintf(szFileName,"Images\\Compounds\\%s.bmp",szName); ptCurPosition.y+=iCurOffset[0]; aboveElementX=ptCurPosition.x; aboveElementY=ptCurPosition.y; bmp->Create(_hOffDC,szFileName); aboveElementWidth=bmp->GetWidth(); aboveElementHeight=bmp->GetHeight(); if(ptCurPosition.x+bmp->GetWidth()>(iLayerWidth-RIGHTMARGIN)){ NewLine(); } bmp->Draw(_hOffDC,ptCurPosition.x,ptCurPosition.y-bmp->GetHeight()/2,true); ptCurPosition.x+=bmp->GetWidth(); ptCurPosition.y+=iCurOffset[1]; } else if(!strcmp(szSubCommand,"ARRW")){ char szName[1024]; int infoArrow[3]; for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ szName[j]=GetChar(); } szName[3]='\0'; infoArrow[i]=atoi(szName); } char szFilesAbove[32]; char szFileName[64]; bool bIsButtonBelow,bIsButtonAbove; int iBtnWidth[2]; char szListAbove[128],szListBelow[128]; int iArrangeAbove[2],iArrangeBelow[2]; POINT ptAbove,ptBelow; int i=0; while(true){ szFilesAbove[i]=GetChar(); if(szFilesAbove[i]==(char)172){ break; } i++; } szFilesAbove[i]='\0'; if(!strcmp(szFilesAbove,"BTTN")){ bIsButtonAbove=true; char szWidth[8]; for(int i=0;i<2;i++){ szWidth[i]=GetChar(); } szWidth[2]='\0'; iBtnWidth[0]=atoi(szWidth); for(int i = 0;i<2;i++){ szWidth[0]=GetChar(); szWidth[1]='\0'; iArrangeAbove[i]=atoi(szWidth); } i=0; while(true){ szListAbove[i]=GetChar(); if(szListAbove[i++]==(char)172) break; } szListAbove[--i]='\0'; } else if(strcmp(szFilesAbove,"NULL")!=0){ wsprintf(szFileName,"Images\\Compounds\\%s.bmp",szFilesAbove); bmpAbove->Create(_hOffDC,szFileName); bIsButtonAbove=false; } else{ bmpAbove->SetEmpty(); bIsButtonAbove=false; } char szFilesBelow[32]; i=0; while(true){ szFilesBelow[i]=GetChar(); if(szFilesBelow[i]==(char)172){ break; } i++; } szFilesBelow[i]='\0'; if(!strcmp(szFilesBelow,"BTTN")){ bIsButtonBelow=true; char szWidth[8]; for(int i=0;i<2;i++){ szWidth[i]=GetChar(); } szWidth[2]='\0'; iBtnWidth[1]=atoi(szWidth); for(int i = 0;i<2;i++){ szWidth[0]=GetChar(); szWidth[1]='\0'; iArrangeBelow[i]=atoi(szWidth); } i=0; while(true){ szListBelow[i]=GetChar(); if(szListBelow[i++]==(char)172) break; } szListBelow[--i]='\0'; } else if(strcmp(szFilesBelow,"NULL")!=0){ wsprintf(szFileName,"Images\\Compounds\\%s.bmp",szFilesBelow); bmpBelow->Create(_hOffDC,szFileName); bIsButtonBelow=false; } else{ bmpBelow->SetEmpty(); bIsButtonBelow=false; } POINT ptStartLn; POINT ptEndLn; POINT ptEdges[2]; int iAboveImageX; int iAboveImageY; int iBelowImageX; int iBelowImageY; //// || //Downward-right\/ if(aboveElementX+aboveElementWidth+infoArrow[0]+infoArrow[1]>iLayerWidth-RIGHTMARGIN && bArrowForward){ ptStartLn.x=aboveElementX+aboveElementWidth/2; ptStartLn.y=aboveElementY+aboveElementHeight/2; ptEndLn.x=aboveElementX+aboveElementWidth/2; ptEndLn.y=aboveElementY+aboveElementHeight/2+infoArrow[0]; ptEdges[0].x=ptEndLn.x-5; ptEdges[1].y=ptEdges[0].y=ptEndLn.y-5; ptEdges[1].x=ptEndLn.x+5; ptCurPosition.y=aboveElementY+infoArrow[0]+aboveElementHeight/2+infoArrow[2]/2; ptCurPosition.x=aboveElementX+aboveElementWidth/2-infoArrow[1]/2; if(ptCurPosition.x+infoArrow[1]>iLayerWidth){ ptCurPosition.x=iLayerWidth-infoArrow[1]-RIGHTMARGIN; } else if(ptCurPosition.xGetWidth()); iAboveImageY=(infoArrow[0]-bmpAbove->GetHeight())/2+aboveElementY+aboveElementHeight/2; } if(bIsButtonBelow){ iBelowImageY=(infoArrow[0]-IMGHEIGHT)/2+aboveElementY+aboveElementHeight/2; iBelowImageX=aboveElementX+aboveElementWidth/2; ptBelow.x=iBelowImageX+iBtnWidth[1]; ptBelow.y=iBelowImageY+(IMGHEIGHT-CORRECTIONSIZE)/2; } else if(bmpBelow){ iBelowImageY=(infoArrow[0]-bmpBelow->GetHeight())/2+aboveElementY+aboveElementHeight/2; iBelowImageX=aboveElementX+aboveElementWidth/2; } bArrowForward=false; } // ---> else if(aboveElementX+aboveElementWidth+infoArrow[0]+infoArrow[1]<=iLayerWidth-RIGHTMARGIN && bArrowForward){ ptStartLn.x=aboveElementX+aboveElementWidth; ptStartLn.y=aboveElementY; ptEndLn.x=ptStartLn.x+infoArrow[0]; ptEndLn.y=ptStartLn.y; ptEdges[0].y=ptEndLn.y-5; ptEdges[1].x=ptEdges[0].x=ptEndLn.x-5; ptEdges[1].y=ptEndLn.y+5; ptCurPosition.x=aboveElementX+infoArrow[0]+aboveElementWidth; ptCurPosition.y=aboveElementY; if(bIsButtonAbove){ iAboveImageY=(aboveElementY-IMGHEIGHT); iAboveImageX=(infoArrow[0]-iBtnWidth[0])/2+aboveElementX+aboveElementWidth; ptAbove.x=iAboveImageX+(iBtnWidth[0]-CORRECTIONSIZE)/2; ptAbove.y=iAboveImageY-CORRECTIONSIZE; } else if(bmpAbove){ iAboveImageY=(aboveElementY-bmpAbove->GetHeight()); iAboveImageX=(infoArrow[0]-bmpAbove->GetWidth())/2+aboveElementX+aboveElementWidth; } if(bIsButtonBelow){ iBelowImageX=(infoArrow[0]-iBtnWidth[1])/2+aboveElementX+aboveElementWidth; iBelowImageY=aboveElementY; ptBelow.x=iBelowImageX+(iBtnWidth[1]-CORRECTIONSIZE)/2; ptBelow.y=iBelowImageY+IMGHEIGHT; } else if(bmpBelow){ iBelowImageX=(infoArrow[0]-bmpBelow->GetWidth())/2+aboveElementX+aboveElementWidth; iBelowImageY=aboveElementY; } } // || // \/ Left of the margin else if(aboveElementX-infoArrow[0]-infoArrow[1]iLayerWidth){ ptCurPosition.x=iLayerWidth-infoArrow[1]-RIGHTMARGIN; } else if(ptCurPosition.xGetWidth()); iAboveImageY=(infoArrow[0]-bmpAbove->GetHeight())/2+aboveElementY+aboveElementHeight/2; } if(bIsButtonBelow){ iBelowImageY=(infoArrow[0]-IMGHEIGHT)/2+aboveElementY+aboveElementHeight/2; iBelowImageX=aboveElementX+aboveElementWidth/2; ptBelow.x=iBelowImageX+iBtnWidth[1]; ptBelow.y=iBelowImageY+(IMGHEIGHT-CORRECTIONSIZE)/2; } else if(bmpBelow){ iBelowImageY=(infoArrow[0]-bmpBelow->GetHeight())/2+aboveElementY+aboveElementHeight/2; iBelowImageX=aboveElementX+aboveElementWidth/2; } bArrowForward=true; } // <--- else if(aboveElementX-infoArrow[0]-infoArrow[1]>=MARGIN && !bArrowForward){ ptStartLn.x=aboveElementX; ptStartLn.y=aboveElementY; ptEndLn.x=ptStartLn.x-infoArrow[0]; ptEndLn.y=ptStartLn.y; ptEdges[0].y=ptEndLn.y-5; ptEdges[1].x=ptEdges[0].x=ptEndLn.x+5; ptEdges[1].y=ptEndLn.y+5; ptCurPosition.x=aboveElementX-infoArrow[0]-infoArrow[1]; ptCurPosition.y=aboveElementY; if(bIsButtonAbove){ iAboveImageY=(aboveElementY-IMGHEIGHT); iAboveImageX=aboveElementX-(infoArrow[0]-iBtnWidth[0])/2-iBtnWidth[0]; ptAbove.x=iAboveImageX+(iBtnWidth[0]-CORRECTIONSIZE)/2; ptAbove.y=iAboveImageY-CORRECTIONSIZE; } else if(bmpAbove){ iAboveImageY=(aboveElementY-bmpAbove->GetHeight()); iAboveImageX=aboveElementX-(infoArrow[0]-bmpAbove->GetWidth())/2-bmpAbove->GetWidth(); } if(bIsButtonBelow){ iBelowImageX=aboveElementX-(infoArrow[0]-iBtnWidth[1])/2-iBtnWidth[1]; iBelowImageY=aboveElementY; ptBelow.x=iBelowImageX+(iBtnWidth[1]-CORRECTIONSIZE)/2; ptBelow.y=iBelowImageY+IMGHEIGHT; } else if(bmpBelow){ iBelowImageX=aboveElementX-(infoArrow[0]-bmpAbove->GetWidth())/2-bmpAbove->GetWidth(); iBelowImageY=aboveElementY; } } HPEN hGridPen = CreatePen(PS_SOLID, 1, RGB(0,0,0));//(255, 204, 153)); HPEN hPen = (HPEN)SelectObject(_hOffDC, hGridPen); MoveToEx(_hOffDC ,ptStartLn.x,ptStartLn.y,NULL); LineTo(_hOffDC,ptEndLn.x,ptEndLn.y); LineTo(_hOffDC,ptEdges[0].x,ptEdges[0].y); MoveToEx(_hOffDC,ptEndLn.x,ptEndLn.y,NULL); LineTo(_hOffDC,ptEdges[1].x,ptEdges[1].y); SelectObject(_hOffDC,hPen); DeleteObject(hGridPen); if(bIsButtonAbove){ pMenuGroups[iMenuGroups++]->SetMenuGroup(_hOffDC,iArrangeAbove[0],iArrangeAbove[1], iAboveImageX,iAboveImageY, iBtnWidth[0],szListAbove); int selectedAnswer; if((selectedAnswer=transMenu[iQuesitions].iSelectedAnswer[iMenuGroups-1])!=-1){ pMenuGroups[iMenuGroups-1]->SetSelectedIndex(selectedAnswer); } int correctAnswer=transMenu[iQuesitions].iCorrectAnswer[iMenuGroups-1]= pMenuGroups[iMenuGroups-1]->GetCorrectIndex(); if(bIsCheckingAnswers){ if(selectedAnswer==correctAnswer) bmpRight2->Draw(_hOffDC,ptAbove.x,ptAbove.y,true); else if(selectedAnswer==-1) bmpQues2->Draw(_hOffDC,ptAbove.x,ptAbove.y,true); else bmpWrong2->Draw(_hOffDC,ptAbove.x,ptAbove.y,true); } } else if(bmpAbove){ bmpAbove->Draw(_hOffDC,iAboveImageX,iAboveImageY,true); } if(bIsButtonBelow){ pMenuGroups[iMenuGroups++]->SetMenuGroup(_hOffDC,iArrangeBelow[0],iArrangeBelow[1], iBelowImageX,iBelowImageY, iBtnWidth[1],szListBelow); int selectedAnswer; if((selectedAnswer=transMenu[iQuesitions].iSelectedAnswer[iMenuGroups-1])!=-1){ pMenuGroups[iMenuGroups-1]->SetSelectedIndex(selectedAnswer); } int correctAnswer=transMenu[iQuesitions].iCorrectAnswer[iMenuGroups-1]= pMenuGroups[iMenuGroups-1]->GetCorrectIndex(); if(bIsCheckingAnswers){ if(selectedAnswer==correctAnswer) bmpRight2->Draw(_hOffDC,ptBelow.x,ptBelow.y,true); else if(selectedAnswer==-1) bmpQues2->Draw(_hOffDC,ptBelow.x,ptBelow.y,true); else bmpWrong2->Draw(_hOffDC,ptBelow.x,ptBelow.y,true); } } else if(bmpBelow){ bmpBelow->Draw(_hOffDC,iBelowImageX,iBelowImageY,true); } } else if(!strcmp(szSubCommand,"PLUS")){ char szName[1024]; int infoPlus[2]; for(int i=0;i<2;i++){ for(int j=0;j<3;j++){ szName[j]=GetChar(); } szName[3]='\0'; infoPlus[i]=atoi(szName); } POINT ptCover; if(aboveElementX+aboveElementWidth+infoPlus[0]+10>iLayerWidth-RIGHTMARGIN && bArrowForward){ ptCover.x=aboveElementX+aboveElementWidth/2; ptCover.y=aboveElementY+aboveElementHeight/2+5; ptCurPosition.y=aboveElementY+10+aboveElementHeight/2+infoPlus[1]/2; ptCurPosition.x=aboveElementX+aboveElementWidth/2-infoPlus[0]/2; if(ptCurPosition.x+infoPlus[0]>iLayerWidth){ ptCurPosition.x=iLayerWidth-infoPlus[0]-RIGHTMARGIN; } else if(ptCurPosition.xiLayerWidth){ ptCurPosition.x=iLayerWidth-infoPlus[0]-RIGHTMARGIN; } else if(ptCurPosition.x=MARGIN && !bArrowForward){ ptCover.x=aboveElementX-5; ptCover.y=aboveElementY; ptCurPosition.x=aboveElementX-10-infoPlus[0]; ptCurPosition.y=aboveElementY; } HPEN hGridPen = CreatePen(PS_SOLID, 1, RGB(0,0,0));//(255, 204, 153)); HPEN hPen = (HPEN)SelectObject(_hOffDC, hGridPen); MoveToEx(_hOffDC ,ptCover.x,ptCover.y,NULL); LineTo(_hOffDC,ptCover.x+5,ptCover.y); MoveToEx(_hOffDC ,ptCover.x,ptCover.y,NULL); LineTo(_hOffDC,ptCover.x-5,ptCover.y); MoveToEx(_hOffDC ,ptCover.x,ptCover.y,NULL); LineTo(_hOffDC,ptCover.x,ptCover.y+5); MoveToEx(_hOffDC ,ptCover.x,ptCover.y,NULL); LineTo(_hOffDC,ptCover.x,ptCover.y-5); SelectObject(_hOffDC,hPen); DeleteObject(hGridPen); } } } void CContent::DrawBond(HDC hDC,int iBondType,POINT ptStart,POINT ptEnd){ HPEN hGridPen = CreatePen(PS_SOLID, 1, RGB(255,0,0));//(255, 204, 153)); HPEN hPen = (HPEN)SelectObject(hDC, hGridPen); if(iBondType==1 || iBondType==4){ MoveToEx(hDC, ptStart.x,ptStart.y, NULL); LineTo(hDC, ptEnd.x,ptEnd.y); } else if(iBondType==2){ if(abs(ptStart.x-ptEnd.x)>abs(ptStart.y-ptEnd.y)){ MoveToEx(hDC,ptStart.x,ptStart.y+2,NULL); LineTo(hDC,ptEnd.x,ptEnd.y+2); MoveToEx(hDC,ptStart.x,ptStart.y-2,NULL); LineTo(hDC,ptEnd.x,ptEnd.y-2); } else{ MoveToEx(hDC,ptStart.x+2,ptStart.y,NULL); LineTo(hDC,ptEnd.x+2,ptEnd.y); MoveToEx(hDC,ptStart.x-2,ptStart.y,NULL); LineTo(hDC,ptEnd.x-2,ptEnd.y); } } else if(iBondType==3){ if(abs(ptStart.x-ptEnd.x)>abs(ptStart.y-ptEnd.y)){ MoveToEx(hDC, ptStart.x,ptStart.y-3, NULL); LineTo(hDC, ptEnd.x,ptEnd.y-3); MoveToEx(hDC, ptStart.x,ptStart.y, NULL); LineTo(hDC, ptEnd.x,ptEnd.y); MoveToEx(hDC, ptStart.x,ptStart.y+3, NULL); LineTo(hDC, ptEnd.x,ptEnd.y+3); } else{ MoveToEx(hDC, ptStart.x-3,ptStart.y, NULL); LineTo(hDC, ptEnd.x-3,ptEnd.y); MoveToEx(hDC, ptStart.x,ptStart.y, NULL); LineTo(hDC, ptEnd.x,ptEnd.y); MoveToEx(hDC, ptStart.x+3,ptStart.y, NULL); LineTo(hDC, ptEnd.x+3,ptEnd.y); } } SelectObject(hDC, hPen); DeleteObject(hGridPen); } void CContent::NewLine(){ TEXTMETRIC textMextrics; GetTextMetrics(_hOffDC,&textMextrics); ptCurPosition.y=ptCurPosition.y+textMextrics.tmHeight; ptCurPosition.x=MARGIN; } char CContent::GetChar(){ char chData; while(true){ chData=szContent[iNextToRead++]; if(chData!='\n' && chData!='\t' && chData!='\r') return chData; } return chData; } void CContent::ClearLast(){ DeleteObject(_hLayerBitmap); } void CContent::DrawScreen(HDC hDC){ for(int i=0;i DrawScreen(_hOffDC); } if(!bShow) return; CPanel::DrawScreen(_hOffDC); pAnsw->DrawScreen(hDC); for(int i = 0;iDrawScreen(hDC,GetX(),GetY(),iLayerX,iLayerY,bIsCheckingAnswers); } } void CContent::DrawInsidePanel(HDC hDC){ if(iShowingTextElement!=0){ //TransparentBlt(hDC, ptMousePointer.x, ptMousePointer.y, 200, 20,hTextDC, 0, 0,200,20, RGB(255,0,255)); HFONT fntRoman=CreateFont(20, 0, 0,0, false, false, false, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Times New Roman"); SetTextColor(hDC,RGB(0,102,0)); SetBkMode(hDC,TRANSPARENT); HFONT fnt=(HFONT)SelectObject(hDC,fntRoman); TextOut(hDC,ptMousePointer.x+10,ptMousePointer.y,pPosElements[iShowingTextElement-1].szName,strlen(pPosElements[iShowingTextElement-1].szName)); SelectObject(hDC,fnt); DeleteObject(fntRoman); } int i=0; for(;i<2;i++){ buttonHome[i]->DrawScreen(hDC); buttonNext[i]->DrawScreen(hDC); buttonPrev[i]->DrawScreen(hDC); } if(IsQuesion)butNextQ->DrawScreen(hDC); if(IsQuesion)butPrevQ->DrawScreen(hDC); if(IsMainPage && IsQuesion) butStart->DrawScreen(hDC); butCheck->DrawScreen(hDC); char szText[64]; wsprintf(szText,"%d",buttonHome[i]->IsReady()); //MessageBox(GameEngine::GetEngine()->GetWindow(),szText,"hi all",MB_OK); } bool CContent::MouseButtonDown(int x,int y,BOOL bLeft){ int i=0; for(;i<2;i++){ if(buttonHome[i]->MouseButtonDown(x,y,bLeft)) return true; if(buttonNext[i]->MouseButtonDown(x,y,bLeft))return true; if(buttonPrev[i]->MouseButtonDown(x,y,bLeft))return true; } if(butPrevQ->MouseButtonDown(x,y,bLeft))return true; if(butNextQ->MouseButtonDown(x,y,bLeft))return true; butStart->MouseButtonDown(x,y,bLeft); butCheck->MouseButtonDown(x,y,bLeft); if(CPanel::MouseButtonDown(x,y,bLeft)) return true; if (!bIsCheckingAnswers) pAnsw->MouseButtonDown(x,y,bLeft); for(int i = 0;iMouseButtonDown(x-GetX()+iLayerX,y-GetY()+iLayerY,bLeft)){ for(int j=0;jSetHold(false); } iGivenAswers[iQuesitions]=i; break; } } for(int i = 0;iMouseButtonDown(x-GetX()+iLayerX,y-GetY()+iLayerY,bLeft)){ transMenu[iQuesitions].iSelectedAnswer[i]=pMenuGroups[i]->GetSelectedIndex(); } } return false; } void CContent::SetAllButtonNotReady(){ for(int i=0;i<2;i++){ buttonHome[i]->SetReady(false); buttonNext[i]->SetReady(false); buttonPrev[i]->SetReady(false); butStart->SetReady(false); butNextQ->SetReady(false); butPrevQ->SetReady(false); butCheck->SetReady(false); } } void CContent::MouseButtonUp(int x,int y,BOOL bLeft){ bool bReturn; int i; for(int i = 0;iMouseButtonUp(x-GetX()+iLayerX,y-GetY()+iLayerY,bLeft); int iSelected; if((iSelected=transMenu[iQuesitions].iSelectedAnswer[i])==-1){ transMenu[iQuesitions].iSelectedAnswer[i]=pMenuGroups[i]->GetSelectedIndex(); } if(bReturn) return; } if(buttonHome[0]->MouseButtonUp(x,y,bLeft)||buttonHome[1]->MouseButtonUp(x,y,bLeft)){ //bIsCheckingAnswers=false; iShowingTextElement=0; iElementCount=0; GameEngine::GetEngine()->SetExercise(false); ShowHome(); SetAllButtonNotReady(); //GameEngine::GetEngine()->SetLast(); } if((buttonNext[0]->MouseButtonUp(x,y,bLeft) || buttonNext[1]->MouseButtonUp(x,y,bLeft)) && strcmp(szNextFile,"NULL")){ //iLayerX=0; //bIsCheckingAnswers=false; iShowingTextElement=0; iElementCount=0; ChangeTo(szNextFile,0); } if((buttonPrev[0]->MouseButtonUp(x,y,bLeft) || buttonPrev[1]->MouseButtonUp(x,y,bLeft)) && strcmp(szPrevFile,"NULL")){ //iLayerX=0; //bIsCheckingAnswers=false; iShowingTextElement=0; iElementCount=0; ChangeTo(szPrevFile,0); } if(IsQuesion){ if(butPrevQ->MouseButtonUp(x,y,bLeft)){ for(int i = 0;iGetSelectedIndex(); } CheckLittleCompoundsForCorrect(); //for the question if(IsEndPage) return; ptCurPosition.y=0; ptCurPosition.x=MARGIN; if(iQuesitions>1){ iNextToRead=iFlagPrevReactions[--iQuesitions]; --iQuesitions; ContinueToNextQues(); } } if(butNextQ->MouseButtonUp(x,y,bLeft)){ for(int i = 0;iGetSelectedIndex(); } CheckLittleCompoundsForCorrect(); //for the question if(IsEndPage) return; ptCurPosition.y=50; ptCurPosition.x=MARGIN; ContinueToNextQues(); } if(IsMainPage && IsQuesion && butStart->MouseButtonUp(x,y,bLeft)){ ptCurPosition.y=50; ptCurPosition.x=MARGIN; ContinueToNextQues(); butStart->SetReady(false); } } if(butCheck->MouseButtonUp(x,y,bLeft) && butCheck->IsReady()){ butCheck->SetReady(false); bIsCheckingAnswers=true; isFromExercise=false; iNextToRead=0; iQuesitions=0; Update(); } CPanel::MouseButtonUp(x,y,bLeft); if(pAnsw->MouseButtonUp(x,y,bLeft)){ for(int i = 0;ipAnswElements[i].ptStart.x && y-GetY()+iLayerY>pAnswElements[i].ptStart.y && x-GetX()+iLayerXGetMovedElement(); if(iMovedElement==i){ iNumberOfCorrectFills++; //MessageBox(GameEngine::GetEngine()->GetWindow(),"H","bye",MB_OK); } strcpy(transQuestion[iQuesitions].szGivenAnswer[i],szNamesOfOption[iMovedElement]); //MessageBox(GameEngine::GetEngine()->GetWindow(),szNamesOfOption[iMovedElement],"bye",MB_OK); iGivenAswers[iQuesitions]=0; wsprintf(szFileName,"Data\\CElements\\%s.txt",szNamesOfOption[iMovedElement]); bUpNoAnsPnl=true; Update(true); bUpNoAnsPnl=false; SetAnswElements(szFileName,false,ptMiddle); SetAnswElements(szFileName,true,ptMiddle); break; } } } for(int i = 0;iMouseButtonUp(x-GetX()+iLayerX,y-GetY()+iLayerY,bLeft); } } void CContent::SetAnswElements(char* szFileName,bool bOnlyElements,POINT ptStart){ HANDLE hFileC = CreateFile(TEXT(szFileName), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL); char chData; DWORD dwBytesRead; POINT ptSize; char szName[1024]; while(true){ ReadFile(hFileC,&chData,1,&dwBytesRead,NULL); if(chData==(char)179){ break; } ReadFile(hFileC,&chData,1,&dwBytesRead,NULL); if(chData=='E'){ ReadFile(hFileC,&chData,1,&dwBytesRead,NULL); //skip one //Read the Element int iElement[3]; char szNumber[8]; for(int i=0;i<3;i++){ int j=0; while(true){ ReadFile(hFileC,&chData,1,&dwBytesRead,NULL); if(chData==':') break; else szNumber[j++]=chData; } szNumber[j]='\0'; iElement[i]=atoi(szNumber); } pElements[iElement[0]]->Draw(_hOffDC,iElement[1]+ptStart.x,iElement[2]+ptStart.y,true); } else if(chData=='B'){ ReadFile(hFileC,&chData,1,&dwBytesRead,NULL); //skip one //Read the Bond int iBonds[5]; char szNumber[8]; for(int i=0;i<5;i++){ int j=0; while(true){ ReadFile(hFileC,&chData,1,&dwBytesRead,NULL); if(chData==':') break; else szNumber[j++]=chData; } szNumber[j]='\0'; iBonds[i]=atoi(szNumber); } if(!bOnlyElements){ POINT ptStartLn; POINT ptEndLn; ptStartLn.x=iBonds[1]+ptStart.x; ptStartLn.y=iBonds[2]+ptStart.y; ptEndLn.x=iBonds[3]+ptStart.x; ptEndLn.y=iBonds[4]+ptStart.y; DrawBond(_hOffDC,iBonds[0],ptStartLn,ptEndLn); } } else if(chData=='S'){ ReadFile(hFileC,&chData,1,&dwBytesRead,NULL); //skip one //Read the size int iSizes[2]; char szSize[8]; for(int i=0;i<2;i++){ int j=0; while(true){ ReadFile(hFileC,&chData,1,&dwBytesRead,NULL); if(chData==':') break; else szSize[j++]=chData; } szSize[j]='\0'; iSizes[i]=atoi(szSize); } ptSize.x=iSizes[0]; ptSize.y=iSizes[1]; ptStart.x-=iSizes[0]/2; ptStart.y-=iSizes[1]/2; int j=0; while(true){ ReadFile(hFileC,&chData,1,&dwBytesRead,NULL); if(chData==':') break; else szName[j++]=chData; } szName[j]='\0'; } } CloseHandle(hFileC); } void CContent::MouseMove(int x,int y){ for(int i=0;i<2;i++){ buttonHome[i]->MouseMove(x,y); buttonNext[i]->MouseMove(x,y); buttonPrev[i]->MouseMove(x,y); } butPrevQ->MouseMove(x,y); butNextQ->MouseMove(x,y); butStart->MouseMove(x,y); butCheck->MouseMove(x,y); ptMousePointer.x=x; ptMousePointer.y=y; CPanel::MouseMove(x,y); struct PosElements TempElement; if(pPosElements){ for(int i=0;iTempElement.ptStart.x +GetX()-iLayerX && xTempElement.ptStart.y+GetY()-iLayerY && yTempElement.ptStart.x +GetX()-iLayerX && xTempElement.ptStart.y+GetY()-iLayerY && yMouseMove(x-GetX()+iLayerX,y-GetY()+iLayerY); } pAnsw->MouseMove(x,y); for(int i = 0;iMouseMove(x-GetX()+iLayerX,y-GetY()+iLayerY,bIsCheckingAnswers)) return; } static BOOL isOverme[NUMBEROF_FILLS_PER_REACTION]; for(int i = 0;ipAnswElements[i].ptStart.x && y-GetY()+iLayerY>pAnswElements[i].ptStart.y && x-GetX()+iLayerXGetWindow(); HDC hDC=GetDC(hwnd); _hLayerBitmap = CreateCompatibleBitmap(hDC,iLayerWidth, iLayerHeight); ReleaseDC(hwnd,hDC); hOldBitmap=(HBITMAP)SelectObject(_hOffDC,_hLayerBitmap); HBRUSH hWhiteBrush = CreateSolidBrush(RGB(255, 255, 255)); HBRUSH hBrush = (HBRUSH)SelectObject(_hOffDC, hWhiteBrush); Rectangle(_hOffDC,-1,-1,iLayerWidth+1,iLayerHeight+1); //BackGround for(int i=0;i<=iLayerWidth/90;i++){ for(int j=0;j<=iLayerHeight/90;j++){ bmpBackGround->Draw(_hOffDC,i*90,j*90); } } SelectObject(_hOffDC,hBrush); DeleteObject(hWhiteBrush); } void CContent::QuestionManager() { if(GameEngine::GetEngine()->IsExercise()) GameEngine::GetEngine()->SetExercise(false); SetNavigationButtons(); //GameEngine::GetEngine()->SetLast(); butStart->SetPlace(GetX()+100,ptCurPosition.y+50,true); if(bIsCheckingAnswers && bIgnoreMainPage){ bIgnoreMainPage=false; ptCurPosition.y=50; ptCurPosition.x=MARGIN; ContinueToNextQues(); butStart->SetReady(false); } if(iGivenAswers[iQuesitions]!=-1) pTglButton[iGivenAswers[iQuesitions]]->SetHold(true); } void CContent::ContinueToNextQues() { if(!bUpNoAnsPnl)SetLayerY(0); iShowingTextElement=0; iElementCount=0; ptCurPosition.y=40; iQuesitions++; for(int i=0;i<8;i++){ pTglButton[i]->SetReady(false); } iAnswCount=0; IsMainPage=false; iLayerHeight=1500; CreateNewPage(); iFlagPrevReactions[iQuesitions]=iNextToRead; Manager(); } void CContent::SetNavigationButtons() { buttonHome[0]->SetPlace(GetX()+iLayerWidth-110,GetY()+5,true); buttonHome[1]->SetPlace(GetX()+iLayerWidth-110,540,true); buttonNext[0]->SetPlace(GetX()+iLayerWidth-60,GetY()+5,true); buttonNext[1]->SetPlace(GetX()+iLayerWidth-60,540,true); buttonPrev[0]->SetPlace(GetX()+5,GetY()+5,true); buttonPrev[1]->SetPlace(GetX()+5,540,true); butPrevQ->SetPlace(GetX()+50,GetY()+GetHeight()-28,(!IsMainPage)&&(IsQuesion)); butNextQ->SetPlace(GetX()+iLayerWidth-110-150,GetY()+GetHeight()-28,(!IsMainPage)&&(IsQuesion)); } void CContent::AnswerManager() { while(true){ char chData=GetChar(); if(chData==(char)179){ Manager(); break; } char szSubCommand[5]; szSubCommand[0]=chData; for(int i=1;i<4;i++){ szSubCommand[i]=GetChar(); } szSubCommand[4]='\0'; if(!strcmp(szSubCommand,"CIMG")){ char szOffSet[8]; for(int i=0;i<2;i++){ szOffSet[i]=GetChar(); } szOffSet[2]='\0'; int iOffSet=atoi(szOffSet); char szCorrect=GetChar(); char szTitle[64]; int i=0; while(true){ szTitle[i]=GetChar(); if(szTitle[i++]==(char)172) break; } szTitle[i-1]='\0'; pTglButton[iAnswCount]->SetImage(szTitle,MARGIN,ptCurPosition.y,_hOffDC,iOffSet); if(szCorrect=='y'){ iCorrectAnswers[iQuesitions]=iAnswCount; if(bIsCheckingAnswers){ if(iGivenAswers[iQuesitions]==iAnswCount){ bmpRight1->Draw(_hOffDC,MARGIN+pTglButton[iAnswCount]->GetWidth()+5, ptCurPosition.y+pTglButton[iAnswCount]->GetHeight()/2-20,true); } else{ bmpArrow1->Draw(_hOffDC,MARGIN+pTglButton[iAnswCount]->GetWidth()+5, ptCurPosition.y+pTglButton[iAnswCount]->GetHeight()/2-20,true); } } } else{ if(bIsCheckingAnswers){ if(iGivenAswers[iQuesitions]==iAnswCount){ bmpWrong1->Draw(_hOffDC,MARGIN+pTglButton[iAnswCount]->GetWidth()+5, ptCurPosition.y+pTglButton[iAnswCount]->GetHeight()/2-20,true); } } } ptCurPosition.y+=pTglButton[iAnswCount]->GetHeight()+5; iAnswCount++; } if(!strcmp(szSubCommand,"CMPD")){ char szCorrect=GetChar(); char szTitle[64]; int i=0; while(true){ szTitle[i]=GetChar(); if(szTitle[i++]==(char)172) break; } szTitle[i-1]='\0'; pTglButton[iAnswCount]->SetCmpd(szTitle,MARGIN,ptCurPosition.y,_hOffDC,pElements); if(szCorrect=='y'){ iCorrectAnswers[iQuesitions]=iAnswCount; if(bIsCheckingAnswers){ if(iGivenAswers[iQuesitions]==iAnswCount){ bmpRight1->Draw(_hOffDC,MARGIN+pTglButton[iAnswCount]->GetWidth()+5, ptCurPosition.y+pTglButton[iAnswCount]->GetHeight()/2-20,true); } else{ bmpArrow1->Draw(_hOffDC,MARGIN+pTglButton[iAnswCount]->GetWidth()+5, ptCurPosition.y+pTglButton[iAnswCount]->GetHeight()/2-20,true); } } } else{ if(bIsCheckingAnswers){ if(iGivenAswers[iQuesitions]==iAnswCount){ bmpWrong1->Draw(_hOffDC,MARGIN+pTglButton[iAnswCount]->GetWidth()+5, ptCurPosition.y+pTglButton[iAnswCount]->GetHeight()/2-20,true); } } } ptCurPosition.y+=pTglButton[iAnswCount]->GetHeight()+5; if(szCorrect=='y'){ iCorrectAnswers[iQuesitions]=iAnswCount; } iAnswCount++; } } } void CContent::ManagerFinalizingAnswers() { int i; if(GameEngine::GetEngine()->IsExercise()) { isFromExercise=true; GameEngine::GetEngine()->SetExercise(false); return; } if(isFromExercise){ for(int i = 0;iSetReady(false); } iLayerHeight=600; CreateNewPage(); HFONT fntTitle=CreateFont(30, 0, 0,0, FW_MEDIUM, FALSE, TRUE, 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(_hOffDC,fntTitle); char szToType[32]; strcpy(szToType,GameEngine::GetEngine()->IsEnglish()?"Statistic":"m%;sM,"); TextOut(_hOffDC,MARGIN,ptCurPosition.y,szToType,strlen(szToType)); NewLine(); NewLine(); //TextOut(_hOffDC,iOffset/2-10+(i+1)*textMextrics.tmAveCharWidth,ptCurPosition.y,szTitle,i); HFONT fntRoman=CreateFont(20, 0, 0,0, FW_MEDIUM, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, (GameEngine::GetEngine()->IsEnglish()?("Times New Roman"):("DL-Paras."))); SelectObject(_hOffDC,fntRoman); DeleteObject(fntTitle); int iAnswered=0; for(int i = 0;iIsEnglish()?"Overall":"tl;+j",strlen(GameEngine::GetEngine()->IsEnglish()?"Overall":"tl;+j")); NewLine(); int iNumber; iNumber=wsprintf(szToType,GameEngine::GetEngine()->IsEnglish()?"Number of Questions : ":"m%%YaK ixLHdj ("); TextOut(_hOffDC,MARGIN,ptCurPosition.y,szToType,iNumber); iNumber=wsprintf(szToType,"%2d",iQuesitions-1); TextOut(_hOffDC,MARGIN+180,ptCurPosition.y,szToType,iNumber); GetSettings(); if(!bIsCheckingAnswers && addToProfile) ifileQuestions+=iQuesitions-1; SetSettings(); iNumber=wsprintf(szToType,"%4d",ifileQuestions); TextOut(_hOffDC,MARGIN+260,ptCurPosition.y,szToType,iNumber); NewLine(); iNumber=wsprintf(szToType,GameEngine::GetEngine()->IsEnglish()?"Number of Attempts : ":"W;aidyhka ixLHdj ("); TextOut(_hOffDC,MARGIN,ptCurPosition.y,szToType,iNumber); iNumber=wsprintf(szToType,"%2d",iAnswered); TextOut(_hOffDC,MARGIN+180,ptCurPosition.y,szToType,iNumber); GetSettings(); if(!bIsCheckingAnswers && addToProfile)ifileAttepmts+=iAnswered; SetSettings(); iNumber=wsprintf(szToType,"%4d",ifileAttepmts); TextOut(_hOffDC,MARGIN+260,ptCurPosition.y,szToType,iNumber); NewLine(); iAnswered=0; for(int i = 0;iIsEnglish()?"Correct Answers : ":"ksjeros msSetPlace((GetX()+iLayerWidth/2)-175,GetY()+iLayerHeight/2-100,true); SetNavigationButtons(); } ////////// void CContent::GetSettings() { char szFileName[128]; wsprintf(szFileName,"%s\\%s.txt",GameEngine::GetEngine()->GetProfilePath(),GameEngine::GetEngine()->GetStudentName()); HANDLE hFile = CreateFile(szFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL); if(hFile==INVALID_HANDLE_VALUE){ ifileAttepmts=0; ifileAnswersRight=0; ifileQuestions=0; CloseHandle(hFile); //MessageBox(GetWindow(),"Hello","hi",MB_OK); SetSettings(); GetSettings(); return; } DWORD dwBytesRead; if (!(ReadFile(hFile, &ifileAttepmts, sizeof(int), &dwBytesRead, NULL)&& ReadFile(hFile, &ifileAnswersRight, sizeof(int), &dwBytesRead, NULL)&& ReadFile(hFile, &ifileQuestions, sizeof(int), &dwBytesRead, NULL))) { // Something went wrong, so close the file handle MessageBox(GameEngine::GetEngine()->GetWindow(),"Error in Reading Data","Error",MB_OK); CloseHandle(hFile); return ; } //MessageBox(GetWindow(),szLastLesson,"Error",MB_OK); CloseHandle(hFile); } bool CContent::SetSettings() { char szFileName[128]; wsprintf(szFileName,"%s\\%s.txt",GameEngine::GetEngine()->GetProfilePath(),GameEngine::GetEngine()->GetStudentName()); HANDLE hFile = CreateFile(szFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); /* if(hFile==INVALID_HANDLE_VALUE){ CloseHandle(hFile); //SetSttings(); return false; }*/ DWORD dwBytesWritten; if (!(WriteFile(hFile, &ifileAttepmts, sizeof(int), &dwBytesWritten, NULL)&& WriteFile(hFile, &ifileAnswersRight, sizeof(int), &dwBytesWritten, NULL)&& WriteFile(hFile, &ifileQuestions, sizeof(int), &dwBytesWritten, NULL))) { // Something went wrong, so close the file handle MessageBox(GameEngine::GetEngine()->GetWindow(),"Error in Writing data","Error!",MB_OK); CloseHandle(hFile); return false; } //GetSettings(); CloseHandle(hFile); return true; } ///// void CContent::TransformationManager() { if(!GameEngine::GetEngine()->IsExercise()) GameEngine::GetEngine()->SetExercise(true); transMenu[iQuesitions].iNumber=iMenuGroups; transQuestion[iQuesitions].iNumber=iNumberOfFills; GameEngine::GetEngine()->SetLast(); SetNavigationButtons(); //butStart->SetPlace(GetX()+100,ptCurPosition.y+50,true); //butCheck->SetReady(false); if(!bUpNoAnsPnl)pAnsw->SetAnswerList(szNamesOfOption,iNumberOfOptions,pElements); //char szName=szNamesOfOption[2][4]; DrawScreen(GameEngine::GetEngine()->getOffScreenDC()); } void CContent::CheckLittleCompoundsForCorrect() { if(!iMenuGroups &&!GameEngine::GetEngine()->IsExercise()) return; int iAnswerGiven=0; int iAttempts=0; for(int i=0;iIsCorrectAnswerGiven()){ iAnswerGiven++; } if(iGivenAswers[iQuesitions]==-1){ if(pMenuGroups[i]->IsAttempted()){ iGivenAswers[iQuesitions]==0; } //iAttempts++; } } /*if( iAttempts>0 ){ iGivenAswers[iQuesitions]==0; }*/ if(iAnswerGiven==iMenuGroups && iMenuGroups!=0){ //iGivenAswers[iQuesitions]++; } if(iMenuGroups!=0) iCorrectAnswers[iQuesitions]=2; else iCorrectAnswers[iQuesitions]=1; GameEngine::GetEngine()->SetMenuExpanded(true); } bool CContent::IsCheckingAnswers() { return bIsCheckingAnswers; }