g4tools  5.4.0
draw_style
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_sg_draw_style
5 #define tools_sg_draw_style
6 
7 #include "node"
8 
9 #include "lpat"
10 #include "sf_enum"
11 #include "render_action"
12 #include "pick_action"
13 #include "bbox_action"
14 
15 namespace tools {
16 namespace sg {
17 
18 class draw_style : public node {
20 public:
27 public:
28  virtual const desc_fields& node_desc_fields() const {
30  static const desc_fields s_v(parent::node_desc_fields(),6, //WARNING : take care of count.
37  );
38  return s_v;
39  }
40 private:
41  void add_fields(){
42  add_field(&style);
48  }
49 public:
50  virtual void render(render_action& a_action) {
51  state& state = a_action.state();
53 
54  if(style.value()==draw_lines) {
55  //no LINE_STIPPLE in GLES.
56  //::glEnable(GL_LINE_STIPPLE); //done in viewer::render()
57  //::glLineStipple(1,line_pattern.value());
58  a_action.line_width(state.m_line_width);
59  } else if(style.value()==draw_points) {
60  a_action.point_size(state.m_point_size);
61  } else if(style.value()==draw_filled) {
63  a_action.set_winding(state.m_winding);
64  }
65  }
66  virtual void pick(pick_action& a_action) {_set_state(a_action.state());}
67  virtual void bbox(bbox_action& a_action) {_set_state(a_action.state());}
68 public:
70  :parent()
72  ,line_width(1) //NOTE : 0 induces a 501 gl error.
74  ,point_size(1)
75  ,cull_face(true)
76  ,winding_ccw(true)
77  {
78  add_fields();
79  }
80  virtual ~draw_style(){}
81 public:
82  draw_style(const draw_style& a_from)
83  :parent(a_from)
84  ,style(a_from.style)
85  ,line_width(a_from.line_width)
86  ,line_pattern(a_from.line_pattern)
87  ,point_size(a_from.point_size)
88  ,cull_face(a_from.cull_face)
89  ,winding_ccw(a_from.winding_ccw)
90  {
91  add_fields();
92  }
93  draw_style& operator=(const draw_style& a_from){
94  parent::operator=(a_from);
95 
96  style = a_from.style;
97  line_width = a_from.line_width;
98  line_pattern = a_from.line_pattern;
99  point_size = a_from.point_size;
100  cull_face = a_from.cull_face;
101  winding_ccw = a_from.winding_ccw;
102 
103  return *this;
104  }
105 protected:
106  void _set_state(state& a_state) {
107  a_state.m_draw_type = style;
108  a_state.m_line_width = line_width;
109  a_state.m_line_pattern = line_pattern;
110  a_state.m_point_size = point_size;
111  a_state.m_GL_CULL_FACE = cull_face;
113  }
114 };
115 
116 }}
117 
118 #endif
lpat
node
tools::sg::draw_style::_set_state
void _set_state(state &a_state)
Definition: draw_style:106
tools::sg::state
Definition: state:25
tools::sg::line_pattern
line_pattern
Definition: enums:10
tools::sg::draw_style::line_pattern
sf< lpat > line_pattern
Definition: draw_style:23
tools::sg::winding_ccw
@ winding_ccw
Definition: enums:105
tools::sg::state::m_point_size
float m_point_size
Definition: state:269
pick_action
tools::sg::draw_style::line_width
sf< float > line_width
Definition: draw_style:22
tools::sg::draw_style::draw_style
draw_style(const draw_style &a_from)
Definition: draw_style:82
render_action
tools::sg::node
Definition: node:28
tools::sg::state::m_GL_CULL_FACE
bool m_GL_CULL_FACE
Definition: state:249
tools::sg::bbox_action
Definition: bbox_action:15
TOOLS_NODE
#define TOOLS_NODE(a__class, a__sclass, a__parent)
Definition: node:324
tools::sg::render_action::set_cull_face
virtual void set_cull_face(bool)=0
tools::sg::render_action::set_winding
virtual void set_winding(winding_type)=0
tools::sg::state::m_winding
winding_type m_winding
Definition: state:258
tools::sg::draw_style
Definition: draw_style:18
tools::sg::draw_points
@ draw_points
Definition: enums:191
tools::sg::desc_fields
Definition: field_desc:148
tools::sg::draw_style::pick
virtual void pick(pick_action &a_action)
Definition: draw_style:66
tools::sg::winding_cw
@ winding_cw
Definition: enums:106
tools::sg::draw_style::operator=
draw_style & operator=(const draw_style &a_from)
Definition: draw_style:93
tools::sg::pick_action
Definition: pick_action:59
tools::sg::draw_filled
@ draw_filled
Definition: enums:193
tools::sg::render_action::point_size
virtual void point_size(float)=0
tools::sg::style
Definition: style:19
tools::sg::draw_style::winding_ccw
sf< bool > winding_ccw
Definition: draw_style:26
tools::sg::sf_enum< draw_type >
tools::sg::draw_style::~draw_style
virtual ~draw_style()
Definition: draw_style:80
tools::sg::render_action
Definition: render_action:24
sf_enum
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::sg::draw_style::draw_style
draw_style()
Definition: draw_style:69
tools::sg::node::add_field
void add_field(field *a_field)
Definition: node:128
tools::sg::draw_style::node_desc_fields
virtual const desc_fields & node_desc_fields() const
Definition: draw_style:28
tools::sg::draw_style::bbox
virtual void bbox(bbox_action &a_action)
Definition: draw_style:67
tools::sg::draw_style::point_size
sf< float > point_size
Definition: draw_style:24
TOOLS_FIELD_DESC_NODE_CLASS
#define TOOLS_FIELD_DESC_NODE_CLASS(a__class)
Definition: field:68
tools::sg::draw_style::cull_face
sf< bool > cull_face
Definition: draw_style:25
tools::sg::line_solid
@ line_solid
Definition: enums:11
tools::sg::bsf::value
T & value()
Definition: bsf:98
tools::sg::state::m_line_pattern
unsigned short m_line_pattern
Definition: state:268
tools::sg::state::m_line_width
float m_line_width
Definition: state:267
tools::sg::render_action::line_width
virtual void line_width(float)=0
tools::sg::states::state
const sg::state & state() const
Definition: states:76
tools::sg::draw_style::style
sf_enum< draw_type > style
Definition: draw_style:21
tools::sg::state::m_draw_type
draw_type m_draw_type
Definition: state:264
tools::sg::draw_lines
@ draw_lines
Definition: enums:192
tools::sg::sf< float >
tools::sg::draw_style::render
virtual void render(render_action &a_action)
Definition: draw_style:50
TOOLS_ARG_FIELD_DESC
#define TOOLS_ARG_FIELD_DESC(a__field)
Definition: field:71
bbox_action