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,2004 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.48 2004/02/08 17:17:33 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 FXAPI 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 FXdouble getValue(FXint x,FXint y) const; 00098 FXint getSegmentLowerPos(FXint sg) const; 00099 FXint getSegmentUpperPos(FXint sg) const; 00100 FXint getSegmentMiddlePos(FXint sg) const; 00101 void drawUpArrow(FXDCWindow& dc,FXint x,FXint y,FXColor clr); 00102 void drawDnArrow(FXDCWindow& dc,FXint x,FXint y,FXColor clr); 00103 void drawRtArrow(FXDCWindow& dc,FXint x,FXint y,FXColor clr); 00104 void drawLtArrow(FXDCWindow& dc,FXint x,FXint y,FXColor clr); 00105 void drawBottomArrows(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h); 00106 void drawTopArrows(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h); 00107 void drawLeftArrows(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h); 00108 void drawRightArrows(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h); 00109 static FXdouble blendlinear(FXdouble middle,FXdouble pos); 00110 static FXdouble blendpower(FXdouble middle,FXdouble pos); 00111 static FXdouble blendsine(FXdouble middle,FXdouble pos); 00112 static FXdouble blendincreasing(FXdouble middle,FXdouble pos); 00113 static FXdouble blenddecreasing(FXdouble middle,FXdouble pos); 00114 private: 00115 FXGradientBar(const FXGradientBar&); 00116 FXGradientBar &operator=(const FXGradientBar&); 00117 public: 00118 enum { 00119 GRIP_NONE, 00120 GRIP_LOWER, 00121 GRIP_SEG_LOWER, 00122 GRIP_MIDDLE, 00123 GRIP_SEG_UPPER, 00124 GRIP_UPPER 00125 }; 00126 public: 00127 long onPaint(FXObject*,FXSelector,void*); 00128 long onLeftBtnPress(FXObject*,FXSelector,void*); 00129 long onLeftBtnRelease(FXObject*,FXSelector,void*); 00130 long onMotion(FXObject*,FXSelector,void*); 00131 long onDNDEnter(FXObject*,FXSelector,void*); 00132 long onDNDLeave(FXObject*,FXSelector,void*); 00133 long onDNDMotion(FXObject*,FXSelector,void*); 00134 long onDNDDrop(FXObject*,FXSelector,void*); 00135 long onCmdBlending(FXObject*,FXSelector,void*); 00136 long onUpdBlending(FXObject*,FXSelector,void*); 00137 long onUpdSegColor(FXObject*,FXSelector,void*); 00138 long onCmdSegColor(FXObject*,FXSelector,void*); 00139 long onUpdRecenter(FXObject*,FXSelector,void*); 00140 long onCmdRecenter(FXObject*,FXSelector,void*); 00141 long onUpdSplit(FXObject*,FXSelector,void*); 00142 long onCmdSplit(FXObject*,FXSelector,void*); 00143 long onUpdMerge(FXObject*,FXSelector,void*); 00144 long onCmdMerge(FXObject*,FXSelector,void*); 00145 long onUpdUniform(FXObject*,FXSelector,void*); 00146 long onCmdUniform(FXObject*,FXSelector,void*); 00147 long onCmdSetHelp(FXObject*,FXSelector,void*); 00148 long onCmdGetHelp(FXObject*,FXSelector,void*); 00149 long onCmdSetTip(FXObject*,FXSelector,void*); 00150 long onCmdGetTip(FXObject*,FXSelector,void*); 00151 long onQueryHelp(FXObject*,FXSelector,void*); 00152 long onQueryTip(FXObject*,FXSelector,void*); 00153 public: 00154 enum{ 00155 ID_LOWER_COLOR=FXFrame::ID_LAST, 00156 ID_UPPER_COLOR, 00157 ID_BLEND_LINEAR, 00158 ID_BLEND_POWER, 00159 ID_BLEND_SINE, 00160 ID_BLEND_INCREASING, 00161 ID_BLEND_DECREASING, 00162 ID_RECENTER, 00163 ID_SPLIT, 00164 ID_MERGE, 00165 ID_UNIFORM, 00166 ID_LAST 00167 }; 00168 public: 00169 00170 /// Construct a gradient bar 00171 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); 00172 00173 /// Create server-side resources 00174 virtual void create(); 00175 00176 /// Perform layout 00177 virtual void layout(); 00178 00179 /// Return default width 00180 virtual FXint getDefaultWidth(); 00181 00182 /// Return default height 00183 virtual FXint getDefaultHeight(); 00184 00185 /** 00186 * Obtain segment containing location x, y. 00187 * Returns -1 if no matching segment was found. 00188 */ 00189 FXint getSegment(FXint x,FXint y) const; 00190 00191 /** 00192 * Get the grip in segment sg which is closest to location (x, y), 00193 * one of GRIP_LOWER, GRIP_SEG_LOWER, GRIP_MIDDLE, GRIP_SEG_UPPER, 00194 * GRIP_UPPER or GRIP_NONE. 00195 */ 00196 FXint getGrip(FXint sg,FXint x,FXint y) const; 00197 00198 /// Return the number of segments 00199 FXint getNumSegments() const { return nsegs; } 00200 00201 /** 00202 * Replace the current gradient segments. 00203 * The gradient bar makes a copy of the input segments array. 00204 */ 00205 void setGradients(const FXGradient *segments,FXint nsegments); 00206 00207 /** 00208 * Return a copy of the gradient segments. 00209 * The array of segments is allocated using FXMALLOC and should be freed 00210 * by the caller using FXFREE. 00211 */ 00212 void getGradients(FXGradient*& segments,FXint& nsegments) const; 00213 00214 /// Change current segment 00215 void setCurrentSegment(FXint index,FXbool notify=FALSE); 00216 00217 /// Return current segment, or -1 if there is no current segment 00218 FXint getCurrentSegment() const { return current; } 00219 00220 /// Change anchor segment 00221 void setAnchorSegment(FXint index); 00222 00223 /// Return anchor segment, or -1 if there is no anchor segment 00224 FXint getAnchorSegment() const { return anchor; } 00225 00226 /// Select segment(s) 00227 FXbool selectSegments(FXint fm,FXint to,FXbool notify=FALSE); 00228 00229 // Deselect all segments 00230 FXbool deselectSegments(FXbool notify); 00231 00232 /// Returns TRUE if the specified segment is selected 00233 FXbool isSegmentSelected(FXint s) const; 00234 00235 /// Set lower color of a segment 00236 void setSegmentLowerColor(FXint s,FXColor clr,FXbool notify=FALSE); 00237 00238 /// Set upper color of a segment 00239 void setSegmentUpperColor(FXint s,FXColor clr,FXbool notify=FALSE); 00240 00241 /// Get lower color of a segment 00242 FXColor getSegmentLowerColor(FXint s) const; 00243 00244 /// Get upper color of a segment 00245 FXColor getSegmentUpperColor(FXint s) const; 00246 00247 /// Move lower point of segment sg 00248 void moveSegmentLower(FXint sg,FXdouble val,FXbool notify=FALSE); 00249 00250 /// Move middle point of segment sg 00251 void moveSegmentMiddle(FXint sg,FXdouble val,FXbool notify=FALSE); 00252 00253 /// Move upper point of segment sg 00254 void moveSegmentUpper(FXint sg,FXdouble val,FXbool notify=FALSE); 00255 00256 /// Move segments sglo to sghi to new position val 00257 void moveSegments(FXint sglo,FXint sghi,FXdouble val,FXbool notify=FALSE); 00258 00259 /// Get lower value of segment sg 00260 FXdouble getSegmentLower(FXint sg) const; 00261 00262 /// Get middle value of segment sg 00263 FXdouble getSegmentMiddle(FXint sg) const; 00264 00265 /// Get upper value of segment sg 00266 FXdouble getSegmentUpper(FXint sg) const; 00267 00268 /** 00269 * Get gradient ramp. 00270 * The ramp argument should be an array of size nramp, which will be 00271 * filled with the appropriate color values. 00272 */ 00273 void gradient(FXColor *ramp,FXint nramp); 00274 00275 /** 00276 * Get blend mode of segment, one of GRADIENT_BLEND_LINEAR, 00277 * GRADIENT_BLEND_POWER, GRADIENT_BLEND_SINE, GRADIENT_BLEND_INCREASING, 00278 * or GRADIENT_BLEND_DECREASING. 00279 */ 00280 FXuint getSegmentBlend(FXint s) const; 00281 00282 /// Split segment at the midpoint 00283 void splitSegments(FXint sglo,FXint sghi,FXbool notify=FALSE); 00284 00285 /// Merge segments 00286 void mergeSegments(FXint sglo,FXint sghi,FXbool notify=FALSE); 00287 00288 /// Make segments uniformly distributed 00289 void uniformSegments(FXint sglo,FXint sghi,FXbool notify=FALSE); 00290 00291 /// Change blend mode of segment 00292 void blendSegments(FXint sglo,FXint sghi,FXuint blend=GRADIENT_BLEND_LINEAR,FXbool notify=FALSE); 00293 00294 /// Get the gradient bar style 00295 FXuint getBarStyle() const; 00296 00297 /// Change the gradient bar style 00298 void setBarStyle(FXuint style); 00299 00300 /// Set color 00301 void setSelectColor(FXColor clr); 00302 00303 /// Get color 00304 FXColor getSelectColor() const { return selectColor; } 00305 00306 /// Set status line help text for this gradient bar 00307 void setHelpText(const FXString& text){ help=text; } 00308 00309 /// Get status line help text for this gradient bar 00310 FXString getHelpText() const { return help; } 00311 00312 /// Set tool tip message for this gradient bar 00313 void setTipText(const FXString& text){ tip=text; } 00314 00315 /// Get tool tip message for this gradient bar 00316 FXString getTipText() const { return tip; } 00317 00318 /// Save gradient bar to a stream 00319 virtual void save(FXStream& store) const; 00320 00321 /// Load gradient bar from a stream 00322 virtual void load(FXStream& store); 00323 00324 /// Destructor 00325 virtual ~FXGradientBar(); 00326 }; 00327 00328 00329 } 00330 00331 #endif

Copyright © 1997-2004 Jeroen van der Zijp