Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/externals/g4tools/include/tools/sg/infos_box

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 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/infos_box (Version 11.3.0) and /externals/g4tools/include/tools/sg/infos_box (Version 11.2.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_infos_box                          4 #ifndef tools_sg_infos_box
  5 #define tools_sg_infos_box                          5 #define tools_sg_infos_box
  6                                                     6 
  7 //                                                  7 //
  8 // In z the scene is within [0,0.5]                 8 // In z the scene is within [0,0.5]
  9 //                                                  9 //
 10                                                    10 
 11 #include "back_area"                               11 #include "back_area"
 12 #include "matrix"                                  12 #include "matrix"
 13 #include "text_hershey"                            13 #include "text_hershey"
 14 #include "base_freetype"                           14 #include "base_freetype"
 15 #include "enums"                                   15 #include "enums"
 16                                                    16 
 17 #include "../colorf"                               17 #include "../colorf"
 18                                                    18 
 19 namespace tools {                                  19 namespace tools {
 20 namespace sg {                                     20 namespace sg {
 21                                                    21 
 22 class infos_box : public back_area {               22 class infos_box : public back_area {
 23   TOOLS_NODE(infos_box,tools::sg::infos_box,ba     23   TOOLS_NODE(infos_box,tools::sg::infos_box,back_area)
 24 public:                                            24 public:
 25   mf_string lstrings;                              25   mf_string lstrings;
 26   mf_string rstrings;                              26   mf_string rstrings;
 27   sf<unsigned int> num_spaces; //in "number of     27   sf<unsigned int> num_spaces; //in "number of one line height" unit.
 28                                                    28 
 29   sf_vec<colorf,float> color;                      29   sf_vec<colorf,float> color;
 30   sf_string font;                                  30   sf_string font;
 31   sf_enum<sg::font_modeling> font_modeling;        31   sf_enum<sg::font_modeling> font_modeling;
 32   sf_string encoding;                              32   sf_string encoding;
 33   sf<float> line_width; // for text_hershey.       33   sf<float> line_width; // for text_hershey.
 34   sf_enum<winding_type> front_face; //no more      34   sf_enum<winding_type> front_face; //no more used.
 35                                                    35 
 36   sf<bool> back_visible;                           36   sf<bool> back_visible;
 37   sf<float> wmargin_factor;                        37   sf<float> wmargin_factor;
 38   sf<float> hmargin_factor;                        38   sf<float> hmargin_factor;
 39   sf_enum<hjust> lhjust;                           39   sf_enum<hjust> lhjust;
 40   sf_enum<hjust> rhjust;                           40   sf_enum<hjust> rhjust;
 41   sf<bool> confine;                                41   sf<bool> confine;
 42 public:                                            42 public:
 43   virtual const desc_fields& node_desc_fields(     43   virtual const desc_fields& node_desc_fields() const {
 44     TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::inf     44     TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::infos_box)
 45     static const desc_fields s_v(parent::node_     45     static const desc_fields s_v(parent::node_desc_fields(),15, //WARNING : take care of count.
 46       TOOLS_ARG_FIELD_DESC(lstrings),              46       TOOLS_ARG_FIELD_DESC(lstrings),
 47       TOOLS_ARG_FIELD_DESC(rstrings),              47       TOOLS_ARG_FIELD_DESC(rstrings),
 48       TOOLS_ARG_FIELD_DESC(num_spaces),            48       TOOLS_ARG_FIELD_DESC(num_spaces),
 49       TOOLS_ARG_FIELD_DESC(color),                 49       TOOLS_ARG_FIELD_DESC(color),
 50                                                    50 
 51       TOOLS_ARG_FIELD_DESC_OPTS_BEG(font,10)       51       TOOLS_ARG_FIELD_DESC_OPTS_BEG(font,10)
 52         font_hershey().c_str(),                    52         font_hershey().c_str(),
 53         font_lato_regular_ttf().c_str(),           53         font_lato_regular_ttf().c_str(),
 54         font_roboto_bold_ttf().c_str(),            54         font_roboto_bold_ttf().c_str(),
 55         font_arial_ttf().c_str(),                  55         font_arial_ttf().c_str(),
 56         font_arialbd_ttf().c_str(),                56         font_arialbd_ttf().c_str(),
 57         font_timesbd_ttf().c_str(),                57         font_timesbd_ttf().c_str(),
 58         font_symbol_ttf().c_str(),                 58         font_symbol_ttf().c_str(),
 59         font_stixgeneral_otf().c_str(),            59         font_stixgeneral_otf().c_str(),
 60         font_helvetica_ttf().c_str(),              60         font_helvetica_ttf().c_str(),
 61         font_times_roman_ttf().c_str()             61         font_times_roman_ttf().c_str()
 62       TOOLS_ARG_FIELD_DESC_OPTS_END,               62       TOOLS_ARG_FIELD_DESC_OPTS_END,
 63                                                    63 
 64       TOOLS_ARG_FIELD_DESC_ENUMS_BEG(font_mode     64       TOOLS_ARG_FIELD_DESC_ENUMS_BEG(font_modeling,3)
 65         TOOLS_ARG_ENUM(font_outline),              65         TOOLS_ARG_ENUM(font_outline),
 66         TOOLS_ARG_ENUM(font_filled),               66         TOOLS_ARG_ENUM(font_filled),
 67         TOOLS_ARG_ENUM(font_pixmap)                67         TOOLS_ARG_ENUM(font_pixmap)
 68       TOOLS_ARG_FIELD_DESC_ENUMS_END,              68       TOOLS_ARG_FIELD_DESC_ENUMS_END,
 69                                                    69 
 70       TOOLS_ARG_FIELD_DESC(encoding),              70       TOOLS_ARG_FIELD_DESC(encoding),
 71       TOOLS_ARG_FIELD_DESC(line_width),            71       TOOLS_ARG_FIELD_DESC(line_width),
 72       TOOLS_ARG_FIELD_DESC(front_face),            72       TOOLS_ARG_FIELD_DESC(front_face),
 73                                                    73 
 74       TOOLS_ARG_FIELD_DESC(back_visible), //10     74       TOOLS_ARG_FIELD_DESC(back_visible), //10
 75       TOOLS_ARG_FIELD_DESC(wmargin_factor),        75       TOOLS_ARG_FIELD_DESC(wmargin_factor),
 76       TOOLS_ARG_FIELD_DESC(hmargin_factor),        76       TOOLS_ARG_FIELD_DESC(hmargin_factor),
 77       TOOLS_ARG_FIELD_DESC(lhjust),                77       TOOLS_ARG_FIELD_DESC(lhjust),
 78       TOOLS_ARG_FIELD_DESC(rhjust),                78       TOOLS_ARG_FIELD_DESC(rhjust),
 79       TOOLS_ARG_FIELD_DESC(confine)                79       TOOLS_ARG_FIELD_DESC(confine)
 80     );                                             80     );
 81     return s_v;                                    81     return s_v;
 82   }                                                82   }
 83 private:                                           83 private:
 84   void add_fields(){                               84   void add_fields(){
 85     add_field(&lstrings);                          85     add_field(&lstrings);
 86     add_field(&rstrings);                          86     add_field(&rstrings);
 87     add_field(&num_spaces);                        87     add_field(&num_spaces);
 88                                                    88 
 89     add_field(&color);                             89     add_field(&color);
 90     add_field(&font);                              90     add_field(&font);
 91     add_field(&font_modeling);                     91     add_field(&font_modeling);
 92     add_field(&encoding);                          92     add_field(&encoding);
 93     add_field(&line_width);                        93     add_field(&line_width);
 94     add_field(&front_face);                        94     add_field(&front_face);
 95                                                    95 
 96     add_field(&back_visible);                      96     add_field(&back_visible);
 97     add_field(&wmargin_factor);                    97     add_field(&wmargin_factor);
 98     add_field(&hmargin_factor);                    98     add_field(&hmargin_factor);
 99     add_field(&lhjust);                            99     add_field(&lhjust);
100     add_field(&rhjust);                           100     add_field(&rhjust);
101     add_field(&confine);                          101     add_field(&confine);
102   }                                               102   }
103 public:                                           103 public:
104   virtual void render(render_action& a_action)    104   virtual void render(render_action& a_action) {
105     if(touched()) {                               105     if(touched()) {
106       update_sg();                                106       update_sg();
107       reset_touched();                            107       reset_touched();
108     }                                             108     }
109     if(back_visible.value()) m_back_sep.render    109     if(back_visible.value()) m_back_sep.render(a_action);
110     m_sep.render(a_action);                       110     m_sep.render(a_action);
111   }                                               111   }
112   virtual void pick(pick_action& a_action) {      112   virtual void pick(pick_action& a_action) {
113     if(touched()) {                               113     if(touched()) {
114       update_sg();                                114       update_sg();
115       reset_touched();                            115       reset_touched();
116     }                                             116     }
117     if(back_visible.value()) {                    117     if(back_visible.value()) {
118       m_back_sep.pick(a_action);                  118       m_back_sep.pick(a_action);
119       if(a_action.done()) return;                 119       if(a_action.done()) return;
120     }                                             120     }
121   }                                               121   }
122   virtual void search(search_action& a_action)    122   virtual void search(search_action& a_action) {
123     if(touched()) {                               123     if(touched()) {
124       update_sg();                                124       update_sg();
125       reset_touched();                            125       reset_touched();
126     }                                             126     }
127     node::search(a_action);                       127     node::search(a_action);
128     if(a_action.done()) return;                   128     if(a_action.done()) return;
129     if(back_visible.value()) {                    129     if(back_visible.value()) {
130       m_back_sep.search(a_action);                130       m_back_sep.search(a_action);
131       if(a_action.done()) return;                 131       if(a_action.done()) return;
132     }                                             132     }
133     m_sep.search(a_action);                       133     m_sep.search(a_action);
134     if(a_action.done()) return;                   134     if(a_action.done()) return;
135   }                                               135   }
136   virtual bool write(write_action& a_action) {    136   virtual bool write(write_action& a_action) {
137     if(touched()) {                               137     if(touched()) {
138       update_sg();                                138       update_sg();
139       reset_touched();                            139       reset_touched();
140     }                                             140     }
141     if(back_visible.value()) if(!m_back_sep.wr    141     if(back_visible.value()) if(!m_back_sep.write(a_action)) return false;
142     return m_sep.write(a_action);                 142     return m_sep.write(a_action);
143   }                                               143   }
144   virtual void bbox(bbox_action& a_action) {      144   virtual void bbox(bbox_action& a_action) {
145     if(touched()) {                               145     if(touched()) {
146       update_sg();                                146       update_sg();
147       reset_touched();                            147       reset_touched();
148     }                                             148     }
149     if(back_visible.value()) m_back_sep.bbox(a    149     if(back_visible.value()) m_back_sep.bbox(a_action);
150     m_sep.bbox(a_action);                         150     m_sep.bbox(a_action);
151   }                                               151   }
152 public:                                           152 public:
153   infos_box(const base_freetype& a_ttf)           153   infos_box(const base_freetype& a_ttf)
154   :parent()                                       154   :parent()
155   ,lstrings()                                     155   ,lstrings()
156   ,rstrings()                                     156   ,rstrings()
157   ,num_spaces(4)                                  157   ,num_spaces(4)
158                                                   158 
159   ,color(colorf_black())                          159   ,color(colorf_black())
160   ,font(font_hershey())                           160   ,font(font_hershey())
161   ,font_modeling(font_filled)                     161   ,font_modeling(font_filled)
162   ,encoding(encoding_PAW())                       162   ,encoding(encoding_PAW())
163   ,line_width(1)                                  163   ,line_width(1)
164   ,front_face(winding_ccw)                        164   ,front_face(winding_ccw)
165                                                   165 
166   ,back_visible(true)                             166   ,back_visible(true)
167   ,wmargin_factor(0.9f)                           167   ,wmargin_factor(0.9f)
168   ,hmargin_factor(0.9f)                           168   ,hmargin_factor(0.9f)
169   ,lhjust(left)                                   169   ,lhjust(left)
170   ,rhjust(right)                                  170   ,rhjust(right)
171                                                   171 
172   ,confine(false)                                 172   ,confine(false)
173                                                   173 
174   ,m_ttf(a_ttf)                                   174   ,m_ttf(a_ttf)
175   {                                               175   {
176     add_fields();                                 176     add_fields();
177   }                                               177   }
178   virtual ~infos_box(){}                          178   virtual ~infos_box(){}
179 public:                                           179 public:
180   infos_box(const infos_box& a_from)              180   infos_box(const infos_box& a_from)
181   :parent(a_from)                                 181   :parent(a_from)
182   ,lstrings(a_from.lstrings)                      182   ,lstrings(a_from.lstrings)
183   ,rstrings(a_from.rstrings)                      183   ,rstrings(a_from.rstrings)
184   ,num_spaces(a_from.num_spaces)                  184   ,num_spaces(a_from.num_spaces)
185                                                   185 
186   ,color(a_from.color)                            186   ,color(a_from.color)
187   ,font(a_from.font)                              187   ,font(a_from.font)
188   ,font_modeling(a_from.font_modeling)            188   ,font_modeling(a_from.font_modeling)
189   ,encoding(a_from.encoding)                      189   ,encoding(a_from.encoding)
190   ,line_width(a_from.line_width)                  190   ,line_width(a_from.line_width)
191   ,front_face(a_from.front_face)                  191   ,front_face(a_from.front_face)
192                                                   192 
193   ,back_visible(a_from.back_visible)              193   ,back_visible(a_from.back_visible)
194   ,wmargin_factor(a_from.wmargin_factor)          194   ,wmargin_factor(a_from.wmargin_factor)
195   ,hmargin_factor(a_from.hmargin_factor)          195   ,hmargin_factor(a_from.hmargin_factor)
196   ,lhjust(a_from.lhjust)                          196   ,lhjust(a_from.lhjust)
197   ,rhjust(a_from.rhjust)                          197   ,rhjust(a_from.rhjust)
198                                                   198 
199   ,confine(a_from.confine)                        199   ,confine(a_from.confine)
200                                                   200 
201   ,m_ttf(a_from.m_ttf)                            201   ,m_ttf(a_from.m_ttf)
202   {                                               202   {
203     add_fields();                                 203     add_fields();
204   }                                               204   }
205   infos_box& operator=(const infos_box& a_from    205   infos_box& operator=(const infos_box& a_from){
206     parent::operator=(a_from);                    206     parent::operator=(a_from);
207     lstrings = a_from.lstrings;                   207     lstrings = a_from.lstrings;
208     rstrings = a_from.rstrings;                   208     rstrings = a_from.rstrings;
209     num_spaces = a_from.num_spaces;               209     num_spaces = a_from.num_spaces;
210                                                   210 
211     color = a_from.color;                         211     color = a_from.color;
212     font = a_from.font;                           212     font = a_from.font;
213     font_modeling = a_from.font_modeling;         213     font_modeling = a_from.font_modeling;
214     encoding = a_from.encoding;                   214     encoding = a_from.encoding;
215     line_width = a_from.line_width;               215     line_width = a_from.line_width;
216     front_face = a_from.front_face;               216     front_face = a_from.front_face;
217                                                   217 
218     back_visible = a_from.back_visible;           218     back_visible = a_from.back_visible;
219     wmargin_factor = a_from.wmargin_factor;       219     wmargin_factor = a_from.wmargin_factor;
220     hmargin_factor = a_from.hmargin_factor;       220     hmargin_factor = a_from.hmargin_factor;
221     lhjust = a_from.lhjust;                       221     lhjust = a_from.lhjust;
222     rhjust = a_from.rhjust;                       222     rhjust = a_from.rhjust;
223                                                   223 
224     confine = a_from.confine;                     224     confine = a_from.confine;
225                                                   225 
226     return *this;                                 226     return *this;
227   }                                               227   }
228 public:                                           228 public:
229   void update_sg() {                              229   void update_sg() {
230     // have this method public in order to use    230     // have this method public in order to use it in plotter.
231     // This is so because infos_box::height is    231     // This is so because infos_box::height is an output field
232     // needed in plotter to place the box.        232     // needed in plotter to place the box.
233                                                   233 
234     m_back_sep.clear(); //back_area::update_sg    234     m_back_sep.clear(); //back_area::update_sg done last.
235                                                   235 
236     m_sep.clear();                                236     m_sep.clear();
237                                                   237 
238     if(width.value()<=0) return;                  238     if(width.value()<=0) return;
239     if(confine) {                                 239     if(confine) {
240       if(height.value()<=0) return;               240       if(height.value()<=0) return;
241     }                                             241     }
242                                                   242 
243    {bool empty = true;                            243    {bool empty = true;
244     std::vector<std::string>::const_iterator i    244     std::vector<std::string>::const_iterator it;
245     for(it=lstrings.values().begin();it!=lstri    245     for(it=lstrings.values().begin();it!=lstrings.values().end();++it) {
246       if((*it).size()) {empty = false;break;}     246       if((*it).size()) {empty = false;break;}
247     }                                             247     }
248     if(empty){                                    248     if(empty){
249       for(it=rstrings.values().begin();it!=rst    249       for(it=rstrings.values().begin();it!=rstrings.values().end();++it) {
250         if((*it).size()) {empty = false;break;    250         if((*it).size()) {empty = false;break;}
251       }                                           251       }
252     }                                             252     }
253     if(empty) {                                   253     if(empty) {
254       //parent::update_sg();                      254       //parent::update_sg();
255       return;                                     255       return;
256     }}                                            256     }}
257                                                   257 
258     rgba* mat = new rgba();                       258     rgba* mat = new rgba();
259     mat->color = color;                           259     mat->color = color;
260     m_sep.add(mat);                               260     m_sep.add(mat);
261                                                   261 
262     if(font==font_hershey()) {                    262     if(font==font_hershey()) {
263       draw_style* ds = new draw_style;            263       draw_style* ds = new draw_style;
264       ds->style.value(draw_lines);                264       ds->style.value(draw_lines);
265       //ds->line_pattern = line_pattern;          265       //ds->line_pattern = line_pattern;
266       ds->line_width = line_width;                266       ds->line_width = line_width;
267       m_sep.add(ds);                              267       m_sep.add(ds);
268     }                                             268     }
269                                                   269 
270     //////////////////////////////////////////    270     ////////////////////////////////////////////////////////////
271     /// left text ////////////////////////////    271     /// left text //////////////////////////////////////////////
272     //////////////////////////////////////////    272     ////////////////////////////////////////////////////////////
273     base_text* ltext = 0;                         273     base_text* ltext = 0;
274     matrix* ltsf = 0;                             274     matrix* ltsf = 0;
275                                                   275 
276    {separator* sep = new separator;               276    {separator* sep = new separator;
277     m_sep.add(sep);                               277     m_sep.add(sep);
278     ltsf = new matrix;                            278     ltsf = new matrix;
279     sep->add(ltsf);                               279     sep->add(ltsf);
280     if(font==font_hershey()) {                    280     if(font==font_hershey()) {
281       text_hershey* text = new text_hershey;      281       text_hershey* text = new text_hershey;
282       ltext = text;                               282       ltext = text;
283       text->encoding = encoding;                  283       text->encoding = encoding;
284       sep->add(text);                             284       sep->add(text);
285     } else {                                      285     } else {
286       base_freetype* text = base_freetype::cre    286       base_freetype* text = base_freetype::create(m_ttf);
287       //TTNODE* text = new TTNODE;                287       //TTNODE* text = new TTNODE;
288       ltext = text;                               288       ltext = text;
289       text->font = font;                          289       text->font = font;
290       text->modeling = font_modeling;             290       text->modeling = font_modeling;
291       sep->add(text);                             291       sep->add(text);
292     }                                             292     }
293     ltext->strings = lstrings;                    293     ltext->strings = lstrings;
294     ltext->hjust = lhjust;}                       294     ltext->hjust = lhjust;}
295                                                   295 
296     //////////////////////////////////////////    296     ////////////////////////////////////////////////////////////
297     /// right text ///////////////////////////    297     /// right text /////////////////////////////////////////////
298     //////////////////////////////////////////    298     ////////////////////////////////////////////////////////////
299     base_text* rtext = 0;                         299     base_text* rtext = 0;
300     matrix* rtsf = 0;                             300     matrix* rtsf = 0;
301                                                   301 
302    {separator* sep = new separator;               302    {separator* sep = new separator;
303     m_sep.add(sep);                               303     m_sep.add(sep);
304     rtsf = new matrix;                            304     rtsf = new matrix;
305     sep->add(rtsf);                               305     sep->add(rtsf);
306     if(font==font_hershey()) {                    306     if(font==font_hershey()) {
307       text_hershey* text = new text_hershey;      307       text_hershey* text = new text_hershey;
308       rtext = text;                               308       rtext = text;
309       text->encoding = encoding;                  309       text->encoding = encoding;
310       sep->add(text);                             310       sep->add(text);
311     } else {                                      311     } else {
312       base_freetype* text = base_freetype::cre    312       base_freetype* text = base_freetype::create(m_ttf);
313       //TTNODE* text = new TTNODE;                313       //TTNODE* text = new TTNODE;
314       rtext = text;                               314       rtext = text;
315       text->font = font;                          315       text->font = font;
316       text->modeling = font_modeling;             316       text->modeling = font_modeling;
317       sep->add(text);                             317       sep->add(text);
318     }                                             318     }
319     rtext->strings = rstrings;                    319     rtext->strings = rstrings;
320     rtext->hjust = rhjust;}                       320     rtext->hjust = rhjust;}
321                                                   321 
322     //////////////////////////////////////////    322     ////////////////////////////////////////////////////////////
323     /// middle spaces ////////////////////////    323     /// middle spaces //////////////////////////////////////////
324     //////////////////////////////////////////    324     ////////////////////////////////////////////////////////////
325     base_text* mtext = 0;                         325     base_text* mtext = 0;
326    {std::string _s(num_spaces,' ');               326    {std::string _s(num_spaces,' ');
327     if(font==font_hershey()) {                    327     if(font==font_hershey()) {
328       text_hershey* text = new text_hershey;      328       text_hershey* text = new text_hershey;
329       mtext = text;                               329       mtext = text;
330       text->strings.add(_s);                      330       text->strings.add(_s);
331       text->hjust = left;                         331       text->hjust = left;
332     } else {                                      332     } else {
333       base_freetype* text = base_freetype::cre    333       base_freetype* text = base_freetype::create(m_ttf);
334       //TTNODE* text = new TTNODE;                334       //TTNODE* text = new TTNODE;
335       mtext = text;                               335       mtext = text;
336       text->strings.add(_s);                      336       text->strings.add(_s);
337       text->hjust = left;                         337       text->hjust = left;
338       text->font = font;                          338       text->font = font;
339       text->modeling = font_modeling;             339       text->modeling = font_modeling;
340     }}                                            340     }}
341                                                   341 
342     //sf<float> zfront ?                          342     //sf<float> zfront ?
343     float zz = back_visible.value()?0.01f:0;      343     float zz = back_visible.value()?0.01f:0;
344                                                   344 
345     float fw = width * wmargin_factor;            345     float fw = width * wmargin_factor;
346                                                   346 
347     if(confine) {                                 347     if(confine) {
348       // left right texts may overlap.            348       // left right texts may overlap.
349                                                   349 
350       // adjust height :                          350       // adjust height :
351       float fh = height * hmargin_factor;         351       float fh = height * hmargin_factor;
352       float th = fh;                              352       float th = fh;
353      {float mn_x,mn_y,mn_z;                       353      {float mn_x,mn_y,mn_z;
354       float mx_x,mx_y,mx_z;                       354       float mx_x,mx_y,mx_z;
355       ltext->get_bounds(th,mn_x,mn_y,mn_z,mx_x    355       ltext->get_bounds(th,mn_x,mn_y,mn_z,mx_x,mx_y,mx_z);
356       float bxh = mx_y-mn_y;                      356       float bxh = mx_y-mn_y;
357       // adjust box height :                      357       // adjust box height :
358       // fh -> bxh then to have fh :              358       // fh -> bxh then to have fh :
359       if(!bxh) {                                  359       if(!bxh) {
360         m_sep.clear();                            360         m_sep.clear();
361         parent::update_sg();                      361         parent::update_sg();
362         delete mtext;                             362         delete mtext;
363         return;                                   363         return;
364       }                                           364       }
365       th = fh*fh/bxh;}                            365       th = fh*fh/bxh;}
366                                                   366 
367       ltext->height = th;                         367       ltext->height = th;
368       rtext->height = th;                         368       rtext->height = th;
369                                                   369 
370      {float mn_x,mn_y,mn_z;                       370      {float mn_x,mn_y,mn_z;
371       float mx_x,mx_y,mx_z;                       371       float mx_x,mx_y,mx_z;
372       ltext->get_bounds(th,mn_x,mn_y,mn_z,mx_x    372       ltext->get_bounds(th,mn_x,mn_y,mn_z,mx_x,mx_y,mx_z);
373       float lw = mx_x-mn_x;                       373       float lw = mx_x-mn_x;
374       float xtrans = (fw-lw)*0.5f; //left just    374       float xtrans = (fw-lw)*0.5f; //left justified
375       float xx = -(mn_x+mx_x)*0.5F-xtrans;        375       float xx = -(mn_x+mx_x)*0.5F-xtrans;
376       float yy = -(mn_y+mx_y)*0.5F;               376       float yy = -(mn_y+mx_y)*0.5F;
377       ltsf->set_translate(xx,yy,zz);}             377       ltsf->set_translate(xx,yy,zz);}
378                                                   378 
379      {float mn_x,mn_y,mn_z;                       379      {float mn_x,mn_y,mn_z;
380       float mx_x,mx_y,mx_z;                       380       float mx_x,mx_y,mx_z;
381       rtext->get_bounds(th,mn_x,mn_y,mn_z,mx_x    381       rtext->get_bounds(th,mn_x,mn_y,mn_z,mx_x,mx_y,mx_z);
382       rtext->hjust = right;                       382       rtext->hjust = right;
383       float xx = fw*0.5f;                         383       float xx = fw*0.5f;
384       float yy = -(mn_y+mx_y)*0.5F;               384       float yy = -(mn_y+mx_y)*0.5F;
385       rtsf->set_translate(xx,yy,zz);}             385       rtsf->set_translate(xx,yy,zz);}
386                                                   386 
387       parent::update_sg();                        387       parent::update_sg();
388                                                   388 
389     } else {                                      389     } else {
390       // height of the info box is an output o    390       // height of the info box is an output of the below.
391       // The input to compute the geometry is     391       // The input to compute the geometry is the width of the infos
392       // box, the left/right texts and the spa    392       // box, the left/right texts and the space between
393       // left/right texts.                        393       // left/right texts.
394                                                   394 
395       // from a text height of th=1, and a lef    395       // from a text height of th=1, and a left/right sep
396       // of num_spaces*th, get width of the bo    396       // of num_spaces*th, get width of the box :
397                                                   397 
398       float th = 1;                               398       float th = 1;
399                                                   399 
400       float lmn_x,lmn_y,lmn_z;                    400       float lmn_x,lmn_y,lmn_z;
401       float lmx_x,lmx_y,lmx_z;                    401       float lmx_x,lmx_y,lmx_z;
402       ltext->get_bounds(th,lmn_x,lmn_y,lmn_z,l    402       ltext->get_bounds(th,lmn_x,lmn_y,lmn_z,lmx_x,lmx_y,lmx_z);
403       float lw = (lmx_x<lmn_x)?0:lmx_x-lmn_x;     403       float lw = (lmx_x<lmn_x)?0:lmx_x-lmn_x;
404                                                   404 
405       float rmn_x,rmn_y,rmn_z;                    405       float rmn_x,rmn_y,rmn_z;
406       float rmx_x,rmx_y,rmx_z;                    406       float rmx_x,rmx_y,rmx_z;
407       rtext->get_bounds(th,rmn_x,rmn_y,rmn_z,r    407       rtext->get_bounds(th,rmn_x,rmn_y,rmn_z,rmx_x,rmx_y,rmx_z);
408       float rw = (rmx_x<rmn_x)?0:rmx_x-rmn_x;     408       float rw = (rmx_x<rmn_x)?0:rmx_x-rmn_x;
409                                                   409 
410       float mmn_x,mmn_y,mmn_z;                    410       float mmn_x,mmn_y,mmn_z;
411       float mmx_x,mmx_y,mmx_z;                    411       float mmx_x,mmx_y,mmx_z;
412       mtext->get_bounds(th,mmn_x,mmn_y,mmn_z,m    412       mtext->get_bounds(th,mmn_x,mmn_y,mmn_z,mmx_x,mmx_y,mmx_z);
413       float mw = (mmx_x<mmn_x)?0:mmx_x-mmn_x;     413       float mw = (mmx_x<mmn_x)?0:mmx_x-mmn_x;
414                                                   414 
415       float winfos = lw+mw+rw;                    415       float winfos = lw+mw+rw;
416       if(!winfos) {                               416       if(!winfos) {
417         m_sep.clear();                            417         m_sep.clear();
418         height = 1;                               418         height = 1;
419         parent::update_sg();                      419         parent::update_sg();
420         delete mtext;                             420         delete mtext;
421         return;                                   421         return;
422       }                                           422       }
423                                                   423 
424       // assuming that text size is linear rel    424       // assuming that text size is linear relative
425       // to th, we get the th needed to match     425       // to th, we get the th needed to match infos_box.width :
426       // th -> winfos then to have fw :           426       // th -> winfos then to have fw :
427       th = fw*th/winfos;                          427       th = fw*th/winfos;
428                                                   428 
429       // place the left/right texts by rescali    429       // place the left/right texts by rescaling them to
430       // the new th :                             430       // the new th :
431       ltext->height = th;                         431       ltext->height = th;
432       ltext->get_bounds(th,lmn_x,lmn_y,lmn_z,l    432       ltext->get_bounds(th,lmn_x,lmn_y,lmn_z,lmx_x,lmx_y,lmx_z);
433       float hinfos = (lmx_x<lmn_x)?0:lmx_y-lmn    433       float hinfos = (lmx_x<lmn_x)?0:lmx_y-lmn_y;
434                                                   434 
435       float xx = -fw*0.5F; //left justified.      435       float xx = -fw*0.5F; //left justified.
436       float ty = -ltext->ascent(th)+hinfos*0.5    436       float ty = -ltext->ascent(th)+hinfos*0.5f;
437       ltsf->set_translate(xx,ty,zz);              437       ltsf->set_translate(xx,ty,zz);
438                                                   438 
439       rtext->height = th;                         439       rtext->height = th;
440       if(rtext->hjust==right) {                   440       if(rtext->hjust==right) {
441         xx = fw*0.5F;                             441         xx = fw*0.5F;
442       } else if(rtext->hjust==left) {             442       } else if(rtext->hjust==left) {
443         rtext->get_bounds(th,rmn_x,rmn_y,rmn_z    443         rtext->get_bounds(th,rmn_x,rmn_y,rmn_z,rmx_x,rmx_y,rmx_z);
444         rw = (rmx_x<rmn_x)?0:rmx_x-rmn_x;         444         rw = (rmx_x<rmn_x)?0:rmx_x-rmn_x;
445         xx = fw*0.5F-rw;                          445         xx = fw*0.5F-rw;
446       } else { //center                           446       } else { //center
447         rtext->get_bounds(th,rmn_x,rmn_y,rmn_z    447         rtext->get_bounds(th,rmn_x,rmn_y,rmn_z,rmx_x,rmx_y,rmx_z);
448         rw = (rmx_x<rmn_x)?0:rmx_x-rmn_x;         448         rw = (rmx_x<rmn_x)?0:rmx_x-rmn_x;
449         xx = fw*0.5F-rw*0.5F;                     449         xx = fw*0.5F-rw*0.5F;
450       }                                           450       }
451       rtsf->set_translate(xx,ty,zz);              451       rtsf->set_translate(xx,ty,zz);
452                                                   452 
453       // set infos_box.height :                   453       // set infos_box.height :
454       height = hinfos/hmargin_factor;             454       height = hinfos/hmargin_factor;
455                                                   455 
456       //done last because of the upper height     456       //done last because of the upper height setup.
457       parent::update_sg();                        457       parent::update_sg();
458                                                   458 
459     }                                             459     }
460                                                   460 
461     delete mtext;                                 461     delete mtext;
462                                                   462 
463   }                                               463   }
464 protected:                                        464 protected:
465   const base_freetype& m_ttf;                     465   const base_freetype& m_ttf;
466                                                   466 
467   separator m_sep;                                467   separator m_sep;
468 };                                                468 };
469                                                   469 
470 }}                                                470 }}
471                                                   471 
472 #endif                                            472 #endif