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,91 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 MyColorEditor class which lets you
00049 | interactively edit colors using color sliders and a color wheel.
00050 | You can either use it directly to edit a color field in the database
00051 | by using the attach()/detach() routines, or use it by registering a callback
00052 | routine which will get called whenever the color changed (passing an
00053 | SbColor to that routine).
00054 |
00055 | Author(s) : Alain Dumesny
00056 |
00057 |
00058 ______________ S I L I C O N G R A P H I C S I N C . ____________
00059 _______________________________________________________________________
00060 */
00061
00062 #ifndef _SO_XT_COLOR_EDITOR_
00063 #define _SO_XT_COLOR_EDITOR_
00064
00065 #include <Xm/Xm.h>
00066 #include <Inventor/SbColor.h>
00067 #include <Inventor/misc/SoCallbackList.h>
00068 #include <Inventor/Xt/SoXtComponent.h>
00069
00070 class SoBase;
00071 class SoNodeSensor;
00072 class SoMFColor;
00073 class SoPathList;
00074 class SoSFColor;
00075 class SoSensor;
00076 class SoXtClipboard;
00077 class MyColorPatch;
00078 class MyColorWheel;
00079 class MyColorSlider;
00080
00081 struct _ColorEditorCBData;
00082
00083 // callback function prototypes
00084 typedef void MyColorEditorCB(void *userData, const SbColor *color);
00085
00087 //
00088 // Class: MyColorEditor
00089 //
00090 // MyColorEditor class which lets you interactively edit a color.
00091 //
00093
00094 // C-api: prefix=SoXtColEd
00095 class MyColorEditor : public SoXtComponent {
00096
00097 public:
00098
00099 //
00100 // list of possible slider combinations, which is used to specify
00101 // which sliders should be displayed at any time.
00102 //
00103 enum Sliders {
00104 NONE,
00105 INTENSITY, // default
00106 RGB,
00107 HSV,
00108 RGB_V,
00109 RGB_HSV
00110 };
00111
00112 // UpdateFrequency is how often new values should be sent
00113 // to the node or the callback routine.
00114 enum UpdateFrequency {
00115 CONTINUOUS, // send updates with every mouse motion
00116 AFTER_ACCEPT // only send updates after user hits accept button
00117 };
00118
00119 // Constructor/Destructor
00120 MyColorEditor(
00121 Widget parent = NULL,
00122 const char *name = NULL,
00123 SbBool buildInsideParent = TRUE);
00124 ~MyColorEditor();
00125
00126 //
00127 // Routines for attaching/detaching the editor to a color field. It uses a
00128 // sensor on the color field to automatically update itself when the
00129 // color is changed externally.
00130 //
00131 // NOTE: the node containing the field needs to also be passed to attach
00132 // the sensor to it (since field sensors are not yet suported).
00133 //
00134 // NOTE: it can only be attached to either a single field or a multiple
00135 // field at any given time.
00136 //
00137 // C-api: name=attachSF
00138 void attach(SoSFColor *color, SoBase *node);
00139 // C-api: name=attachMF
00140 void attach(SoMFColor *color, int index, SoBase *node);
00141 void detach();
00142 SbBool isAttached() { return attached; }
00143
00144 //
00145 // Additional way of using the color editor, by registering a callback
00146 // and setting the color. At the time dictated by setUpdateFrequency
00147 // the callbacks will be called with the new color.
00148 //
00149 // NOTE: this is independent to the attach/detach routines, and
00150 // therefore can be used in conjunction.
00151 //
00152 // C-api: name=addColChangedCB
00153 inline void addColorChangedCallback(
00154 MyColorEditorCB *f,
00155 void *userData = NULL);
00156 // C-api: name=removeColChangedCB
00157 inline void removeColorChangedCallback(
00158 MyColorEditorCB *f,
00159 void *userData = NULL);
00160
00161 //
00162 // Sets/gets the color displayed by the color editor.
00163 //
00164 // NOTE: setColor() will call colorChanged callbacks if the color
00165 // differs.
00166 //
00167 // C-api: name=setCol
00168 void setColor(const SbColor &color);
00169 // C-api: name=getCol
00170 const SbColor & getColor() { return baseRGB; }
00171
00172 //
00173 // Sets/gets the WYSIWYG mode. (default OFF).
00174 //
00175 void setWYSIWYG(SbBool trueOrFalse);
00176 SbBool isWYSIWYG() { return WYSIWYGmode; }
00177
00178 //
00179 // Sets/gets which slider should be displayed. (default INTENSITY)
00180 //
00181 // C-api: name=setCurSldrs
00182 void setCurrentSliders(MyColorEditor::Sliders whichSliders);
00183 // C-api: name=getCurSldrs
00184 MyColorEditor::Sliders getCurrentSliders() { return whichSliders; }
00185
00186 //
00187 // Set/get the update frequency of when colorChanged callbacks should
00188 // be called. (default CONTINUOUS).
00189 //
00190 // C-api: name=setUpdateFreq
00191 void setUpdateFrequency(MyColorEditor::UpdateFrequency freq);
00192 // C-api: name=getUpdateFreq
00193 MyColorEditor::UpdateFrequency getUpdateFrequency()
00194 { return updateFreq; }
00195
00196 protected:
00197
00198 // This constructor takes a boolean whether to build the widget now.
00199 // Subclasses can pass FALSE, then call MyColorEditor::buildWidget()
00200 // when they are ready for it to be built.
00201 SoEXTENDER
00202 MyColorEditor(
00203 Widget parent,
00204 const char *name,
00205 SbBool buildInsideParent,
00206 SbBool buildNow);
00207
00208 // redefine these
00209 virtual const char * getDefaultWidgetName() const;
00210 virtual const char * getDefaultTitle() const;
00211 virtual const char * getDefaultIconTitle() const;
00212
00213 private:
00214
00215 // redefine these to do colorEditor specific things
00216 Widget buildWidget(Widget parent);
00217 static void visibilityChangeCB(void *pt, SbBool visible);
00218
00219 // local variables
00220 Widget mgrWidget; // form manages all child widgets
00221 SbBool WYSIWYGmode;
00222 Sliders whichSliders;
00223 SbColor baseRGB;
00224 float baseHSV[3];
00225 SbBool ignoreCallback;
00226 MyColorSlider *sliders[6];
00227 MyColorWheel *wheel;
00228 MyColorPatch *current, *previous;
00229 _ColorEditorCBData *dataId;
00230 SbPList menuItems; // Widgets
00231 MyColorEditor::UpdateFrequency updateFreq;
00232
00233 // attach/detach variables
00234 SbBool attached;
00235 SoBase *editNode;
00236 SoSFColor *colorSF;
00237 SoMFColor *colorMF;
00238 SoNodeSensor *colorSensor;
00239 SoCallbackList *callbackList;
00240 int index;
00241
00242 // copy/paste support
00243 SoXtClipboard *clipboard;
00244 void copy(Time eventTime);
00245 void paste(Time eventTime);
00246 void pasteDone(SoPathList *pathList);
00247 static void pasteDoneCB(void *userData, SoPathList *pathList);
00248
00249 // list of widgets which need to be accessed
00250 Widget acceptButton, slidersForm, buttonsForm, wheelForm;
00251
00252 // build/destroy routines
00253 Widget buildPulldownMenu(Widget parent);
00254 Widget buildControls(Widget parent);
00255 Widget buildSlidersForm(Widget parent);
00256
00257 void doSliderLayout();
00258 void doDynamicTopLevelLayout();
00259 int numberOfSliders(MyColorEditor::Sliders slider);
00260
00261
00262 // do the updates - if attached, update the node; if callback, call it.
00263 void doUpdates();
00264
00265 // color field sensor callback and routine
00266 void fieldChanged();
00267 static void fieldChangedCB(void *, SoSensor *);
00268
00269 // callbacks and actual routine from sliders, wheel, buttons, menu...
00270 static void wheelCallback(void *, const float hsv[3]);
00271 void wheelChanged(const float hsv[3]);
00272 static void sliderCallback(void *, float);
00273 void sliderChanged(short id, float value);
00274 static void buttonsCallback(Widget, _ColorEditorCBData *, XtPointer);
00275 void buttonPressed(short id);
00276 static void editMenuCallback(Widget, _ColorEditorCBData *, XmAnyCallbackStruct *);
00277 static void sliderMenuCallback(Widget, _ColorEditorCBData *, XtPointer);
00278
00279 static void menuDisplay(Widget, MyColorEditor *editor, XtPointer);
00280
00281 // this is called by both constructors
00282 void constructorCommon(SbBool buildNow);
00283 };
00284
00285 // Inline functions
00286 void
00287 MyColorEditor::addColorChangedCallback(
00288 MyColorEditorCB *f,
00289 void *userData)
00290 { callbackList->addCallback((SoCallbackListCB *) f, userData); }
00291
00292 void
00293 MyColorEditor::removeColorChangedCallback(
00294 MyColorEditorCB *f,
00295 void *userData)
00296 { callbackList->removeCallback((SoCallbackListCB *) f, userData); }
00297
00298
00299 #endif /* _SO_XT_COLOR_EDITOR_ */
1.2.11.1 written by Dimitri van Heesch,
© 1997-2001