]>
git.saurik.com Git - wxWidgets.git/blob - src/x11/brush.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/x11/brush.cpp 
   4 // Author:      Julian Smart 
   8 // Copyright:   (c) Julian Smart 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "brush.h" 
  19 #include "wx/bitmap.h" 
  20 #include "wx/colour.h" 
  22 //----------------------------------------------------------------------------- 
  24 //----------------------------------------------------------------------------- 
  26 class wxBrushRefData
: public wxObjectRefData
 
  34     wxBrushRefData( const wxBrushRefData
& data 
) 
  36         m_style 
= data
.m_style
; 
  37         m_stipple 
= data
.m_stipple
; 
  38         m_colour 
= data
.m_colour
; 
  41     bool operator == (const wxBrushRefData
& data
) const 
  43         return (m_style 
== data
.m_style 
&& 
  44                 m_stipple 
== data
.m_stipple 
&& 
  45                 m_colour 
== data
.m_colour
); 
  53 //----------------------------------------------------------------------------- 
  55 #define M_BRUSHDATA ((wxBrushRefData *)m_refData) 
  57 IMPLEMENT_DYNAMIC_CLASS(wxBrush
,wxGDIObject
) 
  59 wxBrush::wxBrush( const wxColour 
&colour
, int style 
) 
  61     m_refData 
= new wxBrushRefData(); 
  62     M_BRUSHDATA
->m_style 
= style
; 
  63     M_BRUSHDATA
->m_colour 
= colour
; 
  66 wxBrush::wxBrush( const wxBitmap 
&stippleBitmap 
) 
  68     m_refData 
= new wxBrushRefData(); 
  69     M_BRUSHDATA
->m_colour 
= *wxBLACK
; 
  71     M_BRUSHDATA
->m_stipple 
= stippleBitmap
; 
  73     if (M_BRUSHDATA
->m_stipple
.GetMask()) 
  74         M_BRUSHDATA
->m_style 
= wxSTIPPLE_MASK_OPAQUE
; 
  76         M_BRUSHDATA
->m_style 
= wxSTIPPLE
; 
  81     // m_refData unrefed in ~wxObject 
  84 wxObjectRefData 
*wxBrush::CreateRefData() const 
  86     return new wxBrushRefData
; 
  89 wxObjectRefData 
*wxBrush::CloneRefData(const wxObjectRefData 
*data
) const 
  91     return new wxBrushRefData(*(wxBrushRefData 
*)data
); 
  94 bool wxBrush::operator == ( const wxBrush
& brush 
) const 
  96     if (m_refData 
== brush
.m_refData
) return TRUE
; 
  98     if (!m_refData 
|| !brush
.m_refData
) return FALSE
; 
 100     return ( *(wxBrushRefData
*)m_refData 
== *(wxBrushRefData
*)brush
.m_refData 
); 
 103 int wxBrush::GetStyle() const 
 105     if (m_refData 
== NULL
) 
 107         wxFAIL_MSG( wxT("invalid brush") ); 
 111     return M_BRUSHDATA
->m_style
; 
 114 wxColour 
&wxBrush::GetColour() const 
 116     if (m_refData 
== NULL
) 
 118         wxFAIL_MSG( wxT("invalid brush") ); 
 122     return M_BRUSHDATA
->m_colour
; 
 125 wxBitmap 
*wxBrush::GetStipple() const 
 127     if (m_refData 
== NULL
) 
 129         wxFAIL_MSG( wxT("invalid brush") ); 
 130         return &wxNullBitmap
; 
 133     return &M_BRUSHDATA
->m_stipple
; 
 136 void wxBrush::SetColour( const wxColour
& col 
) 
 140     M_BRUSHDATA
->m_colour 
= col
; 
 143 void wxBrush::SetColour( unsigned char r
, unsigned char g
, unsigned char b 
) 
 147     M_BRUSHDATA
->m_colour
.Set( r
, g
, b 
); 
 150 void wxBrush::SetStyle( int style 
) 
 154     M_BRUSHDATA
->m_style 
= style
; 
 157 void wxBrush::SetStipple( const wxBitmap
& stipple 
) 
 161     M_BRUSHDATA
->m_stipple 
= stipple
; 
 162     if (M_BRUSHDATA
->m_stipple
.GetMask()) 
 164         M_BRUSHDATA
->m_style 
= wxSTIPPLE_MASK_OPAQUE
; 
 168         M_BRUSHDATA
->m_style 
= wxSTIPPLE
;