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

MySimpleMaterialEditor.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  |      Simplified Material Editor.
00049  |
00050  |   Classes    : MySimpleMaterialEditor
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_MATERIAL_EDITOR_
00059 #define _MY_MATERIAL_EDITOR_
00060 
00061 #include <X11/Intrinsic.h>
00062 #include <Xm/Xm.h>
00063 #include <Inventor/Xt/SoXtComponent.h>
00064 #include <Inventor/misc/SoCallbackList.h>
00065 #include <Inventor/SbColor.h>
00066 
00067 class SoMaterial;
00068 class SoXtRenderArea;
00069 class MyColorWheel;
00070 class MyColorSlider;
00071 class SoXtClipboard;
00072 class SoPathList;
00073 class MySimpleMaterialEditor;
00074 
00075 
00076 // callback function prototypes
00077 typedef void MySimpleMaterialEditorCB(void *userData, 
00078                             MySimpleMaterialEditor *editor);
00079 
00081 //
00082 //  Class: MySimpleMaterialEditor
00083 //
00084 //  This editor Gizmo lets you interactively edit a material
00085 //
00087 
00088 // C-api: prefix=SoXtMtlEd
00089 class MySimpleMaterialEditor : public SoXtComponent {
00090   public:
00091     MySimpleMaterialEditor(
00092         Widget parent = NULL,
00093         const char *name = NULL, 
00094         SbBool buildInsideParent = TRUE, 
00095         SbBool showMaterialName = FALSE);
00096    ~MySimpleMaterialEditor();
00097     
00098     // sets/gets the current material
00099     // C-api: name=setMtl
00100     void                setMaterial(const SoMaterial *mtl);
00101     // C-api: name=getMtl
00102     const SoMaterial *  getMaterial() const         { return material; }
00103     
00104     // specify whether the material name is being displayed
00105     // as an editable text field. The user can then use the set/get
00106     // material name methods to display and retreive the name.
00107     // (default set in constructor to FALSE).
00108     //
00109     // C-api: name=isMtlNameVisible
00110     SbBool              isMaterialNameVisible()   { return nameVisible; }
00111     
00112     // set/gets the material name which will be displayed (if set to
00113     // be visible) in the text field.
00114     // C-api: name=setMtlName
00115     void                setMaterialName(const char *name);
00116     // C-api: name=getMtlName
00117     const char *        getMaterialName() const     { return materialName; }
00118     
00119     // Callbacks - register functions that will be called whenever the user
00120     // chooses a new material (accept button)
00121     // C-api: name=addCB
00122     void    addCallback(
00123                 MySimpleMaterialEditorCB *f,
00124                 void *userData = NULL)
00125         { callbackList.addCallback((SoCallbackListCB *) f, userData);}
00126     
00127     // C-api: name=removeCB
00128     void    removeCallback(
00129                 MySimpleMaterialEditorCB *f,
00130                 void *userData = NULL)
00131         { callbackList.removeCallback((SoCallbackListCB *) f, userData); }
00132     
00133   protected:
00134 
00135     // This constructor takes a boolean whether to build the widget now.
00136     // Subclasses can pass FALSE, then call MySimpleMaterialEditor::buildWidget()
00137     // when they are ready for it to be built.
00138     SoEXTENDER
00139     MySimpleMaterialEditor(
00140         Widget parent,
00141         const char *name, 
00142         SbBool buildInsideParent, 
00143         SbBool showMaterialName, 
00144         SbBool buildNow);
00145     
00146     // redefine these
00147     virtual const char *    getDefaultWidgetName() const;
00148     virtual const char *    getDefaultTitle() const;
00149     virtual const char *    getDefaultIconTitle() const;
00150 
00151     // build routines
00152     Widget          buildWidget(Widget parent);
00153        
00154   private:
00155     SoCallbackList  callbackList;
00156     SbBool          ignoreCallback;
00157     SbBool          fieldChanged;
00158     SoMaterial      *material, *savedMaterial;
00159     char            *materialName, *savedMaterialName;
00160     SoXtRenderArea  *renderArea;
00161     MyColorWheel  *colWheel;
00162     MyColorSlider *colSlider;
00163     Widget          sldWidgets[3], nameField;
00164     float           metalness, savedMetalness, smoothness, savedSmoothness;
00165     SbColor         baseColor, savedBaseColor;
00166     SoXtClipboard   *clipboard;
00167     SbBool          nameVisible;
00168     
00169     void            copyMaterial(SoMaterial *mat1, const SoMaterial *mat2);
00170     void            updateMaterial();
00171     void            calculateMaterialFactors();
00172     void            updateMaterialUI();
00173     void            saveMaterialFactors();
00174     
00175     static void     colWheelCB(void *, const float hsv[3]);
00176     static void     colSliderCB(void *, float v);
00177     static void     nameFieldCB(Widget, MySimpleMaterialEditor *, void *);
00178     static void     fieldChangedCB(Widget, MySimpleMaterialEditor *, void *);
00179     static void     sldWidgetsCB(Widget, MySimpleMaterialEditor *, void *);
00180     static void     applyCB(Widget, MySimpleMaterialEditor *, void *);
00181     static void     resetCB(Widget, MySimpleMaterialEditor *, void *);
00182     static void     copyCB(Widget, MySimpleMaterialEditor *, XmAnyCallbackStruct *);
00183     static void     pasteCB(Widget, MySimpleMaterialEditor *, XmAnyCallbackStruct *);
00184     static void     pasteDone(void *, SoPathList *);
00185   
00186     // this is called by both constructors
00187     void constructorCommon(SbBool showMaterialName, SbBool buildNow);
00188 };
00189 
00190 
00191 #endif // _MY_MATERIAL_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