g4tools  5.4.0
Public Member Functions | Public Attributes | Protected Attributes | List of all members
tools::sg::legend Class Reference
Inheritance diagram for tools::sg::legend:
Inheritance graph
[legend]
Collaboration diagram for tools::sg::legend:
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 void bbox (bbox_action &a_action)
 
 legend (const base_freetype &a_ttf)
 
virtual ~legend ()
 
 legend (const legend &a_from)
 
legendoperator= (const legend &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 bool write (write_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 strings
 
sf_vec< colorf, float > color
 
sf_string font
 
sf_enum< sg::font_modelingfont_modeling
 
sf_string encoding
 
sf< bool > back_visible
 
sf< float > wmargin_factor
 
sf< float > hmargin_factor
 
sf_enum< hjustlhjust
 
sf_enum< hjustrhjust
 
sf_enum< sg::marker_stylemarker_style
 
sf< float > marker_size
 
- 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

separator m_sep
 
const base_freetypem_ttf
 
- 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 23 of file legend.

Constructor & Destructor Documentation

◆ legend() [1/2]

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

Definition at line 129 of file legend.

130  :parent()
131  ,strings()
132 
133  ,color(colorf_black())
134  //,transparency(0)
135  ,font(font_hershey())
138  //,line_width(1)
139 
140  ,back_visible(true)
141  ,wmargin_factor(0.9f)
142  ,hmargin_factor(0.9f)
143  ,lhjust(left)
144  ,rhjust(right)
145 
147  ,marker_size(10)
148 
149  //,confine(false)
150 
151  ,m_ttf(a_ttf)
152  {
153  add_fields();
154  }

◆ ~legend()

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

Definition at line 155 of file legend.

155 {}

◆ legend() [2/2]

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

Definition at line 157 of file legend.

158  :parent(a_from)
159  ,strings(a_from.strings)
160 
161  ,color(a_from.color)
162  //,transparency(a_from.transparency)
163  ,font(a_from.font)
164  ,font_modeling(a_from.font_modeling)
165  ,encoding(a_from.encoding)
166  //,line_width(a_from.line_width)
167 
168  ,back_visible(a_from.back_visible)
169  ,wmargin_factor(a_from.wmargin_factor)
170  ,hmargin_factor(a_from.hmargin_factor)
171  ,lhjust(a_from.lhjust)
172  ,rhjust(a_from.rhjust)
173 
174  ,marker_style(a_from.marker_style)
175  ,marker_size(a_from.marker_size)
176 
177  //,confine(a_from.confine)
178 
179  ,m_ttf(a_from.m_ttf)
180  {
181  add_fields();
182  }

Member Function Documentation

◆ bbox()

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

Reimplemented from tools::sg::node.

Definition at line 120 of file legend.

120  {
121  if(touched()) {
122  update_sg();
123  reset_touched();
124  }
125  if(back_visible.value()) m_back_sep.bbox(a_action);
126  m_sep.bbox(a_action);
127  }

◆ node_desc_fields()

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

◆ operator=()

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

Definition at line 183 of file legend.

183  {
184  parent::operator=(a_from);
185  strings = a_from.strings;
186 
187  color = a_from.color;
188  //transparency = a_from.transparency;
189  font = a_from.font;
190  font_modeling = a_from.font_modeling;
191  encoding = a_from.encoding;
192  //line_width = a_from.line_width;
193 
194  back_visible = a_from.back_visible;
195  wmargin_factor = a_from.wmargin_factor;
196  hmargin_factor = a_from.hmargin_factor;
197  lhjust = a_from.lhjust;
198  rhjust = a_from.rhjust;
199 
200  marker_style = a_from.marker_style;
201  marker_size = a_from.marker_size;
202 
203  //confine = a_from.confine;
204 
205  return *this;
206  }

◆ pick()

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

Reimplemented from tools::sg::back_area.

Definition at line 96 of file legend.

96  {
97  if(touched()) {
98  update_sg();
99  reset_touched();
100  }
101  if(back_visible.value()) {
102  m_back_sep.pick(a_action);
103  if(a_action.done()) return;
104  }
105  }

◆ render()

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

Reimplemented from tools::sg::back_area.

Definition at line 88 of file legend.

88  {
89  if(touched()) {
90  update_sg();
91  reset_touched();
92  }
93  if(back_visible.value()) m_back_sep.render(a_action);
94  m_sep.render(a_action);
95  }

◆ search()

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

Reimplemented from tools::sg::back_area.

Definition at line 106 of file legend.

106  {
107  if(touched()) {
108  update_sg();
109  reset_touched();
110  }
111  node::search(a_action);
112  if(a_action.done()) return;
113  if(back_visible.value()) {
114  m_back_sep.search(a_action);
115  if(a_action.done()) return;
116  }
117  m_sep.search(a_action);
118  if(a_action.done()) return;
119  }

◆ update_sg()

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

rep at left ////////////////////////////////////////////

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

Definition at line 208 of file legend.

208  {
209  // have this method public in order to use it in plotter.
210  // This is so because legend::height is an output field
211  // needed in plotter to place the box.
212 
213  m_back_sep.clear(); //back_area::update_sg done last.
214 
215  m_sep.clear();
216 
217  if(width.value()<=0) return;
218  //if(confine) {
219  // if(height.value()<=0) return;
220  //}
221 
222  {bool empty = true;
223  std::vector<std::string>::const_iterator it;
224  for(it=strings.values().begin();it!=strings.values().end();++it) {
225  if((*it).size()) {empty = false;break;}
226  }
227  if(empty) return;}
228 
229  //sf<float> zfront ?
230  float zz = back_visible.value()?0.01f:0;
231 
232  //bool rep_line = false;
233 
234  /*
235  float fw = 0;
236  float fh = 0;
237  float lw = 0;
238  float rw = 0;
239  if(rep_line) {
240  fw = width * wmargin_factor;
241  fh = height * hmargin_factor;
242 
243  lw = fw*0.5f*0.95f;
244  rw = fw*0.5f;
245  }*/
249 
250  {separator* _sep = new separator;
251  m_sep.add(_sep);
252 
253  rgba* mat = new rgba();
254  mat->color = color;
255  _sep->add(mat);
256 
257 /* if(rep_line) {
258  matrix* ltsf = new matrix;
259  float xx = -fw*0.5F; //left justified.
260  ltsf->set_translate(xx,0,zz);
261  _sep->add(ltsf);
262 
263  draw_style* ds = new draw_style;
264  ds->style = draw_lines;
265  _sep->add(ds);
266 
267  vertices* vtxs = new vertices;
268  vtxs->mode = gl::line_strip();
269  vtxs->add( 0,0,zz);
270  vtxs->add(lw,0,zz);
271  _sep->add(vtxs);
272 
273  } else*/ { // rep marker :
274  if(marker_style.value()==marker_dot) {
275  draw_style* ds = new draw_style;
276  ds->style = draw_points;
277  ds->point_size = marker_size;
278  _sep->add(ds);
279  vertices* vtxs = new vertices;
280  vtxs->mode = gl::points();
281  vtxs->add(-width*0.5f+height*0.5f,0,zz);
282  _sep->add(vtxs);
283  } else {
284  markers* vtxs = new markers;
285  vtxs->size = marker_size;
286  vtxs->style = marker_style;
287  vtxs->add(-width*0.5f+height*0.5f,0,zz);
288  _sep->add(vtxs);
289  }
290  }
291 
292  }
293 
297  base_text* rtext = 0;
298  matrix* rtsf = 0;
299 
300  {separator* _sep = new separator;
301  m_sep.add(_sep);
302 
303  rgba* mat = new rgba();
304  mat->color = colorf_black();
305  _sep->add(mat);
306 
307  if(font==font_hershey()) {
308  draw_style* ds = new draw_style;
309  ds->style.value(draw_lines);
310  _sep->add(ds);
311  }
312 
313  rtsf = new matrix;
314  _sep->add(rtsf);
315  if(font==font_hershey()) {
316  text_hershey* text = new text_hershey;
317  text->encoding = encoding;
318  text->strings = strings;
319  _sep->add(text);
320  rtext = text;
321  } else {
322  if(encoding==encoding_PAW()) {
323  text_valop* text = new text_valop(m_ttf);
324  text->font = font;
325  text->font_modeling = font_modeling;
326  text->strings = strings;
327  _sep->add(text);
328  rtext = text;
329  } else {
330  base_freetype* text = base_freetype::create(m_ttf);
331  text->font = font;
332  text->modeling = font_modeling;
333  text->strings = strings;
334  _sep->add(text);
335  rtext = text;
336  }
337  }
338  rtext->hjust = rhjust;}
339 
343 
344 /* if(rep_line) {
345 
346  // adjust width :
347  float th = fh;
348  {float mn_x,mn_y,mn_z;
349  float mx_x,mx_y,mx_z;
350  rtext->get_bounds(th,mn_x,mn_y,mn_z,mx_x,mx_y,mx_z);
351  float bxw = mx_x-mn_x;
352  if(!bxw) {
353  m_sep.clear();
354  parent::update_sg();
355  return;
356  }
357  // adjust box width :
358  // fh -> bxw then to have rw :
359  float max_width = rw;
360  if(bxw>max_width) th = max_width*fh/bxw;}
361 
362  rtext->height = th;
363 
364  {float mn_x,mn_y,mn_z;
365  float mx_x,mx_y,mx_z;
366  rtext->get_bounds(th,mn_x,mn_y,mn_z,mx_x,mx_y,mx_z);
367  rtext->hjust = right;
368  float xx = fw*0.5f;
369  float yy = -(mn_y+mx_y)*0.5F;
370  rtsf->set_translate(xx,yy,zz);}
371 
372  } else*/ { //rep mark :
373 
374  // adjust width :
375  float th = height;
376  {float mn_x,mn_y,mn_z;
377  float mx_x,mx_y,mx_z;
378  rtext->get_bounds(th,mn_x,mn_y,mn_z,mx_x,mx_y,mx_z);
379  float bxw = mx_x-mn_x;
380  if(!bxw) {
381  m_sep.clear();
382  parent::update_sg();
383  return;
384  }
385  // adjust box width :
386  // height -> bxw then to have a wanted width :
387  float max_width = (width-height)*wmargin_factor;
388  if(bxw>max_width) th = max_width*height/bxw;
389  if(th<0) {
390  m_sep.clear();
391  parent::update_sg();
392  return;
393  }}
394 
395  rtext->height = th;
396  {float mn_x,mn_y,mn_z;
397  float mx_x,mx_y,mx_z;
398  rtext->get_bounds(th,mn_x,mn_y,mn_z,mx_x,mx_y,mx_z);
399  rtext->hjust = left;
400  float yy = -(mn_y+mx_y)*0.5F;
401  rtsf->set_translate(-width*0.5f+height,yy,zz);}
402 
403  }
404 
405  parent::update_sg();
406 
407  }

Member Data Documentation

◆ back_visible

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

Definition at line 36 of file legend.

◆ color

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

Definition at line 28 of file legend.

◆ encoding

sf_string tools::sg::legend::encoding

Definition at line 33 of file legend.

◆ font

sf_string tools::sg::legend::font

Definition at line 31 of file legend.

◆ font_modeling

sf_enum<sg::font_modeling> tools::sg::legend::font_modeling

Definition at line 32 of file legend.

◆ hmargin_factor

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

Definition at line 38 of file legend.

◆ lhjust

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

Definition at line 39 of file legend.

◆ m_sep

separator tools::sg::legend::m_sep
protected

Definition at line 409 of file legend.

◆ m_ttf

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

Definition at line 410 of file legend.

◆ marker_size

sf<float> tools::sg::legend::marker_size

Definition at line 44 of file legend.

◆ marker_style

sf_enum<sg::marker_style> tools::sg::legend::marker_style

Definition at line 43 of file legend.

◆ rhjust

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

Definition at line 40 of file legend.

◆ strings

mf_string tools::sg::legend::strings

Definition at line 26 of file legend.

◆ wmargin_factor

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

Definition at line 37 of file legend.


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::legend::font_modeling
sf_enum< sg::font_modeling > font_modeling
Definition: legend:32
tools::sg::legend::encoding
sf_string encoding
Definition: legend:33
tools::sg::bmf::add
void add(const T &a_value)
Definition: bmf:73
TOOLS_ARG_FIELD_DESC_ENUMS_BEG
#define TOOLS_ARG_FIELD_DESC_ENUMS_BEG(a__field, a__num)
Definition: field:77
tools::sg::legend::m_ttf
const base_freetype & m_ttf
Definition: legend:410
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::marker_dot
@ marker_dot
Definition: enums:18
tools::sg::draw_points
@ draw_points
Definition: enums:191
tools::sg::bmf::values
const std::vector< T > & values() const
Definition: bmf:71
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::legend::font
sf_string font
Definition: legend:31
tools::sg::legend::marker_size
sf< float > marker_size
Definition: legend:44
tools::sg::group::add
void add(node *a_node)
Definition: group:96
tools::sg::legend::back_visible
sf< bool > back_visible
Definition: legend:36
tools::sg::legend::m_sep
separator m_sep
Definition: legend:409
tools::sg::font_outline
@ font_outline
Definition: enums:92
tools::gl::points
mode_t points()
Definition: glprims:16
tools::sg::back_area::height
sf< float > height
Definition: back_area:31
tools::sg::node::search
virtual void search(search_action &a_action)
Definition: node:56
tools::sg::legend::update_sg
void update_sg()
Definition: legend:208
tools::sg::legend::color
sf_vec< colorf, float > color
Definition: legend:28
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::legend::wmargin_factor
sf< float > wmargin_factor
Definition: legend:37
TOOLS_FIELD_DESC_NODE_CLASS
#define TOOLS_FIELD_DESC_NODE_CLASS(a__class)
Definition: field:68
tools::sg::legend::rhjust
sf_enum< hjust > rhjust
Definition: legend:40
tools::sg::legend::lhjust
sf_enum< hjust > lhjust
Definition: legend:39
TOOLS_ARG_ENUM
#define TOOLS_ARG_ENUM(a__value)
Definition: field:85
tools::sg::legend::marker_style
sf_enum< sg::marker_style > marker_style
Definition: legend:43
tools::sg::group::clear
void clear()
Definition: group:235
tools::sg::legend::hmargin_factor
sf< float > hmargin_factor
Definition: legend:38
tools::sg::bsf::value
T & value()
Definition: bsf:98
tools::sg::legend::strings
mf_string strings
Definition: legend:26
tools::sg::font_hershey
const std::string & font_hershey()
Definition: strings:186
tools::sg::back_area::width
sf< float > width
Definition: back_area:30
tools::sg::font_filled
@ font_filled
Definition: enums:93
tools::sg::legend
Definition: legend:23
tools::sg::draw_lines
@ draw_lines
Definition: enums:192
tools::sg::node::touched
virtual bool touched()
Definition: node:96
TOOLS_ARG_FIELD_DESC
#define TOOLS_ARG_FIELD_DESC(a__field)
Definition: field:71
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