g4tools  5.4.0
Public Member Functions | Public Attributes | Protected Attributes | List of all members
tools::sg::infos_box Class Reference
Inheritance diagram for tools::sg::infos_box:
Inheritance graph
[legend]
Collaboration diagram for tools::sg::infos_box:
Collaboration graph
[legend]

Public Member Functions

virtual const desc_fieldsnode_desc_fields () const
 
virtual void render (render_action &a_action)
 
virtual void pick (pick_action &a_action)
 
virtual void search (search_action &a_action)
 
virtual bool write (write_action &a_action)
 
virtual void bbox (bbox_action &a_action)
 
 infos_box (const base_freetype &a_ttf)
 
virtual ~infos_box ()
 
 infos_box (const infos_box &a_from)
 
infos_boxoperator= (const infos_box &a_from)
 
void update_sg ()
 
- Public Member Functions inherited from tools::sg::back_area
 back_area ()
 
virtual ~back_area ()
 
 back_area (const back_area &a_from)
 
back_areaoperator= (const back_area &a_from)
 
- Public Member Functions inherited from tools::sg::node
virtual void * cast (const std::string &a_class) const
 
virtual const std::string & s_cls () const =0
 
virtual nodecopy () const =0
 
virtual unsigned int cls_version () const
 
virtual void get_matrix (get_matrix_action &a_action)
 
virtual void event (event_action &)
 
virtual bool read (read_action &a_action)
 
virtual void is_visible (visible_action &)
 
virtual void protocol_one_fields (std::vector< field * > &a_fields) const
 
virtual bool draw_in_frame_buffer () const
 
virtual bool touched ()
 
virtual void reset_touched ()
 
 node ()
 
virtual ~node ()
 
void touch ()
 
fieldfield_from_desc (const field_desc &a_desc) const
 
void dump_field_descs (std::ostream &a_out) const
 
fieldfind_field_by_name (const std::string &a_name) const
 

Public Attributes

mf_string lstrings
 
mf_string rstrings
 
sf< unsigned int > num_spaces
 
sf_vec< colorf, float > color
 
sf_string font
 
sf_enum< sg::font_modelingfont_modeling
 
sf_string encoding
 
sf< float > line_width
 
sf_enum< winding_typefront_face
 
sf< bool > back_visible
 
sf< float > wmargin_factor
 
sf< float > hmargin_factor
 
sf_enum< hjustlhjust
 
sf_enum< hjustrhjust
 
sf< bool > confine
 
- Public Attributes inherited from tools::sg::back_area
sf< float > width
 
sf< float > height
 
sf_vec< colorf, float > color
 
sf< bool > gradient
 
sf_vec< colorf, float > color_top
 
sf< bool > border_visible
 
sf_vec< colorf, float > border_color
 
sf< float > border_line_width
 
sf< float > shadow
 
sf< float > corner_radius
 
sf< unsigned int > corner_steps
 
sf< unsigned int > corner_mask
 

Protected Attributes

const base_freetypem_ttf
 
separator m_sep
 
- Protected Attributes inherited from tools::sg::back_area
separator m_back_sep
 

Additional Inherited Members

- Static Public Member Functions inherited from tools::sg::back_area
static unsigned int corner_top_right ()
 
static unsigned int corner_top_left ()
 
static unsigned int corner_bottom_right ()
 
static unsigned int corner_bottom_left ()
 
static unsigned int corner_all ()
 
- Protected Member Functions inherited from tools::sg::back_area
void update_sg ()
 
- Protected Member Functions inherited from tools::sg::node
 node (const node &)
 
nodeoperator= (const node &)
 
void add_field (field *a_field)
 
bool write_fields (write_action &a_action)
 
bool read_fields (read_action &a_action)
 
field_desc::offset_t field_offset (const field *a_field) const
 
fieldfind_field (const field_desc &a_rdesc) const
 
void check_fields (std::ostream &a_out) const
 

Detailed Description

Definition at line 22 of file infos_box.

Constructor & Destructor Documentation

