bitmap.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/cocoa/bitmap.h
  3. // Purpose: wxBitmap class
  4. // Author: David Elliott
  5. // Modified by:
  6. // Created: 2003/07/19
  7. // Copyright: (c) 2003 David Elliott
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef __WX_COCOA_BITMAP_H__
  11. #define __WX_COCOA_BITMAP_H__
  12. #include "wx/palette.h"
  13. // Bitmap
  14. class WXDLLIMPEXP_FWD_CORE wxBitmap;
  15. class WXDLLIMPEXP_FWD_CORE wxIcon;
  16. class WXDLLIMPEXP_FWD_CORE wxCursor;
  17. class WXDLLIMPEXP_FWD_CORE wxImage;
  18. class WXDLLIMPEXP_FWD_CORE wxPixelDataBase;
  19. // ========================================================================
  20. // wxMask
  21. // ========================================================================
  22. // A mask is a 1-bit alpha bitmap used for drawing bitmaps transparently.
  23. class WXDLLIMPEXP_CORE wxMask: public wxObject
  24. {
  25. DECLARE_DYNAMIC_CLASS(wxMask)
  26. public:
  27. wxMask();
  28. // Construct a mask from a bitmap and a colour indicating
  29. // the transparent area
  30. wxMask(const wxBitmap& bitmap, const wxColour& colour);
  31. // Construct a mask from a bitmap and a palette index indicating
  32. // the transparent area
  33. wxMask(const wxBitmap& bitmap, int paletteIndex);
  34. // Construct a mask from a mono bitmap (copies the bitmap).
  35. wxMask(const wxBitmap& bitmap);
  36. // Copy constructor
  37. wxMask(const wxMask& src);
  38. virtual ~wxMask();
  39. bool Create(const wxBitmap& bitmap, const wxColour& colour);
  40. bool Create(const wxBitmap& bitmap, int paletteIndex);
  41. bool Create(const wxBitmap& bitmap);
  42. // wxCocoa
  43. inline WX_NSBitmapImageRep GetNSBitmapImageRep()
  44. { return m_cocoaNSBitmapImageRep; }
  45. protected:
  46. WX_NSBitmapImageRep m_cocoaNSBitmapImageRep;
  47. };
  48. // ========================================================================
  49. // wxBitmap
  50. // ========================================================================
  51. class WXDLLIMPEXP_CORE wxBitmap: public wxGDIObject,
  52. public wxBitmapHelpers
  53. {
  54. // ------------------------------------------------------------------------
  55. // initialization
  56. // ------------------------------------------------------------------------
  57. public:
  58. // Platform-specific default constructor
  59. wxBitmap();
  60. // Initialize with raw data.
  61. wxBitmap(const char bits[], int width, int height, int depth = 1);
  62. // Initialize with XPM data
  63. wxBitmap(const char* const* bits);
  64. // Load a file or resource
  65. wxBitmap(const wxString& name, wxBitmapType type = wxBITMAP_DEFAULT_TYPE);
  66. // Construct from Cocoa's NSImage
  67. wxBitmap(NSImage* cocoaNSImage);
  68. // Construct from Cocoa's NSBitmapImageRep
  69. wxBitmap(NSBitmapImageRep* cocoaNSBitmapImageRep);
  70. // Constructor for generalised creation from data
  71. wxBitmap(const void* data, wxBitmapType type, int width, int height, int depth = 1);
  72. // If depth is omitted, will create a bitmap compatible with the display
  73. wxBitmap(int width, int height, int depth = -1)
  74. { (void)Create(width, height, depth); }
  75. wxBitmap(const wxSize& sz, int depth = -1)
  76. { (void)Create(sz, depth); }
  77. // Convert from wxImage:
  78. wxBitmap(const wxImage& image, int depth = -1)
  79. { CreateFromImage(image, depth); }
  80. // Convert from wxIcon
  81. wxBitmap(const wxIcon& icon) { CopyFromIcon(icon); }
  82. // destructor
  83. virtual ~wxBitmap();
  84. // ------------------------------------------------------------------------
  85. // Implementation
  86. // ------------------------------------------------------------------------
  87. public:
  88. // Initialize from wxImage
  89. bool CreateFromImage(const wxImage& image, int depth=-1);
  90. virtual bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH);
  91. virtual bool Create(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH)
  92. { return Create(sz.GetWidth(), sz.GetHeight(), depth); }
  93. bool Create(NSImage* cocoaNSImage);
  94. bool Create(NSBitmapImageRep* cocoaNSBitmapImageRep);
  95. virtual bool Create(const void* data, wxBitmapType type, int width, int height, int depth = 1);
  96. virtual bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_DEFAULT_TYPE);
  97. virtual bool SaveFile(const wxString& name, wxBitmapType type, const wxPalette *cmap = NULL) const;
  98. // copies the contents and mask of the given (colour) icon to the bitmap
  99. virtual bool CopyFromIcon(const wxIcon& icon);
  100. wxImage ConvertToImage() const;
  101. // get the given part of bitmap
  102. wxBitmap GetSubBitmap( const wxRect& rect ) const;
  103. int GetWidth() const;
  104. int GetHeight() const;
  105. int GetDepth() const;
  106. int GetQuality() const;
  107. void SetWidth(int w);
  108. void SetHeight(int h);
  109. void SetDepth(int d);
  110. void SetQuality(int q);
  111. void SetOk(bool isOk);
  112. // raw bitmap access support functions
  113. void *GetRawData(wxPixelDataBase& data, int bpp);
  114. void UngetRawData(wxPixelDataBase& data);
  115. wxPalette* GetPalette() const;
  116. void SetPalette(const wxPalette& palette);
  117. wxMask *GetMask() const;
  118. void SetMask(wxMask *mask) ;
  119. wxBitmapType GetBitmapType() const;
  120. // wxCocoa
  121. WX_NSBitmapImageRep GetNSBitmapImageRep();
  122. void SetNSBitmapImageRep(WX_NSBitmapImageRep bitmapImageRep);
  123. WX_NSImage GetNSImage(bool useMask) const;
  124. static void InitStandardHandlers() { }
  125. static void CleanUpHandlers() { }
  126. protected:
  127. wxGDIRefData *CreateGDIRefData() const;
  128. wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
  129. DECLARE_DYNAMIC_CLASS(wxBitmap)
  130. };
  131. #endif // __WX_COCOA_BITMAP_H__