From 17bec151f9ae5d715023889377ee6979fb887d4a Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Thu, 23 Dec 1999 18:18:43 +0000 Subject: [PATCH] Added wxBitmap::GetSubBitmap() Correct images in gen. dir dlg. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5084 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/bitmap.h | 2 ++ include/wx/gtk1/bitmap.h | 2 ++ samples/image/image.cpp | 11 +++++++++-- src/generic/dirdlgg.cpp | 7 ++++--- src/gtk/bitmap.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/gtk1/bitmap.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 95 insertions(+), 5 deletions(-) diff --git a/include/wx/gtk/bitmap.h b/include/wx/gtk/bitmap.h index 2917413d43..9e37103fae 100644 --- a/include/wx/gtk/bitmap.h +++ b/include/wx/gtk/bitmap.h @@ -80,6 +80,8 @@ public: wxMask *GetMask() const; void SetMask( wxMask *mask ); + + wxBitmap GetSubBitmap( const wxRect& rect ) const; bool SaveFile( const wxString &name, int type, wxPalette *palette = (wxPalette *) NULL ); bool LoadFile( const wxString &name, int type = wxBITMAP_TYPE_XPM ); diff --git a/include/wx/gtk1/bitmap.h b/include/wx/gtk1/bitmap.h index 2917413d43..9e37103fae 100644 --- a/include/wx/gtk1/bitmap.h +++ b/include/wx/gtk1/bitmap.h @@ -80,6 +80,8 @@ public: wxMask *GetMask() const; void SetMask( wxMask *mask ); + + wxBitmap GetSubBitmap( const wxRect& rect ) const; bool SaveFile( const wxString &name, int type, wxPalette *palette = (wxPalette *) NULL ); bool LoadFile( const wxString &name, int type = wxBITMAP_TYPE_XPM ); diff --git a/samples/image/image.cpp b/samples/image/image.cpp index c9985fad5e..6d63802c5f 100644 --- a/samples/image/image.cpp +++ b/samples/image/image.cpp @@ -212,10 +212,17 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) dc.SetPen( *wxWHITE_PEN ); dc.DrawRectangle( 150, 30, 100, 100 ); - if (my_anti && my_anti->Ok()) dc.DrawBitmap( *my_anti, 250, 140 ); + if (my_anti && my_anti->Ok()) dc.DrawBitmap( *my_anti, 280, 30 ); dc.DrawText( "PNG handler", 30, 135 ); - if (my_horse_png && my_horse_png->Ok()) dc.DrawBitmap( *my_horse_png, 30, 150 ); + if (my_horse_png && my_horse_png->Ok()) + { + dc.DrawBitmap( *my_horse_png, 30, 150 ); + wxRect rect(0,0,100,100); + wxBitmap sub( my_horse_png->GetSubBitmap(rect) ); + dc.DrawText( "GetSubBitmap()", 280, 190 ); + dc.DrawBitmap( sub, 280, 210 ); + } dc.DrawText( "JPEG handler", 30, 365 ); if (my_horse_jpeg && my_horse_jpeg->Ok()) dc.DrawBitmap( *my_horse_jpeg, 30, 380 ); diff --git a/src/generic/dirdlgg.cpp b/src/generic/dirdlgg.cpp index d5b8014cbf..ba118204be 100644 --- a/src/generic/dirdlgg.cpp +++ b/src/generic/dirdlgg.cpp @@ -225,11 +225,12 @@ void wxDirCtrl::CreateItems(const wxTreeItemId &parent) for (unsigned int i=0; im_hasSubDirs) SetItemHasChildren(id); } diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 572a176c3b..919af2c170 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -366,6 +366,45 @@ void wxBitmap::SetMask( wxMask *mask ) M_BMPDATA->m_mask = mask; } +wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const +{ + wxCHECK_MSG( Ok() && + (rect.x >= 0) && (rect.y >= 0) && + (rect.x+rect.width <= M_BMPDATA->m_width) && (rect.y+rect.height <= M_BMPDATA->m_height), + wxNullBitmap, wxT("invalid bitmap or bitmap region") ); + + wxBitmap ret( rect.width, rect.height, M_BMPDATA->m_bpp ); + wxASSERT_MSG( ret.Ok(), wxT("GetSubBitmap error") ); + + if (ret.GetPixmap()) + { + GdkGC *gc = gdk_gc_new( ret.GetPixmap() ); + gdk_draw_pixmap( ret.GetPixmap(), gc, GetPixmap(), rect.x, rect.y, 0, 0, rect.width, rect.height ); + gdk_gc_destroy( gc ); + } + else + { + GdkGC *gc = gdk_gc_new( ret.GetBitmap() ); + gdk_draw_bitmap( ret.GetBitmap(), gc, GetBitmap(), rect.x, rect.y, 0, 0, rect.width, rect.height ); + gdk_gc_destroy( gc ); + } + + if (GetMask()) + { + wxMask *mask = new wxMask; + GdkWindow *parent = (GdkWindow*) &gdk_root_parent; + mask->m_bitmap = gdk_pixmap_new( parent, rect.width, rect.height, 1 ); + + GdkGC *gc = gdk_gc_new( mask->m_bitmap ); + gdk_draw_bitmap( mask->m_bitmap, gc, M_BMPDATA->m_mask->m_bitmap, 0, 0, rect.x, rect.y, rect.width, rect.height ); + gdk_gc_destroy( gc ); + + ret.SetMask( mask ); + } + + return ret; +} + bool wxBitmap::SaveFile( const wxString &name, int type, wxPalette *WXUNUSED(palette) ) { wxCHECK_MSG( Ok(), FALSE, wxT("invalid bitmap") ); diff --git a/src/gtk1/bitmap.cpp b/src/gtk1/bitmap.cpp index 572a176c3b..919af2c170 100644 --- a/src/gtk1/bitmap.cpp +++ b/src/gtk1/bitmap.cpp @@ -366,6 +366,45 @@ void wxBitmap::SetMask( wxMask *mask ) M_BMPDATA->m_mask = mask; } +wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const +{ + wxCHECK_MSG( Ok() && + (rect.x >= 0) && (rect.y >= 0) && + (rect.x+rect.width <= M_BMPDATA->m_width) && (rect.y+rect.height <= M_BMPDATA->m_height), + wxNullBitmap, wxT("invalid bitmap or bitmap region") ); + + wxBitmap ret( rect.width, rect.height, M_BMPDATA->m_bpp ); + wxASSERT_MSG( ret.Ok(), wxT("GetSubBitmap error") ); + + if (ret.GetPixmap()) + { + GdkGC *gc = gdk_gc_new( ret.GetPixmap() ); + gdk_draw_pixmap( ret.GetPixmap(), gc, GetPixmap(), rect.x, rect.y, 0, 0, rect.width, rect.height ); + gdk_gc_destroy( gc ); + } + else + { + GdkGC *gc = gdk_gc_new( ret.GetBitmap() ); + gdk_draw_bitmap( ret.GetBitmap(), gc, GetBitmap(), rect.x, rect.y, 0, 0, rect.width, rect.height ); + gdk_gc_destroy( gc ); + } + + if (GetMask()) + { + wxMask *mask = new wxMask; + GdkWindow *parent = (GdkWindow*) &gdk_root_parent; + mask->m_bitmap = gdk_pixmap_new( parent, rect.width, rect.height, 1 ); + + GdkGC *gc = gdk_gc_new( mask->m_bitmap ); + gdk_draw_bitmap( mask->m_bitmap, gc, M_BMPDATA->m_mask->m_bitmap, 0, 0, rect.x, rect.y, rect.width, rect.height ); + gdk_gc_destroy( gc ); + + ret.SetMask( mask ); + } + + return ret; +} + bool wxBitmap::SaveFile( const wxString &name, int type, wxPalette *WXUNUSED(palette) ) { wxCHECK_MSG( Ok(), FALSE, wxT("invalid bitmap") ); -- 2.45.2