◆ infos_box() [1/2]

tools::sg::infos_box::infos_box ( const base_freetype a_ttf)
inline

Definition at line 153 of file infos_box.

154  :parent()
155  ,lstrings()
156  ,rstrings()
157  ,num_spaces(4)
158 
159  ,color(colorf_black())
160  ,font(font_hershey())
163  ,line_width(1)
165 
166  ,back_visible(true)
167  ,wmargin_factor(0.9f)
168  ,hmargin_factor(0.9f)
169  ,lhjust(left)
170  ,rhjust(right)
171 
172  ,confine(false)
173 
174  ,m_ttf(a_ttf)
175  {
176  add_fields();
177  }

◆ ~infos_box()

virtual tools::sg::infos_box::~infos_box ( )
inlinevirtual

Definition at line 178 of file infos_box.

178 {}

◆ infos_box() [2/2]

tools::sg::infos_box::infos_box ( const infos_box a_from)
inline

Definition at line 180 of file infos_box.

181  :parent(a_from)
182  ,lstrings(a_from.lstrings)
183  ,rstrings(a_from.rstrings)
184  ,num_spaces(a_from.num_spaces)
185 
186  ,color(a_from.color)
187  ,font(a_from.font)
188  ,font_modeling(a_from.font_modeling)
189  ,encoding(a_from.encoding)
190  ,line_width(a_from.line_width)
191  ,front_face(a_from.front_face)
192 
193  ,back_visible(a_from.back_visible)
194  ,wmargin_factor(a_from.wmargin_factor)
195  ,hmargin_factor(a_from.hmargin_factor)
196  ,lhjust(a_from.lhjust)
197  ,rhjust(a_from.rhjust)
198 
199  ,confine(a_from.confine)
200 
201  ,m_ttf(a_from.m_ttf)
202  {
203  add_fields();
204  }

Member Function Documentation

◆ bbox()

virtual void tools::sg::infos_box::bbox ( bbox_action a_action)
inlinevirtual

Reimplemented from tools::sg::node.

Definition at line 144 of file infos_box.

144  {
145  if(touched()) {
146  update_sg();
147  reset_touched();
148  }
149  if(back_visible.value()) m_back_sep.bbox(a_action);
150  m_sep.bbox(a_action);
151  }

◆ node_desc_fields()

virtual const desc_fields& tools::sg::infos_box::node_desc_fields ( ) const
inlinevirtual

Reimplemented from tools::sg::back_area.

Definition at line 43 of file infos_box.

43  {
45  static const desc_fields s_v(parent::node_desc_fields(),15, //WARNING : take care of count.
50 
52  font_hershey().c_str(),
53  font_lato_regular_ttf().c_str(),
54  font_roboto_bold_ttf().c_str(),
55  font_arial_ttf().c_str(),
56  font_arialbd_ttf().c_str(),
57  font_timesbd_ttf().c_str(),
58  font_symbol_ttf().c_str(),
59  font_stixgeneral_otf().c_str(),
60  font_helvetica_ttf().c_str(),
61  font_times_roman_ttf().c_str()
63 
69 
73 
80  );
81  return s_v;
82  }

◆ operator=()

infos_box& tools::sg::infos_box::operator= ( const infos_box a_from)
inline

Definition at line 205 of file infos_box.

205  {
206  parent::operator=(a_from);
207  lstrings = a_from.lstrings;
208  rstrings = a_from.rstrings;
209  num_spaces = a_from.num_spaces;
210 
211  color = a_from.color;
212  font = a_from.font;
213  font_modeling = a_from.font_modeling;
214  encoding = a_from.encoding;
215  line_width = a_from.line_width;
216  front_face = a_from.front_face;
217 
218  back_visible = a_from.back_visible;
219  wmargin_factor = a_from.wmargin_factor;
220  hmargin_factor = a_from.hmargin_factor;
221  lhjust = a_from.lhjust;
222  rhjust = a_from.rhjust;
223 
224  confine = a_from.confine;
225 
226  return *this;
227  }

