fshake3d  0.0.1
FreeformDensity3DSurfaceEditor
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
ui_View.cpp
Go to the documentation of this file.
00001 #include "ui_View.hpp"
00002 
00003 View::View()
00004   : mViewport(0,0,256,256)
00005   , mBGColor(0,0,0)
00006   , mpParent(0)
00007 {
00008 }
00009 void View::reshape(int w, int h) 
00010 { 
00011   setViewport( Vec4i(mViewport[0], mViewport[1], w, h) );
00012 }
00013 void View::setViewport(const Vec4i& vp)
00014 {
00015   mViewport = vp;
00016 }
00017   
00018 const int& View::width()  const 
00019 { 
00020   return mViewport[2]; 
00021 }
00022 
00023 const int& View::height() const 
00024 { 
00025   return mViewport[3]; 
00026 }
00027 
00028 void View::setBGColor(const Vec3d& color)
00029 {
00030   mBGColor = color;
00031 }
00032 
00033 void View::display()
00034 {
00035   setupViewport();
00036   setupTransformation();
00037   drawClearRect();
00038 }
00039 
00040   // user input
00041 
00042 void View::mouse(int button, int state, int x, int y) 
00043 { 
00044 }
00045 void View::motion(int x, int y) 
00046 { 
00047 }
00048 
00049 void View::onEvent(Event& e) 
00050 { 
00051 }
00052 
00053 Window* View::getWindow() 
00054 { 
00055   return (mpParent) ? mpParent->getWindow() : 0; 
00056 }
00057 
00058 
00059 void View::drawClearRect()
00060 {  
00061   glColor3d(mBGColor[0],mBGColor[1],mBGColor[2]);
00062   glRecti(-1,-1,1,1);
00063 }
00072 void View::setupProjectionOrthoNormal()
00073 {
00074   glMatrixMode(GL_PROJECTION);
00075   glLoadIdentity();
00076   glOrtho(-1,1,-1,1,-1,1);
00077 }
00078 void View::setupTransformationNormal()
00079 {
00080   setupProjectionOrthoNormal();
00081   glMatrixMode(GL_MODELVIEW);
00082   glLoadIdentity();
00083 }
00092 void View::setupTransformationScreen()
00093 {
00094   glMatrixMode(GL_PROJECTION);
00095   glLoadIdentity();
00096   glOrtho(0,width()-1,0,height()-1,0,1);
00097   glMatrixMode(GL_MODELVIEW);
00098   glLoadIdentity();
00099 }
00100 
00101 void View::setupViewport()
00102 {
00103   int x = (mViewport[0] < 0) ? 0 : mViewport[0];
00104   int y = (mViewport[1] < 0) ? 0 : mViewport[1];
00105   int w = (mViewport[2] < 0) ? 0 : mViewport[2];
00106   int h = (mViewport[3] < 0) ? 0 : mViewport[3];
00107   glViewport(x,y,w,h);
00108 }
00109 
00110 void View::setupTransformation()
00111 {
00112   setupTransformationNormal();
00113 }
00114 
00115 void View::setParent(View* pParent)
00116 {
00117   mpParent = pParent;
00118 }