X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8636c073a373e38e6a3f7c1b013799016896406b..02a1dfbae942c883d8651e34dcfbc5153aabc56e:/contrib/src/canvas/canvas.cpp?ds=sidebyside diff --git a/contrib/src/canvas/canvas.cpp b/contrib/src/canvas/canvas.cpp index bb33ecd1ba..0cedafc946 100644 --- a/contrib/src/canvas/canvas.cpp +++ b/contrib/src/canvas/canvas.cpp @@ -51,6 +51,8 @@ FT_Library g_freetypeLibrary; // wxCanvasObject //---------------------------------------------------------------------------- +IMPLEMENT_CLASS(wxCanvasObject, wxEvtHandler) + wxCanvasObject::wxCanvasObject() { // the default event handler is just this object @@ -60,9 +62,9 @@ wxCanvasObject::wxCanvasObject() m_isVector = FALSE; m_isImage = FALSE; m_visible = TRUE; - m_dragmode = DRAG_ONTOP; + m_dragmode = wxDRAG_ONTOP; // handy when debugging -// m_dragmode = DRAG_RECTANGLE; +// m_dragmode = wxDRAG_RECTANGLE; m_dragable = TRUE; } @@ -216,7 +218,7 @@ void wxCanvasObject::MoveRelative( double x, double y ) void wxCanvasObject::DragStart() { - if (m_dragmode == DRAG_RECTANGLE) + if (m_dragmode == wxDRAG_RECTANGLE) { this->SetVisible(FALSE); wxTransformMatrix help; @@ -236,7 +238,7 @@ void wxCanvasObject::DragStart() dc.SetBrush(wxNullBrush); dc.SetPen(wxNullPen); } - else + else if (m_dragmode != wxDRAG_REDRAW) { this->SetVisible(FALSE); wxTransformMatrix help; @@ -266,7 +268,7 @@ void wxCanvasObject::DragStart() void wxCanvasObject::DragRelative( double x, double y) { - if (m_dragmode == DRAG_RECTANGLE) + if (m_dragmode == wxDRAG_RECTANGLE) { wxTransformMatrix help; @@ -285,7 +287,7 @@ void wxCanvasObject::DragRelative( double x, double y) dc.SetBrush(wxNullBrush); dc.SetPen(wxNullPen); } - else + else if (m_dragmode != wxDRAG_REDRAW) { wxClientDC dc(m_admin->GetActive()); wxMemoryDC tmp; @@ -336,6 +338,8 @@ void wxCanvasObject::DragRelative( double x, double y) dcm.SelectObject(wxNullBitmap); this->SetVisible(FALSE); } + else + MoveRelative(x,y); } @@ -405,6 +409,8 @@ void wxCanvasObject::WriteSVG( wxTextOutputStream &stream ) // wxCanvasObjectGroup //---------------------------------------------------------------------------- +IMPLEMENT_CLASS(wxCanvasObjectGroup, wxCanvasObject) + wxCanvasObjectGroup::wxCanvasObjectGroup(double x, double y) { lworld.Translate(x,y); @@ -676,7 +682,7 @@ wxCanvasObject* wxCanvasObjectGroup::IsHitWorld( double x, double y, double marg if (!obj->IsControl() ) { - if (obj->IsHitWorld(x,y,margin)) + if (obj->IsHitWorld(xh,yh,margin)) { return obj; } @@ -714,6 +720,8 @@ int wxCanvasObjectGroup::IndexOf( wxCanvasObject* obj ) // wxCanvasObjectRef //---------------------------------------------------------------------------- +IMPLEMENT_CLASS(wxCanvasObjectRef, wxCanvasObject) + wxCanvasObjectRef::wxCanvasObjectRef(double x, double y, wxCanvasObject* obj) : wxCanvasObject() { @@ -878,6 +886,8 @@ wxCanvasObject* wxCanvasObjectRef::IsHitWorld( double x, double y, double margin // wxCanvasRect //---------------------------------------------------------------------------- +IMPLEMENT_CLASS(wxCanvasRect, wxCanvasObject) + wxCanvasRect::wxCanvasRect( double x, double y, double w, double h , double radius ) : wxCanvasObject() { @@ -1321,6 +1331,13 @@ wxCanvasImage::wxCanvasImage( const wxImage &image, double x, double y, double w CalcBoundingBox(); } +void wxCanvasImage::SetPosXY( double x, double y) +{ + m_x = x; + m_y = y; + CalcBoundingBox(); +} + void wxCanvasImage::TransLate( double x, double y ) { m_x += x; @@ -1337,7 +1354,7 @@ void wxCanvasImage::CalcBoundingBox() void wxCanvasImage::Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height ) { if (!m_visible) return; - + wxRect tmparea; tmparea.x = m_admin->LogicalToDeviceXRel( m_bbox.GetMinX()); @@ -1352,6 +1369,7 @@ void wxCanvasImage::Render(wxTransformMatrix* cworld, int clip_x, int clip_y, in y = m_admin->LogicalToDeviceY(y); + // What is this??? if ( m_orgw*5 < m_admin->LogicalToDeviceXRel( m_bbox.GetWidth() ) || m_orgw/5 > m_admin->LogicalToDeviceXRel( m_bbox.GetWidth() ) || m_orgh*5 < m_admin->LogicalToDeviceYRel( m_bbox.GetHeight() ) || @@ -1375,29 +1393,54 @@ void wxCanvasImage::Render(wxTransformMatrix* cworld, int clip_x, int clip_y, in dc->DestroyClippingRegion(); return; } + + wxImage tmp; + bool is_cashed = FALSE; - if ((m_admin->LogicalToDeviceXRel( m_bbox.GetWidth() ) == m_image.GetWidth()) && - (m_admin->LogicalToDeviceYRel( m_bbox.GetHeight() ) == m_image.GetHeight())) + if (m_cImage.Ok() && (m_cW == m_bbox.GetWidth()) && (m_cH == m_bbox.GetHeight())) { - m_tmp = m_image; + // use cached image + tmp = m_cImage; + is_cashed = TRUE; } else { - m_tmp = m_image.Scale( m_admin->LogicalToDeviceXRel( m_bbox.GetWidth()), - m_admin->LogicalToDeviceYRel( m_bbox.GetHeight()) ); + if ((m_admin->LogicalToDeviceXRel( m_bbox.GetWidth() ) == m_image.GetWidth()) && + (m_admin->LogicalToDeviceYRel( m_bbox.GetHeight() ) == m_image.GetHeight())) + { + tmp = m_image; + } + else + { + tmp = m_image.Scale( m_admin->LogicalToDeviceXRel( m_bbox.GetWidth()), + m_admin->LogicalToDeviceYRel( m_bbox.GetHeight()) ); + } + + // create cached image + m_cImage = tmp; + m_cW = tmp.GetWidth(); + m_cH = tmp.GetHeight(); } - wxBitmap bmp; // wxPoint centr(m_admin->LogicalToDeviceX(m_x),m_admin->LogicalToDeviceY(m_y)); wxPoint centr(0,0); - if (cworld->GetRotation()) + wxBitmap bmp; + + if (m_cBitmap.Ok() && is_cashed && (m_cR == cworld->GetRotation())) { - bmp=m_tmp.Rotate(-cworld->GetRotation()/180.0 * pi,centr, TRUE, NULL).ConvertToBitmap(); + bmp = m_cBitmap; } else { - bmp = m_tmp.ConvertToBitmap(); + if (cworld->GetRotation()) + tmp = tmp.Rotate(-cworld->GetRotation()/180.0 * pi, centr, TRUE, NULL ); + + bmp = wxBitmap(tmp); + + // create cached bitmap + m_cBitmap = bmp; + m_cR = cworld->GetRotation(); } wxDC *dc = m_admin->GetActive()->GetDC(); @@ -1423,28 +1466,9 @@ void wxCanvasImage::Render(wxTransformMatrix* cworld, int clip_x, int clip_y, in } else { - //TODO clipping not right -// dc->DrawPoint(centr2); -// dc->DrawPoint(x,y); - - if ((clip_x == x) && - (clip_y == y) && - (clip_width == tmparea.width) && - (clip_height == tmparea.height)) - { - dc->DrawBitmap( m_tmp, clip_x, clip_y, TRUE ); - } - else - { - int start_x = clip_x - (int)x; - int start_y = clip_y - (int)y; - - //dc->DrawBitmap( bmp, x, y, TRUE ); - wxMemoryDC dcm; - dcm.SelectObject(bmp); - dc->Blit(clip_x, clip_y,clip_width, clip_height,&dcm,start_x,start_y,wxCOPY,TRUE); - dcm.SelectObject(wxNullBitmap); - } + dc->SetClippingRegion( clip_x, clip_y, clip_width, clip_height ); + dc->DrawBitmap( bmp, x, y, TRUE ); + dc->DestroyClippingRegion(); } } @@ -1642,7 +1666,7 @@ void wxCanvasText::Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int wxRect sub_rect( clip_x, clip_y, clip_width, clip_height ); wxBitmap sub_bitmap( bitmap->GetSubBitmap( sub_rect ) ); - wxImage image( sub_bitmap ); + wxImage image( sub_bitmap.ConvertToImage() ); // local coordinates int start_x = clip_x - tmparea.x; @@ -1679,7 +1703,7 @@ void wxCanvasText::Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int } } - sub_bitmap = image.ConvertToBitmap(); + sub_bitmap = wxBitmap(image); wxDC *dc = m_admin->GetActive()->GetDC(); dc->DrawBitmap( sub_bitmap, clip_x, clip_y );