Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3