From 27d1065d3874e6102df25d113c5c1323b931755f Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Thu, 14 Sep 2000 06:42:27 +0000 Subject: [PATCH] Compilation fixes, bug fixes and streamlining in wxCanvas. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8357 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- contrib/include/wx/canvas/canvas.h | 32 ++++++++++---------- contrib/samples/canvas/test/test.cpp | 12 +++++--- contrib/src/canvas/canvas.cpp | 44 +++++++++++++--------------- 3 files changed, 45 insertions(+), 43 deletions(-) diff --git a/contrib/include/wx/canvas/canvas.h b/contrib/include/wx/canvas/canvas.h index 3c12ffa079..4c055e89e5 100644 --- a/contrib/include/wx/canvas/canvas.h +++ b/contrib/include/wx/canvas/canvas.h @@ -181,10 +181,10 @@ protected: class wxCanvasPolygon: public wxCanvasObject { public: - wxCanvasPolygon(int n, wxPoint2DDouble points[]); + wxCanvasPolygon( int n, wxPoint2DDouble points[] ); ~wxCanvasPolygon(); - SetBrush(wxBrush& brush){m_brush = brush;}; - SetPen(wxPen& pen){m_pen = pen;}; + void SetBrush(wxBrush& brush) { m_brush = brush; }; + void SetPen(wxPen& pen) { m_pen = pen; }; virtual void Recreate(); @@ -218,7 +218,7 @@ class wxCanvasPolyline: public wxCanvasObject public: wxCanvasPolyline(int n, wxPoint2DDouble points[]); ~wxCanvasPolyline(); - SetPen(wxPen& pen){m_pen = pen;}; + void SetPen(wxPen& pen) { m_pen = pen; }; virtual void Recreate(); @@ -251,8 +251,9 @@ private: class wxCanvasRect: public wxCanvasObject { public: - wxCanvasRect( double x, double y, double w, double h, - unsigned char red, unsigned char green, unsigned char blue ); + wxCanvasRect( double x, double y, double w, double h ); + void SetBrush(wxBrush& brush) { m_brush = brush; }; + void SetPen(wxPen& pen) { m_pen = pen; }; virtual void Recreate(); @@ -260,14 +261,13 @@ public: virtual void WriteSVG( wxTextOutputStream &stream ); private: + wxPen m_pen; + wxBrush m_brush; + double m_x; double m_y; double m_width; double m_height; - - unsigned char m_red; - unsigned char m_green; - unsigned char m_blue; }; //---------------------------------------------------------------------------- @@ -277,8 +277,8 @@ private: class wxCanvasLine: public wxCanvasObject { public: - wxCanvasLine( double x1, double y1, double x2, double y2, - unsigned char red, unsigned char green, unsigned char blue ); + wxCanvasLine( double x1, double y1, double x2, double y2 ); + void SetPen(wxPen& pen) { m_pen = pen; }; virtual void Recreate(); @@ -286,14 +286,12 @@ public: virtual void WriteSVG( wxTextOutputStream &stream ); private: + wxPen m_pen; + double m_x1; double m_y1; double m_x2; double m_y2; - - unsigned char m_red; - unsigned char m_green; - unsigned char m_blue; }; //---------------------------------------------------------------------------- @@ -449,6 +447,8 @@ private: bool m_frozen; wxCanvasObject *m_lastMouse; wxCanvasObject *m_captureMouse; + + int m_oldDeviceX,m_oldDeviceY; friend class wxCanvasObject; diff --git a/contrib/samples/canvas/test/test.cpp b/contrib/samples/canvas/test/test.cpp index 4934995543..255d8e2e2a 100644 --- a/contrib/samples/canvas/test/test.cpp +++ b/contrib/samples/canvas/test/test.cpp @@ -214,13 +214,17 @@ MyFrame::MyFrame() int i; for (i = 10; i < 300; i+=10) - m_canvas->Append( new wxCanvasRect( i,50,3,140, 255,0,0 ) ); + { + wxCanvasRect *r = new wxCanvasRect( i,50,3,140 ); + r->SetBrush( *wxRED_BRUSH ); + m_canvas->Append( r ); + } m_sm2 = new wxCanvasImage( image, 0,140,24,24 ); m_canvas->Append( m_sm2 ); for (i = 15; i < 300; i+=10) - m_canvas->Append( new wxCanvasRect( i,50,3,140, 255,0,0 ) ); + m_canvas->Append( new wxCanvasRect( i,50,3,140 ) ); wxButton *button = new wxButton( m_canvas, -1, "Hello", wxPoint(80,50) ); m_canvas->Append( new wxCanvasControl( button ) ); @@ -232,7 +236,7 @@ MyFrame::MyFrame() m_canvas->Append( m_sm3 ); 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,-15,i,300 ) ); m_sm4 = new MywxCanvasImage( image, 0,270,64,32 ); m_canvas->Append( m_sm4 ); @@ -244,7 +248,7 @@ MyFrame::MyFrame() /* //make a group of wxCanvasObjects wxCanvasObjectGroup* group1 = new wxCanvasObjectGroup(); - group1->Prepend( new wxCanvasLine( 10,-35,50,190,100,255,0 ) ); + group1->Prepend( new wxCanvasLine( 10,-35,50,190 ) ); group1->Prepend( new wxCanvasImage( image, 4,38,32,32 ) ); group1->Prepend( new wxCanvasRect(20,-20,50,170,0,20,240 ) ); diff --git a/contrib/src/canvas/canvas.cpp b/contrib/src/canvas/canvas.cpp index f541b0e944..67935663df 100644 --- a/contrib/src/canvas/canvas.cpp +++ b/contrib/src/canvas/canvas.cpp @@ -455,7 +455,7 @@ wxCanvasPolyline::wxCanvasPolyline( int n, wxPoint2DDouble points[]) { m_n = n; m_points = points; - m_pen = wxPen(wxColour(0,0,0),1,wxSOLID); + m_pen = *wxBLACK_PEN; } wxCanvasPolyline::~wxCanvasPolyline() @@ -547,8 +547,8 @@ wxCanvasPolygon::wxCanvasPolygon( int n, wxPoint2DDouble points[]) { m_n = n; m_points = points; - m_brush = wxBrush(wxColour(0,0,0),wxSOLID); - m_pen = wxPen(wxColour(0,0,0),1,wxSOLID); + m_brush = *wxBLACK_BRUSH; + m_pen = *wxTRANSPARENT_PEN; } wxCanvasPolygon::~wxCanvasPolygon() @@ -639,8 +639,7 @@ void wxCanvasPolygon::WriteSVG( wxTextOutputStream &stream ) // wxCanvasRect //---------------------------------------------------------------------------- -wxCanvasRect::wxCanvasRect( double x, double y, double w, double h, - unsigned char red, unsigned char green, unsigned char blue ) +wxCanvasRect::wxCanvasRect( double x, double y, double w, double h ) : wxCanvasObject() { m_x = x; @@ -648,9 +647,8 @@ wxCanvasRect::wxCanvasRect( double x, double y, double w, double h, m_width = w; m_height = h; - m_red = red; - m_green = green; - m_blue = blue; + m_brush = *wxBLACK_BRUSH; + m_pen = *wxTRANSPARENT_PEN; } void wxCanvasRect::Recreate() @@ -681,10 +679,8 @@ void wxCanvasRect::Render(int xabs, int yabs, int clip_x, int clip_y, int clip_w image->SetRGB( x, y, m_red, m_green, m_blue ); #else wxMemoryDC *dc = m_owner->GetDC(); - dc->SetPen( *wxTRANSPARENT_PEN ); - wxBrush brush( wxColour( m_red,m_green,m_blue), wxSOLID ); - dc->SetBrush( brush ); - + dc->SetPen( m_pen ); + dc->SetBrush( m_brush ); dc->DrawRectangle( clip_x-buffer_x, clip_y-buffer_y, clip_width, clip_height ); #endif } @@ -697,8 +693,7 @@ void wxCanvasRect::WriteSVG( wxTextOutputStream &stream ) // wxCanvasLine //---------------------------------------------------------------------------- -wxCanvasLine::wxCanvasLine( double x1, double y1, double x2, double y2, - unsigned char red, unsigned char green, unsigned char blue ) +wxCanvasLine::wxCanvasLine( double x1, double y1, double x2, double y2 ) : wxCanvasObject() { m_x1 = x1; @@ -706,9 +701,7 @@ wxCanvasLine::wxCanvasLine( double x1, double y1, double x2, double y2, m_x2 = x2; m_y2 = y2; - m_red = red; - m_green = green; - m_blue = blue; + m_pen = *wxBLACK_PEN; } void wxCanvasLine::Recreate() @@ -807,9 +800,7 @@ void wxCanvasLine::Render(int xabs, int yabs, int clip_x, int clip_y, int clip_w #else wxMemoryDC *dc = m_owner->GetDC(); dc->SetClippingRegion( clip_x-buffer_x, clip_y-buffer_y, clip_width, clip_height ); - - wxPen pen( wxColour(m_red,m_green,m_blue), 0, wxSOLID ); - dc->SetPen( pen ); + dc->SetPen( m_pen ); dc->DrawLine( x1-buffer_x, y1-buffer_y, x2-buffer_x, y2-buffer_y ); dc->DestroyClippingRegion(); @@ -1143,7 +1134,9 @@ wxCanvas::wxCanvas( wxWindow *parent, wxWindowID id, m_lastMouse = (wxCanvasObject*)NULL; m_captureMouse = (wxCanvasObject*)NULL; m_frozen = TRUE; - + m_oldDeviceX = 0; + m_oldDeviceY = 0; + //root group always at 0,0 m_root = new wxCanvasObjectGroup(); m_root->DeleteContents( TRUE ); @@ -1239,6 +1232,8 @@ void wxCanvas::Thaw() void wxCanvas::Update( int x, int y, int width, int height, bool blit ) { + CalcScrolledPosition( 0, 0, &m_oldDeviceX, &m_oldDeviceY ); + if (m_frozen) return; // clip to buffer @@ -1489,8 +1484,11 @@ 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(); + // expect the previous m_bufferX and m_bufferY as well as + // the previous device origin values. + wxClientDC dc( this ); + dc.SetDeviceOrigin( m_oldDeviceX, m_oldDeviceY ); + BlitBuffer( dc ); // The buffer always starts at the top left corner of the // client area. Indeed, it is the client area. -- 2.45.2