00001 /*
00002 *
00003 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
00004 *
00005 * This library is free software; you can redistribute it and/or
00006 * modify it under the terms of the GNU Lesser General Public
00007 * License as published by the Free Software Foundation; either
00008 * version 2.1 of the License, or (at your option) any later version.
00009 *
00010 * This library is distributed in the hope that it will be useful,
00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00013 * Lesser General Public License for more details.
00014 *
00015 * Further, this software is distributed without any warranty that it is
00016 * free of the rightful claim of any third person regarding infringement
00017 * or the like. Any license provided herein, whether implied or
00018 * otherwise, applies only to this software file. Patent licenses, if
00019 * any, provided herein do not apply to combinations of this program with
00020 * other software, or any other product whatsoever.
00021 *
00022 * You should have received a copy of the GNU Lesser General Public
00023 * License along with this library; if not, write to the Free Software
00024 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00025 *
00026 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
00027 * Mountain View, CA 94043, or:
00028 *
00029 * http://www.sgi.com
00030 *
00031 * For further information regarding this notice, see:
00032 *
00033 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
00034 *
00035 */
00036
00037 // -*- C++ -*-
00038
00039 /*
00040 * Copyright (C) 1990-93 Silicon Graphics, Inc.
00041 *
00042 _______________________________________________________________________
00043 ______________ S I L I C O N G R A P H I C S I N C . ____________
00044 |
00045 | $Revision: 1.1 $
00046 |
00047 | Description:
00048 | This file contains the MySlider class which is a GL slider within
00049 | a GLX widget. The slider contains a text label to its left, and a
00050 | user editable text field to the right which displays the numeric value
00051 | of the slider. There are methods to disable either of these text fields.
00052 |
00053 | Classes:
00054 | MySlider
00055 |
00056 | Author(s) : Alain Dumesny
00057 |
00058 ______________ S I L I C O N G R A P H I C S I N C . ____________
00059 _______________________________________________________________________
00060 */
00061
00062 #ifndef _SO_XT_SLIDER_
00063 #define _SO_XT_SLIDER_
00064
00065 #include <Inventor/misc/SoCallbackList.h>
00066 #include <Inventor/Xt/SoXtGLWidget.h>
00067
00068
00069 class MyFloatCallbackList;
00070 class SoXtMouse;
00071
00072 // callback function prototypes
00073 typedef void MySliderCB(void *userData, float val);
00074
00076 //
00077 // Class: MySlider
00078 //
00079 // This is the basic slider type, which lets you set the slider value and
00080 // register callbacks when the slider is being moved (either as soon as the
00081 // slider changes values, or when the slider has stopped moving (mouse up)).
00082 //
00084
00085 // C-api: prefix=SoXtSldr
00086 class MySlider : public SoXtGLWidget {
00087 public:
00088
00089 // constructor/destructor
00090 MySlider(
00091 Widget parent = NULL,
00092 const char *name = NULL,
00093 SbBool buildInsideParent = TRUE);
00094 ~MySlider();
00095
00096 //
00097 // Those routines are used to specify the slider value (which is automatically
00098 // reflected in the slider) and get the current value.
00099 //
00100 // NOTE: setValue() will call valueChanged callbacks if the value differs.
00101 //
00102 // NOTE: currently only values [0.0 , 1.0] are supported
00103 //
00104 void setValue(float v);
00105 float getValue() const { return value; }
00106
00107 //
00108 // Specifies the label string which appears before the slider. A NULL
00109 // string will remove the label altogether. (default behavior)
00110 //
00111 void setLabel(const char *newlabel);
00112 const char *getLabel() const { return labelStr; }
00113
00114 //
00115 // Display a numeric value in a text field to the right of the slider
00116 // which can be edited to change the value of the slider.
00117 // Default is TRUE (display the numeric value).
00118 //
00119 void setNumericFieldVisible(SbBool b);
00120 SbBool isNumericFieldVisible() const { return numberVisible; }
00121
00122 //
00123 // Those routines are used to register callbacks for the different slider
00124 // actions.
00125 //
00126 // NOTE: the start and finish callbacks are only to signal when the mouse
00127 // goes down and up. No valid callback data is passed (0.0 passed).
00128 //
00129 // C-api: name=addStartCB
00130 void addStartCallback(
00131 MySliderCB *f,
00132 void *userData = NULL);
00133 // C-api: name=addValueChangedCB
00134 void addValueChangedCallback(
00135 MySliderCB *f,
00136 void *userData = NULL);
00137 // C-api: name=addFinishCB
00138 void addFinishCallback(
00139 MySliderCB *f,
00140 void *userData = NULL);
00141
00142 // C-api: name=removeStartCB
00143 void removeStartCallback(
00144 MySliderCB *f,
00145 void *userData = NULL);
00146 // C-api: name=removeValueChangedCB
00147 void removeValueChangedCallback(
00148 MySliderCB *f,
00149 void *userData = NULL);
00150 // C-api: name=removeFinishCB
00151 void removeFinishCallback(
00152 MySliderCB *f,
00153 void *userData = NULL);
00154
00155 // true while the value is changing interactively
00156 SbBool isInteractive() { return interactive; }
00157
00158 // sets/gets the size of the actual slider, excluding the label and
00159 // text field widget sizes which are fixed in size.
00160 //
00161 // This is the prefered behavior since it allows a user to align
00162 // multiple sliders (same size) regardless of the text label size
00163 // (which are usually different).
00164 //
00165 // NOTE: this is different from most widgets, which do resize their
00166 // container widgets. This functionality can still be achieved using
00167 // the setSize() and getSize() methods.
00168 //
00169 void setSliderSize(const SbVec2s &size);
00170 SbVec2s getSliderSize();
00171
00172 protected:
00173
00174 // This constructor takes a boolean whether to build the widget now.
00175 // Subclasses can pass FALSE, then call MySlider::buildWidget()
00176 // when they are ready for it to be built.
00177 SoEXTENDER
00178 MySlider(
00179 Widget parent,
00180 const char *name,
00181 SbBool buildInsideParent,
00182 SbBool buildNow);
00183
00184 // redefine these to do slider specific things
00185 virtual void redraw();
00186 virtual void processEvent(XAnyEvent *anyevent);
00187 virtual void sizeChanged(const SbVec2s &newSize);
00188
00189 Widget buildWidget(Widget parent);
00190
00191 //
00192 // this is the routine subclasses would redefine to change the look of
00193 // the actual slider top region, which defaults to grey with a thin white marker.
00194 //
00195 virtual void drawSliderTopRegion();
00196
00197 // slider top region area (used by subclasses to do their own
00198 // drawings in there).
00199 short slx1, sly1, slx2, sly2;
00200 short thumx1, thumy1, thumx2, thumy2;
00201
00202 private:
00203 Widget mgrWidget, numberWidget, sliderWidget, labelWidget;
00204 SbBool numberVisible; // whether numeric field is visible
00205 char *labelStr; // label preceeding slider
00206 SbVec2s sliderSize; // size of the 'widget' and 'shell'
00207 SoXtMouse *mouse;
00208
00209 // slider local variables (slider value, thum position)
00210 float value;
00211 short position, posdiff;
00212
00213 // build routines
00214 void doLabelLayout();
00215 void doNumberLayout();
00216
00217 // callback variables
00218 MyFloatCallbackList *startCallbacks;
00219 MyFloatCallbackList *changedCallbacks;
00220 MyFloatCallbackList *finishCallbacks;
00221 SbBool interactive;
00222
00223 // text field vars and callbacks
00224 static void textFieldCB(Widget, MySlider *, XtPointer);
00225
00226 // this is called by both constructors
00227 void constructorCommon(SbBool buildNow);
00228 };
00229
00230 #endif /* _SO_XT_SLIDER_ */
1.2.11.1 written by Dimitri van Heesch,
© 1997-2001