bitmap.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/gtk1/bitmap.h
  3. // Purpose:
  4. // Author: Robert Roebling
  5. // Copyright: (c) 1998 Robert Roebling
  6. // Licence: wxWindows licence
  7. /////////////////////////////////////////////////////////////////////////////
  8. #ifndef __GTKBITMAPH__
  9. #define __GTKBITMAPH__
  10. #include "wx/defs.h"
  11. #include "wx/object.h"
  12. #include "wx/string.h"
  13. #include "wx/palette.h"
  14. #include "wx/gdiobj.h"
  15. class WXDLLIMPEXP_FWD_CORE wxPixelDataBase;
  16. //-----------------------------------------------------------------------------
  17. // classes
  18. //-----------------------------------------------------------------------------
  19. class WXDLLIMPEXP_FWD_CORE wxMask;
  20. class WXDLLIMPEXP_FWD_CORE wxBitmap;
  21. class WXDLLIMPEXP_FWD_CORE wxImage;
  22. //-----------------------------------------------------------------------------
  23. // wxMask
  24. //-----------------------------------------------------------------------------
  25. class WXDLLIMPEXP_CORE wxMask: public wxObject
  26. {
  27. public:
  28. wxMask();
  29. wxMask( const wxBitmap& bitmap, const wxColour& colour );
  30. #if wxUSE_PALETTE
  31. wxMask( const wxBitmap& bitmap, int paletteIndex );
  32. #endif // wxUSE_PALETTE
  33. wxMask( const wxBitmap& bitmap );
  34. virtual ~wxMask();
  35. bool Create( const wxBitmap& bitmap, const wxColour& colour );
  36. #if wxUSE_PALETTE
  37. bool Create( const wxBitmap& bitmap, int paletteIndex );
  38. #endif // wxUSE_PALETTE
  39. bool Create( const wxBitmap& bitmap );
  40. // implementation
  41. GdkBitmap *m_bitmap;
  42. GdkBitmap *GetBitmap() const;
  43. private:
  44. DECLARE_DYNAMIC_CLASS(wxMask)
  45. };
  46. //-----------------------------------------------------------------------------
  47. // wxBitmap
  48. //-----------------------------------------------------------------------------
  49. class WXDLLIMPEXP_CORE wxBitmap: public wxBitmapBase
  50. {
  51. public:
  52. wxBitmap() {}
  53. wxBitmap( int width, int height, int depth = -1 ) { Create( width, height, depth ); }
  54. wxBitmap( const wxSize& sz, int depth = -1 ) { Create( sz, depth ); }
  55. wxBitmap( const char bits[], int width, int height, int depth = 1 );
  56. wxBitmap( const char* const* bits );
  57. #ifdef wxNEEDS_CHARPP
  58. // needed for old GCC
  59. wxBitmap(char** data)
  60. {
  61. *this = wxBitmap(const_cast<const char* const*>(data));
  62. }
  63. #endif
  64. wxBitmap( const wxString &filename, wxBitmapType type = wxBITMAP_DEFAULT_TYPE );
  65. wxBitmap( const wxImage& image, int depth = -1 ) { (void)CreateFromImage(image, depth); }
  66. virtual ~wxBitmap();
  67. bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH);
  68. bool Create(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH)
  69. { return Create(sz.GetWidth(), sz.GetHeight(), depth); }
  70. bool Create(int width, int height, const wxDC& WXUNUSED(dc))
  71. { return Create(width,height); }
  72. virtual int GetHeight() const;
  73. virtual int GetWidth() const;
  74. virtual int GetDepth() const;
  75. wxImage ConvertToImage() const;
  76. // copies the contents and mask of the given (colour) icon to the bitmap
  77. virtual bool CopyFromIcon(const wxIcon& icon);
  78. wxMask *GetMask() const;
  79. void SetMask( wxMask *mask );
  80. wxBitmap GetSubBitmap( const wxRect& rect ) const;
  81. bool SaveFile(const wxString &name, wxBitmapType type,
  82. const wxPalette *palette = NULL) const;
  83. bool LoadFile(const wxString &name, wxBitmapType type = wxBITMAP_DEFAULT_TYPE);
  84. #if wxUSE_PALETTE
  85. wxPalette *GetPalette() const;
  86. void SetPalette(const wxPalette& palette);
  87. wxPalette *GetColourMap() const { return GetPalette(); }
  88. #endif // wxUSE_PALETTE
  89. static void InitStandardHandlers();
  90. // implementation
  91. // --------------
  92. void SetHeight( int height );
  93. void SetWidth( int width );
  94. void SetDepth( int depth );
  95. void SetPixmap( GdkPixmap *pixmap );
  96. void SetBitmap( GdkBitmap *bitmap );
  97. GdkPixmap *GetPixmap() const;
  98. GdkBitmap *GetBitmap() const;
  99. bool HasPixmap() const;
  100. // Basically, this corresponds to Win32 StretchBlt()
  101. wxBitmap Rescale( int clipx, int clipy, int clipwidth, int clipheight, int width, int height );
  102. // raw bitmap access support functions
  103. void *GetRawData(wxPixelDataBase& data, int bpp);
  104. void UngetRawData(wxPixelDataBase& data);
  105. bool HasAlpha() const;
  106. protected:
  107. bool CreateFromImage(const wxImage& image, int depth);
  108. virtual wxGDIRefData *CreateGDIRefData() const;
  109. virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
  110. private:
  111. // to be called from CreateFromImage only!
  112. bool CreateFromImageAsBitmap(const wxImage& image);
  113. bool CreateFromImageAsPixmap(const wxImage& image);
  114. friend class wxBitmapHandler;
  115. private:
  116. DECLARE_DYNAMIC_CLASS(wxBitmap)
  117. };
  118. #endif // __GTKBITMAPH__