Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "vgfx.h"
00037 #include "drawer.h"
00038
00039 #include "common/wave_ex.h"
00040 #include "perf/perf.h"
00041 #include "util/parsing.h"
00042
00043
00044
00045 namespace vgfx {
00046
00047
00048
00049
00050
00051
00052
00053 class Line : public Primitive {
00054 public:
00055 ~Line(void) throw() { }
00056
00057
00058 void initialize(IN const init_line_t& init);
00059
00060
00061 virtual const char * getType(void) const throw() { return "line"; }
00062 virtual void persist(OUT std::ostream& stream) const;
00063 virtual void recalcBoundingRect(IN const char * tag_path,
00064 IN Drawer * drawer,
00065 IN const xform_2d_t& T) { }
00066 virtual bool getBoundingRect(OUT rect_t& r) const throw();
00067 virtual void draw(IN Drawer * drawer,
00068 IN const rect_t& r_cm,
00069 IN const xform_2d_t& T);
00070
00071 private:
00072 point_t m_p0;
00073 point_t m_p1;
00074 };
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 void
00085 Line::initialize
00086 (
00087 IN const init_line_t& init
00088 )
00089 {
00090 this->setID(init.id.c_str());
00091 m_p0.set(init.x0, init.y0);
00092 m_p1.set(init.x1, init.y1);
00093 }
00094
00095
00096
00097 bool
00098 Line::getBoundingRect
00099 (
00100 OUT rect_t& r
00101 )
00102 const throw()
00103 {
00104 r.left = (m_p0.x < m_p1.x) ? m_p0.x : m_p1.x;
00105 r.right =(m_p0.x > m_p1.x) ? m_p0.x : m_p1.x;
00106
00107 r.top = (m_p0.y < m_p1.y) ? m_p0.y : m_p1.y;
00108 r.bottom = (m_p0.y > m_p1.y) ? m_p0.y : m_p1.y;
00109
00110 r.expand(0.05);
00111 return true;
00112 }
00113
00114
00115
00116 #define WRITE_L_FIELD(tag, q) { if (q) { stream << " " << #tag << " " << q; } }
00117
00118 void
00119 Line::persist
00120 (
00121 OUT std::ostream& stream
00122 )
00123 const
00124 {
00125 stream << "line id " << this->getID();
00126 WRITE_L_FIELD(x0, m_p0.x)
00127 WRITE_L_FIELD(y0, m_p0.y)
00128 WRITE_L_FIELD(x1, m_p1.x)
00129 WRITE_L_FIELD(y1, m_p1.y)
00130 }
00131
00132
00133
00134 void
00135 Line::draw
00136 (
00137 IN Drawer * drawer,
00138 IN const rect_t& r_cm,
00139 IN const xform_2d_t& T
00140 )
00141 {
00142 ASSERT(drawer, "null");
00143
00144 drawer->setTransform(T);
00145 drawer->drawLine(m_p0, m_p1);
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 #define SET_L_FIELD(x) init.x = atof(getOptionalValue(data, #x , "0.0"));
00157
00158 void
00159 init_line_from_data
00160 (
00161 IN const dictionary_t& data,
00162 OUT init_line_t& init
00163 )
00164 {
00165 init.id = getRequiredValue(data, "id");
00166
00167 SET_L_FIELD(x0)
00168 SET_L_FIELD(y0)
00169 SET_L_FIELD(x1)
00170 SET_L_FIELD(y1)
00171 }
00172
00173
00174
00175 smart_ptr<Primitive>
00176 create_line
00177 (
00178 IN const init_line_t& init
00179 )
00180 {
00181 smart_ptr<Line> local = new Line;
00182 ASSERT(local, "out of memory");
00183
00184 local->initialize(init);
00185
00186 return local;
00187 }
00188
00189
00190 };
00191