OpenGLCtrl Class Reference

#include <TAPsOpenGLCtrl.hpp>

Inheritance diagram for OpenGLCtrl:

Inheritance graph
[legend]

List of all members.

Public Member Functions

virtual void Default ()
virtual void Draw ()=0
void GetBackgroundActColor (float &r, float &g, float &b, float &a) const
void GetBackgroundColor (float &r, float &g, float &b, float &a) const
int GetBorder () const
float GetBorderOpacity () const
void GetForegroundActColor (float &r, float &g, float &b, float &a) const
void GetForegroundColor (float &r, float &g, float &b, float &a) const
int GetID () const
float GetOpacity () const
void GetSize (int &width, int &height) const
void GetStartPos (int &x, int &y) const
bool GetStatus () const
std::string GetText () const
virtual bool IsInside (int x, int y)
virtual bool IsInsidePlusBorder (int x, int y)
 OpenGLCtrl ()
void SetBackgroundActColor (float r, float g, float b, float a)
void SetBackgroundColor (float r, float g, float b, float a)
void SetBorder (int size)
void SetBorderOpacity (float alpha)
void SetForegroundActColor (float r, float g, float b, float a)
void SetForegroundColor (float r, float g, float b, float a)
virtual void SetOpacity (float alpha)
virtual void SetSize (int width, int height)
virtual void SetStartPos (int x=0, int y=0)
void SetStatus (bool b)
void SetText (std::string text)
void ToggleStatus ()
virtual ~OpenGLCtrl ()

Static Public Member Functions

static void BeginDrawing (float fUnitsPerPixel=1, bool useBlending=true)
static void EndDrawing ()
static void GetBorderColor (float &r, float &g, float &b, float &a)
static void SetBorderColor (float r, float g, float b, float a)

Protected Member Functions

virtual void DrawBackgroundAndBorder ()
virtual void DrawBackgroundAndBorder_Off ()
virtual void DrawBackgroundAndBorder_On ()
virtual void DrawText ()

Protected Attributes

float m_BackgroundActColor [4]
float m_BackgroundColor [4]
int m_BorderSize
int m_DrawSizeXY [2]
float m_ForegroundActColor [4]
float m_ForegroundColor [4]
bool m_IsOn
std::string m_Text
int m_xyLowerLeftPt [2]

Static Protected Attributes

static float g_BorderColor [4] = { 0.5, 0.5, 0.5, 0.7 }
static int g_ID = 0


Detailed Description

Definition at line 17 of file TAPsOpenGLCtrl.hpp.


Constructor & Destructor Documentation

OpenGLCtrl::OpenGLCtrl (  ) 

Definition at line 23 of file TAPsOpenGLCtrl.cpp.

00024 {
00025     ++g_ID;
00026     Default();
00027 }

OpenGLCtrl::~OpenGLCtrl (  )  [virtual]

Definition at line 29 of file TAPsOpenGLCtrl.cpp.

00030 {}


Member Function Documentation

void OpenGLCtrl::BeginDrawing ( float  fUnitsPerPixel = 1,
bool  useBlending = true 
) [static]

BeginDrawing/EndDrawing functions help facilitate drawing of OpenGL control components. fUnitsPerPixel maps units per pixel. useBlending is true for transparency drawing. Currently only value of 1 will work correctly. Future plan will support any positive value.

The draw function of any control should be called between these functions.

Example:

TAPs::OpenGL::OpenGLCtrl::BeginDrawing();

gTransferFnCtrl->Draw();

TAPs::OpenGL::OpenGLCtrl::EndDrawing();

Definition at line 196 of file TAPsOpenGLCtrl.cpp.

