int wxImageList::Add( const wxBitmap &bitmap ) { wxASSERT_MSG( (bitmap.GetScaledWidth() >= m_width && bitmap.GetScaledHeight() == m_height) || (m_width == 0 && m_height == 0), wxT("invalid bitmap size in wxImageList: this might work ") wxT("on this platform but definitely won't under Windows.") ); // Mimic behaviour of Windows ImageList_Add that automatically breaks up the added // bitmap into sub-images of the correct size if (m_width > 0 && bitmap.GetScaledWidth() > m_width && bitmap.GetScaledHeight() >= m_height) { int numImages = bitmap.GetScaledWidth() / m_width; for (int subIndex = 0; subIndex < numImages; subIndex++) { wxRect rect(m_width * subIndex, 0, m_width, m_height); wxBitmap tmpBmp = bitmap.GetSubBitmap(rect); m_images.Append( new wxBitmap(tmpBmp) ); } } else { m_images.Append( new wxBitmap(bitmap) ); } if (m_width == 0 && m_height == 0) { m_width = bitmap.GetScaledWidth(); m_height = bitmap.GetScaledHeight(); } return m_images.GetCount() - 1; }
void wxGCDCImpl::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask ) { wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid DC") ); wxCHECK_RET( bmp.IsOk(), wxT("wxGCDC(cg)::DoDrawBitmap - invalid bitmap") ); int w = bmp.GetScaledWidth(); int h = bmp.GetScaledHeight(); if ( bmp.GetDepth() == 1 ) { m_graphicContext->SetPen(*wxTRANSPARENT_PEN); m_graphicContext->SetBrush(m_textBackgroundColour); m_graphicContext->DrawRectangle( x, y, w, h ); m_graphicContext->SetBrush(m_textForegroundColour); m_graphicContext->DrawBitmap( bmp, x, y, w, h ); m_graphicContext->SetBrush( m_graphicContext->CreateBrush(m_brush)); m_graphicContext->SetPen( m_graphicContext->CreatePen(m_pen)); } else // not a monochrome bitmap, handle it normally { // make a copy in case we need to remove its mask, if we don't modify // it the copy is cheap as bitmaps are reference-counted wxBitmap bmpCopy(bmp); if ( !useMask && bmp.GetMask() ) bmpCopy.SetMask(NULL); m_graphicContext->DrawBitmap( bmpCopy, x, y, w, h ); } CalcBoundingBox(x, y); CalcBoundingBox(x + w, y + h); }
void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap ) { if ( m_selected.IsOk() ) { m_selected.EndRawAccess() ; wxDELETE(m_graphicContext); } m_selected = bitmap; if (m_selected.IsOk()) { if ( m_selected.GetDepth() != 1 ) m_selected.UseAlpha() ; m_selected.BeginRawAccess() ; m_width = bitmap.GetScaledWidth(); m_height = bitmap.GetScaledHeight(); m_contentScaleFactor = bitmap.GetScaleFactor(); CGColorSpaceRef genericColorSpace = wxMacGetGenericRGBColorSpace(); CGContextRef bmCtx = (CGContextRef) m_selected.GetHBITMAP(); if ( bmCtx ) { CGContextSetFillColorSpace( bmCtx, genericColorSpace ); CGContextSetStrokeColorSpace( bmCtx, genericColorSpace ); SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx ) ); } m_ok = (m_graphicContext != NULL) ; } else { m_ok = false; } }