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[ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/tools/sg/text_valop (Version 11.3.0) and /externals/g4tools/include/tools/sg/text_valop (Version 11.1.1)


  1 // Copyright (C) 2010, Guy Barrand. All rights      1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.            2 // See the file tools.license for terms.
  3                                                     3 
  4 #ifndef tools_sg_text_valop                         4 #ifndef tools_sg_text_valop
  5 #define tools_sg_text_valop                         5 #define tools_sg_text_valop
  6                                                     6 
  7 #include "base_text"                                7 #include "base_text"
  8 #include "valop2sg"                                 8 #include "valop2sg"
  9 #include "nodekit"                                  9 #include "nodekit"
 10 #include "base_freetype"                           10 #include "base_freetype"
 11 #include "mnmx"                                    11 #include "mnmx"
 12 #include "../nostream"                             12 #include "../nostream"
 13                                                    13 
 14 namespace tools {                                  14 namespace tools {
 15 namespace sg {                                     15 namespace sg {
 16                                                    16 
 17 class text_valop : public base_text {              17 class text_valop : public base_text {
 18 public:                                            18 public:
 19   TOOLS_NODE(text_valop,tools::sg::text_valop,     19   TOOLS_NODE(text_valop,tools::sg::text_valop,base_text)
 20 public:                                            20 public:
 21   sf_string encoding;                              21   sf_string encoding;
 22   sf_string font;                                  22   sf_string font;
 23   sf_enum<sg::font_modeling> font_modeling;        23   sf_enum<sg::font_modeling> font_modeling;
 24 public:                                            24 public:
 25   virtual const desc_fields& node_desc_fields(     25   virtual const desc_fields& node_desc_fields() const {
 26     TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::tex     26     TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::text_valop)
 27     static const desc_fields s_v(parent::node_     27     static const desc_fields s_v(parent::node_desc_fields(),3, //WARNING : take care of count.
 28       TOOLS_ARG_FIELD_DESC(encoding),              28       TOOLS_ARG_FIELD_DESC(encoding),
 29       TOOLS_ARG_FIELD_DESC(font),                  29       TOOLS_ARG_FIELD_DESC(font),
 30       TOOLS_ARG_FIELD_DESC_ENUMS_BEG(font_mode     30       TOOLS_ARG_FIELD_DESC_ENUMS_BEG(font_modeling,3)
 31         TOOLS_ARG_ENUM(font_outline),              31         TOOLS_ARG_ENUM(font_outline),
 32         TOOLS_ARG_ENUM(font_filled),               32         TOOLS_ARG_ENUM(font_filled),
 33         TOOLS_ARG_ENUM(font_pixmap)                33         TOOLS_ARG_ENUM(font_pixmap)
 34       TOOLS_ARG_FIELD_DESC_ENUMS_END               34       TOOLS_ARG_FIELD_DESC_ENUMS_END
 35     );                                             35     );
 36     return s_v;                                    36     return s_v;
 37   }                                                37   }
 38 private:                                           38 private:
 39   void add_fields(){                               39   void add_fields(){
 40     add_field(&encoding);                          40     add_field(&encoding);
 41     add_field(&font);                              41     add_field(&font);
 42     add_field(&font_modeling);                     42     add_field(&font_modeling);
 43   }                                                43   }
 44 public:                                            44 public:
 45   virtual void render(render_action& a_action)     45   virtual void render(render_action& a_action) {
 46     if(touched()) {                                46     if(touched()) {
 47       update_sg(a_action.out());                   47       update_sg(a_action.out());
 48       reset_touched();                             48       reset_touched();
 49     }                                              49     }
 50     m_sep.render(a_action);                        50     m_sep.render(a_action);
 51   }                                                51   }
 52   virtual void pick(pick_action& a_action) {       52   virtual void pick(pick_action& a_action) {
 53     if(touched()) {                                53     if(touched()) {
 54       update_sg(a_action.out());                   54       update_sg(a_action.out());
 55       reset_touched();                             55       reset_touched();
 56     }                                              56     }
 57     nodekit_pick(a_action,m_sep,this);             57     nodekit_pick(a_action,m_sep,this);
 58   }                                                58   }
 59   virtual void bbox(bbox_action& a_action) {       59   virtual void bbox(bbox_action& a_action) {
 60     if(touched()) {                                60     if(touched()) {
 61       update_sg(a_action.out());                   61       update_sg(a_action.out());
 62       reset_touched();                             62       reset_touched();
 63     }                                              63     }
 64     m_sep.bbox(a_action);                          64     m_sep.bbox(a_action);
 65   }                                                65   }
 66   virtual void search(search_action& a_action)     66   virtual void search(search_action& a_action) {
 67     if(touched()) {                                67     if(touched()) {
 68       update_sg(a_action.out());                   68       update_sg(a_action.out());
 69       reset_touched();                             69       reset_touched();
 70     }                                              70     }
 71     parent::search(a_action);                      71     parent::search(a_action);
 72     if(a_action.done()) return;                    72     if(a_action.done()) return;
 73     if(a_action.do_path()) a_action.path_push(     73     if(a_action.do_path()) a_action.path_push(this);
 74     m_sep.search(a_action);                        74     m_sep.search(a_action);
 75     if(a_action.done()) return;                    75     if(a_action.done()) return;
 76     if(a_action.do_path()) a_action.path_pop()     76     if(a_action.do_path()) a_action.path_pop();
 77   }                                                77   }
 78 public:                                            78 public:
 79   text_valop(const base_freetype& a_ttf)           79   text_valop(const base_freetype& a_ttf)
 80   :parent()                                        80   :parent()
 81   ,encoding(encoding_none())                       81   ,encoding(encoding_none())
 82   ,font(font_hershey())                            82   ,font(font_hershey())
 83   ,font_modeling(font_filled)                      83   ,font_modeling(font_filled)
 84   ,m_ttf(a_ttf)                                    84   ,m_ttf(a_ttf)
 85   {                                                85   {
 86     add_fields();                                  86     add_fields();
 87   }                                                87   }
 88   virtual ~text_valop(){}                          88   virtual ~text_valop(){}
 89 public:                                            89 public:
 90   text_valop(const text_valop& a_from)             90   text_valop(const text_valop& a_from)
 91   :parent(a_from)                                  91   :parent(a_from)
 92   ,encoding(a_from.encoding)                       92   ,encoding(a_from.encoding)
 93   ,font(a_from.font)                               93   ,font(a_from.font)
 94   ,font_modeling(a_from.font_modeling)             94   ,font_modeling(a_from.font_modeling)
 95   ,m_ttf(a_from.m_ttf)                             95   ,m_ttf(a_from.m_ttf)
 96   {                                                96   {
 97     add_fields();                                  97     add_fields();
 98   }                                                98   }
 99   text_valop& operator=(const text_valop& a_fr     99   text_valop& operator=(const text_valop& a_from){
100     parent::operator=(a_from);                    100     parent::operator=(a_from);
101     encoding = a_from.encoding;                   101     encoding = a_from.encoding;
102     font = a_from.font;                           102     font = a_from.font;
103     font_modeling = a_from.font_modeling;         103     font_modeling = a_from.font_modeling;
104     return *this;                                 104     return *this;
105   }                                               105   }
106 public: //sg::base_text :                         106 public: //sg::base_text :
107   virtual void get_bounds(float /*a_height*/,     107   virtual void get_bounds(float /*a_height*/,
108                           float& a_mn_x,float&    108                           float& a_mn_x,float& a_mn_y,float& a_mn_z,
109                           float& a_mx_x,float&    109                           float& a_mx_x,float& a_mx_y,float& a_mx_z) const {
110     text_valop& self = const_cast<text_valop&>    110     text_valop& self = const_cast<text_valop&>(*this);
111     if(self.touched()) {                          111     if(self.touched()) {
112       self.update_sg(self.m_out);                 112       self.update_sg(self.m_out);
113       self.reset_touched();                       113       self.reset_touched();
114     }                                             114     }
115     vec3f mn,mx;                                  115     vec3f mn,mx;
116     mnmx(self.m_out,self.m_sep,mn,mx);            116     mnmx(self.m_out,self.m_sep,mn,mx);
117     a_mn_x = mn[0];a_mn_y = mn[1];a_mn_z = mn[    117     a_mn_x = mn[0];a_mn_y = mn[1];a_mn_z = mn[2];
118     a_mx_x = mx[0];a_mx_y = mx[1];a_mx_z = mx[    118     a_mx_x = mx[0];a_mx_y = mx[1];a_mx_z = mx[2];
119     //::printf("debug : get_bounds : %g %g %g     119     //::printf("debug : get_bounds : %g %g %g : %g %g %g\n",a_mn_x,a_mn_y,a_mn_z,a_mx_x,a_mx_y,a_mx_z);
120   }                                               120   }
121   virtual float ascent(float) const {return 1;    121   virtual float ascent(float) const {return 1;}
122   virtual float y_advance(float) const {return    122   virtual float y_advance(float) const {return 1;}
123   virtual float descent(float) const {return 0    123   virtual float descent(float) const {return 0;}
124   virtual bool truncate(const std::string&,flo    124   virtual bool truncate(const std::string&,float,float,std::string&) const {return false;}
125 protected:                                        125 protected:
126   void update_sg(std::ostream& a_out) {           126   void update_sg(std::ostream& a_out) {
127     m_sep.clear();                                127     m_sep.clear();
128     matrix* tsf = new matrix;                     128     matrix* tsf = new matrix;
129     m_sep.add(tsf);                               129     m_sep.add(tsf);
130     tools_vforcit(std::string,strings.values()    130     tools_vforcit(std::string,strings.values(),it) {
131       valop* _valop = new valop(valop::STRING,    131       valop* _valop = new valop(valop::STRING,*it);
132       valop2sg v(a_out,m_sep,m_ttf);              132       valop2sg v(a_out,m_sep,m_ttf);
133       if(!v.visit(*_valop)) {                     133       if(!v.visit(*_valop)) {
134         a_out << "tools::sg::text_valop::upate    134         a_out << "tools::sg::text_valop::upate_sg : valop2sg.visit() failed." << std::endl;
135         m_sep.clear();                            135         m_sep.clear();
136         delete _valop;                            136         delete _valop;
137         return;                                   137         return;
138       }                                           138       }
139       delete _valop;                              139       delete _valop;
140     }                                             140     }
141     vec3f mn,mx;                                  141     vec3f mn,mx;
142     mnmx(a_out,m_sep,mn,mx);                      142     mnmx(a_out,m_sep,mn,mx);
143     float h = mx[1]-mn[1];                        143     float h = mx[1]-mn[1];
144     if(!h) {                                      144     if(!h) {
145       a_out << "tools::sg::text_valop::upate_s    145       a_out << "tools::sg::text_valop::upate_sg : valop has null height." << std::endl;
146       m_sep.clear();                              146       m_sep.clear();
147       return;                                     147       return;
148     }                                             148     }
149     float scale = height.value()/h;               149     float scale = height.value()/h;
150     tsf->set_scale(scale,scale,1);                150     tsf->set_scale(scale,scale,1);
151   }                                               151   }
152 protected:                                        152 protected:
153   const base_freetype& m_ttf;                     153   const base_freetype& m_ttf;
154   separator m_sep;                                154   separator m_sep;
155   nostream m_out;                                 155   nostream m_out;
156 };                                                156 };
157                                                   157 
158 }}                                                158 }}
159                                                   159 
160 #endif                                            160 #endif