00197 {
00198     glPushAttrib( GL_ALL_ATTRIB_BITS );
00199     //---------------------------------------------------------------
00200     // Setup Ortho and Viewport
00201     glMatrixMode( GL_PROJECTION );
00202     glPushMatrix();
00203     glLoadIdentity();
00204     GLfloat pViewPort[4];
00205     glGetFloatv( GL_VIEWPORT, pViewPort );
00206     //glOrtho( 0, pViewPort[2]-pViewPort[0], 0, pViewPort[3]-pViewPort[1], -1, 1 );
00207     glOrtho( pViewPort[0]*fUnitsPerPixel, pViewPort[2]*fUnitsPerPixel, 
00208              pViewPort[1]*fUnitsPerPixel, pViewPort[3]*fUnitsPerPixel, 
00209              -1, 1 );
00210     glMatrixMode( GL_MODELVIEW );
00211     glPushMatrix();
00212     glLoadIdentity();
00213     //---------------------------------------------------------------
00214     if ( useBlending ) {
00215         glEnable( GL_BLEND );
00216         glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
00217     }
00218     else {
00219         glDisable( GL_BLEND );
00220     }
00221     glDisable( GL_LIGHTING );
00222     glDisable( GL_DEPTH_TEST );
00223     //glDisable( GL_CULL_FACE );
00224     glFrontFace( GL_CW );
00225     glPointSize( 1 );
00226     glLineWidth( 1 );
00227 }

void OpenGLCtrl::Default (  )  [virtual]

Reimplemented in OpenGLCtrlButton, OpenGLCtrlSlider, and OpenGLCtrlTransferFn.

Definition at line 37 of file TAPsOpenGLCtrl.cpp.

00038 {
00039     SetStartPos( 0, 0 );
00040     SetSize( 20, 20 );
00041     SetText( "Ctrl" );
00042     //
00043     m_BorderSize = 2;
00044     //
00045     m_IsOn = false;
00046     //
00047     m_ForegroundColor[0] = 1.0;
00048     m_ForegroundColor[1] = 1.0;
00049     m_ForegroundColor[2] = 1.0;
00050     m_ForegroundColor[3] = 0.70;
00051     //
00052     m_BackgroundColor[0] = 0.25;
00053     m_BackgroundColor[1] = 0.25;
00054     m_BackgroundColor[2] = 0.25;
00055     m_BackgroundColor[3] = 0.70;
00056     //
00057     m_ForegroundActColor[0] = 0.2;
00058     m_ForegroundActColor[1] = 0.1;
00059     m_ForegroundActColor[2] = 0.2;
00060     m_ForegroundActColor[3] = 0.70;
00061     //
00062     m_BackgroundActColor[0] = 0.2;
00063     m_BackgroundActColor[1] = 1.0;
00064     m_BackgroundActColor[2] = 0.2;
00065     m_BackgroundActColor[3] = 0.70;
00066 }

virtual void OpenGLCtrl::Draw (  )  [pure virtual]

The start (x,y) is the left-bottom point of a bounding box. A subclass that overrides this method should use start (x,y) as drawing w/o border. Another words, the border is extended from the start (x,y).

Hence, in order to use border as the starting point for drawing, the code below can be used.

SetStartPos( GetBorder() + x, GetBorder() + y );

Where (x,y) is the starting position.

Implemented in OpenGLCtrlButton, OpenGLCtrlSlider, and OpenGLCtrlTransferFn.

void OpenGLCtrl::DrawBackgroundAndBorder (  )  [inline, protected, virtual]

Definition at line 241 of file TAPsOpenGLCtrl.cpp.

00242 {
00243     //---------------------------------------------------------------
00244     // Draw Background with Border
00245     if ( m_IsOn ) {
00246         DrawBackgroundAndBorder_On();
00247     }
00248     else {
00249         DrawBackgroundAndBorder_Off();
00250     }
00251 }

void OpenGLCtrl::DrawBackgroundAndBorder_Off (  )  [protected, virtual]

Definition at line 253 of file TAPsOpenGLCtrl.cpp.

