/////////////////////////////////////////////////////////////////////////////
-// Name: brush.cpp
+// Name: src/mgl/brush.cpp
// Purpose:
// Author: Vaclav Slavik
// Id: $Id$
-// Copyright: (c) 2001 Vaclav Slavik
-// 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"
// 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);
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();
}
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();
}
IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
-wxBrush::wxBrush()
-{
- if (wxTheBrushList) wxTheBrushList->AddBrush(this);
-}
-
wxBrush::wxBrush(const wxColour &colour, int style)
{
m_refData = new wxBrushRefData();
M_BRUSHDATA->m_style = style;
M_BRUSHDATA->m_colour = colour;
-
- if (wxTheBrushList) wxTheBrushList->AddBrush(this);
}
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;
-
- if (wxTheBrushList) wxTheBrushList->AddBrush(this);
+ M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
+ else
+ M_BRUSHDATA->m_style = wxSTIPPLE;
}
wxBrush::wxBrush(const wxBrush &brush)
{
Ref(brush);
-
- if (wxTheBrushList) wxTheBrushList->AddBrush(this);
-}
-
-wxBrush::~wxBrush()
-{
- if (wxTheBrushList) wxTheBrushList->RemoveBrush(this);
}
wxBrush& wxBrush::operator = (const wxBrush& brush)
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;
M_BRUSHDATA->m_style = wxSTIPPLE;
}
-void wxBrush::Unshare()
+wxObjectRefData *wxBrush::CreateRefData() const
{
- if (!m_refData)
- {
- m_refData = new wxBrushRefData();
- }
- else
- {
- wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData);
- UnRef();
- m_refData = ref;
- }
+ return new wxBrushRefData;
}
+wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const
+{
+ return new wxBrushRefData(*(wxBrushRefData *)data);
+}