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

MyColorWheel.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) 1990-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  |      This file contains The MyColorWheel class, which lets you 
00049  |  interactively select colors using a color wheel. 
00050  |
00051  |   Author(s)  : Alain Dumesny
00052  |
00053  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00054  _______________________________________________________________________
00055  */
00056 
00057 #ifndef  _SO_XT_COLOR_WHEEL_
00058 #define  _SO_XT_COLOR_WHEEL_
00059 
00060 #include <Inventor/SbColor.h>
00061 #include <Inventor/SbLinear.h>
00062 #include <Inventor/misc/SoCallbackList.h>
00063 #include <Inventor/Xt/SoXtGLWidget.h>
00064 
00065 class SoXtMouse;
00066 
00067 // callback function prototypes
00068 typedef void MyColorWheelCB(void *userData, const float hsv[3]);
00069                                            
00071 //
00072 //  Class: MyColorWheel
00073 //
00074 //      Lets you interactively select colors using a color wheel. User register
00075 //  callback(s) to be notified when a new color has been selected. There is
00076 //  also a call to tell the color wheel what the current color is when it is
00077 //  changed externally.
00078 //
00080 
00081 // C-api: prefix=SoXtColWhl
00082 class MyColorWheel : public SoXtGLWidget {
00083 
00084   public:
00085     
00086     MyColorWheel(
00087         Widget parent = NULL,
00088         const char *name = NULL, 
00089         SbBool buildInsideParent = TRUE);
00090     ~MyColorWheel();
00091     
00092     //
00093     // Routine to tell the color wheel what the current HSV color is.
00094     //
00095     // NOTE: if calling setBaseColor() changes the marker position the
00096     // valueChanged callbacks will be called with the new hsv color.
00097     //
00098     // C-api: name=setBaseCol
00099     void        setBaseColor(const float hsv[3]);
00100     // C-api: name=getBaseCol
00101     const float *getBaseColor()         { return hsvColor; }
00102     
00103     //
00104     // This routine sets the WYSIWYG (What You See Is What You Get) mode.
00105     // When WYSIWYG is on the colors on the wheel will reflect the current
00106     // color intensity (i.e. get darker and brighter)
00107     //
00108     void        setWYSIWYG(SbBool trueOrFalse);    // default FALSE
00109     SbBool      isWYSIWYG()             { return WYSIWYGmode; }
00110     
00111     //
00112     // Those routines are used to register callbacks for the different 
00113     // color wheel actions.
00114     //
00115     // NOTE: the start and finish callbacks are only to signal when the mouse
00116     // goes down and up. No valid callback data is passed (NULL passed).
00117     //
00118     // C-api: name=addStartCB
00119     void    addStartCallback(
00120                     MyColorWheelCB *f,
00121                     void *userData = NULL)
00122             { startCallbacks->addCallback((SoCallbackListCB *) f, userData); }
00123 
00124     // C-api: name=addValueChangedCB
00125     void    addValueChangedCallback(
00126                     MyColorWheelCB *f, 
00127                     void *userData = NULL)
00128             { changedCallbacks->addCallback((SoCallbackListCB *) f, userData); }
00129         
00130     // C-api: name=addFinishCB
00131     void    addFinishCallback(
00132                     MyColorWheelCB *f,
00133                     void *userData = NULL)
00134             { finishCallbacks->addCallback((SoCallbackListCB *) f, userData); }
00135                                        
00136     // C-api: name=removeStartCB
00137     void    removeStartCallback(
00138                     MyColorWheelCB *f,
00139                     void *userData = NULL)
00140             { startCallbacks->removeCallback((SoCallbackListCB *) f, userData); }
00141 
00142     // C-api: name=removeValueChangedCB
00143     void    removeValueChangedCallback(
00144                     MyColorWheelCB *f,
00145                     void *userData = NULL)
00146             { changedCallbacks->removeCallback((SoCallbackListCB *) f, userData); }
00147 
00148     // C-api: name=removeFinishCB
00149     void    removeFinishCallback(
00150                     MyColorWheelCB *f,
00151                     void *userData = NULL)
00152             { finishCallbacks->removeCallback((SoCallbackListCB *) f, userData); }
00153         
00154         
00155     // true while the color is changing interactively
00156     SbBool  isInteractive()                     { return interactive; }
00157 
00158   protected:  
00159 
00160     // This constructor takes a boolean whether to build the widget now.
00161     // Subclasses can pass FALSE, then call MyColorWheel::buildWidget()
00162     // when they are ready for it to be built.
00163     SoEXTENDER
00164     MyColorWheel(
00165         Widget parent,
00166         const char *name, 
00167         SbBool buildInsideParent, 
00168         SbBool buildNow);
00169 
00170     Widget          buildWidget(Widget parent);
00171 
00172   private:
00173     
00174     // redefine these to do color wheel specific things
00175     virtual void    redraw();
00176     virtual void    redrawOverlay();
00177     virtual void    processEvent(XAnyEvent *anyevent);
00178     virtual void    initOverlayGraphic();
00179     virtual void    sizeChanged(const SbVec2s &newSize);
00180     
00181     // color wheels local variables
00182     SbBool      WYSIWYGmode;
00183     SbBool      blackMarker;
00184     float       hsvColor[3];
00185     short       cx, cy, radius;
00186     SbColor     *defaultColors, *colors;
00187     SbVec2f     *geometry;
00188     SoXtMouse   *mouse;
00189     
00190     // callback variables
00191     SoCallbackList *startCallbacks;
00192     SoCallbackList *changedCallbacks;
00193     SoCallbackList *finishCallbacks;
00194     SbBool      interactive;
00195     
00196     // routines to make the wheel geometry, colors, draw it....
00197     void    makeWheelGeometry();
00198     void    makeWheelColors(SbColor *col, float intensity);
00199     void    drawWheelSurrounding();
00200     void    drawWheelColors();
00201     void    checkMarkerColor();
00202     void    drawWheelMarker();
00203     void    moveWheelMarker(short x, short y);
00204 
00205     // this is called by both constructors
00206     void constructorCommon(SbBool buildNow);
00207 };
00208 
00209 
00210 #endif  /* _SO_XT_COLOR_WHEEL_ */

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