]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/brush.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/gtk/brush.cpp 
   4 // Author:      Robert Roebling 
   6 // Copyright:   (c) 1998 Robert Roebling 
   7 // Licence:     wxWindows licence 
   8 ///////////////////////////////////////////////////////////////////////////// 
  11 #pragma implementation "brush.h" 
  15 #include "wx/colour.h" 
  19 //----------------------------------------------------------------------------- 
  21 //----------------------------------------------------------------------------- 
  23 class wxBrushRefData
: public wxObjectRefData
 
  31     wxBrushRefData( const wxBrushRefData
& data 
) 
  34         m_style 
= data
.m_style
; 
  35         m_stipple 
= data
.m_stipple
; 
  36         m_colour 
= data
.m_colour
; 
  39     bool operator == (const wxBrushRefData
& data
) const 
  41         return (m_style 
== data
.m_style 
&& 
  42                 m_stipple 
== data
.m_stipple 
&& 
  43                 m_colour 
== data
.m_colour
); 
  51 //----------------------------------------------------------------------------- 
  53 #define M_BRUSHDATA ((wxBrushRefData *)m_refData) 
  55 IMPLEMENT_DYNAMIC_CLASS(wxBrush
,wxGDIObject
) 
  57 wxBrush::wxBrush( const wxColour 
&colour
, int style 
) 
  59     m_refData 
= new wxBrushRefData(); 
  60     M_BRUSHDATA
->m_style 
= style
; 
  61     M_BRUSHDATA
->m_colour 
= colour
; 
  64 wxBrush::wxBrush( const wxBitmap 
&stippleBitmap 
) 
  66     m_refData 
= new wxBrushRefData(); 
  67     M_BRUSHDATA
->m_colour 
= *wxBLACK
; 
  69     M_BRUSHDATA
->m_stipple 
= stippleBitmap
; 
  71     if (M_BRUSHDATA
->m_stipple
.GetMask()) 
  72         M_BRUSHDATA
->m_style 
= wxSTIPPLE_MASK_OPAQUE
; 
  74         M_BRUSHDATA
->m_style 
= wxSTIPPLE
; 
  79     // m_refData unrefed in ~wxObject 
  82 wxObjectRefData 
*wxBrush::CreateRefData() const 
  84     return new wxBrushRefData
; 
  87 wxObjectRefData 
*wxBrush::CloneRefData(const wxObjectRefData 
*data
) const 
  89     return new wxBrushRefData(*(wxBrushRefData 
*)data
); 
  92 bool wxBrush::operator == ( const wxBrush
& brush 
) const 
  94     if (m_refData 
== brush
.m_refData
) return TRUE
; 
  96     if (!m_refData 
|| !brush
.m_refData
) return FALSE
; 
  98     return ( *(wxBrushRefData
*)m_refData 
== *(wxBrushRefData
*)brush
.m_refData 
); 
 101 int wxBrush::GetStyle() const 
 103     if (m_refData 
== NULL
) 
 105         wxFAIL_MSG( wxT("invalid brush") ); 
 109     return M_BRUSHDATA
->m_style
; 
 112 wxColour 
&wxBrush::GetColour() const 
 114     if (m_refData 
== NULL
) 
 116         wxFAIL_MSG( wxT("invalid brush") ); 
 120     return M_BRUSHDATA
->m_colour
; 
 123 wxBitmap 
*wxBrush::GetStipple() const 
 125     if (m_refData 
== NULL
) 
 127         wxFAIL_MSG( wxT("invalid brush") ); 
 128         return &wxNullBitmap
; 
 131     return &M_BRUSHDATA
->m_stipple
; 
 134 void wxBrush::SetColour( const wxColour
& col 
) 
 138     M_BRUSHDATA
->m_colour 
= col
; 
 141 void wxBrush::SetColour( unsigned char r
, unsigned char g
, unsigned char b 
) 
 145     M_BRUSHDATA
->m_colour
.Set( r
, g
, b 
); 
 148 void wxBrush::SetStyle( int style 
) 
 152     M_BRUSHDATA
->m_style 
= style
; 
 155 void wxBrush::SetStipple( const wxBitmap
& stipple 
) 
 159     M_BRUSHDATA
->m_stipple 
= stipple
; 
 160     if (M_BRUSHDATA
->m_stipple
.GetMask()) 
 162         M_BRUSHDATA
->m_style 
= wxSTIPPLE_MASK_OPAQUE
; 
 166         M_BRUSHDATA
->m_style 
= wxSTIPPLE
;