00254 {
00255     //---------------------------------------------------------------
00256     // Draw Background with Border
00257     {
00258         int X = m_xyLowerLeftPt[0] + m_DrawSizeXY[0];
00259         int Y = m_xyLowerLeftPt[1] + m_DrawSizeXY[1];
00260         int mx = m_xyLowerLeftPt[0];
00261         int my = m_xyLowerLeftPt[1];
00262         glBegin( GL_QUADS );
00263             // Draw Background
00264             glColor4fv( m_BackgroundColor );
00265             glVertex2f( mx, my );
00266             glVertex2f(  X, my );
00267             glVertex2f(  X,  Y );
00268             glVertex2f( mx,  Y );
00269             //
00270             glColor4fv( g_BorderColor );
00271             // Draw Left Border
00272             int LX = m_xyLowerLeftPt[0] - m_BorderSize;
00273             int BY = m_xyLowerLeftPt[1] - m_BorderSize;
00274             glVertex2f( LX,  m_xyLowerLeftPt[1] );
00275             glVertex2f( m_xyLowerLeftPt[0], m_xyLowerLeftPt[1] );
00276             glVertex2f( m_xyLowerLeftPt[0], Y );
00277             glVertex2f( LX,  Y );
00278             // Draw Right Border
00279             int RX = X + m_BorderSize;
00280             int TY = Y + m_BorderSize;
00281             glVertex2f(  X, m_xyLowerLeftPt[1] );
00282             glVertex2f( RX, m_xyLowerLeftPt[1] );
00283             glVertex2f( RX,  Y );
00284             glVertex2f(  X,  Y );
00285             // Draw Top Border
00286             glVertex2f( LX,  Y );
00287             glVertex2f( RX,  Y );
00288             glVertex2f( RX, TY );
00289             glVertex2f( LX, TY );
00290             // Draw Bottom Border
00291             glVertex2f( LX, BY );
00292             glVertex2f( RX, BY );
00293             glVertex2f( RX, m_xyLowerLeftPt[1] );
00294             glVertex2f( LX, m_xyLowerLeftPt[1] );
00295         glEnd();
00296     }
00297 }

void OpenGLCtrl::DrawBackgroundAndBorder_On (  )  [protected, virtual]

Definition at line 299 of file TAPsOpenGLCtrl.cpp.

00300 {
00301     //---------------------------------------------------------------
00302     // Draw Background with Border
00303     {
00304         int X = m_xyLowerLeftPt[0] + m_DrawSizeXY[0];
00305         int Y = m_xyLowerLeftPt[1] + m_DrawSizeXY[1];
00306         int mx = m_xyLowerLeftPt[0];
00307         int my = m_xyLowerLeftPt[1];
00308         glBegin( GL_QUADS );
00309             // Draw Background
00310             glColor4fv( m_BackgroundActColor );
00311             glVertex2f( mx, my );
00312             glVertex2f(  X, my );
00313             glVertex2f(  X,  Y );
00314             glVertex2f( mx,  Y );
00315             //
00316             //X  += m_BorderSize;
00317             //Y  += m_BorderSize;
00318             //mx -= m_BorderSize;
00319             //my -= m_BorderSize;
00320             glColor4fv( g_BorderColor );
00321             // Draw Left Border
00322             int LX = m_xyLowerLeftPt[0] - m_BorderSize;
00323             int BY = m_xyLowerLeftPt[1] - m_BorderSize;
00324             glVertex2f( LX, m_xyLowerLeftPt[1] );
00325             glVertex2f( m_xyLowerLeftPt[0], m_xyLowerLeftPt[1] );
00326             glVertex2f( m_xyLowerLeftPt[0], Y );
00327             glVertex2f( LX,  Y );
00328             // Draw Right Border
00329             int RX = X + m_BorderSize;
00330             int TY = Y + m_BorderSize;
00331             glVertex2f(  X, m_xyLowerLeftPt[1] );
00332             glVertex2f( RX, m_xyLowerLeftPt[1] );
00333             glVertex2f( RX,  Y );
00334             glVertex2f(  X,  Y );
00335             // Draw Top Border
00336             glVertex2f( LX,  Y );
00337             glVertex2f( RX,  Y );
00338             glVertex2f( RX, TY );
00339             glVertex2f( LX, TY );
00340             // Draw Bottom Border
00341             glVertex2f( LX, BY );
00342             glVertex2f( RX, BY );
00343             glVertex2f( RX, m_xyLowerLeftPt[1] );
00344             glVertex2f( LX, m_xyLowerLeftPt[1] );
00345         glEnd();
00346     }
00347 }

