Open Inventor Release 2025.1.0
 
Loading...
Searching...
No Matches
SoXtColorEditor.h
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2024 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : VSG (MMM YYYY)
22**=======================================================================*/
23
24#ifdef SOQT
25# include <Inventor/Qt/SoQtColorEditor.h>
26#elif defined(_WIN32)
27# include <Inventor/Win/SoWinColorEditor.h>
28#else // _WIN32
29
30#ifndef _SO_XT_COLOR_EDITOR_
31#define _SO_XT_COLOR_EDITOR_
32
33#include <Xm/Xm.h>
34#include <Inventor/SbColor.h>
35#include <Inventor/misc/SoCallbackList.h>
36#include <Inventor/Xt/SoXtComponent.h>
37
38class SoBase;
39class SoNodeSensor;
40class SoMFColor;
41class SoPathList;
42class SoSFColor;
43class SoSensor;
44class SoXtClipboard;
45class SoXtColorPatch;
46class SoXtColorWheel;
47class SoXtColorSlider;
48
49class SoMFUInt32;
50
51struct _ColorEditorCBData;
52
53// callback function prototypes
55typedef void SoXtColorEditorCB(void *userData, const SbColor *color);
56
58//
59// Class: SoXtColorEditor
60//
61// SoXtColorEditor class which lets you interactively edit a color.
62//
64
86class SoXtColorEditor : public SoXtComponent {
87
88 public:
89
120
135
139 SoXtColorEditor(SoWidget parent = NULL,
140 const char *name = NULL,
141 SbBool buildInsideParent = TRUE);
146
161 void attach(SoSFColor *color, SoBase *node);
166 void attach(SoMFColor *color, int index, SoBase *node);
171 void attach(SoMFUInt32 *color, int index, SoBase *node);
172
178 void detach();
182 SbBool isAttached() { return attached; }
183
189 inline void addColorChangedCallback(SoXtColorEditorCB *f, void *userData = NULL);
193 inline void removeColorChangedCallback(SoXtColorEditorCB *f, void *userData = NULL);
194
199 void setColor(const SbColor &color);
203 const SbColor & getColor() { return baseRGB; }
204
219 void setWYSIWYG(SbBool trueOrFalse);
223 SbBool isWYSIWYG() { return WYSIWYGmode; }
224
228 void setCurrentSliders(SoXtColorEditor::Sliders whichSliders);
233
237 void setUpdateFrequency(SoXtColorEditor::UpdateFrequency freq);
242
243 private:
244
245 // This constructor takes a boolean whether to build the widget now.
246 // Subclasses can pass FALSE, then call SoXtColorEditor::buildWidget()
247 // when they are ready for it to be built.
248 SoEXTENDER
249 SoXtColorEditor(SoWidget parent,
250 const char *name,
251 SbBool buildInsideParent,
252 SbBool buildNow);
253
254 // redefine these
255 virtual SbString getDefaultWidgetName() const;
256 virtual SbString getDefaultTitle() const;
257 virtual SbString getDefaultIconTitle() const;
258
259 private:
260
261 // redefine these to do colorEditor specific things
262 SoWidget buildWidget(SoWidget parent);
263 static void visibilityChangeCB(void *pt, SbBool visible);
264
265 // local variables
266 SoWidget mgrWidget; // form manages all child widgets
267 SbBool WYSIWYGmode;
268 Sliders whichSliders;
269 SbColor baseRGB;
270 float baseHSV[3];
271 SbBool ignoreCallback;
272 SoXtColorSlider *sliders[6];
273 SoXtColorWheel *wheel;
274 SoXtColorPatch *current, *previous;
275 _ColorEditorCBData *dataId;
276 SbPList menuItems; // Widgets
277 SoXtColorEditor::UpdateFrequency updateFreq;
278
279 // attach/detach variables
280 SbBool attached;
281 SoBase *editNode;
282 SoSFColor *colorSF;
283 SoMFColor *colorMF;
284 SoNodeSensor *colorSensor;
285 SoCallbackList *callbackList;
286 int index;
287
288 // Extension (mmh)
289 // additional attach variables for handling "orderedRGBA" fields
290 SoMFUInt32 *colorUInt32MF;
291 float transparency;
292
293 // copy/paste support
294 SoXtClipboard *clipboard;
295 void copy(Time eventTime);
296 void paste(Time eventTime);
297 void pasteDone(SoPathList *pathList);
298 static void pasteDoneCB(void *userData, SoPathList *pathList);
299
300 // list of widgets which need to be accessed
301 SoWidget acceptButton, slidersForm, buttonsForm, wheelForm;
302
303 // build/destroy routines
304 SoWidget buildPulldownMenu(SoWidget parent);
305 SoWidget buildControls(SoWidget parent);
306 SoWidget buildSlidersForm(SoWidget parent);
307
308 void doSliderLayout();
309 void doDynamicTopLevelLayout();
310 int numberOfSliders(SoXtColorEditor::Sliders slider);
311
312 // do the updates - if attached, update the node; if callback, call it.
313 void doUpdates();
314
315 // color field sensor callback and routine
316 void fieldChanged();
317 static void fieldChangedCB(void *, SoSensor *);
318
319 // callbacks and actual routine from sliders, wheel, buttons, menu...
320 static void wheelCallback(void *, const float hsv[3]);
321 void wheelChanged(const float hsv[3]);
322 static void sliderCallback(void *, float);
323 void sliderChanged(short id, float value);
324 static void buttonsCallback(SoWidget, _ColorEditorCBData *, XtPointer);
325 void buttonPressed(short id);
326 static void editMenuCallback(SoWidget, _ColorEditorCBData *, XmAnyCallbackStruct *);
327 static void sliderMenuCallback(SoWidget, _ColorEditorCBData *, XtPointer);
328
329 static void menuDisplay(SoWidget, SoXtColorEditor *editor, XtPointer);
330
331 // this is called by both constructors
332 void constructorCommon(SbBool buildNow);
333 // Function used to create strings in motif buttons/menus.
334 void initStrings( void );
335
336};
337
338// Inline functions
339void
341{
342 callbackList->addCallback((SoCallbackListCB *)f, userData);
343}
344
345void
347{
348 callbackList->removeCallback((SoCallbackListCB *)f, userData);
349}
350
351#endif /* _SO_XT_COLOR_EDITOR_ */
352
353#endif // _WIN32
354
355
Color vector class.
Definition SbColor.h:82
List of generic (void *) pointers.
Definition SbPList.h:77
Class for smart character strings.
Definition SbString.h:202
Base class for all nodes, paths, and engines.
Definition SoBase.h:111
Manages a list of callbacks and associated data.
Multiple-value field containing any number of RGB colors stored as three floats.
Definition SoMFColor.h:98
Multiple-value field containing any number of uint32_t integers.
Definition SoMFUInt32.h:90
Sensor class that can be attached to Open Inventor nodes.
Maintains a list of pointers to paths.
Definition SoPathList.h:81
Field containing an RGB color.
Definition SoSFColor.h:82
Abstract base class for Open Inventor sensors.
Definition SoSensor.h:100
const SbColor & getColor()
Gets the current color value.
void attach(SoMFColor *color, int index, SoBase *node)
Attaches the editor to a color node and edits the color of the given index.
SoXtColorEditor::UpdateFrequency getUpdateFrequency()
Gets the update frequency.
void SoXtColorEditorCB(void *userData, const SbColor *color)
Sliders
list of possible slider combinations, which is used to specify which sliders should be displayed at a...
@ INTENSITY
Display intensity slider (default)
@ RGB_V
Display RGB and value sliders.
@ RGB
Display RGB sliders.
@ HSV
Display HSV sliders.
@ NONE
Display no sliders.
@ RGB_HSV
Display RGB and HSV sliders.
void attach(SoMFUInt32 *color, int index, SoBase *node)
Attaches the editor to a color node and edits the color of the given index.
SoXtColorEditor::Sliders getCurrentSliders()
Gets which slider(s) should be displayed.
void setWYSIWYG(SbBool trueOrFalse)
Sets the WYSIWYG (what-you-see-is-what-you-get) mode on/off for the colored backgrounds of the slider...
void setUpdateFrequency(SoXtColorEditor::UpdateFrequency freq)
Sets the update frequency.
void attach(SoSFColor *color, SoBase *node)
Attaches the editor to a color node and edits the specified color.
SbBool isWYSIWYG()
Gets the WYSIWYG mode.
~SoXtColorEditor()
Destructor.
void removeColorChangedCallback(SoXtColorEditorCB *f, void *userData=NULL)
Removes colorChanged callback.
void setCurrentSliders(SoXtColorEditor::Sliders whichSliders)
Sets which slider(s) should be displayed.
SbBool isAttached()
Returns TRUE if the editor is attached.
void detach()
Detaches the editor from a color node.
SoXtColorEditor(SoWidget parent=NULL, const char *name=NULL, SbBool buildInsideParent=TRUE)
Constructor.
UpdateFrequency
UpdateFrequency is how often new values should be sent to the node or the callback routine.
@ CONTINUOUS
Send updates with every mouse motion.
@ AFTER_ACCEPT
Only send updates after user hits accept button.
void setColor(const SbColor &color)
Sets a new color value.
void addColorChangedCallback(SoXtColorEditorCB *f, void *userData=NULL)
Additional way of using the color editor, by registering a callback which will be called whenever the...
int SbBool
Boolean type.
Definition SbBase.h:87