コード例 #1
0
ファイル: owlext.cpp プロジェクト: Meridian59/Meridian59
void DrawDisabledButton(TDC& dc, const TRect& rc)
{
  // create a monochrome memory DC
  //
  TMemoryDC ddc;
  TBitmap bmp(ddc, rc.Width(), rc.Height());
  ddc.SelectObject(bmp);

  // build a mask
  //
  ddc.PatBlt(0, 0, rc.Width(), rc.Height(), WHITENESS);
  dc.SetBkColor(TColor::Sys3dFace);
  ddc.BitBlt(0, 0, rc.Width(), rc.Height(), dc, rc.left, rc.top, SRCCOPY);
  dc.SetBkColor(TColor::Sys3dHilight);
  ddc.BitBlt(0, 0, rc.Width(), rc.Height(), dc, rc.left, rc.top, SRCPAINT);

  // Copy the image from the toolbar into the memory DC
  // and draw it (grayed) back into the toolbar.
  //
  dc.FillRect(rc, TBrush(TColor::Sys3dFace));
  dc.SetBkColor(RGB(0, 0, 0));
  dc.SetTextColor(RGB(255, 255, 255));
  TBrush brShadow(TColor::Sys3dShadow);
  TBrush brHilight(TColor::Sys3dHilight);
  dc.SelectObject(brHilight);
  dc.BitBlt(rc.left+1, rc.top+1, rc.Width(), rc.Height(), ddc, 0, 0, 0x00E20746L);
  dc.SelectObject(brShadow);
  dc.BitBlt(rc.left, rc.top, rc.Width(), rc.Height(), ddc, 0, 0, 0x00E20746L);

  // reset DCs
  //
  dc.RestoreBrush();
  dc.RestoreBrush();
  ddc.RestoreBitmap();
}
コード例 #2
0
ファイル: uiborder.cpp プロジェクト: GarMeridian3/Meridian59
//
/// Paints a 2-color single pixel-thick frame. Bevel corners get their own color.
//
void
TUIBorder::PaintFrameC(TDC& dc, const TRect& fr, uint flags, const TColor& tlColor, const TColor& brColor, const TColor& bcColor)
{
  if (flags & (Top | Left)) {
    TBrush brsh(tlColor);
    dc.SelectObject(brsh);
    if (flags & Top) {
      dc.PatBlt(fr.left, fr.top, fr.Width()-2, 1);
      dc.SetPixel(fr.right-1, fr.top, bcColor);
    }
    if (flags & Left)
      dc.PatBlt(fr.left, fr.top+1, 1, fr.Height()-2);
    dc.RestoreBrush();
  }

  if (flags & (Bottom | Right)) {
    TBrush brsh(brColor);
    dc.SelectObject(brsh);
    if (flags & Bottom) {
      dc.SetPixel(fr.left, fr.bottom-1, bcColor);
      dc.PatBlt(fr.left+1, fr.bottom-1, fr.Width(), 1);
    }
    if (flags & Right)
      dc.PatBlt(fr.right-1, fr.top, 1, fr.Height()-1);
    dc.RestoreBrush();    
  }
}
コード例 #3
0
ファイル: lprogdlg.cpp プロジェクト: GarMeridian3/Meridian59
///////////////////////////////////////////////////////////////
// TLevelProgressDialog
// --------------------
//
void DrawIconicGauge(TDC &dc, int yPosition, int Width, int Height, int Value)
{
	TBrush BleueBrush(TColor(0,0,255));
	TPen BleuePen (TColor(0,0,255));
	// TBrush GrayBrush (TColor(200,200,200));
	TPen WhitePen (TColor(255,255,255));
	TPen GrayPen (TColor(100,100,100));
	// TPen GrayPen (TColor(0,0,0));

	// Draw upper left white border
	dc.SelectObject(GrayPen);
	dc.MoveTo(0, yPosition + Height - 1);
	dc.LineTo(0, yPosition);
	dc.LineTo(Width - 1, yPosition);

	// Draw lower right border
	dc.SelectObject(WhitePen);
	dc.LineTo(Width - 1, yPosition + Height - 1);
	dc.LineTo(0, yPosition + Height - 1);

	// Draw gauge
	dc.SelectObject(BleueBrush);
	dc.SelectObject(BleuePen);
	dc.Rectangle(1, yPosition + 1, (Width - 1) * Value / 100, yPosition + Height - 1);

	dc.RestoreObjects();
}
コード例 #4
0
void TSensorView::Grid3D(TDC& dc)
{
  if(m_bGrid)
  {
    TPen pen(TColor(192,192,192),0);
    dc.SelectObject(pen);
    for (int y = 0; y <= m_ySize ; y++)
    {
      MOVE(dc,Project2D(0,y,1));
      LINE(dc,Project2D(0,y,0));
      LINE(dc,Project2D(m_xSize,y,0));
    }
    for (int x = 0; x <= m_xSize; x++)
    {
      MOVE(dc,Project2D(x,0,1));
      LINE(dc,Project2D(x,0,0));
      LINE(dc,Project2D(x,m_ySize,0));
    }
    for (SHORTREAL z = 0; z < 1.05; z += (SHORTREAL) 0.1)
    {
      MOVE(dc,Project2D(0,m_ySize,z));
      LINE(dc,Project2D(0,0,z));
      LINE(dc,Project2D(m_xSize,0,z));
    }
    dc.RestorePen();
  }
}
コード例 #5
0
void TSensorView::LineViewer(TDC& dc,PSHORTREAL pData)
{
  m_xSize = m_nDimSize[0]-1;
  m_ySize = m_nDimSize[1]-1;
  m_yAdd = (int) (500L * m_ySize / m_xSize / 2);
  dc.SetWindowExt(TSize(m_xSize * 2 +  m_ySize,500 + m_yAdd));
  Grid3D(dc);
  if(m_nDimSize[1] == 1)
    for(int x = 0; x < m_nDimSize[0]; x++)
    {
      TPoint pt = Project2D(x,0,pData[x]);
      if (x)
        LINE(dc,pt);
      else
        MOVE(dc,pt);
    }
  else
  {
    TBrush br(SYSCOLOR(COLOR_BTNFACE));
    dc.SelectObject(br);
    for (int y = 0; y < m_nDimSize[1]-1; y++)
      for (int x = 0; x < m_nDimSize[0]-1; x++)
      {
        TPoint pt[4] =
        {
          Project2D(x,y,pData[x + (LONGINT) m_nDimSize[0] * y]),
          Project2D(x+1,y,pData[x+1 + (LONGINT) m_nDimSize[0] * y]),
          Project2D(x+1,y+1,pData[x+1 + (LONGINT) m_nDimSize[0] * (y+1)]),
          Project2D(x,y+1,pData[x + (LONGINT) m_nDimSize[0] * (y+1)])
        };
        POLY(dc,pt,4);
      }
  }
  dc.RestorePen();
}
コード例 #6
0
ファイル: font.cpp プロジェクト: Darkman-M59/Meridian59_115
//
/// Retrieves information about this font when selected in the specified dc.
//
void
TFont::GetTextMetrics(TEXTMETRIC& tm, TDC& dc) const
{
  dc.SelectObject(*this);
  dc.GetTextMetrics(tm);
  dc.RestoreFont();
}
コード例 #7
0
//
/// Paint the text gadget by painting gadget borders, & then painting text in
/// the InnerRect. Empty or 0 text blanks the gadget.
//
/// Calls TGadget::PaintBorder to paint the border. Calls TGadget::GetInnerRect to
/// calculate the area of the text gadget's rectangle. If the text is left-aligned,
/// Paint calls dc.GetTextExtent to compute the width and height of a line of the
/// text. To set the background color, Paint calls dc.GetSysColor and sets the
/// default background color to face shading (COLOR_BTNFACE). To set the button text
/// color, Paint calls dc.SetTextColor and sets the default button text color to
/// COLOR_BTNTEXT. To draw the text, Paint calls dc.ExtTextOut and passes the
/// parameters ETO_CLIPPED (so the text is clipped to fit the rectangle) and
/// ETO_OPAQUE (so the rectangle is filled with the current background color).
//
void
TTextGadget::Paint(TDC& dc)
{
  PaintBorder(dc);

  TRect  innerRect;
  GetInnerRect(innerRect);

  if (!Font)
    dc.SelectObject(GetGadgetWindow()->GetFont());
  else
    dc.SelectObject(*Font);

  TColor textColor = GetEnabledColor();
  if(!GetEnabled())
    textColor = TColor::Sys3dHilight;

  bool transparent = GetGadgetWindow()->GetFlatStyle() & TGadgetWindow::FlatXPTheme;
  if(!Text){
    if (!transparent)
    {
    TColor color = dc.SetBkColor(TColor::Sys3dFace);
    dc.ExtTextOut(0,0, ETO_OPAQUE, &innerRect, _T(""), 0);
    dc.SetBkColor(color);
  }
  }
  else
  {
    // Create a UI Face object for this button & let it paint the button face
    //
    uint align[] = {DT_LEFT, DT_CENTER, DT_RIGHT};
    uint format =  DT_SINGLELINE | DT_VCENTER | align[Align];
            TUIFace face(innerRect, Text, BkgndColor, format);

     TPoint  dstPt(innerRect.TopLeft());

      dc.SetBkColor(BkgndColor);

     TColor oldTxColor  = dc.SetTextColor(textColor);
    if (!GetEnabled())
      face.Paint(dc, dstPt, TUIFace::Disabled, false, !transparent);
    else
      face.Paint(dc, dstPt, TUIFace::Normal, false, !transparent);
    dc.SetTextColor(oldTxColor);
  }
  dc.RestoreFont();
}
コード例 #8
0
void TSensorView::ColumnViewer(TDC& dc,PSHORTREAL pData)
{
  m_xSize = m_nDimSize[0];
  m_ySize = m_nDimSize[1];
  m_yAdd = (int) (500L * m_ySize / m_xSize / 2);
  dc.SetWindowExt(TSize(m_xSize * 2 +  m_ySize,500 + m_yAdd));
  Grid3D(dc);
  TBrush brGray(SYSCOLOR(COLOR_BTNFACE)),
			brWhite(SYSCOLOR(COLOR_BTNHIGHLIGHT)),
			brDark(SYSCOLOR(COLOR_BTNSHADOW));
  for (int y = 0; y < m_nDimSize[1]; y++)
    for (int x = 0; x < m_nDimSize[0]; x++)
    {
      SHORTREAL r = pData[x + (LONGINT) m_nDimSize[0] * y];
      TPoint pt[4] =
      {
        Project2D(x,y+1,r),
        Project2D(x+1,y+1,r),
        Project2D(x+1,y,r),
        Project2D(x,y,r)
      };
      dc.SelectObject(brWhite);
      POLY(dc,pt,4);
      SHORTREAL r2 = y == m_nDimSize[1]-1
                     ? 0
                     : pData[x + (LONGINT) m_nDimSize[0] * (y+1)];
      if(r2 < r)
      {
        pt[2] = Project2D(x+1,y+1,r2);
        pt[3] = Project2D(x,y+1,r2);
        dc.SelectObject(brGray);
        POLY(dc,pt,4);
      }
      r2 = x == m_nDimSize[0]-1 ? 0
                  : pData[x+1 + (LONGINT) m_nDimSize[0] * y];
      if (r2 < r)
      {
        pt[0] = Project2D(x+1,y,r);
        pt[2] = Project2D(x+1,y+1,r2);
        pt[3] = Project2D(x+1,y,r2);
        dc.SelectObject(brDark);
        POLY(dc,pt,4);
      }
    }
  dc.RestoreBrush();
}
コード例 #9
0
ファイル: font.cpp プロジェクト: Darkman-M59/Meridian59_115
//
/// Returns the extent of a given string using this particular font in a
/// particular DC.
//
TSize
TFont::GetTextExtent(TDC& dc, const tstring& text) const
{
  dc.SelectObject(*this);
  TSize size = dc.GetTextExtent(text, static_cast<int>(text.length())); // TODO: Widen parameter type to avoid this narrowing cast.
  dc.RestoreFont();
  return size;
}
コード例 #10
0
ファイル: gaugegad.cpp プロジェクト: Meridian59/Meridian59
void
TGaugeGadget::Paint(TDC& dc, bool erase, TRect &rect)
{
  // Select the approprate font
  dc.SelectObject(Window->GetFont());
  TGauge::Paint(dc, erase, rect);
  dc.RestoreFont();
}
コード例 #11
0
ファイル: urllink.cpp プロジェクト: Meridian59/Meridian59
//
/// Override TWindow virtual member function to paint the control.
//
void
TUrlLink::Paint(TDC& dc, bool /*erase*/, TRect& /*rect*/)
{
  TPointer<TFont>  tmpFnt; // Object wrapping font handle
  TAPointer<tchar> text;   // Pointer to caption dynamic buffer
  // Select the font
  if(!LinkFont){
    HFONT hFont = HFONT(::SendMessage(::GetParent(*this), WM_GETFONT, 0, 0));
    if (!hFont)
      hFont = HFONT(GetStockObject(ANSI_VAR_FONT));
    if (hFont)
      tmpFnt = new TFont(hFont);
  }
  if (LinkFont) {
    CHECK(LinkFont->IsGDIObject());
    dc.SelectObject(*LinkFont);
  }
  else if (tmpFnt) {
    CHECK(((TFont&)tmpFnt).IsGDIObject());
    dc.SelectObject((TFont&)tmpFnt);
  }
  int len = GetWindowTextLength();
  text = new tchar[len+1];
  GetWindowText(text, len+1);
  TRect textRect;
  GetClientRect(textRect);

  TColor textColor = LinkColor;
  if (bOverControl)
    textColor = HoverColor;
  else if (bVisited)
    textColor = VisitedColor;

  TColor oldColor = dc.SetTextColor(textColor);
  int oldMode = dc.SetBkMode(TRANSPARENT);
  dc.DrawText(&text[0], len, textRect, 0);
  dc.SetBkMode(oldMode);
  dc.SetTextColor(oldColor);

  // Restore font
  if (LinkFont || tmpFnt)
    dc.RestoreFont();
}
コード例 #12
0
//
/// Puts the font into the device context and calls PaintGadgets.
///
/// Respond to virtual TWindow Paint call. Call our own virtual PaintGadgets
/// to actually perform the painting of the gadgets
//
void
TGadgetWindow::Paint(TDC& dc, bool erase, TRect& rect)
{
  if (IsBackgroundThemed())
  {
    TThemePart part(GetHandle(), (LPCWSTR) L"REBAR", 0, 0);
    part.DrawBackground(dc, GetClientRect(), rect);
    erase = false;
  }

  dc.SelectObject(*Font);
  PaintGadgets(dc, erase, rect);

#if defined(__TRACE) || defined(__WARN)
  // Highlight the tools of this gadgetwindow for debugging purposes.
  // Especially useful for docking windows which undergo internal state
  // changes
  //
  TProfile iniFile(_T("Diagnostics"), _T(OWL_INI));

  bool useDiagColor = iniFile.GetInt(_T("DiagToolbarBorders")) != 0;

  if (useDiagColor && Tooltip && Tooltip->IsWindow()) {
    uint count = Tooltip->GetToolCount();
    if (count) {
      TPen redPen(TColor(0xff, 0, 0));
      dc.SelectObject(redPen);

      TToolInfo ti;
      while (count) {
        if (Tooltip->EnumTools(--count, ti)) {
          dc.MoveTo(ti.rect.left, ti.rect.top);
          dc.LineTo(ti.rect.right,ti.rect.top);
          dc.LineTo(ti.rect.right,ti.rect.bottom);
          dc.LineTo(ti.rect.left, ti.rect.bottom);
          dc.LineTo(ti.rect.left, ti.rect.top);
        }
      }
      dc.RestorePen();
    }
  }
#endif
}
コード例 #13
0
void TSensorView::Grid2D(TDC& dc)
{
  if(m_bGrid)
  {
    TPen pen(TColor(0,0,0),0);
    dc.SelectObject(pen);
    for (int y = 0; y <= m_nDimSize[1] ; y++)
    {
      MOVE(dc,TPoint(0,y));
      LINE(dc,TPoint(m_nDimSize[0],y));
    }
    for (int x = 0; x <= m_nDimSize[0]; x++)
    {
      MOVE(dc,TPoint(x,0));
      LINE(dc,TPoint(x,m_nDimSize[1]));
    }
    dc.RestorePen();
  }
}
コード例 #14
0
ファイル: infocont.cpp プロジェクト: Tatsujinichi/Meridian59
/////////////////////////////////////////////////////////////////////
// TInfoControl
// ------------
//
void TInfoControl::Paint (TDC& dc, BOOL erase, TRect& rect)
{
	TControl::Paint(dc, erase, rect);

	TRect cRect = GetClientRect();

	// Select font
	dc.SelectObject (*StaticFont);
	dc.SetBkMode (TRANSPARENT);

	// Draw each text line
	if ( TextLineTab != NULL )
	{
		for (int i = 0 ; i < NumLines ; i++)
		{
			if (TextLineTab[i] != NULL  && TextLineTab[i]->Text != NULL)
			{
				int x;

				dc.SetTextColor ( TMapDC::GetColor16(TextLineTab[i]->Color));
				dc.SetTextAlign( TextLineTab[i]->Align);

				switch (TextLineTab[i]->Align & (TA_CENTER |TA_LEFT |TA_RIGHT))
				{
				case TA_LEFT:
					x = 0;
					break;
				case TA_CENTER:
					x = cRect.Width() / 2;
					break;
				case TA_RIGHT:
					x = cRect.Width() - 1;
					break;
				}

				dc.TextOut( x, FontHeight * i, TextLineTab[i]->Text);
			}
		}
	}
	dc.RestoreFont();
}
コード例 #15
0
ファイル: messageb.cpp プロジェクト: Meridian59/Meridian59
//
/// Adjusts the message bar and paints a highlight line. Then, PaintGadgets either
/// paints the hint text if any is set or calls TGadgetWindow::PaintGadgets to
/// repaint each gadget.
//
void
TMessageBar::PaintGadgets(TDC& dc, bool erase, TRect& rect)
{
  if (HighlightLine && rect.top == 0)
    dc.TextRect(0, 0, rect.right, TUIMetric::CyBorder, TColor::Sys3dHilight);

  if (!HintText.empty())
  {
    TRect clientRect = GetClientRect();
    int y = (clientRect.bottom - GetFontHeight()) / 2;
    if (HighlightLine)
      clientRect.top += TUIMetric::CyBorder;
    dc.SelectObject(GetFont());
    dc.SetBkColor(TColor::Sys3dFace);
    dc.ExtTextOut(5, y, ETO_OPAQUE, &clientRect, HintText, static_cast<int>(HintText.length()));
  }
  else
  {
    TGadgetWindow::PaintGadgets(dc, erase, rect);
  }
}
コード例 #16
0
void TFuncSpecView::Paint(TDC& dc, bool erase, TRect& rect)
{
  TSwitchMinApp* theApp = TYPESAFE_DOWNCAST(GetApplication(), TSwitchMinApp);
  if (theApp) {
    // Only paint if we're printing and we have something to paint, otherwise do nothing.
    //
    if (theApp->Printing && theApp->Printer && !rect.IsEmpty()) {
      // Use pageSize to get the size of the window to render into.  For a Window it's the client area,
      // for a printer it's the printer DC dimensions and for print preview it's the layout window.
      //
      TSize   pageSize(rect.right - rect.left, rect.bottom - rect.top);

      TPrintDialog::TData& printerData = theApp->Printer->GetSetup();

      // Get area we can draw in
      TRect drawingArea(swdoc->PaintHeader(dc, rect, "", 0, 0, false), rect.BottomRight());

      TEXTMETRIC tm;
      dc.SelectObject(TFont("Arial", -12));
      if (!dc.GetTextMetrics(tm)) {
        dc.SelectObject(TFont("Arial", -12));
        dc.GetTextMetrics(tm);
      }
      int fHeight=tm.tmHeight+tm.tmExternalLeading;

      unsigned long inputs=swdoc->GetSystem()->GetInputs();

      XPosVector xpos;
      uint divider;
      char* data;

      Print_CreateWidths(xpos, divider, dc);
      if (xpos.back().x < rect.Size().cx) {  // put space in structure to stretch across page
        uint spacing=(rect.Size().cx - xpos.back().x)/(xpos.size()+1);
        uint space_inc=spacing;
        for(XPosVector::size_type i=0; i<xpos.size(); i++) {
          if (i==inputs) {  // after inputs section, increase divider
            divider += space_inc;
            space_inc += spacing;
          }
          xpos[i].x += space_inc;
          space_inc += spacing;
        }
      }

      data=new char[xpos.size()];

      unsigned long PagesDown=1+pow(2,inputs)/( (drawingArea.Size().cy/fHeight) - 2);  // 2 lines for header and horz divider
      unsigned long PagesAcross=1+xpos.back().x/drawingArea.Size().cx;
      unsigned long Pages=1+PagesDown*PagesAcross;

      // Compute the number of pages to print.
      //
      printerData.MinPage = 1;
      printerData.MaxPage = Pages;


      int fromPage = printerData.FromPage == -1 ? 1 : printerData.FromPage;
      int toPage = printerData.ToPage == -1 ? 1 : printerData.ToPage;
      int currentPage = fromPage;

      TPoint p;

      dc.SelectObject(TPen(TColor::Black));

      while (currentPage <= toPage) {
        swdoc->PaintHeader(dc, rect, "Specification", currentPage, Pages, true);
        if (currentPage==1) Print_Summary(dc, drawingArea);
        else {
          // Calculate origin of line by page number
            // x
            int col=((currentPage-2) ) % PagesAcross;
            p.x=drawingArea.left - col * drawingArea.Size().cx;
            // y
            int row=floor((currentPage-2)/PagesAcross);
            p.y=drawingArea.top/* - row * drawingArea.Size().cy*/;

          // Calculate starting and ending input states
          CELL_TYPE state, stateEnd;
          state=(row*(drawingArea.Size().cy-fHeight))/fHeight;
          stateEnd=state+(drawingArea.Size().cy-fHeight)/fHeight;
          if (stateEnd >= (pow(2,inputs)-1) ) stateEnd=pow(2,inputs)-1;

          //
          // Draw header and lines

          // Vertical
          if ( ((p.x+divider) > drawingArea.left) && ((p.x+divider)<drawingArea.right) ) {
            dc.MoveTo(p.x+divider, p.y);
            dc.LineTo(p.x+divider, p.y+((stateEnd-state)+3)*fHeight);
          }

          // Labels
          for(XPosVector::size_type i=0; i<xpos.size(); i++)
            dc.TextOut(TPoint(xpos[i].x, p.y), xpos[i].s.c_str());
          p.y += fHeight;

          // Horizontal
          dc.MoveTo(drawingArea.left, p.y + fHeight/2);
          dc.LineTo(p.x+xpos.back().x, p.y + fHeight/2);
          p.y += fHeight;

          //
          // Draw each line
          while(state <= stateEnd) {
            Print_GenerateLine(data, state);
            Print_Line(dc, p, xpos, data);
            p.y += fHeight;
            state++;
          }
        }

        currentPage++;
      }

      delete[] data;
    }
    else {
      // INSERT>> Normal painting code goes here.
      wTabs->InvalidateRect(rect, erase);
    }
  }
}
コード例 #17
0
ファイル: uiborder.cpp プロジェクト: GarMeridian3/Meridian59
//
/// This is a static function that performs the actual drawing of edges for a
/// UIBorder or an external client. It uses the system ::DrawEdge if available.
//
bool
TUIBorder::DrawEdge(TDC& dc, const TRect& frame, uint edge, uint flags)
{
  static int hasDrawEdge = true;

  // Try once to see if the API call is available. If not, do ourselves.
  //
  if (hasDrawEdge) {
    if (::DrawEdge(dc, (LPRECT)&frame, edge, flags))
      return true;
    if (::GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
      hasDrawEdge = false;
    else
      return false;
  }

  // ::DrawEdge is not available, do the drawing ourselves
  //
  TRect f(frame);  // working frame rectangle

  // If mono is set, draw a thin, flat, black (windowFrame) frame
  //
  if (flags & Mono) {
    if (edge & EdgeOuter) {
      PaintFrame(dc, f, flags, TColor::SysWindowFrame, TColor::SysWindowFrame);
      f.Inflate(-1,-1);
    }
    if (flags & Fill) { // !CQ repeated code--nest else?
      TBrush brsh(TColor::SysWindow);
      dc.SelectObject(brsh);
      dc.PatBlt(f);
      dc.RestoreBrush();
    }
    return true;
  }

  // If flat is set, draw a thin, flat, shadow frame
  //
  if (flags & Flat) {
    if (edge & EdgeOuter) {
      PaintFrame(dc, f, flags, TColor::Sys3dShadow, TColor::Sys3dShadow);
      f.Inflate(-1,-1);
    }
    if (flags & Fill) { // !CQ repeated code--nest else?
      TBrush brsh(TColor::Sys3dFace);
      dc.SelectObject(brsh);
      dc.PatBlt(f);
      dc.RestoreBrush();
    }
    return true;
  }

  // Draw outer edge if indicated, adjusting rect afterwards
  //
  if (edge & EdgeOuter) {
    static TColor tlColors[] = {
      TColor::Sys3dLight,       // EdgeRaised
      TColor::Sys3dHilight,     // EdgeRaised + Soft
      TColor::Sys3dShadow,      // EdgeSunken
      TColor::Sys3dDkShadow,    // EdgeSunken + Soft
    };
    static TColor brColors[] = {
      TColor::Sys3dDkShadow,    // EdgeRaised
      TColor::Sys3dDkShadow,    // EdgeRaised + Soft
      TColor::Sys3dHilight,     // EdgeSunken
      TColor::Sys3dHilight,     // EdgeSunken + Soft
    };
    int ci = ((edge & SunkenOuter) ? 2 : 0) | ((flags & Soft) ? 1 : 0);
    PaintFrame(dc, f, flags, tlColors[ci], brColors[ci]);
    f.Inflate(-1,-1);
  }

  // Draw inner edge if indicated, adjusting rect afterwards
  //
  if (edge & EdgeInner) {
    static TColor tlColors[] = {
      TColor::Sys3dHilight,     // EdgeRaised
      TColor::Sys3dLight,       // EdgeRaised + Soft
      TColor::Sys3dDkShadow,    // EdgeSunken
      TColor::Sys3dShadow,      // EdgeSunken + Soft
    };
    static TColor brColors[] = {
      TColor::Sys3dShadow,      // EdgeRaised
      TColor::Sys3dShadow,      // EdgeRaised + Soft
      TColor::Sys3dLight,       // EdgeSunken
      TColor::Sys3dLight,       // EdgeSunken + Soft
    };
    int ci = ((edge & SunkenOuter) ? 2 : 0) | ((flags & Soft) ? 1 : 0);
    PaintFrame(dc, f, flags, tlColors[ci], brColors[ci]);
    f.Inflate(-1,-1);
  }

  // Fill interior if indicated
  //
  if (flags & Fill) {
    TBrush brsh(TColor::Sys3dFace);
    dc.SelectObject(brsh);
    dc.PatBlt(f);
    dc.RestoreBrush();
  }

// !CQ not really usefull since frame is not returned
//  if (flags & Adjust)
//    frame = f;

  return true;
}
コード例 #18
0
//
/// Paints the DIB onto the window.
//
void
TPictureWindow::Paint(TDC& dc, bool /*erase*/, TRect& /*rect*/)
{
  TPointer<TPalette> palette(0);
  bool hasPalette = ToBool(dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE);

  TDib* dib = GetDib();
  if (dib) {
    if (hasPalette) {
      palette = new TPalette(*GetDib());
      dc.SelectObject(*palette);
      dc.RealizePalette();
    }

    // figure out upper left corner of the client area
    //
    TRect clientRect(GetClientRect());
    TPoint sourcePoint(0, 0);

    // adjust the upper left corner for centering picture
    //
    if (HowToDisplay == Center) {
      // determine offsets
      //
      int offsetX = abs(dib->Width() - clientRect.Width()) / 2;
      if (dib->Width() > clientRect.Width())
        sourcePoint.x += offsetX;
      else
        clientRect.Offset(offsetX, 0);

      int offsetY = abs(dib->Height() - clientRect.Height()) / 2;
      if (dib->Height() > clientRect.Height())
        sourcePoint.y += offsetY;
      else
        clientRect.Offset(0, offsetY);
    }

    // adjust the lower right corner
    //
    if (HowToDisplay != Stretch) {
      clientRect.bottom = clientRect.top + dib->Height();
      clientRect.right  = clientRect.left + dib->Width();

      // if the picture is larger than screen dimensions,
      // adjust the upper left corner.
      //
      clientRect.top   -= sourcePoint.y;
      clientRect.left  -= sourcePoint.x;
    }

    // display the dib
    //
    switch (HowToDisplay) {
      case UpperLeft:
      case Center:
        dc.SetDIBitsToDevice(clientRect, sourcePoint, *dib);
//        if(!dc.SetDIBitsToDevice(clientRect, sourcePoint, *dib)){
//          TSystemMessage().MessageBox();
//        }
        break;
      case Stretch: {
        TRect sourceRect(0, 0, dib->Width(), dib->Height());
        dc.StretchDIBits(clientRect, sourceRect, *dib);
        break;
      }
    } // switch HowToDisplay

    dc.RestoreObjects();
  }
}
コード例 #19
0
ファイル: DISPLAY.CPP プロジェクト: abishekahluwaila/read
void npredictMDIChild::Paint ( TDC& dc , BOOL , TRect& )
{
	int i, j, n, b, row, col, rstart, rstop, cstart, cstop, prevcol ;
	int xlab_height, xlab_width, ylab_height, ylab_width, wide ;
	int xlab_lw, xlab_rw, tick_height, font_height, r0, r1, c0 ;
	double xscale, yscale, xtickscale, ytickscale, *sig, val ;
   double x, xfac ;
	char msg[256] ;
	TRect rect ;
	SIZE size ;
	TColor bkgnd, *lines ;
	TBrush *brush ;
	TPen *pen, *second_pen ;
   TFont *font ;

	n = istop - istart + 1 ;
	sig = signal->sig ;
	
	dc.SetMapMode ( MM_TEXT ) ;
	dc.SetROP2 ( R2_COPYPEN ) ;
	dc.SetBkMode ( OPAQUE ) ;
	bkgnd = dc.GetNearestColor ( TColor ( background_color ) ) ;
	dc.SetBkColor ( bkgnd ) ;
	GetClientRect ( rect ) ;
	b = rect.bottom ;   // We use origin at bottom, so b-y adapts to Windows

/*
	Paint the background
*/

	brush = new TBrush ( bkgnd ) ;
	dc.SelectObject ( *brush ) ;
	pen = new TPen ( bkgnd ) ;
	dc.SelectObject ( *pen ) ;
	dc.Rectangle ( rect ) ;
	dc.RestoreBrush () ;
	delete brush ;
	dc.RestorePen () ;
	delete pen ;
		
/*
   Setup main drawing pen and secondary pen for hash lines
*/

   lines = new TColor ( 0 , 0 , 0 ) ;
	pen = new TPen ( *lines , 1 , PS_SOLID ) ;
	second_pen = new TPen ( *lines , 1 , PS_DASH ) ;

/*
	Compute the maximum height and width of the axis tick labels.
	This lets us position the graph optimally.
*/
	
	xlab_height = xlab_width = ylab_height = ylab_width = xlab_lw = xlab_rw = 0 ;
	
	font_height = rect.bottom / 20 ;
	if (rect.right / 24 < font_height)
		font_height = rect.right / 24 ;

	if (font_height < 8)
      font_height = 0 ;

	if (font_height) {
		font = new TFont ( "Helvetica" , font_height ) ;
		dc.SelectObject ( *font ) ;
   	for (i=0 ; i<xnticks ; i++) {
   		sprintf ( msg , "%*.*lf", xndigits, xnfrac, xmin + i * xdif ) ;
   		GetTextExtentPoint ( dc , msg , strlen(msg) , &size ) ;
   		if (! i)
   			xlab_lw = size.cx ;      // Width of leftmost x label
   		if (i == xnticks-1)
   			xlab_rw = size.cx ;      // And rightmost x label
   		if (size.cx > xlab_width)
   			xlab_width = size.cx ;
   		if (size.cy > xlab_height)
   			xlab_height = size.cy ;
   		}

   	for (i=0 ; i<ynticks ; i++) {
   		sprintf ( msg , "%*.*lf", yndigits, ynfrac, ymin + i * ydif ) ;
   		GetTextExtentPoint ( dc , msg , strlen(msg) , &size ) ;
			if (size.cx > ylab_width)
				ylab_width = size.cx ;
			if (size.cy > ylab_height)
				ylab_height = size.cy ;
			}

		tick_height = xlab_height / 2 ;
		}

	else {
		tick_height = rect.bottom / 64  +  2 ;
      font = NULL ;
      }

/*
   Last check on label display.  Are X-axis labels to wide?
*/

   if ((xlab_width * xnticks) > (3 * rect.right / 4)) {
      font_height = 0 ;
	   xlab_height = xlab_width = ylab_height = ylab_width = 0 ;
      xlab_lw = xlab_rw = 0 ;
		tick_height = rect.bottom / 64  +  2 ;
      if (font != NULL) {
	      dc.RestoreFont () ;
      	delete font ;
         font = NULL ;
         }
      }

/*
	Compute the graph extent based on these label metrics
*/

	
	rstart = tick_height + xlab_height + 1  ;  // Ticks, X tick labels
	rstop = rect.bottom - ylab_height/2 - 2 ;  // Top half of topmost label

	if (xlab_lw / 2  >  ylab_width)            // If left half of X label biggest
		cstart = xlab_lw / 2 + 1 ;              // Use it for offset
	else
		cstart = ylab_width + 2 ;               // Otherwise Y labels determine it

	cstop = rect.right - xlab_rw / 2 - 2 ;     // Leave room for rightmost label
	
/*
	Compute scales for data and ticks
*/

   xscale = (double) (cstop - cstart) / (xmax - xmin) ;
   xfac = (rightx - leftx) / (n-1) ;
	yscale = (double) (rstop - rstart) / (ymax - ymin) ;

	xtickscale = (double) (cstop-cstart) / (double) (xnticks-1) ;
	ytickscale = (double) (rstop-rstart) / (double) (ynticks-1) ;

/*
	Outline the graph, draw ticks, and write their labels
*/

	dc.SelectObject ( *pen ) ;
	dc.MoveTo ( cstart , b-rstart ) ;
	dc.LineTo ( cstop , b-rstart ) ;
	dc.LineTo ( cstop , b-rstop ) ;
	dc.LineTo ( cstart , b-rstop ) ;
	dc.LineTo ( cstart , b-rstart ) ;
	dc.RestorePen () ;

	for (i=0 ; i<ynticks ; i++) {                 /* Y ticks */
		row = rstart + i * ytickscale + 0.5 ;
		if (i  &&  (i < ynticks-1)) {  // Horizontal interior lines
         dc.SelectObject ( *second_pen ) ;
			dc.MoveTo ( cstart , b-row ) ;
			dc.LineTo ( cstop , b-row ) ;
         dc.RestorePen () ;
			}
      if (font_height) {
   		sprintf ( msg , "%*.*lf", yndigits, ynfrac, ymin + i * ydif ) ;
   		rect.bottom = b - (row - ylab_height / 2) ;
   		rect.top = rect.bottom - ylab_height - 1 ;
   		rect.right = cstart - 1 ;
   		rect.left = rect.right - ylab_width - 1 ;
         dc.SelectObject ( *pen ) ;
   		dc.DrawText ( msg , -1 , rect , DT_SINGLELINE | DT_BOTTOM | DT_RIGHT );
         dc.RestorePen () ;
         }
		}

   dc.SelectObject ( *pen ) ;
	prevcol = 0 ;
	for (i=0 ; i<xnticks ; i++) {                         /* X ticks */
		col = cstart + i * xtickscale + 0.5 ;
		dc.MoveTo ( col , b-rstart ) ;
		dc.LineTo ( col , b-(rstart - tick_height) ) ;
		if (i) {  /* Make an additional, unlabeled tick between main ones */
			dc.MoveTo ( (col + prevcol) / 2  , b-rstart ) ;
			dc.LineTo ( (col + prevcol) / 2 , b-(rstart - tick_height/2) ) ;
			}
		prevcol = col ;
		if (font_height) {
			sprintf ( msg , "%*.*lf", xndigits, xnfrac, xmin + i * xdif ) ;
         while (*msg == ' ')          // Remove leading blanks
            strcpy ( msg , msg+1 ) ;
			rect.top = b - (rstart - tick_height) ;
			rect.bottom = rect.top + xlab_height - 1 ;
			rect.right = col + xlab_width / 2 ;
			rect.left = rect.right - xlab_width - 1 ;
			dc.DrawText ( msg , -1 , rect , DT_SINGLELINE | DT_BOTTOM | DT_CENTER);
			}
		}
   dc.RestorePen () ;

   if (font_height) {
	   dc.RestoreFont () ;
   	delete font ;
      }

/*
   Draw the graph
*/

   if ((signal->type == DataSignal)  ||  (signal->type == SpectrumSignal)
    || (signal->type == SpectrumDevSignal)) {
      if ((command_id == ID_PRED_DISPLAY_CONFIDENCE) && // Draw confidence first
          (signal->known_n <= istop)) {                 // If visible
         delete second_pen ;    // No longer needed for hash lines, so use for
         second_pen = new TPen ( *lines , 1 , PS_DOT ) ; // Confidence lines
         dc.SelectObject ( *second_pen ) ;
         i = signal->known_n - 1 ;
         if (i >= istart)
            r0 = rstart + (int) ((sig[i] - ymin) * yscale) ;
         else {
            i = istart ;
            j = i - signal->known_n ;
            if (signal->mult_conf)
               val = sig[i] * signal->intervals[2*j] ;
            else 
               val = sig[i] + signal->intervals[2*j] ;
            r0 = rstart + (int) ((val - ymin) * yscale + 0.5) ;
            }
         if (r0 < rstart)
            r0 = rstart ;
         if (r0 > rstop)
            r0 = rstop ;
         r0 = b - r0 ;
         x = (i - istart) * xfac + leftx ;
         c0 = cstart + (int) (xscale * (x-xmin) + 0.5) ;
         dc.MoveTo ( c0 , r0 ) ;
         for (i=i+1 ; i<signal->known_n+signal->npred ; i++) {
            if (i > istop)
               break ;
            j = i - signal->known_n ;
            if (signal->mult_conf)
               val = sig[i] * signal->intervals[2*j] ;
            else 
               val = sig[i] + signal->intervals[2*j] ;
            r0 = rstart + (int) ((val - ymin) * yscale + 0.5) ;
            if (r0 < rstart)
               r0 = rstart ;
            if (r0 > rstop)
               r0 = rstop ;
            r0 = b - r0 ;
            x = (i - istart) * xfac + leftx ;
            c0 = cstart + (int) (xscale * (x-xmin) + 0.5) ;
      		dc.LineTo ( c0 , r0 ) ;
            }

         i = signal->known_n - 1 ;
         if (i >= istart)
            r0 = rstart + (int) ((sig[i] - ymin) * yscale) ;
         else {
            i = istart ;
            j = i - signal->known_n ;
            if (signal->mult_conf)
               val = sig[i] * signal->intervals[2*j] ;
            else 
               val = sig[i] + signal->intervals[2*j] ;
            r0 = rstart + (int) ((val - ymin) * yscale + 0.5) ;
            }
         if (r0 < rstart)
            r0 = rstart ;
         if (r0 > rstop)
            r0 = rstop ;
         r0 = b - r0 ;
         x = (i - istart) * xfac + leftx ;
         c0 = cstart + (int) (xscale * (x-xmin) + 0.5) ;
         dc.MoveTo ( c0 , r0 ) ;
         for (i=signal->known_n ; i<signal->known_n+signal->npred ; i++) {
            if (i > istop)
               break ;
            j = i - signal->known_n ;
            if (signal->mult_conf)
               val = sig[i] * signal->intervals[2*j+1] ;
            else 
               val = sig[i] + signal->intervals[2*j+1] ;
            r0 = rstart + (int) ((val - ymin) * yscale + 0.5) ;
            if (r0 < rstart)
               r0 = rstart ;
            if (r0 > rstop)
               r0 = rstop ;
            r0 = b - r0 ;
            x = (i - istart) * xfac + leftx ;
            c0 = cstart + (int) (xscale * (x-xmin) + 0.5) ;
      		dc.LineTo ( c0 , r0 ) ;
            }
         dc.RestorePen () ;
         }

      if (signal->type == SpectrumDevSignal) {
         delete second_pen ;    // No longer needed for hash lines, so use for
         second_pen = new TPen ( *lines , 1 , PS_DOT ) ; // Confidence lines
         dc.SelectObject ( *second_pen ) ;
         row = rstart + (int) ((corrlim - ymin) * yscale + 0.5) ; // Confidence
         if ((row >= rstart)  &&  (row <= rstop)) {
            dc.MoveTo ( cstart , b-row ) ;
            dc.LineTo ( cstop , b-row ) ;
            }
         row = rstart + (int) ((-corrlim - ymin) * yscale + 0.5) ; // Confidence
         if ((row >= rstart)  &&  (row <= rstop)) {
            dc.MoveTo ( cstart , b-row ) ;
            dc.LineTo ( cstop , b-row ) ;
            }
         dc.RestorePen () ;
         }

      dc.SelectObject ( *pen ) ;
      r0 = rstart + (int) ((sig[istart] - ymin) * yscale) ;
      if (r0 < rstart)
         r0 = rstart ;
      if (r0 > rstop)
         r0 = rstop ;
      r0 = b - r0 ;
      x = leftx ;
      c0 = cstart + (int) (xscale * (x-xmin) + 0.5) ;
      dc.MoveTo ( c0 , r0 ) ;
   	for (i=istart+1 ; i<=istop ; i++) {
         r0 = rstart + (int) ((sig[i] - ymin) * yscale + 0.5) ;
         if (r0 < rstart)
            r0 = rstart ;
         if (r0 > rstop)
            r0 = rstop ;
         r0 = b - r0 ;
         x = (i - istart) * xfac + leftx ;
         c0 = cstart + (int) (xscale * (x-xmin) + 0.5) ;
   		dc.LineTo ( c0 , r0 ) ;
   		}
      dc.RestorePen () ;
      } // If DataSignal or SpectrumSignal

   else if (signal->type == CorrelationSignal) {
      delete second_pen ;    // No longer needed for hash lines, so use for
      second_pen = new TPen ( *lines , 1 , PS_DOT ) ; // Confidence lines
      dc.SelectObject ( *second_pen ) ;
      row = rstart + (int) ((corrlim - ymin) * yscale + 0.5) ; // Confidence
      if ((row >= rstart)  &&  (row <= rstop)) {
         dc.MoveTo ( cstart , b-row ) ;
         dc.LineTo ( cstop , b-row ) ;
         }
      row = rstart + (int) ((-corrlim - ymin) * yscale + 0.5) ; // Confidence
      if ((row >= rstart)  &&  (row <= rstop)) {
         dc.MoveTo ( cstart , b-row ) ;
         dc.LineTo ( cstop , b-row ) ;
         }
      dc.RestorePen () ;
      wide = (cstop - cstart) / n ;
      r0 = rstart + (int) ((0.0 - ymin) * yscale + 0.5) ;
      for (i=0 ; i<ynticks ; i++) {            // Search all horizontal ticks
         row = rstart + i * ytickscale + 0.5 ; // Because rounding error
         if (abs ( r0 - row ) <= 1) {          // Might make 0 off by one
            r0 = row ;                         // Which looks ugly
            break ;
            }
         }
      if (r0 < rstart)
         r0 = rstart ;
      if (r0 > rstop)
         r0 = rstop ;
      r0 = b - r0 ;
      dc.SelectObject ( *pen ) ;
   	for (i=0 ; i<n ; i++) {
         c0 = cstart + (int) (xscale * (i+1) + 0.5) ;
         r1 = rstart + (int) ((sig[i] - ymin) * yscale + 0.5) ;
         if (r1 < rstart)
            r1 = rstart ;
         if (r1 > rstop)
            r1 = rstop ;
         r1 = b - r1 ;
         dc.MoveTo ( c0 , r0 ) ;
   		dc.LineTo ( c0 , r1 ) ;
         if (wide && (c0 > cstart)) {
            dc.MoveTo ( c0-1 , r0 ) ;
            dc.LineTo ( c0-1 , r1 ) ;
            }
         if (wide && (c0 < cstop)) {
            dc.MoveTo ( c0+1 , r0 ) ;
            dc.LineTo ( c0+1 , r1 ) ;
            }
         if ((wide > 9)  &&  (c0 > cstart+1)) {
            dc.MoveTo ( c0-2 , r0 ) ;
            dc.LineTo ( c0-2 , r1 ) ;
            }
         if ((wide > 9)  &&  (c0 < cstop-1)) {
            dc.MoveTo ( c0+2 , r0 ) ;
            dc.LineTo ( c0+2 , r1 ) ;
            }
   		}
      dc.RestorePen () ;
      }

	delete pen ;
	delete second_pen ;
	delete lines ;
}
コード例 #20
0
ファイル: btntextg.cpp プロジェクト: Meridian59/Meridian59
//
/// Paint Text
//
void
TButtonTextGadget::PaintText(TDC& dc, TRect& rect, const tstring& text)
{
  dc.SelectObject(GetFont());

  TColor textColor = TColor::SysBtnText;
  if(!GetEnabled())
    textColor = TColor::Sys3dHilight;
  else if((GetGadgetWindow()->GetFlatStyle()&TGadgetWindow::FlatHotText) && IsHaveMouse())
     textColor = TColor::LtBlue;

   TColor oldTxColor  = dc.SetTextColor(textColor);

  uint format =  DT_SINGLELINE|DT_NOCLIP|DT_END_ELLIPSIS;
  switch(Align){
    case aLeft:
      format |= DT_LEFT;
      break;
    case aRight:
      format |= DT_RIGHT;
      break;
    case aCenter:
      format |= DT_CENTER;
      break;
  }
  switch(LayoutStyle){
    case lTextLeft:
    case lTextRight:
      format |= DT_VCENTER;
      break;
    case lTextTop:
      format |= DT_VCENTER;//DT_BOTTOM;
      break;
    case lTextBottom:
      format |= DT_VCENTER;//DT_TOP;
      break;
  }

  // Create a UI Face object for this button & let it paint the button face
  //
  TPoint  dstPt(rect.TopLeft());

  if (GetButtonState() == Down && GetEnabled() &&
      GetGadgetWindow()->GetFlatStyle()&TGadgetWindow::FlatStandard)
  {
    if(IsHaveMouse())
    {
      if(IsPressed())
      {
        const int dx = (format & DT_CENTER) ? 2 : 1;
        const int dy = (format & DT_VCENTER) ? 2 : 1;
        rect.Offset(dx, dy);
      }
      TUIFace(rect, text, TColor::Sys3dFace,format).Paint(dc, dstPt,
                TUIFace::Normal, true, true);
    }
    else
    {
      TUIFace face(rect, text, TColor::Sys3dFace,format);
      if(GetGadgetWindow()->GadgetGetCaptured()==this)
        face.Paint(dc, dstPt, TUIFace::Normal, true);
      else
        face.Paint(dc, dstPt, TUIFace::Down, IsPressed(), false);
    }
  }
  else
  {
    TUIFace face(rect, text, TColor::Sys3dFace,format);
    if (!GetEnabled())
      face.Paint(dc, dstPt, TUIFace::Disabled, false, false);
    else if (GetButtonState() == Indeterminate)
      face.Paint(dc, dstPt, TUIFace::Indeterm, IsPressed(), false);
    else if (GetButtonState() == Down) // Down and not flat
      face.Paint(dc, dstPt, TUIFace::Down, IsPressed(), false);
    else
      face.Paint(dc, dstPt, TUIFace::Normal, IsPressed(), false);
  }

  dc.SetTextColor(oldTxColor);

  dc.RestoreFont();
}
コード例 #21
0
ファイル: bmp256ct.cpp プロジェクト: Anonic/Meridian59
////////////////////////////////////////////////////////////
// TBitmap256Control
// -----------------
//  Display bitmap in DC
void TBitmap256Control::DisplayBitmap (TDC& dc, TRect &rect)
{
	// Display a cross if no bitmap
	if ( pDIBInfo == 0 )
	{
		dc.SelectObject(TPen(TColor::LtGray));
		dc.MoveTo (0, 0);
		dc.LineTo (MaxWidth, MaxHeight);
		dc.MoveTo (0, MaxHeight);
		dc.LineTo (MaxWidth, 0);
		dc.SetTextAlign(TA_CENTER);
		dc.SetTextColor(TColor::White);
		dc.SetBkColor(TColor::Black);
		char tmp[40];
		if ( BitmapName[0] != '\0' && BitmapName[0] != '-' )
			wsprintf (tmp, "No picture (%s)", BitmapName);
		else
			wsprintf (tmp, "No picture");
		dc.TextOut (MaxWidth / 2, MaxHeight / 2 - 6, tmp);
		return;
	}

	assert (pBitmapPalette != NULL);

	// pBitmapPalette->UnrealizeObject();
	dc.SelectObject (*pBitmapPalette);
	dc.RealizePalette();
	dc.SetStretchBltMode (COLORONCOLOR);

#if 1
	TRect ZoomRect;
	ZoomRect.left   = rect.left;
	ZoomRect.top    = rect.top;
	ZoomRect.right  = rect.right;
	ZoomRect.bottom = rect.bottom;

	// Convert the rect. size to a rect in the sprite
	rect.left   /= ZoomFactor;
	rect.top    /= ZoomFactor;
	rect.right  /= ZoomFactor;
	rect.bottom /= ZoomFactor;

	TRect DIBRect;
	DIBRect.left   = rect.left;
	DIBRect.top    = BitmapYSize - rect.bottom; 	// DIBs are Y inversed
	DIBRect.right  = DIBRect.left + rect.Width();
	DIBRect.bottom = DIBRect.top + rect.Height();

	dc.StretchDIBits (ZoomRect,
					  DIBRect,
					  pDIBits, *pDIBInfo,
					  DIB_PAL_COLORS, SRCCOPY);
#else
	// Create memory DC and display bitmap
	TMemoryDC mdc (dc);
	mdc.SelectObject (*pBitmapPalette);
	mdc.SelectObject (*pBitmap);
	dc.StretchBlt(0, 0, ZoomXSize,   ZoomYSize,
				  mdc,
				  0, 0, BitmapXSize, BitmapYSize,
				  SRCCOPY);

	// Restore GDI objects
	mdc.RestoreBitmap();
	mdc.RestorePalette();
#endif
	dc.RestorePalette();
}
コード例 #22
0
ファイル: Pndsmdi1.cpp プロジェクト: Xangis/magma
//
// Paint routine for Window, Printer, and PrintPreview for a TEdit/TListBox client.
//
void poundsMDIChild::Paint (TDC& dc, BOOL, TRect& rect)
{
    poundsApp *theApp = TYPESAFE_DOWNCAST(GetApplication(), poundsApp);
    if (theApp) {
        // Only paint if we're printing and we have something to paint, otherwise do nothing.
        if (theApp->Printing && theApp->Printer && !rect.IsEmpty()) {
            // Use pageSize to get the size of the window to render into.  For a Window it's the client area,
            // for a printer it's the printer DC dimensions and for print preview it's the layout window.
            TSize   pageSize(rect.right - rect.left, rect.bottom - rect.top);

            HFONT   hFont = (HFONT)GetClientWindow()->GetWindowFont();
            TFont   font("Arial", -12);
            if (hFont == 0)
              dc.SelectObject(font);
            else
              dc.SelectObject(TFont(hFont));

            TEXTMETRIC  tm;
            int fHeight = (dc.GetTextMetrics(tm) == TRUE) ? tm.tmHeight + tm.tmExternalLeading : 10;

            // How many lines of this font can we fit on a page.
            int linesPerPage = MulDiv(pageSize.cy, 1, fHeight);
            if (linesPerPage) {
                TPrintDialog::TData &printerData = theApp->Printer->GetSetup();

                int maxPg = 1;

                // Get the client class window (this is the contents we're going to print).
                TEdit *clientEditWindow /* = 0*/;
                TListBox *clientListWindow = 0;
                TWindow *clientUnknownWindow = 0;

                clientEditWindow = TYPESAFE_DOWNCAST(GetClientWindow(), TEdit);
                if (clientEditWindow)
                    maxPg = ((clientEditWindow->GetNumLines() / linesPerPage) + 1.0);
                else {
                    clientListWindow = TYPESAFE_DOWNCAST(GetClientWindow(), TListBox);
                    if (clientListWindow)
                        maxPg = ((clientListWindow->GetCount() / linesPerPage) + 1.0);
                    else
                       clientUnknownWindow = TYPESAFE_DOWNCAST(GetClientWindow(), TWindow);
                }

                // Compute the number of pages to print.
                printerData.MinPage = 1;
                printerData.MaxPage = maxPg;

                // Do the text stuff:
                int     fromPage = printerData.FromPage == -1 ? 1 : printerData.FromPage;
                int     toPage = printerData.ToPage == -1 ? 1 : printerData.ToPage;
                char    buffer[255];
                int     currentPage = fromPage;

                while (currentPage <= toPage) {
                    int startLine = (currentPage - 1) * linesPerPage;
                    int lineIdx = 0;
                    while (lineIdx < linesPerPage) {
                        // If the string is no longer valid then there's nothing more to display.
                        if (clientEditWindow) {
                            if (!clientEditWindow->GetLine(buffer, sizeof(buffer), startLine + lineIdx))
                                break;
                        }
                        else if (clientListWindow) {
                            if (clientListWindow->GetString(buffer, startLine + lineIdx) < 0)
                                break;
                        }
                        else if (clientUnknownWindow) {
                           clientUnknownWindow->Paint(dc, FALSE, rect);
                           break;
                        }
                        dc.TabbedTextOut(TPoint(0, lineIdx * fHeight), buffer, lstrlen(buffer), 0, NULL, 0);
                        lineIdx++;
                    }
                    currentPage++;
                }
            }
        }
    }
}