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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 9.4.p2)


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