Wrote wxMask(bitmap,colour).
Some docs for it and wxBitmap::GetSubBitmap(). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5110 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -98,9 +98,9 @@ If all possible wxWindows settings are used, the Windows platform supports BMP f
|
|||||||
XPM data, and XPM. Under wxGTK, the available formats are BMP file, XPM data, XPM file, and PNG file.
|
XPM data, and XPM. Under wxGTK, the available formats are BMP file, XPM data, XPM file, and PNG file.
|
||||||
Under wxMotif, the available formats are XBM data, XBM file, XPM data, XPM file.
|
Under wxMotif, the available formats are XBM data, XBM file, XPM data, XPM file.
|
||||||
|
|
||||||
In addition, wxBitmap can read all formats that \helpref{wxImage}{wximage} can
|
In addition, wxBitmap can read all formats that \helpref{wxImage}{wximage} can, which currently include
|
||||||
(wxBITMAP\_TYPE\_JPEG, wxBITMAP\_TYPE\_PNG, wxBITMAP\_TYPE\_GIF, wxBITMAP\_TYPE\_PCX, wxBITMAP\_TYPE\_PNM).
|
wxBITMAP\_TYPE\_JPEG, wxBITMAP\_TYPE\_TIF, wxBITMAP\_TYPE\_PNG, wxBITMAP\_TYPE\_GIF, wxBITMAP\_TYPE\_PCX,
|
||||||
(Of course you must have wxImage handlers loaded.) }
|
and wxBITMAP\_TYPE\_PNM. Of course, you must have wxImage handlers loaded. }
|
||||||
|
|
||||||
\wxheading{Remarks}
|
\wxheading{Remarks}
|
||||||
|
|
||||||
@@ -312,6 +312,13 @@ Gets the width of the bitmap in pixels.
|
|||||||
|
|
||||||
\helpref{wxBitmap::GetHeight}{wxbitmapgetheight}
|
\helpref{wxBitmap::GetHeight}{wxbitmapgetheight}
|
||||||
|
|
||||||
|
\membersection{wxBitmap::GetSubBitmap}\label{wxbitmapgetsubbitmap}
|
||||||
|
|
||||||
|
\constfunc{wxBitmap}{GetSubBitmap}{\param{const wxRect&}{rect}}
|
||||||
|
|
||||||
|
Returns a sub bitmap of the current one as long as the rect belongs entirely to
|
||||||
|
the bitmap. This function preserves bit depth and mask information.
|
||||||
|
|
||||||
\membersection{wxBitmap::InitStandardHandlers}
|
\membersection{wxBitmap::InitStandardHandlers}
|
||||||
|
|
||||||
\func{static void}{InitStandardHandlers}{\void}
|
\func{static void}{InitStandardHandlers}{\void}
|
||||||
|
@@ -37,8 +37,7 @@ Constructs a mask from a monochrome bitmap.
|
|||||||
|
|
||||||
\func{}{wxMask}{\param{const wxBitmap\& }{bitmap}, \param{const wxColour\& }{colour}}
|
\func{}{wxMask}{\param{const wxBitmap\& }{bitmap}, \param{const wxColour\& }{colour}}
|
||||||
|
|
||||||
Constructs a mask from a bitmap and a colour that indicates the background. Not
|
Constructs a mask from a bitmap and a colour that indicates the background.
|
||||||
yet implemented for GTK.
|
|
||||||
|
|
||||||
\pythonnote{wxPython has an alternate wxMask constructor matching this
|
\pythonnote{wxPython has an alternate wxMask constructor matching this
|
||||||
form called \tt{wxMaskColour}.}
|
form called \tt{wxMaskColour}.}
|
||||||
@@ -70,8 +69,7 @@ Constructs a mask from a monochrome bitmap.
|
|||||||
|
|
||||||
\func{bool}{Create}{\param{const wxBitmap\& }{bitmap}, \param{const wxColour\& }{colour}}
|
\func{bool}{Create}{\param{const wxBitmap\& }{bitmap}, \param{const wxColour\& }{colour}}
|
||||||
|
|
||||||
Constructs a mask from a bitmap and a colour that indicates the background. Not
|
Constructs a mask from a bitmap and a colour that indicates the background.
|
||||||
yet implemented for GTK.
|
|
||||||
|
|
||||||
\func{bool}{Create}{\param{const wxBitmap\& }{bitmap}, \param{int}{ index}}
|
\func{bool}{Create}{\param{const wxBitmap\& }{bitmap}, \param{int}{ index}}
|
||||||
|
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
#include "wx/icon.h"
|
#include "wx/icon.h"
|
||||||
#include "wx/filefn.h"
|
#include "wx/filefn.h"
|
||||||
#include "wx/image.h"
|
#include "wx/image.h"
|
||||||
|
#include "wx/dcmemory.h"
|
||||||
|
|
||||||
#include <gdk/gdk.h>
|
#include <gdk/gdk.h>
|
||||||
#include <gdk/gdkprivate.h>
|
#include <gdk/gdkprivate.h>
|
||||||
@@ -67,14 +68,18 @@ bool wxMask::Create( const wxBitmap& bitmap,
|
|||||||
wxImage image( bitmap );
|
wxImage image( bitmap );
|
||||||
if (!image.Ok()) return FALSE;
|
if (!image.Ok()) return FALSE;
|
||||||
|
|
||||||
GdkVisual *visual = gdk_visual_get_system();
|
|
||||||
|
|
||||||
GdkImage *mask_image = gdk_image_new( GDK_IMAGE_FASTEST, visual, image.GetWidth(), image.GetHeight() );
|
|
||||||
if (!mask_image) return FALSE;
|
|
||||||
|
|
||||||
GdkWindow *parent = (GdkWindow*) &gdk_root_parent;
|
GdkWindow *parent = (GdkWindow*) &gdk_root_parent;
|
||||||
m_bitmap = gdk_pixmap_new( parent, image.GetWidth(), image.GetHeight(), 1 );
|
m_bitmap = gdk_pixmap_new( parent, image.GetWidth(), image.GetHeight(), 1 );
|
||||||
|
GdkGC *gc = gdk_gc_new( m_bitmap );
|
||||||
|
|
||||||
|
GdkColor color;
|
||||||
|
color.red = 65000;
|
||||||
|
color.green = 65000;
|
||||||
|
color.blue = 65000;
|
||||||
|
color.pixel = 1;
|
||||||
|
gdk_gc_set_foreground( gc, &color );
|
||||||
|
gdk_gc_set_fill( gc, GDK_SOLID );
|
||||||
|
gdk_draw_rectangle( m_bitmap, gc, TRUE, 0, 0, image.GetWidth(), image.GetHeight() );
|
||||||
|
|
||||||
unsigned char *data = image.GetData();
|
unsigned char *data = image.GetData();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@@ -83,6 +88,7 @@ bool wxMask::Create( const wxBitmap& bitmap,
|
|||||||
unsigned char green = colour.Green();
|
unsigned char green = colour.Green();
|
||||||
unsigned char blue = colour.Blue();
|
unsigned char blue = colour.Blue();
|
||||||
|
|
||||||
|
GdkVisual *visual = gdk_visual_get_system();
|
||||||
int bpp = visual->depth;
|
int bpp = visual->depth;
|
||||||
if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15;
|
if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15;
|
||||||
if (bpp == 15)
|
if (bpp == 15)
|
||||||
@@ -98,30 +104,42 @@ bool wxMask::Create( const wxBitmap& bitmap,
|
|||||||
green = green & 0xf8;
|
green = green & 0xf8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
color.red = 0;
|
||||||
|
color.green = 0;
|
||||||
|
color.blue = 0;
|
||||||
|
color.pixel = 0;
|
||||||
|
gdk_gc_set_foreground( gc, &color );
|
||||||
|
|
||||||
for (int j = 0; j < image.GetHeight(); j++)
|
for (int j = 0; j < image.GetHeight(); j++)
|
||||||
for (int i = 0; i < image.GetWidth(); i++)
|
{
|
||||||
|
int start_x = -1;
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < image.GetWidth(); i++)
|
||||||
{
|
{
|
||||||
if ((data[index] == red) &&
|
if ((data[index] == red) &&
|
||||||
(data[index+1] == green) &&
|
(data[index+1] == green) &&
|
||||||
(data[index+2] == blue))
|
(data[index+2] == blue))
|
||||||
{
|
{
|
||||||
gdk_image_put_pixel( mask_image, i, j, 1 );
|
if (start_x == -1)
|
||||||
|
start_x = i;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gdk_image_put_pixel( mask_image, i, j, 1 );
|
if (start_x != -1)
|
||||||
}
|
{
|
||||||
index += 3;
|
gdk_draw_line( m_bitmap, gc, start_x, j, i-1, j );
|
||||||
}
|
start_x = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
index += 3;
|
||||||
|
}
|
||||||
|
if (start_x != -1)
|
||||||
|
gdk_draw_line( m_bitmap, gc, start_x, j, i, j );
|
||||||
|
}
|
||||||
|
|
||||||
GdkGC *mask_gc = gdk_gc_new( m_bitmap );
|
gdk_gc_unref( gc );
|
||||||
|
|
||||||
gdk_draw_image( m_bitmap, mask_gc, mask_image, 0, 0, 0, 0, image.GetWidth(), image.GetHeight() );
|
return TRUE;
|
||||||
|
|
||||||
gdk_gc_unref( mask_gc );
|
|
||||||
gdk_image_destroy( mask_image );
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxMask::Create( const wxBitmap& WXUNUSED(bitmap),
|
bool wxMask::Create( const wxBitmap& WXUNUSED(bitmap),
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
#include "wx/icon.h"
|
#include "wx/icon.h"
|
||||||
#include "wx/filefn.h"
|
#include "wx/filefn.h"
|
||||||
#include "wx/image.h"
|
#include "wx/image.h"
|
||||||
|
#include "wx/dcmemory.h"
|
||||||
|
|
||||||
#include <gdk/gdk.h>
|
#include <gdk/gdk.h>
|
||||||
#include <gdk/gdkprivate.h>
|
#include <gdk/gdkprivate.h>
|
||||||
@@ -67,14 +68,18 @@ bool wxMask::Create( const wxBitmap& bitmap,
|
|||||||
wxImage image( bitmap );
|
wxImage image( bitmap );
|
||||||
if (!image.Ok()) return FALSE;
|
if (!image.Ok()) return FALSE;
|
||||||
|
|
||||||
GdkVisual *visual = gdk_visual_get_system();
|
|
||||||
|
|
||||||
GdkImage *mask_image = gdk_image_new( GDK_IMAGE_FASTEST, visual, image.GetWidth(), image.GetHeight() );
|
|
||||||
if (!mask_image) return FALSE;
|
|
||||||
|
|
||||||
GdkWindow *parent = (GdkWindow*) &gdk_root_parent;
|
GdkWindow *parent = (GdkWindow*) &gdk_root_parent;
|
||||||
m_bitmap = gdk_pixmap_new( parent, image.GetWidth(), image.GetHeight(), 1 );
|
m_bitmap = gdk_pixmap_new( parent, image.GetWidth(), image.GetHeight(), 1 );
|
||||||
|
GdkGC *gc = gdk_gc_new( m_bitmap );
|
||||||
|
|
||||||
|
GdkColor color;
|
||||||
|
color.red = 65000;
|
||||||
|
color.green = 65000;
|
||||||
|
color.blue = 65000;
|
||||||
|
color.pixel = 1;
|
||||||
|
gdk_gc_set_foreground( gc, &color );
|
||||||
|
gdk_gc_set_fill( gc, GDK_SOLID );
|
||||||
|
gdk_draw_rectangle( m_bitmap, gc, TRUE, 0, 0, image.GetWidth(), image.GetHeight() );
|
||||||
|
|
||||||
unsigned char *data = image.GetData();
|
unsigned char *data = image.GetData();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@@ -83,6 +88,7 @@ bool wxMask::Create( const wxBitmap& bitmap,
|
|||||||
unsigned char green = colour.Green();
|
unsigned char green = colour.Green();
|
||||||
unsigned char blue = colour.Blue();
|
unsigned char blue = colour.Blue();
|
||||||
|
|
||||||
|
GdkVisual *visual = gdk_visual_get_system();
|
||||||
int bpp = visual->depth;
|
int bpp = visual->depth;
|
||||||
if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15;
|
if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15;
|
||||||
if (bpp == 15)
|
if (bpp == 15)
|
||||||
@@ -98,30 +104,42 @@ bool wxMask::Create( const wxBitmap& bitmap,
|
|||||||
green = green & 0xf8;
|
green = green & 0xf8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
color.red = 0;
|
||||||
|
color.green = 0;
|
||||||
|
color.blue = 0;
|
||||||
|
color.pixel = 0;
|
||||||
|
gdk_gc_set_foreground( gc, &color );
|
||||||
|
|
||||||
for (int j = 0; j < image.GetHeight(); j++)
|
for (int j = 0; j < image.GetHeight(); j++)
|
||||||
for (int i = 0; i < image.GetWidth(); i++)
|
{
|
||||||
|
int start_x = -1;
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < image.GetWidth(); i++)
|
||||||
{
|
{
|
||||||
if ((data[index] == red) &&
|
if ((data[index] == red) &&
|
||||||
(data[index+1] == green) &&
|
(data[index+1] == green) &&
|
||||||
(data[index+2] == blue))
|
(data[index+2] == blue))
|
||||||
{
|
{
|
||||||
gdk_image_put_pixel( mask_image, i, j, 1 );
|
if (start_x == -1)
|
||||||
|
start_x = i;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gdk_image_put_pixel( mask_image, i, j, 1 );
|
if (start_x != -1)
|
||||||
}
|
{
|
||||||
index += 3;
|
gdk_draw_line( m_bitmap, gc, start_x, j, i-1, j );
|
||||||
}
|
start_x = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
index += 3;
|
||||||
|
}
|
||||||
|
if (start_x != -1)
|
||||||
|
gdk_draw_line( m_bitmap, gc, start_x, j, i, j );
|
||||||
|
}
|
||||||
|
|
||||||
GdkGC *mask_gc = gdk_gc_new( m_bitmap );
|
gdk_gc_unref( gc );
|
||||||
|
|
||||||
gdk_draw_image( m_bitmap, mask_gc, mask_image, 0, 0, 0, 0, image.GetWidth(), image.GetHeight() );
|
return TRUE;
|
||||||
|
|
||||||
gdk_gc_unref( mask_gc );
|
|
||||||
gdk_image_destroy( mask_image );
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxMask::Create( const wxBitmap& WXUNUSED(bitmap),
|
bool wxMask::Create( const wxBitmap& WXUNUSED(bitmap),
|
||||||
|
Reference in New Issue
Block a user