◆ pick()

virtual void tools::sg::infos_box::pick ( pick_action a_action)
inlinevirtual

Reimplemented from tools::sg::back_area.

Definition at line 112 of file infos_box.

112  {
113  if(touched()) {
114  update_sg();
115  reset_touched();
116  }
117  if(back_visible.value()) {
118  m_back_sep.pick(a_action);
119  if(a_action.done()) return;
120  }
121  }

◆ render()

virtual void tools::sg::infos_box::render ( render_action a_action)
inlinevirtual

Reimplemented from tools::sg::back_area.

Definition at line 104 of file infos_box.

104  {
105  if(touched()) {
106  update_sg();
107  reset_touched();
108  }
109  if(back_visible.value()) m_back_sep.render(a_action);
110  m_sep.render(a_action);
111  }

◆ search()

virtual void tools::sg::infos_box::search ( search_action a_action)
inlinevirtual

Reimplemented from tools::sg::back_area.

Definition at line 122 of file infos_box.

122  {
123  if(touched()) {
124  update_sg();
125  reset_touched();
126  }
127  node::search(a_action);
128  if(a_action.done()) return;
129  if(back_visible.value()) {
130  m_back_sep.search(a_action);
131  if(a_action.done()) return;
132  }
133  m_sep.search(a_action);
134  if(a_action.done()) return;
135  }

◆ update_sg()

void tools::sg::infos_box::update_sg ( )
inline

left text //////////////////////////////////////////////

right text /////////////////////////////////////////////

middle spaces //////////////////////////////////////////

Definition at line 229 of file infos_box.

