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 "bezier/quad.h"
00040 #include "common/wave_ex.h"
00041 #include "perf/perf.h"
00042 #include "util/parsing.h"
00043
00044
00045
00046 namespace vgfx {
00047
00048
00049
00050
00051
00052
00053
00054 class Quad : public Primitive {
00055 public:
00056 ~Quad(void) throw() { }
00057
00058
00059 void initialize(IN const init_quad_t& init);
00060
00061
00062 virtual const char * getType(void) const throw() { return "quad"; }
00063 virtual void persist(OUT std::ostream& stream) const;
00064 virtual void getContainerDictionary(IN const VecString& path,
00065 OUT dictionary_t& data) const;
00066 virtual void recalcBoundingRect(IN const char * tag_path,
00067 IN Drawer * drawer,
00068 IN const xform_2d_t& T) { }
00069 virtual bool getBoundingRect(OUT rect_t& r) const throw();
00070 virtual void draw(IN Drawer * drawer,
00071 IN const rect_t& r_cm,
00072 IN const xform_2d_t& T);
00073
00074 private:
00075 bezier::quad_bezier_t m_quad;
00076 rect_t m_rect;
00077 };
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 void
00088 Quad::initialize
00089 (
00090 IN const init_quad_t& init
00091 )
00092 {
00093 this->setID(init.id.c_str());
00094 m_quad = init.quad;
00095 }
00096
00097
00098
00099 bool
00100 Quad::getBoundingRect
00101 (
00102 OUT rect_t& r
00103 )
00104 const throw()
00105 {
00106 m_quad.getBoundingRect(r);
00107 r.expand(0.05);
00108 return true;
00109 }
00110
00111
00112
00113 #define WRITE_L_FIELD(tag, q) { if (q) { stream << " " << #tag << " " << q; } }
00114
00115 void
00116 Quad::persist
00117 (
00118 OUT std::ostream& stream
00119 )
00120 const
00121 {
00122 stream << "quad id " << this->getID();
00123 WRITE_L_FIELD(x0, m_quad.p0.x)
00124 WRITE_L_FIELD(y0, m_quad.p0.y)
00125 WRITE_L_FIELD(x1, m_quad.p1.x)
00126 WRITE_L_FIELD(y1, m_quad.p1.y)
00127 WRITE_L_FIELD(x2, m_quad.p2.x)
00128 WRITE_L_FIELD(y2, m_quad.p2.y)
00129 }
00130
00131
00132
00133 void
00134 Quad::getContainerDictionary
00135 (
00136 IN const VecString& path,
00137 OUT dictionary_t& data
00138 )
00139 const
00140 {
00141 ASSERT(0 == path.size(),
00142 "quads only have zero-size dictionaries!");
00143
00144
00145 data.clear();
00146 data["x0"] = getStringValue(m_quad.p0.x);
00147 data["y0"] = getStringValue(m_quad.p0.y);
00148 data["x2"] = getStringValue(m_quad.p2.x);
00149 data["y2"] = getStringValue(m_quad.p2.y);
00150 }
00151
00152
00153
00154 void
00155 Quad::draw
00156 (
00157 IN Drawer * drawer,
00158 IN const rect_t& r_cm,
00159 IN const xform_2d_t& T
00160 )
00161 {
00162 ASSERT(drawer, "null");
00163
00164 drawer->setTransform(T);
00165 drawer->drawQuadBezier(m_quad);
00166 }
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 #define SET_L_FIELD(x, tag) init.quad.x = atof(getOptionalValue(data, #tag , "0.0"));
00177
00178 void
00179 init_quad_from_data
00180 (
00181 IN const dictionary_t& data,
00182 OUT init_quad_t& init
00183 )
00184 {
00185 init.id = getRequiredValue(data, "id");
00186
00187 SET_L_FIELD(p0.x, x0)
00188 SET_L_FIELD(p0.y, y0)
00189 SET_L_FIELD(p1.x, x1)
00190 SET_L_FIELD(p1.y, y1)
00191 SET_L_FIELD(p2.x, x2)
00192 SET_L_FIELD(p2.y, y2)
00193 }
00194
00195
00196
00197 smart_ptr<Primitive>
00198 create_quad
00199 (
00200 IN const init_quad_t& init
00201 )
00202 {
00203 smart_ptr<Quad> local = new Quad;
00204 ASSERT(local, "out of memory");
00205
00206 local->initialize(init);
00207
00208 return local;
00209 }
00210
00211
00212 };
00213