home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 11.ddi / OWLSRC.PAK / BITMAPGA.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  2.4 KB  |  97 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1993 by Borland International
  3. //   source\owl\bitmapga.cpp
  4. //   Implementation of class TBitmapGadget
  5. //----------------------------------------------------------------------------
  6. #include <owl\owlpch.h>
  7. #include <owl\bitmapga.h>
  8. #include <owl\gadgetwi.h>
  9. #include <owl\celarray.h>
  10.  
  11. TBitmapGadget::TBitmapGadget(TResId bmpResId,
  12.                              int id,
  13.                              TBorderStyle borderStyle,
  14.                              int numImages, int startImage)
  15.   : TGadget(id,borderStyle),
  16.     ResId(bmpResId),
  17.     NumImages(numImages)
  18. {
  19.   ImageArray = 0;
  20.   CurrentImage = startImage;
  21.   BitmapOrigin.x = BitmapOrigin.y = 0;
  22. }
  23.  
  24. TBitmapGadget::~TBitmapGadget()
  25. {
  26.   delete ImageArray;
  27. }
  28.  
  29. //
  30. // Handle a system color change by cleaning up & reloading & processing the
  31. // bitmap. Can also be called to create the initial bitmap.
  32. //
  33. void
  34. TBitmapGadget::SysColorChange()
  35. {
  36.   if (ImageArray)
  37.     delete ImageArray;
  38.   
  39.   TDib dib(*Window->GetModule(), ResId);
  40.   dib.MapUIColors(
  41.     TDib::MapFace | TDib::MapText | TDib::MapShadow | TDib::MapHighlight
  42.   );
  43.   ImageArray = new TCelArray(dib, NumImages);
  44. }
  45.  
  46. void
  47. TBitmapGadget::SetBounds(TRect& boundRect)
  48. {
  49.   TGadget::SetBounds(boundRect);
  50.   TRect  innerRect;
  51.   TSize  bitmapSize = ImageArray->CelSize();
  52.   GetInnerRect(innerRect);
  53.   
  54.   BitmapOrigin.x = innerRect.left + (innerRect.Width()-bitmapSize.cx)/2;
  55.   BitmapOrigin.y = innerRect.top + (innerRect.Height()-bitmapSize.cy)/2;
  56. }
  57.  
  58. void
  59. TBitmapGadget::GetDesiredSize(TSize& size)
  60. {
  61.   TGadget::GetDesiredSize(size);
  62.  
  63.   if (!ImageArray)
  64.     SysColorChange();   // Get the initial bitmap
  65.  
  66.   size += ImageArray->CelSize();
  67. }
  68.  
  69. int
  70. TBitmapGadget::SelectImage(int imageNum, BOOL immediate)
  71. {
  72.   UINT oldImageNum = CurrentImage;
  73.   if (imageNum != CurrentImage) {
  74.     CurrentImage = imageNum;
  75.     Invalidate(FALSE);
  76.   }
  77.   if (immediate)
  78.     Update();
  79.   return oldImageNum;
  80. }
  81.  
  82. void
  83. TBitmapGadget::Paint(TDC& dc)
  84. {
  85.   PaintBorder(dc);
  86.  
  87.   TMemoryDC imageDC;
  88.   imageDC.SelectObject(*ImageArray);
  89.  
  90.   TRect sourceRect = ImageArray->CelRect(CurrentImage);
  91.   TRect destRect;
  92.   GetInnerRect(destRect);
  93.   dc.BitBlt(destRect.left, destRect.top,
  94.             sourceRect.Width(), sourceRect.Height(),
  95.             imageDC, sourceRect.left, sourceRect.top);
  96. }
  97.