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 Rectangle : public Primitive {
00054 public:
00055 ~Rectangle(void) throw() { }
00056
00057
00058 void initialize(IN const init_rect_t& init);
00059
00060
00061 virtual const char * getType(void) const throw() { return "rect"; }
00062 virtual void persist(OUT std::ostream& stream) const;
00063 virtual bool doesContainerExist(IN const VecString& path) const;
00064 virtual bool canCreateContainer(IN const VecString& path) const;
00065 virtual void removeContainer(IN const VecString& path);
00066 virtual void getContainerDictionary(IN const VecString& path,
00067 OUT dictionary_t& data) const;
00068 virtual void setContainerDictionary(IN const VecString& path,
00069 IN const dictionary_t& data);
00070 virtual void recalcBoundingRect(IN const char * tag_path,
00071 IN Drawer * drawer,
00072 IN const xform_2d_t& T) { }
00073 virtual bool getBoundingRect(OUT rect_t& r) const throw();
00074 virtual void draw(IN Drawer * drawer,
00075 IN const rect_t& r_cm,
00076 IN const xform_2d_t& T);
00077
00078 private:
00079 rect_t m_rect;
00080 bool m_fill;
00081 };
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 void
00092 Rectangle::initialize
00093 (
00094 IN const init_rect_t& init
00095 )
00096 {
00097 this->setID(init.id.c_str());
00098 m_rect = init.rect;
00099 m_fill = init.fill;
00100 }
00101
00102
00103
00104 bool
00105 Rectangle::getBoundingRect
00106 (
00107 OUT rect_t& r
00108 )
00109 const throw()
00110 {
00111 r = m_rect;
00112 return true;
00113 }
00114
00115
00116
00117 #define WRITE_R_FIELD(q) { if (m_rect.q) { stream << " " << #q << " " << m_rect.q; } }
00118
00119 void
00120 Rectangle::persist
00121 (
00122 OUT std::ostream& stream
00123 )
00124 const
00125 {
00126 stream << "rect id " << this->getID();
00127 WRITE_R_FIELD(left)
00128 WRITE_R_FIELD(top)
00129 WRITE_R_FIELD(right)
00130 WRITE_R_FIELD(bottom)
00131
00132 if (m_fill) {
00133 stream << " fill true";
00134 }
00135 }
00136
00137
00138
00139 bool
00140 Rectangle::doesContainerExist
00141 (
00142 IN const VecString& path
00143 )
00144 const
00145 {
00146 if (path.size() > 0) {
00147 return false;
00148 }
00149 return true;
00150 }
00151
00152
00153 bool
00154 Rectangle::canCreateContainer
00155 (
00156 IN const VecString& path
00157 )
00158 const
00159 {
00160 return false;
00161 }
00162
00163
00164 void
00165 Rectangle::removeContainer
00166 (
00167 IN const VecString& path
00168 )
00169 {
00170 WAVE_EX(wex);
00171 wex << "rectangles have no removable containers";
00172 }
00173
00174
00175
00176 #define ADD_R_VALUE(q) { data[ #q ] = getStringValue( m_rect.q ); }
00177
00178 void
00179 Rectangle::getContainerDictionary
00180 (
00181 IN const VecString& path,
00182 OUT dictionary_t& data
00183 )
00184 const
00185 {
00186 if (path.size() > 0) {
00187 WAVE_EX(wex);
00188 wex << "Rectangles do not support subcontainers";
00189 }
00190
00191 data.clear();
00192 ADD_R_VALUE(left)
00193 ADD_R_VALUE(top)
00194 ADD_R_VALUE(right)
00195 ADD_R_VALUE(bottom)
00196 }
00197
00198
00199
00200 #define CHECK_R_VALUE(q) { if (!strcmp(name, #q )) { m_rect.q = atof(value); continue; } }
00201
00202 void
00203 Rectangle::setContainerDictionary
00204 (
00205 IN const VecString& path,
00206 IN const dictionary_t& data
00207 )
00208 {
00209 if (path.size() > 0) {
00210 WAVE_EX(wex);
00211 wex << "Rectangles do not support subcontainers";
00212 }
00213
00214 for (dictionary_t::const_iterator i = data.begin(); i != data.end();
00215 ++i) {
00216 const char * name = i->first.c_str();
00217 const char * value = i->second.c_str();
00218
00219 CHECK_R_VALUE(left)
00220 CHECK_R_VALUE(top)
00221 CHECK_R_VALUE(right)
00222 CHECK_R_VALUE(bottom)
00223
00224 {
00225 WAVE_EX(wex);
00226 wex << "Invalid property for rect curve: '";
00227 wex << name << "'";
00228 }
00229 }
00230 }
00231
00232
00233
00234 void
00235 Rectangle::draw
00236 (
00237 IN Drawer * drawer,
00238 IN const rect_t& r_cm,
00239 IN const xform_2d_t& T
00240 )
00241 {
00242 ASSERT(drawer, "null");
00243
00244 drawer->setTransform(T);
00245 if (m_fill)
00246 drawer->fillRect(m_rect);
00247 else
00248 drawer->drawRect(m_rect);
00249 }
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 #define SET_R_FIELD(x) init.rect.x = atof(getOptionalValue(data, #x , "0.0"));
00260
00261 void
00262 init_rect_from_data
00263 (
00264 IN const dictionary_t& data,
00265 OUT init_rect_t& init
00266 )
00267 {
00268 init.id = getRequiredValue(data, "id");
00269
00270 SET_R_FIELD(left)
00271 SET_R_FIELD(top)
00272 SET_R_FIELD(right)
00273 SET_R_FIELD(bottom)
00274
00275 init.fill = !strcmp("true", getOptionalValue(data, "fill", "false"));
00276 }
00277
00278
00279
00280 smart_ptr<Primitive>
00281 create_rect
00282 (
00283 IN const init_rect_t& init
00284 )
00285 {
00286 smart_ptr<Rectangle> local = new Rectangle;
00287 ASSERT(local, "out of memory");
00288
00289 local->initialize(init);
00290
00291 return local;
00292 }
00293
00294
00295 };
00296