Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
SoWinColorEditor.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
25#ifndef _SO_WIN_COLOR_EDITOR_
26#define _SO_WIN_COLOR_EDITOR_
27
28#include <Inventor/sys/port.h>
29#ifdef _WIN32
30# include <Inventor/Win/SoWinBeginStrict.h>
31#else
32# include <Xm/Xm.h>
33#endif
34#include <Inventor/SbColor.h>
35#include <Inventor/misc/SoCallbackList.h>
36#include <Inventor/Win/SoWinComponent.h>
37
38
39class SoBase;
40class SoNodeSensor;
41class SoMFColor;
42class SoPathList;
43class SoSFColor;
44class SoSensor;
45class SoWinClipboard;
46class SoWinColorPatch;
47class SoWinColorWheel;
48class SoWinColorSlider;
49
50class SoMFUInt32; //Allow attaching to "orderedRGBA" field
51
52struct ColorEditorCBData;
53
54// callback function prototypes
61typedef void SoWinColorEditorCB(void *userData, const SbColor *color);
62
63#ifdef _WIN32
64class CBitButton ;
65#endif
66
68//
69// Class: SoWinColorEditor
70//
71// SoWinColorEditor class which lets you interactively edit a color.
72//
74
97
98 public:
129
144
149 SoWidget parent = NULL,
150 const char *name = NULL,
151 SbBool buildInsideParent = TRUE);
156
171 void attach(SoSFColor *color, SoBase *node);
176 void attach(SoMFColor *color, int index, SoBase *node);
177
181 void attach(SoMFUInt32 *color, int index, SoBase *node);
182
188 void detach();
192 SbBool isAttached() { return attached; }
193
200 inline void addColorChangedCallback(
202 void *userData = NULL);
207 inline void removeColorChangedCallback(
209 void *userData = NULL);
210
215 void setColor(const SbColor &color);
219 const SbColor & getColor() { return baseRGB; }
220
235 void setWYSIWYG(SbBool trueOrFalse);
239 SbBool isWYSIWYG() { return WYSIWYGmode; }
240
249
259
260
262 private:
263
264
265 // This constructor takes a boolean whether to build the widget now.
266 // Subclasses can pass FALSE, then call SoWinColorEditor::buildWidget()
267 // when they are ready for it to be built.
268 SoEXTENDER
270 SoWidget parent,
271 const char *name,
272 SbBool buildInsideParent,
273 SbBool buildNow);
274
275 // redefine these
276 virtual SbString getDefaultWidgetName() const;
277 virtual SbString getDefaultTitle() const;
278 virtual SbString getDefaultIconTitle() const;
279
280 private:
281
282#ifdef _WIN32
283 POINT sliderPos[6] ;
284 POINT sliderLabPos[6] ;
285 POINT sliderValPos[6] ;
286 RECT areaPos[6] ;
287 RECT rcDlg ;
288
289 unsigned long sliderId[6] ;
290 unsigned long sliderLabId[6] ;
291 unsigned long sliderValId[6] ;
292 unsigned long areaId[6] ;
293 unsigned long nCurrSliderId ;
294 unsigned long nCurrEditId ;
295
296 HMENU menubar ;
297 HGLOBAL hDlgTemplate;
298
299 CBitButton *lpleftButton ;
300 CBitButton *lprightButton ;
301 CBitButton *lpswitchButton ;
302
303 void finishBuild() ;
304 void getControlPositions() ;
305 void hideAllSliders() ;
306 void showAllSliders() ;
307 void moveSlider(int nSlider,int nPos) ;
308 void showSlider(int nSlider) ;
309 void hideSlider(int nSlider) ;
310 void showControl(int nId) ;
311 void hideControl(int nId) ;
312 void sizeToArea(int n) ;
313 void layoutAccept(WBOOL nReduceOk) ;
314 void showArea0() ;
315 void showArea1() ;
316 void showArea2() ;
317 void showArea3() ;
318 void showArea4() ;
319 void showArea5() ;
320
321 static WBOOL CALLBACK mgrDlgProc( Hwnd hdlg, UINT message,
322 WPARAM wParam, LPARAM lParam );
323 static void onCommand(
324 Hwnd hdlg,
325 int id,
326 Hwnd hCtrl,
327 UINT codeNotify ) ;
328
329 void handleEdit(
330 int nSlider,
331 Hwnd hEdit,
332 UINT codeNotify) ;
333
334 WBOOL handleDrawItem(
335 WPARAM wParam,
336 LPARAM lParam ) ;
337
338
339#endif
340
341 // redefine these to do colorEditor specific things
342 SoWidget buildWidget(SoWidget parent);
343 static void visibilityChangeCB(void *pt, SbBool visible);
344
345 // local variables
346 SoWidget mgrWidget; // form manages all child widgets
347 SbBool WYSIWYGmode;
348 Sliders whichSliders;
349 SbColor baseRGB;
350 float baseHSV[3];
351 SbBool ignoreCallback;
352 SoWinColorSlider *sliders[6];
353 SoWinColorWheel *wheel;
354 SoWinColorPatch *current, *previous;
355 ColorEditorCBData *dataId;
356 SbPList menuItems; // Widgets
358
359 // attach/detach variables
360 SbBool attached;
361 SoBase *editNode;
362 SoSFColor *colorSF;
363 SoMFColor *colorMF;
364 SoNodeSensor *colorSensor;
365 SoCallbackList *callbackList;
366 int index;
367
368 // additional attach variables for handling "orderedRGBA" fields
369 SoMFUInt32 *colorUInt32MF;
370 float transparency;
371
372 // copy/paste support
373 SoWinClipboard *clipboard;
374 void copy(Time eventTime);
375 void paste(Time eventTime);
376
377 void pasteDone(SoPathList *pathList);
378 static void pasteDoneCB(void *userData, SoPathList *pathList);
379
380 // list of widgets which need to be accessed
381 SoWidget acceptButton, slidersForm, buttonsForm, wheelForm;
382
383 // build/destroy routines
384 SoWidget buildPulldownMenu(SoWidget parent);
385 SoWidget buildControls(SoWidget parent);
386 SoWidget buildSlidersForm(SoWidget parent);
387
388 void doSliderLayout();
389 void doDynamicTopLevelLayout();
390 int numberOfSliders(SoWinColorEditor::Sliders slider);
391
392
393 // do the updates - if attached, update the node; if callback, call it.
394 void doUpdates();
395
396 // color field sensor callback and routine
397 void fieldChanged();
398 static void fieldChangedCB(void *, SoSensor *);
399
400 // callbacks and actual routine from sliders, wheel, buttons, menu...
401 static void wheelCallback(void *, const float hsv[3]);
402 void wheelChanged(const float hsv[3]);
403 static void sliderCallback(void *, float);
404 void sliderChanged(short id, float value);
405
406#ifdef _WIN32
407 void buttonsCallback(int id);
408#else
409 static void buttonsCallback(SoWidget, ColorEditorCBData *, XtPointer);
410#endif
411 void buttonPressed(short id);
412
413#ifdef _WIN32
414 void editMenuCallback(int id);
415 void sliderMenuCallback(int id);
416#else
417 static void editMenuCallback(SoWidget, ColorEditorCBData *, XmAnyCallbackStruct *);
418 static void sliderMenuCallback(SoWidget, ColorEditorCBData *, XtPointer);
419#endif
420
421 static void menuDisplay(SoWidget, SoWinColorEditor *editor, XtPointer);
422
423 // this is called by both constructors
424 void constructorCommon(SbBool buildNow);
425
426};
427
428// Inline functions
429void
431 SoWinColorEditorCB *f,
432 void *userData)
433{ callbackList->addCallback((SoCallbackListCB *) f, userData); }
434
435void
437 SoWinColorEditorCB *f,
438 void *userData)
439{ callbackList->removeCallback((SoCallbackListCB *) f, userData); }
440
441
442#ifdef _WIN32
443#include <Inventor/Win/SoWinEndStrict.h>
444#endif
445#endif /* _SO_WIN_COLOR_EDITOR_ */
446
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.
void addCallback(SoCallbackListCB *f, void *userData=NULL)
Adds a function to the list of callback functions.
void removeCallback(SoCallbackListCB *f, void *userData=NULL)
Removes a function from the list of callback functions.
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
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Supports copy/pa...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Component that l...
Sliders
list of possible slider combinations, which is used to specify which sliders should be displayed at a...
@ RGB_HSV
Display RGB and HSV sliders.
@ NONE
Display no sliders.
@ HSV
Display HSV sliders.
@ RGB
Display RGB sliders.
@ RGB_V
Display RGB and value sliders.
@ INTENSITY
Display intensity slider (default)
void attach(SoMFColor *color, int index, SoBase *node)
Attaches the editor to a color node and edits the specified color.
void setColor(const SbColor &color)
Sets a new color value.
SoWinColorEditor::UpdateFrequency getUpdateFrequency()
Gets the update frequency.
void attach(SoMFUInt32 *color, int index, SoBase *node)
Handles attaching to an "orderedRGBA" field (e.g. SoVertexProperty)
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 removeColorChangedCallback(SoWinColorEditorCB *f, void *userData=NULL)
Removes colorChanged callback.
void setCurrentSliders(SoWinColorEditor::Sliders whichSliders)
Sets which slider(s) should be displayed.
void detach()
Detaches the editor from a color node.
void addColorChangedCallback(SoWinColorEditorCB *f, void *userData=NULL)
Additional way of using the color editor, by registering a callback which will be called whenever the...
SoWinColorEditor(SoWidget parent=NULL, const char *name=NULL, SbBool buildInsideParent=TRUE)
Constructor.
const SbColor & getColor()
Gets the current color value.
void attach(SoSFColor *color, SoBase *node)
Attaches the editor to a color node and edits the specified color.
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.
SbBool isAttached()
Returns TRUE if the editor is attached.
void setUpdateFrequency(SoWinColorEditor::UpdateFrequency freq)
Sets the update frequency.
SbBool isWYSIWYG()
Gets the WYSIWYG mode.
void SoWinColorEditorCB(void *userData, const SbColor *color)
SoWinColorEditor::Sliders getCurrentSliders()
Gets which slider(s) should be displayed.
~SoWinColorEditor()
Destructor.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract base cl...
int SbBool
Boolean type.
Definition SbBase.h:87
void * XtPointer
Definition SoQtDef.h:122