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

Public Member Functions

virtual const desc_fieldsnode_desc_fields () const
 
virtual void render (render_action &a_action)
 
virtual void search (search_action &a_action)
 
virtual void pick (pick_action &a_action)
 
 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 bbox (bbox_action &)
 
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
 

Static Public Member Functions

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 ()
 

Public Attributes

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 Member Functions

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
 

Protected Attributes

separator m_back_sep
 

Detailed Description

Definition at line 19 of file back_area.

Constructor & Destructor Documentation

◆ back_area() [1/2]

tools::sg::back_area::back_area ( )
inline

Definition at line 110 of file back_area.

111  :parent()
112  ,width(1)
113  ,height(1)
114  ,color(colorf_white())
115  ,gradient(false)
116  ,color_top(colorf_white())
117  ,border_visible(true)
118  ,border_color(colorf_black())
120  ,shadow(0)
121  ,corner_radius(0) //in percent of the height.
122  ,corner_steps(12)
124  {
125  add_fields();
126  }

◆ ~back_area()

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

Definition at line 127 of file back_area.

127 {}

◆ back_area() [2/2]

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

Definition at line 129 of file back_area.

130  :parent(a_from)
131  ,width(a_from.width)
132  ,height(a_from.height)
133  ,color(a_from.color)
134  ,gradient(a_from.gradient)
135  ,color_top(a_from.color_top)
136  ,border_visible(a_from.border_visible)
137  ,border_color(a_from.border_color)
138  ,border_line_width(a_from.border_line_width)
139  ,shadow(a_from.shadow)
140  ,corner_radius(a_from.corner_radius)
141  ,corner_steps(a_from.corner_steps)
142  ,corner_mask(a_from.corner_mask)
143  {
144  add_fields();
145  }

Member Function Documentation

◆ corner_all()

static unsigned int tools::sg::back_area::corner_all ( )
inlinestatic

Definition at line 26 of file back_area.

◆ corner_bottom_left()

static unsigned int tools::sg::back_area::corner_bottom_left ( )
inlinestatic

Definition at line 25 of file back_area.

25 {return 1<<3;}

◆ corner_bottom_right()

static unsigned int tools::sg::back_area::corner_bottom_right ( )
inlinestatic

Definition at line 24 of file back_area.

24 {return 1<<2;}

◆ corner_top_left()

static unsigned int tools::sg::back_area::corner_top_left ( )
inlinestatic

Definition at line 23 of file back_area.

23 {return 1<<1;}

◆ corner_top_right()

static unsigned int tools::sg::back_area::corner_top_right ( )
inlinestatic

Definition at line 22 of file back_area.

22 {return 1<<0;}

◆ node_desc_fields()

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

Reimplemented from tools::sg::node.

Reimplemented in tools::sg::text, tools::sg::legend, and tools::sg::infos_box.

Definition at line 48 of file back_area.

◆ operator=()

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

Definition at line 146 of file back_area.

146  {
147  parent::operator=(a_from);
148  width = a_from.width;
149  height = a_from.height;
150  color = a_from.color;
151  gradient = a_from.gradient;
152  color_top = a_from.color_top;
153  border_visible = a_from.border_visible;
154  border_color = a_from.border_color;
155  border_line_width = a_from.border_line_width;
156  shadow = a_from.shadow;
157  corner_radius = a_from.corner_radius;
158  corner_steps = a_from.corner_steps;
159  corner_mask = a_from.corner_mask;
160  return *this;
161  }

◆ pick()

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

Reimplemented from tools::sg::node.

Reimplemented in tools::sg::text, tools::sg::legend, and tools::sg::infos_box.

Definition at line 102 of file back_area.

102  {
103  if(touched()) {
104  update_sg();
105  reset_touched();
106  }
107  m_back_sep.pick(a_action);
108  }

◆ render()

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

Reimplemented from tools::sg::node.

Reimplemented in tools::sg::text, tools::sg::legend, and tools::sg::infos_box.

Definition at line 85 of file back_area.

85  {
86  if(touched()) {
87  update_sg();
88  reset_touched();
89  }
90  m_back_sep.render(a_action);
91  }

◆ search()

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

Reimplemented from tools::sg::node.

Reimplemented in tools::sg::text, tools::sg::legend, and tools::sg::infos_box.

Definition at line 92 of file back_area.

92  {
93  if(touched()) {
94  update_sg();
95  reset_touched();
96  }
97  parent::search(a_action);
98  if(a_action.done()) return;
99  m_back_sep.search(a_action);
100  if(a_action.done()) return;
101  }

◆ update_sg()

