BOOL CMagneticView::LineFull(CDC* pDC, LPCSTR lpszText, int iLength) { CMagneticApp* pApp = (CMagneticApp*)AfxGetApp(); CSize TextLen = pDC->GetTextExtent(lpszText,iLength); CRect Client; GetClientRect(Client); return (TextLen.cx >= (Client.Width()-(2*pApp->GetMargins().cx))) ? 1 : 0; }
void CMagneticView::SetCursorPos(CDC* pDC, int iRight) { CMagneticApp* pApp = (CMagneticApp*)AfxGetApp(); int i = m_PageTable.GetSize()-2; // Start of the last visible line int offset = m_iLines-m_iMaxLines-1; if (offset > 0) i -= offset; if (i >= 0) { CSize TextLen = pDC->GetTextExtent((LPCTSTR)m_strOutput+m_PageTable[i], m_PageTable[i+1]-m_PageTable[i]-1-iRight); // Set the caret position SetCaretPos(CPoint(TextLen.cx+pApp->GetMargins().cx,m_LastLineRect.top)); } }
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); 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 iOffset = m_bStatusBar ? iFontHeight : 0; iPicWidth = m_Picture.GetScaledWidth(); iPicHeight = m_Picture.GetScaledHeight(); if (iPicWidth > 0 && iPicHeight > 0) { TextClient.top += iPicHeight; 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*pApp->GetMargins().cy)) / iFontHeight; y += pApp->GetMargins().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(pApp->GetMargins().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 + pApp->GetMargins().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); }