Main Page   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

MyTextureEditor.h

00001 /*
00002  *
00003  *  Copyright (C) 2000 Silicon Graphics, Inc.  All Rights Reserved. 
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Lesser General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2.1 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Lesser General Public License for more details.
00014  *
00015  *  Further, this software is distributed without any warranty that it is
00016  *  free of the rightful claim of any third person regarding infringement
00017  *  or the like.  Any license provided herein, whether implied or
00018  *  otherwise, applies only to this software file.  Patent licenses, if
00019  *  any, provided herein do not apply to combinations of this program with
00020  *  other software, or any other product whatsoever.
00021  * 
00022  *  You should have received a copy of the GNU Lesser General Public
00023  *  License along with this library; if not, write to the Free Software
00024  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  *  Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
00027  *  Mountain View, CA  94043, or:
00028  * 
00029  *  http://www.sgi.com 
00030  * 
00031  *  For further information regarding this notice, see: 
00032  * 
00033  *  http://oss.sgi.com/projects/GenInfo/NoticeExplan/
00034  *
00035  */
00036 
00037 //  -*- C++ -*-
00038 
00039 /*
00040  * Copyright (C) 1991-93   Silicon Graphics, Inc.
00041  *
00042  _______________________________________________________________________
00043  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00044  |
00045  |   $Revision: 1.1 $
00046  |
00047  |   Description:
00048  |      Component which lets you specify and edit a texture for an object
00049  |
00050  |   Classes:   MyTextureEditor
00051  |
00052  |   Author(s): Alain Dumesny
00053  |
00054  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00055  _______________________________________________________________________
00056  */
00057 
00058 #ifndef _MY_TEXTURE_EDITOR_
00059 #define _MY_TEXTURE_EDITOR_
00060 
00061 #include <X11/Intrinsic.h>
00062 #include <Xm/Xm.h>
00063 #include <GL/glx.h>
00064 #include <Inventor/Xt/SoXtComponent.h>
00065 #include <Inventor/misc/SoCallbackList.h>
00066 #include <Inventor/SbPList.h>
00067 
00068 class SoPath;
00069 class SoSensor;
00070 class SoNodeSensor;
00071 class SoTexture2;
00072 class SoTexture2Transform;
00073 class SoTextureCoordinateFunction;
00074 class SoNode;
00075 class SoSeparator;
00076 class SoXtExaminerViewer;
00077 class MyColorWheel;
00078 class MyColorSlider;
00079 class MyThumbWheel;
00080 
00081 struct TextureNameStruct;
00082 class MyTextureEditor;
00083 
00084 // callback function prototypes
00085 typedef void MyTextureEditorCB(void *userData, MyTextureEditor *editor);
00086 
00087 
00089 //
00090 //  Class: MyTextureEditor
00091 //
00092 //  This editor components lets you interactively specify a texture map to
00093 //  use (from palettes of textures) as well as modify how the texture is
00094 //  applied to the object (translate, rotate, scale as well as different 
00095 //  mapping and other functions).
00096 //
00098 
00099 class MyTextureEditor : public SoXtComponent {
00100   public:
00101     
00102     // Pass the home directory of the texture palettes to use.
00103     // By default the system installed location is used, in addition
00104     // to looking at the SO_TEXTURE_DIR environment variable.
00105     //
00106     MyTextureEditor(
00107         Widget parent = NULL,
00108         const char *name = NULL, 
00109         SbBool buildInsideParent = TRUE, 
00110         const char *dir = NULL);
00111    ~MyTextureEditor();
00112     
00113     //
00114     // specify the geometry to display as textured map in the editor
00115     // viewing window.
00116     //
00117     void        setObjectGeometry(SoNode *geomRoot);
00118     
00119     //
00120     // set/get the SoTexture2 and the SoTextureCoordinateFunction nodes.
00121     // Those routines should be used in conjunction to the callbacks to
00122     // set and get the editor's texture nodes.
00123     //
00124     void        setTextureNode(const SoTexture2 *txtNode);
00125     const SoTexture2 *getTextureNode() const        { return texNode; }
00126     
00127     void        setTransformNode(const SoTexture2Transform *xf);
00128     const SoTexture2Transform *getTransformNode() const
00129                                                     { return texXfNode; }
00130     
00131     void        setFunctionNode(const SoTextureCoordinateFunction *func);
00132     const SoTextureCoordinateFunction *getFunctionNode() const
00133                                                     { return texFuncNode; }
00134     
00135     //
00136     // Callbacks - register functions that will be called whenever the user
00137     // accepts the current texture settings (press the accept button).
00138     //
00139     // Note: the Editor class pointer is passed as the callback data, so
00140     // the user should use the get methods to access the texture nodes
00141     //
00142     void    addCallback(
00143                 MyTextureEditorCB *f,
00144                 void *userData = NULL)
00145         { callbackList.addCallback((SoCallbackListCB *) f, userData);}
00146     
00147     void    removeCallback(
00148                 MyTextureEditorCB *f,
00149                 void *userData = NULL)
00150         { callbackList.removeCallback((SoCallbackListCB *) f, userData); }
00151     
00152   protected:
00153 
00154     // redefine these
00155     virtual const char *    getDefaultWidgetName() const;
00156     virtual const char *    getDefaultTitle() const;
00157     virtual const char *    getDefaultIconTitle() const;
00158     
00159   private:
00160     // scene graph and vars
00161     SoSeparator         *sceneRoot;
00162     SoTexture2          *texNode;
00163     SoTexture2Transform *texXfNode;
00164     SoTextureCoordinateFunction *texFuncNode;
00165     SoNode              *userGeometry;
00166     SbBool              repeatState;
00167     
00168     SoCallbackList      callbackList;
00169     
00170     void            updateTexture2UI();
00171     void            updateTextureXfUI();
00172     void            updateTextureFuncUI();
00173     void            updateTextureFieldAndSlider(int fieldID);
00174     SbBool          setRepeatState(SbBool flag);
00175     
00176     void            deselectCurrentItem(SbBool drawHighlight = TRUE);
00177     void            updateTextureName();
00178     void            updateTextureNode();
00179     void            getPaletteNames();
00180     void            loadPaletteItems();
00181     void            savePalette();
00182     void            deleteTextureEntry(int id);
00183     SbBool          addTextureEntry(int id, char *fullName);
00184     SbBool          readScaledImage(char *fileName, int xsize, int ysize, 
00185                         char *buf, int &zsize);
00186     char            *readImage(char *file, int &xsize, int &ysize, int &zsize);
00187     void            switchPalette(int id);
00188     void            updateWindowTitle();
00189     void            createNewPalette(char *palName);
00190     
00191     // component vars and callbacks
00192     SbBool          ignoreCallback;
00193     MyColorWheel    *colWheel;
00194     MyColorSlider   *colSlider;
00195     SoXtExaminerViewer *viewer;
00196     MyThumbWheel    *scaleXThumb, *scaleYThumb;
00197     float           oldXThumbVal, oldYThumbVal;
00198     static void     colWheelCB(void *, const float hsv[3]);
00199     static void     colSliderCB(void *, float);
00200     static void     scaleXThumbCB(void *, float);
00201     static void     scaleYThumbCB(void *, float);
00202     
00203     // Build routines
00204     Widget          buildWidget(Widget parent);
00205     Widget          buildMenu(Widget parent);
00206     void            buildPaletteSubMenu();
00207     Widget          buildPaletteMenuEntry(int id);
00208     Widget          buildSliders(Widget parent);
00209     Widget          buildButtons(Widget parent);
00210     Widget          buildTexturePaletteWidget(Widget parent);
00211  
00212     // motif vars and callbacks
00213     Widget          *widgetList;
00214     SbBool          fieldChanged;
00215     static void     fieldChangedCB(Widget, MyTextureEditor *, void *);
00216     static void     fieldsCB(Widget, int, void *);
00217     static void     slidersCB(Widget, int, void *);
00218     static void     mappingMenuCB(Widget, int, void *);
00219     static void     optionMenuCB(Widget, int, void *);
00220     static void     acceptCB(Widget, MyTextureEditor *, void *);
00221     
00222     // menu vars and callbacks
00223     void            createNewDialog();
00224     void            createDeleteDialog(char *title, char *str1, char *str2);
00225     void            updateFileMenu();
00226     static void     fileMenuCB(Widget, int id, void *);
00227     static void     paletteMenuCB(Widget w, int num, void *);
00228     static void     newDialogCB(Widget, MyTextureEditor *, XmAnyCallbackStruct *);
00229     static void     deleteDialogCB(Widget, MyTextureEditor *, XmAnyCallbackStruct *);
00230     
00231     // texture palette vars and callbacks
00232     GLXContext      paletteCtx;
00233     SbBool          loadedPalette;
00234     char            *paletteDir;
00235     Time            prevTime;
00236     int             selectedItem, currentItem;
00237     int             curPalette;
00238     TextureNameStruct *textureNames;
00239     SbPList         paletteList;
00240     void            redrawPalette();
00241     void            drawTextureTile(int id, int style);
00242     void            handleEvent(XAnyEvent *xe);
00243     static void     glxExposeCB(Widget, MyTextureEditor *, void *);
00244     static void     glxInitCB(Widget, MyTextureEditor *, void *);
00245     static void     glxEventCB(Widget, MyTextureEditor *, XAnyEvent *, Boolean *);
00246     
00247     // image dialog vars and callbacks
00248     GLXContext      imageDialogCtx;
00249     char            *dialogImage;
00250     char            *dialogImageName, *dialogImageInfo;
00251     int             dialogImageSize[3];
00252     short           buttonsTotalWidth;
00253     void            openImageDialog();
00254     void            redrawImageDialog();
00255     void            setNewDialogImage(char *fileName = NULL);
00256     static void     imageDialogDestroyCB(Widget, MyTextureEditor *, void *);
00257     static void     imageDialogExposeCB(Widget, MyTextureEditor *, void *);
00258     static void     imageDialogInitCB(Widget, MyTextureEditor *, void *);
00259     static void     imageDialogOpenCB(Widget, MyTextureEditor *, void *);
00260     static void     imageDialogClearCB(Widget, MyTextureEditor *, void *);
00261     static void     imageDialogApplyCB(Widget, MyTextureEditor *, void *);
00262     static void     imageDialogCloseCB(Widget, MyTextureEditor *, void *);
00263     static void     fileDialogOkCB(Widget, MyTextureEditor *, XmFileSelectionBoxCallbackStruct *);
00264 };
00265 
00266 #endif // _MY_TEXTURE_EDITOR_

Generated on Fri Oct 26 23:38:09 2001 for bicobj-intersection by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001