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

FXGradientBar.h

00001 /********************************************************************************
00002 *                                                                               *
00003 *                      G r a d i e n t B a r   W i d g e t                      *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2002 by Jeroen van der Zijp.   All Rights Reserved.             *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (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 GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXGradientBar.h,v 1.41 2002/09/30 13:06:56 fox Exp $                     *
00023 ********************************************************************************/
00024 #ifndef FXGRADIENTBAR_H
00025 #define FXGRADIENTBAR_H
00026 
00027 #ifndef FXFRAME_H
00028 #include "FXFrame.h"
00029 #endif
00030 
00031 
00032 namespace FX {
00033 
00034 
00035 
00036 /// Gradient bar orientation
00037 enum {
00038   GRADIENTBAR_HORIZONTAL      = 0,                          /// Gradient bar shown horizontally
00039   GRADIENTBAR_VERTICAL        = 0x00008000,                 /// Gradient bar shown vertically
00040   GRADIENTBAR_NO_CONTROLS     = 0,                          /// No controls shown
00041   GRADIENTBAR_CONTROLS_TOP    = 0x00010000,                 /// Controls on top
00042   GRADIENTBAR_CONTROLS_BOTTOM = 0x00020000,                 /// Controls on bottom
00043   GRADIENTBAR_CONTROLS_LEFT   = GRADIENTBAR_CONTROLS_TOP,   /// Controls on left
00044   GRADIENTBAR_CONTROLS_RIGHT  = GRADIENTBAR_CONTROLS_BOTTOM /// Controls on right
00045   };
00046 
00047 
00048 /// Blend modes
00049 enum {
00050   GRADIENT_BLEND_LINEAR,                /// Linear blend
00051   GRADIENT_BLEND_POWER,                 /// Power law blend
00052   GRADIENT_BLEND_SINE,                  /// Sine blend
00053   GRADIENT_BLEND_INCREASING,            /// Quadratic increasing blend
00054   GRADIENT_BLEND_DECREASING             /// Quadratic decreasing blend
00055   };
00056 
00057 
00058 
00059 // Gradient segment
00060 struct FXGradient {
00061   FXdouble lower;                     /// Lower value
00062   FXdouble middle;                    /// Middle value
00063   FXdouble upper;                     /// Upper value
00064   FXColor  lowerColor;                /// Lower color
00065   FXColor  upperColor;                /// Upper color
00066   FXuchar  blend;                     /// Blend method
00067   };
00068 
00069 
00070 class FXImage;
00071 
00072 
00073 /**
00074 * The gradient bar is a control that is used to edit color gradient,
00075 * such as used in texture mapping and shape filling.
00076 */
00077 class FXGradientBar : public FXFrame {
00078   FXDECLARE(FXGradientBar)
00079 protected:
00080   FXImage     *bar;                     // Image containing colors
00081   FXGradient  *seg;                     // Segments
00082   FXint        nsegs;                   // Number of segments
00083   FXint        sellower;                // Lower selected segment
00084   FXint        selupper;                // Upper selected segment
00085   FXint        dropped;                 // Dropped segment
00086   FXint        current;                 // Current segment
00087   FXint        anchor;                  // Anchor segment
00088   FXint        grip;                    // Grip being dragged, if any
00089   FXint        where;                   // Where dropped in segment
00090   FXString     tip;                     // Tooltip value
00091   FXString     help;                    // Help value
00092   FXColor      selectColor;             // Select color
00093   FXint        offset;                  // Offset
00094 protected:
00095   FXGradientBar();
00096   void updatebar();
00097   virtual void layout();
00098   FXdouble getValue(FXint x,FXint y) const;
00099   FXint getSegmentLowerPos(FXint sg) const;
00100   FXint getSegmentUpperPos(FXint sg) const;
00101   FXint getSegmentMiddlePos(FXint sg) const;
00102   void drawUpArrow(FXDCWindow& dc,FXint x,FXint y,FXColor clr);
00103   void drawDnArrow(FXDCWindow& dc,FXint x,FXint y,FXColor clr);
00104   void drawRtArrow(FXDCWindow& dc,FXint x,FXint y,FXColor clr);
00105   void drawLtArrow(FXDCWindow& dc,FXint x,FXint y,FXColor clr);
00106   void drawBottomArrows(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
00107   void drawTopArrows(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
00108   void drawLeftArrows(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
00109   void drawRightArrows(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
00110   static FXdouble blendlinear(FXdouble middle,FXdouble pos);
00111   static FXdouble blendpower(FXdouble middle,FXdouble pos);
00112   static FXdouble blendsine(FXdouble middle,FXdouble pos);
00113   static FXdouble blendincreasing(FXdouble middle,FXdouble pos);
00114   static FXdouble blenddecreasing(FXdouble middle,FXdouble pos);
00115 protected:
00116   enum {
00117     GRIP_NONE,
00118     GRIP_LOWER,
00119     GRIP_SEG_LOWER,
00120     GRIP_MIDDLE,
00121     GRIP_SEG_UPPER,
00122     GRIP_UPPER
00123     };
00124 private:
00125   FXGradientBar(const FXGradientBar&);
00126   FXGradientBar &operator=(const FXGradientBar&);
00127 public:
00128   long onPaint(FXObject*,FXSelector,void*);
00129   long onLeftBtnPress(FXObject*,FXSelector,void*);
00130   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00131   long onMotion(FXObject*,FXSelector,void*);
00132   long onDNDEnter(FXObject*,FXSelector,void*);
00133   long onDNDLeave(FXObject*,FXSelector,void*);
00134   long onDNDMotion(FXObject*,FXSelector,void*);
00135   long onDNDDrop(FXObject*,FXSelector,void*);
00136   long onQueryHelp(FXObject*,FXSelector,void*);
00137   long onQueryTip(FXObject*,FXSelector,void*);
00138   long onCmdBlending(FXObject*,FXSelector,void*);
00139   long onUpdBlending(FXObject*,FXSelector,void*);
00140   long onUpdSegColor(FXObject*,FXSelector,void*);
00141   long onCmdSegColor(FXObject*,FXSelector,void*);
00142   long onUpdRecenter(FXObject*,FXSelector,void*);
00143   long onCmdRecenter(FXObject*,FXSelector,void*);
00144   long onUpdSplit(FXObject*,FXSelector,void*);
00145   long onCmdSplit(FXObject*,FXSelector,void*);
00146   long onUpdMerge(FXObject*,FXSelector,void*);
00147   long onCmdMerge(FXObject*,FXSelector,void*);
00148   long onUpdUniform(FXObject*,FXSelector,void*);
00149   long onCmdUniform(FXObject*,FXSelector,void*);
00150 public:
00151   enum{
00152     ID_LOWER_COLOR=FXFrame::ID_LAST,
00153     ID_UPPER_COLOR,
00154     ID_BLEND_LINEAR,
00155     ID_BLEND_POWER,
00156     ID_BLEND_SINE,
00157     ID_BLEND_INCREASING,
00158     ID_BLEND_DECREASING,
00159     ID_RECENTER,
00160     ID_SPLIT,
00161     ID_MERGE,
00162     ID_UNIFORM,
00163     ID_LAST
00164     };
00165 public:
00166 
00167   /// Construct a gradient bar
00168   FXGradientBar(FXComposite* p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=FRAME_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);
00169 
00170   /// Create server-side resources
00171   virtual void create();
00172 
00173   /// Return default width
00174   virtual FXint getDefaultWidth();
00175 
00176   /// Return default height
00177   virtual FXint getDefaultHeight();
00178 
00179   /// Obtain segment containing location x, y
00180   FXint getSegment(FXint x,FXint y) const;
00181 
00182   /// Get the grip in segment sg which is closest to location x, y
00183   FXint getGrip(FXint sg,FXint x,FXint y) const;
00184 
00185   /// Return the number of segments
00186   FXint geNumSegments() const { return nsegs; }
00187 
00188   /// Change several the gradient segments
00189   void setGradients(const FXGradient *segments,FXint nsegments);
00190 
00191   /// Return the gradient segments
00192   void getGradients(FXGradient*& segments,FXint& nsegments) const;
00193 
00194   /// Change current segment
00195   void setCurrentSegment(FXint index,FXbool notify=FALSE);
00196 
00197   /// Return current segment, if any
00198   FXint getCurrentSegment() const { return current; }
00199 
00200   /// Change anchor segment
00201   void setAnchorSegment(FXint index);
00202 
00203   /// Return anchor segment, if any
00204   FXint getAnchorSegment() const { return anchor; }
00205 
00206   /// Select segment
00207   FXbool selectSegments(FXint fm,FXint to,FXbool notify=FALSE);
00208 
00209   // Deselect all segments
00210   FXbool deselectSegments(FXbool notify);
00211 
00212   /// Is segment selected
00213   FXbool isSegmentSelected(FXint s) const;
00214 
00215   /// Set colors of a segment
00216   void setSegmentLowerColor(FXint s,FXColor clr,FXbool notify=FALSE);
00217   void setSegmentUpperColor(FXint s,FXColor clr,FXbool notify=FALSE);
00218 
00219   /// Get colors of a segment
00220   FXColor getSegmentLowerColor(FXint s) const;
00221   FXColor getSegmentUpperColor(FXint s) const;
00222 
00223   /// Move lower point of segment sg
00224   void moveSegmentLower(FXint sg,FXdouble val,FXbool notify=FALSE);
00225 
00226   /// Move middle point of segment sg
00227   void moveSegmentMiddle(FXint sg,FXdouble val,FXbool notify=FALSE);
00228 
00229   /// Move upper point of segment sg
00230   void moveSegmentUpper(FXint sg,FXdouble val,FXbool notify=FALSE);
00231 
00232   /// Move segments sglo to sghi to new position val
00233   void moveSegments(FXint sglo,FXint sghi,FXdouble val,FXbool notify=FALSE);
00234 
00235   /// Get values of segment sg
00236   FXdouble getSegmentLower(FXint sg) const;
00237   FXdouble getSegmentMiddle(FXint sg) const;
00238   FXdouble getSegmentUpper(FXint sg) const;
00239 
00240   /// Get gradient ramp
00241   void gradient(FXColor *ramp,FXint nramp);
00242 
00243   /// Get blend cuve of segment
00244   FXuint getSegmentBlend(FXint s) const;
00245 
00246   /// Split segment at the midpoint
00247   void splitSegments(FXint sglo,FXint sghi,FXbool notify=FALSE);
00248 
00249   /// Merge segments
00250   void mergeSegments(FXint sglo,FXint sghi,FXbool notify=FALSE);
00251 
00252   /// Make segments uniformly distributed
00253   void uniformSegments(FXint sglo,FXint sghi,FXbool notify=FALSE);
00254 
00255   /// Change blend curve of segment
00256   void blendSegments(FXint sglo,FXint sghi,FXuint blend=GRADIENT_BLEND_LINEAR,FXbool notify=FALSE);
00257 
00258   /// Change the gradient bar style
00259   FXuint getBarStyle() const;
00260 
00261   /// Get the gradient bar style
00262   void setBarStyle(FXuint style);
00263 
00264   /// Set color
00265   void setSelectColor(FXColor clr);
00266 
00267   /// Get color
00268   FXColor getSelectColor() const { return selectColor; }
00269 
00270   /// Set status line help text for this gradient bar
00271   void setHelpText(const FXString& text){ help=text; }
00272 
00273   /// Get status line help text for this gradient bar
00274   const FXString& getHelpText() const { return help; }
00275 
00276   /// Set tool tip message for this gradient bar
00277   void setTipText(const FXString& text){ tip=text; }
00278 
00279   /// Get tool tip message for this gradient bar
00280   const FXString& getTipText() const { return tip; }
00281 
00282   /// Save gradient bar to a stream
00283   virtual void save(FXStream& store) const;
00284 
00285   /// Load gradient bar from a stream
00286   virtual void load(FXStream& store);
00287 
00288   virtual ~FXGradientBar();
00289   };
00290 
00291 
00292 }
00293 
00294 #endif