home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / FWBitmap.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  5.7 KB  |  215 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWBitmap.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWBITMAP_H
  11. #define FWBITMAP_H
  12.  
  13. #ifndef FWGCONST_H
  14. #include "FWGConst.h"
  15. #endif
  16.  
  17. #ifndef FWRECT_H
  18. #include "FWRect.h"
  19. #endif
  20.  
  21. #ifndef SLGRDEF_H
  22. #include "SLGrDef.h"
  23. #endif
  24.  
  25. #ifndef SLGDEV_H
  26. #include "SLGDev.h"
  27. #endif
  28.  
  29. #ifndef FWRESOUR_H
  30. #include "FWResour.h"
  31. #endif
  32.  
  33. #ifndef FWGC_H
  34. #include "FWGC.h"
  35. #endif
  36.  
  37. #ifndef FWPICTUR_H
  38. #include "FWPictur.h"
  39. #endif
  40.  
  41. #ifndef SLBITMAP_H
  42. #include "SLBitmap.h"
  43. #endif
  44.  
  45. #ifndef SLPALETE_H
  46. #include "SLPalete.h"
  47. #endif
  48.  
  49. //========================================================================================
  50. //    Forward Class Declarations
  51. //========================================================================================
  52.  
  53. class    FW_CWritableStream;
  54. class    FW_CReadableStream;
  55. class    FW_CPicture;
  56. class    FW_CGraphicContext;
  57. struct    FW_SGraphicContext;
  58. class    FW_CColor;
  59. struct    FW_SColor;
  60.  
  61. //========================================================================================
  62. //    class FW_CBitmap
  63. //========================================================================================
  64.  
  65. class FW_CBitmap : public FW_TGrRefPtr<FW_HBitmap>
  66. {
  67. public:
  68.     FW_DECLARE_AUTO(FW_CBitmap)
  69.  
  70.     FW_CBitmap();
  71.     ~FW_CBitmap();
  72.     
  73.     FW_CBitmap(short width, short height,
  74.         short pixelSize, FW_Palette palette = NULL);
  75.         
  76.     FW_CBitmap(void* image, long imageSize, short rowBytes,
  77.         short width, short height, short pixelSize, FW_Palette palette = NULL);
  78.  
  79. #ifdef FW_BUILD_MAC
  80.     static const FW_SRect gWholePicture;
  81.     FW_CBitmap(const FW_CPicture& picture,
  82.               const FW_CColor& fillColor = FW_kRGBWhite,
  83.               const FW_CRect& pictPart = gWholePicture);
  84.               
  85.     FW_CPicture MacGetAsPicture(const FW_SRect& pictPart = gWholePicture) const;
  86. #endif
  87.  
  88.     FW_CBitmap(FW_PResourceFile& resourceFile, FW_ResourceID resourceID);
  89.     FW_CBitmap(FW_CReadableStream& stream, FW_Boolean bDIBHeader = TRUE);
  90.  
  91.     FW_CBitmap(FW_PlatformBitmap platformBitmap);
  92.     
  93.     FW_CBitmap(const FW_CBitmap& other);
  94.     FW_CBitmap& operator=(const FW_CBitmap& other);
  95.     
  96.     FW_CBitmap    Copy(const FW_CRect& srcRect) const;
  97.     
  98.     friend FW_CReadableStream& operator>>(FW_CReadableStream& stream, FW_CBitmap& bitmap);
  99.     friend FW_CWritableStream& operator<<(FW_CWritableStream& stream, const FW_CBitmap& bitmap);
  100.  
  101.     // Delegation
  102.     
  103.     FW_Boolean             IsEqual(const FW_CBitmap& bitmap) const
  104.         { return FW_PrivBitmap_IsEqual(fRep, bitmap.fRep); }
  105.  
  106.     // Handle operations
  107.     
  108.     FW_PlatformBitmap    GetPlatformBitmap() const
  109.         { return FW_PrivBitmap_GetPlatformBitmap(fRep); }
  110.         
  111.     FW_Boolean            IsPlatformBitmapOrphan() const
  112.         { return FW_PrivBitmap_IsPlatformBitmapOrphan(fRep); }
  113.         
  114.     FW_PlatformBitmap    OrphanPlatformBitmap() const
  115.         { return FW_PrivBitmap_OrphanPlatformBitmap(fRep); }
  116.         
  117.     void                 SetPlatformBitmap(FW_PlatformBitmap newBitmap)
  118.         { FW_PrivBitmap_SetPlatformBitmap(fRep, newBitmap); }
  119.         
  120.     void                AdoptPlatformBitmap(FW_PlatformBitmap newBitmap)
  121.         { FW_PrivBitmap_AdoptPlatformBitmap(fRep, newBitmap); }
  122.  
  123.     // Palette
  124.         
  125.     FW_Palette            GetPalette() const;
  126.         
  127.     void                SetPalette(FW_Palette palette)
  128.         { FW_FailOnError(FW_PrivBitmap_SetPalette(fRep, palette)); }
  129.  
  130.     // Bitmap info
  131.     void                GetBitmapInfo(
  132.                             short&        width,
  133.                             short&        height, 
  134.                             short&        rowBytes,
  135.                             short&        pixelSize) const
  136.         { FW_FailOnError(FW_PrivBitmap_GetBitmapInfo(fRep, width, height, rowBytes, pixelSize)); }
  137.  
  138.     void                GetBitmapBounds(FW_SGraphicContext& gc, FW_SRect& bounds) const;
  139.         
  140.     void                GetBitmapBounds(FW_SRect& bounds) const
  141.         { FW_PrivBitmap_GetBitmapBounds(fRep, bounds); }
  142.         
  143.     void                GetPixelColor(short horiz, short vert, FW_CColor& color) const
  144.         { FW_PrivBitmap_GetPixelColor(fRep, horiz, vert, color); }
  145.     void                SetPixelColor(short horiz, short vert, const FW_CColor& newColor)
  146.         { FW_PrivBitmap_SetPixelColor(fRep, horiz, vert, newColor); }
  147.  
  148.     // Changing the bitmap
  149.     
  150.     void                ChangeBitmap(
  151.                             void*        image,
  152.                             long        imageSize,
  153.                             short        rowBytes,
  154.                             short        width,
  155.                             short        height, 
  156.                             short        pixelSize,
  157.                             FW_Boolean    bScale)
  158.         { FW_FailOnError(FW_PrivBitmap_ChangeBitmap(fRep, image, imageSize, rowBytes, width, height, pixelSize, bScale)); }
  159.                                     
  160.     void                ChangeBitmap(
  161.                             short        width,
  162.                             short        height, 
  163.                             short        pixelSize,
  164.                             FW_Boolean    bScale)
  165.         { FW_FailOnError(FW_PrivBitmap_ChangeBitmapGeometry(fRep, width, height, pixelSize, bScale)); }
  166.                                     
  167.     void                SetImage(void* image, long imageSize, short rowBytes)
  168.         { FW_FailOnError(FW_PrivBitmap_SetImage(fRep, image, imageSize, rowBytes)); }
  169.  
  170.     // Copy Pixels
  171.     void                CopyPixels(
  172.                             const FW_CBitmap&    bitmapDst,
  173.                             FW_SRect&             boundsSrc, 
  174.                             FW_SRect&            boundsDst)
  175.         { FW_FailOnError(FW_PrivBitmap_CopyPixels(fRep, bitmapDst.fRep, boundsSrc, boundsDst)); }
  176.  
  177.     // Macintosh specific
  178.     
  179. #ifdef FW_BUILD_MAC    
  180.     PixMapHandle        MacLockPixels()
  181.         { return FW_PrivBitmap_MacLockPixels(fRep); }    // return NULL if fails
  182.         
  183.     void                MacUnlockPixels()
  184.         { FW_FailOnError(FW_PrivBitmap_MacUnlockPixels(fRep)); }
  185.         
  186.     FW_Boolean            MacIsPixelsLocked() const
  187.         { return FW_PrivBitmap_MacIsPixelsLocked(fRep); }
  188. #endif
  189. };
  190.  
  191. //========================================================================================
  192. //    class FW_CBitmapContext
  193. //========================================================================================
  194.  
  195. class FW_CBitmapContext : public FW_CGraphicContext
  196. {
  197. public:
  198.     FW_DECLARE_AUTO(FW_CBitmapContext)
  199.  
  200.     FW_CBitmapContext(Environment* ev, FW_CBitmap& bitmap);
  201.     ~FW_CBitmapContext();
  202.  
  203.     virtual void        Reset();
  204.     
  205. private:
  206.     FW_CBitmap             fBitmap;
  207.     FW_HGDevice            fGraphicDevice;
  208.     
  209. #ifdef FW_BUILD_WIN
  210.     HBITMAP                fOldBitmap;
  211. #endif
  212. };
  213.  
  214. #endif
  215.