void OpenGLCtrl::DrawText (  )  [inline, protected, virtual]

Definition at line 349 of file TAPsOpenGLCtrl.cpp.

00350 {
00351     if ( m_IsOn )   glColor4fv( m_ForegroundActColor );
00352     else            glColor4fv( m_ForegroundColor );
00353     OpenGL::Fn::DrawGLText( m_Text, 
00354         m_xyLowerLeftPt[0]+2, m_xyLowerLeftPt[1] + m_DrawSizeXY[1]/3 );
00355 }

void OpenGLCtrl::EndDrawing (  )  [static]

Definition at line 229 of file TAPsOpenGLCtrl.cpp.

00230 {
00231     //---------------------------------------------------------------
00232     // Return the previous Ortho and Viewport
00233     glPopMatrix();
00234     glMatrixMode( GL_PROJECTION );
00235     glPopMatrix();
00236     glMatrixMode( GL_MODELVIEW );
00237     //---------------------------------------------------------------
00238     glPopAttrib();
00239 }

void OpenGLCtrl::GetBackgroundActColor ( float &  r,
float &  g,
float &  b,
float &  a 
) const

Definition at line 146 of file TAPsOpenGLCtrl.cpp.

00148 {
00149     r = m_BackgroundActColor[0];
00150     g = m_BackgroundActColor[1];
00151     b = m_BackgroundActColor[2];
00152     a = m_BackgroundActColor[3];
00153 }

void OpenGLCtrl::GetBackgroundColor ( float &  r,
float &  g,
float &  b,
float &  a 
) const

Definition at line 110 of file TAPsOpenGLCtrl.cpp.

00112 {
00113     r = m_BackgroundColor[0];
00114     g = m_BackgroundColor[1];
00115     b = m_BackgroundColor[2];
00116     a = m_BackgroundColor[3];
00117 }

int OpenGLCtrl::GetBorder (  )  const [inline]

Definition at line 35 of file TAPsOpenGLCtrl.hpp.

00035 { return m_BorderSize; }

void OpenGLCtrl::GetBorderColor ( float &  r,
float &  g,
float &  b,
float &  a 
) [static]

Definition at line 164 of file TAPsOpenGLCtrl.cpp.

00166 {
00167     r = g_BorderColor[0];
00168     g = g_BorderColor[1];
00169     b = g_BorderColor[2];
00170     a = g_BorderColor[3];
00171 }

float OpenGLCtrl::GetBorderOpacity (  )  const [inline]

Definition at line 58 of file TAPsOpenGLCtrl.hpp.

00058 { return g_BorderColor[3]; }

void OpenGLCtrl::GetForegroundActColor ( float &  r,
float &  g,
float &  b,
float &  a 
) const

Definition at line 128 of file TAPsOpenGLCtrl.cpp.

00130 {
00131     r = m_ForegroundActColor[0];
00132     g = m_ForegroundActColor[1];
00133     b = m_ForegroundActColor[2];
00134     a = m_ForegroundActColor[3];
00135 }

void OpenGLCtrl::GetForegroundColor ( float &  r,
float &  g,
float &  b,
float &  a 
) const

Definition at line 92 of file TAPsOpenGLCtrl.cpp.

00094 {
00095     r = m_ForegroundColor[0];
00096     g = m_ForegroundColor[1];
00097     b = m_ForegroundColor[2];
00098     a = m_ForegroundColor[3];
00099 }

int OpenGLCtrl::GetID (  )  const [inline]

Definition at line 27 of file TAPsOpenGLCtrl.hpp.

00027 { return g_ID; };

float OpenGLCtrl::GetOpacity (  )  const [inline]

Definition at line 56 of file TAPsOpenGLCtrl.hpp.

00056 { return m_ForegroundColor[3]; }

void OpenGLCtrl::GetSize ( int &  width,
int &  height 
) const

