]> git.saurik.com Git - wxWidgets.git/commitdiff
Changed scrollsub sample.
authorRobert Roebling <robert@roebling.de>
Thu, 9 Dec 1999 15:01:04 +0000 (15:01 +0000)
committerRobert Roebling <robert@roebling.de>
Thu, 9 Dec 1999 15:01:04 +0000 (15:01 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4887 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/scrollsub/scrollsub.cpp

index d1e09ec23e6f12136c514a40de0f142d40804ecf..0c341aa85fd3355fe2032b36b3a38f4439154de2 100644 (file)
@@ -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 );
   
@@ -173,13 +173,55 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
 
     dc.SetPen( *wxBLACK_PEN );
     
-    dc.DrawText( "Some text", 140, 140 );
-
-    dc.DrawRectangle( 100, 160, 200, 200 );
+    // 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))
+       {
+           printf( "Redraw first cell\n" );
+            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))
+       {
+           printf( "Redraw second cell\n" );
+            dc.DrawRectangle( 200, 0, 100, 25 );
+           dc.DrawText( "Second Cell", 205, 5 );
+       }
+    }
     
-    dc.DrawRectangle( 10, 10, 480, 980 );
 }