g4tools  5.4.0
viewer
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_viewer
5 #define tools_sg_viewer
6 
7 #include "group"
8 
9 #ifdef TOOLS_MEM
10 #include "../mem"
11 #endif
12 
13 #include "cursor_shape"
14 
15 namespace tools {
16 namespace sg {
17 
18 class viewer {
19 public:
21  virtual void* cast(const std::string& a_class) const {
22  if(void* p = cmp_cast<viewer>(this,a_class)) {return p;}
23  else return 0;
24  }
25 public:
26  virtual void set_size(unsigned int a_w,unsigned int a_h) {
27  //m_out << "debug : tools::sg::viewer::set_size :"
28  // << " ww " << a_w
29  // << " wh " << a_h
30  // << std::endl;
31  size_event e(m_ww,m_wh,a_w,a_h);
32  m_ww = a_w;
33  m_wh = a_h;
35  action.set_do_switch_children(true); //Android : rot device : GUI & scene.
36  m_sg.event(action); //used by m_plots in plots_viewer.
37  }
38 
39  virtual bool set_cursor_shape(cursor_shape) {return false;}
40 public:
41  viewer(std::ostream& a_out,unsigned int a_width,unsigned int a_height)
42  :m_out(a_out)
43  ,m_clear_color(1,1,1)
44  ,m_ww(a_width)
45  ,m_wh(a_height)
46  ,m_use_gsto(false)
47  ,m_produce_out_jpeg(false)
48  ,m_produce_out_png(false)
51  {
52 #ifdef TOOLS_MEM
53  mem::increment(s_class().c_str());
54 #endif
55  }
56  virtual ~viewer(){
57  m_sg.clear(); //we must delete node before m_zb_mgr (and any render_manager).
58 #ifdef TOOLS_MEM
59  mem::decrement(s_class().c_str());
60 #endif
61  }
62 public:
63  viewer(const viewer& a_from)
64  :m_out(a_from.m_out)
66  ,m_ww(a_from.m_ww)
67  ,m_wh(a_from.m_wh)
68  ,m_sg(a_from.m_sg)
69  ,m_use_gsto(a_from.m_use_gsto)
74  {
75 #ifdef TOOLS_MEM
76  mem::increment(s_class().c_str());
77 #endif
78  }
79  viewer& operator=(const viewer& a_from){
81  m_ww = a_from.m_ww;
82  m_wh = a_from.m_wh;
83  m_sg = a_from.m_sg;
84  m_use_gsto = a_from.m_use_gsto;
89  return *this;
90  }
91 public:
93 
94  group& sg() {return m_sg;}
95  const group& sg() const {return m_sg;}
96 
97  unsigned int width() const {return m_ww;}
98  unsigned int height() const {return m_wh;}
99 
100  bool screen2aspect(int a_x,int a_y,float& a_wx,float& a_wy) const {
101  // convert screen point in [aspect,1] coordinates.
102  //if(!m_ww) {a_wx = a_wy = 0;return false;}
103  //if(!m_wh) {a_wx = a_wy = 0;return false;}
104  float aspect = float(m_ww)/float(m_wh);
105  float wch = 1;
106  float wcw = wch*aspect;
107  a_wx = float(a_x) * wcw/float(m_ww);
108  a_wy = float(a_y) * wch/float(m_wh);
109  return true;
110  }
111 
112  void set_clear_color(float a_r,float a_g,float a_b,float a_a = 1) {
113  m_clear_color = colorf(a_r,a_g,a_b,a_a);
114  }
115  void set_clear_color(const colorf& a_color) {
116  m_clear_color = a_color;
117  }
118  void get_clear_color(float& a_r,float& a_g,float& a_b,float& a_a) {
119  a_r = m_clear_color.r();
120  a_g = m_clear_color.g();
121  a_b = m_clear_color.b();
122  a_a = m_clear_color.a();
123  }
124 
125  const colorf& background() const {return m_clear_color;}
126 
127  std::ostream& out() const {return m_out;}
128 
129  const std::string& out_dir() const {return m_out_dir;}
130 
131 
132  void set_produce_out_jpeg(bool a_value) {m_produce_out_jpeg = a_value;}
133  bool produce_out_jpeg() const {return m_produce_out_jpeg;}
134 
135  void set_produce_out_png(bool a_value) {m_produce_out_png = a_value;}
136  bool produce_out_png() const {return m_produce_out_png;}
137 
138  void set_produce_out_file(const std::string& a_file) {m_produce_out_file = a_file;}
139  const std::string& produce_out_file() const {return m_produce_out_file;}
140 
141  void set_produce_out_bpp(unsigned int a_bpp) {m_produce_out_bpp = a_bpp;}
142  unsigned int produce_out_bpp() const {return m_produce_out_bpp;}
143 protected:
144  // iPod : 320 x 480
145  // iPad : 768 x 1024
146  // SGS : API-1 : 320 x 533, API-5 : 480 x 800
147  // SGT : 1024 x 600 ?
148 
149  // LRI WILD : borders w = 100 x h = 120. 4x8 screens with 2560x1600 pixels.
150  // LAL ARTS : borders 88x100. 2x4 screens of 1920 x 1080
151 
152  //bool is_iPad() const {
153  // if( (m_ww==768) && (m_wh==1024) ) return true;
154  // if( (m_wh==768) && (m_ww==1024) ) return true;
155  // return false;
156  //}
157  //bool is_SGS() const {
158  // //API : 1
159  // //if( (m_ww==320) && (m_wh==533) ) return true;
160  // //if( (m_wh==320) && (m_ww==533) ) return true;
161  //
162  // //API : 5
163  // if( (m_ww==480) && (m_wh==800) ) return true;
164  // if( (m_wh==480) && (m_ww==800) ) return true;
165  // return false;
166  //}
167 
168 protected:
169  std::ostream& m_out;
171  unsigned int m_ww;
172  unsigned int m_wh;
174  std::string m_out_dir;
178  std::string m_produce_out_file;
179  unsigned int m_produce_out_bpp;
180 };
181 
182 }}
183 
184 #include "../pointer"
185 
186 namespace tools {
187 namespace sg {
188 
189 // used with Python and lua :
190 inline viewer* cast_viewer(const std::string& a_s) {
191  void* p;
192  if(!to_pointer(a_s,p)) return 0; //read with %lx and, if failure, with %lu.
193  return (viewer*)p;
194 }
195 
196 }}
197 
198 #endif
199 
tools::sg::viewer::operator=
viewer & operator=(const viewer &a_from)
Definition: viewer:79
tools::sg::viewer::produce_out_file
const std::string & produce_out_file() const
Definition: viewer:139
tools::sg::viewer::m_wh
unsigned int m_wh
Definition: viewer:172
tools::sg::viewer::set_default_cursor_shape
bool set_default_cursor_shape()
Definition: viewer:92
tools::sg::viewer::m_ww
unsigned int m_ww
Definition: viewer:171
tools::sg::action
Definition: action:19
tools::sg::viewer::m_produce_out_png
bool m_produce_out_png
Definition: viewer:177
tools::sg::viewer::set_produce_out_bpp
void set_produce_out_bpp(unsigned int a_bpp)
Definition: viewer:141
tools::sg::group::event
virtual void event(event_action &a_action)
Definition: group:45
tools::sg::event_action
Definition: event_action:14
tools::colorf
Definition: colorf:11
tools::sg::size_event
Definition: event:53
tools::sg::viewer::viewer
viewer(std::ostream &a_out, unsigned int a_width, unsigned int a_height)
Definition: viewer:41
tools::sg::viewer::m_produce_out_bpp
unsigned int m_produce_out_bpp
Definition: viewer:179
tools::sg::group
Definition: group:21
tools::sg::viewer::m_out_dir
std::string m_out_dir
Definition: viewer:174
cursor_shape
tools::sg::viewer::m_use_gsto
bool m_use_gsto
Definition: viewer:175
group
tools::sg::viewer::m_produce_out_file
std::string m_produce_out_file
Definition: viewer:178
tools::sg::viewer::background
const colorf & background() const
Definition: viewer:125
tools::sg::viewer::produce_out_png
bool produce_out_png() const
Definition: viewer:136
tools::sg::viewer::set_size
virtual void set_size(unsigned int a_w, unsigned int a_h)
Definition: viewer:26
tools::colorf::g
float g() const
Definition: colorf:33
TOOLS_SCLASS
#define TOOLS_SCLASS(a_name)
Definition: S_STRING:41
tools::sg::viewer::out_dir
const std::string & out_dir() const
Definition: viewer:129
tools::sg::viewer::set_produce_out_png
void set_produce_out_png(bool a_value)
Definition: viewer:135
tools::sg::cast_viewer
viewer * cast_viewer(const std::string &a_s)
Definition: viewer:190
tools::sg::viewer::m_sg
group m_sg
Definition: viewer:173
tools::sg::viewer::screen2aspect
bool screen2aspect(int a_x, int a_y, float &a_wx, float &a_wy) const
Definition: viewer:100
tools::sg::viewer::set_clear_color
void set_clear_color(float a_r, float a_g, float a_b, float a_a=1)
Definition: viewer:112
tools::sg::viewer::viewer
viewer(const viewer &a_from)
Definition: viewer:63
tools::sg::viewer::set_produce_out_jpeg
void set_produce_out_jpeg(bool a_value)
Definition: viewer:132
tools::sg::viewer::produce_out_jpeg
bool produce_out_jpeg() const
Definition: viewer:133
tools::sg::viewer::sg
group & sg()
Definition: viewer:94
tools::colorf::a
float a() const
Definition: colorf:35
tools::sg::cursor_default
@ cursor_default
Definition: cursor_shape:11
tools::sg::viewer::sg
const group & sg() const
Definition: viewer:95
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::sg::viewer::m_out
std::ostream & m_out
Definition: viewer:169
tools::sg::viewer::produce_out_bpp
unsigned int produce_out_bpp() const
Definition: viewer:142
tools::sg::viewer::m_produce_out_jpeg
bool m_produce_out_jpeg
Definition: viewer:176
tools::sg::viewer::set_cursor_shape
virtual bool set_cursor_shape(cursor_shape)
Definition: viewer:39
tools::sg::group::clear
void clear()
Definition: group:235
tools::colorf::r
float r() const
Definition: colorf:32
tools::sg::viewer::set_produce_out_file
void set_produce_out_file(const std::string &a_file)
Definition: viewer:138
tools::to_pointer
bool to_pointer(const std::string &a_string, void *&a_value)
Definition: pointer:18
tools::sg::viewer::cast
virtual void * cast(const std::string &a_class) const
Definition: viewer:21
tools::sg::viewer::get_clear_color
void get_clear_color(float &a_r, float &a_g, float &a_b, float &a_a)
Definition: viewer:118
tools::sg::viewer::height
unsigned int height() const
Definition: viewer:98
tools::sg::viewer::width
unsigned int width() const
Definition: viewer:97
tools::sg::viewer::set_clear_color
void set_clear_color(const colorf &a_color)
Definition: viewer:115
tools::sg::viewer
Definition: viewer:18
tools::sg::viewer::out
std::ostream & out() const
Definition: viewer:127
tools::sg::viewer::m_clear_color
colorf m_clear_color
Definition: viewer:170
tools::sg::viewer::~viewer
virtual ~viewer()
Definition: viewer:56
tools::sg::cursor_shape
cursor_shape
Definition: cursor_shape:10
tools::colorf::b
float b() const
Definition: colorf:34