00001 /*======================================================================= 00002 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00003 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00004 *** *** 00005 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00006 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00007 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00008 *** *** 00009 *** RESTRICTED RIGHTS LEGEND *** 00010 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00011 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00012 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00013 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00014 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00015 *** *** 00016 *** COPYRIGHT (C) 1996-2020 BY FEI S.A.S, *** 00017 *** BORDEAUX, FRANCE *** 00018 *** ALL RIGHTS RESERVED *** 00019 **=======================================================================*/ 00020 /*======================================================================= 00021 ** Author : VSG (MMM YYYY) 00022 **=======================================================================*/ 00023 00024 00025 #ifndef _SO_XT_SLIDER_ 00026 #define _SO_XT_SLIDER_ 00027 00028 #ifdef SOQT 00029 # include <Inventor/Qt/SoQtSlider.h> 00030 #elif defined(_WIN32) 00031 # include <Inventor/Win/SoWinSlider.h> 00032 #else 00033 00034 #include <Inventor/misc/SoCallbackList.h> 00035 #include <Inventor/Xt/SoXtGLWidget.h> 00036 00037 00038 class SoFloatCallbackList; 00039 class SoXtMouse; 00040 00041 // callback function prototypes 00042 typedef void SoXtSliderCB(void *userData, float val); 00043 00045 // 00046 // Class: SoXtSlider 00047 // 00048 // This is the basic slider type, which lets you set the slider value and 00049 // register callbacks when the slider is being moved (either as soon as the 00050 // slider changes values, or when the slider has stopped moving (mouse up)). 00051 // 00053 00054 { 00055 public: 00056 00057 // constructor/destructor 00058 SoXtSlider( 00059 SoWidget parent = NULL, 00060 const char *name = NULL, 00061 SbBool buildInsideParent = TRUE); 00062 ~SoXtSlider(); 00063 00064 // 00065 // Those routines are used to specify the slider value (which is automatically 00066 // reflected in the slider) and get the current value. 00067 // 00068 // NOTE: setValue() will call valueChanged callbacks if the value differs. 00069 // 00070 // NOTE: currently only values [0.0 , 1.0] are supported 00071 // 00072 void setValue(float v); 00073 float getValue() const { return value; } 00074 00075 // 00076 // Specifies the label string which appears before the slider. A NULL 00077 // string will remove the label altogether. (default behavior) 00078 // 00079 // @UNICODE_WARNING 00080 // 00081 SoNONUNICODE void setLabel(const char *newlabel); 00082 00083 00084 // 00085 // Specifies the label string which appears before the slider. A NULL 00086 // string will remove the label altogether. (default behavior) 00087 // 00088 void setLabel(const SbString& newlabel); 00089 00090 00091 SbString getLabel() const {return labelStr;} 00092 00093 // 00094 // Display a numeric value in a text field to the right of the slider 00095 // which can be edited to change the value of the slider. 00096 // Default is TRUE (display the numeric value). 00097 // 00098 void setNumericFieldVisible(SbBool b); 00099 SbBool isNumericFieldVisible() const { return numberVisible; } 00100 00101 // 00102 // Those routines are used to register callbacks for the different slider 00103 // actions. 00104 // 00105 // NOTE: the start and finish callbacks are only to signal when the mouse 00106 // goes down and up. No valid callback data is passed (0.0 passed). 00107 // 00108 void addStartCallback( 00109 SoXtSliderCB *f, 00110 void *userData = NULL); 00111 void addValueChangedCallback( 00112 SoXtSliderCB *f, 00113 void *userData = NULL); 00114 void addFinishCallback( 00115 SoXtSliderCB *f, 00116 void *userData = NULL); 00117 00118 void removeStartCallback( 00119 SoXtSliderCB *f, 00120 void *userData = NULL); 00121 void removeValueChangedCallback( 00122 SoXtSliderCB *f, 00123 void *userData = NULL); 00124 void removeFinishCallback( 00125 SoXtSliderCB *f, 00126 void *userData = NULL); 00127 00128 // true while the value is changing interactively 00129 void interactivity( SbBool flag ) { interactive = flag; } 00130 SbBool isInteractive() { return interactive; } 00131 00132 // sets/gets the size of the actual slider, excluding the label and 00133 // text field widget sizes which are fixed in size. 00134 // 00135 // This is the prefered behavior since it allows a user to align 00136 // multiple sliders (same size) regardless of the text label size 00137 // (which are usually different). 00138 // 00139 // NOTE: this is different from most widgets, which do resize their 00140 // container widgets. This functionality can still be achieved using 00141 // the setSize() and getSize() methods. 00142 // 00143 void setSliderSize(const SbVec2s &size); 00144 SbVec2s getSliderSize(); 00145 00146 private: 00147 00148 // This constructor takes a boolean whether to build the widget now. 00149 // Subclasses can pass FALSE, then call SoXtSlider::buildWidget() 00150 // when they are ready for it to be built. 00151 SoEXTENDER 00152 SoXtSlider( 00153 SoWidget parent, 00154 const char *name, 00155 SbBool buildInsideParent, 00156 SbBool buildNow); 00157 00158 // redefine these to do slider specific things 00159 virtual void redraw(); 00160 virtual void processEvent(XAnyEvent *anyevent); 00161 virtual void sizeChanged(const SbVec2s &newSize); 00162 00163 SoWidget buildWidget(SoWidget parent); 00164 00165 // 00166 // this is the routine subclasses would redefine to change the look of 00167 // the actual slider top region, which defaults to grey with a thin white marker. 00168 // 00169 virtual void drawSliderTopRegion(); 00170 00171 // slider top region area (used by subclasses to do their own 00172 // drawings in there). 00173 short slx1, sly1, slx2, sly2; 00174 short thumx1, thumy1, thumx2, thumy2; 00175 00176 private: 00177 00178 SoWidget mgrWidget, numberWidget, sliderWidget, labelWidget; 00179 SbBool numberVisible; // whether numeric field is visible 00180 SbString labelStr; // label preceeding slider 00181 SbVec2s sliderSize; // size of the 'widget' and 'shell' 00182 SoXtMouse *mouse; 00183 00184 // slider local variables (slider value, thum position) 00185 float value; 00186 short position, posdiff; 00187 00188 // build routines 00189 void doLabelLayout(); 00190 void doNumberLayout(); 00191 00192 // callback variables 00193 SoFloatCallbackList *startCallbacks; 00194 SoFloatCallbackList *changedCallbacks; 00195 SoFloatCallbackList *finishCallbacks; 00196 SbBool interactive; 00197 00198 // text field vars and callbacks 00199 static void textFieldCB(SoWidget, SoXtSlider *, XtPointer); 00200 00201 // this is called by both constructors 00202 void constructorCommon(SbBool buildNow); 00203 00204 }; 00205 00206 #endif 00207 00208 #endif /* _SO_XT_SLIDER_ */ 00209 00210 00211