From 61b64bd92a02df762e59c368536b52d76516ce8c Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Wed, 6 Sep 2000 15:09:17 +0000 Subject: [PATCH] Added various missing bits to scrolling wxCanvas. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8275 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- contrib/include/wx/canvas/canvas.h | 1 + contrib/samples/canvas/test/test.cpp | 10 ++--- contrib/src/canvas/canvas.cpp | 59 +++++++++++++++++++++++++--- 3 files changed, 60 insertions(+), 10 deletions(-) diff --git a/contrib/include/wx/canvas/canvas.h b/contrib/include/wx/canvas/canvas.h index fb9b04f1b1..325d5dcfed 100644 --- a/contrib/include/wx/canvas/canvas.h +++ b/contrib/include/wx/canvas/canvas.h @@ -281,6 +281,7 @@ private: void OnIdle( wxIdleEvent &event ); void OnSetFocus( wxFocusEvent &event ); void OnKillFocus( wxFocusEvent &event ); + void OnEraseBackground( wxEraseEvent &event ); private: DECLARE_CLASS(wxCanvas) diff --git a/contrib/samples/canvas/test/test.cpp b/contrib/samples/canvas/test/test.cpp index 26e88ece40..2a555f6320 100644 --- a/contrib/samples/canvas/test/test.cpp +++ b/contrib/samples/canvas/test/test.cpp @@ -155,7 +155,7 @@ MyFrame::MyFrame() m_canvas = new wxCanvas( this, -1, wxPoint(0,0), wxSize(10,10) ); - m_canvas->SetArea( 400, 600 ); + m_canvas->SetArea( 1400, 600 ); m_canvas->SetColour( 255, 255, 255 ); wxBitmap bitmap( smile_xpm ); @@ -163,7 +163,7 @@ MyFrame::MyFrame() m_sm1 = new wxCanvasImage( image, 0,70,16,16 ); m_canvas->Append( m_sm1 ); - + int i; for (i = 10; i < 300; i+=10) m_canvas->Append( new wxCanvasRect( i,50,3,140, 255,0,0 ) ); @@ -186,12 +186,12 @@ MyFrame::MyFrame() for (i = 10; i < 300; i+=10) m_canvas->Append( new wxCanvasLine( 10,-15,i,300, 0,255,0 ) ); -// m_canvas->Append( new wxCanvasLine( 10,-1500e6,50,300000e6, 0,255,0 ) ); -// m_canvas->Append( new wxCanvasLine( 10,-150000,50,300000, 0,255,0 ) ); - m_sm4 = new MywxCanvasImage( image, 0,270,64,32 ); m_canvas->Append( m_sm4 ); +// m_canvas->Append( new wxCanvasLine( 10,-1500e6,50,300000e6, 0,255,0 ) ); +// m_canvas->Append( new wxCanvasLine( 10,-150000,50,300000, 0,255,0 ) ); + m_log = new wxTextCtrl( this, -1, "", wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE ); wxLog *old_log = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) ); delete old_log; diff --git a/contrib/src/canvas/canvas.cpp b/contrib/src/canvas/canvas.cpp index c5a21e10ff..14bdeb0fe4 100644 --- a/contrib/src/canvas/canvas.cpp +++ b/contrib/src/canvas/canvas.cpp @@ -218,7 +218,7 @@ void wxCanvasLine::Render( int clip_x, int clip_y, int clip_width, int clip_heig wxImage *image = m_owner->GetBuffer(); int buffer_x = m_owner->GetBufferX(); int buffer_y = m_owner->GetBufferY(); - + if ((m_area.width == 0) && (m_area.height == 0)) { image->SetRGB( m_area.x-buffer_x, m_area.y-buffer_y, m_red, m_green, m_blue ); @@ -248,8 +248,8 @@ void wxCanvasLine::Render( int clip_x, int clip_y, int clip_width, int clip_heig while (ii != x1) { - if ((ii >= clip_x) && (ii <= clip_x+clip_width) && - (jj >= clip_y) && (jj <= clip_y+clip_height)) + if ((ii >= clip_x) && (ii < clip_x+clip_width) && + (jj >= clip_y) && (jj < clip_y+clip_height)) { image->SetRGB( ii-buffer_x, jj-buffer_y, m_red, m_blue, m_green ); } @@ -269,8 +269,8 @@ void wxCanvasLine::Render( int clip_x, int clip_y, int clip_width, int clip_heig while (jj != y1) { - if ((ii >= clip_x) && (ii <= clip_x+clip_width) && - (jj >= clip_y) && (jj <= clip_y+clip_height)) + if ((ii >= clip_x) && (ii < clip_x+clip_width) && + (jj >= clip_y) && (jj < clip_y+clip_height)) { image->SetRGB( ii-buffer_x, jj-buffer_y, m_red, m_blue, m_green ); } @@ -555,6 +555,7 @@ BEGIN_EVENT_TABLE(wxCanvas,wxScrolledWindow) EVT_MOUSE_EVENTS( wxCanvas::OnMouse ) EVT_SET_FOCUS( wxCanvas::OnSetFocus ) EVT_KILL_FOCUS( wxCanvas::OnKillFocus ) + EVT_ERASE_BACKGROUND( wxCanvas::OnEraseBackground ) END_EVENT_TABLE() wxCanvas::wxCanvas( wxWindow *parent, wxWindowID id, @@ -597,6 +598,8 @@ void wxCanvas::SetColour( unsigned char red, unsigned char green, unsigned char m_green = green; m_blue = blue; + SetBackgroundColour( wxColour( red, green, blue ) ); + if (m_frozen) return; unsigned char *data = m_buffer.GetData(); @@ -803,6 +806,8 @@ void wxCanvas::BlitBuffer( wxDC &dc ) void wxCanvas::UpdateNow() { + if (m_frozen) return; + if (!m_needUpdate) return; wxClientDC dc( this ); @@ -928,8 +933,12 @@ void wxCanvas::OnPaint(wxPaintEvent &event) void wxCanvas::ScrollWindow( int dx, int dy, const wxRect* rect ) { + // If any updates are pending, do them now since they will + // expect the previous m_bufferX and m_bufferY values. UpdateNow(); + // The buffer always starts at the top left corner of the + // client area. Indeed, it is the client area. CalcUnscrolledPosition( 0, 0, &m_bufferX, &m_bufferY ); unsigned char* data = m_buffer.GetData(); @@ -943,6 +952,9 @@ void wxCanvas::ScrollWindow( int dx, int dy, const wxRect* rect ) size_t count = (size_t) (m_buffer.GetWidth() * 3 * (m_buffer.GetHeight()-dy)); memmove( dest, source, count ); + // We update the new buffer area, but there is no need to + // blit (last param FALSE) since the ensuing paint event will + // do that anyway. Update( m_bufferX, m_bufferY, m_buffer.GetWidth(), dy, FALSE ); } else @@ -952,12 +964,45 @@ void wxCanvas::ScrollWindow( int dx, int dy, const wxRect* rect ) size_t count = (size_t) (m_buffer.GetWidth() * 3 * (m_buffer.GetHeight()+dy)); memmove( dest, source, count ); + // We update the new buffer area, but there is no need to + // blit (last param FALSE) since the ensuing paint event will + // do that anyway. Update( m_bufferX, m_bufferY+m_buffer.GetHeight()+dy, m_buffer.GetWidth(), -dy, FALSE ); } } if (dx != 0) { + if (dx > 0) + { + unsigned char *source = data; + for (int y = 0; y < m_buffer.GetHeight(); y++) + { + unsigned char *dest = source + dx*3; + memmove( dest, source, (m_buffer.GetWidth()-dx) * 3 ); + source += m_buffer.GetWidth()*3; + } + + // We update the new buffer area, but there is no need to + // blit (last param FALSE) since the ensuing paint event will + // do that anyway. + Update( m_bufferX, m_bufferY, dx, m_buffer.GetHeight(), FALSE ); + } + else + { + unsigned char *dest = data; + for (int y = 0; y < m_buffer.GetHeight(); y++) + { + unsigned char *source = dest - dx*3; + memmove( dest, source, (m_buffer.GetWidth()+dx) * 3 ); + dest += m_buffer.GetWidth()*3; + } + + // We update the new buffer area, but there is no need to + // blit (last param FALSE) since the ensuing paint event will + // do that anyway. + Update( m_bufferX+m_buffer.GetWidth()+dx, m_bufferY, -dx, m_buffer.GetHeight(), FALSE ); + } } wxWindow::ScrollWindow( dx, dy, rect ); @@ -1096,6 +1141,10 @@ void wxCanvas::OnChar(wxKeyEvent &event) event.Skip(); } +void wxCanvas::OnEraseBackground(wxEraseEvent &event) +{ +} + //-------------------------------------------------------------------- // wxCanvasModule //-------------------------------------------------------------------- -- 2.47.2