OpenGLView.cxx

Go to the documentation of this file.
00001 /* Hippo OpenGLView implementation
00002  *
00003  */
00004 
00005 // this :
00006 #include "OpenGLView.h"
00007 
00008 #ifdef HAVE_CONFIG_H
00009 #include "hippoconfig.h"
00010 #else
00011 #ifdef _MSC_VER
00012 #include "msdevstudio/MSconfig.h"
00013 #endif
00014 #endif
00015 
00016 #include "graphics/Color.h"
00017 #include "plotters/CompositePlotter.h"
00018 #include "plotters/PlotterBase.h"
00019 #include "graphics/FontBase.h"
00020 
00021 #include "TextTTF.h"
00022 #include "OpenGL.h"
00023 
00024 #include <iostream>
00025 
00026 #ifdef SSTREAM_DEFECT
00027 #include <strstream>
00028 #else
00029 #include <sstream>
00030 #endif
00031 
00032 //#define DEBUG_GL
00033 
00034 using namespace hippodraw;
00035 
00036 OpenGLView::OpenGLView ()
00037 :m_TTF(0)
00038 {
00039   m_draw_rect.setRect(0,0,100,100);
00040   m_TTF = new hippodraw::TextTTF;
00041 }
00042 
00043 
00044 OpenGLView::~OpenGLView()
00045 {
00046   delete m_TTF;
00047 }
00048 
00049 void OpenGLView::setRect(double aX, double aY, double aW, double aH)
00050 {
00051   m_draw_rect.setRect(aX,aY,aW,aH);
00052 }
00053 
00054 
00055 void OpenGLView::setPlotter ( PlotterBase * plotter )
00056 {
00057   ViewBase::setPlotter ( plotter );
00058   plotter -> addObserver ( this );
00059 }
00060 
00061 PlotterBase* OpenGLView::getPlotter () const
00062 {
00063   return ViewBase::getPlotter ();
00064 }
00065 
00066 
00067 void OpenGLView::drawLines ( const std::vector< double > & x,
00068                              const std::vector< double > & y,
00069                              hippodraw::Line::Style style,
00070                              const Color & color ,float)
00071 {
00072 #ifdef DEBUG_GL  
00073   std::cout << " debug : drawLines " << std::endl;
00074 #endif
00075 
00076   float r = (float)(color.getRed() / 255.0);
00077   float g = (float)(color.getGreen() / 255.0);
00078   float b = (float)(color.getBlue() / 255.0);   
00079 
00080   glColor3f(r,g,b);
00081 
00082 #ifdef DEBUG_GL  
00083   std::cout << "debug : drawLines : color " 
00084             << " r : " << r
00085             << " g : " << g
00086             << " b : " << b
00087             << std::endl;
00088 #endif
00089 
00090   switch (style)
00091     {
00092     case Line::Solid:
00093       break;
00094     case Line::Dot:
00095       break;
00096     case Line::Dash:
00097       break;
00098     case Line::DashDot:
00099       break;
00100     default:
00101       break;
00102     }
00103   
00104   for ( unsigned int i = 0; i < x.size(); i = i+2 ) {
00105     glBegin (GL_LINES);
00106     glVertex3f (toViewX(x[i]),toViewY(y[i]),0 );
00107     glVertex3f (toViewX(x[i+1]),toViewY(y[i+1]),0 );
00108     glEnd ();
00109 #ifdef DEBUG_GL  
00110     std::cout << "debug : " << x[i] << " " << y[i] << std::endl;
00111     std::cout << "debug : " << x[i+1] << " " << y[i+1] << std::endl;
00112 #endif
00113   }
00114 }
00115 
00116 void
00117 OpenGLView::
00118 drawColorLines ( const std::vector< double > & x,
00119                  const std::vector< double > & y,
00120                  hippodraw::Line::Style style,
00121                  const std::vector< Color > & colors,
00122                  float )
00123 {
00124 #ifdef DEBUG_GL  
00125   std::cout << "hippodraw::OpenGLView::drawColorLines :" << std::endl;
00126 #endif
00127 
00128   for (unsigned int i = 0; i < x.size(); i+=2 ){
00129     
00130     const Color & color = colors[i];
00131     float r = color.getRed () / 255.0;
00132     float g = color.getGreen () / 255.0;
00133     float b = color.getBlue () / 255.0;
00134 
00135     glColor3f(r,g,b);
00136 
00137     //FIXME m_outfile << size << " setlinewidth" << endl;
00138 
00139     switch (style) { //FIXME
00140     case Line::Solid:
00141       break;
00142     case Line::Dot:
00143       break;
00144     case Line::Dash:
00145       break;
00146     case Line::DashDot:
00147       break;
00148     default:
00149       break;
00150     }
00151 
00152     glBegin (GL_LINES);
00153     glVertex3f (toViewX(x[i]),toViewY(y[i]),0 );
00154     glVertex3f (toViewX(x[i+1]),toViewY(y[i+1]),0 );
00155     glEnd ();
00156     
00157   }
00158 }
00159 
00160 void OpenGLView::drawViewLines ( 
00161  const std::vector< double > & x
00162 ,const std::vector< double > & y
00163 ,hippodraw::Line::Style style
00164 ,bool //color
00165 ,float
00166 )
00167 {
00168 #ifdef DEBUG_GL  
00169   std::cout << " debug : drawViewLines" << std::endl;
00170 #endif
00171   glColor3f(0,0,0);
00172 
00173   switch (style) { //FIXME
00174   case Line::Solid:
00175     break;
00176   case Line::Dot:
00177     break;
00178   case Line::Dash:
00179     break;
00180   case Line::DashDot:
00181     break;
00182   default:
00183     break;
00184   }
00185 
00186   for ( unsigned int i = 0; i < x.size(); i = i+2 ) {
00187     glBegin (GL_LINES);
00188     glVertex3f (toX(x[i]),toY(y[i]),0 );
00189     glVertex3f (toX(x[i+1]),toY(y[i+1]),0 );
00190     glEnd ();
00191     //std::cout << "debug : " << toX(x[i]) << " " << toY(y[i]) << std::endl;
00192     //std::cout << "debug : " << toX(x[i+1]) << " " << toY(y[i+1]) << std::endl;
00193   }
00194 }
00195  
00196 void OpenGLView::drawViewLines ( const std::vector< double > & x,
00197                                  const std::vector< double > & y,
00198                                  hippodraw::Line::Style style,
00199                                  const Color & color, float)
00200 {
00201 #ifdef DEBUG_GL  
00202   std::cout << " debug : drawViewLines 2" << std::endl;
00203 #endif
00204 
00205   float r = (float)(color.getRed() / 255.0);
00206   float g = (float)(color.getGreen() / 255.0);
00207   float b = (float)(color.getBlue() / 255.0);   
00208 
00209   glColor3f(r,g,b);
00210 
00211   switch (style) { //FIXME
00212   case Line::Solid:
00213     break;
00214   case Line::Dot:
00215     break;
00216   case Line::Dash:
00217     break;
00218   case Line::DashDot:
00219     break;
00220   default:
00221     break;
00222   }
00223   
00224   for ( unsigned int i = 0; i < x.size(); i = i+2 ) {
00225     glBegin (GL_LINES);
00226     glVertex3d (toX(x[i]),toY(y[i]),0 );
00227     glVertex3d (toX(x[i+1]),toY(y[i+1]),0 );
00228     glEnd ();
00229   }
00230 }
00231  
00232 void OpenGLView::drawPolyLine ( const std::vector< double > & xpoints,
00233                                 const std::vector< double > & ypoints, 
00234                                 hippodraw::Line::Style style,
00235                                 const Color & color, float)
00236 {
00237 #ifdef DEBUG_GL  
00238   std::cout << " debug : drawPolyLine" << std::endl;
00239 #endif
00240 
00241   float r = (float)(color.getRed() / 255.0);
00242   float g = (float)(color.getGreen() / 255.0);
00243   float b = (float)(color.getBlue() / 255.0);   
00244 
00245   glColor3f(r,g,b);
00246 
00247   switch (style) {
00248   case Line::Solid:
00249     break;
00250   case Line::Dot:
00251     break;
00252   case Line::Dash:
00253     break;
00254   case Line::DashDot:
00255     break;
00256   default:
00257     break;
00258   }
00259 
00260   glBegin (GL_LINE_STRIP);
00261   for ( unsigned int i = 0; i < xpoints.size(); i++ ) {
00262     glVertex3f (toViewX(xpoints[i]),toViewY(ypoints[i]),0 );
00263 #ifdef DEBUG_GL  
00264     //std::cout << "debug : pol " << i << " " << toViewX(xpoints[i]) << " " << toViewY(ypoints[i]) << std::endl;
00265 #endif
00266   }
00267   glEnd ();
00268 }
00269 
00270 void OpenGLView::drawSquare ( double x1, double y1, double x2, double y2,
00271                            int red, int green, int blue )
00272 {
00273 #ifdef DEBUG_GL  
00274   std::cout << " debug : drawSquare " << std::endl;
00275 #endif
00276 
00277   float r = (float)(red / 255.0);
00278   float g = (float)(green / 255.0);
00279   float b = (float)(blue / 255.0);   
00280 
00281   glColor3f(r,g,b);
00282 
00283   glBegin(GL_POLYGON);
00284   glVertex3f(toViewX(x1),toViewY(y1),0);
00285   glVertex3f(toViewX(x2),toViewY(y1),0);
00286   glVertex3f(toViewX(x2),toViewY(y2),0);
00287   glVertex3f(toViewX(x1),toViewY(y2),0);
00288   glEnd();
00289 }
00290 
00291 void OpenGLView::drawViewSquare ( float x1, float y1, float x2, float y2,
00292                                 int red, int green, int blue ){
00293 #ifdef DEBUG_GL  
00294   std::cout << "hippodraw::OpenGLView::drawViewSquare : " << std::endl;
00295 #endif  
00296   
00297   float r = (float)(red / 255.0);
00298   float g = (float)(green / 255.0);
00299   float b = (float)(blue / 255.0);   
00300 
00301   glColor3f(r,g,b);
00302 
00303   glBegin(GL_POLYGON);
00304   glVertex3f(toX(x1),toY(y1),0);
00305   glVertex3f(toX(x2),toY(y1),0);
00306   glVertex3f(toX(x2),toY(y2),0);
00307   glVertex3f(toX(x1),toY(y2),0);
00308   glEnd();
00309 
00310 }
00311 
00312 void OpenGLView::drawPoints ( const std::vector<double> & x,
00313                               const std::vector<double> & y,
00314                               hippodraw::Symbol::Type type, 
00315                               float sym_size, 
00316                               const Color & color )
00317 {
00318 #ifdef DEBUG_GL  
00319   std::cout << " debug : drawPoints " << std::endl;
00320 #endif
00321 
00322   //printf("debug : type %d %g\n",type,sym_size);
00323 
00324   float r = (float)(color.getRed() / 255.0);
00325   float g = (float)(color.getGreen() / 255.0);
00326   float b = (float)(color.getBlue() / 255.0);   
00327 
00328   glColor3f(r,g,b);
00329 
00330   sym_size *= 0.2;
00331 
00332   for (unsigned int i = 0; i < x.size(); i++) {
00333     switch(type) {
00334       case hippodraw::Symbol::SQUARE:
00335         glBegin(GL_LINE_STRIP);
00336         glVertex3f(toViewX(x[i])-(sym_size/2),toViewY(y[i])-(sym_size/2),0);
00337         glVertex3f(toViewX(x[i])+(sym_size/2),toViewY(y[i])-(sym_size/2),0);
00338         glVertex3f(toViewX(x[i])+(sym_size/2),toViewY(y[i])+(sym_size/2),0);
00339         glVertex3f(toViewX(x[i])-(sym_size/2),toViewY(y[i])+(sym_size/2),0);
00340         glVertex3f(toViewX(x[i])-(sym_size/2),toViewY(y[i])-(sym_size/2),0);
00341         glEnd ();
00342         break;
00343       case hippodraw::Symbol::SOLIDSQUARE:
00344         glBegin(GL_POLYGON);
00345         glVertex3f(toViewX(x[i])-(sym_size/2),toViewY(y[i])-(sym_size/2),0);
00346         glVertex3f(toViewX(x[i])+(sym_size/2),toViewY(y[i])-(sym_size/2),0);
00347         glVertex3f(toViewX(x[i])+(sym_size/2),toViewY(y[i])+(sym_size/2),0);
00348         glVertex3f(toViewX(x[i])-(sym_size/2),toViewY(y[i])+(sym_size/2),0);
00349         glEnd ();
00350         break;
00351       case hippodraw::Symbol::TRIANGLE:
00352         glBegin(GL_LINE_STRIP);
00353         glVertex3f(toViewX(x[i])-(sym_size/2),toViewY(y[i])-(sym_size/2),0);
00354         glVertex3f(toViewX(x[i])+(sym_size/2),toViewY(y[i])-(sym_size/2),0);
00355         glVertex3f(toViewX(x[i]),toViewY(y[i])+(sym_size/2),0);
00356         glVertex3f(toViewX(x[i])-(sym_size/2),toViewY(y[i])-(sym_size/2),0);
00357         glEnd ();
00358         break;
00359       case hippodraw::Symbol::FILLED_TRIANGLE:
00360         glBegin(GL_POLYGON);
00361         glVertex3f(toViewX(x[i])-(sym_size/2),toViewY(y[i])-(sym_size/2),0);
00362         glVertex3f(toViewX(x[i])+(sym_size/2),toViewY(y[i])-(sym_size/2),0);
00363         glVertex3f(toViewX(x[i]),toViewY(y[i])+(sym_size/2),0);
00364         glEnd ();
00365         break;
00366       case hippodraw::Symbol::CIRCLE:
00367       case hippodraw::Symbol::FILLED_CIRCLE:
00368         std::cout << " debug : drawPoints : circle : dummy." << std::endl;
00369         glBegin(GL_LINE_STRIP);
00370 /*
00371           s_outfile << toViewX (x[i]) + (sym_size/2) << " "
00372                     << toViewY (y[i]) << " moveto" << endl;
00373           s_outfile << toViewX (x[i]) << " "
00374                     << toViewY (y[i]) << " "
00375                   << sym_size/2 << " "
00376                   << "0.0 360 arc" << endl;
00377 */
00378         glEnd ();
00379         break;
00380       case hippodraw::Symbol::PLUS:
00381         glBegin(GL_LINES);
00382         glVertex3f(toViewX(x[i])-(sym_size/2),toViewY (y[i]),0);
00383         glVertex3f(toViewX(x[i])+(sym_size/2),toViewY (y[i]),0);
00384         glVertex3f(toViewX(x[i]),toViewY(y[i])-(sym_size/2),0);
00385         glVertex3f(toViewX(x[i]),toViewY(y[i])+(sym_size/2),0);
00386         glEnd ();
00387         break;
00388       case hippodraw::Symbol::TIMES:
00389         glBegin(GL_LINES);
00390         glVertex3f(toViewX(x[i])-(sym_size/2),toViewY(y[i])-(sym_size/2),0);
00391         glVertex3f(toViewX(x[i])+(sym_size/2),toViewY(y[i])+(sym_size/2),0);
00392         glVertex3f(toViewX(x[i])+(sym_size/2),toViewY(y[i])-(sym_size/2),0);
00393         glVertex3f(toViewX(x[i])-(sym_size/2),toViewY(y[i])+(sym_size/2),0);
00394         glEnd ();
00395         break;
00396       default:
00397         break;
00398       }
00399     }
00400 }
00401 
00402 void OpenGLView::drawPoints ( 
00403  const std::vector< double > & //x
00404 ,const std::vector< double > & //y
00405 ,const std::vector< Color > & //colors
00406 ,hippodraw::Symbol::Type //type
00407 ,float //sym_size
00408 )
00409 {
00410 #ifdef DEBUG_GL  
00411   std::cout << " debug : drawPoints 2" << std::endl;
00412 #endif
00413   std::cout << " debug : drawPoints 2 : dummy" << std::endl;
00414   /*
00415   for (unsigned int i = 0; i < x.size(); i++)
00416     {
00417     
00418       s_outfile << "gsave" << endl;
00419       s_outfile << hue[i] << " 1.0 1.0 sethsbcolor" << endl;
00420       s_outfile << "newpath systemdict begin" << endl;
00421 
00422       switch ( type )
00423         {
00424         case hippodraw::Symbol::SQUARE:
00425         case hippodraw::Symbol::SOLIDSQUARE:
00426           
00427           s_outfile << toViewX (x[i])-(sym_size/2) << " " 
00428                   << toViewY (y[i])-(sym_size/2) << " moveto" << endl;
00429           s_outfile << toViewX (x[i])+(sym_size/2) << " " 
00430                     << toViewY (y[i])-(sym_size/2) << " lineto" << endl;
00431           s_outfile << toViewX (x[i])+(sym_size/2) << " " 
00432                     << toViewY (y[i])+(sym_size/2) << " lineto" << endl;
00433           s_outfile << toViewX (x[i])-(sym_size/2) << " " 
00434                     << toViewY (y[i])+(sym_size/2) << " lineto" << endl;
00435           s_outfile << "closepath" << endl;
00436           
00437           break;
00438           
00439         case hippodraw::Symbol::TRIANGLE:
00440         case hippodraw::Symbol::FILLED_TRIANGLE:
00441           s_outfile << toViewX (x[i]) << " " 
00442                     << toViewY (y[i]) + (sym_size/2) << " moveto" << endl;
00443           s_outfile << toViewX (x[i]) + (sym_size/2) << " " 
00444                     << toViewY (y[i])-(sym_size/2) << " lineto" << endl;
00445           s_outfile << toViewX (x[i]) - (sym_size/2) << " " 
00446                     << toViewY (y[i])-(sym_size/2) << " lineto" << endl;
00447           s_outfile << "closepath" << endl;
00448           break;
00449           
00450         case hippodraw::Symbol::CIRCLE:
00451         case hippodraw::Symbol::FILLED_CIRCLE:
00452           s_outfile << toViewX (x[i]) + (sym_size/2) << " "
00453                   << toViewY (y[i]) << " moveto" << endl;
00454           s_outfile << toViewX (x[i]) << " "
00455                   << toViewY (y[i]) << " "
00456                   << sym_size/2 << " "
00457                   << "0.0 360 arc" << endl;
00458           break;
00459 
00460         case hippodraw::Symbol::PLUS:
00461           s_outfile << toViewX (x[i])-(sym_size/2) << " " 
00462                     << toViewY (y[i]) << " moveto" << endl;
00463           s_outfile << toViewX (x[i])+(sym_size/2) << " " 
00464                     << toViewY (y[i]) << " lineto" << endl;
00465           s_outfile << toViewX (x[i]) << " " 
00466                     << toViewY (y[i])-(sym_size/2) << " moveto" << endl;
00467           s_outfile << toViewX (x[i]) << " " 
00468                     << toViewY (y[i])+(sym_size/2) << " lineto" << endl;
00469           break;
00470           
00471         case hippodraw::Symbol::TIMES:
00472           s_outfile << toViewX (x[i])-(sym_size/2) << " " 
00473                     << toViewY (y[i])-(sym_size/2) << " moveto" << endl;
00474           s_outfile << toViewX (x[i])+(sym_size/2) << " " 
00475                     << toViewY (y[i])+(sym_size/2) << " lineto" << endl;
00476           s_outfile << toViewX (x[i])+(sym_size/2) << " " 
00477                     << toViewY (y[i])-(sym_size/2) << " moveto" << endl;
00478           s_outfile << toViewX (x[i])-(sym_size/2) << " " 
00479                     << toViewY (y[i])+(sym_size/2) << " lineto" << endl;
00480           break;
00481 
00482         default:
00483           break;
00484 
00485         }
00486    
00487       s_outfile << "end" << endl;
00488       
00489       if(filled)
00490         {
00491           s_outfile << "fill grestore" << endl;
00492         }
00493       else
00494         {
00495           s_outfile << "stroke grestore" << endl;
00496         }
00497     }
00498   */  
00499 }
00500 
00501 void OpenGLView::drawMag ( float x, float y, int mag, float fontsize )
00502 {
00503 #ifdef SSTREAM_DEFECT
00504   std::ostrstream ost;
00505 #else
00506   std::ostringstream ost;
00507 #endif
00508 
00509   ost << mag << std::ends;
00510   const std::string s(ost.str());
00511 #ifdef DEBUG_GL  
00512   std::cout << " debug : drawMag " << s 
00513             << " x " << x << " y " << y 
00514             << " fontsize " << fontsize
00515             << std::endl;
00516 #endif
00517   // AxisRep2D::drawXTickLabels do not give good y position
00518   // when having an y upstream. We try to reverse what is done
00519   // here (yp=t) and correct.
00520 
00521   // Reverse :
00522 /*
00523   float font_size = fontsize / 0.75;
00524   y -= m_draw_rect.getY();
00525   y -= (font_size * 1.2);
00526   // Correct :
00527   y -= (font_size * 1.2);
00528   y += m_draw_rect.getY();
00529 */
00530 
00531   draw_Text ( std::string("x10"), toX(x), toY(y), fontsize, 0, 'l', 't' );
00532 
00533   draw_Text ( s, toX(x+2*fontsize), toY(y+fontsize*0.2), fontsize, 0, 'l', 't' );
00534 }
00535 
00536 // void OpenGLView::drawUserText ( const std::string &s, float x, float y,
00537 //                           float fontsize, float angle,
00538 //                           char xp, char yp )
00539 // {
00540 // #ifdef DEBUG_GL  
00541 //   std::cout << " debug : drawUserText " << s << std::endl;
00542 // #endif
00543 //   draw_Text ( s, toViewX (x), toViewY (y), fontsize, angle, xp , yp);
00544 // }
00545 
00546 void OpenGLView::drawText ( const std::string &s, float x, float y,
00547                          float fontsize, float angle,
00548                          char xp, char yp , bool)
00549 {
00550 #ifdef DEBUG_GL  
00551   std::cout << " debug : drawText " << s << std::endl;
00552 #endif
00553   draw_Text ( s, toX(x), toY(y), fontsize, angle, xp, yp );
00554 }
00555 
00556 void OpenGLView::drawText ( const std::string &s, float x, float y,
00557                             float fontsize, float angle,
00558                             char xp, char yp, bool,
00559                             const FontBase * font,
00560                             const Color * color )
00561 {
00562 #ifdef DEBUG_GL  
00563   std::cout << " debug : drawText2 " << s << std::endl;
00564 #endif
00565   draw_Text ( s, toX(x), toY(y), fontsize, angle, xp, yp, font );
00566 }
00567 
00568 void OpenGLView:: update (  
00569  const Observable * //display 
00570 )
00571 {
00572   //std::cout << " debug : update : dummy." << std::endl;
00573 }
00574 
00575 float OpenGLView::userToDrawX ( double x ) const
00576 {
00577 //   return m_plotter->userToMarginX( x );
00578   return userToMarginX( x );
00579 }
00580 
00581 float OpenGLView::userToDrawY ( double y ) const
00582 {
00583 //   return m_plotter->userToInvertedMarginY( y );
00584   return userToInvertedMarginY( y );
00585 }
00586 
00587 float OpenGLView::userToDrawColor ( double c ) const
00588 {
00589  //  return m_plotter->userToMarginColor( c );
00590 // }
00591 return userToMarginColor( c );
00592 }
00593 
00594 Rect OpenGLView::getDrawRect() const
00595 {
00596   return m_draw_rect;
00597 }
00598 void OpenGLView::setDrawRect ( 
00599  float //x
00600 ,float //y
00601 ,float //w
00602 ,float //h 
00603 ) {
00604   std::cout << "hippodraw::OpenGLView::setDrawRect : dummy " << std::endl;
00605 }
00606 
00610 void OpenGLView::draw_Text ( 
00611  const std::string &s
00612 ,float x
00613 ,float y
00614 ,float fontsize
00615 ,float angle
00616 ,char xp
00617 ,char yp
00618 ,const FontBase* font
00619 )
00620 {
00621 #ifdef DEBUG_GL  
00622 #endif
00623   std::cout << " debug : draw_Text \"" << s 
00624             << "\" : x " << x
00625             << " y " << y
00626             << " fontsize " << fontsize
00627             << " angle " << angle
00628             << " xp " << xp
00629             << " yp " << yp
00630             << " font " << font
00631             << std::endl;
00632   if(font) 
00633     std::cout << " debug : draw_Text \"" << font->family() 
00634               << "\" : pointSize " << font->pointSize()
00635               << std::endl;
00636   if(angle==90)
00637     glRasterPos2f(x+12,y);
00638   else 
00639     glRasterPos2f(x,y);
00640 
00641   hippodraw::TextTTF::Justification hJ;
00642   switch (xp) {
00643   case 'c':
00644   case 'C':
00645     hJ = hippodraw::TextTTF::CENTER;
00646     break;
00647   case 'r':
00648   case 'R':
00649     hJ = hippodraw::TextTTF::RIGHT;
00650     break;
00651   default:
00652     hJ = hippodraw::TextTTF::LEFT;
00653     break;
00654   }
00655 
00656   hippodraw::TextTTF::Justification vJ;
00657   switch (yp){
00658   case 'c':
00659   case 'C':
00660     vJ = hippodraw::TextTTF::MIDDLE;
00661     break;
00662   case 't':
00663   case 'T':
00664     vJ = hippodraw::TextTTF::TOP;
00665     break;
00666   default:
00667     vJ = hippodraw::TextTTF::BOTTOM;
00668     break;
00669   }
00670   
00671   // fontsize 4 -> TTF pointSize 10
00672   // fontsize 5 -> TTF pointSize 25  (CERN Personnel)
00674   //  25 = a * 5 + b;
00675   //  10 = a * 4 + b;
00676   //float a = (25-10)/(5-4);
00677   //float b = 25 - a * 5;
00678   //float pointSize = a * fontsize + b;
00679   float pointSize = fontsize * 0.8;
00680 
00681   m_TTF->setString(s);
00682   m_TTF->setSize(pointSize);
00683   m_TTF->setJustification(hJ,vJ);
00684   m_TTF->setRotated(angle==90?true:false);
00685   m_TTF->render();
00686 }
00687 
00688 float OpenGLView::toViewX ( double datX ) const
00689 {
00690   //return toX(m_plotter->userToMarginX ( datX ));
00691 //   return ( m_draw_rect.getX() + m_plotter->userToMarginX ( datX ) );
00692   return ( m_draw_rect.getX() + userToMarginX ( datX ) );
00693 }
00694 
00695 float OpenGLView::toViewY ( double datY ) const
00696 {
00697   Rect m_boundingRect(m_draw_rect.getX(),
00698                       m_draw_rect.getY(),
00699                       m_draw_rect.getWidth(),
00700                       m_draw_rect.getHeight());
00701   //From EpsView::toViewY.
00702   float s1 = 2 * m_boundingRect.getY() + m_boundingRect.getHeight();
00703 
00704   float s2 = 2 * m_draw_rect.getY() + m_draw_rect.getHeight();
00705 
00706 //   return ( s1 - ( s2 -  ( ( m_draw_rect.getY() 
00707 //                          + m_plotter->userToMarginY ( datY ) ) - 
00708 //                        ( 2 * m_plotter->getMarginRect().getY() ) +
00709 //                        ( m_draw_rect.getHeight() ) - 
00710 //                        ( m_plotter->getMarginRect().getHeight() )
00711   return ( s1 - ( s2 -  ( ( m_draw_rect.getY() 
00712                             + userToMarginY ( datY ) ) - 
00713                           ( 2 * getMarginRect().getY() ) +
00714                           ( m_draw_rect.getHeight() ) - 
00715                           ( getMarginRect().getHeight() )
00716                           )
00717                   )
00718            );
00719 }
00720 
00721 float OpenGLView::toCanvasX ( double dx ) const
00722 {
00723   return static_cast < float > ( dx );
00724 }
00725 
00726 float OpenGLView::toCanvasY ( double dy ) const
00727 {
00728   return static_cast < float > ( dy );
00729   //return toY(dy);
00730 }
00731 
00732 float OpenGLView::toX ( double x ) const
00733 {
00734   return static_cast<float> ( m_draw_rect.getX() + x );
00735 }
00736 float OpenGLView::toY ( double y ) const
00737 {
00738   return static_cast<float>(m_draw_rect.getY()+m_draw_rect.getHeight()-y);
00739 }

Generated for HippoDraw Class Library by doxygen