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

FXGradientBar.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * G r a d i e n t B a r W i d g e t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2002,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXGradientBar.h,v 1.52 2006/01/22 17:58:04 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXGRADIENTBAR_H
25 #define FXGRADIENTBAR_H
26 
27 #ifndef FXFRAME_H
28 #include "FXFrame.h"
29 #endif
30 
31 
32 namespace FX {
33 
34 
35 
36 /// Gradient bar orientation
37 enum {
38  GRADIENTBAR_HORIZONTAL = 0, /// Gradient bar shown horizontally
39  GRADIENTBAR_VERTICAL = 0x00008000, /// Gradient bar shown vertically
40  GRADIENTBAR_NO_CONTROLS = 0, /// No controls shown
41  GRADIENTBAR_CONTROLS_TOP = 0x00010000, /// Controls on top
42  GRADIENTBAR_CONTROLS_BOTTOM = 0x00020000, /// Controls on bottom
45  };
46 
47 
48 /// Blend modes
49 enum {
50  GRADIENT_BLEND_LINEAR, /// Linear blend
51  GRADIENT_BLEND_POWER, /// Power law blend
52  GRADIENT_BLEND_SINE, /// Sine blend
53  GRADIENT_BLEND_INCREASING, /// Quadratic increasing blend
54  GRADIENT_BLEND_DECREASING /// Quadratic decreasing blend
55  };
56 
57 
58 
59 // Gradient segment
60 struct FXGradient {
61  FXdouble lower; /// Lower value
62  FXdouble middle; /// Middle value
63  FXdouble upper; /// Upper value
64  FXColor lowerColor; /// Lower color
65  FXColor upperColor; /// Upper color
66  FXuchar blend; /// Blend method
67  };
68 
69 
70 class FXImage;
71 
72 
73 /**
74 * The gradient bar is a control that is used to edit color gradient,
75 * such as used in texture mapping and shape filling.
76 */
77 class FXAPI FXGradientBar : public FXFrame {
79 protected:
80  FXImage *bar; // Image containing colors
81  FXGradient *seg; // Segments
82  FXint nsegs; // Number of segments
83  FXint sellower; // Lower selected segment
84  FXint selupper; // Upper selected segment
85  FXint dropped; // Dropped segment
86  FXint current; // Current segment
87  FXint anchor; // Anchor segment
88  FXint grip; // Grip being dragged, if any
89  FXint where; // Where dropped in segment
90  FXString tip; // Tooltip value
91  FXString help; // Help value
92  FXColor selectColor; // Select color
93  FXint offset; // Offset
94 protected:
95  FXGradientBar();
96  void updatebar();
97  FXdouble getValue(FXint x,FXint y) const;
98  FXint getSegmentLowerPos(FXint sg) const;
99  FXint getSegmentUpperPos(FXint sg) const;
100  FXint getSegmentMiddlePos(FXint sg) const;
101  void drawUpArrow(FXDCWindow& dc,FXint x,FXint y,FXColor clr);
102  void drawDnArrow(FXDCWindow& dc,FXint x,FXint y,FXColor clr);
103  void drawRtArrow(FXDCWindow& dc,FXint x,FXint y,FXColor clr);
104  void drawLtArrow(FXDCWindow& dc,FXint x,FXint y,FXColor clr);
105  void drawBottomArrows(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
106  void drawTopArrows(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
107  void drawLeftArrows(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
108  void drawRightArrows(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
109  static FXdouble blendlinear(FXdouble middle,FXdouble pos);
110  static FXdouble blendpower(FXdouble middle,FXdouble pos);
111  static FXdouble blendsine(FXdouble middle,FXdouble pos);
112  static FXdouble blendincreasing(FXdouble middle,FXdouble pos);
113  static FXdouble blenddecreasing(FXdouble middle,FXdouble pos);
114 private:
116  FXGradientBar &operator=(const FXGradientBar&);
117 public:
118  enum {
119  GRIP_NONE,
120  GRIP_LOWER,
121  GRIP_SEG_LOWER,
122  GRIP_MIDDLE,
123  GRIP_SEG_UPPER,
124  GRIP_UPPER
125  };
126 public:
127  long onPaint(FXObject*,FXSelector,void*);
128  long onLeftBtnPress(FXObject*,FXSelector,void*);
129  long onLeftBtnRelease(FXObject*,FXSelector,void*);
130  long onMotion(FXObject*,FXSelector,void*);
131  long onDNDEnter(FXObject*,FXSelector,void*);
132  long onDNDLeave(FXObject*,FXSelector,void*);
133  long onDNDMotion(FXObject*,FXSelector,void*);
134  long onDNDDrop(FXObject*,FXSelector,void*);
135  long onCmdBlending(FXObject*,FXSelector,void*);
136  long onUpdBlending(FXObject*,FXSelector,void*);
137  long onUpdSegColor(FXObject*,FXSelector,void*);
138  long onCmdSegColor(FXObject*,FXSelector,void*);
139  long onUpdRecenter(FXObject*,FXSelector,void*);
140  long onCmdRecenter(FXObject*,FXSelector,void*);
141  long onUpdSplit(FXObject*,FXSelector,void*);
142  long onCmdSplit(FXObject*,FXSelector,void*);
143  long onUpdMerge(FXObject*,FXSelector,void*);
144  long onCmdMerge(FXObject*,FXSelector,void*);
145  long onUpdUniform(FXObject*,FXSelector,void*);
146  long onCmdUniform(FXObject*,FXSelector,void*);
147  long onCmdSetHelp(FXObject*,FXSelector,void*);
148  long onCmdGetHelp(FXObject*,FXSelector,void*);
149  long onCmdSetTip(FXObject*,FXSelector,void*);
150  long onCmdGetTip(FXObject*,FXSelector,void*);
151  long onQueryHelp(FXObject*,FXSelector,void*);
152  long onQueryTip(FXObject*,FXSelector,void*);
153 public:
154  enum{
155  ID_LOWER_COLOR=FXFrame::ID_LAST,
156  ID_UPPER_COLOR,
157  ID_BLEND_LINEAR,
158  ID_BLEND_POWER,
159  ID_BLEND_SINE,
160  ID_BLEND_INCREASING,
161  ID_BLEND_DECREASING,
162  ID_RECENTER,
163  ID_SPLIT,
164  ID_MERGE,
165  ID_UNIFORM,
166  ID_LAST
167  };
168 public:
169 
170  /// Construct a gradient bar
172 
173  /// Create server-side resources
174  virtual void create();
175 
176  /// Perform layout
177  virtual void layout();
178 
179  /// Return default width
180  virtual FXint getDefaultWidth();
181 
182  /// Return default height
183  virtual FXint getDefaultHeight();
185  /**
186  * Obtain segment containing location x, y.
187  * Returns -1 if no matching segment was found.
188  */
189  FXint getSegment(FXint x,FXint y) const;
191  /**
192  * Get the grip in segment sg which is closest to location (x, y),
193  * one of GRIP_LOWER, GRIP_SEG_LOWER, GRIP_MIDDLE, GRIP_SEG_UPPER,
194  * GRIP_UPPER or GRIP_NONE.
195  */
196  FXint getGrip(FXint sg,FXint x,FXint y) const;
197 
198  /// Return the number of segments
199  FXint getNumSegments() const { return nsegs; }
200 
201  /**
202  * Replace the current gradient segments.
203  * The gradient bar makes a copy of the input segments array.
204  */
205  void setGradients(const FXGradient *segments,FXint nsegments);
206 
207  /**
208  * Return a copy of the gradient segments.
209  * The array of segments is allocated using FXMALLOC and should be freed
210  * by the caller using FXFREE.
211  */
212  void getGradients(FXGradient*& segments,FXint& nsegments) const;
213 
214  /// Change current segment
215  void setCurrentSegment(FXint index,FXbool notify=FALSE);
216 
217  /// Return current segment, or -1 if there is no current segment
218  FXint getCurrentSegment() const { return current; }
219 
220  /// Change anchor segment
221  void setAnchorSegment(FXint index);
222 
223  /// Return anchor segment, or -1 if there is no anchor segment
224  FXint getAnchorSegment() const { return anchor; }
225 
226  /// Select segment(s)
227  FXbool selectSegments(FXint fm,FXint to,FXbool notify=FALSE);
228 
229  /// Deselect all segments
230  FXbool deselectSegments(FXbool notify);
231 
232  /// Returns TRUE if the specified segment is selected
233  FXbool isSegmentSelected(FXint s) const;
234 
235  /// Set lower color of a segment
236  void setSegmentLowerColor(FXint s,FXColor clr,FXbool notify=FALSE);
237 
238  /// Set upper color of a segment
239  void setSegmentUpperColor(FXint s,FXColor clr,FXbool notify=FALSE);
240 
241  /// Get lower color of a segment
242  FXColor getSegmentLowerColor(FXint s) const;
243 
244  /// Get upper color of a segment
245  FXColor getSegmentUpperColor(FXint s) const;
246 
247  /// Move lower point of segment sg
248  void moveSegmentLower(FXint sg,FXdouble val,FXbool notify=FALSE);
249 
250  /// Move middle point of segment sg
251  void moveSegmentMiddle(FXint sg,FXdouble val,FXbool notify=FALSE);
252 
253  /// Move upper point of segment sg
254  void moveSegmentUpper(FXint sg,FXdouble val,FXbool notify=FALSE);
255 
256  /// Move segments sglo to sghi to new position val
257  void moveSegments(FXint sglo,FXint sghi,FXdouble val,FXbool notify=FALSE);
258 
259  /// Get lower value of segment sg
260  FXdouble getSegmentLower(FXint sg) const;
261 
262  /// Get middle value of segment sg
263  FXdouble getSegmentMiddle(FXint sg) const;
264 
265  /// Get upper value of segment sg
266  FXdouble getSegmentUpper(FXint sg) const;
267 
268  /**
269  * Get gradient ramp.
270  * The ramp argument should be an array of size nramp, which will be
271  * filled with the appropriate color values.
272  */
273  void gradient(FXColor *ramp,FXint nramp);
274 
275  /**
276  * Get blend mode of segment, one of GRADIENT_BLEND_LINEAR,
277  * GRADIENT_BLEND_POWER, GRADIENT_BLEND_SINE, GRADIENT_BLEND_INCREASING,
278  * or GRADIENT_BLEND_DECREASING.
279  */
280  FXuint getSegmentBlend(FXint s) const;
281 
282  /// Split segment at the midpoint
283  void splitSegments(FXint sglo,FXint sghi,FXbool notify=FALSE);
284 
285  /// Merge segments
286  void mergeSegments(FXint sglo,FXint sghi,FXbool notify=FALSE);
287 
288  /// Make segments uniformly distributed
289  void uniformSegments(FXint sglo,FXint sghi,FXbool notify=FALSE);
290 
291  /// Change blend mode of segment
292  void blendSegments(FXint sglo,FXint sghi,FXuint blend=GRADIENT_BLEND_LINEAR,FXbool notify=FALSE);
293 
294  /// Get the gradient bar style
295  FXuint getBarStyle() const;
296 
297  /// Change the gradient bar style
298  void setBarStyle(FXuint style);
299 
300  /// Set color
301  void setSelectColor(FXColor clr);
302 
303  /// Get color
304  FXColor getSelectColor() const { return selectColor; }
305 
306  /// Set status line help text for this gradient bar
307  void setHelpText(const FXString& text){ help=text; }
308 
309  /// Get status line help text for this gradient bar
310  const FXString& getHelpText() const { return help; }
311 
312  /// Set tool tip message for this gradient bar
313  void setTipText(const FXString& text){ tip=text; }
314 
315  /// Get tool tip message for this gradient bar
316  const FXString& getTipText() const { return tip; }
317 
318  /// Save gradient bar to a stream
319  virtual void save(FXStream& store) const;
320 
321  /// Load gradient bar from a stream
322  virtual void load(FXStream& store);
323 
324  /// Destructor
325  virtual ~FXGradientBar();
326  };
327 
328 
329 }
330 
331 #endif
Gradient bar shown horizontally.
Definition: FXGradientBar.h:41
No controls shown.
Definition: FXGradientBar.h:43
Linear blend.
Definition: FXGradientBar.h:57
The Frame widget provides borders around some contents.
Definition: FXFrame.h:73
Definition: FXWindow.h:241
unsigned int FXuint
Definition: fxdefs.h:389
Definition: FXFrame.h:56
FXuint FXSelector
Association key.
Definition: FXObject.h:53
#define FXAPI
Definition: fxdefs.h:122
Quadratic decreasing blend.
Definition: FXGradientBar.h:61
FXuchar FXbool
Definition: fxdefs.h:386
Base composite.
Definition: FXComposite.h:35
Controls on top.
Definition: FXGradientBar.h:44
#define NULL
Definition: fxdefs.h:41
FXuint FXColor
Definition: fxdefs.h:447
Controls on right.
Definition: FXGradientBar.h:47
FXColor lowerColor
Upper value.
Definition: FXGradientBar.h:72
double FXdouble
Definition: fxdefs.h:392
FXColor upperColor
Lower color.
Definition: FXGradientBar.h:73
The gradient bar is a control that is used to edit color gradient, such as used in texture mapping an...
Definition: FXGradientBar.h:89
Definition: FX4Splitter.h:31
int FXint
Definition: fxdefs.h:390
Definition: FXGradientBar.h:68
FXdouble upper
Middle value.
Definition: FXGradientBar.h:71
Gradient bar shown vertically.
Definition: FXGradientBar.h:42
#define FALSE
Definition: fxdefs.h:35
FXuchar blend
Upper color.
Definition: FXGradientBar.h:74
Regular raised/thick border.
Definition: FXWindow.h:82
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:166
unsigned char FXuchar
Definition: fxdefs.h:385
Controls on left.
Definition: FXGradientBar.h:46
Window Device Context.
Definition: FXDCWindow.h:52
An Image is a rectangular array of pixels.
Definition: FXImage.h:67
FXdouble lower
Definition: FXGradientBar.h:69
FXdouble middle
Lower value.
Definition: FXGradientBar.h:70
Sine blend.
Definition: FXGradientBar.h:59
Power law blend.
Definition: FXGradientBar.h:58
#define FXDECLARE(classname)
Macro to set up class declaration.
Definition: FXObject.h:92
Controls on bottom.
Definition: FXGradientBar.h:45
Quadratic increasing blend.
Definition: FXGradientBar.h:60
FXString provides essential string manipulation capabilities.
Definition: FXString.h:33

Copyright © 1997-2005 Jeroen van der Zijp