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