arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

GLWidgets.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //     6-20-03
00005 //                   ________    ____   ___ 
00006 //                  |        \  /    | /  /
00007 //                  +---+     \/     |/  /
00008 //                  +--+|  |\    /|     < 
00009 //                  |  ||  | \  / |  |\  \ 
00010 //                  |      |  \/  |  | \  \ 
00011 //                   \_____|      |__|  \__\
00012 //                       Copyright  2003 
00013 //                      Joe Michael Kniss
00014 //                   <<< jmk@cs.utah.edu >>>
00015 //               "All Your Base are Belong to Us"
00016 //-------------------------------------------------------------------------
00017 
00018 /// GLWidgets.h
00019 
00020 
00021 #ifndef __GL_WIDGETS_DOT_H
00022 #define __GL_WIDGETS_DOT_H
00023 
00024 #include "GLItems.h"
00025 #include <widget/WidgetBase.h>
00026 #include "GLWidgetState.h"
00027 
00028 /////////////
00029 /// we are using multiple inheritance here to avoid replicating
00030 ///   data, by subclassing from GLUItem directly we can override the
00031 ///   drawGLDef() to draw based on Widgets current data, we can
00032 ///   also make it easy to track changes to the widget for display lists.
00033 
00034 //////////////////////////////////////////////////////////
00035 /// a glu sphere widget
00036 class GLUNodeWidget : public GLUItem, public NodeWidget {
00037 public:
00038    GLUNodeWidget(gutz::vec3f pos, float rad = -1, 
00039                  WidgetItem *parent=0,
00040                  int slice = 10, int stack = 10)
00041       : GLUItem(slice,stack), NodeWidget(pos,rad,parent)
00042    {
00043       _color = new GLColorWState(defNodeColor);
00044       setColor( _color );
00045    }
00046 
00047    /// calls the NodeWidget and GLUItem copy constructors
00048    GLUNodeWidget(const GLUNodeWidget &nw)
00049       : GLUItem(nw), NodeWidget(nw)
00050    {}
00051 
00052    /// calls the NodeWiget and GLUItem assignment operators
00053    GLUNodeWidget &operator=(const GLUNodeWidget &gnw)
00054    {
00055       GLUItem::operator=(gnw);
00056       NodeWidget::operator=(gnw);
00057       return *this;
00058    }
00059 
00060    /// implementation of NodeWidget::cloneNode()
00061    virtual NodeWidget *cloneNode() const
00062    { return new GLUNodeWidget(*this); }
00063 
00064    /// override of NodeWidget::drawDef()
00065    /// sets up GL style picking names and calls the GLItem::drawGL()
00066    void drawDef(const gutz::RenderEvent &r) 
00067    {
00068       initNames(RENDERABLE_NAME, (unsigned int)(Renderable*)this);
00069       glPushMatrix();
00070       {
00071          glMultMatrixf( _manip->getWorldTransform().m );
00072          if(_color) _color->bind();
00073          drawGL();
00074          if(_color) _color->release();
00075       }
00076       glPopMatrix();
00077       popNames();
00078    }
00079 
00080 protected:
00081    virtual void appearanceChanged() { setUp();}
00082    /// override of GLUItem::drawGLDef()
00083    void drawGLDef() 
00084    { 
00085       drawSphere(gutz::vec3f_zero,getRad()); 
00086    }
00087 };
00088 
00089 //////////////////////////////////////////////////////////
00090 /// a glu bar widget
00091 class GLUEdgeWidget : public GLUItem, public EdgeWidget {
00092 public:
00093    GLUEdgeWidget(NodeWidget *start, NodeWidget *end, float rad = -1,  
00094                  WidgetItem *parent=0,
00095                  int slice = 10, int stack = 10)
00096       : GLUItem(slice,stack), EdgeWidget(start,end,rad,parent) 
00097    {
00098       _color = new GLColorWState(defEdgeColor);
00099       setColor( _color );
00100    }
00101    GLUEdgeWidget(gutz::vec3f start, gutz::vec3f end, float rad = -1, 
00102                  WidgetItem *parent=0,
00103                  int slice = 10, int stack = 10)
00104       : GLUItem(slice,stack), EdgeWidget(start,end,rad,parent)
00105    {
00106       _color = new GLColorWState(defEdgeColor);
00107       setColor( _color );
00108    }
00109 
00110    /// calls the EdgeWidget and GLUItem copy constructors
00111    GLUEdgeWidget(const GLUEdgeWidget &gew)
00112       : GLUItem(gew), EdgeWidget(gew)
00113    {}
00114 
00115    /// calls EdgeWidget and GLUItem assignment operators
00116    GLUEdgeWidget &operator=(const GLUEdgeWidget &gew)
00117    {
00118       GLUItem::operator =(gew);
00119       EdgeWidget::operator =(gew);
00120       return *this;
00121    }
00122 
00123    /// definition of EdgeWidget::cloneEdge()
00124    virtual EdgeWidget *cloneEdge() const
00125    {
00126       return new GLUEdgeWidget(*this);
00127    }
00128 
00129    void drawDef(const gutz::RenderEvent &r) 
00130    {
00131       initNames(RENDERABLE_NAME, (unsigned int)(Renderable*)this);
00132       glPushMatrix();
00133       {
00134          glMultMatrixf( _manip->getWorldTransform().m );
00135          if(_color) _color->bind();
00136          drawGL(); 
00137          if(_color) _color->release();
00138       }
00139       glPopMatrix();
00140       popNames();
00141    }
00142 
00143 protected:
00144    virtual void appearanceChanged() { setUp();}
00145    void drawGLDef() 
00146    { 
00147       drawBar(_start, _end, getRad()); 
00148    }   
00149 };
00150 
00151 
00152 #endif
00153 

Send questions, comments, and bug reports to:
jmk