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
This commit is contained in:
Robert Roebling 1999-12-23 18:18:43 +00:00
parent 8eb2940f7f
commit 17bec151f9
6 changed files with 95 additions and 5 deletions

View File

@ -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 );

View File

@ -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 );

View File

@ -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 );

View File

@ -225,11 +225,12 @@ void wxDirCtrl::CreateItems(const wxTreeItemId &parent)
for (unsigned int i=0; i<m_paths.Count(); i++)
{
dir_item = new wxDirItemData(m_paths[i],m_names[i]);
dir_item = new wxDirItemData(m_paths[i],m_names[i]);
#ifdef __WXMSW__
id = AppendItem( parent, m_names[i], -1, -1, dir_item);
id = AppendItem( parent, m_names[i], -1, -1, dir_item);
#else
id = AppendItem( parent, m_names[i], 0, 1, dir_item);
id = AppendItem( parent, m_names[i], 0, -1, dir_item);
SetItemImage( id, 1, wxTreeItemIcon_Expanded );
#endif
if (dir_item->m_hasSubDirs) SetItemHasChildren(id);
}

View File

@ -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") );

View File

@ -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") );