bitmap.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/gtk/bitmap.h
  3. // Purpose:
  4. // Author: Robert Roebling
  5. // Copyright: (c) 1998 Robert Roebling
  6. // Licence: wxWindows licence
  7. /////////////////////////////////////////////////////////////////////////////
  8. #ifndef _WX_GTK_BITMAP_H_
  9. #define _WX_GTK_BITMAP_H_
  10. #ifdef __WXGTK3__
  11. typedef struct _cairo cairo_t;
  12. typedef struct _cairo_surface cairo_surface_t;
  13. #endif
  14. typedef struct _GdkPixbuf GdkPixbuf;
  15. class WXDLLIMPEXP_FWD_CORE wxPixelDataBase;
  16. //-----------------------------------------------------------------------------
  17. // wxMask
  18. //-----------------------------------------------------------------------------
  19. class WXDLLIMPEXP_CORE wxMask: public wxMaskBase
  20. {
  21. public:
  22. wxMask();
  23. wxMask(const wxMask& mask);
  24. wxMask( const wxBitmap& bitmap, const wxColour& colour );
  25. #if wxUSE_PALETTE
  26. wxMask( const wxBitmap& bitmap, int paletteIndex );
  27. #endif // wxUSE_PALETTE
  28. wxMask( const wxBitmap& bitmap );
  29. virtual ~wxMask();
  30. wxBitmap GetBitmap() const;
  31. // implementation
  32. #ifdef __WXGTK3__
  33. wxMask(cairo_surface_t*);
  34. operator cairo_surface_t*() const;
  35. #else
  36. wxMask(GdkPixmap*);
  37. operator GdkPixmap*() const;
  38. #endif
  39. protected:
  40. virtual void FreeData();
  41. virtual bool InitFromColour(const wxBitmap& bitmap, const wxColour& colour);
  42. virtual bool InitFromMonoBitmap(const wxBitmap& bitmap);
  43. private:
  44. #ifdef __WXGTK3__
  45. cairo_surface_t* m_bitmap;
  46. #else
  47. GdkPixmap* m_bitmap;
  48. #endif
  49. DECLARE_DYNAMIC_CLASS(wxMask)
  50. };
  51. //-----------------------------------------------------------------------------
  52. // wxBitmap
  53. //-----------------------------------------------------------------------------
  54. class WXDLLIMPEXP_CORE wxBitmap: public wxBitmapBase
  55. {
  56. public:
  57. wxBitmap() { }
  58. wxBitmap( int width, int height, int depth = wxBITMAP_SCREEN_DEPTH )
  59. { Create(width, height, depth); }
  60. wxBitmap( const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH )
  61. { Create(sz, depth); }
  62. wxBitmap( const char bits[], int width, int height, int depth = 1 );
  63. wxBitmap( const char* const* bits );
  64. #ifdef wxNEEDS_CHARPP
  65. // needed for old GCC
  66. wxBitmap(char** data)
  67. { *this = wxBitmap(const_cast<const char* const*>(data)); }
  68. #endif
  69. wxBitmap( const wxString &filename, wxBitmapType type = wxBITMAP_DEFAULT_TYPE );
  70. #if wxUSE_IMAGE
  71. wxBitmap(const wxImage& image, int depth = wxBITMAP_SCREEN_DEPTH);
  72. #endif // wxUSE_IMAGE
  73. wxBitmap(GdkPixbuf* pixbuf, int depth = 0);
  74. virtual ~wxBitmap();
  75. bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH);
  76. bool Create(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH)
  77. { return Create(sz.GetWidth(), sz.GetHeight(), depth); }
  78. bool Create(int width, int height, const wxDC& WXUNUSED(dc))
  79. { return Create(width,height); }
  80. virtual int GetHeight() const;
  81. virtual int GetWidth() const;
  82. virtual int GetDepth() const;
  83. #if wxUSE_IMAGE
  84. wxImage ConvertToImage() const;
  85. #endif // wxUSE_IMAGE
  86. // copies the contents and mask of the given (colour) icon to the bitmap
  87. virtual bool CopyFromIcon(const wxIcon& icon);
  88. wxMask *GetMask() const;
  89. void SetMask( wxMask *mask );
  90. wxBitmap GetSubBitmap( const wxRect& rect ) const;
  91. bool SaveFile(const wxString &name, wxBitmapType type,
  92. const wxPalette *palette = NULL) const;
  93. bool LoadFile(const wxString &name, wxBitmapType type = wxBITMAP_DEFAULT_TYPE);
  94. #if wxUSE_PALETTE
  95. wxPalette *GetPalette() const;
  96. void SetPalette(const wxPalette& palette);
  97. wxPalette *GetColourMap() const { return GetPalette(); }
  98. #endif // wxUSE_PALETTE
  99. static void InitStandardHandlers();
  100. // implementation
  101. // --------------
  102. void SetHeight( int height );
  103. void SetWidth( int width );
  104. void SetDepth( int depth );
  105. #ifdef __WXGTK3__
  106. GdkPixbuf* GetPixbufNoMask() const;
  107. cairo_t* CairoCreate() const;
  108. void Draw(cairo_t* cr, int x, int y, bool useMask = true, const wxColour* fg = NULL, const wxColour* bg = NULL) const;
  109. void SetSourceSurface(cairo_t* cr, int x, int y, const wxColour* fg = NULL, const wxColour* bg = NULL) const;
  110. #else
  111. GdkPixmap *GetPixmap() const;
  112. bool HasPixmap() const;
  113. bool HasPixbuf() const;
  114. wxBitmap(GdkPixmap* pixmap);
  115. #endif
  116. GdkPixbuf *GetPixbuf() const;
  117. // raw bitmap access support functions
  118. void *GetRawData(wxPixelDataBase& data, int bpp);
  119. void UngetRawData(wxPixelDataBase& data);
  120. bool HasAlpha() const;
  121. protected:
  122. #ifndef __WXGTK3__
  123. #if wxUSE_IMAGE
  124. bool CreateFromImage(const wxImage& image, int depth);
  125. #endif // wxUSE_IMAGE
  126. #endif
  127. virtual wxGDIRefData* CreateGDIRefData() const;
  128. virtual wxGDIRefData* CloneGDIRefData(const wxGDIRefData* data) const;
  129. private:
  130. #ifndef __WXGTK3__
  131. void SetPixmap(GdkPixmap* pixmap);
  132. #if wxUSE_IMAGE
  133. // to be called from CreateFromImage only!
  134. bool CreateFromImageAsPixmap(const wxImage& image, int depth);
  135. bool CreateFromImageAsPixbuf(const wxImage& image);
  136. #endif // wxUSE_IMAGE
  137. public:
  138. // implementation only
  139. enum Representation
  140. {
  141. Pixmap,
  142. Pixbuf
  143. };
  144. // removes other representations from memory, keeping only 'keep'
  145. // (wxBitmap may keep same bitmap e.g. as both pixmap and pixbuf):
  146. void PurgeOtherRepresentations(Representation keep);
  147. #endif
  148. DECLARE_DYNAMIC_CLASS(wxBitmap)
  149. };
  150. #endif // _WX_GTK_BITMAP_H_