X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/45da7759b82ec09ade8236a17f822dc54c5e5483..9c05a3ca23d9746639884ff57236758ff7a0d974:/contrib/src/fl/newbmpbtn.cpp diff --git a/contrib/src/fl/newbmpbtn.cpp b/contrib/src/fl/newbmpbtn.cpp index b811e40c12..138e9cf1c6 100644 --- a/contrib/src/fl/newbmpbtn.cpp +++ b/contrib/src/fl/newbmpbtn.cpp @@ -27,6 +27,10 @@ #include "wx/fl/newbmpbtn.h" #include "wx/utils.h" // import wxMin,wxMax macros +#ifdef __WXMSW__ +#include "wx/msw/private.h" +#endif + ///////////// button-label rendering helpers ////////////////// static int* create_array( int width, int height, int fill = 0 ) @@ -516,7 +520,14 @@ void wxNewBitmapButton::RenderLabelImage( wxBitmap*& destBmp, wxBitmap* srcBmp, destBmp->GetHeight() + mMarginY*2, 0 ); } + destDc.SelectObject( wxNullBitmap ); + +#ifdef __WXMSW__ + // Map to system colours + (void) MapBitmap(destBmp->GetHBITMAP(), destBmp->GetWidth(), destBmp->GetHeight()); +#endif } + void wxNewBitmapButton::RenderAllLabelImages() { if ( !mIsCreated ) @@ -802,3 +813,49 @@ void wxNewBitmapButton::OnKillFocus( wxFocusEvent& event ) wxMessageBox("kill-focus for button!"); } +#ifdef __WXMSW__ +WXHBITMAP wxNewBitmapButton::MapBitmap(WXHBITMAP bitmap, int width, int height) +{ + MemoryHDC hdcMem; + + if ( !hdcMem ) + { + wxLogLastError(_T("CreateCompatibleDC")); + + return bitmap; + } + + SelectInHDC bmpInHDC(hdcMem, (HBITMAP)bitmap); + + if ( !bmpInHDC ) + { + wxLogLastError(_T("SelectObject")); + + return bitmap; + } + + wxCOLORMAP *cmap = wxGetStdColourMap(); + + for ( int i = 0; i < width; i++ ) + { + for ( int j = 0; j < height; j++ ) + { + COLORREF pixel = ::GetPixel(hdcMem, i, j); + + for ( size_t k = 0; k < wxSTD_COL_MAX; k++ ) + { + COLORREF col = cmap[k].from; + if ( abs(GetRValue(pixel) - GetRValue(col)) < 10 && + abs(GetGValue(pixel) - GetGValue(col)) < 10 && + abs(GetBValue(pixel) - GetBValue(col)) < 10 ) + { + ::SetPixel(hdcMem, i, j, cmap[k].to); + break; + } + } + } + } + + return bitmap; +} +#endif