]> git.saurik.com Git - wxWidgets.git/blame - src/generic/mask.cpp
Forgot header with OSX prefix
[wxWidgets.git] / src / generic / mask.cpp
CommitLineData
87f83ac8
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/generic/mask.cpp
3// Purpose: generic wxMask implementation
4// Author: Vadim Zeitlin
5// Created: 2006-09-28
6// RCS-ID: $Id$
7// Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19// for compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26#ifndef WX_PRECOMP
27 #include "wx/bitmap.h"
28 #include "wx/image.h"
29#endif // WX_PRECOMP
30
31#if wxUSE_GENERIC_MASK
32
33// ============================================================================
34// wxMask implementation
35// ============================================================================
36
37IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
38
39void wxMask::FreeData()
40{
41 m_bitmap = wxNullBitmap;
42}
43
44bool wxMask::InitFromColour(const wxBitmap& bitmap, const wxColour& colour)
45{
46#if wxUSE_IMAGE
47 const wxColour clr(bitmap.QuantizeColour(colour));
48
49 wxImage imgSrc(bitmap.ConvertToImage());
50 imgSrc.SetMask(false);
51 wxImage image(imgSrc.ConvertToMono(clr.Red(), clr.Green(), clr.Blue()));
52 if ( !image.Ok() )
53 return false;
54
55 m_bitmap = wxBitmap(image, 1);
56
57 return m_bitmap.Ok();
58#else // !wxUSE_IMAGE
59 wxUnusedVar(bitmap);
60 wxUnusedVar(colour);
61
62 return false;
63#endif // wxUSE_IMAGE/!wxUSE_IMAGE
64}
65
66bool wxMask::InitFromMonoBitmap(const wxBitmap& bitmap)
67{
68 wxCHECK_MSG( bitmap.Ok(), false, wxT("Invalid bitmap") );
69 wxCHECK_MSG( bitmap.GetDepth() == 1, false, wxT("Cannot create mask from colour bitmap") );
70
71 m_bitmap = bitmap;
72
73 return true;
74}
75
76#endif // wxUSE_GENERIC_MASK