229  {
230  // have this method public in order to use it in plotter.
231  // This is so because infos_box::height is an output field
232  // needed in plotter to place the box.
233 
234  m_back_sep.clear(); //back_area::update_sg done last.
235 
236  m_sep.clear();
237 
238  if(width.value()<=0) return;
239  if(confine) {
240  if(height.value()<=0) return;
241  }
242 
243  {bool empty = true;
244  std::vector<std::string>::const_iterator it;
245  for(it=lstrings.values().begin();it!=lstrings.values().end();++it) {
246  if((*it).size()) {empty = false;break;}
247  }
248  if(empty){
249  for(it=rstrings.values().begin();it!=rstrings.values().end();++it) {
250  if((*it).size()) {empty = false;break;}
251  }
252  }
253  if(empty) {
254  //parent::update_sg();
255  return;
256  }}
257 
258  rgba* mat = new rgba();
259  mat->color = color;
260  m_sep.add(mat);
261 
262  if(font==font_hershey()) {
263  draw_style* ds = new draw_style;
264  ds->style.value(draw_lines);
265  //ds->line_pattern = line_pattern;
266  ds->line_width = line_width;
267  m_sep.add(ds);
268  }
269 
273  base_text* ltext = 0;
274  matrix* ltsf = 0;
275 
276  {separator* sep = new separator;
277  m_sep.add(sep);
278  ltsf = new matrix;
279  sep->add(ltsf);
280  if(font==font_hershey()) {
281  text_hershey* text = new text_hershey;
282  ltext = text;
283  text->encoding = encoding;
284  sep->add(text);
285  } else {
286  base_freetype* text = base_freetype::create(m_ttf);
287  //TTNODE* text = new TTNODE;
288  ltext = text;
289  text->font = font;
290  text->modeling = font_modeling;
291  sep->add(text);
292  }
293  ltext->strings = lstrings;
294  ltext->hjust = lhjust;}
295 
299  base_text* rtext = 0;
300  matrix* rtsf = 0;
301 
302  {separator* sep = new separator;
303  m_sep.add(sep);
304  rtsf = new matrix;
305  sep->add(rtsf);
306  if(font==font_hershey()) {
307  text_hershey* text = new text_hershey;
308  rtext = text;
309  text->encoding = encoding;
310  sep->add(text);
311  } else {
312  base_freetype* text = base_freetype::create(m_ttf);
313  //TTNODE* text = new TTNODE;
314  rtext = text;
315  text->font = font;
316  text->modeling = font_modeling;
317  sep->add(text);
318  }
319  rtext->strings = rstrings;
320  rtext->hjust = rhjust;}
321 
325  base_text* mtext = 0;
326  {std::string s(num_spaces,' ');
327  if(font==font_hershey()) {
328  text_hershey* text = new text_hershey;
329  mtext = text;
330  text->strings.add(s);
331  text->hjust = left;
332  } else {
333  base_freetype* text = base_freetype::create(m_ttf);
334  //TTNODE* text = new TTNODE;
335  mtext = text;
336  text->strings.add(s);
337  text->hjust = left;
338  text->font = font;
339  text->modeling = font_modeling;
340  }}
341 
342  //sf<float> zfront ?
343  float zz = back_visible.value()?0.01f:0;
344 
345  float fw = width * wmargin_factor;
346 
347  if(confine) {
348  // left right texts may overlap.
349 
350  // adjust height :
351  float fh = height * hmargin_factor;
352  float th = fh;
353  {float mn_x,mn_y,mn_z;
354  float mx_x,mx_y,mx_z;
355  ltext->get_bounds(th,mn_x,mn_y,mn_z,mx_x,mx_y,mx_z);
356  float bxh = mx_y-mn_y;
357  // adjust box height :
358  // fh -> bxh then to have fh :
359  if(!bxh) {
360  m_sep.clear();
361  parent::update_sg();
362  delete mtext;
363  return;
364  }
365  th = fh*fh/bxh;}
366 
367  ltext->height = th;
368  rtext->height = th;
369 
370  {float mn_x,mn_y,mn_z;
371  float mx_x,mx_y,mx_z;
372  ltext->get_bounds(th,mn_x,mn_y,mn_z,mx_x,mx_y,mx_z);
373  float lw = mx_x-mn_x;
374  float xtrans = (fw-lw)*0.5f; //left justified
375  float xx = -(mn_x+mx_x)*0.5F-xtrans;
376  float yy = -(mn_y+mx_y)*0.5F;
377  ltsf->set_translate(xx,yy,zz);}
378 
379  {float mn_x,mn_y,mn_z;
380  float mx_x,mx_y,mx_z;
381  rtext->get_bounds(th,mn_x,mn_y,mn_z,mx_x,mx_y,mx_z);
382  rtext->hjust = right;
383  float xx = fw*0.5f;
384  float yy = -(mn_y+mx_y)*0.5F;
385  rtsf->set_translate(xx,yy,zz);}
386 
387  parent::update_sg();
388 
389  } else {
390  // height of the info box is an output of the below.
391  // The input to compute the geometry is the width of the infos
392  // box, the left/right texts and the space between
393  // left/right texts.
394 
395  // from a text height of th=1, and a left/right sep
396  // of num_spaces*th, get width of the box :
397 
398  float th = 1;
399 
400  float lmn_x,lmn_y,lmn_z;
401  float lmx_x,lmx_y,lmx_z;
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;
404 
405  float rmn_x,rmn_y,rmn_z;
406  float rmx_x,rmx_y,rmx_z;
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;
409 
410  float mmn_x,mmn_y,mmn_z;
411  float mmx_x,mmx_y,mmx_z;
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;
414 
415  float winfos = lw+mw+rw;
416  if(!winfos) {
417  m_sep.clear();
418  height = 1;
419  parent::update_sg();
420  delete mtext;
421  return;
422  }
423 
424  // assuming that text size is linear relative
425  // to th, we get the th needed to match infos_box.width :
426  // th -> winfos then to have fw :
427  th = fw*th/winfos;
428 
429  // place the left/right texts by rescaling them to
430  // the new th :
431  ltext->height = th;
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_y;
434 
435  float xx = -fw*0.5F; //left justified.
436  float ty = -ltext->ascent(th)+hinfos*0.5f;
437  ltsf->set_translate(xx,ty,zz);
438 
439  rtext->height = th;
440  if(rtext->hjust==right) {
441  xx = fw*0.5F;
442  } else if(rtext->hjust==left) {
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;
445  xx = fw*0.5F-rw;
446  } else { //center
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;
449  xx = fw*0.5F-rw*0.5F;
450  }
451  rtsf->set_translate(xx,ty,zz);
452 
453  // set infos_box.height :
454  height = hinfos/hmargin_factor;
455 
456  //done last because of the upper height setup.
457  parent::update_sg();
458 
459  }
460 
461  delete mtext;
462 
463  }

