[wx2.8.0, wxGTK, gcc4.1.2] wxDC::Blit() and wxMask again

Vadim Zeitlin vadim at wxwindows.org
Mon Jan 29 16:05:28 PST 2007


On Mon, 29 Jan 2007 14:45:33 +0100 Kövesdi György <kgy at deverto.hu> wrote:

KG> I tried it, now the source is:
KG> 
KG>          wxMemoryDC mdc;
KG>          wxBitmap bm(100, 100);
KG>          mdc.SelectObject(bm);
KG>          mdc.SetBackground(*wxBLUE_BRUSH);
KG>          mdc.Clear();
KG>          mdc.SelectObject(wxNullBitmap);
KG>          bm.SetMask(new wxMask(bm, *wxBLUE));
KG>          mdc.SelectObject(bm);
KG>          mdc.SetPen(wxPen(wxColour(0, 0, 0), 8));
KG>          mdc.DrawLine(5, 5, 20, 20);
KG> 
KG>          wxBitmap bm2(100, 100);
KG>          wxMemoryDC dc2;
KG>          dc2.SelectObject(bm2);
KG>          dc2.SetBackground(*wxGREEN_BRUSH);
KG>          dc2.Clear();
KG>          dc2.Blit(0, 0, 100, 100, &mdc, 0, 0, wxCOPY, true);
KG>          dc2.SelectObject(wxNullBitmap);
KG>          mdc.SelectObject(wxNullBitmap);
KG> 
KG>          (void)new wxStaticBitmap(panel, wxID_ANY, bm2, wxPoint(300, 120));
KG> 
KG> Now, nothing copied in the Blit() function (the picture is full green).

 This makes sense: the colour of the mask is used when creating it, not
when blitting. And when it's created, the entire bitmap is blue so
everything is indeed masked.

KG> In my mind the mask sould be created just before the Blit() function call,  

 Why? I.e. how is bitmap supposed to know about it?

KG> but the whole bitmap is copied in that case (without mask).

 Here is the code which does what I think you want to do:

    wxMemoryDC mdc;
    wxBitmap bm(100, 100);
    mdc.SelectObject(bm);
    mdc.SetBackground(*wxBLUE_BRUSH);
    mdc.Clear();
    mdc.SetPen(wxPen(wxColour(0, 0, 0), 8));
    mdc.DrawLine(5, 5, 20, 20);
    mdc.SelectObject(wxNullBitmap);
    bm.SetMask(new wxMask(bm, *wxBLUE));
    mdc.SelectObject(bm);

    wxBitmap bm2(100, 100);
    wxMemoryDC dc2;
    dc2.SelectObject(bm2);
    dc2.SetBackground(*wxGREEN_BRUSH);
    dc2.Clear();
    dc2.Blit(0, 0, 100, 100, &mdc, 0, 0, wxCOPY, true);
    dc2.SelectObject(wxNullBitmap);
    mdc.SelectObject(wxNullBitmap);

 Regards,
VZ

-- 
TT-Solutions: wxWidgets consultancy and technical support
               http://www.tt-solutions.com/





More information about the wx-users mailing list