void tools::sg::back_area::update_sg ( )
inlineprotected

Definition at line 163 of file back_area.

163  {
164  m_back_sep.clear();
165 
166  if(width.value()<=0) return;
167  if(height.value()<=0) return;
168 
169  float xb = -width*0.5f;
170  float xe = width*0.5f;
171  float yb = -height*0.5f;
172 
173  //float zshadow = -0.05f;
174  float zshadow = -0.005f; //ok with gopaw and ROOT_default.
175  float zback = 0;
176  float zborder = 0.01f;
177 
178  if(shadow.value()) {
179  float zz = zback+zshadow;
180  float ye = height*0.5f;
181 
182  sg::rgba* mat = new sg::rgba();
183  mat->color = colorf_black();
184  m_back_sep.add(mat);
185 
186  normal* nm = new normal;
187  //nm->vec.value(); //default is z. ok.
188  m_back_sep.add(nm);
189 
190  vertices* vtxs = new vertices;
191  vtxs->mode = gl::triangle_fan();
192  m_back_sep.add(vtxs);
193 
194  float dx = width*shadow;
195  float dy = -dx;
196  vtxs->add(xb+dx,yb+dy,zz);
197  vtxs->add(xe+dx,yb+dy,zz);
198  vtxs->add(xe+dx,ye+dy,zz);
199  vtxs->add(xb+dx,ye+dy,zz);
200  }
201 
202  {//background :
203  normal* nm = new normal;
204  //nm->vec.value(); //default is z. ok.
205  m_back_sep.add(nm);
206 
207  if(gradient.value()) {
208 // if(true) {
209  //color gradient from (bottom,color) to (top,color_top)
210 
211  atb_vertices* vtxs = new atb_vertices;
212  vtxs->mode = gl::triangle_strip();
213  m_back_sep.add(vtxs);
214 
215  float zz = zback;
216 
217  unsigned int ncol = 50;
218  float dy = height/ncol;
219  float ye = yb+dy;
220 
221  colorf col_beg = color.value();
222  colorf col_end = color_top.value();
223 
224  float dr = (col_end.r()-col_beg.r())/ncol;
225  float dg = (col_end.g()-col_beg.g())/ncol;
226  float db = (col_end.b()-col_beg.b())/ncol;
227  float da = (col_end.a()-col_beg.a())/ncol;
228  vec4f dcol(dr,dg,db,da);
229 
230  colorf col = col_beg;
231 
232  vtxs->add(xb,yb,zz);
233  vtxs->add_color(col);
234 
235  vtxs->add(xe,yb,zz);
236  vtxs->add_color(col);
237 
238  for(unsigned int index=0;index<ncol;index++) {
239  vtxs->add(xb,ye,zz);
240  vtxs->add(xe,ye,zz);
241 
242  vtxs->add_color(col);
243  vtxs->add_color(col);
244 
245  ye += dy;
246  col += dcol;
247  }
248 
249  } else {
250 
251  float zz = zback;
252  float ye = height*0.5f;
253 
254  sg::rgba* mat = new sg::rgba();
255  mat->color = color;
256  m_back_sep.add(mat);
257 
258  vertices* vtxs = new vertices;
259  vtxs->mode = gl::triangle_fan();
260  m_back_sep.add(vtxs);
261 
262  float r = height*corner_radius;
263  if((r>(0.5f*height.value()))||(r>(0.5f*width.value()))) r = 0;
264 
265  if((r>0) && corner_steps.value()) {
266  float dangle = fhalf_pi()/float(corner_steps);
267  unsigned int nslice = corner_steps;
268 
269  vtxs->add(0,0,zz);
270  vtxs->add(xe,yb+r,zz);
271  vtxs->add(xe,ye-r,zz);
272 
273  // top-right :
274  float angle = dangle;
276  float xc = xe-r;
277  float yc = ye-r;
278  for(unsigned int i=0;i<nslice;i++,angle+=dangle) {
279  vtxs->add(r*fcos(angle)+xc,r*fsin(angle)+yc,zz);
280  }
281  } else {
282  angle += fhalf_pi();
283  vtxs->add(xe,ye,zz);
284  vtxs->add(xe-r,ye,zz);
285  }
286 
287  vtxs->add(xb+r,ye,zz);
288 
289  // top-left :
290  if(corner_mask.value() & corner_top_left()) {
291  float xc = xb+r;
292  float yc = ye-r;
293  for(unsigned int i=0;i<nslice;i++,angle+=dangle) {
294  vtxs->add(r*fcos(angle)+xc,r*fsin(angle)+yc,zz);
295  }
296  } else {
297  angle += fhalf_pi();
298  vtxs->add(xb,ye,zz);
299  vtxs->add(xb,ye-r,zz);
300  }
301 
302  vtxs->add(xb,yb+r,zz);
303 
304  // bottom-left :
306  float xc = xb+r;
307  float yc = yb+r;
308  for(unsigned int i=0;i<nslice;i++,angle+=dangle) {
309  vtxs->add(r*fcos(angle)+xc,r*fsin(angle)+yc,zz);
310  }
311  } else {
312  angle += fhalf_pi();
313  vtxs->add(xb,yb,zz);
314  vtxs->add(xb+r,yb,zz);
315  }
316 
317  vtxs->add(xe-r,yb,zz);
318 
319  // bottom-right :
321  float xc = xe-r;
322  float yc = yb+r;
323  for(unsigned int i=0;i<nslice;i++,angle+=dangle) {
324  vtxs->add(r*fcos(angle)+xc,r*fsin(angle)+yc,zz);
325  }
326  } else {
327  angle += fhalf_pi();
328  vtxs->add(xe,yb,zz);
329  vtxs->add(xe,yb+r,zz);
330  }
331 
332  } else {
333  vtxs->add(xb,yb,zz);
334  vtxs->add(xe,yb,zz);
335  vtxs->add(xe,ye,zz);
336  vtxs->add(xb,ye,zz);
337  }
338 
339  }}
340 
341  if(border_visible.value()){
342  float zz = zborder;
343  float ye = height*0.5f;
344 
345  sg::rgba* mat = new sg::rgba();
346  mat->color = border_color;
347  m_back_sep.add(mat);
348 
349  draw_style* ds = new draw_style;
350  ds->style = draw_lines;
351  ds->line_width = border_line_width;
352  m_back_sep.add(ds);
353 
354  vertices* vtxs = new vertices;
355  vtxs->mode = gl::line_strip();
356  m_back_sep.add(vtxs);
357 
358  float r = height*corner_radius;
359  if((r>(0.5f*height.value()))||(r>(0.5f*width.value()))) r = 0;
360 
361  if((r>0) && corner_steps.value()) {
362  float dangle = fhalf_pi()/float(corner_steps);
363  unsigned int nslice = corner_steps;
364 
365  vtxs->add(xe,yb+r,zz);
366  vtxs->add(xe,ye-r,zz);
367 
368  // top-right :
369  float angle = dangle;
371  float xc = xe-r;
372  float yc = ye-r;
373  for(unsigned int i=0;i<nslice;i++,angle+=dangle) {
374  vtxs->add(r*fcos(angle)+xc,r*fsin(angle)+yc,zz);
375  }
376  } else {
377  angle += fhalf_pi();
378  vtxs->add(xe,ye,zz);
379  vtxs->add(xe-r,ye,zz);
380  }
381 
382  vtxs->add(xb+r,ye,zz);
383 
384  // top-left :
385  if(corner_mask.value() & corner_top_left()) {
386  float xc = xb+r;
387  float yc = ye-r;
388  for(unsigned int i=0;i<nslice;i++,angle+=dangle) {
389  vtxs->add(r*fcos(angle)+xc,r*fsin(angle)+yc,zz);
390  }
391  } else {
392  angle += fhalf_pi();
393  vtxs->add(xb,ye,zz);
394  vtxs->add(xb,ye-r,zz);
395  }
396 
397  vtxs->add(xb,yb+r,zz);
398 
399  // bottom-left :
401  float xc = xb+r;
402  float yc = yb+r;
403  for(unsigned int i=0;i<nslice;i++,angle+=dangle) {
404  vtxs->add(r*fcos(angle)+xc,r*fsin(angle)+yc,zz);
405  }
406  } else {
407  angle += fhalf_pi();
408  vtxs->add(xb,yb,zz);
409  vtxs->add(xb+r,yb,zz);
410  }
411 
412  vtxs->add(xe-r,yb,zz);
413 
414  // bottom-right :
416  float xc = xe-r;
417  float yc = yb+r;
418  for(unsigned int i=0;i<nslice;i++,angle+=dangle) {
419  vtxs->add(r*fcos(angle)+xc,r*fsin(angle)+yc,zz);
420  }
421  } else {
422  angle += fhalf_pi();
423  vtxs->add(xe,yb,zz);
424  vtxs->add(xe,yb+r,zz);
425  }
426 
427  } else {
428  vtxs->add(xb,yb,zz);
429  vtxs->add(xe,yb,zz);
430  vtxs->add(xe,ye,zz);
431  vtxs->add(xb,ye,zz);
432  vtxs->add(xb,yb,zz);
433  }
434  }
435 
436  }

