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,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: FXGLObject.h,v 1.28.2.3 2006/11/17 16:02:31 fox Exp $                        *
00023 ********************************************************************************/
00024 #ifndef FX_DISABLEGL
00025 
00026 #if FX_GRAPHINGMODULE
00027 
00028 #ifndef FXGLOBJECT_H
00029 #define FXGLOBJECT_H
00030 
00031 #ifndef FXOBJECT_H
00032 #include "FXObject.h"
00033 #endif
00034 
00035 namespace FX {
00036 
00037 
00038 class FXGLViewer;
00039 class FXGLObject;
00040 
00041 
00043 class FXGRAPHINGMODULEAPI FXGLColor
00044 {
00045 public:
00046   FXfloat r,g,b,a;
00047 public:
00048   // Constructors
00049   FXGLColor() : r(1), g(1), b(1), a(1) { }
00050   FXGLColor(FXfloat _r, FXfloat _g, FXfloat _b, FXfloat _a=1) : r(_r), g(_g), b(_b), a(_a) { }
00051   explicit FXGLColor(const FXfloat *colors) : r(colors ? colors[0] : 1), g(colors ? colors[1] : 1), b(colors ? colors[2] : 1), a(colors ? colors[3] : 1) { }
00052   FXGLColor(const FXColor &o) : r(FXREDVAL(o)/255.0f), g(FXGREENVAL(o)/255.0f), b(FXBLUEVAL(o)/255.0f), a(FXALPHAVAL(o)/255.0f) { }
00053   operator FXColor() const { return FXRGBA(((FXuchar)(r*255.0f) & 0xff), ((FXuchar)(g*255.0f) & 0xff), ((FXuchar)(b*255.0f) & 0xff), ((FXuchar)(a*255.0f) & 0xff)); }
00054 
00056   bool isWhite() const { return 1==r && 1==g && 1==b; }
00057 
00059   bool isBlack() const { return 0==r && 0==g && 0==b; }
00060 
00061   friend FXGRAPHINGMODULEAPI FXStream &operator<<(FXStream &s, const FXGLColor &o);
00062   friend FXGRAPHINGMODULEAPI FXStream &operator>>(FXStream &s, FXGLColor &o);
00063 };
00064 
00065 
00067 class FXGRAPHINGMODULEAPI FXGLObject : public FXObject {
00068   FXDECLARE(FXGLObject)
00069 public:
00070   enum {
00071     ID_LAST=10000       // Leaving ample room for FXGLViewer subclasses
00072     };
00073 public:
00074 
00076   FXGLObject(){}
00077 
00079   FXGLObject(const FXGLObject& orig):FXObject(orig){}
00080 
00082   virtual void bounds(FXRangef& box);
00083 
00085   virtual void draw(FXGLViewer* viewer);
00086 
00088   virtual void hit(FXGLViewer* viewer);
00089 
00091   virtual FXGLObject* copy();
00092 
00094   virtual FXGLObject* identify(FXuint* path);
00095 
00097   virtual FXbool canDrag() const;
00098 
00100   virtual FXbool canDelete() const;
00101 
00103   virtual FXbool drag(FXGLViewer* viewer,FXint fx,FXint fy,FXint tx,FXint ty);
00104 
00106   virtual ~FXGLObject(){}
00107   };
00108 
00109 
00111 typedef FXObjectListOf<FXGLObject> FXGLObjectList;
00112 
00113 
00114 #ifdef _MSC_VER
00115 #pragma warning(push)
00116 #pragma warning(disable: 4251)
00117 #endif
00118 
00120 class FXGRAPHINGMODULEAPI FXGLGroup : public FXGLObject {
00121   FXDECLARE(FXGLGroup)
00122 protected:
00123   FXGLObjectList list;    // List of all objects
00124 public:
00125 
00127   FXGLGroup(){ }
00128 
00130   FXGLGroup(const FXGLGroup& orig):FXGLObject(orig),list(orig.list){ }
00131 
00133   FXGLObjectList& getList(){ return list; }
00134 
00136   virtual void bounds(FXRangef& box);
00137 
00139   virtual void draw(FXGLViewer* viewer);
00140 
00142   virtual void hit(FXGLViewer* viewer);
00143 
00145   virtual FXGLObject* copy();
00146 
00148   virtual FXGLObject* identify(FXuint* path);
00149 
00151   virtual FXbool canDrag() const;
00152 
00154   virtual FXbool drag(FXGLViewer* viewer,FXint fx,FXint fy,FXint tx,FXint ty);
00155 
00157   FXint no() const { return list.no(); }
00158 
00160   FXGLObject* child(FXint pos) const { return list[pos]; }
00161 
00163   void insert(FXint pos,FXGLObject* obj){ list.insert(pos,obj); }
00164 
00166   void prepend(FXGLObject* obj){ list.prepend(obj); }
00167 
00169   void append(FXGLObject* obj){ list.append(obj); }
00170 
00172   void replace(FXint pos,FXGLObject* obj){ list.replace(pos,obj); }
00173 
00175   void remove(FXGLObject* obj){ list.remove(obj); }
00176 
00178   void erase(FXint pos){ list.erase(pos); }
00179 
00181   void clear(){ list.clear(); }
00182 
00184   virtual void save(FXStream& store) const;
00185   virtual void load(FXStream& store);
00186 
00188   virtual ~FXGLGroup();
00189   };
00190 
00191 #ifdef _MSC_VER
00192 #pragma warning(pop)
00193 #endif
00194 
00195 }
00196 
00197 #endif
00198 #endif
00199 #endif

(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:31:22 2009 for TnFOX by doxygen v1.4.7