◆ write()

virtual bool tools::sg::infos_box::write ( write_action a_action)
inlinevirtual

Reimplemented from tools::sg::node.

Definition at line 136 of file infos_box.

136  {
137  if(touched()) {
138  update_sg();
139  reset_touched();
140  }
141  if(back_visible.value()) if(!m_back_sep.write(a_action)) return false;
142  return m_sep.write(a_action);
143  }

Member Data Documentation

◆ back_visible

sf<bool> tools::sg::infos_box::back_visible

Definition at line 36 of file infos_box.

◆ color

sf_vec<colorf,float> tools::sg::infos_box::color

Definition at line 29 of file infos_box.

◆ confine

sf<bool> tools::sg::infos_box::confine

Definition at line 41 of file infos_box.

◆ encoding

sf_string tools::sg::infos_box::encoding

Definition at line 32 of file infos_box.

◆ font

sf_string tools::sg::infos_box::font

Definition at line 30 of file infos_box.

◆ font_modeling

sf_enum<sg::font_modeling> tools::sg::infos_box::font_modeling

Definition at line 31 of file infos_box.

◆ front_face

sf_enum<winding_type> tools::sg::infos_box::front_face

Definition at line 34 of file infos_box.

◆ hmargin_factor

sf<float> tools::sg::infos_box::hmargin_factor

Definition at line 38 of file infos_box.

◆ lhjust

sf_enum<hjust> tools::sg::infos_box::lhjust

Definition at line 39 of file infos_box.

◆ line_width

sf<float> tools::sg::infos_box::line_width

Definition at line 33 of file infos_box.

◆ lstrings

mf_string tools::sg::infos_box::lstrings

Definition at line 25 of file infos_box.

◆ m_sep

separator tools::sg::infos_box::m_sep
protected

Definition at line 467 of file infos_box.

◆ m_ttf

const base_freetype& tools::sg::infos_box::m_ttf
protected

Definition at line 465 of file infos_box.

◆ num_spaces

sf<unsigned int> tools::sg::infos_box::num_spaces

Definition at line 27 of file infos_box.

◆ rhjust

sf_enum<hjust> tools::sg::infos_box::rhjust

Definition at line 40 of file infos_box.

◆ rstrings

mf_string tools::sg::infos_box::rstrings

Definition at line 26 of file infos_box.

◆ wmargin_factor

sf<float> tools::sg::infos_box::wmargin_factor

Definition at line 37 of file infos_box.