Member Data Documentation

◆ border_color

sf_vec<colorf,float> tools::sg::back_area::border_color

Definition at line 39 of file back_area.

◆ border_line_width

sf<float> tools::sg::back_area::border_line_width

Definition at line 40 of file back_area.

◆ border_visible

sf<bool> tools::sg::back_area::border_visible

Definition at line 38 of file back_area.

◆ color

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

Definition at line 33 of file back_area.

◆ color_top

sf_vec<colorf,float> tools::sg::back_area::color_top

Definition at line 36 of file back_area.

◆ corner_mask

sf<unsigned int> tools::sg::back_area::corner_mask

Definition at line 46 of file back_area.

◆ corner_radius

sf<float> tools::sg::back_area::corner_radius

Definition at line 44 of file back_area.

◆ corner_steps

sf<unsigned int> tools::sg::back_area::corner_steps

Definition at line 45 of file back_area.

◆ gradient

sf<bool> tools::sg::back_area::gradient

Definition at line 35 of file back_area.

◆ height

sf<float> tools::sg::back_area::height

Definition at line 31 of file back_area.

◆ m_back_sep

separator tools::sg::back_area::m_back_sep
protected

Definition at line 438 of file back_area.

◆ shadow

sf<float> tools::sg::back_area::shadow

Definition at line 42 of file back_area.

