X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ecab4dba7d33782458d7cc8b91c981d03d7b9e37..37e2cb08cd1910ec5a14b38f0addfc6e2e8e172e:/samples/scrollsub/scrollsub.cpp diff --git a/samples/scrollsub/scrollsub.cpp b/samples/scrollsub/scrollsub.cpp index da86fbb5ac..954eb7e5cc 100644 --- a/samples/scrollsub/scrollsub.cpp +++ b/samples/scrollsub/scrollsub.cpp @@ -154,8 +154,8 @@ MyCanvas::MyCanvas( wxScrolledWindow *parent, wxWindowID id, { m_owner = parent; - (void)new wxButton( this, -1, "Hallo I", wxPoint(20,20), wxSize(100,30) ); - (void)new wxButton( this, -1, "Hallo II", wxPoint(220,20), wxSize(100,30) ); + (void)new wxButton( this, -1, "Hallo I", wxPoint(0,50), wxSize(100,25) ); + (void)new wxButton( this, -1, "Hallo II", wxPoint(200,50), wxSize(100,25) ); SetBackgroundColour( *wxWHITE ); @@ -171,13 +171,57 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) wxPaintDC dc( this ); m_owner->PrepareDC( dc ); - dc.DrawText( "Some text", 140, 140 ); - - dc.DrawRectangle( 100, 160, 200, 200 ); + dc.SetPen( *wxBLACK_PEN ); + + // OK, let's assume we are a grid control and we have two + // grid cells. Here in OnPaint we want to know which cell + // to redraw so that we prevent redrawing cells that don't + // need to get redrawn. We have one cell at (0,0) and one + // more at (200,0), both having a size of (100,25). + + // We can query how much the window has been scrolled + // by calling CalcUnscrolledPosition() + + int scroll_x = 0; + int scroll_y = 0; + m_owner->CalcUnscrolledPosition( scroll_x, scroll_y, &scroll_x, &scroll_y ); + + // We also need to know the size of the window to see which + // cells are completely hidden and not get redrawn + + int size_x = 0; + int size_y = 0; + GetClientSize( &size_x, &size_y ); + + // First cell: (0,0)(100,25) + // It it on screen? + if ((0+100-scroll_x > 0) && (0+25-scroll_y > 0) && + (0-scroll_x < size_x) && (0-scroll_y < size_y)) + { + // Has the region an screen been exposed? + if (IsExposed(0,0,100,25)) + { + wxLogMessage( "Redraw first cell" ); + dc.DrawRectangle( 0, 0, 100, 25 ); + dc.DrawText( "First Cell", 5, 5 ); + } + } + - dc.SetBrush( *wxTRANSPARENT_BRUSH ); + // Second cell: (0,200)(100,25) + // It it on screen? + if ((200+100-scroll_x > 0) && (0+25-scroll_y > 0) && + (200-scroll_x < size_x) && (0-scroll_y < size_y)) + { + // Has the region an screen been exposed? + if (IsExposed(200,0,100,25)) + { + wxLogMessage( "Redraw second cell" ); + dc.DrawRectangle( 200, 0, 100, 25 ); + dc.DrawText( "Second Cell", 205, 5 ); + } + } - dc.DrawRectangle( 10, 10, 480, 980 ); }