1 /********************************************************************************
2 *                                                                               *
3 *                        C h a r t   B a s e   W i d g e t                      *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 2003,2005 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: FXChart.h,v 1.12 2005/01/16 16:06:06 fox Exp $                           *
23 ********************************************************************************/
24 #ifndef FXCHART_H
25 #define FXCHART_H
26 
27 
28 //////////////////////////////  UNDER DEVELOPMENT  //////////////////////////////
29 
30 
31 // Define FXCHARTAPI for DLL builds
32 #ifdef FOXDLL
33 #ifdef CHARTDLL_EXPORTS
34 #define FXCHARTAPI FXEXPORT
35 #else
36 #define FXCHARTAPI FXIMPORT
37 #endif
38 #else
39 #define FXCHARTAPI
40 #endif
41 
42 
43 namespace FX {
44 
45 
46 /// Tickmark placement styles
47 enum {
48   TICKS_OFF     = 0,                            /// No tickmarks
49   TICKS_MAJOR   = 0x01,                         /// Display major ticks
50   TICKS_MINOR   = 0x02,                         /// Display minor ticks
51   TICKS_INSIDE  = 0x04,                         /// Tickmarks inside box
52   TICKS_OUTSIDE = 0x08,                         /// Tickmarks outside box
53   TICKS_CROSS   = (TICKS_INSIDE|TICKS_OUTSIDE)  /// Tickmarks inside and outside box
54   };
55 
56 
57 /// Tickmark definition
58 struct Ticks {
59   FXuint   style;               /// Style flags
60   FXuchar  majorlength;         /// Major tick length
61   FXuchar  minorlength;         /// Minor tick length
62   FXuchar  majorweight;         /// Major tick line weight
63   FXuchar  minorweight;         /// Minor tick line weight
64   FXdouble majorspace;          /// Major tick spacing
65   FXdouble minorspace;          /// Minor tick spacing
66   FXColor  majorcolor;          /// Major tick color
67   FXColor  minorcolor;          /// Minor tick color
68   };
69 
70 
71 // Line styles
72 enum {
73   LINESTYLE_NONE,               /// No line
74   LINESTYLE_SOLID,              /// Solid line
75   LINESTYLE_DOTTED,             /// Dotted line
76   LINESTYLE_SHORTDASHED,        /// Short dashed line
77   LINESTYLE_LONGDASHED,         /// Long dashed line
78   LINESTYLE_DOTDASHED           /// Dot-dashed line
79   };
80 
81 
82 /// Line style definition
83 struct LineStyle {
84   FXuchar  style;               /// Line style flags
85   FXuchar  width;               /// Line width
86   FXuchar  cap;                 /// End cap style
87   FXuchar  join;                /// Join style
88   FXColor  color;               /// Line color
89   FXColor  backcolor;           /// Back color when stippling (may be clear)
90   };
91 
92 
93 /// Fill styles
94 enum {
95   FILLSTYLE_OFF,                /// Not filled
96   FILLSTYLE_SOLID,              /// Solid color
97   FILLSTYLE_HATCH,              /// Hatch pattern
98   FILLSTYLE_TEXTURE,            /// Repeating texture
99   FILLSTYLE_IMAGE,              /// Fill with an image
100   FILLSTYLE_HORIZONTAL,         /// Horizontal gradient
101   FILLSTYLE_VERTICAL,           /// Vertical gradient
102   FILLSTYLE_DIAGONAL,           /// Diagonal gradient
103   FILLSTYLE_RDIAGONAL           /// Reverse diagonal gradient
104   };
105 
106 
107 /// Fill style definition
108 struct FillStyle {
109   FXuchar   style;              /// Fill style
110   FXuchar   hatch;              /// Hatch pattern if hatch style
111   FXImage  *image;              /// Image used for texture or image fill
112   FXColor   color;              /// Fill color
113   FXColor   backcolor;          /// Back color when hatching (may be clear)
114   FXColor   lower;              /// Lower gradient color
115   FXColor   upper;              /// Upper gradient color
116   };
117 
118 
119 /// Text definition
120 struct TextStyle {
121   FXFont   *font;               /// Text font
122   FXColor   color;              /// Text color
123   FXColor   shadowcolor;        /// Text shadow color (may be clear)
124   FXshort   shadowx;            /// X shadow offset
125   FXshort   shadowy;            /// Y shadow offset
126   };
127 
128 
129 /// Tick number definition
130 struct Numbers {
131   FXuint    style;              /// Number format style
132   // ... How to format ... //
133   TextStyle textstyle;          /// Text display style
134   };
135 
136 
137 /// Caption definition
138 struct Caption {
139   FXString  caption;            /// Text string
140   TextStyle textstyle;          /// Text display style
141   };
142 
143 
144 /// Axis styles
145 enum {
146   AXIS_OFF       = 0,           /// Nothing drawn on axis
147   AXIS_CAPTION   = 0x0001,      /// Axis label drawn
148   AXIS_NUMBERS   = 0x0002,      /// Draw numbers on major ticks
149   AXIS_UNITS     = 0x0004,      /// Units display (. . .  N/m^2)
150   AXIS_GRID      = 0x0008,      /// Grid lines drawn on major ticks
151   AXIS_TICKS     = 0x0010,      /// Grid lines drawn on major ticks
152   AXIS_EXPONENT  = 0x0020,      /// Exponent near end of axis ( . . .  x 10^5 N/m^2)
153   AXIS_REVERSED  = 0x0040,      /// Numbers increase to left
154   AXIS_ROUND     = 0x0080,      /// Round range to nearest nice number
155   AXIS_LOG       = 0x0100,      /// Logarithmic scale
156   AXIS_GRIDFRONT = 0x0200       /// Grid in front of data
157   };
158 
159 
160 /// Axis definition
161 struct Axis {
162   FXuint      style;            /// Axis style flags
163   Ticks       ticks;            /// Tick drawing style
164   Caption     label;            /// Axis caption
165   Caption     units;            /// Axis units
166   Numbers     numbers;          /// Number drawing info
167   FXColor     linecolor;        /// Line color of axis line
168   FXuchar     lineweight;       /// Line weight of axis line
169   FXdouble    minimum;          /// Maximum data value
170   FXdouble    maximum;          /// Minimum data value
171   };
172 
173 
174 class FXImage;
175 
176 
177 // Base class for the various chart widgets
178 class FXCHARTAPI FXChart : public FXComposite {
179   FXDECLARE(FXChart)
180 protected:
181   FXImage  *chart;      // Chart image
182   FXString  tip;        // Tooltip value
183   FXString  help;       // Help value
184   FillStyle fill;       // Fill style
185 protected:
186   FXChart();
187 private:
188   FXChart(const FXChart&);
189   FXChart &operator=(const FXChart&);
190 public:
191   long onPaint(FXObject*,FXSelector,void*);
192   long onQueryHelp(FXObject*,FXSelector,void*);
193   long onQueryTip(FXObject*,FXSelector,void*);
194   long onClipboardLost(FXObject*,FXSelector,void*);
195   long onClipboardRequest(FXObject*,FXSelector,void*);
196 public:
197   static FXDragType bmpType;
198   static FXDragType gifType;
199   static FXDragType jpgType;
200   static FXDragType pngType;
201   static FXDragType tifType;
202   static FXDragType csvType;
203 public:
204   static const FXchar bmpTypeName[];
205   static const FXchar gifTypeName[];
206   static const FXchar jpgTypeName[];
207   static const FXchar pngTypeName[];
208   static const FXchar tifTypeName[];
209   static const FXchar csvTypeName[];
210 public:
211 
212   /// Construct color well with initial color clr
213   FXChart(FXComposite* p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=FRAME_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
214 
215   /// Create server-side resources
216   virtual void create();
217 
218   /// Detach server-side resources
219   virtual void detach();
220 
221   /// Perform layout
222   virtual void layout();
223 
224   /// Set fill style
225   void setFillStyle(const FillStyle& fs);
226 
227   /// Get fill style
getFillStyle()228   FillStyle getFillStyle() const { return fill; }
229 
230   /// Set status line help text for this chart
231   void setHelpText(const FXString& text);
232 
233   /// Get status line help text for this chart
getHelpText()234   FXString getHelpText() const { return help; }
235 
236   /// Set tool tip message for this chart
237   void setTipText(const FXString& text);
238 
239   /// Get tool tip message for this chart
getTipText()240   FXString getTipText() const { return tip; }
241 
242   /// Save chart to a stream
243   virtual void save(FXStream& store) const;
244 
245   /// Load chart from a stream
246   virtual void load(FXStream& store);
247 
248   /// Destructor
249   virtual ~FXChart();
250   };
251 
252 }
253 
254 #endif
255