+ wxCanvasObject *obj = (wxCanvasObject*) node->Data();
+
+ obj->AppendEventHandler(handler);
+
+ node = node->Next();
+ }
+}
+
+wxEvtHandler *wxCanvasObjectGroup::RemoveLastEventHandler(bool deleteHandler)
+{
+ wxNode *node = m_objects.First();
+ while (node)
+ {
+ wxCanvasObject *obj = (wxCanvasObject*) node->Data();
+
+ obj->RemoveLastEventHandler(deleteHandler);
+
+ node = node->Next();
+ }
+ return wxCanvasObject::RemoveLastEventHandler(deleteHandler);
+}
+
+void wxCanvasObjectGroup::TransLate( double x, double y )
+{
+ lworld.Translate(x,y);
+ CalcBoundingBox();
+}
+
+void wxCanvasObjectGroup::SetAdmin(wxCanvasAdmin* admin)
+{
+ m_admin=admin;
+ wxNode *node = m_objects.First();
+ while (node)
+ {
+ wxCanvasObject *obj = (wxCanvasObject*) node->Data();
+
+ obj->SetAdmin(admin);
+
+ node = node->Next();
+ }
+}
+
+void wxCanvasObjectGroup::DeleteContents( bool flag)
+{
+ m_objects.DeleteContents( flag );
+ m_bbox.SetValid(FALSE);
+ CalcBoundingBox();
+}
+
+void wxCanvasObjectGroup::Prepend( wxCanvasObject* obj )
+{
+ m_objects.Insert( obj );
+ if (m_objects.First())
+ {
+ m_bbox.Expand(obj->GetBbox());
+ }
+ else
+ {
+ m_bbox.SetValid(FALSE);
+ CalcBoundingBox();
+ }
+}
+
+void wxCanvasObjectGroup::Append( wxCanvasObject* obj )
+{
+ m_objects.Append( obj );
+ if (m_objects.First())
+ {
+ m_bbox.Expand(obj->GetBbox());
+ }
+ else
+ {
+ m_bbox.SetValid(FALSE);
+ CalcBoundingBox();
+ }
+}
+
+void wxCanvasObjectGroup::Insert( size_t before, wxCanvasObject* obj )
+{
+ m_objects.Insert( before, obj );
+ m_bbox.SetValid(FALSE);
+ if (m_objects.First())
+ {
+ m_bbox.Expand(obj->GetBbox());
+ }
+ else
+ {
+ m_bbox.SetValid(FALSE);
+ CalcBoundingBox();
+ }
+}
+
+void wxCanvasObjectGroup::Remove( wxCanvasObject* obj )
+{
+ m_objects.DeleteObject( obj );
+ m_bbox.SetValid(FALSE);
+ CalcBoundingBox();
+}
+
+void wxCanvasObjectGroup::CalcBoundingBox()
+{
+ m_bbox.SetValid(FALSE);
+ wxNode *node = m_objects.First();
+ while (node)
+ {
+ wxCanvasObject *obj = (wxCanvasObject*) node->Data();
+
+
+ obj->CalcBoundingBox();
+ wxBoundingBox tmp;
+ tmp=obj->GetBbox();
+ tmp.MapBbox(lworld);
+
+ m_bbox.Expand( tmp );
+ node = node->Next();
+ }
+}
+
+void wxCanvasObjectGroup::Render(wxTransformMatrix* cworld, int x, int y, int width, int height )
+{
+ if (!m_visible) return;
+
+ wxTransformMatrix backup = *cworld;
+ *cworld *= lworld;
+
+ wxNode *node = m_objects.First();
+
+ if (!node) return;
+
+
+#ifdef CANVASDEBUG
+ wxRect absarea=GetAbsoluteArea(*cworld);
+ wxDC *dc = m_admin->GetActive()->GetDC();
+ dc->SetPen(*wxBLACK_PEN);
+ dc->SetBrush(*wxTRANSPARENT_BRUSH);
+ dc->DrawRectangle( absarea.x , absarea.y , absarea.width , absarea.height );
+ dc->SetBrush(wxNullBrush);
+ dc->SetPen(wxNullPen);
+#endif
+ //TODO the next will only work if all boundingboxes stay up to date (problem when mowing currently
+ /*
+ if (! ( wxMax(absarea.x, x) < wxMin(absarea.x + absarea.width , x + width ) &&
+ wxMax(absarea.y, y) < wxMin(absarea.y + absarea.height , y + height )
+ )
+ )
+ return;
+ */
+
+ // cycle through all objects
+ while (node)
+ {
+ wxCanvasObject *obj = (wxCanvasObject*) node->Data();
+
+ if (!obj->IsControl() && obj->GetVisible())
+ {
+
+ //get area at the absolute position
+ wxRect absareaobject = obj->GetAbsoluteArea(*cworld);
+
+ // If we have 10.000 objects, we will go through
+ // this 10.000 times for each update, so we have
+ // to optimise carefully.
+ int clip_x = absareaobject.x;
+ int clip_width = absareaobject.width;
+ if (clip_x < x)
+ {
+ clip_width -= x-clip_x;
+ clip_x = x;
+ }
+ if (clip_width > 0)
+ {
+ if (clip_x + clip_width > x + width)
+ clip_width = x+width-clip_x;
+
+ if (clip_width > 0)
+ {
+ int clip_y = absareaobject.y;
+ int clip_height = absareaobject.height;
+ if (clip_y < y)
+ {
+ clip_height -= y-clip_y;
+ clip_y = y;
+ }
+ if (clip_height > 0)
+ {
+ if (clip_y + clip_height > y + height)
+ clip_height = y+height-clip_y;
+
+ if (clip_height > 0)
+ {
+ obj->Render(cworld, clip_x, clip_y, clip_width, clip_height );
+ }
+ }
+ }
+ }
+ }
+
+ node = node->Next();
+ }
+ *cworld = backup;
+}
+
+void wxCanvasObjectGroup::WriteSVG( wxTextOutputStream &stream )
+{
+}
+
+wxCanvasObject* wxCanvasObjectGroup::IsHitWorld( double x, double y, double margin )
+{
+ //KKKfirst check if within bbox
+ //will only work if they are always uptodate
+ //if (!m_bbox.PointInBox(x,y,margin))
+ // return (wxCanvasObject*) NULL;
+
+ wxTransformMatrix inverse = lworld;
+ double xh,yh;
+ inverse.Invert();
+ inverse.TransformPoint(x,y,xh,yh);
+
+ wxCanvasObject *obj=0;
+ wxNode *node = m_objects.Last();
+ while (node)
+ {
+ obj=(wxCanvasObject*) node->Data();
+
+ if (!obj->IsControl() )
+ {
+ if (obj->IsHitWorld(xh,yh,margin))
+ {
+ return obj;
+ }
+ }
+ node = node->Previous();
+ }
+
+ return (wxCanvasObject*) NULL;
+}
+
+wxCanvasObject* wxCanvasObjectGroup::Contains( wxCanvasObject* obj )
+{
+ wxCanvasObject* cobj;
+ wxNode *node = m_objects.First();
+ while (node)
+ {
+ cobj=(wxCanvasObject*) node->Data();
+
+ if (cobj->Contains(obj))
+ {
+ return obj;
+ }
+ node = node->Next();
+ }
+
+ return (wxCanvasObject*) NULL;
+}
+
+int wxCanvasObjectGroup::IndexOf( wxCanvasObject* obj )
+{
+ return m_objects.IndexOf( obj );
+}
+
+//----------------------------------------------------------------------------
+// wxCanvasObjectRef
+//----------------------------------------------------------------------------
+
+IMPLEMENT_CLASS(wxCanvasObjectRef, wxCanvasObject)
+
+wxCanvasObjectRef::wxCanvasObjectRef(double x, double y, wxCanvasObject* obj)
+ : wxCanvasObject()
+{
+ lworld.Translate(x,y);
+ m_obj = obj;
+
+ m_bbox.SetValid(FALSE);
+ wxBoundingBox tmp;
+ tmp=obj->GetBbox();
+ tmp.MapBbox(lworld);
+ m_bbox.Expand( tmp );
+}
+
+void wxCanvasObjectRef::PushEventHandler(wxEvtHandler *handler)
+{
+ wxCanvasObject::PushEventHandler(handler);
+ m_obj->PushEventHandler(handler);
+}
+
+wxEvtHandler *wxCanvasObjectRef::PopEventHandler(bool deleteHandler)
+{
+ m_obj->PopEventHandler(deleteHandler);
+ return wxCanvasObject::PopEventHandler(deleteHandler);
+}
+
+void wxCanvasObjectRef::AppendEventHandler(wxEvtHandler *handler)
+{
+ wxCanvasObject::AppendEventHandler(handler);
+ m_obj->AppendEventHandler(handler);
+}
+
+wxEvtHandler *wxCanvasObjectRef::RemoveLastEventHandler(bool deleteHandler)
+{
+ m_obj->RemoveLastEventHandler(deleteHandler);
+ return wxCanvasObject::RemoveLastEventHandler(deleteHandler);
+}
+
+void wxCanvasObjectRef::TransLate( double x, double y )
+{
+ lworld.Translate(x,y);
+ CalcBoundingBox();
+}
+
+wxCanvasObject* wxCanvasObjectRef::Contains( wxCanvasObject* obj )
+{
+ if (obj == this || m_obj->Contains(obj))
+ return this;
+
+ return (wxCanvasObject*) NULL;
+}
+
+
+void wxCanvasObjectRef::SetRotation(double rotation)
+{
+ lworld.SetRotation(rotation);
+ CalcBoundingBox();
+}
+
+void wxCanvasObjectRef::SetScale(double scalex,double scaley)
+{
+ lworld.Scale(scalex,scaley,lworld.GetValue(2,0),lworld.GetValue(2,1));
+ CalcBoundingBox();
+}
+
+void wxCanvasObjectRef::SetAdmin(wxCanvasAdmin* admin)
+{
+ m_admin = admin;
+ m_obj->SetAdmin(admin);
+}
+
+void wxCanvasObjectRef::CalcBoundingBox()
+{
+ m_bbox.SetValid(FALSE);
+ m_obj->CalcBoundingBox();
+
+ wxBoundingBox tmp;
+ tmp=m_obj->GetBbox();
+ tmp.MapBbox(lworld);
+ m_bbox.Expand( tmp );
+}
+
+void wxCanvasObjectRef::Render(wxTransformMatrix* cworld, int x, int y, int width, int height )
+{
+ if (!m_visible) return;
+
+ //get the absolute area (without the local matrix included)
+ //the boundingbox is relative to the parent.
+ wxRect absarea=GetAbsoluteArea(*cworld);
+
+ wxTransformMatrix backup = *cworld;
+ *cworld *= lworld;
+
+#ifdef CANVASDEBUG
+ wxDC *dc = m_admin->GetActive()->GetDC();
+ dc->SetPen(*wxBLACK_PEN);
+ dc->SetBrush(*wxTRANSPARENT_BRUSH);
+ dc->DrawRectangle( absarea.x , absarea.y , absarea.width , absarea.height );
+ dc->SetBrush(wxNullBrush);
+ dc->SetPen(wxNullPen);
+#endif
+
+ int clip_x = absarea.x;
+ int clip_width = absarea.width;
+ if (clip_x < x)
+ {
+ clip_width -= x-clip_x;
+ clip_x = x;
+ }
+ if (clip_width > 0)
+ {
+ if (clip_x + clip_width > x + width)
+ clip_width = x+width-clip_x;
+
+ if (clip_width > 0)
+ {
+ int clip_y = absarea.y;
+ int clip_height = absarea.height;
+ if (clip_y < y)
+ {
+ clip_height -= y-clip_y;
+ clip_y = y;
+ }
+ if (clip_height > 0)
+ {
+ if (clip_y + clip_height > y + height)
+ clip_height = y+height-clip_y;
+
+ if (clip_height > 0)
+ m_obj->Render(cworld, clip_x, clip_y, clip_width, clip_height );
+ }
+ }
+ }
+
+ *cworld = backup;
+}
+
+void wxCanvasObjectRef::WriteSVG( wxTextOutputStream &stream )
+{
+}
+
+wxCanvasObject* wxCanvasObjectRef::IsHitWorld( double x, double y, double margin )
+{
+ //KKKfirst check if within bbox
+ //will only work if they are always uptodate
+ //if (!m_bbox.PointInBox(x,y,margin))
+ // return (wxCanvasObject*) NULL;
+
+ wxTransformMatrix inverse = lworld;
+ double xh,yh;
+ inverse.Invert();
+ inverse.TransformPoint(x,y,xh,yh);
+
+ if (m_obj->IsHitWorld(xh,yh,margin))
+ return this;
+
+ return (wxCanvasObject*) NULL;
+}
+
+
+
+//----------------------------------------------------------------------------
+// wxCanvasRect
+//----------------------------------------------------------------------------
+
+IMPLEMENT_CLASS(wxCanvasRect, wxCanvasObject)
+
+wxCanvasRect::wxCanvasRect( double x, double y, double w, double h , double radius )
+ : wxCanvasObject()
+{
+ m_x = x;
+ m_y = y;
+ m_width = w;
+ m_height = h;
+ m_radius = radius;
+
+ m_brush = *wxBLACK_BRUSH;
+ m_pen = *wxTRANSPARENT_PEN;
+ CalcBoundingBox();
+}
+
+void wxCanvasRect::TransLate( double x, double y )
+{
+ m_x += x;
+ m_y += y;
+ CalcBoundingBox();
+}
+
+void wxCanvasRect::CalcBoundingBox()
+{
+ m_bbox.SetMin( m_x , m_y);
+ m_bbox.SetMax( m_x + m_width ,m_y + m_height );
+
+ //include the pen width also
+//KKK m_bbox.EnLarge(m_pen.GetWidth()+m_radius);
+ m_bbox.EnLarge(m_pen.GetWidth()/2);
+}
+
+void wxCanvasRect::Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height )
+{
+ if (!m_visible) return;
+
+ if (cworld->GetRotation())
+ {
+ wxPoint *cpoints = new wxPoint[4];
+ double x;
+ double y;
+ cworld->TransformPoint( m_x, m_y, x, y );
+ cpoints[0].x = m_admin->LogicalToDeviceX(x);
+ cpoints[0].y = m_admin->LogicalToDeviceY(y);
+ cworld->TransformPoint( m_x , m_y + m_height, x, y );
+ cpoints[1].x = m_admin->LogicalToDeviceX(x);
+ cpoints[1].y = m_admin->LogicalToDeviceY(y);
+ cworld->TransformPoint( m_x + m_width, m_y + m_height, x, y );
+ cpoints[2].x = m_admin->LogicalToDeviceX(x);
+ cpoints[2].y = m_admin->LogicalToDeviceY(y);
+ cworld->TransformPoint( m_x + m_width, m_y , x, y );
+ cpoints[3].x = m_admin->LogicalToDeviceX(x);
+ cpoints[3].y = m_admin->LogicalToDeviceY(y);
+
+ wxDC *dc = m_admin->GetActive()->GetDC();
+ dc->SetClippingRegion(clip_x, clip_y, clip_width, clip_height);
+ dc->SetBrush(m_brush);
+ int pw=m_pen.GetWidth();
+ m_pen.SetWidth(m_admin->LogicalToDeviceXRel(pw));
+ dc->SetPen(m_pen);
+ dc->DrawPolygon(4, cpoints, 0,0,wxWINDING_RULE);
+ delete [] cpoints;
+ dc->SetBrush(wxNullBrush);
+ dc->SetPen(wxNullPen);
+ dc->DestroyClippingRegion();
+ m_pen.SetWidth(pw);
+ }
+ else
+ {
+ wxDC *dc = m_admin->GetActive()->GetDC();
+ dc->SetClippingRegion(clip_x, clip_y, clip_width, clip_height);
+ dc->SetBrush(m_brush);
+ int pw=m_pen.GetWidth();
+ m_pen.SetWidth(m_admin->LogicalToDeviceXRel(pw));
+ dc->SetPen(m_pen);
+ //yes the whole not only the clipping region, because we have a pen also
+ int x = m_admin->LogicalToDeviceX(cworld->GetValue(2,0) + m_x );
+ int y = m_admin->LogicalToDeviceY(cworld->GetValue(2,1) + m_y );
+ int w = m_admin->LogicalToDeviceXRel( m_width );
+ int h = m_admin->LogicalToDeviceYRel( m_height );
+ int r = m_admin->LogicalToDeviceYRel( m_radius );
+ if (w > 0 && w < 1) w=1;
+ if (w < 0 && w > -1) w=-1;
+ if (h > 0 && h < 1) h=1;
+ if (h < 0 && h > -1) h=-1;
+ if (m_radius)
+ dc->DrawRoundedRectangle( x,y,w,h,r);
+ else
+ dc->DrawRectangle( x,y,w,h);
+ dc->SetBrush(wxNullBrush);
+ dc->SetPen(wxNullPen);
+ dc->DestroyClippingRegion();
+ m_pen.SetWidth(pw);
+ }
+}
+
+void wxCanvasRect::WriteSVG( wxTextOutputStream &stream )
+{
+}
+
+//----------------------------------------------------------------------------
+// wxCanvasCircle
+//----------------------------------------------------------------------------
+
+wxCanvasCircle::wxCanvasCircle( double x, double y, double radius )
+ : wxCanvasObject()
+{
+ m_x = x;
+ m_y = y;
+ m_radius = radius;
+
+ m_brush = *wxBLACK_BRUSH;
+ m_pen = *wxTRANSPARENT_PEN;
+ CalcBoundingBox();
+}
+
+void wxCanvasCircle::TransLate( double x, double y )
+{
+ m_x += x;
+ m_y += y;
+ CalcBoundingBox();
+}
+
+void wxCanvasCircle::CalcBoundingBox()
+{
+ m_bbox.SetMin( m_x-m_radius , m_y-m_radius );
+ m_bbox.SetMax( m_x+m_radius , m_y+m_radius );
+
+ //include the pen width also
+ m_bbox.EnLarge(m_pen.GetWidth()/2);
+}
+
+void wxCanvasCircle::Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height )
+{
+ if (!m_visible) return;
+
+ wxDC *dc = m_admin->GetActive()->GetDC();
+ dc->SetClippingRegion(clip_x, clip_y, clip_width, clip_height);
+ dc->SetBrush(m_brush);
+ int pw=m_pen.GetWidth();
+ m_pen.SetWidth(m_admin->LogicalToDeviceXRel(pw));
+ dc->SetPen(m_pen);
+ //yes the whole not only the clipping region, because we have a pen also
+ //and rotation on a circle is not important so only a shift with cworld
+ int x = m_admin->LogicalToDeviceX(cworld->GetValue(2,0) + m_x );
+ int y = m_admin->LogicalToDeviceY(cworld->GetValue(2,1) + m_y );
+ int radius = m_admin->LogicalToDeviceXRel( m_radius );
+ if (radius < 1) radius=1;
+ dc->DrawCircle( x,y,radius);
+ dc->SetBrush(wxNullBrush);
+ dc->SetPen(wxNullPen);
+ dc->DestroyClippingRegion();
+ m_pen.SetWidth(pw);
+}
+
+void wxCanvasCircle::WriteSVG( wxTextOutputStream &stream )
+{
+}
+
+wxCanvasObject* wxCanvasCircle::IsHitWorld( double x, double y, double margin )
+{
+ if ((x >= m_bbox.GetMinX()-margin) &&
+ (x <= m_bbox.GetMaxX()+margin) &&
+ (y >= m_bbox.GetMinY()-margin) &&
+ (y <= m_bbox.GetMaxY()+margin)
+ )
+ {
+ if (m_radius+m_pen.GetWidth()/2+margin > sqrt(pow(m_x-x,2)+pow(m_y-y,2)))
+ return this;
+ else
+ return (wxCanvasObject*) NULL;
+ }
+ return (wxCanvasObject*) NULL;
+}
+
+//----------------------------------------------------------------------------
+// wxCanvasEllipse
+//----------------------------------------------------------------------------
+
+wxCanvasEllipse::wxCanvasEllipse( double x, double y, double width, double height )
+ : wxCanvasObject()
+{
+ m_x = x;
+ m_y = y;
+ m_width = width;
+ m_height = height;
+
+ m_brush = *wxBLACK_BRUSH;
+ m_pen = *wxTRANSPARENT_PEN;
+ CalcBoundingBox();
+}
+
+void wxCanvasEllipse::TransLate( double x, double y )
+{
+ m_x += x;
+ m_y += y;
+ CalcBoundingBox();
+}
+
+void wxCanvasEllipse::CalcBoundingBox()
+{
+ m_bbox.SetMin( m_x, m_y );
+ m_bbox.SetMax( m_x+m_width , m_y+m_height );
+
+ //include the pen width also
+ m_bbox.EnLarge(m_pen.GetWidth()/2);
+}
+
+void wxCanvasEllipse::Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height )
+{
+ if (!m_visible) return;
+
+ wxDC *dc = m_admin->GetActive()->GetDC();
+ dc->SetClippingRegion(clip_x, clip_y, clip_width, clip_height);
+ dc->SetBrush(m_brush);
+ int pw=m_pen.GetWidth();
+ m_pen.SetWidth(m_admin->LogicalToDeviceXRel(pw));
+ dc->SetPen(m_pen);
+ int x = m_admin->LogicalToDeviceX(cworld->GetValue(2,0) + m_x );
+ int y = m_admin->LogicalToDeviceY(cworld->GetValue(2,1) + m_y );
+ int w = m_admin->LogicalToDeviceXRel( m_width );
+ int h = m_admin->LogicalToDeviceYRel( m_height );
+ if (w > 0 && w < 1) w=1;
+ if (w < 0 && w > -1) w=-1;
+ if (h > 0 && h < 1) h=1;
+ if (h < 0 && h > -1) h=-1;
+ dc->DrawEllipse( x,y,w,h);
+ dc->SetBrush(wxNullBrush);
+ dc->SetPen(wxNullPen);
+ dc->DestroyClippingRegion();
+ m_pen.SetWidth(pw);
+}
+
+void wxCanvasEllipse::WriteSVG( wxTextOutputStream &stream )
+{
+}
+
+wxCanvasObject* wxCanvasEllipse::IsHitWorld( double x, double y, double margin )
+{
+ if ((x >= m_bbox.GetMinX()-margin) &&
+ (x <= m_bbox.GetMaxX()+margin) &&
+ (y >= m_bbox.GetMinY()-margin) &&
+ (y <= m_bbox.GetMaxY()+margin)
+ )
+ {
+ double a=(m_width+m_pen.GetWidth())/2+margin ;
+ double b=(m_height+m_pen.GetWidth())/2+margin;
+ double c=pow((m_x+m_width/2-x)/a,2)+pow((m_y+m_height/2-y)/b,2);
+ if ( 1 > c)
+ return this;
+ else
+ return (wxCanvasObject*) NULL;
+ }
+ return (wxCanvasObject*) NULL;
+}
+
+//----------------------------------------------------------------------------
+// wxCanvasEllipticArc
+//----------------------------------------------------------------------------
+
+wxCanvasEllipticArc::wxCanvasEllipticArc( double x, double y, double width, double height, double start, double end )
+ : wxCanvasObject()
+{
+ m_x = x;
+ m_y = y;
+ m_width = width;
+ m_height = height;
+ m_start = start;
+ m_end = end;
+
+ m_brush = *wxBLACK_BRUSH;
+ m_pen = *wxTRANSPARENT_PEN;
+ CalcBoundingBox();
+}
+
+void wxCanvasEllipticArc::TransLate( double x, double y )
+{
+ m_x += x;
+ m_y += y;
+ CalcBoundingBox();
+}
+
+void wxCanvasEllipticArc::CalcBoundingBox()
+{
+ m_bbox.SetMin( m_x, m_y );
+ m_bbox.SetMax( m_x+m_width , m_y+m_height );
+
+ //include the pen width also
+ m_bbox.EnLarge(m_pen.GetWidth()/2);
+}
+
+void wxCanvasEllipticArc::Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height )
+{
+ if (!m_visible) return;
+
+ wxDC *dc = m_admin->GetActive()->GetDC();
+ dc->SetClippingRegion(clip_x, clip_y, clip_width, clip_height);
+ dc->SetBrush(m_brush);
+ int pw=m_pen.GetWidth();
+ m_pen.SetWidth(m_admin->LogicalToDeviceXRel(pw));
+ dc->SetPen(m_pen);
+ int x = m_admin->LogicalToDeviceX(cworld->GetValue(2,0) + m_x );
+ int y = m_admin->LogicalToDeviceY(cworld->GetValue(2,1) + m_y );
+ int w = m_admin->LogicalToDeviceXRel( m_width );
+ int h = m_admin->LogicalToDeviceYRel( m_height );
+ if (w > 0 && w < 1) w=1;
+ if (w < 0 && w > -1) w=-1;
+ if (h > 0 && h < 1) h=1;
+ if (h < 0 && h > -1) h=-1;
+ if (m_admin->GetActive()->GetYaxis())
+ dc->DrawEllipticArc( x,y,w,h,-m_end,-m_start);
+ else
+ dc->DrawEllipticArc( x,y,w,h,m_start,m_end);
+ dc->SetBrush(wxNullBrush);
+ dc->SetPen(wxNullPen);
+ dc->DestroyClippingRegion();
+ m_pen.SetWidth(pw);
+}
+
+void wxCanvasEllipticArc::WriteSVG( wxTextOutputStream &stream )
+{
+}
+
+wxCanvasObject* wxCanvasEllipticArc::IsHitWorld( double x, double y, double margin )
+{
+ if ((x >= m_bbox.GetMinX()-margin) &&
+ (x <= m_bbox.GetMaxX()+margin) &&
+ (y >= m_bbox.GetMinY()-margin) &&
+ (y <= m_bbox.GetMaxY()+margin)
+ )
+ {
+ double a=(m_width+m_pen.GetWidth())/2+margin ;
+ double b=(m_height+m_pen.GetWidth())/2+margin;
+ double c=pow((m_x+m_width/2-x)/a,2)+pow((m_y+m_height/2-y)/b,2);
+ if ( 1 > c)
+ return this;
+ else
+ return (wxCanvasObject*) NULL;
+ }
+ return (wxCanvasObject*) NULL;
+}
+
+//----------------------------------------------------------------------------
+// wxCanvasLine
+//----------------------------------------------------------------------------
+
+wxCanvasLine::wxCanvasLine( double x1, double y1, double x2, double y2 )
+ : wxCanvasObject()
+{
+ m_x1 = x1;
+ m_y1 = y1;
+ m_x2 = x2;
+ m_y2 = y2;
+
+ m_pen = *wxBLACK_PEN;
+ CalcBoundingBox();
+}
+
+void wxCanvasLine::TransLate( double x, double y )
+{
+ m_x1 += x;
+ m_y1 += y;
+ m_x2 += x;
+ m_y2 += y;
+ CalcBoundingBox();
+}
+
+void wxCanvasLine::CalcBoundingBox()
+{
+ m_bbox.SetMin( m_x1 , m_y1);
+ m_bbox.SetMax( m_x2 , m_y2);
+
+ //include the pen width also
+ m_bbox.EnLarge(m_pen.GetWidth()/2);
+}
+
+void wxCanvasLine::Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height )
+{
+ if (!m_visible) return;
+
+ double x1,y1,x2,y2;
+ cworld->TransformPoint( m_x1, m_y1, x1, y1 );
+ cworld->TransformPoint( m_x2, m_y2, x2, y2 );
+ x1 = m_admin->LogicalToDeviceX( x1 );
+ y1 = m_admin->LogicalToDeviceY( y1 );
+ x2 = m_admin->LogicalToDeviceX( x2 );
+ y2 = m_admin->LogicalToDeviceY( y2 );
+
+ wxDC *dc = m_admin->GetActive()->GetDC();
+ dc->SetClippingRegion( clip_x, clip_y, clip_width, clip_height );
+ int pw=m_pen.GetWidth();
+ m_pen.SetWidth(m_admin->LogicalToDeviceXRel(pw));
+ dc->SetPen( m_pen );
+ dc->DrawLine( x1, y1, x2, y2 );
+
+ dc->DestroyClippingRegion();
+ m_pen.SetWidth(pw);
+}
+
+void wxCanvasLine::WriteSVG( wxTextOutputStream &stream )
+{
+ // no idea
+}
+
+wxCanvasObject* wxCanvasLine::IsHitWorld( double x, double y, double margin )
+{
+ if ((x >= m_bbox.GetMinX()-margin) &&
+ (x <= m_bbox.GetMaxX()+margin) &&
+ (y >= m_bbox.GetMinY()-margin) &&
+ (y <= m_bbox.GetMaxY()+margin)
+ )
+ {
+ wxLine line1(m_x1,m_y1,m_x2,m_y2);
+ wxPoint2DDouble P=wxPoint2DDouble(x,y);
+ double distance;
+ if (line1.PointInLine(P,distance,m_pen.GetWidth()/2+margin) == R_IN_AREA)
+ return this;
+ else
+ return (wxCanvasObject*) NULL;
+ }
+ return (wxCanvasObject*) NULL;
+}
+
+//----------------------------------------------------------------------------
+// wxCanvasImage
+//----------------------------------------------------------------------------
+
+wxCanvasImage::wxCanvasImage( const wxImage &image, double x, double y, double w, double h )
+ : wxCanvasObject()
+{
+ m_x = x;
+ m_y = y;
+ m_width = w;
+ m_height = h;
+
+ m_image = image;
+
+ m_orgw = m_image.GetWidth();
+ m_orgh = m_image.GetHeight();
+
+ m_isImage = TRUE;
+ 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;
+ m_y += y;
+ CalcBoundingBox();
+}
+
+void wxCanvasImage::CalcBoundingBox()
+{
+ m_bbox.SetMin( m_x, m_y );
+ m_bbox.SetMax( m_x + m_width, m_y + m_height );
+}
+
+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());
+ tmparea.y = m_admin->LogicalToDeviceYRel( m_bbox.GetMinY());
+ tmparea.width = m_admin->LogicalToDeviceXRel( m_bbox.GetWidth() );
+ tmparea.height = m_admin->LogicalToDeviceYRel( m_bbox.GetHeight() );
+
+ double x;
+ double y;
+ cworld->TransformPoint( m_x, m_y, x, y );
+ x = m_admin->LogicalToDeviceX(x);
+ 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() ) ||
+ m_orgh/5 > m_admin->LogicalToDeviceYRel( m_bbox.GetHeight() )
+ )
+ {
+ wxDC *dc = m_admin->GetActive()->GetDC();
+ dc->SetClippingRegion(clip_x, clip_y, clip_width, clip_height);
+ dc->SetBrush(*wxTRANSPARENT_BRUSH);
+ dc->SetPen(*wxBLACK_PEN);
+ //yes the whole not only the clipping region, because we have a pen also
+ int x = m_admin->LogicalToDeviceX(cworld->GetValue(2,0) + m_x );
+ int y = m_admin->LogicalToDeviceY(cworld->GetValue(2,1) + m_y );
+ int w = m_admin->LogicalToDeviceXRel( m_width );
+ int h = m_admin->LogicalToDeviceYRel( m_height );
+ if (w < 1) w=1;
+ if (h < 1) h=1;
+ dc->DrawRectangle( x,y,w,h);
+ dc->SetBrush(wxNullBrush);
+ dc->SetPen(wxNullPen);
+ dc->DestroyClippingRegion();
+ return;
+ }
+
+ wxImage tmp;
+ bool is_cashed = FALSE;
+
+ if (m_cImage.Ok() && (m_cW == m_bbox.GetWidth()) && (m_cH == m_bbox.GetHeight()))
+ {
+ // use cached image
+ tmp = m_cImage;
+ is_cashed = TRUE;
+ }
+ else
+ {
+ 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();
+ }
+
+// wxPoint centr(m_admin->LogicalToDeviceX(m_x),m_admin->LogicalToDeviceY(m_y));
+ wxPoint centr(0,0);
+
+ wxBitmap bmp;
+
+ if (m_cBitmap.Ok() && is_cashed && (m_cR == cworld->GetRotation()))
+ {
+ bmp = m_cBitmap;
+ }
+ else
+ {
+ if (cworld->GetRotation())
+ tmp = tmp.Rotate(-cworld->GetRotation()/180.0 * pi, centr, TRUE, NULL );
+
+ bmp = wxBitmap(tmp);