]> git.saurik.com Git - wxWidgets.git/blobdiff - contrib/src/canvas/canvas.cpp
added QueryRawValue() to wxRegKey and test code for it in the sample
[wxWidgets.git] / contrib / src / canvas / canvas.cpp
index f541b0e944a04aab45cca9324eba1d8a5016847e..1be997526aeec5e68ea0b5e059ec75b7cbc43444 100644 (file)
@@ -368,8 +368,8 @@ void wxCanvasObjectGroupRef::Recreate()
 
 void wxCanvasObjectGroupRef::Render(int xabs, int yabs, int x, int y, int width, int height )
 {
-    xabs += m_owner->GetDeviceX(m_x);
-    yabs += m_owner->GetDeviceY(m_y);
+    xabs += m_area.x;
+    yabs += m_area.y;
 
     int clip_x = xabs + m_group->GetXMin();
     int clip_width = m_group->GetXMax()-m_group->GetXMin();
@@ -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();
@@ -1020,10 +1011,11 @@ void wxCanvasText::Render(int xabs, int yabs, int clip_x, int clip_y, int clip_w
 {
     if (!m_alpha) return;
 
-#if IMAGE_CANVAS
-    wxImage *image = m_owner->GetBuffer();
     int buffer_x = m_owner->GetBufferX();
     int buffer_y = m_owner->GetBufferY();
+    
+#if IMAGE_CANVAS
+    wxImage *image = m_owner->GetBuffer();
 
     // local coordinates
     int start_x = clip_x - m_area.x;
@@ -1059,6 +1051,52 @@ void wxCanvasText::Render(int xabs, int yabs, int clip_x, int clip_y, int clip_w
                 image->SetRGB( image_x, image_y, red1+red2, green1+green2, blue1+blue2 );
             }
         }
+#else
+    wxBitmap *bitmap = m_owner->GetBuffer();
+    wxRect sub_rect( clip_x-buffer_x, clip_y-buffer_y, clip_width, clip_height );
+    wxBitmap sub_bitmap( bitmap->GetSubBitmap( sub_rect ) );
+    
+    wxImage image( sub_bitmap );
+
+    // local coordinates
+    int start_x = clip_x - m_area.x;
+    int end_x = clip_width + start_x;
+    int start_y = clip_y - m_area.y;
+    int end_y = clip_height + start_y;
+
+    for (int y = start_y; y < end_y; y++)
+        for (int x = start_x; x < end_x; x++)
+        {
+            int alpha = m_alpha[y*m_area.width + x];
+            if (alpha)
+            {
+                int image_x = x - start_x;
+                int image_y = y - start_y;
+                if (alpha == 255)
+                {
+                    image.SetRGB( image_x, image_y, m_red, m_green, m_blue );
+                    continue;
+                }
+                int red1 = (m_red * alpha) / 255;
+                int green1 = (m_green * alpha) / 255;
+                int blue1 = (m_blue * alpha) / 255;
+
+                alpha = 255-alpha;
+                int red2 = image.GetRed( image_x, image_y );
+                int green2 = image.GetGreen( image_x, image_y );
+                int blue2 = image.GetBlue( image_x, image_y );
+                red2 = (red2 * alpha) / 255;
+                green2 = (green2 * alpha) / 255;
+                blue2 = (blue2 * alpha) / 255;
+
+                image.SetRGB( image_x, image_y, red1+red2, green1+green2, blue1+blue2 );
+            }
+        }
+   
+   sub_bitmap = image.ConvertToBitmap();
+   
+   wxMemoryDC *dc = m_owner->GetDC();
+   dc->DrawBitmap( sub_bitmap, clip_x-buffer_x, clip_y-buffer_y );
 #endif
 }
 
@@ -1073,9 +1111,9 @@ void wxCanvasText::Recreate()
     m_area.x = m_owner->GetDeviceX( m_x );
     m_area.y = m_owner->GetDeviceY( m_y );
 
-    m_area.width = 100;  // TODO, calculate length
-    m_area.height = m_size;
-    m_alpha = new unsigned char[100*m_size];
+    m_area.width = 100;                   // TODO calculate length
+    m_area.height = m_size + (m_size/2);  // TODO space for sub-baseline (pgypq)
+    m_alpha = new unsigned char[m_area.width*m_area.height];
     memset( m_alpha, 0, m_area.width*m_area.height );
 
 #if wxUSE_FREETYPE
@@ -1143,7 +1181,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 +1279,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 +1531,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.