示例#1
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);
}
示例#2
0
文件: caret.cpp 项目: beanhome/dev
 void PrevLine() { if ( !m_yCaret-- ) LastLine(); }