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

FXGradientBar.h
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,2022 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (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 *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXGRADIENTBAR_H
22 #define FXGRADIENTBAR_H
23 
24 #ifndef FXFRAME_H
25 #include "FXFrame.h"
26 #endif
27 
28 namespace FX {
29 
30 
32 enum {
33  GRADIENTBAR_HORIZONTAL = 0,
34  GRADIENTBAR_VERTICAL = 0x00008000,
35  GRADIENTBAR_NO_CONTROLS = 0,
36  GRADIENTBAR_CONTROLS_TOP = 0x00010000,
37  GRADIENTBAR_CONTROLS_BOTTOM = 0x00020000,
38  GRADIENTBAR_CONTROLS_LEFT = GRADIENTBAR_CONTROLS_TOP,
39  GRADIENTBAR_CONTROLS_RIGHT = GRADIENTBAR_CONTROLS_BOTTOM
40  };
41 
42 
44 enum {
45  GRADIENT_BLEND_LINEAR,
46  GRADIENT_BLEND_POWER,
47  GRADIENT_BLEND_SINE,
48  GRADIENT_BLEND_INCREASING,
49  GRADIENT_BLEND_DECREASING
50  };
51 
52 
53 // Gradient segment
54 struct FXGradient {
55  FXdouble lower;
56  FXdouble middle;
57  FXdouble upper;
58  FXColor lowerColor;
59  FXColor upperColor;
60  FXuchar blend;
61  };
62 
63 
64 class FXImage;
65 
66 
71 class FXAPI FXGradientBar : public FXFrame {
72  FXDECLARE(FXGradientBar)
73 protected:
74  FXImage *bar; // Image containing colors
75  FXGradient *seg; // Segments
76  FXint nsegs; // Number of segments
77  FXint sellower; // Lower selected segment
78  FXint selupper; // Upper selected segment
79  FXint dropped; // Dropped segment
80  FXint current; // Current segment
81  FXint anchor; // Anchor segment
82  FXint grip; // Grip being dragged, if any
83  FXint where; // Where dropped in segment
84  FXint barsize; // Bar size
85  FXint controlsize; // Size of control
86  FXColor selectColor; // Select color
87  FXString tip; // Tooltip value
88  FXString help; // Help value
89  FXint offset; // Offset
90 protected:
91  FXGradientBar();
92  void updatebar();
93  FXdouble getValue(FXint x,FXint y) const;
94  FXint getSegmentLowerPos(FXint sg) const;
95  FXint getSegmentUpperPos(FXint sg) const;
96  FXint getSegmentMiddlePos(FXint sg) const;
97  void drawUpArrow(FXDCWindow& dc,FXint x,FXint y,FXColor clr);
98  void drawDnArrow(FXDCWindow& dc,FXint x,FXint y,FXColor clr);
99  void drawRtArrow(FXDCWindow& dc,FXint x,FXint y,FXColor clr);
100  void drawLtArrow(FXDCWindow& dc,FXint x,FXint y,FXColor clr);
101  void drawBottomArrows(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
102  void drawTopArrows(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
103  void drawLeftArrows(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
104  void drawRightArrows(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
105  static FXdouble blendlinear(FXdouble middle,FXdouble pos);
106  static FXdouble blendpower(FXdouble middle,FXdouble pos);
107  static FXdouble blendsine(FXdouble middle,FXdouble pos);
108  static FXdouble blendincreasing(FXdouble middle,FXdouble pos);
109  static FXdouble blenddecreasing(FXdouble middle,FXdouble pos);
110  static const FXGradient defaultGradient[3];
111 private:
113  FXGradientBar &operator=(const FXGradientBar&);
114 public:
115  enum {
116  GRIP_NONE,
117  GRIP_LOWER,
118  GRIP_SEG_LOWER,
119  GRIP_MIDDLE,
120  GRIP_SEG_UPPER,
121  GRIP_UPPER
122  };
123 public:
124  long onPaint(FXObject*,FXSelector,void*);
125  long onMotion(FXObject*,FXSelector,void*);
126  long onLeftBtnPress(FXObject*,FXSelector,void*);
127  long onLeftBtnRelease(FXObject*,FXSelector,void*);
128  long onRightBtnPress(FXObject*,FXSelector,void*);
129  long onRightBtnRelease(FXObject*,FXSelector,void*);
130  long onDNDEnter(FXObject*,FXSelector,void*);
131  long onDNDLeave(FXObject*,FXSelector,void*);
132  long onDNDMotion(FXObject*,FXSelector,void*);
133  long onDNDDrop(FXObject*,FXSelector,void*);
134  long onCmdBlending(FXObject*,FXSelector,void*);
135  long onUpdBlending(FXObject*,FXSelector,void*);
136  long onUpdSegColor(FXObject*,FXSelector,void*);
137  long onCmdSegColor(FXObject*,FXSelector,void*);
138  long onUpdRecenter(FXObject*,FXSelector,void*);
139  long onCmdRecenter(FXObject*,FXSelector,void*);
140  long onUpdSplit(FXObject*,FXSelector,void*);
141  long onCmdSplit(FXObject*,FXSelector,void*);
142  long onUpdMerge(FXObject*,FXSelector,void*);
143  long onCmdMerge(FXObject*,FXSelector,void*);
144  long onUpdUniform(FXObject*,FXSelector,void*);
145  long onCmdUniform(FXObject*,FXSelector,void*);
146  long onCmdReset(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_RESET,
167  ID_LAST
168  };
169 public:
170 
172  FXGradientBar(FXComposite* p,FXObject* tgt=nullptr,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);
173 
175  virtual void create();
176 
178  virtual void layout();
179 
181  virtual FXint getDefaultWidth();
182 
184  virtual FXint getDefaultHeight();
185 
190  FXint getSegment(FXint x,FXint y) const;
191 
197  FXint getGrip(FXint sg,FXint x,FXint y) const;
198 
200  FXint getNumSegments() const { return nsegs; }
201 
205  void resetGradients();
206 
211  void setGradients(const FXGradient *segments,FXint nsegments);
212 
218  void getGradients(FXGradient*& segments,FXint& nsegments) const;
219 
221  void setCurrentSegment(FXint index,FXbool notify=false);
222 
224  FXint getCurrentSegment() const { return current; }
225 
227  void setAnchorSegment(FXint index);
228 
230  FXint getAnchorSegment() const { return anchor; }
231 
233  FXbool selectSegments(FXint fm,FXint to,FXbool notify=false);
234 
236  FXbool deselectSegments(FXbool notify=false);
237 
239  FXbool isSegmentSelected(FXint s) const;
240 
242  void setSegmentLowerColor(FXint s,FXColor clr,FXbool notify=false);
243 
245  void setSegmentUpperColor(FXint s,FXColor clr,FXbool notify=false);
246 
248  FXColor getSegmentLowerColor(FXint s) const;
249 
251  FXColor getSegmentUpperColor(FXint s) const;
252 
254  void moveSegmentLower(FXint sg,FXdouble val,FXbool notify=false);
255 
257  void moveSegmentMiddle(FXint sg,FXdouble val,FXbool notify=false);
258 
260  void moveSegmentUpper(FXint sg,FXdouble val,FXbool notify=false);
261 
263  void moveSegments(FXint sglo,FXint sghi,FXdouble val,FXbool notify=false);
264 
266  FXdouble getSegmentLower(FXint sg) const;
267 
269  FXdouble getSegmentMiddle(FXint sg) const;
270 
272  FXdouble getSegmentUpper(FXint sg) const;
273 
279  void gradient(FXColor *ramp,FXint nramp) const;
280 
286  FXuint getSegmentBlend(FXint s) const;
287 
289  void splitSegments(FXint sglo,FXint sghi,FXbool notify=false);
290 
292  void mergeSegments(FXint sglo,FXint sghi,FXbool notify=false);
293 
295  void uniformSegments(FXint sglo,FXint sghi,FXbool notify=false);
296 
298  void blendSegments(FXint sglo,FXint sghi,FXuint blend=GRADIENT_BLEND_LINEAR,FXbool notify=false);
299 
301  void setControlSize(FXint cs);
302 
304  FXint getControlSize() const { return controlsize; }
305 
307  void setBarSize(FXint bs);
308 
310  FXint getBarSize() const { return barsize; }
311 
313  FXuint getBarStyle() const;
314 
316  void setBarStyle(FXuint style);
317 
319  void setSelectColor(FXColor clr);
320 
322  FXColor getSelectColor() const { return selectColor; }
323 
325  void setHelpText(const FXString& text){ help=text; }
326 
328  const FXString& getHelpText() const { return help; }
329 
331  void setTipText(const FXString& text){ tip=text; }
332 
334  const FXString& getTipText() const { return tip; }
335 
337  virtual void save(FXStream& store) const;
338 
340  virtual void load(FXStream& store);
341 
343  virtual ~FXGradientBar();
344  };
345 
346 
347 }
348 
349 #endif
FXint getNumSegments() const
Return the number of segments.
Definition: FXGradientBar.h:200
const FXString & getHelpText() const
Get status line help text for this gradient bar.
Definition: FXGradientBar.h:328
The Frame widget provides borders around some contents.
Definition: FXFrame.h:58
void setTipText(const FXString &text)
Set tool tip message for this gradient bar.
Definition: FXGradientBar.h:331
Base composite.
Definition: FXComposite.h:32
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:81
const FXString & getTipText() const
Get tool tip message for this gradient bar.
Definition: FXGradientBar.h:334
FXColor lowerColor
Upper value.
Definition: FXGradientBar.h:58
FXint getAnchorSegment() const
Return anchor segment, or -1 if there is no anchor segment.
Definition: FXGradientBar.h:230
FXColor upperColor
Lower color.
Definition: FXGradientBar.h:59
The gradient bar is a control that is used to edit color gradient, such as used in texture mapping an...
Definition: FXGradientBar.h:71
Definition: FX4Splitter.h:28
FXColor getSelectColor() const
Get color.
Definition: FXGradientBar.h:322
Definition: FXGradientBar.h:54
FXdouble upper
Middle value.
Definition: FXGradientBar.h:57
FXint getCurrentSegment() const
Return current segment, or -1 if there is no current segment.
Definition: FXGradientBar.h:224
FXuchar blend
Upper color.
Definition: FXGradientBar.h:60
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:134
Window Device Context.
Definition: FXDCWindow.h:48
An Image is a rectangular array of pixels.
Definition: FXImage.h:67
FXdouble middle
Lower value.
Definition: FXGradientBar.h:56
FXint getBarSize() const
Get bar size.
Definition: FXGradientBar.h:310
void setHelpText(const FXString &text)
Set status line help text for this gradient bar.
Definition: FXGradientBar.h:325
FXint getControlSize() const
Get control size.
Definition: FXGradientBar.h:304
FXString provides essential string manipulation capabilities in FOX.
Definition: FXString.h:42

Copyright © 1997-2022 Jeroen van der Zijp