// /// Creates a bitmap object for the given device context with the given dib and /// usage argument values. // TBitmap::TBitmap(const TDC& dc, const TDib& dib, uint32 usage) { Handle = ::CreateDIBitmap(dc, (BITMAPINFOHEADER *)dib.GetInfoHeader(), usage, (const uint8 *)dib.GetBits(), (BITMAPINFO *)dib.GetInfo(), dib.Usage()); // API casts WARNX(OwlGDI, !Handle, 0, "Cannot create bitmap from DIB " << hex << (uint)(HANDLE)dib << " for " << (uint)(HDC)dc); CheckValid(); RefAdd(Handle, Bitmap); TRACEX(OwlGDI, OWL_CDLEVEL, "TBitmap constructed @" << (void*)this << " from DIB for " << (uint)(HDC)dc << "."); }
// /// Constructs a TCelArray from a device independent bitmap (DIB) by slicing the DIB /// into a horizontal array of evenly sized cels. If numRows is 0, the number of /// rows is calculated using the bitmap height and the celSize y parameter. // TCelArray::TCelArray(const TDib& dib, int numCels, int numRows) { NGrowBy = 1; NCels = NCelsUsed = std::max(1, numCels); NRows = std::max(1, numRows); CSize = TSize(dib.Width() / NCels, dib.Height() / NRows); NCurRow = 0; Offs = TPoint(0, 0); ShouldDelete = true; TPalette palette((HPALETTE)::GetStockObject(DEFAULT_PALETTE)); Bitmap = new TBitmap(dib, &palette); TRACEX(OwlGadget, OWL_CDLEVEL, "TCelArray constructed @" << (void*)this << " from slicing the dib @" << (void*)&dib); }
// /// Create a bitmap & get its handle, given a dib and a palette /// Used by ctors here and in derived classes. Assumes Handle member can be /// over written, & adds handle to reference container. // void TBitmap::Create(const TDib& dib, const TPalette& palette) { TScreenDC dc; dc.SelectObject(palette, false); dc.RealizePalette(); Handle = ::CreateDIBitmap( dc, (LPBITMAPINFOHEADER)dib.GetInfoHeader(), CBM_INIT, (const uint8 *)dib.GetBits(), (LPBITMAPINFO)dib.GetInfo(), dib.Usage() ); // API type casts CheckValid(); RefAdd(Handle, Bitmap); }
// /// Constructs a TImageList from a DIB, slicing the bitmap up into a horizontal array of /// the given number of evenly sized images. // !CQ add an optional mask color? or mask? or palette? // TImageList::TImageList(const TDib& dib, uint flags, int imageCount, int growBy) { if (!TCommCtrl::IsAvailable()) TXCommCtrl::Raise(); if (!imageCount) imageCount = 1; ImageSize = TSize(dib.Width() / imageCount, dib.Height()); Bitmap = 0; Handle = TCommCtrl::Dll()->ImageList_Create(ImageSize.cx, ImageSize.cy, flags, imageCount, growBy); TPalette pal((HPALETTE)::GetStockObject(DEFAULT_PALETTE)); // Use masked support with 3dFace color as background color // Add(TBitmap(dib, &pal), TColor::Sys3dFace); }
// /// 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(); } }