void CMagneticView::CaretOff(void) { CMagneticView* pView = CMagneticView::GetView(); if (pView) pView->HideCaret(); DestroyCaret(); }
void CMagneticView::CaretOn(void) { CMagneticView* pView = CMagneticView::GetView(); if (pView == NULL) return; TEXTMETRIC FontInfo; pView->m_pTextDC->GetTextMetrics(&FontInfo); int iFontHeight = (int)(FontInfo.tmHeight*1.1); // Turn the caret on pView->CreateSolidCaret(2,iFontHeight); pView->ShowCaret(); }
type8 ms_load_file(type8s *name, type8 *ptr, type16 size) { CMagneticApp* pApp = (CMagneticApp*)AfxGetApp(); CString strLoadName; FILE *fh; if (name == NULL) { CMagneticView* pView = CMagneticView::GetView(); if (pView == NULL) return 0; SimpleFileDialog LoadDlg(TRUE,NULL,pView->GetFileName(), OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_ENABLESIZING, "Saved Game Files (*.sav)|*.sav|All Files (*.*)|*.*||",pView); LoadDlg.m_ofn.lpstrTitle = "Load a Saved Game"; if (ms_is_running()) pApp->SetRedrawStatus(CMagneticApp::Redraw::ThisLine); if (LoadDlg.DoModal() == IDOK) { strLoadName = LoadDlg.GetPathName(); pView->GetFileName() = strLoadName; } else return 0; } else strLoadName = (char*)name; if ((fh = fopen(strLoadName,"rb")) == NULL) return 1; if (fread(ptr,1,size,fh) != size) return 1; fclose(fh); return 0; }
void ms_playmusic(type8 * midi_data, type32 length, type16 tempo) { CMagneticView* pView = CMagneticView::GetView(); if (pView != NULL) pView->PlayMusic(midi_data,length,tempo); }
void ms_showpic(type32 c, type8 mode) { CMagneticApp* pApp = (CMagneticApp*)AfxGetApp(); if (pApp->GetShowGraphics() != CMagneticApp::ShowGraphics::NoGraphics) { CMagneticView* pView = CMagneticView::GetView(); if (pView == NULL) return; type8 *pPictureData = NULL; type16 Width, Height; type8 IsAnim = 0; switch (mode) { case 0: // Graphics off if (pView->GetPictureWindow().GetSafeHwnd()) pView->GetPictureWindow().SendMessage(WM_CLOSE,0,0); pView->GetPicture().ClearAll(); pView->SetAnimate(FALSE); pView->ClearAnims(); break; case 1: // Graphics on (thumbnails) case 2: // Graphics on (normal) pView->SetAnimate(FALSE); pView->ClearAnims(); pPictureData = ms_extract(c,&Width,&Height,pView->GetPalette(),&IsAnim); if (pPictureData) { pView->GetPicture().NewPicture(Width,Height,pPictureData,pView->GetPalette()); pView->SetAnimate(IsAnim != 0); if (IsAnim != 0) pView->Animate(); pView->Invalidate(); pView->SetPictureWindowState(); } break; } } }
type8 ms_getchar(type8 trans) { bool done = false; char c = 0; do { CMagneticView* pView = CMagneticView::GetView(); if (pView == NULL) return 1; if (pView->GetRecording() == CMagneticView::Recording::PlaybackOn) { if (pView->GetRecordFile()) { CMagneticApp* pApp = (CMagneticApp*)AfxGetApp(); if (pApp->GetAnimWait()) { while (pView->GetAnimate() && (ms_anim_is_repeating() == 0)) { if (pApp->PumpMessage() == FALSE) { ::PostQuitMessage(0); return 1; } pApp->CWinApp::OnIdle(0); } } char cInput = CMagneticView::GetPlaybackChar(pView->GetRecordFile()); if (feof(pView->GetRecordFile()) != 0) { pView->SetRecording(CMagneticView::Recording::RecordingOff); fclose(pView->GetRecordFile()); pView->SetRecordFile(NULL); pView->ClearPagination(); } else { if (cInput == '\n') { cInput = 10; pView->TrimOutput(); pView->GetPageTable().RemoveAll(); pView->Invalidate(); } else pView->AddOutChar(cInput); return cInput; } } } c = CMagneticView::GetInput(done,trans != 0); } while (done == false); return c; }
void ms_putchar(type8 c) { CMagneticView* pView = CMagneticView::GetView(); if (pView != NULL) pView->AddOutChar(c); }
void ms_statuschar(type8 c) { CMagneticView* pView = CMagneticView::GetView(); if (pView != NULL) pView->AddStatChar(c); }
char CMagneticView::GetInput(bool& done, bool trans) { static const int MAX_HISTORY = 20; done = true; CMagneticApp* pApp = (CMagneticApp*)AfxGetApp(); CMagneticView* pView = CMagneticView::GetView(); if (pView == NULL) return 0; int cInput = 0; // Input character int iPosition = 0; // Current cursor position int iHistory = -1; // Current history position static CString strFullLine; // Input line already obtained? if (strFullLine.GetLength() > 0) { cInput = strFullLine[0]; strFullLine = strFullLine.Right(strFullLine.GetLength()-1); if (cInput == (signed char)(CMagneticView::SPECIAL_KEYS + VK_SPACE)) cInput = ' '; return (char)cInput; } if (pView->m_bMorePrompt) pView->m_PageTable.RemoveAt(pView->m_PageTable.GetSize()-1); else pView->m_PageTable.RemoveAll(); // Refresh the view pView->Invalidate(); pView->CaretOn(); pView->m_bInputActive = true; while (cInput != 10 && cInput != 1) { pView = CMagneticView::GetView(); if (pView == NULL) break; // Wait for a character CArray<int, int>& Input = pView->m_Input; if (Input.GetSize() == 0) { pApp->PumpMessage(); pApp->CWinApp::OnIdle(0); // Call base class OnIdle(); pView = CMagneticView::GetView(); if (pView) { CMagneticApp::Redraw Status = pApp->GetRedrawStatus(); switch (Status) { case CMagneticApp::Redraw::EndPlayback: done = false; // intentional fall-through case CMagneticApp::Redraw::EndLine: case CMagneticApp::Redraw::EndOpcode: Input.RemoveAll(); strFullLine.Empty(); if (Status == CMagneticApp::Redraw::EndOpcode) cInput = 1; else cInput = 10; // intentional fall-through case CMagneticApp::Redraw::ThisLine: pView->CaretOff(); pView->CaretOn(); pView->Invalidate(); break; } pView->SetCursorPos(pView->m_pTextDC,strFullLine.GetLength()-iPosition); } } else { cInput = (pView->m_bMorePrompt) ? 10 : Input[0]; Input.RemoveAt(0); int iInsertPos, iRemovePos; switch (cInput) { case 10: // Return strFullLine += (char)cInput; break; case CMagneticView::SPECIAL_KEYS + VK_LEFT: // Cursor left if (iPosition > 0) iPosition--; break; case CMagneticView::SPECIAL_KEYS + VK_RIGHT: // Cursor right if (iPosition < strFullLine.GetLength()) iPosition++; break; case CMagneticView::SPECIAL_KEYS + VK_HOME: // Home iPosition = 0; break; case CMagneticView::SPECIAL_KEYS + VK_END: // End iPosition = strFullLine.GetLength(); break; case CMagneticView::SPECIAL_KEYS + VK_DELETE: // Delete if (iPosition < strFullLine.GetLength()) { iRemovePos = strFullLine.GetLength() - iPosition; pView->RemoveChar(strFullLine,iRemovePos); pView->RemoveChar(pView->m_strOutput,iRemovePos,TRUE); } break; case 8: // Backspace if (iPosition > 0) { iRemovePos = strFullLine.GetLength() - iPosition + 1; pView->RemoveChar(strFullLine,iRemovePos); pView->RemoveChar(pView->m_strOutput,iRemovePos,TRUE); iPosition--; } break; case CMagneticView::SPECIAL_KEYS + VK_UP: // Cursor up if (iHistory < pView->m_History.GetSize()-1) iHistory++; if ((iHistory >= 0) && (pView->m_History.GetSize() > 0)) { int iOldLength = strFullLine.GetLength(); strFullLine = pView->m_History[iHistory]; pView->UseHistory(strFullLine,iOldLength); iPosition = strFullLine.GetLength(); } break; case CMagneticView::SPECIAL_KEYS + VK_DOWN: // Cursor down if (iHistory > 0) iHistory--; if ((iHistory >= 0) && (pView->m_History.GetSize() > 0)) { int iOldLength = strFullLine.GetLength(); strFullLine = pView->m_History[iHistory]; pView->UseHistory(strFullLine,iOldLength); iPosition = strFullLine.GetLength(); } break; case CMagneticView::SPECIAL_KEYS + VK_SPACE: // Space iInsertPos = strFullLine.GetLength() - iPosition; pView->InsertChar(pView->m_strOutput,(char)cInput,iInsertPos,TRUE); pView->InsertChar(strFullLine,(char)cInput,iInsertPos); iPosition++; break; default: if (isprint(cInput) && (cInput < CMagneticView::SPECIAL_KEYS)) { // Insert the character into the input string iInsertPos = strFullLine.GetLength() - iPosition; pView->InsertChar(pView->m_strOutput,(char)cInput,iInsertPos,TRUE); pView->InsertChar(strFullLine,(char)cInput,iInsertPos); iPosition++; } break; } // Update the input line pView->InvalidateRect(pView->m_LastLineRect,FALSE); } } if (pView && (strFullLine.GetLength() > 0)) { if (pView->m_bMorePrompt == false) { // Store in input history CString strHistory = strFullLine.Left(strFullLine.GetLength()-1); if (strHistory.GetLength() > 0) { pView->m_History.InsertAt(0,strHistory); if (pView->m_History.GetSize() > MAX_HISTORY) pView->m_History.RemoveAt(pView->m_History.GetSize()-1); } int i; while ((i = strHistory.Find((char)(CMagneticView::SPECIAL_KEYS + VK_SPACE))) >= 0) strHistory.SetAt(i,' '); // Input recording if ((pView->m_Recording == Recording::RecordingOn) && (pView->m_pFileRecord)) fprintf(pView->m_pFileRecord,"%s\n",strHistory); // Scrollback buffer pView->m_Scrollback.GetScrollback() += strHistory; // Scripting if (pView->m_Scripting == Scripting::ScriptingOn) pView->m_strScript += strHistory; } if (trans && (strFullLine.CompareNoCase("#undo\n") == 0)) { cInput = 0; strFullLine.Empty(); } else { cInput = strFullLine[0]; strFullLine = strFullLine.Right(strFullLine.GetLength()-1); } } if (pView) { pView->m_iLines = 0; pView->m_bInputActive = false; pView->CaretOff(); } if (cInput == (signed char)(CMagneticView::SPECIAL_KEYS + VK_SPACE)) cInput = ' '; return (char)cInput; }
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; }