]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/brush.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/gtk/brush.cpp 
   4 // Author:      Robert Roebling 
   6 // Copyright:   (c) 1998 Robert Roebling 
   7 // Licence:     wxWindows licence 
   8 ///////////////////////////////////////////////////////////////////////////// 
  10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) 
  11 #pragma implementation "brush.h" 
  14 // For compilers that support precompilation, includes "wx.h". 
  15 #include "wx/wxprec.h" 
  18 #include "wx/colour.h" 
  22 //----------------------------------------------------------------------------- 
  24 //----------------------------------------------------------------------------- 
  26 class wxBrushRefData
: public wxObjectRefData
 
  34     wxBrushRefData( const wxBrushRefData
& data 
) 
  37         m_style 
= data
.m_style
; 
  38         m_stipple 
= data
.m_stipple
; 
  39         m_colour 
= data
.m_colour
; 
  42     bool operator == (const wxBrushRefData
& data
) const 
  44         return (m_style 
== data
.m_style 
&& 
  45                 m_stipple 
== data
.m_stipple 
&& 
  46                 m_colour 
== data
.m_colour
); 
  54 //----------------------------------------------------------------------------- 
  56 #define M_BRUSHDATA ((wxBrushRefData *)m_refData) 
  58 IMPLEMENT_DYNAMIC_CLASS(wxBrush
,wxGDIObject
) 
  60 wxBrush::wxBrush( const wxColour 
&colour
, int style 
) 
  62     m_refData 
= new wxBrushRefData(); 
  63     M_BRUSHDATA
->m_style 
= style
; 
  64     M_BRUSHDATA
->m_colour 
= colour
; 
  67 wxBrush::wxBrush( const wxBitmap 
&stippleBitmap 
) 
  69     m_refData 
= new wxBrushRefData(); 
  70     M_BRUSHDATA
->m_colour 
= *wxBLACK
; 
  72     M_BRUSHDATA
->m_stipple 
= stippleBitmap
; 
  74     if (M_BRUSHDATA
->m_stipple
.GetMask()) 
  75         M_BRUSHDATA
->m_style 
= wxSTIPPLE_MASK_OPAQUE
; 
  77         M_BRUSHDATA
->m_style 
= wxSTIPPLE
; 
  82     // m_refData unrefed in ~wxObject 
  85 wxObjectRefData 
*wxBrush::CreateRefData() const 
  87     return new wxBrushRefData
; 
  90 wxObjectRefData 
*wxBrush::CloneRefData(const wxObjectRefData 
*data
) const 
  92     return new wxBrushRefData(*(wxBrushRefData 
*)data
); 
  95 bool wxBrush::operator == ( const wxBrush
& brush 
) const 
  97     if (m_refData 
== brush
.m_refData
) return TRUE
; 
  99     if (!m_refData 
|| !brush
.m_refData
) return FALSE
; 
 101     return ( *(wxBrushRefData
*)m_refData 
== *(wxBrushRefData
*)brush
.m_refData 
); 
 104 int wxBrush::GetStyle() const 
 106     if (m_refData 
== NULL
) 
 108         wxFAIL_MSG( wxT("invalid brush") ); 
 112     return M_BRUSHDATA
->m_style
; 
 115 wxColour 
&wxBrush::GetColour() const 
 117     if (m_refData 
== NULL
) 
 119         wxFAIL_MSG( wxT("invalid brush") ); 
 123     return M_BRUSHDATA
->m_colour
; 
 126 wxBitmap 
*wxBrush::GetStipple() const 
 128     if (m_refData 
== NULL
) 
 130         wxFAIL_MSG( wxT("invalid brush") ); 
 131         return &wxNullBitmap
; 
 134     return &M_BRUSHDATA
->m_stipple
; 
 137 void wxBrush::SetColour( const wxColour
& col 
) 
 141     M_BRUSHDATA
->m_colour 
= col
; 
 144 void wxBrush::SetColour( unsigned char r
, unsigned char g
, unsigned char b 
) 
 148     M_BRUSHDATA
->m_colour
.Set( r
, g
, b 
); 
 151 void wxBrush::SetStyle( int style 
) 
 155     M_BRUSHDATA
->m_style 
= style
; 
 158 void wxBrush::SetStipple( const wxBitmap
& stipple 
) 
 162     M_BRUSHDATA
->m_stipple 
= stipple
; 
 163     if (M_BRUSHDATA
->m_stipple
.GetMask()) 
 165         M_BRUSHDATA
->m_style 
= wxSTIPPLE_MASK_OPAQUE
; 
 169         M_BRUSHDATA
->m_style 
= wxSTIPPLE
;