Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXGLObject.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                           O p e n G L   O b j e c t                           *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1998,2010 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 ********************************************************************************/
00021 #ifndef FXGLOBJECT_H
00022 #define FXGLOBJECT_H
00023 
00024 #ifndef FXOBJECT_H
00025 #include "FXObject.h"
00026 #endif
00027 
00028 namespace FX {
00029 
00030 
00031 class FXGLViewer;
00032 class FXGLObject;
00033 
00034 
00035 
00036 /// Basic OpenGL object
00037 class FXAPI FXGLObject : public FXObject {
00038   FXDECLARE(FXGLObject)
00039 public:
00040   enum {
00041     ID_LAST=10000       // Leaving ample room for FXGLViewer subclasses
00042     };
00043 public:
00044 
00045   /// Constructors
00046   FXGLObject(){}
00047 
00048   /// Copy constructor
00049   FXGLObject(const FXGLObject& orig):FXObject(orig){}
00050 
00051   /// Called by the viewer to get bounds for this object
00052   virtual void bounds(FXRangef& box);
00053 
00054   /// Draw this object in a viewer
00055   virtual void draw(FXGLViewer* viewer);
00056 
00057   /// Draw this object for hit-testing purposes
00058   virtual void hit(FXGLViewer* viewer);
00059 
00060   /// Copy this object
00061   virtual FXGLObject* copy();
00062 
00063   /// Identify sub-object given path
00064   virtual FXGLObject* identify(FXuint* path);
00065 
00066   /// Return true if this object can be dragged around
00067   virtual FXbool canDrag() const;
00068 
00069   /// Return true if this object can be deleted from the scene
00070   virtual FXbool canDelete() const;
00071 
00072   /// Drag this object from one position to another
00073   virtual FXbool drag(FXGLViewer* viewer,FXint fx,FXint fy,FXint tx,FXint ty);
00074 
00075   /// Destructor
00076   virtual ~FXGLObject(){}
00077   };
00078 
00079 
00080 /// Explicit template specialization
00081 //extern template class FXAPI FXObjectListOf<FXGLObject>;
00082 
00083 
00084 /// List of GL objects
00085 typedef FXObjectListOf<FXGLObject> FXGLObjectList;
00086 
00087 
00088 /// Group object
00089 class FXAPI FXGLGroup : public FXGLObject {
00090   FXDECLARE(FXGLGroup)
00091 protected:
00092   FXGLObjectList list;    // List of all objects
00093 public:
00094 
00095   /// Constructor
00096   FXGLGroup(){ }
00097 
00098   /// Copy constructor
00099   FXGLGroup(const FXGLGroup& orig):FXGLObject(orig),list(orig.list){ }
00100 
00101   /// Return list of childern
00102   FXGLObjectList& getList(){ return list; }
00103 
00104   /// Return bounding box
00105   virtual void bounds(FXRangef& box);
00106 
00107   /// Draw into viewer
00108   virtual void draw(FXGLViewer* viewer);
00109 
00110   /// Hit in viewer
00111   virtual void hit(FXGLViewer* viewer);
00112 
00113   /// Copy this object
00114   virtual FXGLObject* copy();
00115 
00116   /// Identify object by means of path
00117   virtual FXGLObject* identify(FXuint* path);
00118 
00119   /// Return true if group can be dragged
00120   virtual FXbool canDrag() const;
00121 
00122   /// Drag group object
00123   virtual FXbool drag(FXGLViewer* viewer,FXint fx,FXint fy,FXint tx,FXint ty);
00124 
00125   /// Return number of children
00126   FXint no() const { return list.no(); }
00127 
00128   /// Child at position
00129   FXGLObject* child(FXint pos) const { return list[pos]; }
00130 
00131   /// Insert child object at given position
00132   void insert(FXint pos,FXGLObject* obj){ list.insert(pos,obj); }
00133 
00134   /// Prepend child object
00135   void prepend(FXGLObject* obj){ list.prepend(obj); }
00136 
00137   /// Append child object
00138   void append(FXGLObject* obj){ list.append(obj); }
00139 
00140   /// Replace child object
00141   void replace(FXint pos,FXGLObject* obj){ list.replace(pos,obj); }
00142 
00143   /// Remove child object
00144   void remove(FXGLObject* obj){ list.remove(obj); }
00145 
00146   /// Remove child object at given position
00147   void erase(FXint pos){ list.erase(pos); }
00148 
00149   /// Remove all children
00150   void clear(){ list.clear(); }
00151 
00152   /// Stream save and load
00153   virtual void save(FXStream& store) const;
00154   virtual void load(FXStream& store);
00155 
00156   /// Destructor
00157   virtual ~FXGLGroup();
00158   };
00159 
00160 
00161 /// OpenGL Point Object
00162 class FXAPI FXGLPoint : public FXGLObject {
00163   FXDECLARE(FXGLPoint)
00164 public:
00165   FXVec3f pos;
00166 public:
00167 
00168   /// Default constructor
00169   FXGLPoint();
00170 
00171   /// Copy constructor
00172   FXGLPoint(const FXGLPoint& orig);
00173 
00174   /// Construct with specified coordinates
00175   FXGLPoint(FXfloat x,FXfloat y,FXfloat z);
00176 
00177   /// Copy this object
00178   virtual FXGLObject* copy();
00179 
00180   /// Called by the viewer to get bounds for this object
00181   virtual void bounds(FXRangef& box);
00182 
00183   /// Draw this object in a viewer
00184   virtual void draw(FXGLViewer* viewer);
00185 
00186   /// Draw this object for hit-testing purposes
00187   virtual void hit(FXGLViewer* viewer);
00188 
00189   /// Save to a stream
00190   virtual void save(FXStream& store) const;
00191 
00192   /// Load from a stream
00193   virtual void load(FXStream& store);
00194   };
00195 
00196 
00197 /// OpenGL Line Object
00198 class FXAPI FXGLLine : public FXGLObject {
00199   FXDECLARE(FXGLLine)
00200 public:
00201   FXGLPoint fm,to;
00202 public:
00203 
00204   /// Default constructor
00205   FXGLLine();
00206 
00207   /// Copy constructor
00208   FXGLLine(const FXGLLine& orig);
00209 
00210   /// Construct with specified endpoints
00211   FXGLLine(FXfloat fx,FXfloat fy,FXfloat fz,FXfloat tx,FXfloat ty,FXfloat tz);
00212 
00213   /// Called by the viewer to get bounds for this object
00214   virtual void bounds(FXRangef& box);
00215 
00216   /// Draw this object in a viewer
00217   virtual void draw(FXGLViewer* viewer);
00218 
00219   /// Copy this object
00220   virtual FXGLObject* copy();
00221 
00222   /// Draw this object for hit-testing purposes
00223   virtual void hit(FXGLViewer* viewer);
00224 
00225   /// Save to a stream
00226   virtual void save(FXStream& store) const;
00227 
00228   /// Load from a stream
00229   virtual void load(FXStream& store);
00230   };
00231 
00232 }
00233 
00234 #endif
00235 

Copyright © 1997-2010 Jeroen van der Zijp