예제 #1
0
//
/// Creates a bitmap object from the given metaFile using the given palette and size
/// arguments.
//
TBitmap::TBitmap(const TMetaFilePict& metaFile, TPalette& palette, const TSize& defSize)
{
  // Adjust size to final metafile size as needed
  //
  TMemoryDC memDC;
  TSize size = metaFile.CalcPlaySize(memDC, defSize);

  // Create bitmap, either mono or screen compatible
  //
  uint16  nColors;
  palette.GetObject(nColors);
  if (nColors > 2) {
    TScreenDC dc;
    Handle = ::CreateCompatibleBitmap(dc, size.cx, size.cy);
  }
  else
    Handle = ::CreateBitmap(size.cx, size.cy, 1, 1, 0);

  CheckValid();
  RefAdd(Handle, Bitmap);

  // clear bitmap, then play metafile onto it
  //
  memDC.SelectObject(*this);

  memDC.SelectStockObject(WHITE_BRUSH);
  memDC.PatBlt(0, 0, size.cx, size.cy);
  memDC.SelectObject(palette, false);

  metaFile.PlayOnto(memDC, size);

  TRACEX(OwlGDI, OWL_CDLEVEL, "TBitmap constructed @" << (void*)this <<
         " from metafile @" << (void*)&metaFile << ".");
}
예제 #2
0
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();
}
예제 #3
0
//////////////////////////////////////////////////////////
// TMapDC
// ------
//  draw a LineDef
void TMapDC::DrawLineDefLen (SHORT x0, SHORT y0, SHORT x1, SHORT y1, int color)
{
	char Text[10];

	// How to display a Text using a XOR mode?
	//  1. Create a memory dc
	//  2. Calc the text size (GetTextExtent)
	//  3. Create a bitmap of this size
	//  4. Draw text in bitmap (TextOut) in the memory DC
	//  5. Draw bitmap (with text in it) on screen using XOR

	// Build the string of the line length
	sprintf (Text, "%d", ComputeDist (abs(x1 - x0), abs(y1 - y0)));

	// Get the text size
	TSize TextSize = GetTextExtent(Text, strlen(Text));

	// Calc. the text drawing rect
#ifdef WINDOWS_SCALING
	TRect TTextRect(TPoint ((x0 + x1) / 2, (y0 + y1) /2), TextSize));
#else
	TRect TTextRect(TPoint (SCREENX((x0 + x1) / 2), SCREENY((y0 + y1) /2)), TextSize);
#endif
	// Draw text in bitmap
	TMemoryDC MemDC;
	TBitmap TextBitmap (*this, TextSize.cx, TextSize.cy);
	MemDC.SelectObject (TextBitmap);
	MemDC.SetTextAlign (TA_LEFT);
	MemDC.SetBkMode (TRANSPARENT);
	MemDC.SetTextColor (GetColor16(BLUE));
	MemDC.SelectObject (TPen(GetColor16(color)));
	MemDC.SelectObject (TBrush(GetColor16(WHITE)));
	MemDC.Rectangle (TPoint(0, 0), TextSize);
	MemDC.TextOut (0, 0, Text);

	// Draw bitmap (with text in it) on screen using XOR
    // TTextRect.left -= TextSize.cx; // align to right
	BitBlt (TTextRect,
			MemDC,
			TPoint(0, 0),
			SRCINVERT);
}
예제 #4
0
////////////////////////////////////////////////////////////
// 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();
}