![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
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,2009 by Jeroen van der Zijp. 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: FXGradientBar.h,v 1.61 2009/01/06 13:07:24 fox Exp $ * 00022 ********************************************************************************/ 00023 #ifndef FXGRADIENTBAR_H 00024 #define FXGRADIENTBAR_H 00025 00026 #ifndef FXFRAME_H 00027 #include "FXFrame.h" 00028 #endif 00029 00030 00031 namespace FX { 00032 00033 00034 /// Gradient bar orientation 00035 enum { 00036 GRADIENTBAR_HORIZONTAL = 0, /// Gradient bar shown horizontally 00037 GRADIENTBAR_VERTICAL = 0x00008000, /// Gradient bar shown vertically 00038 GRADIENTBAR_NO_CONTROLS = 0, /// No controls shown 00039 GRADIENTBAR_CONTROLS_TOP = 0x00010000, /// Controls on top 00040 GRADIENTBAR_CONTROLS_BOTTOM = 0x00020000, /// Controls on bottom 00041 GRADIENTBAR_CONTROLS_LEFT = GRADIENTBAR_CONTROLS_TOP, /// Controls on left 00042 GRADIENTBAR_CONTROLS_RIGHT = GRADIENTBAR_CONTROLS_BOTTOM /// Controls on right 00043 }; 00044 00045 00046 /// Blend modes 00047 enum { 00048 GRADIENT_BLEND_LINEAR, /// Linear blend 00049 GRADIENT_BLEND_POWER, /// Power law blend 00050 GRADIENT_BLEND_SINE, /// Sine blend 00051 GRADIENT_BLEND_INCREASING, /// Quadratic increasing blend 00052 GRADIENT_BLEND_DECREASING /// Quadratic decreasing blend 00053 }; 00054 00055 00056 // Gradient segment 00057 struct FXGradient { 00058 FXdouble lower; /// Lower value 00059 FXdouble middle; /// Middle value 00060 FXdouble upper; /// Upper value 00061 FXColor lowerColor; /// Lower color 00062 FXColor upperColor; /// Upper color 00063 FXuchar blend; /// Blend method 00064 }; 00065 00066 00067 class FXImage; 00068 00069 00070 /** 00071 * The gradient bar is a control that is used to edit color gradient, 00072 * such as used in texture mapping and shape filling. 00073 */ 00074 class FXAPI FXGradientBar : public FXFrame { 00075 FXDECLARE(FXGradientBar) 00076 protected: 00077 FXImage *bar; // Image containing colors 00078 FXGradient *seg; // Segments 00079 FXint nsegs; // Number of segments 00080 FXint sellower; // Lower selected segment 00081 FXint selupper; // Upper selected segment 00082 FXint dropped; // Dropped segment 00083 FXint current; // Current segment 00084 FXint anchor; // Anchor segment 00085 FXint grip; // Grip being dragged, if any 00086 FXint where; // Where dropped in segment 00087 FXint barsize; // Bar size 00088 FXint controlsize; // Size of control 00089 FXColor selectColor; // Select color 00090 FXString tip; // Tooltip value 00091 FXString help; // Help value 00092 FXint offset; // Offset 00093 protected: 00094 FXGradientBar(); 00095 void updatebar(); 00096 FXdouble getValue(FXint x,FXint y) const; 00097 FXint getSegmentLowerPos(FXint sg) const; 00098 FXint getSegmentUpperPos(FXint sg) const; 00099 FXint getSegmentMiddlePos(FXint sg) const; 00100 void drawUpArrow(FXDCWindow& dc,FXint x,FXint y,FXColor clr); 00101 void drawDnArrow(FXDCWindow& dc,FXint x,FXint y,FXColor clr); 00102 void drawRtArrow(FXDCWindow& dc,FXint x,FXint y,FXColor clr); 00103 void drawLtArrow(FXDCWindow& dc,FXint x,FXint y,FXColor clr); 00104 void drawBottomArrows(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h); 00105 void drawTopArrows(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h); 00106 void drawLeftArrows(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h); 00107 void drawRightArrows(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h); 00108 static FXdouble blendlinear(FXdouble middle,FXdouble pos); 00109 static FXdouble blendpower(FXdouble middle,FXdouble pos); 00110 static FXdouble blendsine(FXdouble middle,FXdouble pos); 00111 static FXdouble blendincreasing(FXdouble middle,FXdouble pos); 00112 static FXdouble blenddecreasing(FXdouble middle,FXdouble pos); 00113 static const FXGradient defaultGradient[3]; 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 onMotion(FXObject*,FXSelector,void*); 00129 long onLeftBtnPress(FXObject*,FXSelector,void*); 00130 long onLeftBtnRelease(FXObject*,FXSelector,void*); 00131 long onRightBtnPress(FXObject*,FXSelector,void*); 00132 long onRightBtnRelease(FXObject*,FXSelector,void*); 00133 long onDNDEnter(FXObject*,FXSelector,void*); 00134 long onDNDLeave(FXObject*,FXSelector,void*); 00135 long onDNDMotion(FXObject*,FXSelector,void*); 00136 long onDNDDrop(FXObject*,FXSelector,void*); 00137 long onCmdBlending(FXObject*,FXSelector,void*); 00138 long onUpdBlending(FXObject*,FXSelector,void*); 00139 long onUpdSegColor(FXObject*,FXSelector,void*); 00140 long onCmdSegColor(FXObject*,FXSelector,void*); 00141 long onUpdRecenter(FXObject*,FXSelector,void*); 00142 long onCmdRecenter(FXObject*,FXSelector,void*); 00143 long onUpdSplit(FXObject*,FXSelector,void*); 00144 long onCmdSplit(FXObject*,FXSelector,void*); 00145 long onUpdMerge(FXObject*,FXSelector,void*); 00146 long onCmdMerge(FXObject*,FXSelector,void*); 00147 long onUpdUniform(FXObject*,FXSelector,void*); 00148 long onCmdUniform(FXObject*,FXSelector,void*); 00149 long onCmdReset(FXObject*,FXSelector,void*); 00150 long onCmdSetHelp(FXObject*,FXSelector,void*); 00151 long onCmdGetHelp(FXObject*,FXSelector,void*); 00152 long onCmdSetTip(FXObject*,FXSelector,void*); 00153 long onCmdGetTip(FXObject*,FXSelector,void*); 00154 long onQueryHelp(FXObject*,FXSelector,void*); 00155 long onQueryTip(FXObject*,FXSelector,void*); 00156 public: 00157 enum{ 00158 ID_LOWER_COLOR=FXFrame::ID_LAST, 00159 ID_UPPER_COLOR, 00160 ID_BLEND_LINEAR, 00161 ID_BLEND_POWER, 00162 ID_BLEND_SINE, 00163 ID_BLEND_INCREASING, 00164 ID_BLEND_DECREASING, 00165 ID_RECENTER, 00166 ID_SPLIT, 00167 ID_MERGE, 00168 ID_UNIFORM, 00169 ID_RESET, 00170 ID_LAST 00171 }; 00172 public: 00173 00174 /// Construct a gradient bar 00175 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); 00176 00177 /// Create server-side resources 00178 virtual void create(); 00179 00180 /// Perform layout 00181 virtual void layout(); 00182 00183 /// Return default width 00184 virtual FXint getDefaultWidth(); 00185 00186 /// Return default height 00187 virtual FXint getDefaultHeight(); 00188 00189 /** 00190 * Obtain segment containing location x, y. 00191 * Returns -1 if no matching segment was found. 00192 */ 00193 FXint getSegment(FXint x,FXint y) const; 00194 00195 /** 00196 * Get the grip in segment sg which is closest to location (x, y), 00197 * one of GRIP_LOWER, GRIP_SEG_LOWER, GRIP_MIDDLE, GRIP_SEG_UPPER, 00198 * GRIP_UPPER or GRIP_NONE. 00199 */ 00200 FXint getGrip(FXint sg,FXint x,FXint y) const; 00201 00202 /// Return the number of segments 00203 FXint getNumSegments() const { return nsegs; } 00204 00205 /** 00206 * Reset gradients to default color ramp. 00207 */ 00208 void resetGradients(); 00209 00210 /** 00211 * Replace the current gradient segments. 00212 * The gradient bar makes a copy of the input segments array. 00213 */ 00214 void setGradients(const FXGradient *segments,FXint nsegments); 00215 00216 /** 00217 * Return a copy of the gradient segments. 00218 * The array of segments is allocated using FXMALLOC and should be freed 00219 * by the caller using FXFREE. 00220 */ 00221 void getGradients(FXGradient*& segments,FXint& nsegments) const; 00222 00223 /// Change current segment 00224 void setCurrentSegment(FXint index,FXbool notify=false); 00225 00226 /// Return current segment, or -1 if there is no current segment 00227 FXint getCurrentSegment() const { return current; } 00228 00229 /// Change anchor segment 00230 void setAnchorSegment(FXint index); 00231 00232 /// Return anchor segment, or -1 if there is no anchor segment 00233 FXint getAnchorSegment() const { return anchor; } 00234 00235 /// Select segment(s) 00236 FXbool selectSegments(FXint fm,FXint to,FXbool notify=false); 00237 00238 /// Deselect all segments 00239 FXbool deselectSegments(FXbool notify=false); 00240 00241 /// Returns TRUE if the specified segment is selected 00242 FXbool isSegmentSelected(FXint s) const; 00243 00244 /// Set lower color of a segment 00245 void setSegmentLowerColor(FXint s,FXColor clr,FXbool notify=false); 00246 00247 /// Set upper color of a segment 00248 void setSegmentUpperColor(FXint s,FXColor clr,FXbool notify=false); 00249 00250 /// Get lower color of a segment 00251 FXColor getSegmentLowerColor(FXint s) const; 00252 00253 /// Get upper color of a segment 00254 FXColor getSegmentUpperColor(FXint s) const; 00255 00256 /// Move lower point of segment sg 00257 void moveSegmentLower(FXint sg,FXdouble val,FXbool notify=false); 00258 00259 /// Move middle point of segment sg 00260 void moveSegmentMiddle(FXint sg,FXdouble val,FXbool notify=false); 00261 00262 /// Move upper point of segment sg 00263 void moveSegmentUpper(FXint sg,FXdouble val,FXbool notify=false); 00264 00265 /// Move segments sglo to sghi to new position val 00266 void moveSegments(FXint sglo,FXint sghi,FXdouble val,FXbool notify=false); 00267 00268 /// Get lower value of segment sg 00269 FXdouble getSegmentLower(FXint sg) const; 00270 00271 /// Get middle value of segment sg 00272 FXdouble getSegmentMiddle(FXint sg) const; 00273 00274 /// Get upper value of segment sg 00275 FXdouble getSegmentUpper(FXint sg) const; 00276 00277 /** 00278 * Get gradient ramp. 00279 * The ramp argument should be an array of size nramp, which will be 00280 * filled with the appropriate color values. 00281 */ 00282 void gradient(FXColor *ramp,FXint nramp); 00283 00284 /** 00285 * Get blend mode of segment, one of GRADIENT_BLEND_LINEAR, 00286 * GRADIENT_BLEND_POWER, GRADIENT_BLEND_SINE, GRADIENT_BLEND_INCREASING, 00287 * or GRADIENT_BLEND_DECREASING. 00288 */ 00289 FXuint getSegmentBlend(FXint s) const; 00290 00291 /// Split segment at the midpoint 00292 void splitSegments(FXint sglo,FXint sghi,FXbool notify=false); 00293 00294 /// Merge segments 00295 void mergeSegments(FXint sglo,FXint sghi,FXbool notify=false); 00296 00297 /// Make segments uniformly distributed 00298 void uniformSegments(FXint sglo,FXint sghi,FXbool notify=false); 00299 00300 /// Change blend mode of segment 00301 void blendSegments(FXint sglo,FXint sghi,FXuint blend=GRADIENT_BLEND_LINEAR,FXbool notify=false); 00302 00303 /// Change control size 00304 void setControlSize(FXint cs); 00305 00306 /// Get control size 00307 FXint getControlSize() const { return controlsize; } 00308 00309 /// Change bar size 00310 void setBarSize(FXint bs); 00311 00312 /// Get bar size 00313 FXint getBarSize() const { return barsize; } 00314 00315 /// Get the gradient bar style 00316 FXuint getBarStyle() const; 00317 00318 /// Change the gradient bar style 00319 void setBarStyle(FXuint style); 00320 00321 /// Set color 00322 void setSelectColor(FXColor clr); 00323 00324 /// Get color 00325 FXColor getSelectColor() const { return selectColor; } 00326 00327 /// Set status line help text for this gradient bar 00328 void setHelpText(const FXString& text){ help=text; } 00329 00330 /// Get status line help text for this gradient bar 00331 const FXString& getHelpText() const { return help; } 00332 00333 /// Set tool tip message for this gradient bar 00334 void setTipText(const FXString& text){ tip=text; } 00335 00336 /// Get tool tip message for this gradient bar 00337 const FXString& getTipText() const { return tip; } 00338 00339 /// Save gradient bar to a stream 00340 virtual void save(FXStream& store) const; 00341 00342 /// Load gradient bar from a stream 00343 virtual void load(FXStream& store); 00344 00345 /// Destructor 00346 virtual ~FXGradientBar(); 00347 }; 00348 00349 00350 } 00351 00352 #endif
![]() |