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

FXGLShape.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                   O p e n G L   S h a p e   O b j e c t                       *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1998,2006 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (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 GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXGLShape.h,v 1.25 2006/01/22 17:58:03 fox Exp $                         *
00023 ********************************************************************************/
00024 #ifndef FXGLSHAPE_H
00025 #define FXGLSHAPE_H
00026 
00027 #ifndef FXGLOBJECT_H
00028 #include "FXGLObject.h"
00029 #endif
00030 
00031 namespace FX {
00032 
00033 
00034 class FXGLViewer;
00035 class FXGLObject;
00036 
00037 
00038 // Shape drawing options
00039 enum {
00040   SURFACE_SINGLESIDED   = 0,              // Single-sided [both sides same]
00041   SURFACE_DUALSIDED     = 0x00000001,     // Dual-sided surface
00042   SHADING_NONE          = 0,              // No light source
00043   SHADING_SMOOTH        = 0x00000002,     // Smooth shaded
00044   SHADING_FLAT          = 0x00000004,     // Flag shaded
00045   FACECULLING_OFF       = 0,              // No face culling
00046   FACECULLING_ON        = 0x00000008,     // Cull backward facing surfaces
00047   STYLE_SURFACE         = 0x00000010,     // Draw filled surfaces
00048   STYLE_WIREFRAME       = 0x00000020,     // Draw wire frame
00049   STYLE_POINTS          = 0x00000040,     // Draw as points
00050   STYLE_BOUNDBOX        = 0x00000080      // Draw bounding box
00051   };
00052 
00053 
00054 
00055 /// OpenGL Shape Object
00056 class FXAPI FXGLShape : public FXGLObject {
00057   FXDECLARE_ABSTRACT(FXGLShape)
00058 protected:
00059   FXVec3f       position;             // Middle of the Bounding Box
00060   FXMaterial    material[2];          // Front and back material properties
00061   FXRangef      range;                // Range box
00062   FXuint  options;              // Drawing options
00063   FXString  tip;
00064 protected:
00065   FXGLShape();
00066   virtual void drawshape(FXGLViewer*){}  // To be overloaded by derived class
00067   void drawbox();
00068   void drawhandles();
00069 public:
00070   long onDNDDrop(FXObject*,FXSelector,void*);
00071   long onDNDMotion(FXObject*,FXSelector,void*);
00072   long onQueryTip(FXObject*,FXSelector,void*);
00073   long onCmdShadeOff(FXObject*,FXSelector,void*);
00074   long onUpdShadeOff(FXObject*,FXSelector,void*);
00075   long onCmdShadeOn(FXObject*,FXSelector,void*);
00076   long onUpdShadeOn(FXObject*,FXSelector,void*);
00077   long onCmdShadeSmooth(FXObject*,FXSelector,void*);
00078   long onUpdShadeSmooth(FXObject*,FXSelector,void*);
00079   long onCmdFrontMaterial(FXObject*,FXSelector,void*);
00080   long onUpdFrontMaterial(FXObject*,FXSelector,void*);
00081   long onCmdBackMaterial(FXObject*,FXSelector,void*);
00082   long onUpdBackMaterial(FXObject*,FXSelector,void*);
00083   long onCmdDrawingStyle(FXObject*,FXSelector,void*);
00084   long onUpdDrawingStyle(FXObject*,FXSelector,void*);
00085 public:
00086   enum {
00087     ID_SHADEOFF=FXGLObject::ID_LAST,
00088     ID_SHADEON,
00089     ID_SHADESMOOTH,
00090     ID_TOGGLE_SIDED,
00091     ID_TOGGLE_CULLING,
00092     ID_STYLE_POINTS,
00093     ID_STYLE_WIREFRAME,
00094     ID_STYLE_SURFACE,
00095     ID_STYLE_BOUNDINGBOX,
00096     ID_FRONT_MATERIAL,
00097     ID_BACK_MATERIAL,
00098     ID_LAST
00099     };
00100 public:
00101 
00102   /// Construct with specified origin and options
00103   FXGLShape(FXfloat x,FXfloat y,FXfloat z,FXuint opts);
00104 
00105   /// Construct with specified origin, options and front and back materials
00106   FXGLShape(FXfloat x,FXfloat y,FXfloat z,FXuint opts,const FXMaterial& front,const FXMaterial& back);
00107 
00108   /// Copy constructor
00109   FXGLShape(const FXGLShape& orig);
00110 
00111   /// Called by the viewer to get bounds for this object
00112   virtual void bounds(FXRangef& box);
00113 
00114   /// Draw this object in a viewer
00115   virtual void draw(FXGLViewer* viewer);
00116 
00117   /// Draw this object for hit-testing purposes
00118   virtual void hit(FXGLViewer* viewer);
00119 
00120   /// Copy this object
00121   virtual FXGLObject* copy();
00122 
00123   /// Return true if this object can be dragged around
00124   virtual FXbool canDrag() const;
00125 
00126   /// Return true if this object can be deleted from the scene
00127   virtual FXbool canDelete() const;
00128 
00129   /// Drag this object from one position to another
00130   virtual FXbool drag(FXGLViewer* viewer,FXint fx,FXint fy,FXint tx,FXint ty);
00131 
00132   /// Set the tool tip message for this object
00133   void setTipText(const FXString& text){ tip=text; }
00134 
00135   /// Get the tool tip message for this object
00136   const FXString& getTipText() const { return tip; }
00137 
00138   /// Set the material for specified side (where side = 0 or 1)
00139   void setMaterial(FXint side,const FXMaterial &mtl);
00140 
00141   /// Get the material for specified side (where side = 0 or 1)
00142   void getMaterial(FXint side,FXMaterial &mtl) const;
00143 
00144   /// Save shape to a stream
00145   virtual void save(FXStream& store) const;
00146 
00147   /// Load shape from a stream
00148   virtual void load(FXStream& store);
00149   };
00150 
00151 }
00152 
00153 #endif
00154 

Copyright © 1997-2005 Jeroen van der Zijp