Here is my paint event code:
Code: Select all
void ColorList::ColorList_Paint(wxPaintEvent& event)
{
wxAutoBufferedPaintDC dc(this);
this->DoPrepareDC(dc);
auto* gc = wxGraphicsContext::Create(dc);
auto size = this->GetVirtualSize();
gc->SetBrush(wxTheColourDatabase->Find("WHITE"));
gc->SetPen(wxTheColourDatabase->Find("WHITE"));
gc->DrawRectangle(0, 0, size.GetWidth(), size.GetHeight());
auto actualSize = this->GetClientSize();
auto viewStart = this->GetViewStart();
gc->SetPen(wxTheColourDatabase->Find("BLACK"));
for (auto i = 0; i < this->colors.size(); i++)
{
auto drawX = 5;
auto drawY = 5 + this->itemHeight * i;
auto drawWidth = size.GetWidth() - 10;
auto drawHeight = this->itemHeight - 10;
// if ((drawY < viewStart.y * this->itemHeight) || (drawY + drawHeight > viewStart.y * this->itemHeight + actualSize.GetHeight()))
// {
// continue;
// }
gc->SetBrush(this->colors[i]);
gc->DrawRectangle(drawX, drawY, drawWidth, drawHeight);
}
delete gc;
}
What is the proper way to only draw the items that are completely visible within the scroll view?