Definition at line 80 of file TAPsOpenGLCtrl.cpp.

00081 {
00082     width  = m_DrawSizeXY[0];
00083     height = m_DrawSizeXY[1];
00084 }

void OpenGLCtrl::GetStartPos ( int &  x,
int &  y 
) const

Definition at line 68 of file TAPsOpenGLCtrl.cpp.

00069 {
00070     x = m_xyLowerLeftPt[0];
00071     y = m_xyLowerLeftPt[1];
00072 }

bool OpenGLCtrl::GetStatus (  )  const [inline]

Definition at line 28 of file TAPsOpenGLCtrl.hpp.

00028 { return m_IsOn; }

std::string OpenGLCtrl::GetText (  )  const [inline]

Definition at line 37 of file TAPsOpenGLCtrl.hpp.

00037 { return m_Text; }

virtual bool OpenGLCtrl::IsInside ( int  x,
int  y 
) [inline, virtual]

Inquire whether the position is inside the object.

Reimplemented in OpenGLCtrlTransferFn.

Definition at line 68 of file TAPsOpenGLCtrl.hpp.

00069     {
00070         return 
00071              m_xyLowerLeftPt[0] <= x && x <= m_xyLowerLeftPt[0]+m_DrawSizeXY[0]
00072           && m_xyLowerLeftPt[1] <= y && y <= m_xyLowerLeftPt[1]+m_DrawSizeXY[1];
00073     }

virtual bool OpenGLCtrl::IsInsidePlusBorder ( int  x,
int  y 
) [inline, virtual]

Inquire whether the position is inside the object including its border.

Reimplemented in OpenGLCtrlTransferFn.

Definition at line 77 of file TAPsOpenGLCtrl.hpp.

00078     {
00079         return 
00080              m_xyLowerLeftPt[0]-m_BorderSize <= x && x <= m_xyLowerLeftPt[0]+m_DrawSizeXY[0]+m_BorderSize
00081           && m_xyLowerLeftPt[1]-m_BorderSize <= y && y <= m_xyLowerLeftPt[1]+m_DrawSizeXY[1]+m_BorderSize;
00082     }

void OpenGLCtrl::SetBackgroundActColor ( float  r,
float  g,
float  b,
float  a 
)

Definition at line 155 of file TAPsOpenGLCtrl.cpp.

00157 {
00158     m_BackgroundActColor[0] = r;
00159     m_BackgroundActColor[1] = g;
00160     m_BackgroundActColor[2] = b;
00161     m_BackgroundActColor[3] = a;
00162 }

void OpenGLCtrl::SetBackgroundColor ( float  r,
float  g,
float  b,
float  a 
)

Definition at line 119 of file TAPsOpenGLCtrl.cpp.

00121 {
00122     m_BackgroundColor[0] = r;
00123     m_BackgroundColor[1] = g;
00124     m_BackgroundColor[2] = b;
00125     m_BackgroundColor[3] = a;
00126 }

void OpenGLCtrl::SetBorder ( int  size  )  [inline]

Definition at line 36 of file TAPsOpenGLCtrl.hpp.

00036 { m_BorderSize = size; }

void OpenGLCtrl::SetBorderColor ( float  r,
float  g,
float  b,
float  a 
) [static]

Definition at line 173 of file TAPsOpenGLCtrl.cpp.

00175 {
00176     g_BorderColor[0] = r;
00177     g_BorderColor[1] = g;
00178     g_BorderColor[2] = b;
00179     g_BorderColor[3] = a;
00180 }

void OpenGLCtrl::SetBorderOpacity ( float  alpha  )  [inline]

Definition at line 59 of file TAPsOpenGLCtrl.hpp.

00059 { g_BorderColor[3] = alpha; }

void OpenGLCtrl::SetForegroundActColor ( float  r,
float  g,
float  b,
float  a 
)

Definition at line 137 of file TAPsOpenGLCtrl.cpp.

00139 {
00140     m_ForegroundActColor[0] = r;
00141     m_ForegroundActColor[1] = g;
00142     m_ForegroundActColor[2] = b;
00143     m_ForegroundActColor[3] = a;
00144 }

