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

unatima.hpp

00001 /* ==================================================== ======== ======= *
00002  *
00003  *  unatima.hpp  [Native Layer: platform dependent implementation]
00004  *  Ubit Project  [Elc][2003]
00005  *  Author: Eric Lecolinet
00006  *
00007  *  Part of the Ubit Toolkit: A Brick Construction Game Model for Creating GUIs
00008  *
00009  *  (C) 1999-2003 Eric Lecolinet @ ENST Paris
00010  *  WWW: http://www.enst.fr/~elc/ubit   Email: elc@enst.fr (subject: ubit)
00011  *
00012  * ***********************************************************************
00013  * COPYRIGHT NOTICE : 
00014  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE 
00015  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 
00016  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU 
00017  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION; 
00018  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
00019  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
00020  * ***********************************************************************
00021  *
00022  * ==================================================== [Elc:03] ======= *
00023  * ==================================================== ======== ======= */
00024 
00025 #ifndef _unatima_hpp_
00026 #define _unatima_hpp_
00027 //pragma ident  "@(#)unatima.hh ubit:03.06.04"
00028 #include <ubit/ubit_config.h>
00029 #include <ubit/unatgraph.hpp>
00030 
00031 
00039 class UNatIma {
00040 public:
00041   static const char* const GIF;
00042   static const char* const JPG;
00043   static const char* const XPM;
00044   static const char* const XPM_DATA;
00045 
00046   UNatIma(UNatDisp*, UX_Image xima, UX_Image ximashape);
00053   ~UNatIma();
00054 
00055   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00056 
00057   u_dim getWidth()   const;
00058   u_dim getHeight()  const;
00059 
00060   const UX_Image getXImage()      const {return xima;}
00061   const UX_Image getXImageShape() const {return ximashape;}
00062 
00063   bool  isRealized() const;
00064   bool  isShaped()   const {return ximashape != null;}
00065 
00066   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00067 
00068   static int readImage(UNatDisp*, const char* filename, const char* filetype, 
00069                        UNatIma*& natima);
00076   UNatIma* createScaledImage(float xscale, float yscale);
00077   UNatIma* createScaledImage(UNatDisp* to_nd, float xscale, float yscale);
00084   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00085 
00086   static UX_Image createEmptyImage(UNatDisp*, u_dim width, u_dim height, 
00087                                    u_dim depth);
00097   static UX_Image createScaledImage(UNatDisp* to_nd, UNatDisp* from_nd,
00098                                     UX_Image from_ima, 
00099                                     float xscale, float yscale);
00108   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00109 
00110   static bool blendImages(UNatDisp*, UX_Image xima1, UX_Image xima2, 
00111                           float alpha);
00112   static bool blendImage(UNatDisp*, UX_Image xima1, UX_Color pixel2,
00113                          float alpha);
00119   static unsigned long* allocXColors(UNatDisp *nd,
00120                                      const XColor* colors, int colorCount); 
00122 
00123   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00124 
00126   typedef int (*Reader) (class UNatDisp*, const char *fpath, UNatIma*& natima);
00127 
00129   typedef int (*Writer) (class UNatDisp*, const char *fpath, const UNatIma* natima);
00130 
00131   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00132 
00133   static int xpmFileReader(UNatDisp*, const char *fpath, UNatIma*& natima);
00134   static int xpmDataReader(UNatDisp*, const char *xpm_data, UNatIma*& natima);
00135   static int gifFileReader(UNatDisp*, const char *fpath, UNatIma*& natima);
00136   static int jpegFileReader(UNatDisp*, const char *fpath,UNatIma*& natima); 
00138 
00139 #ifndef NO_DOC
00140   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00141   // implementation
00142 
00143 protected:
00144   friend class UGraph;
00145   friend class UIma;
00146   friend class UPix;
00147   friend class UNatPix;
00148 
00149   UNatDisp *natdisp;
00150   UX_Image xima, ximashape;
00151   int      lscale;   //LOGICAL scale
00152 
00153 #ifdef WITH_GL
00154   GLuint glIma;  // texture Identifiant
00155   unsigned char *imaData;
00156   bool createGLTexture(UNatDisp*);
00157 #endif
00158 #endif
00159 };
00160 
00161 /* ==================================================== [Elc:03] ======= */
00162 /* ==================================================== ======== ======= */
00163 
00164 class UNatPix {
00165   friend class UGraph;
00166   friend class UPix;
00167   UNatDisp *natdisp;
00168   UX_Pixmap xpix, xpixshape;
00169   u_dim width, height;
00170   int depth, lscale;   //lscale = LOGICAL scale (used by UPix)
00171 #ifdef WITH_GL
00172   GLuint glIma;  // texture Identifiant
00173 #endif
00174 
00175 public:
00176   // xpixshape == None ==> opaque image
00177   // xpixshape != None ==> transparent background
00178   UNatPix(UNatDisp*, UX_Pixmap xpix, UX_Pixmap xpixshape, 
00179           u_dim width, u_dim height, int depth);
00180 
00181   // creates the pixmaps from the images
00182   // ximashape == null ==> opaque image
00183   // ximashape != null ==> transparent background
00184   UNatPix(UNatDisp*, UX_Image xima, UX_Image ximashape);
00185   UNatPix(UNatDisp*, UNatIma*);
00186   ~UNatPix();
00187 
00188   void set(UX_Image xima, UX_Image ximashape);
00189 
00190   u_dim getWidth()  const {return width;}
00191   u_dim getHeight() const {return height;}
00192   bool isRealized() const {return xpix != None;}
00193   bool isShaped()   const {return xpixshape != None;}
00194   const UX_Pixmap getXPixmap()      const {return xpix;}
00195   const UX_Pixmap getXPixmapShape() const {return xpixshape;}
00196 };
00197 
00198 #endif
00199 /* ==================================================== [TheEnd] ======= */
00200 /* ==================================================== [Elc:03] ======= */

Generated on Thu Mar 3 06:36:49 2005 for Ubit[Eric.Lecolinet@enst.fr] by  doxygen 1.4.1