◆ width

sf<float> tools::sg::back_area::width

Definition at line 30 of file back_area.


The documentation for this class was generated from the following file:
tools::sg::group::search
virtual void search(search_action &a_action)
Definition: group:51
tools::gl::triangle_fan
mode_t triangle_fan()
Definition: glprims:22
tools::sg::back_area::corner_all
static unsigned int corner_all()
Definition: back_area:26
tools::sg::back_area::m_back_sep
separator m_back_sep
Definition: back_area:438
tools::gl::line_strip
mode_t line_strip()
Definition: glprims:19
tools::fcos
float fcos(const float &x)
Definition: mathf:42
tools::sg::separator::pick
virtual void pick(pick_action &a_action)
Definition: separator:31
tools::sg::back_area::border_color
sf_vec< colorf, float > border_color
Definition: back_area:39
tools::sg::back_area::corner_mask
sf< unsigned int > corner_mask
Definition: back_area:46
tools::sg::back_area::color
sf_vec< colorf, float > color
Definition: back_area:33
tools::sg::back_area::color_top
sf_vec< colorf, float > color_top
Definition: back_area:36
tools::gl::triangle_strip
mode_t triangle_strip()
Definition: glprims:21
tools::sg::group::add
void add(node *a_node)
Definition: group:96
tools::sg::back_area::gradient
sf< bool > gradient
Definition: back_area:35
tools::sg::back_area::height
sf< float > height
Definition: back_area:31
tools::sg::back_area::corner_top_left
static unsigned int corner_top_left()
Definition: back_area:23
tools::sg::back_area::border_visible
sf< bool > border_visible
Definition: back_area:38
tools::sg::separator::render
virtual void render(render_action &a_action)
Definition: separator:18
tools::sg::back_area::corner_bottom_left
static unsigned int corner_bottom_left()
Definition: back_area:25
tools::fhalf_pi
float fhalf_pi()
Definition: mathf:13
TOOLS_FIELD_DESC_NODE_CLASS
#define TOOLS_FIELD_DESC_NODE_CLASS(a__class)
Definition: field:68
tools::sg::back_area::corner_radius
sf< float > corner_radius
Definition: back_area:44
tools::sg::back_area::border_line_width
sf< float > border_line_width
Definition: back_area:40
tools::sg::back_area
Definition: back_area:19
tools::sg::group::clear
void clear()
Definition: group:235
tools::sg::bsf::value
T & value()
Definition: bsf:98
tools::fsin
float fsin(const float &x)
Definition: mathf:43
tools::sg::back_area::update_sg
void update_sg()
Definition: back_area:163
tools::sg::back_area::width
sf< float > width
Definition: back_area:30
tools::sg::back_area::corner_steps
sf< unsigned int > corner_steps
Definition: back_area:45
tools::sg::back_area::corner_top_right
static unsigned int corner_top_right()
Definition: back_area:22
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::back_area::shadow
sf< float > shadow
Definition: back_area:42
tools::sg::node::reset_touched
virtual void reset_touched()
Definition: node:102
tools::sg::back_area::corner_bottom_right
static unsigned int corner_bottom_right()
Definition: back_area:24