The documentation for this class was generated from the following file:
tools::sg::font_pixmap
@ font_pixmap
Definition: enums:94
tools::sg::group::search
virtual void search(search_action &a_action)
Definition: group:51
tools::sg::infos_box::lstrings
mf_string lstrings
Definition: infos_box:25
tools::sg::winding_ccw
@ winding_ccw
Definition: enums:105
tools::sg::infos_box::encoding
sf_string encoding
Definition: infos_box:32
TOOLS_ARG_FIELD_DESC_ENUMS_BEG
#define TOOLS_ARG_FIELD_DESC_ENUMS_BEG(a__field, a__num)
Definition: field:77
tools::sg::infos_box::m_sep
separator m_sep
Definition: infos_box:467
tools::sg::encoding_PAW
const std::string & encoding_PAW()
Definition: strings:42
tools::sg::back_area::m_back_sep
separator m_back_sep
Definition: back_area:438
tools::sg::right
@ right
Definition: enums:76
tools::sg::infos_box::rhjust
sf_enum< hjust > rhjust
Definition: infos_box:40
tools::sg::infos_box::font_modeling
sf_enum< sg::font_modeling > font_modeling
Definition: infos_box:31
tools::sg::bmf::values
const std::vector< T > & values() const
Definition: bmf:71
tools::sg::infos_box::wmargin_factor
sf< float > wmargin_factor
Definition: infos_box:37
tools::sg::separator::pick
virtual void pick(pick_action &a_action)
Definition: separator:31
tools::sg::separator::bbox
virtual void bbox(bbox_action &a_action)
Definition: separator:38
tools::sg::left
@ left
Definition: enums:74
tools::sg::infos_box::line_width
sf< float > line_width
Definition: infos_box:33
tools::sg::infos_box
Definition: infos_box:22
tools::sg::group::add
void add(node *a_node)
Definition: group:96
tools::sg::font_outline
@ font_outline
Definition: enums:92
TOOLS_ARG_FIELD_DESC_OPTS_BEG
#define TOOLS_ARG_FIELD_DESC_OPTS_BEG(a__field, a__num)
Definition: field:87
tools::sg::back_area::height
sf< float > height
Definition: back_area:31
tools::sg::infos_box::update_sg
void update_sg()
Definition: infos_box:229
tools::sg::node::search
virtual void search(search_action &a_action)
Definition: node:56
TOOLS_ARG_FIELD_DESC_OPTS_END
#define TOOLS_ARG_FIELD_DESC_OPTS_END
Definition: field:89
tools::sg::infos_box::m_ttf
const base_freetype & m_ttf
Definition: infos_box:465
tools::sg::infos_box::font
sf_string font
Definition: infos_box:30
tools::sg::separator::render
virtual void render(render_action &a_action)
Definition: separator:18
tools::sg::base_freetype::create
static base_freetype * create(const base_freetype &a_ttf)
Definition: base_freetype:108
tools::sg::infos_box::num_spaces
sf< unsigned int > num_spaces
Definition: infos_box:27
tools::sg::infos_box::back_visible
sf< bool > back_visible
Definition: infos_box:36
tools::sg::infos_box::confine
sf< bool > confine
Definition: infos_box:41
TOOLS_FIELD_DESC_NODE_CLASS
#define TOOLS_FIELD_DESC_NODE_CLASS(a__class)
Definition: field:68
TOOLS_ARG_ENUM
#define TOOLS_ARG_ENUM(a__value)
Definition: field:85
tools::sg::group::clear
void clear()
Definition: group:235
tools::sg::infos_box::hmargin_factor
sf< float > hmargin_factor
Definition: infos_box:38
tools::sg::bsf::value
T & value()
Definition: bsf:98
tools::sg::infos_box::rstrings
mf_string rstrings
Definition: infos_box:26
tools::sg::font_hershey
const std::string & font_hershey()
Definition: strings:186
tools::sep
const std::string & sep()
Definition: sep:11
tools::sg::back_area::width
sf< float > width
Definition: back_area:30
tools::sg::infos_box::color
sf_vec< colorf, float > color
Definition: infos_box:29
tools::sg::font_filled
@ font_filled
Definition: enums:93
tools::sg::draw_lines
@ draw_lines
Definition: enums:192
tools::sg::node::touched
virtual bool touched()
Definition: node:96
tools::sg::infos_box::front_face
sf_enum< winding_type > front_face
Definition: infos_box:34
TOOLS_ARG_FIELD_DESC
#define TOOLS_ARG_FIELD_DESC(a__field)
Definition: field:71
tools::sg::infos_box::lhjust
sf_enum< hjust > lhjust
Definition: infos_box:39
tools::sg::node::reset_touched
virtual void reset_touched()
Definition: node:102
TOOLS_ARG_FIELD_DESC_ENUMS_END
#define TOOLS_ARG_FIELD_DESC_ENUMS_END
Definition: field:83
tools::sg::separator::write
virtual bool write(write_action &a_action)
Definition: separator:59