Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXKnob.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                             K n o b   W i d g e t                             *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2005,2009 by Leandro Nini.   All Rights Reserved.               *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 *********************************************************************************
00021 * $Id: FXKnob.h,v 1.14 2009/01/06 13:07:25 fox Exp $                            *
00022 ********************************************************************************/
00023 #ifndef FXKNOB_H
00024 #define FXKNOB_H
00025 
00026 #ifndef FXFRAME_H
00027 #include "FXFrame.h"
00028 #endif
00029 
00030 namespace FX {
00031 
00032 
00033 /// Knob Control styles
00034 enum {
00035   KNOB_NEEDLE    = 0,                           /// Use a needle as indicator
00036   KNOB_DOT       = 0x00008000,                  /// Use a dot as indicator
00037   KNOB_TICKS     = 0x00010000,                  /// Show ticks around the knob
00038   KNOB_INDICATOR = 0x00020000,                  /// Show only the indicator (like a speedometer)
00039   KNOB_NORMAL    = (KNOB_NEEDLE|KNOB_TICKS)     /// Normal knob looks
00040   };
00041 
00042 
00043 
00044 /**
00045 * The knob widget is a valuator widget which provides simple linear value range.
00046 * While being moved, the knob sends SEL_CHANGED messages to its target;
00047 * at the end of the interaction, a final SEL_COMMAND message is sent.
00048 * The message data represents the current knob value, of type FXint.
00049 */
00050 class FXAPI FXKnob : public FXFrame {
00051   FXDECLARE(FXKnob)
00052 protected:
00053   FXint    range[2];            // Reported data range
00054   FXdouble limits[2];           // Starting and ending positions
00055   FXColor  lineColor;           // Color of indicator needle
00056   FXint    pos;                 // Reported data position
00057   FXint    incr;                // Increment when auto-sliding
00058   FXint    delta;               // Interval between ticks
00059   FXString help;                // Help string
00060   FXString tip;                 // Tip string
00061 protected:
00062   FXKnob();
00063   FXint calcValue(FXint x,FXint y);
00064 private:
00065   FXKnob(const FXKnob&);
00066   FXKnob &operator=(const FXKnob&);
00067 public:
00068   long onPaint(FXObject*,FXSelector,void*);
00069   long onLeftBtnPress(FXObject*,FXSelector,void*);
00070   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00071   long onMiddleBtnPress(FXObject*,FXSelector,void*);
00072   long onMiddleBtnRelease(FXObject*,FXSelector,void*);
00073   long onMouseWheel(FXObject*,FXSelector,void*);
00074   long onUngrabbed(FXObject*,FXSelector,void*);
00075   long onMotion(FXObject*,FXSelector,void*);
00076   long onFocusIn(FXObject*,FXSelector,void*);
00077   long onFocusOut(FXObject*,FXSelector,void*);
00078   long onKeyPress(FXObject*,FXSelector,void*);
00079   long onKeyRelease(FXObject*,FXSelector,void*);
00080   long onAutoSlide(FXObject*,FXSelector,void*);
00081   long onCmdSetValue(FXObject*,FXSelector,void*);
00082   long onCmdSetIntValue(FXObject*,FXSelector,void*);
00083   long onCmdGetIntValue(FXObject*,FXSelector,void*);
00084   long onCmdSetLongValue(FXObject*,FXSelector,void*);
00085   long onCmdGetLongValue(FXObject*,FXSelector,void*);
00086   long onCmdSetRealValue(FXObject*,FXSelector,void*);
00087   long onCmdGetRealValue(FXObject*,FXSelector,void*);
00088   long onCmdSetIntRange(FXObject*,FXSelector,void*);
00089   long onCmdGetIntRange(FXObject*,FXSelector,void*);
00090   long onCmdSetRealRange(FXObject*,FXSelector,void*);
00091   long onCmdGetRealRange(FXObject*,FXSelector,void*);
00092   long onCmdSetHelp(FXObject*,FXSelector,void*);
00093   long onCmdGetHelp(FXObject*,FXSelector,void*);
00094   long onCmdSetTip(FXObject*,FXSelector,void*);
00095   long onCmdGetTip(FXObject*,FXSelector,void*);
00096   long onQueryHelp(FXObject*,FXSelector,void*);
00097   long onQueryTip(FXObject*,FXSelector,void*);
00098 public:
00099   enum{
00100     ID_AUTOSLIDE=FXFrame::ID_LAST,
00101     ID_LAST
00102     };
00103 public:
00104 
00105   /// Construct a knob widget
00106   FXKnob(FXComposite* p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=KNOB_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0,FXint pl=DEFAULT_PAD,FXint pr=DEFAULT_PAD,FXint pt=DEFAULT_PAD,FXint pb=DEFAULT_PAD);
00107 
00108   /// Returns true because a knob can receive focus
00109   virtual FXbool canFocus() const;
00110 
00111   /// Return default width
00112   virtual FXint getDefaultWidth();
00113 
00114   /// Return default height
00115   virtual FXint getDefaultHeight();
00116 
00117   /// Perform layout
00118   virtual void layout();
00119 
00120   /// Enable the knob
00121   virtual void enable();
00122 
00123   /// Disable the knob
00124   virtual void disable();
00125 
00126   /// Change knob value
00127   void setValue(FXint value,FXbool notify=false);
00128 
00129   /// Return knob value
00130   FXint getValue() const { return pos; }
00131 
00132   /// Change the knob's range
00133   void setRange(FXint lo,FXint hi,FXbool notify=false);
00134 
00135   /// Get the knob's current range
00136   void getRange(FXint& lo,FXint& hi) const { lo=range[0]; hi=range[1]; }
00137 
00138   /**
00139   * Change the knob's movement limits (start and ending angles)
00140   * accept values in degrees from 0 (south) to 360.
00141   */
00142   void setLimits(FXint start,FXint end,FXbool notify=false);
00143 
00144   /// Get the knob's current limits
00145   void getLimits(FXint& start,FXint& end);
00146 
00147   /// Change the knob style
00148   FXuint getKnobStyle() const;
00149 
00150   /// Get the current knob style
00151   void setKnobStyle(FXuint style);
00152 
00153   /// Get the knob's auto-increment/decrement value
00154   FXint getIncrement() const { return incr; }
00155 
00156   /// Change the knob's auto-increment/decrement value
00157   void setIncrement(FXint inc){ incr=inc; }
00158 
00159   /// Change the delta between ticks
00160   void setTickDelta(FXint dist);
00161 
00162   /// Get delta between ticks
00163   FXint getTickDelta() const { return delta; }
00164 
00165   /// Change the indicator needle color
00166   void setLineColor(FXColor clr);
00167 
00168   /// Get the current indicator needle color
00169   FXColor getLineColor() const { return lineColor; }
00170 
00171   /// Set the help text to be displayed on the status line
00172   void setHelpText(const FXString& text){ help=text; }
00173 
00174   /// Get the current help text
00175   const FXString& getHelpText() const { return help; }
00176 
00177   /// Set the tip text to be displayed in the tooltip
00178   void setTipText(const FXString& text){ tip=text; }
00179 
00180   /// Get the current tooltip text value
00181   const FXString& getTipText() const { return tip; }
00182 
00183   /// Save to stream
00184   virtual void save(FXStream& store) const;
00185 
00186   /// Load from stream
00187   virtual void load(FXStream& store);
00188 
00189   /// Destroy the knob
00190   virtual ~FXKnob();
00191   };
00192 
00193 }
00194 
00195 #endif

Copyright © 1997-2009 Jeroen van der Zijp