]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mgl/brush.cpp
use quotes around SRCROOT to handle the case when it contains spaces (patch 1912354)
[wxWidgets.git] / src / mgl / brush.cpp
index 6bddd63b3b2b3e926d972f2ca1b79fe6248a2930..b8f6073f388fcfb6c45294161a306f0a2d1bf52f 100644 (file)
@@ -1,16 +1,12 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        brush.cpp
+// Name:        src/mgl/brush.cpp
 // Purpose:
 // Author:      Vaclav Slavik
 // Id:          $Id$
-// Copyright:   (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
-// Licence:    wxWindows licence
+// Copyright:   (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
-#pragma implementation "brush.h"
-#endif
-
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
@@ -20,7 +16,7 @@
 
 #include "wx/brush.h"
 #include "wx/mgl/private.h"
-#include "wx/mgl/dcmemory.h"
+#include "wx/dcmemory.h"
 
 
 // ---------------------------------------------------------------------------
 // This function converts wxBitmap into pixpattern24_t representation
 // (used by wxBrush and wxPen)
 
-void wxBitmapToPixPattern(const wxBitmap& bitmap, 
+void wxBitmapToPixPattern(const wxBitmap& bitmap,
                           pixpattern24_t *pix, pattern_t *mask)
 {
     wxMemoryDC mem;
     MGLDevCtx *dc;
     int x, y;
-    
+
     if ( pix != NULL )
     {
-        mem.SelectObject(bitmap);
+        mem.SelectObjectAsSource(bitmap);
         dc = mem.GetMGLDC();
         wxCurrentDCSwitcher curDC(dc);
         dc->beginPixel();
         for (y = 0; y < 8; y++)
             for (x = 0; x < 8; x++)
-                dc->unpackColorFast(dc->getPixelFast(x, y), 
+                dc->unpackColorFast(dc->getPixelFast(x, y),
                                     pix->p[y][x][2],
-                                    pix->p[y][x][1], 
+                                    pix->p[y][x][1],
                                     pix->p[y][x][0]);
         dc->endPixel();
     }
 
     if ( mask && bitmap.GetMask() )
     {
-        mem.SelectObject(*bitmap.GetMask()->GetBitmap());
+        mem.SelectObjectAsSource(bitmap.GetMask()->GetBitmap());
         dc = mem.GetMGLDC();
         wxCurrentDCSwitcher curDC(dc);
         dc->beginPixel();
@@ -63,7 +59,7 @@ void wxBitmapToPixPattern(const wxBitmap& bitmap,
             mask->p[y] = 0;
             for (x = 0; x < 8; x++)
                 if ( dc->getPixelFast(x, y) != 0 )
-                    mask->p[y] |= 1 << (7 - x);
+                    mask->p[y] = (uchar)(mask->p[y] | (1 << (7 - x)));
         }
         dc->endPixel();
     }
@@ -74,12 +70,21 @@ void wxBitmapToPixPattern(const wxBitmap& bitmap,
 // wxBrush
 //-----------------------------------------------------------------------------
 
-class wxBrushRefData: public wxObjectRefData
+class wxBrushRefData : public wxGDIRefData
 {
 public:
     wxBrushRefData();
     wxBrushRefData(const wxBrushRefData& data);
 
+    virtual bool IsOk() const { return m_colour.IsOk(); }
+
+    bool operator==(const wxBrushRefData& data) const
+    {
+        return (m_style == data.m_style &&
+                m_stipple.IsSameAs(data.m_stipple) &&
+                m_colour == data.m_colour);
+    }
+
     int            m_style;
     wxColour       m_colour;
     wxBitmap       m_stipple;
@@ -131,37 +136,29 @@ wxBrush::wxBrush(const wxColour &colour, int style)
 wxBrush::wxBrush(const wxBitmap &stippleBitmap)
 {
     wxCHECK_RET( stippleBitmap.Ok(), _T("invalid bitmap") );
-    wxCHECK_RET( stippleBitmap.GetWidth() == 8 && stippleBitmap.GetHeight() == 8, 
+    wxCHECK_RET( stippleBitmap.GetWidth() == 8 && stippleBitmap.GetHeight() == 8,
                   _T("stipple bitmap must be 8x8") );
 
     m_refData = new wxBrushRefData();
     M_BRUSHDATA->m_colour = *wxBLACK;
-    
+
     M_BRUSHDATA->m_stipple = stippleBitmap;
-    wxBitmapToPixPattern(stippleBitmap, &(M_BRUSHDATA->m_pixPattern), 
+    wxBitmapToPixPattern(stippleBitmap, &(M_BRUSHDATA->m_pixPattern),
                                         &(M_BRUSHDATA->m_maskPattern));
 
     if (M_BRUSHDATA->m_stipple.GetMask())
-               M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
-       else
-               M_BRUSHDATA->m_style = wxSTIPPLE;
+        M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
+    else
+        M_BRUSHDATA->m_style = wxSTIPPLE;
 }
 
-wxBrush::wxBrush(const wxBrush &brush)
+bool wxBrush::operator == (const wxBrush& brush) const
 {
-    Ref(brush);
-}
+    if (m_refData == brush.m_refData) return true;
 
-wxBrush& wxBrush::operator = (const wxBrush& brush)
-{
-    if (*this == brush) return (*this);
-    Ref(brush);
-    return *this;
-}
+    if (!m_refData || !brush.m_refData) return false;
 
-bool wxBrush::operator == (const wxBrush& brush) const
-{
-    return m_refData == brush.m_refData;
+    return *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData;
 }
 
 bool wxBrush::operator != (const wxBrush& brush) const
@@ -169,11 +166,6 @@ bool wxBrush::operator != (const wxBrush& brush) const
     return m_refData != brush.m_refData;
 }
 
-bool wxBrush::Ok() const
-{
-    return ((m_refData) && M_BRUSHDATA->m_colour.Ok());
-}
-
 int wxBrush::GetStyle() const
 {
     if (m_refData == NULL)
@@ -223,28 +215,28 @@ void* wxBrush::GetPixPattern() const
 
 void wxBrush::SetColour(const wxColour& col)
 {
-    Unshare();
+    AllocExclusive();
     M_BRUSHDATA->m_colour = col;
 }
 
 void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b)
 {
-    Unshare();
+    AllocExclusive();
     M_BRUSHDATA->m_colour.Set(r, g, b);
 }
 
 void wxBrush::SetStyle( int style )
 {
-    Unshare();
+    AllocExclusive();
     M_BRUSHDATA->m_style = style;
 }
 
 void wxBrush::SetStipple(const wxBitmap& stipple)
 {
-    Unshare();
+    AllocExclusive();
 
     wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") );
-    wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8, 
+    wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8,
                   _T("stipple bitmap must be 8x8") );
 
     M_BRUSHDATA->m_stipple = stipple;
@@ -257,17 +249,12 @@ void wxBrush::SetStipple(const wxBitmap& stipple)
         M_BRUSHDATA->m_style = wxSTIPPLE;
 }
 
-void wxBrush::Unshare()
+wxGDIRefData *wxBrush::CreateGDIRefData() const
 {
-    if (!m_refData)
-    {
-        m_refData = new wxBrushRefData();
-    }
-    else
-    {
-        wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData);
-        UnRef();
-        m_refData = ref;
-    }
+    return new wxBrushRefData;
 }
 
+wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const
+{
+    return new wxBrushRefData(*(wxBrushRefData *)data);
+}