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 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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:
 20   TOOLS_SCLASS(tools::sg::viewer)
 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;
 34     event_action action(m_out,m_ww,m_wh,e);
 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)
 49   ,m_produce_out_file()
 50   ,m_produce_out_bpp(4)
 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)
 65   ,m_clear_color(a_from.m_clear_color)
 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)
 70   ,m_produce_out_jpeg(a_from.m_produce_out_jpeg)
 71   ,m_produce_out_png(a_from.m_produce_out_png)
 72   ,m_produce_out_file(a_from.m_produce_out_file)
 73   ,m_produce_out_bpp(a_from.m_produce_out_bpp)
 74   {
 75 #ifdef TOOLS_MEM
 76     mem::increment(s_class().c_str());
 77 #endif
 78   }
 79   viewer& operator=(const viewer& a_from){
 80     m_clear_color = a_from.m_clear_color;
 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;
 85     m_produce_out_jpeg = a_from.m_produce_out_jpeg;
 86     m_produce_out_png = a_from.m_produce_out_png;
 87     m_produce_out_file = a_from.m_produce_out_file;
 88     m_produce_out_bpp = a_from.m_produce_out_bpp;
 89     return *this;
 90   }
 91 public:
 92   bool set_default_cursor_shape() {return set_cursor_shape(cursor_default);}
 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;
170   colorf m_clear_color;
171   unsigned int m_ww;
172   unsigned int m_wh;
173   group m_sg;
174   std::string m_out_dir;
175   bool m_use_gsto;
176   bool m_produce_out_jpeg;
177   bool m_produce_out_png;
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