Open Inventor Release 2024.1.0
 
Loading...
Searching...
No Matches
SoQtColorWheel.h
Go to the documentation of this file.
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-2014 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : Alain Dumesny (MMM yyyy)
22**=======================================================================*/
23
24#ifndef _SO_QT_COLOR_WHEEL_
25#define _SO_QT_COLOR_WHEEL_
26
28#include <Inventor/SbColor.h>
29#include <Inventor/SbLinear.h>
32
33
34class SoQtMouse;
35
36// callback function prototypes
37typedef void SoQtColorWheelCB(void *userData, const float hsv[3]);
38
40//
41// Class: SoQtColorWheel
42//
43// Lets you interactively select colors using a color wheel. User register
44// callback(s) to be notified when a new color has been selected. There is
45// also a call to tell the color wheel what the current color is when it is
46// changed externally.
47//
49
50
51{
52 Q_OBJECT
53
54public:
55
56 SoQtColorWheel(QWidget* parent = NULL,
57 const char *name = NULL,
58 SbBool buildInsideParent = TRUE);
60
61 //
62 // Routine to tell the color wheel what the current HSV color is.
63 //
64 // NOTE: if calling setBaseColor() changes the marker position the
65 // valueChanged callbacks will be called with the new hsv color.
66 //
67 void setBaseColor(const float hsv[3]);
68 const float *getBaseColor() { return hsvColor; }
69
70 //
71 // This routine sets the WYSIWYG (What You See Is What You Get) mode.
72 // When WYSIWYG is on the colors on the wheel will reflect the current
73 // color intensity (i.e. get darker and brighter)
74 //
75 void setWYSIWYG(SbBool trueOrFalse); // default FALSE
76 SbBool isWYSIWYG() { return WYSIWYGmode; }
77
78 //
79 // Those routines are used to register callbacks for the different
80 // color wheel actions.
81 //
82 // NOTE: the start and finish callbacks are only to signal when the mouse
83 // goes down and up. No valid callback data is passed (NULL passed).
84 //
87 void *userData = NULL)
88 { startCallbacks->addCallback((SoCallbackListCB *) f, userData); }
89
92 void *userData = NULL)
93 { changedCallbacks->addCallback((SoCallbackListCB *) f, userData); }
94
97 void *userData = NULL)
98 { finishCallbacks->addCallback((SoCallbackListCB *) f, userData); }
99
102 void *userData = NULL)
103 { startCallbacks->removeCallback((SoCallbackListCB *) f, userData); }
104
107 void *userData = NULL)
108 { changedCallbacks->removeCallback((SoCallbackListCB *) f, userData); }
109
112 void *userData = NULL)
113 { finishCallbacks->removeCallback((SoCallbackListCB *) f, userData); }
114
115
116 // true while the color is changing interactively
117 SbBool isInteractive() { return interactive; }
118
119private:
120
121 // This constructor takes a boolean whether to build the widget now.
122 // Subclasses can pass FALSE, then call SoQtColorWheel::buildWidget()
123 // when they are ready for it to be built.
125 SoQtColorWheel(
126 QWidget* parent,
127 const char *name,
128 SbBool buildInsideParent,
129 SbBool buildNow);
130
131 QWidget* buildWidget(QWidget* parent);
132
133private:
134
135 // redefine these to do color wheel specific things
136 virtual void redraw();
137 virtual void redrawOverlay();
138 virtual void processEvent(QEvent *anyevent);
139 virtual void sizeChanged(const SbVec2s &newSize);
140
141 // color wheels local variables
142 SbBool WYSIWYGmode;
143 SbBool blackMarker;
144 float hsvColor[3];
145 int cx, cy, radius;
146 SbColor *defaultColors, *colors;
147 SbVec2f *geometry;
148 SoQtMouse *mouse;
149
150 // callback variables
151 SoCallbackList *startCallbacks;
152 SoCallbackList *changedCallbacks;
153 SoCallbackList *finishCallbacks;
154 SbBool interactive;
155
156 // routines to make the wheel geometry, colors, draw it....
157 void makeWheelGeometry();
158 void makeWheelColors(SbColor *col, float intensity);
159 void drawWheelSurrounding();
160 void drawWheelColors();
161 void checkMarkerColor();
162 void drawWheelMarker();
163 void moveWheelMarker(short x, short y);
164
165 // this is called by both constructors
166 void constructorCommon(SbBool buildNow);
167#ifdef _WIN32
168 void SaveUnder(short x,short y);
169 void RestoreUnder();
170
171 SbBool nSaved;
172 short nSaveX, nSaveY;
173# ifndef GDISAVE
174 unsigned long *pSaveBuf;
175# else
176 HBITMAP hSaveBits;
177 HDC hSaveDC;
178# endif
179#endif
180#if defined(__APPLE__) || defined(_WIN32)
181 int nMarkR, nMarkG, nMarkB;
182#endif
183};
184
185#endif /* _SO_QT_COLOR_WHEEL_ */
186
187
#define SoEXTENDER
#define TRUE
Possible value of SbBool.
Definition SbBase.h:77
const float * getBaseColor()
SbBool isInteractive()
void SoQtColorWheelCB(void *userData, const float hsv[3])
void removeFinishCallback(SoQtColorWheelCB *f, void *userData=NULL)
~SoQtColorWheel()
SbBool isWYSIWYG()
void removeStartCallback(SoQtColorWheelCB *f, void *userData=NULL)
void addStartCallback(SoQtColorWheelCB *f, void *userData=NULL)
void setWYSIWYG(SbBool trueOrFalse)
void addValueChangedCallback(SoQtColorWheelCB *f, void *userData=NULL)
void removeValueChangedCallback(SoQtColorWheelCB *f, void *userData=NULL)
void addFinishCallback(SoQtColorWheelCB *f, void *userData=NULL)
void setBaseColor(const float hsv[3])
Color vector class.
Definition SbColor.h:82
2D vector class.
Definition SbVec.h:76
2D vector class.
Definition SbVec.h:700
Manages a list of callbacks and associated data.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Translates and r...
Definition SoQtMouse.h:58
int SbBool
Boolean type.
Definition SbBase.h:87
void SoCallbackListCB(void *userData, void *callbackData)
#define HDC
Definition port.h:351