wxFillSolidRect + wxFloodFillSolid

If you have a cool piece of software to share, but you are not hosting it officially yet, please dump it in here. If you have code snippets that are useful, please donate!
Post Reply
Troels
Experienced Solver
Experienced Solver
Posts: 79
Joined: Fri Jan 07, 2005 12:02 pm
Location: Denmark

wxFillSolidRect + wxFloodFillSolid

Post by Troels » Wed Jun 17, 2009 10:23 pm

It gets to be a nuisance to dabble with brushes when all you want is a solid wxColour. The api for drawing rectangles and especially the api for doing a flood fill are cumbersome and bound to be timewasters to everybody. Taketh away :-)

http://trac.wxwidgets.org/ticket/10904

Code: Select all

void wxFillSolidRect(wxDC* dc, const wxRect& rect, const wxColour& color)
{
   wxPen pen(color, 1, wxSOLID);
   wxBrush brush(color, wxSOLID);
   dc->SetBrush(brush);
   dc->SetPen(pen);
   dc->DrawRectangle(rect);
   dc->SetPen(wxNullPen);
   dc->SetBrush(wxNullBrush);
}

bool wxFloodFillSolid(wxDC* dc, const wxPoint& pt, const wxColour& clr)
{
   wxBrush br(clr, wxSOLID);
   dc->SetBrush(br);

   wxColour sample;
   bool ok = dc->GetPixel(pt.x, pt.y, &sample);
   if (ok)
   {
      ok = dc->FloodFill(pt.x, pt.y, sample);
   }
   dc->SetBrush(wxNullBrush);
   return ok;
}

Post Reply