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,2009 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 * $Id: FXGLObject.h,v 1.39 2009/01/06 13:07:24 fox Exp $                        *
00022 ********************************************************************************/
00023 #ifndef FXGLOBJECT_H
00024 #define FXGLOBJECT_H
00025 
00026 #ifndef FXOBJECT_H
00027 #include "FXObject.h"
00028 #endif
00029 
00030 namespace FX {
00031 
00032 
00033 class FXGLViewer;
00034 class FXGLObject;
00035 
00036 
00037 
00038 /// Basic OpenGL object
00039 class FXAPI FXGLObject : public FXObject {
00040   FXDECLARE(FXGLObject)
00041 public:
00042   enum {
00043     ID_LAST=10000       // Leaving ample room for FXGLViewer subclasses
00044     };
00045 public:
00046 
00047   /// Constructors
00048   FXGLObject(){}
00049 
00050   /// Copy constructor
00051   FXGLObject(const FXGLObject& orig):FXObject(orig){}
00052 
00053   /// Called by the viewer to get bounds for this object
00054   virtual void bounds(FXRangef& box);
00055 
00056   /// Draw this object in a viewer
00057   virtual void draw(FXGLViewer* viewer);
00058 
00059   /// Draw this object for hit-testing purposes
00060   virtual void hit(FXGLViewer* viewer);
00061 
00062   /// Copy this object
00063   virtual FXGLObject* copy();
00064 
00065   /// Identify sub-object given path
00066   virtual FXGLObject* identify(FXuint* path);
00067 
00068   /// Return true if this object can be dragged around
00069   virtual FXbool canDrag() const;
00070 
00071   /// Return true if this object can be deleted from the scene
00072   virtual FXbool canDelete() const;
00073 
00074   /// Drag this object from one position to another
00075   virtual FXbool drag(FXGLViewer* viewer,FXint fx,FXint fy,FXint tx,FXint ty);
00076 
00077   /// Destructor
00078   virtual ~FXGLObject(){}
00079   };
00080 
00081 
00082 /// Explicit template specialization
00083 //extern template class FXAPI FXObjectListOf<FXGLObject>;
00084 
00085 
00086 /// List of GL objects
00087 typedef FXObjectListOf<FXGLObject> FXGLObjectList;
00088 
00089 
00090 /// Group object
00091 class FXAPI FXGLGroup : public FXGLObject {
00092   FXDECLARE(FXGLGroup)
00093 protected:
00094   FXGLObjectList list;    // List of all objects
00095 public:
00096 
00097   /// Constructor
00098   FXGLGroup(){ }
00099 
00100   /// Copy constructor
00101   FXGLGroup(const FXGLGroup& orig):FXGLObject(orig),list(orig.list){ }
00102 
00103   /// Return list of childern
00104   FXGLObjectList& getList(){ return list; }
00105 
00106   /// Return bounding box
00107   virtual void bounds(FXRangef& box);
00108 
00109   /// Draw into viewer
00110   virtual void draw(FXGLViewer* viewer);
00111 
00112   /// Hit in viewer
00113   virtual void hit(FXGLViewer* viewer);
00114 
00115   /// Copy this object
00116   virtual FXGLObject* copy();
00117 
00118   /// Identify object by means of path
00119   virtual FXGLObject* identify(FXuint* path);
00120 
00121   /// Return true if group can be dragged
00122   virtual FXbool canDrag() const;
00123 
00124   /// Drag group object
00125   virtual FXbool drag(FXGLViewer* viewer,FXint fx,FXint fy,FXint tx,FXint ty);
00126 
00127   /// Return number of children
00128   FXint no() const { return list.no(); }
00129 
00130   /// Child at position
00131   FXGLObject* child(FXint pos) const { return list[pos]; }
00132 
00133   /// Insert child object at given position
00134   void insert(FXint pos,FXGLObject* obj){ list.insert(pos,obj); }
00135 
00136   /// Prepend child object
00137   void prepend(FXGLObject* obj){ list.prepend(obj); }
00138 
00139   /// Append child object
00140   void append(FXGLObject* obj){ list.append(obj); }
00141 
00142   /// Replace child object
00143   void replace(FXint pos,FXGLObject* obj){ list.replace(pos,obj); }
00144 
00145   /// Remove child object
00146   void remove(FXGLObject* obj){ list.remove(obj); }
00147 
00148   /// Remove child object at given position
00149   void erase(FXint pos){ list.erase(pos); }
00150 
00151   /// Remove all children
00152   void clear(){ list.clear(); }
00153 
00154   /// Stream save and load
00155   virtual void save(FXStream& store) const;
00156   virtual void load(FXStream& store);
00157 
00158   /// Destructor
00159   virtual ~FXGLGroup();
00160   };
00161 
00162 
00163 /// OpenGL Point Object
00164 class FXAPI FXGLPoint : public FXGLObject {
00165   FXDECLARE(FXGLPoint)
00166 public:
00167   FXVec3f pos;
00168 public:
00169 
00170   /// Default constructor
00171   FXGLPoint();
00172 
00173   /// Copy constructor
00174   FXGLPoint(const FXGLPoint& orig);
00175 
00176   /// Construct with specified coordinates
00177   FXGLPoint(FXfloat x,FXfloat y,FXfloat z);
00178 
00179   /// Copy this object
00180   virtual FXGLObject* copy();
00181 
00182   /// Called by the viewer to get bounds for this object
00183   virtual void bounds(FXRangef& box);
00184 
00185   /// Draw this object in a viewer
00186   virtual void draw(FXGLViewer* viewer);
00187 
00188   /// Draw this object for hit-testing purposes
00189   virtual void hit(FXGLViewer* viewer);
00190 
00191   /// Save to a stream
00192   virtual void save(FXStream& store) const;
00193 
00194   /// Load from a stream
00195   virtual void load(FXStream& store);
00196   };
00197 
00198 
00199 /// OpenGL Line Object
00200 class FXAPI FXGLLine : public FXGLObject {
00201   FXDECLARE(FXGLLine)
00202 public:
00203   FXGLPoint fm,to;
00204 public:
00205 
00206   /// Default constructor
00207   FXGLLine();
00208 
00209   /// Copy constructor
00210   FXGLLine(const FXGLLine& orig);
00211 
00212   /// Construct with specified endpoints
00213   FXGLLine(FXfloat fx,FXfloat fy,FXfloat fz,FXfloat tx,FXfloat ty,FXfloat tz);
00214 
00215   /// Called by the viewer to get bounds for this object
00216   virtual void bounds(FXRangef& box);
00217 
00218   /// Draw this object in a viewer
00219   virtual void draw(FXGLViewer* viewer);
00220 
00221   /// Copy this object
00222   virtual FXGLObject* copy();
00223 
00224   /// Draw this object for hit-testing purposes
00225   virtual void hit(FXGLViewer* viewer);
00226 
00227   /// Save to a stream
00228   virtual void save(FXStream& store) const;
00229 
00230   /// Load from a stream
00231   virtual void load(FXStream& store);
00232   };
00233 
00234 }
00235 
00236 #endif
00237 

Copyright © 1997-2009 Jeroen van der Zijp