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 
00038 #include "drawer.h"
00039 
00040 #include "util/parsing.h"
00041 
00042 
00043 namespace vgfx {
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 class Text : public Primitive {
00052 public:
00053         ~Text(void) throw() { }
00054 
00055         
00056         void initialize(IN const init_text_t& init);
00057 
00058         
00059         const char * getType(void) const throw() { return "text"; }
00060         void persist(IO std::ostream& stream) const;
00061         void recalcBoundingRect(IN const char * tag_path,
00062                                 IN Drawer * drawer,
00063                                 IN const xform_2d_t& T);
00064         bool getBoundingRect(OUT rect_t& r) const throw();
00065         void draw(IN Drawer * drawer,
00066                                 IN const rect_t& r_cm,
00067                                 IN const xform_2d_t& T);
00068 
00069 private:
00070         std::string     m_text;
00071         rect_t          m_rect;         
00072 };
00073 
00074 
00075 
00076 
00077 
00078 
00079 
00080 
00081 
00082 void
00083 Text::initialize
00084 (
00085 IN const init_text_t& init
00086 )
00087 {
00088         this->setID(init.id.c_str());
00089         m_text = init.text;
00090 
00091 
00092 }
00093 
00094 
00095 
00096 
00097 
00098 
00099 
00100 
00101 
00102 void
00103 Text::draw
00104 (
00105 IN Drawer * drawer,
00106 IN const rect_t& r_cm,
00107 IN const xform_2d_t& T
00108 )
00109 {
00110         ASSERT(drawer, "null drawer");
00111 
00112         drawer->setTransform(T);
00113         drawer->drawText(m_rect, m_text.c_str());
00114 }
00115 
00116 
00117 
00118 void
00119 Text::persist
00120 (
00121 OUT std::ostream& out
00122 )
00123 const
00124 {
00125         out << "text id " << this->getID() << " text \"" << m_text << "\"";
00126 }
00127 
00128 
00129 
00130 void
00131 Text::recalcBoundingRect
00132 (
00133 IN const char * tag_path,
00134 IN Drawer * drawer,
00135 IN const xform_2d_t& T
00136 )
00137 {
00138         ASSERT(drawer, "null drawer");
00139 
00140         
00141         drawer->setTransform(T);
00142         drawer->getBoundingRect(m_text.c_str(), m_rect);
00143         m_rect.expand(0.05);    
00144 }
00145 
00146 
00147 
00148 bool
00149 Text::getBoundingRect
00150 (
00151 OUT rect_t& r
00152 )
00153 const throw()
00154 {
00155         r = m_rect;
00156         return true;
00157 }
00158 
00159 
00160 
00161 
00162 
00163 
00164 
00165 
00166 
00167 void
00168 init_text_from_data
00169 (
00170 IN const dictionary_t& data,
00171 OUT init_text_t& init
00172 )
00173 {
00174         init.id = getRequiredValue(data, "id");
00175         init.text = getRequiredValue(data, "text");
00176 }
00177 
00178 
00179 
00180 smart_ptr<Primitive>
00181 create_text
00182 (
00183 IN const init_text_t& init
00184 )
00185 {
00186         smart_ptr<Text> local = new Text;
00187         ASSERT(local, "out of memory");
00188 
00189         local->initialize(init);
00190 
00191         return local;
00192 }
00193 
00194 
00195 };      
00196