fshake3d  0.0.1
FreeformDensity3DSurfaceEditor
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
ui_SceneRuler.cpp
Go to the documentation of this file.
00001 #include "ui_SceneRuler.hpp"
00002 
00003 Ruler::Ruler()
00004 : mpFont( new Font() )
00005 , mSize(20.0)
00006 , mLeft(0)
00007 , mWidth(1)
00008 , mTick(0.5)
00009 , mVisible(true)
00010 {
00011 }
00012 
00013 void Ruler::display()
00014 {
00015   if (mVisible)
00016   {
00017     setupViewport();
00018     setupTransformationScreen();
00019 
00020     glPushAttrib(GL_ENABLE_BIT|GL_SCISSOR_BIT);
00021 
00022     glEnable(GL_BLEND);
00023     glEnable(GL_SCISSOR_TEST);
00024 
00025     {
00026       int x = (mViewport[0]+mSize < 0) ? 0 : mViewport[0]+mSize;
00027       int y = (mViewport[1] < 0) ? 0 : mViewport[1];
00028       int w = (mViewport[2]-mSize < 0) ? 0 : mViewport[2]-mSize;
00029       int h = (mViewport[3] < 0) ? 0 : mViewport[3];
00030 
00031       glScissor(x,y,w,h);
00032     }
00033 
00034     glColor4d(1.0,1.0,0.0,0.5);
00035     glRectd(0,0,width()-1,mSize);
00036     glColor4d(0.0,0.0,0.0,0.9);
00037     
00038     {
00039       double rest = fmod( mLeft, mTick );
00040 
00041       int n( mWidth / mTick );
00042       double xbase = mLeft - rest;
00043 
00044       glMatrixMode(GL_MODELVIEW);
00045       glPushMatrix();
00046       glScaled( width() / mWidth, 1, 1);
00047       glTranslated( -mLeft, 0, 0 );
00048 
00049 
00050 
00051       for (int i = -1; i <= n+1; ++i ) 
00052       {  
00053         double x = xbase+i*mTick;
00054         glBegin(GL_LINES);
00055         glVertex2d(x,mSize*0.5);
00056         glVertex2d(x,mSize);
00057         glEnd();
00058         char buf[32];
00059         sprintf(buf, "%g", x);
00060         double w = mpFont->computeWidth(buf);
00061 
00062         double shift = w*0.5 * ( mWidth / width() );
00063 
00064         glRasterPos2d(x-shift,0);
00065         mpFont->draw(buf);
00066       }
00067       glPopMatrix();
00068     }
00069 
00070     {
00071       int x = (mViewport[0] < 0) ? 0 : mViewport[0];
00072       int y = (mViewport[1]+mSize < 0) ? 0 : mViewport[1]+mSize;
00073       int w = (mViewport[2] < 0) ? 0 : mViewport[2];
00074       int h = (mViewport[3]-mSize < 0) ? 0 : mViewport[3]-mSize;
00075 
00076       glScissor(x,y,w,h);
00077     }
00078     glColor4d(1.0,1.0,0.0,0.5);
00079     glRectd(0,0,mSize,height()-1);
00080     glColor4d(0.0,0.0,0.0,0.9);
00081 
00082     {
00083       double rest = fmod( mBottom, mTick );
00084 
00085       int n( mHeight / mTick );
00086       double ybase = mBottom - rest;
00087 
00088       glMatrixMode(GL_MODELVIEW);
00089       glPushMatrix();
00090       glScaled( 1, height() / mHeight, 1);
00091       glTranslated( 0, -mBottom, 0 );
00092 
00093       double shift = mpFont->getDescender() * 0.5 * (mWidth / width() );
00094 
00095       for (int i = -1; i <= n+1; ++i ) 
00096       {  
00097         double y = ybase+i*mTick;
00098         glBegin(GL_LINES);
00099         glVertex2d(mSize*0.5,y);
00100         glVertex2d(mSize,y);
00101         glEnd();
00102         char buf[32];
00103         sprintf(buf, "%2.2g", y);
00104         glRasterPos2d(0,y-shift);
00105         mpFont->draw(buf);
00106       }
00107       glPopMatrix();
00108     }
00109 
00110 
00111 
00112     glPopAttrib();
00113   }
00114 }
00115