void CMagneticView::OnPlayback() { CMagneticApp* pApp = (CMagneticApp*)AfxGetApp(); SimpleFileDialog PlayDlg(TRUE,NULL,m_strRecName, OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_ENABLESIZING, "Record Files (*.rec)|*.rec|All Files (*.*)|*.*||",this); PlayDlg.m_ofn.lpstrTitle = "Play Back a File"; switch (m_Recording) { case Recording::RecordingOff: if (ms_is_running()) pApp->SetRedrawStatus(CMagneticApp::Redraw::ThisLine); if (PlayDlg.DoModal() == IDOK) { m_strRecName = PlayDlg.GetPathName(); if ((m_pFileRecord = fopen(m_strRecName,"rt")) != NULL) { m_Recording = Recording::PlaybackOn; if (pApp->GetGameLoaded() && ms_is_running()) pApp->SetRedrawStatus(CMagneticApp::Redraw::EndPlayback); } } break; case Recording::RecordingOn: break; case Recording::PlaybackOn: if (m_pFileRecord) fclose(m_pFileRecord); m_pFileRecord = NULL; m_Recording = Recording::RecordingOff; break; } }
BOOL CMagneticView::OnEraseBkgnd(CDC* pDC) { CMagneticApp* pApp = (CMagneticApp*)AfxGetApp(); CRect Background; GetClientRect(Background); if (pApp->GetGameLoaded() == 0) pDC->FillSolidRect(Background,pApp->GetBackColour()); return 1; }
void CMagneticView::OnDraw(CDC* pDrawDC) { CMagneticApp* pApp = (CMagneticApp*)AfxGetApp(); // Don't draw anything if there isn't a loaded game if (pApp->GetGameLoaded() == 0) return; CDC BitmapDC; BitmapDC.CreateCompatibleDC(pDrawDC); CRect Client; GetClientRect(Client); CBitmap Bitmap; CSize Size(Client.Width(),Client.Height()); Bitmap.CreateCompatibleBitmap(pDrawDC,Size.cx,Size.cy); CBitmap* pOldBitmap = BitmapDC.SelectObject(&Bitmap); // Set up the font CFont* pOldFont = NULL; TEXTMETRIC FontInfo; pOldFont = BitmapDC.SelectObject(m_pTextFont); BitmapDC.GetTextMetrics(&FontInfo); int iFontHeight = (int)(FontInfo.tmHeight*1.1); int iPicWidth = 0; int iPicHeight = 0; CRect TextClient(Client); CSize Margins(GetMargins()); if (m_bStatusBar) { TextClient.top += iFontHeight; // Display the status line LONG lStatSpace = (LONG)(Client.Width()*0.075); SolidRect(&BitmapDC,CRect(Client.left,0,Client.right,iFontHeight), pApp->GetForeColour()); BitmapDC.SetTextColor(pApp->GetBackColour()); BitmapDC.SetBkColor(pApp->GetForeColour()); BitmapDC.TextOut(lStatSpace,0,m_strStatLocation,m_strStatLocation.GetLength()); BitmapDC.TextOut(lStatSpace*10,0,m_strStatScore,m_strStatScore.GetLength()); } // If the picture is to be drawn in the main window, leave enough // space and draw both background and picture if (pApp->GetShowGraphics() == CMagneticApp::ShowGraphics::MainWindow) { int dpi = DPI::getWindowDPI(this); iPicWidth = m_Picture.GetScaledWidth(dpi); iPicHeight = m_Picture.GetScaledHeight(dpi); if (iPicWidth > 0 && iPicHeight > 0) { TextClient.top += iPicHeight; int iOffset = m_bStatusBar ? iFontHeight : 0; BitmapDC.FillSolidRect(Client.left,Client.top+iOffset,Client.Width(), iPicHeight,pApp->GetGfxColour()); CRect PicArea((Client.Width()-iPicWidth)/2,iOffset, (Client.Width()+iPicWidth)/2,iOffset+iPicHeight); m_Picture.Paint(&BitmapDC,PicArea,m_AnimFrames); } } BitmapDC.FillSolidRect(TextClient,pApp->GetBackColour()); int y = TextClient.top; // Repaginate if necessary TrimOutput(); if (m_PageTable.GetSize() == 0) { Paginate(&BitmapDC,0,0); if (m_bMorePrompt) m_PageTable.RemoveAt(m_PageTable.GetSize()-1); } LPCSTR lpszOutput = m_strOutput; BitmapDC.SetTextColor(pApp->GetForeColour()); BitmapDC.SetBkColor(pApp->GetBackColour()); // Work out the number of lines of text to draw m_iMaxLines = (TextClient.Height()-(2*Margins.cy)) / iFontHeight; y += Margins.cy; // Starting position in the text output buffer int i = m_PageTable.GetSize() - m_iMaxLines - 1; // Adjust for a More... prompt int offset = 0; if (m_bMorePrompt) { if (iPicWidth > 0 && iPicHeight > 0) { if (m_iLines > m_iMaxLines) { if (m_iLines - m_iMaxLines - 1 > 0) { offset = m_iLines - m_iMaxLines - 1; i -= offset; } } } } if (i < 0) i = 0; // Draw the text int iCount = 0; while (i < m_PageTable.GetSize()-1-offset) { iCount = m_PageTable[i+1]-m_PageTable[i]-1; if (iCount > 0) { if (*(lpszOutput+m_PageTable[i]+iCount-1) == '\0') iCount--; } BitmapDC.TextOut(Margins.cx,y,lpszOutput+m_PageTable[i],iCount); y += iFontHeight; i++; } // Store information on the last line for updating later CRect LastLine(0,y-iFontHeight,TextClient.Width(),y); m_LastLineRect = LastLine; // Clear the end of the last line to allow input editing if (i > 0) { CSize TextLen = BitmapDC.GetTextExtent(lpszOutput+m_PageTable[i-1], m_PageTable[i]-m_PageTable[i-1]-1); LastLine.left += TextLen.cx + Margins.cx; SolidRect(&BitmapDC,LastLine,pApp->GetBackColour()); } // Remove the font BitmapDC.SelectObject(pOldFont); pDrawDC->BitBlt(0,0,Size.cx,Size.cy,&BitmapDC,0,0,SRCCOPY); BitmapDC.SelectObject(pOldBitmap); }
BOOL CMagneticView::OpenGame(LPCTSTR lpszPathName) { CMagneticApp* pApp = (CMagneticApp*)AfxGetApp(); CMagneticView* pView = CMagneticView::GetView(); if (pApp->GetGameLoaded() && ms_is_running()) pApp->SetRedrawStatus(CMagneticApp::Redraw::EndOpcode); if (pView) pView->ClearAll(); CString strGfxName, strHntName, strSndName; MakeFilePath(strGfxName,lpszPathName,".gfx"); MakeFilePath(strHntName,lpszPathName,".hnt"); MakeFilePath(strSndName,lpszPathName,".snd"); // Free previous game ms_freemem(); // Initialize new game pApp->SetGameLoaded(ms_init((type8s*)lpszPathName, (type8s*)((LPCTSTR)strGfxName), (type8s*)((LPCTSTR)strHntName), (type8s*)((LPCTSTR)strSndName))); // If required, make the random number generator predictable if (pApp->GetPredictable()) ms_seed(pApp->GetRandomSeed()); // Check status of loaded game if (pApp->GetGameLoaded() == 0) { CString strMessage; strMessage.Format("Failed to load game \"%s\"",lpszPathName); AfxMessageBox(strMessage,MB_ICONEXCLAMATION); } else { if (pView) { pView->m_bStatusBar = false; pView->Invalidate(); } // Show the title picture, if possible CMagneticTitleDlg Title; Title.ShowTitle(lpszPathName); if (pView) { // Set up default file names MakeFilePath(pView->m_strRecName,lpszPathName,".rec"); MakeFilePath(pView->m_strScrName,lpszPathName,".scr"); MakeFilePath(pView->m_strFileName,lpszPathName,".sav"); pView->m_bStatusBar = ms_is_magwin() ? false : true; } } if (pView) pView->Invalidate(); return (pApp->GetGameLoaded() != 0) ? TRUE : FALSE; }