00001 /*! \file canvas/src/styleprop.cpp 00002 \author Klaas Holwerda 00003 00004 Copyright: 2000-2004 (c) Klaas Holwerda 00005 00006 Licence: wxWidgets Licence 00007 00008 RCS-ID: $Id: styleprop.cpp,v 1.33 2009/07/24 16:35:01 titato Exp $ 00009 */ 00010 00011 #include "a2dprec.h" 00012 00013 #ifndef WX_PRECOMP 00014 #include "wx/wx.h" 00015 #endif 00016 00017 00018 #include "wx/canvas/canglob.h" 00019 #include "wx/canvas/styleprop.h" 00020 #include "wx/canvas/canobj.h" 00021 #include "wx/canvas/candoc.h" 00022 00023 #define newline wxString("\n") 00024 00025 //IMPLEMENT_DYNAMIC_CLASS(a2dCanvasObjectStroke, a2dOneColourStroke) 00026 00027 00028 /************************************************** 00029 a2dCanvasObjectStroke 00030 **************************************************/ 00031 /* 00032 a2dCanvasObjectStroke::a2dCanvasObjectStroke(): a2dOneColourStroke() 00033 { 00034 m_distance = 0; 00035 m_style = a2dSTROKE_OBJECTS; 00036 SetStyle( m_style ); 00037 m_obj = 0; 00038 } 00039 00040 a2dCanvasObjectStroke::a2dCanvasObjectStroke( a2dCanvasObject* object ): a2dOneColourStroke() 00041 { 00042 m_distance = 0; 00043 m_style = a2dSTROKE_OBJECTS; 00044 SetStyle( m_style ); 00045 wxASSERT_MSG( object != 0 , wxT("a2dCanvasObject for a2dCanvasObjectStroke may not be Null") ); 00046 m_obj = object; 00047 } 00048 00049 a2dCanvasObjectStroke::a2dCanvasObjectStroke( a2dCanvasObject* object, const wxColour& col, float width, a2dStrokeStyle style ) 00050 :a2dOneColourStroke( col, width, style ) 00051 { 00052 m_distance = 0; 00053 m_style = a2dSTROKE_OBJECTS; 00054 SetStyle( m_style ); 00055 wxASSERT_MSG( object != 0 , wxT("a2dCanvasObject for a2dCanvasObjectStroke may not be Null") ); 00056 m_obj = object; 00057 } 00058 00059 a2dCanvasObjectStroke::a2dCanvasObjectStroke( a2dCanvasObject* object, const wxColour& col, int width, a2dStrokeStyle style) 00060 :a2dOneColourStroke( col, width, style ) 00061 { 00062 m_distance = 0; 00063 m_style = a2dSTROKE_OBJECTS; 00064 SetStyle( m_style ); 00065 wxASSERT_MSG( object != 0 , wxT("a2dCanvasObject for a2dCanvasObjectStroke may not be Null") ); 00066 m_obj = object; 00067 } 00068 00069 a2dCanvasObjectStroke::a2dCanvasObjectStroke( a2dCanvasObject* object, const wxPen& stroke ) 00070 :a2dOneColourStroke( stroke ) 00071 { 00072 m_distance = 0; 00073 m_style = a2dSTROKE_OBJECTS; 00074 SetStyle( m_style ); 00075 wxASSERT_MSG( object != 0 , wxT("a2dCanvasObject for a2dCanvasObjectStroke may not be Null") ); 00076 m_obj = object; 00077 } 00078 00079 00080 a2dCanvasObjectStroke::~a2dCanvasObjectStroke() 00081 { 00082 } 00083 00084 a2dObject* a2dCanvasObjectStroke::Clone( CloneOptions WXUNUSED(options) ) const 00085 { 00086 return new a2dCanvasObjectStroke( *this ); 00087 } 00088 00089 a2dCanvasObjectStroke::a2dCanvasObjectStroke( const a2dCanvasObjectStroke& stroke ): a2dOneColourStroke( stroke ) 00090 { 00091 m_distance = stroke.m_distance; 00092 m_obj = stroke.m_obj; 00093 m_style = a2dSTROKE_OBJECTS; 00094 SetStyle( m_style ); 00095 } 00096 00097 #if wxART2D_USE_CVGIO 00098 void a2dCanvasObjectStroke::DoSave( wxObject* parent, a2dIOHandlerXmlSerOut &out, a2dXmlSer_flag xmlparts , a2dObjectList* towrite ) 00099 { 00100 a2dStroke::DoSave( parent, out, xmlparts, towrite ); 00101 if ( xmlparts == a2dXmlSer_attrib ) 00102 { 00103 if ( this == a2dINHERIT_STROKE ) 00104 { 00105 out.WriteAttribute( wxT("style"), wxT("inherit") ); 00106 } 00107 else 00108 { 00109 } 00110 } 00111 else 00112 { 00113 } 00114 } 00115 00116 void a2dCanvasObjectStroke::DoLoad( wxObject* parent, a2dIOHandlerXmlSerIn& parser, a2dXmlSer_flag xmlparts ) 00117 { 00118 a2dStroke::DoLoad( parent, parser, xmlparts ); 00119 if ( xmlparts == a2dXmlSer_attrib ) 00120 { 00121 } 00122 else 00123 { 00124 } 00125 } 00126 #endif //wxART2D_USE_CVGIO 00127 00128 void a2dCanvasObjectStroke::Render( a2dIterC& ic, a2dDrawer2D* drawer, const a2dBoundingBox& WXUNUSED(clipbox), int n, wxPoint points[] ) 00129 { 00130 if ( m_distance == 0 ) 00131 { 00132 int i; 00133 double x,y; 00134 for (i = 0; i < n; i++) 00135 { 00136 x = drawer->DeviceToWorldX( points[i].x ); 00137 y = drawer->DeviceToWorldY( points[i].y ); 00138 a2dAffineMatrix relative; 00139 relative.Translate( x, y ); 00140 00141 a2dIterCU cu( ic, relative ); 00142 00143 m_obj->Render( ic, _ON ); 00144 } 00145 } 00146 else 00147 { //at every distance further around the contour place the object 00148 int i; 00149 double x,y; 00150 double prevx,prevy; 00151 double done = 0; 00152 00153 prevx = drawer->DeviceToWorldX( points[0].x ); 00154 prevy = drawer->DeviceToWorldY( points[0].y ); 00155 00156 for (i = 0; i < n-1; i++) 00157 { 00158 00159 x = drawer->DeviceToWorldX( points[i+1].x ); 00160 y = drawer->DeviceToWorldY( points[i+1].y ); 00161 00162 double dx =(x-prevx); 00163 double dy =(y-prevy); 00164 00165 double lseg = sqrt( dx*dx + dy*dy ); 00166 00167 while ( done <= lseg && lseg) 00168 { 00169 x = prevx + done/lseg * dx ; 00170 y = prevy + done/lseg * dy ; 00171 a2dAffineMatrix relative; 00172 relative.Translate( x, y ); 00173 a2dIterC ic( ic.GetCanvasView() ); 00174 a2dIterCU cu( ic, relative ); 00175 00176 m_obj->Render( ic, _ON ); 00177 done += m_distance; 00178 } 00179 00180 done = done - lseg; 00181 prevx = drawer->DeviceToWorldX( points[i+1].x ); 00182 prevy = drawer->DeviceToWorldY( points[i+1].y ); 00183 } 00184 } 00185 // 00186 drawer->DeviceDrawLines(n, points, spline ); 00187 int i; 00188 double x,y; 00189 for (i = 0; i < n; i++) 00190 { 00191 x = drawer->DeviceToWorldX( points[i].x ); 00192 y = drawer->DeviceToWorldY( points[i].y ); 00193 drawer->SetDrawerStroke( a2dTRANSPARENT_STROKE ); 00194 drawer->SetDrawerContour( wxLAYER_CONTOUR ); 00195 a2dFill* localfill = a2dFill( wxColour(1,233,5 )); 00196 drawer->SetDrawerFill( localfill ); 00197 drawer->DrawCircle( points[i].x, points[i].y, drawer->WorldToDeviceXRel(22) ); 00198 delete localfill; 00199 } 00200 // 00201 } 00202 */ 00203 /* 00204 float a2dCanvasObjectStroke::GetExtend() const 00205 { 00206 a2dBoundingBox box; 00207 box = m_obj->GetBbox(); 00208 00209 double xdisttozero = wxMax( fabs(box.GetMinX()),fabs(box.GetMaxX()) ); 00210 double ydisttozero = wxMax( fabs(box.GetMinY()),fabs(box.GetMaxY()) ); 00211 double max = sqrt ( xdisttozero*xdisttozero + ydisttozero*ydisttozero); 00212 return max; 00213 } 00214 00215 */ 00216 00217 00218 00219