Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
SoXtSlider.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-2020 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_XT_SLIDER_
26#define _SO_XT_SLIDER_
27
28#ifdef SOQT
29# include <Inventor/Qt/SoQtSlider.h>
30#elif defined(_WIN32)
31# include <Inventor/Win/SoWinSlider.h>
32#else
33
34#include <Inventor/misc/SoCallbackList.h>
35#include <Inventor/Xt/SoXtGLWidget.h>
36
37
38class SoFloatCallbackList;
39class SoXtMouse;
40
41// callback function prototypes
42typedef void SoXtSliderCB(void *userData, float val);
43
45//
46// Class: SoXtSlider
47//
48// This is the basic slider type, which lets you set the slider value and
49// register callbacks when the slider is being moved (either as soon as the
50// slider changes values, or when the slider has stopped moving (mouse up)).
51//
53
54{
55 public:
56
57 // constructor/destructor
58 SoXtSlider(
59 SoWidget parent = NULL,
60 const char *name = NULL,
61 SbBool buildInsideParent = TRUE);
62 ~SoXtSlider();
63
64 //
65 // Those routines are used to specify the slider value (which is automatically
66 // reflected in the slider) and get the current value.
67 //
68 // NOTE: setValue() will call valueChanged callbacks if the value differs.
69 //
70 // NOTE: currently only values [0.0 , 1.0] are supported
71 //
72 void setValue(float v);
73 float getValue() const { return value; }
74
75 //
76 // Specifies the label string which appears before the slider. A NULL
77 // string will remove the label altogether. (default behavior)
78 //
79 // @UNICODE_WARNING
80 //
81 SoNONUNICODE void setLabel(const char *newlabel);
82
83
84 //
85 // Specifies the label string which appears before the slider. A NULL
86 // string will remove the label altogether. (default behavior)
87 //
88 void setLabel(const SbString& newlabel);
89
90
91 SbString getLabel() const {return labelStr;}
92
93 //
94 // Display a numeric value in a text field to the right of the slider
95 // which can be edited to change the value of the slider.
96 // Default is TRUE (display the numeric value).
97 //
98 void setNumericFieldVisible(SbBool b);
99 SbBool isNumericFieldVisible() const { return numberVisible; }
100
101 //
102 // Those routines are used to register callbacks for the different slider
103 // actions.
104 //
105 // NOTE: the start and finish callbacks are only to signal when the mouse
106 // goes down and up. No valid callback data is passed (0.0 passed).
107 //
108 void addStartCallback(
109 SoXtSliderCB *f,
110 void *userData = NULL);
111 void addValueChangedCallback(
112 SoXtSliderCB *f,
113 void *userData = NULL);
114 void addFinishCallback(
115 SoXtSliderCB *f,
116 void *userData = NULL);
117
118 void removeStartCallback(
119 SoXtSliderCB *f,
120 void *userData = NULL);
121 void removeValueChangedCallback(
122 SoXtSliderCB *f,
123 void *userData = NULL);
124 void removeFinishCallback(
125 SoXtSliderCB *f,
126 void *userData = NULL);
127
128 // true while the value is changing interactively
129 void interactivity( SbBool flag ) { interactive = flag; }
130 SbBool isInteractive() { return interactive; }
131
132 // sets/gets the size of the actual slider, excluding the label and
133 // text field widget sizes which are fixed in size.
134 //
135 // This is the prefered behavior since it allows a user to align
136 // multiple sliders (same size) regardless of the text label size
137 // (which are usually different).
138 //
139 // NOTE: this is different from most widgets, which do resize their
140 // container widgets. This functionality can still be achieved using
141 // the setSize() and getSize() methods.
142 //
143 void setSliderSize(const SbVec2s &size);
144 SbVec2s getSliderSize();
145
146 private:
147
148 // This constructor takes a boolean whether to build the widget now.
149 // Subclasses can pass FALSE, then call SoXtSlider::buildWidget()
150 // when they are ready for it to be built.
151 SoEXTENDER
152 SoXtSlider(
153 SoWidget parent,
154 const char *name,
155 SbBool buildInsideParent,
156 SbBool buildNow);
157
158 // redefine these to do slider specific things
159 virtual void redraw();
160 virtual void processEvent(XAnyEvent *anyevent);
161 virtual void sizeChanged(const SbVec2s &newSize);
162
163 SoWidget buildWidget(SoWidget parent);
164
165 //
166 // this is the routine subclasses would redefine to change the look of
167 // the actual slider top region, which defaults to grey with a thin white marker.
168 //
169 virtual void drawSliderTopRegion();
170
171 // slider top region area (used by subclasses to do their own
172 // drawings in there).
173 short slx1, sly1, slx2, sly2;
174 short thumx1, thumy1, thumx2, thumy2;
175
176 private:
177
178 SoWidget mgrWidget, numberWidget, sliderWidget, labelWidget;
179 SbBool numberVisible; // whether numeric field is visible
180 SbString labelStr; // label preceeding slider
181 SbVec2s sliderSize; // size of the 'widget' and 'shell'
182 SoXtMouse *mouse;
183
184 // slider local variables (slider value, thum position)
185 float value;
186 short position, posdiff;
187
188 // build routines
189 void doLabelLayout();
190 void doNumberLayout();
191
192 // callback variables
193 SoFloatCallbackList *startCallbacks;
194 SoFloatCallbackList *changedCallbacks;
195 SoFloatCallbackList *finishCallbacks;
196 SbBool interactive;
197
198 // text field vars and callbacks
199 static void textFieldCB(SoWidget, SoXtSlider *, XtPointer);
200
201 // this is called by both constructors
202 void constructorCommon(SbBool buildNow);
203
204};
205
206#endif
207
208#endif /* _SO_XT_SLIDER_ */
209
210
Class for smart character strings.
Definition SbString.h:202
2D vector class.
Definition SbVec.h:700
Translates and reports events for the mouse device.
Definition SoXtMouse.h:87
int SbBool
Boolean type.
Definition SbBase.h:87
void * XtPointer
Definition SoQtDef.h:122