From 82ea63e6e046652bc0799badd9d62f91c9918dbe Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Wed, 12 Jan 2000 17:57:18 +0000 Subject: [PATCH] Chnages to mono-bitmap code. Added ConvertToMonoBitmap() to wxImage. Minor changes to forty. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5359 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- demos/forty/game.cpp | 84 ++++++++++++++++--------------- demos/forty/playerdg.cpp | 2 + include/wx/gtk/bitmap.h | 1 + include/wx/gtk1/bitmap.h | 1 + include/wx/image.h | 3 ++ samples/image/image.cpp | 36 +++++++++++-- src/common/image.cpp | 106 ++++++++++++++++++++++++++++++++++++--- src/gtk/bitmap.cpp | 7 +++ src/gtk/dcclient.cpp | 105 ++++++++++++++++++++++---------------- src/gtk1/bitmap.cpp | 7 +++ src/gtk1/dcclient.cpp | 105 ++++++++++++++++++++++---------------- 11 files changed, 320 insertions(+), 137 deletions(-) diff --git a/demos/forty/game.cpp b/demos/forty/game.cpp index 4ac59941eb..fa1a29e434 100644 --- a/demos/forty/game.cpp +++ b/demos/forty/game.cpp @@ -289,6 +289,7 @@ void Game::Redraw(wxDC& dc) // Initialise the card bitmap to the background colour wxMemoryDC memoryDC; memoryDC.SelectObject(*m_bmapCard); + memoryDC.SetPen( *wxTRANSPARENT_PEN ); memoryDC.SetBrush(FortyApp::BackgroundBrush()); memoryDC.DrawRectangle(0, 0, CardWidth, CardHeight); memoryDC.SelectObject(*m_bmap); @@ -713,14 +714,14 @@ void Pack::Shuffle() } for (i = 0; i <= m_topCard; i++) { - int pos = rand() % (m_topCard + 1); - while (temp[pos]) - { - pos--; - if (pos < 0) pos = m_topCard; - } - m_cards[i]->TurnCard(facedown); - temp[pos] = m_cards[i]; + int pos = rand() % (m_topCard + 1); + while (temp[pos]) + { + pos--; + if (pos < 0) pos = m_topCard; + } + m_cards[i]->TurnCard(facedown); + temp[pos] = m_cards[i]; m_cards[i] = 0; } @@ -729,12 +730,12 @@ void Pack::Shuffle() // unoccupied position after the random position. for (i = 0; i <= m_topCard; i++) { - int pos = rand() % (m_topCard + 1); - while (m_cards[pos]) - { - pos++; + int pos = rand() % (m_topCard + 1); + while (m_cards[pos]) + { + pos++; if (pos > m_topCard) pos = 0; - } + } m_cards[pos] = temp[i]; } } @@ -746,6 +747,7 @@ void Pack::Redraw(wxDC& dc) char str[10]; sprintf(str, "%d ", m_topCard + 1); + dc.SetBackgroundMode( wxSOLID ); dc.SetTextBackground(FortyApp::BackgroundColour()); dc.SetTextForeground(FortyApp::TextColour()); dc.DrawText(str, m_x + CardWidth + 5, m_y + CardHeight / 2); @@ -771,7 +773,7 @@ Pack::~Pack() { for (m_topCard = 0; m_topCard < NumCards; m_topCard++) { - delete m_cards[m_topCard]; + delete m_cards[m_topCard]; } }; @@ -791,9 +793,9 @@ bool Base::AcceptCard(Card* card) if (m_topCard >= 0) { - if (m_cards[m_topCard]->GetSuit() == card->GetSuit() && - m_cards[m_topCard]->GetPipValue() - 1 == card->GetPipValue()) - { + if (m_cards[m_topCard]->GetSuit() == card->GetSuit() && + m_cards[m_topCard]->GetPipValue() - 1 == card->GetPipValue()) + { retval = TRUE; } } @@ -825,15 +827,15 @@ bool Foundation::AcceptCard(Card* card) if (m_topCard >= 0) { - if (m_cards[m_topCard]->GetSuit() == card->GetSuit() && - m_cards[m_topCard]->GetPipValue() + 1 == card->GetPipValue()) - { + if (m_cards[m_topCard]->GetSuit() == card->GetSuit() && + m_cards[m_topCard]->GetPipValue() + 1 == card->GetPipValue()) + { retval = TRUE; } } else if (card->GetPipValue() == 1) { - // It's an ace and the pile is empty - ACCEPT + // It's an ace and the pile is empty - ACCEPT retval = TRUE; } return retval; @@ -857,22 +859,22 @@ void Discard::Redraw(wxDC& dc) { if (m_topCard >= 0) { - if (m_dx == 0 && m_dy == 0) - { + if (m_dx == 0 && m_dy == 0) + { m_cards[m_topCard]->Draw(dc, m_x, m_y); - } - else - { - int x = m_x; - int y = m_y; - for (int i = 0; i <= m_topCard; i++) + } + else { - m_cards[i]->Draw(dc, x, y); - x += m_dx; - y += m_dy; - if (i == 31) - { - x = m_x; + int x = m_x; + int y = m_y; + for (int i = 0; i <= m_topCard; i++) + { + m_cards[i]->Draw(dc, x, y); + x += m_dx; + y += m_dy; + if (i == 31) + { + x = m_x; y = m_y + CardHeight / 3; } } @@ -889,18 +891,18 @@ void Discard::GetTopCardPos(int& x, int& y) { if (m_topCard < 0) { - x = m_x; - y = m_y; + x = m_x; + y = m_y; } else if (m_topCard > 31) { - x = m_x + m_dx * (m_topCard - 32); - y = m_y + CardHeight / 3; + x = m_x + m_dx * (m_topCard - 32); + y = m_y + CardHeight / 3; } else { - x = m_x + m_dx * m_topCard; - y = m_y; + x = m_x + m_dx * m_topCard; + y = m_y; } } diff --git a/demos/forty/playerdg.cpp b/demos/forty/playerdg.cpp index fa3ea03d04..0f646e2e32 100644 --- a/demos/forty/playerdg.cpp +++ b/demos/forty/playerdg.cpp @@ -123,6 +123,8 @@ PlayerSelectionDialog::PlayerSelectionDialog( } Layout(); + + CentreOnParent(); } PlayerSelectionDialog::~PlayerSelectionDialog() diff --git a/include/wx/gtk/bitmap.h b/include/wx/gtk/bitmap.h index 9e37103fae..17ef650888 100644 --- a/include/wx/gtk/bitmap.h +++ b/include/wx/gtk/bitmap.h @@ -97,6 +97,7 @@ public: void SetWidth( int width ); void SetDepth( int depth ); void SetPixmap( GdkPixmap *pixmap ); + void SetBitmap( GdkBitmap *bitmap ); GdkPixmap *GetPixmap() const; GdkBitmap *GetBitmap() const; diff --git a/include/wx/gtk1/bitmap.h b/include/wx/gtk1/bitmap.h index 9e37103fae..17ef650888 100644 --- a/include/wx/gtk1/bitmap.h +++ b/include/wx/gtk1/bitmap.h @@ -97,6 +97,7 @@ public: void SetWidth( int width ); void SetDepth( int depth ); void SetPixmap( GdkPixmap *pixmap ); + void SetBitmap( GdkBitmap *bitmap ); GdkPixmap *GetPixmap() const; GdkBitmap *GetBitmap() const; diff --git a/include/wx/image.h b/include/wx/image.h index 893e272c2e..7f2b0904ea 100644 --- a/include/wx/image.h +++ b/include/wx/image.h @@ -101,6 +101,9 @@ public: wxImage( const wxBitmap &bitmap ); operator wxBitmap() const { return ConvertToBitmap(); } wxBitmap ConvertToBitmap() const; +#ifdef __WXGTK__ + wxBitmap ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue ); +#endif void Create( int width, int height ); void Destroy(); diff --git a/samples/image/image.cpp b/samples/image/image.cpp index e75e7177d4..86eed4733b 100644 --- a/samples/image/image.cpp +++ b/samples/image/image.cpp @@ -252,18 +252,46 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) if (my_smile_xbm && my_smile_xbm->Ok()) { dc.DrawText( "XBM bitmap", 30, 1745 ); - dc.SetPen( *wxRED_PEN ); + dc.SetTextForeground( "RED" ); + dc.SetTextBackground( "GREEN" ); dc.DrawBitmap( *my_smile_xbm, 30, 1760 ); dc.DrawText( "After wxImage conversion", 150, 1745 ); wxImage i( *my_smile_xbm ); - i.SetMaskColour( 0,0,0 ); - i.Replace( 255,255,255, + i.SetMaskColour( 0,0,0 ); + i.Replace( 255,255,255, wxRED_PEN->GetColour().Red(), wxRED_PEN->GetColour().Green(), wxRED_PEN->GetColour().Blue() ); dc.DrawBitmap( i.ConvertToBitmap(), 150, 1760, TRUE ); } + dc.SetTextForeground( "BLACK" ); + + wxBitmap mono( 30,30,1 ); + wxMemoryDC memdc; + memdc.SelectObject( mono ); + memdc.SetPen( *wxTRANSPARENT_PEN ); + memdc.SetBrush( *wxBLACK_BRUSH ); + memdc.DrawRectangle( 0,0,30,30 ); + memdc.SetBrush( *wxWHITE_BRUSH ); + memdc.DrawRectangle( 5,5,20,20 ); + memdc.SelectObject( wxNullBitmap ); + if (mono.Ok()) + { + dc.DrawText( "Mono bitmap", 30, 1845 ); + dc.SetTextForeground( "RED" ); + dc.SetTextBackground( "GREEN" ); + dc.DrawBitmap( mono, 30, 1860 ); + + dc.DrawText( "After wxImage conversion", 150, 1845 ); + wxImage i( mono ); + i.SetMaskColour( 0,0,0 ); + i.Replace( 255,255,255, + wxRED_PEN->GetColour().Red(), + wxRED_PEN->GetColour().Green(), + wxRED_PEN->GetColour().Blue() ); + dc.DrawBitmap( i.ConvertToBitmap(), 150, 1860, TRUE ); + } } void MyCanvas::CreateAntiAliasedBitmap() @@ -347,7 +375,7 @@ MyFrame::MyFrame() m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) ); // 500 width * 1900 height - m_canvas->SetScrollbars( 10, 10, 50, 190 ); + m_canvas->SetScrollbars( 10, 10, 50, 200 ); } void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) ) diff --git a/src/common/image.cpp b/src/common/image.cpp index 2f167850fc..3fa3751748 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -1311,6 +1311,104 @@ wxImage::wxImage( const wxBitmap &bitmap ) #include #endif +wxBitmap wxImage::ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue ) +{ + wxBitmap bitmap; + + wxCHECK_MSG( Ok(), bitmap, wxT("invalid image") ); + + int width = GetWidth(); + int height = GetHeight(); + + bitmap.SetHeight( height ); + bitmap.SetWidth( width ); + + bitmap.SetBitmap( gdk_pixmap_new( (GdkWindow*)&gdk_root_parent, width, height, 1 ) ); + + bitmap.SetDepth( 1 ); + + // Create picture image + + unsigned char *data_data = (unsigned char*)malloc( ((width >> 3)+8) * height ); + + GdkImage *data_image = + gdk_image_new_bitmap( gdk_visual_get_system(), data_data, width, height ); + + // Create mask image + + GdkImage *mask_image = (GdkImage*) NULL; + + if (HasMask()) + { + unsigned char *mask_data = (unsigned char*)malloc( ((width >> 3)+8) * height ); + + mask_image = gdk_image_new_bitmap( gdk_visual_get_system(), mask_data, width, height ); + + wxMask *mask = new wxMask(); + mask->m_bitmap = gdk_pixmap_new( (GdkWindow*)&gdk_root_parent, width, height, 1 ); + + bitmap.SetMask( mask ); + } + + int r_mask = GetMaskRed(); + int g_mask = GetMaskGreen(); + int b_mask = GetMaskBlue(); + + unsigned char* data = GetData(); + + int index = 0; + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++) + { + int r = data[index]; + index++; + int g = data[index]; + index++; + int b = data[index]; + index++; + + if (HasMask()) + { + if ((r == r_mask) && (b == b_mask) && (g == g_mask)) + gdk_image_put_pixel( mask_image, x, y, 1 ); + else + gdk_image_put_pixel( mask_image, x, y, 0 ); + } + + if ((r == red) && (b == blue) && (g == green)) + gdk_image_put_pixel( data_image, x, y, 1 ); + else + gdk_image_put_pixel( data_image, x, y, 0 ); + + } // for + } // for + + // Blit picture + + GdkGC *data_gc = gdk_gc_new( bitmap.GetBitmap() ); + + gdk_draw_image( bitmap.GetBitmap(), data_gc, data_image, 0, 0, 0, 0, width, height ); + + gdk_image_destroy( data_image ); + gdk_gc_unref( data_gc ); + + // Blit mask + + if (HasMask()) + { + GdkGC *mask_gc = gdk_gc_new( bitmap.GetMask()->GetBitmap() ); + + gdk_draw_image( bitmap.GetMask()->GetBitmap(), mask_gc, mask_image, 0, 0, 0, 0, width, height ); + + gdk_image_destroy( mask_image ); + gdk_gc_unref( mask_gc ); + } + + return bitmap; +} + + wxBitmap wxImage::ConvertToBitmap() const { wxBitmap bitmap; @@ -1428,14 +1526,6 @@ wxBitmap wxImage::ConvertToBitmap() const gdk_image_put_pixel( mask_image, x, y, 0 ); } - if (HasMask()) - { - if ((r == r_mask) && (b == b_mask) && (g == g_mask)) - gdk_image_put_pixel( mask_image, x, y, 1 ); - else - gdk_image_put_pixel( mask_image, x, y, 0 ); - } - switch (bpp) { case 8: diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 88a1477166..f28ec07794 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -513,6 +513,13 @@ void wxBitmap::SetPixmap( GdkPixmap *pixmap ) M_BMPDATA->m_pixmap = pixmap; } +void wxBitmap::SetBitmap( GdkPixmap *bitmap ) +{ + if (!m_refData) m_refData = new wxBitmapRefData(); + + M_BMPDATA->m_bitmap = bitmap; +} + GdkPixmap *wxBitmap::GetPixmap() const { wxCHECK_MSG( Ok(), (GdkPixmap *) NULL, wxT("invalid bitmap") ); diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 9248836046..be232b8848 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -500,6 +500,8 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, wxCHECK_RET( bitmap.Ok(), wxT("invalid bitmap") ); + bool is_mono = (bitmap.GetBitmap()); + /* scale/translate size and position */ int xx = XLOG2DEV(x); @@ -523,9 +525,11 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, if ((w != ww) || (h != hh)) { wxImage image( bitmap ); - image = image.Scale( ww, hh ); - - use_bitmap = image.ConvertToBitmap(); + image.Rescale( ww, hh ); + if (is_mono) + use_bitmap = image.ConvertToMonoBitmap(255,255,255); + else + use_bitmap = image.ConvertToBitmap(); } else { @@ -539,32 +543,39 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, if (useMask && mask) { - gdk_gc_set_clip_mask( m_penGC, mask ); - gdk_gc_set_clip_origin( m_penGC, xx, yy ); - } - - /* draw XPixmap or XBitmap, depending on what the wxBitmap contains */ - - GdkPixmap *pm = use_bitmap.GetPixmap(); - if (pm) - { - gdk_draw_pixmap( m_window, m_penGC, pm, 0, 0, xx, yy, -1, -1 ); - } - else - { - GdkBitmap *bm = use_bitmap.GetBitmap(); - if (bm) + if (is_mono) { - gdk_draw_bitmap( m_window, m_penGC, bm, 0, 0, xx, yy, -1, -1 ); + gdk_gc_set_clip_mask( m_textGC, mask ); + gdk_gc_set_clip_origin( m_textGC, xx, yy ); + } + else + { + gdk_gc_set_clip_mask( m_penGC, mask ); + gdk_gc_set_clip_origin( m_penGC, xx, yy ); } } + /* Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For + drawing a mono-bitmap (XBitmap) we use the current text GC */ + if (is_mono) + gdk_draw_bitmap( m_window, m_textGC, use_bitmap.GetBitmap(), 0, 0, xx, yy, -1, -1 ); + else + gdk_draw_pixmap( m_window, m_penGC, use_bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 ); + /* remove mask again if any */ if (useMask && mask) { - gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL ); - gdk_gc_set_clip_origin( m_penGC, 0, 0 ); + if (is_mono) + { + gdk_gc_set_clip_mask( m_textGC, (GdkBitmap *) NULL ); + gdk_gc_set_clip_origin( m_textGC, 0, 0 ); + } + else + { + gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL ); + gdk_gc_set_clip_origin( m_penGC, 0, 0 ); + } } } @@ -587,6 +598,7 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he wxMemoryDC *memDC = (wxMemoryDC*)source; bool use_bitmap_method = FALSE; + bool is_mono = FALSE; if (srcDC->m_isMemDC) { @@ -610,6 +622,7 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he /* we HAVE TO use the direct way for memory dcs that are bitmaps because XCopyArea doesn't cope with different bit depths */ + is_mono = TRUE; use_bitmap_method = TRUE; } else if ((xsrc == 0) && (ysrc == 0) && @@ -653,7 +666,10 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he wxImage image( memDC->m_selected ); image = image.Scale( bm_ww, bm_hh ); - use_bitmap = image.ConvertToBitmap(); + if (is_mono) + use_bitmap = image.ConvertToMonoBitmap(255,255,255); + else + use_bitmap = image.ConvertToBitmap(); } else { @@ -675,34 +691,39 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he if (useMask && mask) { - gdk_gc_set_clip_mask( m_penGC, mask ); - gdk_gc_set_clip_origin( m_penGC, xx, yy ); - } - - /* draw XPixmap or XBitmap, depending on what the wxBitmap contains */ - - GdkPixmap *pm = use_bitmap.GetPixmap(); - if (pm) - { - gdk_draw_pixmap( m_window, m_penGC, pm, xsrc, ysrc, xx, yy, ww, hh ); - } - else - { - GdkBitmap *bm = use_bitmap.GetBitmap(); - if (bm) + if (is_mono) + { + gdk_gc_set_clip_mask( m_textGC, mask ); + gdk_gc_set_clip_origin( m_textGC, xx, yy ); + } + else { - /* we use the textGC here because blitting a bitmap is done - using the current text colour */ - gdk_draw_bitmap( m_window, m_textGC, bm, xsrc, ysrc, xx, yy, ww, hh ); + gdk_gc_set_clip_mask( m_penGC, mask ); + gdk_gc_set_clip_origin( m_penGC, xx, yy ); } } + /* Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For + drawing a mono-bitmap (XBitmap) we use the current text GC */ + if (is_mono) + gdk_draw_bitmap( m_window, m_textGC, use_bitmap.GetBitmap(), xsrc, ysrc, xx, yy, ww, hh ); + else + gdk_draw_pixmap( m_window, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh ); + /* remove mask again if any */ if (useMask && mask) { - gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL ); - gdk_gc_set_clip_origin( m_penGC, 0, 0 ); + if (is_mono) + { + gdk_gc_set_clip_mask( m_textGC, (GdkBitmap *) NULL ); + gdk_gc_set_clip_origin( m_textGC, 0, 0 ); + } + else + { + gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL ); + gdk_gc_set_clip_origin( m_penGC, 0, 0 ); + } } } else /* use_bitmap_method */ diff --git a/src/gtk1/bitmap.cpp b/src/gtk1/bitmap.cpp index 88a1477166..f28ec07794 100644 --- a/src/gtk1/bitmap.cpp +++ b/src/gtk1/bitmap.cpp @@ -513,6 +513,13 @@ void wxBitmap::SetPixmap( GdkPixmap *pixmap ) M_BMPDATA->m_pixmap = pixmap; } +void wxBitmap::SetBitmap( GdkPixmap *bitmap ) +{ + if (!m_refData) m_refData = new wxBitmapRefData(); + + M_BMPDATA->m_bitmap = bitmap; +} + GdkPixmap *wxBitmap::GetPixmap() const { wxCHECK_MSG( Ok(), (GdkPixmap *) NULL, wxT("invalid bitmap") ); diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp index 9248836046..be232b8848 100644 --- a/src/gtk1/dcclient.cpp +++ b/src/gtk1/dcclient.cpp @@ -500,6 +500,8 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, wxCHECK_RET( bitmap.Ok(), wxT("invalid bitmap") ); + bool is_mono = (bitmap.GetBitmap()); + /* scale/translate size and position */ int xx = XLOG2DEV(x); @@ -523,9 +525,11 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, if ((w != ww) || (h != hh)) { wxImage image( bitmap ); - image = image.Scale( ww, hh ); - - use_bitmap = image.ConvertToBitmap(); + image.Rescale( ww, hh ); + if (is_mono) + use_bitmap = image.ConvertToMonoBitmap(255,255,255); + else + use_bitmap = image.ConvertToBitmap(); } else { @@ -539,32 +543,39 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, if (useMask && mask) { - gdk_gc_set_clip_mask( m_penGC, mask ); - gdk_gc_set_clip_origin( m_penGC, xx, yy ); - } - - /* draw XPixmap or XBitmap, depending on what the wxBitmap contains */ - - GdkPixmap *pm = use_bitmap.GetPixmap(); - if (pm) - { - gdk_draw_pixmap( m_window, m_penGC, pm, 0, 0, xx, yy, -1, -1 ); - } - else - { - GdkBitmap *bm = use_bitmap.GetBitmap(); - if (bm) + if (is_mono) { - gdk_draw_bitmap( m_window, m_penGC, bm, 0, 0, xx, yy, -1, -1 ); + gdk_gc_set_clip_mask( m_textGC, mask ); + gdk_gc_set_clip_origin( m_textGC, xx, yy ); + } + else + { + gdk_gc_set_clip_mask( m_penGC, mask ); + gdk_gc_set_clip_origin( m_penGC, xx, yy ); } } + /* Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For + drawing a mono-bitmap (XBitmap) we use the current text GC */ + if (is_mono) + gdk_draw_bitmap( m_window, m_textGC, use_bitmap.GetBitmap(), 0, 0, xx, yy, -1, -1 ); + else + gdk_draw_pixmap( m_window, m_penGC, use_bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 ); + /* remove mask again if any */ if (useMask && mask) { - gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL ); - gdk_gc_set_clip_origin( m_penGC, 0, 0 ); + if (is_mono) + { + gdk_gc_set_clip_mask( m_textGC, (GdkBitmap *) NULL ); + gdk_gc_set_clip_origin( m_textGC, 0, 0 ); + } + else + { + gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL ); + gdk_gc_set_clip_origin( m_penGC, 0, 0 ); + } } } @@ -587,6 +598,7 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he wxMemoryDC *memDC = (wxMemoryDC*)source; bool use_bitmap_method = FALSE; + bool is_mono = FALSE; if (srcDC->m_isMemDC) { @@ -610,6 +622,7 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he /* we HAVE TO use the direct way for memory dcs that are bitmaps because XCopyArea doesn't cope with different bit depths */ + is_mono = TRUE; use_bitmap_method = TRUE; } else if ((xsrc == 0) && (ysrc == 0) && @@ -653,7 +666,10 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he wxImage image( memDC->m_selected ); image = image.Scale( bm_ww, bm_hh ); - use_bitmap = image.ConvertToBitmap(); + if (is_mono) + use_bitmap = image.ConvertToMonoBitmap(255,255,255); + else + use_bitmap = image.ConvertToBitmap(); } else { @@ -675,34 +691,39 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he if (useMask && mask) { - gdk_gc_set_clip_mask( m_penGC, mask ); - gdk_gc_set_clip_origin( m_penGC, xx, yy ); - } - - /* draw XPixmap or XBitmap, depending on what the wxBitmap contains */ - - GdkPixmap *pm = use_bitmap.GetPixmap(); - if (pm) - { - gdk_draw_pixmap( m_window, m_penGC, pm, xsrc, ysrc, xx, yy, ww, hh ); - } - else - { - GdkBitmap *bm = use_bitmap.GetBitmap(); - if (bm) + if (is_mono) + { + gdk_gc_set_clip_mask( m_textGC, mask ); + gdk_gc_set_clip_origin( m_textGC, xx, yy ); + } + else { - /* we use the textGC here because blitting a bitmap is done - using the current text colour */ - gdk_draw_bitmap( m_window, m_textGC, bm, xsrc, ysrc, xx, yy, ww, hh ); + gdk_gc_set_clip_mask( m_penGC, mask ); + gdk_gc_set_clip_origin( m_penGC, xx, yy ); } } + /* Draw XPixmap or XBitmap, depending on what the wxBitmap contains. For + drawing a mono-bitmap (XBitmap) we use the current text GC */ + if (is_mono) + gdk_draw_bitmap( m_window, m_textGC, use_bitmap.GetBitmap(), xsrc, ysrc, xx, yy, ww, hh ); + else + gdk_draw_pixmap( m_window, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh ); + /* remove mask again if any */ if (useMask && mask) { - gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL ); - gdk_gc_set_clip_origin( m_penGC, 0, 0 ); + if (is_mono) + { + gdk_gc_set_clip_mask( m_textGC, (GdkBitmap *) NULL ); + gdk_gc_set_clip_origin( m_textGC, 0, 0 ); + } + else + { + gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL ); + gdk_gc_set_clip_origin( m_penGC, 0, 0 ); + } } } else /* use_bitmap_method */ -- 2.47.2