The Lesser wxMask Refactoring: merged wxMGL and wxDFB version, added wxMaskBase which could/should be used by other ports later
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41495 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -24,10 +24,41 @@
|
||||
|
||||
class WXDLLEXPORT wxBitmap;
|
||||
class WXDLLEXPORT wxBitmapHandler;
|
||||
class WXDLLEXPORT wxIcon;
|
||||
class WXDLLEXPORT wxImage;
|
||||
class WXDLLEXPORT wxMask;
|
||||
class WXDLLEXPORT wxPalette;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxMask represents the transparent area of the bitmap
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxMaskBase : public wxObject
|
||||
{
|
||||
public:
|
||||
// create the mask from bitmap pixels of the given colour
|
||||
bool Create(const wxBitmap& bitmap, const wxColour& colour);
|
||||
|
||||
#if wxUSE_PALETTE
|
||||
// create the mask from bitmap pixels with the given palette index
|
||||
bool Create(const wxBitmap& bitmap, int paletteIndex);
|
||||
#endif // wxUSE_PALETTE
|
||||
|
||||
// create the mask from the given mono bitmap
|
||||
bool Create(const wxBitmap& bitmap);
|
||||
|
||||
protected:
|
||||
// this function is called from Create() to free the existing mask data
|
||||
virtual void FreeData() = 0;
|
||||
|
||||
// these functions must be overridden to implement the corresponding public
|
||||
// Create() methods, they shouldn't call FreeData() as it's already called
|
||||
// by the public wrappers
|
||||
virtual bool InitFromColour(const wxBitmap& bitmap,
|
||||
const wxColour& colour) = 0;
|
||||
virtual bool InitFromMonoBitmap(const wxBitmap& bitmap) = 0;
|
||||
};
|
||||
|
||||
#if defined(__WXMGL__) || \
|
||||
defined(__WXDFB__) || \
|
||||
defined(__WXMAC__) || \
|
||||
@@ -156,6 +187,15 @@ public:
|
||||
|
||||
static void CleanUpHandlers();
|
||||
|
||||
// this method is only used by the generic implementation of wxMask
|
||||
// currently but could be useful elsewhere in the future: it can be
|
||||
// overridden to quantize the colour to correspond to bitmap colour depth
|
||||
// if necessary; default implementation simply returns the colour as is
|
||||
virtual wxColour QuantizeColour(const wxColour& colour) const
|
||||
{
|
||||
return colour;
|
||||
}
|
||||
|
||||
protected:
|
||||
static wxList sm_handlers;
|
||||
|
||||
@@ -188,4 +228,15 @@ protected:
|
||||
#include "wx/os2/bitmap.h"
|
||||
#endif
|
||||
|
||||
// we must include generic mask.h after wxBitmap definition
|
||||
#if defined(__WXMGL__) || defined(__WXDFB__)
|
||||
#define wxUSE_GENERIC_MASK 1
|
||||
#else
|
||||
#define wxUSE_GENERIC_MASK 0
|
||||
#endif
|
||||
|
||||
#if wxUSE_GENERIC_MASK
|
||||
#include "wx/generic/mask.h"
|
||||
#endif
|
||||
|
||||
#endif // _WX_BITMAP_H_BASE_
|
||||
|
||||
@@ -15,38 +15,6 @@
|
||||
|
||||
wxDFB_DECLARE_INTERFACE(IDirectFBSurface);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxMask
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#warning "FIXME: move wxMask to common code"
|
||||
class WXDLLIMPEXP_CORE wxMask: public wxObject
|
||||
{
|
||||
public:
|
||||
wxMask();
|
||||
wxMask(const wxBitmap& bitmap);
|
||||
wxMask(const wxBitmap& bitmap, const wxColour& colour);
|
||||
#if wxUSE_PALETTE
|
||||
wxMask(const wxBitmap& bitmap, int paletteIndex);
|
||||
#endif
|
||||
wxMask(const wxMask& mask);
|
||||
~wxMask();
|
||||
|
||||
bool Create(const wxBitmap& bitmap);
|
||||
bool Create(const wxBitmap& bitmap, const wxColour& colour);
|
||||
#if wxUSE_PALETTE
|
||||
bool Create(const wxBitmap& bitmap, int paletteIndex);
|
||||
#endif
|
||||
|
||||
// implementation
|
||||
const wxBitmap& GetBitmap() const;
|
||||
|
||||
private:
|
||||
wxBitmap *m_bitmap;
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxMask)
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxBitmap
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
54
include/wx/generic/mask.h
Normal file
54
include/wx/generic/mask.h
Normal file
@@ -0,0 +1,54 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/generic/mask.h
|
||||
// Purpose: generic implementation of wxMask
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2006-09-28
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_GENERIC_MASKG_H_
|
||||
#define _WX_GENERIC_MASKG_H_
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// generic wxMask implementation
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxMask : public wxMaskBase
|
||||
{
|
||||
public:
|
||||
wxMask() { }
|
||||
wxMask(const wxBitmap& bitmap, const wxColour& colour)
|
||||
{
|
||||
InitFromColour(bitmap, colour);
|
||||
}
|
||||
|
||||
#if wxUSE_PALETTE
|
||||
wxMask(const wxBitmap& bitmap, int paletteIndex)
|
||||
{
|
||||
Create(bitmap, paletteIndex);
|
||||
}
|
||||
#endif // wxUSE_PALETTE
|
||||
|
||||
wxMask(const wxBitmap& bitmap)
|
||||
{
|
||||
InitFromMonoBitmap(bitmap);
|
||||
}
|
||||
|
||||
// implementation-only from now on
|
||||
wxBitmap GetBitmap() const { return m_bitmap; }
|
||||
|
||||
private:
|
||||
// implement wxMaskBase pure virtuals
|
||||
virtual void FreeData();
|
||||
virtual bool InitFromColour(const wxBitmap& bitmap, const wxColour& colour);
|
||||
virtual bool InitFromMonoBitmap(const wxBitmap& bitmap);
|
||||
|
||||
wxBitmap m_bitmap;
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxMask)
|
||||
};
|
||||
|
||||
#endif // _WX_GENERIC_MASKG_H_
|
||||
|
||||
@@ -9,52 +9,16 @@
|
||||
#ifndef __WX_BITMAP_H__
|
||||
#define __WX_BITMAP_H__
|
||||
|
||||
#include "wx/defs.h"
|
||||
#include "wx/object.h"
|
||||
#include "wx/string.h"
|
||||
#include "wx/palette.h"
|
||||
#include "wx/gdiobj.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// classes
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxMask;
|
||||
class WXDLLEXPORT wxBitmap;
|
||||
class WXDLLEXPORT wxImage;
|
||||
class WXDLLEXPORT wxDC;
|
||||
class WXDLLEXPORT wxMemoryDC;
|
||||
|
||||
class MGLDevCtx;
|
||||
struct bitmap_t;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxMask
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxMask: public wxObject
|
||||
{
|
||||
public:
|
||||
wxMask();
|
||||
wxMask(const wxBitmap& bitmap, const wxColour& colour);
|
||||
wxMask(const wxBitmap& bitmap, int paletteIndex);
|
||||
wxMask(const wxBitmap& bitmap);
|
||||
virtual ~wxMask();
|
||||
|
||||
bool Create(const wxBitmap& bitmap, const wxColour& colour);
|
||||
bool Create(const wxBitmap& bitmap, int paletteIndex);
|
||||
bool Create(const wxBitmap& bitmap);
|
||||
|
||||
// implementation
|
||||
wxBitmap *m_bitmap;
|
||||
|
||||
wxBitmap *GetBitmap() const { return m_bitmap; }
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS(wxMask)
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxBitmap
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -111,6 +75,8 @@ public:
|
||||
virtual void SetWidth(int width);
|
||||
virtual void SetDepth(int depth);
|
||||
|
||||
virtual wxColour QuantizeColour(const wxColour& colour) const;
|
||||
|
||||
// get underlying native representation:
|
||||
bitmap_t *GetMGLbitmap_t() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user