void OpenGLCtrl::SetForegroundColor ( float  r,
float  g,
float  b,
float  a 
)

Definition at line 101 of file TAPsOpenGLCtrl.cpp.

00103 {
00104     m_ForegroundColor[0] = r;
00105     m_ForegroundColor[1] = g;
00106     m_ForegroundColor[2] = b;
00107     m_ForegroundColor[3] = a;
00108 }

void OpenGLCtrl::SetOpacity ( float  alpha  )  [virtual]

Set all alpha channels of this object, except the border alpha channel.

Reimplemented in OpenGLCtrlTransferFn.

Definition at line 182 of file TAPsOpenGLCtrl.cpp.

00183 {
00184     m_ForegroundColor[3] = 
00185     m_BackgroundColor[3] =
00186     m_ForegroundActColor[3] =
00187     m_BackgroundActColor[3] = alpha; 
00188 }

void OpenGLCtrl::SetSize ( int  width,
int  height 
) [virtual]

Definition at line 86 of file TAPsOpenGLCtrl.cpp.

00087 {
00088     m_DrawSizeXY[0] = width;
00089     m_DrawSizeXY[1] = height;
00090 }

void OpenGLCtrl::SetStartPos ( int  x = 0,
int  y = 0 
) [virtual]

Reimplemented in OpenGLCtrlTransferFn.

Definition at line 74 of file TAPsOpenGLCtrl.cpp.

00075 {
00076     m_xyLowerLeftPt[0] = x;
00077     m_xyLowerLeftPt[1] = y;
00078 }

void OpenGLCtrl::SetStatus ( bool  b  )  [inline]

Definition at line 29 of file TAPsOpenGLCtrl.hpp.

00029 { m_IsOn = b; }

void OpenGLCtrl::SetText ( std::string  text  )  [inline]

Definition at line 38 of file TAPsOpenGLCtrl.hpp.

00038 { m_Text = text; }

void OpenGLCtrl::ToggleStatus (  )  [inline]

Definition at line 30 of file TAPsOpenGLCtrl.hpp.

00030 { m_IsOn = !m_IsOn; }


Member Data Documentation

float OpenGLCtrl::g_BorderColor = { 0.5, 0.5, 0.5, 0.7 } [static, protected]

Definition at line 136 of file TAPsOpenGLCtrl.hpp.

BEGIN_NAMESPACE_TAPs__OpenGL int OpenGLCtrl::g_ID = 0 [static, protected]

Definition at line 135 of file TAPsOpenGLCtrl.hpp.

float OpenGLCtrl::m_BackgroundActColor[4] [protected]

Definition at line 147 of file TAPsOpenGLCtrl.hpp.

float OpenGLCtrl::m_BackgroundColor[4] [protected]

Definition at line 145 of file TAPsOpenGLCtrl.hpp.

int OpenGLCtrl::m_BorderSize [protected]

Definition at line 143 of file TAPsOpenGLCtrl.hpp.

int OpenGLCtrl::m_DrawSizeXY[2] [protected]

Definition at line 141 of file TAPsOpenGLCtrl.hpp.

float OpenGLCtrl::m_ForegroundActColor[4] [protected]

Definition at line 146 of file TAPsOpenGLCtrl.hpp.

float OpenGLCtrl::m_ForegroundColor[4] [protected]

Definition at line 144 of file TAPsOpenGLCtrl.hpp.

bool OpenGLCtrl::m_IsOn [protected]

Definition at line 138 of file TAPsOpenGLCtrl.hpp.

std::string OpenGLCtrl::m_Text [protected]

Definition at line 142 of file TAPsOpenGLCtrl.hpp.

int OpenGLCtrl::m_xyLowerLeftPt[2] [protected]

Definition at line 140 of file TAPsOpenGLCtrl.hpp.


The documentation for this class was generated from the following files:

Generated on Mon Oct 13 11:45:42 2008 for TAPs by  doxygen 1.5.6