From eefa26bed1ef371bf618b48ea1d21096e71ea465 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Wed, 21 Apr 1999 12:35:02 +0000 Subject: [PATCH] fixed bitmap constructor for monochrome bitmaps git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2256 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/image/image.cpp | 3 +++ src/gtk/bitmap.cpp | 22 ++++++++++++++++------ src/gtk1/bitmap.cpp | 22 ++++++++++++++++------ 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/samples/image/image.cpp b/samples/image/image.cpp index e6b535b937..0f1b6cf0aa 100644 --- a/samples/image/image.cpp +++ b/samples/image/image.cpp @@ -143,6 +143,9 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) dc.DrawText( "Loaded image", 30, 10 ); if (my_square && my_square->Ok()) dc.DrawBitmap( *my_square, 30, 30 ); + + wxBitmap bm( 1200, 1, 1 ); + dc.DrawBitmap( bm, 10, 10 ); dc.DrawText( "Drawn directly", 150, 10 ); dc.SetBrush( wxBrush( "orange", wxSOLID ) ); diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 0a2da3f4e9..80ecdcddac 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -105,17 +105,27 @@ wxBitmap::wxBitmap() wxBitmap::wxBitmap( int width, int height, int depth ) { wxCHECK_RET( (width > 0) && (height > 0), _T("invalid bitmap size") ) - wxCHECK_RET( (depth > 0) || (depth == -1), _T("invalid bitmap depth") ) - - m_refData = new wxBitmapRefData(); - + GdkWindow *parent = (GdkWindow*) &gdk_root_parent; + if (depth == -1) depth = gdk_window_get_visual( parent )->depth; + + wxCHECK_RET( (depth == gdk_window_get_visual( parent )->depth) || + (depth == 1), _T("invalid bitmap depth") ) + m_refData = new wxBitmapRefData(); M_BMPDATA->m_mask = (wxMask *) NULL; - M_BMPDATA->m_pixmap = gdk_pixmap_new( parent, width, height, depth ); M_BMPDATA->m_width = width; M_BMPDATA->m_height = height; - M_BMPDATA->m_bpp = gdk_window_get_visual( parent )->depth; + if (depth == 1) + { + M_BMPDATA->m_bitmap = gdk_pixmap_new( parent, width, height, 1 ); + M_BMPDATA->m_bpp = 1; + } + else + { + M_BMPDATA->m_pixmap = gdk_pixmap_new( parent, width, height, depth ); + M_BMPDATA->m_bpp = gdk_window_get_visual( parent )->depth; + } if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); } diff --git a/src/gtk1/bitmap.cpp b/src/gtk1/bitmap.cpp index 0a2da3f4e9..80ecdcddac 100644 --- a/src/gtk1/bitmap.cpp +++ b/src/gtk1/bitmap.cpp @@ -105,17 +105,27 @@ wxBitmap::wxBitmap() wxBitmap::wxBitmap( int width, int height, int depth ) { wxCHECK_RET( (width > 0) && (height > 0), _T("invalid bitmap size") ) - wxCHECK_RET( (depth > 0) || (depth == -1), _T("invalid bitmap depth") ) - - m_refData = new wxBitmapRefData(); - + GdkWindow *parent = (GdkWindow*) &gdk_root_parent; + if (depth == -1) depth = gdk_window_get_visual( parent )->depth; + + wxCHECK_RET( (depth == gdk_window_get_visual( parent )->depth) || + (depth == 1), _T("invalid bitmap depth") ) + m_refData = new wxBitmapRefData(); M_BMPDATA->m_mask = (wxMask *) NULL; - M_BMPDATA->m_pixmap = gdk_pixmap_new( parent, width, height, depth ); M_BMPDATA->m_width = width; M_BMPDATA->m_height = height; - M_BMPDATA->m_bpp = gdk_window_get_visual( parent )->depth; + if (depth == 1) + { + M_BMPDATA->m_bitmap = gdk_pixmap_new( parent, width, height, 1 ); + M_BMPDATA->m_bpp = 1; + } + else + { + M_BMPDATA->m_pixmap = gdk_pixmap_new( parent, width, height, depth ); + M_BMPDATA->m_bpp = gdk_window_get_visual( parent )->depth; + } if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); } -- 2.45.2