void CMagneticView::OnToggleGfx() { CMagneticApp* pApp = (CMagneticApp*)AfxGetApp(); if (GetFocus() == this) { if (m_bMorePrompt == false) { switch (pApp->GetShowGraphics()) { case CMagneticApp::ShowGraphics::NoGraphics: pApp->SetShowGraphics(CMagneticApp::ShowGraphics::SeparateWindow); break; case CMagneticApp::ShowGraphics::SeparateWindow: pApp->SetShowGraphics(CMagneticApp::ShowGraphics::MainWindow); break; case CMagneticApp::ShowGraphics::MainWindow: pApp->SetShowGraphics(CMagneticApp::ShowGraphics::NoGraphics); break; } pApp->SetRedrawStatus(CMagneticApp::Redraw::ThisLine); SetPictureWindowState(); } } }
void CMagneticView::Animate(void) { CMagneticApp* pApp = (CMagneticApp*)AfxGetApp(); if (m_bAnimate && (pApp->GetShowGraphics() != CMagneticApp::ShowGraphics::NoGraphics)) { struct ms_position * Positions; type16 Count, Width, Height; type8 * pMask; if (ms_animate(&Positions,&Count) == 0) { m_bAnimate = false; return; } ClearAnims(); for (int i = 0; i < Count; i++) { type8* pPictureData = ms_get_anim_frame(Positions[i].number,&Width,&Height,&pMask); if (pPictureData) { CMagneticPic* pFrame = new CMagneticPic(); pFrame->NewPicture(Width,Height,pPictureData,m_Palette); pFrame->SetOrigin(CPoint(Positions[i].x,Positions[i].y)); pFrame->SetMask(pMask); m_AnimFrames.Add(pFrame); } } switch (pApp->GetShowGraphics()) { case CMagneticApp::ShowGraphics::SeparateWindow: if (m_PicWnd.GetSafeHwnd()) m_PicWnd.Invalidate(); break; case CMagneticApp::ShowGraphics::MainWindow: Invalidate(); break; } } }
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; } } }
void CMagneticView::SetPictureWindowState(void) { CMagneticApp* pApp = (CMagneticApp*)AfxGetApp(); if (pApp->GetShowGraphics() == CMagneticApp::ShowGraphics::SeparateWindow) { if ((m_PicWnd.GetSafeHwnd() == NULL) && (m_Picture.IsValid())) { if (m_PicWnd.CreatePicWnd(this)) SetFocus(); } m_PicWnd.Update(); } else { if (m_PicWnd.GetSafeHwnd()) m_PicWnd.SendMessage(WM_CLOSE,0,0); } }
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); }