Initial release of Maemo 5 port of gnuplot
[gnuplot] / src / gadgets.h
1 /*
2  * gadgets.h,v 1.1.3.1 2000/05/03 21:47:15 hbb Exp
3  */
4
5 /* GNUPLOT - gadgets.h */
6
7 /*[
8  * Copyright 2000, 2004   Thomas Williams, Colin Kelley
9  *
10  * Permission to use, copy, and distribute this software and its
11  * documentation for any purpose with or without fee is hereby granted,
12  * provided that the above copyright notice appear in all copies and
13  * that both that copyright notice and this permission notice appear
14  * in supporting documentation.
15  *
16  * Permission to modify the software is granted, but not the right to
17  * distribute the complete modified source code.  Modifications are to
18  * be distributed as patches to the released version.  Permission to
19  * distribute binaries produced by compiling modified sources is granted,
20  * provided you
21  *   1. distribute the corresponding source modifications from the
22  *    released version in the form of a patch file along with the binaries,
23  *   2. add special version identification to distinguish your version
24  *    in addition to the base release version number,
25  *   3. provide your name and address as the primary contact for the
26  *    support of your modified version, and
27  *   4. retain our contact information in regard to use of the base
28  *    software.
29  * Permission to distribute the released version of the source code along
30  * with corresponding source modifications in the form of a patch file is
31  * granted with same provisions 2 through 4 for binary distributions.
32  *
33  * This software is provided "as is" without express or implied warranty
34  * to the extent permitted by applicable law.
35 ]*/
36
37 #ifndef GNUPLOT_GADGETS_H
38 # define GNUPLOT_GADGETS_H
39
40 #include "syscfg.h"
41
42 #include "term_api.h"
43
44 /* Types and variables concerning graphical plot elements that are not
45  * *terminal-specific, are used by both* 2D and 3D plots, and are not
46  * *assignable to any particular * axis. I.e. they belong to neither
47  * *term_api, graphics, graph3d, nor * axis .h files.
48  */
49
50 /* #if... / #include / #define collection: */
51
52 /* Default point size is taken from the global "pointsize" variable */
53 #define PTSZ_DEFAULT    (-2)
54 #define PTSZ_VARIABLE   (-3)
55
56 /* Type definitions */
57
58 /* Coordinate system specifications: x1/y1, x2/y2, graph-box relative
59  * or screen relative coordinate systems */
60 typedef enum position_type {
61     first_axes,
62     second_axes,
63     graph,
64     screen,
65     character
66 } position_type;
67
68 /* A full 3D position, with all 3 coordinates of different axes,
69  * possibly. Used for 'set label' and 'set arrow' positions: */
70 typedef struct position {
71     enum position_type scalex,scaley,scalez;
72     double x,y,z;
73 } t_position;
74
75 /* Linked list of structures storing 'set label' information */
76 typedef struct text_label {
77     struct text_label *next;    /* pointer to next label in linked list */
78     int tag;                    /* identifies the label */
79     t_position place;
80     enum JUSTIFY pos;
81     int rotate;
82     int layer;
83     char *text;
84     char *font;                 /* Entry font added by DJL */
85     struct t_colorspec textcolor;
86     struct lp_style_type lp_properties;
87     struct position offset;
88     TBOOLEAN noenhanced;
89 } text_label;
90
91 /* This is the default state for the axis, timestamp, and plot title labels
92  * indicated by tag = -2 */
93 #define EMPTY_LABELSTRUCT \
94     {NULL, -2, {character, character, character, 0.0, 0.0, 0.0}, CENTRE, 0, 0, \
95      NULL, NULL, {TC_LT, -2, 0.0}, DEFAULT_LP_STYLE_TYPE, \
96      {character, character, character, 0.0, 0.0, 0.0}, FALSE }
97
98 /* Datastructure for implementing 'set arrow' */
99 typedef struct arrow_def {
100     struct arrow_def *next;     /* pointer to next arrow in linked list */
101     int tag;                    /* identifies the arrow */
102     t_position start;
103     t_position end;
104     TBOOLEAN relative;          /* second coordinate is relative to first */
105     struct arrow_style_type arrow_properties;
106 } arrow_def;
107
108 #ifdef EAM_OBJECTS
109 /* The only object type supported so far is OBJ_RECTANGLE */
110 typedef struct rectangle {
111     int type;                   /* 0 = corners;  1 = center + size */
112     t_position bl;              /* bottom left */
113     t_position tr;              /* top right */
114     t_position center;          /* center */
115     t_position extent;          /* width and height */
116 } t_rectangle;
117
118 /* Datastructure for 'set object' */
119 typedef struct object {
120     struct object *next;
121     int tag;
122     int layer;                  /* behind or back or front */
123     int object_type;    /* OBJ_RECTANGLE */
124     fill_style_type fillstyle;
125     lp_style_type lp_properties;
126     union o {t_rectangle rectangle;} o;
127 } t_object;
128 #define OBJ_RECTANGLE (1)
129 #endif
130
131 /* Datastructure implementing 'set style line' */
132 struct linestyle_def {
133     struct linestyle_def *next; /* pointer to next linestyle in linked list */
134     int tag;                    /* identifies the linestyle */
135     struct lp_style_type lp_properties;
136 };
137
138 /* Datastructure implementing 'set style arrow' */
139 struct arrowstyle_def {
140     struct arrowstyle_def *next;/* pointer to next arrowstyle in linked list */
141     int tag;                    /* identifies the arrowstyle */
142     struct arrow_style_type arrow_properties;
143 };
144
145 /* The stacking direction of the key box: (vertical, horizontal) */
146 typedef enum en_key_stack_direction {
147     GPKEY_VERTICAL,
148     GPKEY_HORIZONTAL
149 } t_key_stack_direction;
150
151 /* The region, with respect to the border, key is located: (inside, outside) */
152 typedef enum en_key_region {
153     GPKEY_AUTO_INTERIOR_LRTBC,   /* Auto placement, left/right/top/bottom/center */
154     GPKEY_AUTO_EXTERIOR_LRTBC,   /* Auto placement, left/right/top/bottom/center */
155     GPKEY_AUTO_EXTERIOR_MARGIN,  /* Auto placement, margin plus lrc or tbc */
156     GPKEY_USER_PLACEMENT         /* User specified placement */
157 } t_key_region;
158
159 /* If exterior, there are 12 possible auto placements.  Since
160    left/right/center with top/bottom/center can only define 9
161    locations, further subdivide the exterior region into four
162    subregions for which left/right/center (TMARGIN/BMARGIN)
163    and top/bottom/center (LMARGIN/RMARGIN) creates 12 locations. */
164 typedef enum en_key_ext_region {
165     GPKEY_TMARGIN,
166     GPKEY_BMARGIN,
167     GPKEY_LMARGIN,
168     GPKEY_RMARGIN
169 } t_key_ext_region;
170
171 /* Key sample to the left or the right of the plot title? */
172 typedef enum en_key_sample_positioning {
173     GPKEY_LEFT,
174     GPKEY_RIGHT
175 } t_key_sample_positioning;
176
177 typedef struct {
178     int opt_given; /* option given / not given (otherwise default) */
179     int closeto;   /* from list FILLEDCURVES_CLOSED, ... */
180     double at;     /* value for FILLEDCURVES_AT... */
181     double aty;    /* the other value for FILLEDCURVES_ATXY */
182     int oneside;   /* -1 if fill below bound only; +1 if fill above bound only */
183 } filledcurves_opts;
184 #define EMPTY_FILLEDCURVES_OPTS { 0, 0, 0.0, 0.0, 0 }
185
186 #ifdef EAM_HISTOGRAMS
187 typedef struct histogram_style {
188     int type;           /* enum t_histogram_type */
189     int gap;            /* set style hist gap <n> (space between clusters) */
190     int clustersize;    /* number of datasets in this histogram */
191     double start;       /* X-coord of first histogram entry */
192     double end;         /* X-coord of last histogram entry */
193     int startcolor;     /* LT_UNDEFINED or explicit color for first entry */
194     int startpattern;   /* LT_UNDEFINED or explicit pattern for first entry */
195     double bar_lw;      /* linewidth for error bars */
196     struct histogram_style *next;
197     struct text_label title;
198 } histogram_style;
199 typedef enum histogram_type {
200         HT_NONE,
201         HT_STACKED_IN_LAYERS,
202         HT_STACKED_IN_TOWERS,
203         HT_CLUSTERED,
204         HT_ERRORBARS
205 } t_histogram_type;
206 #define DEFAULT_HISTOGRAM_STYLE { HT_NONE, 2, 1, 0.0, 0.0, LT_UNDEFINED, LT_UNDEFINED, 0, NULL, EMPTY_LABELSTRUCT }
207
208 #endif
209
210 /***********************************************************/
211 /* Variables defined by gadgets.c needed by other modules. */
212 /***********************************************************/
213
214
215
216 /* EAM Feb 2003 - Move all global variables related to key into a */
217 /* single structure. Eventually this will allow multiple keys.    */
218
219 typedef enum keytitle_type {
220     NOAUTO_KEYTITLES, FILENAME_KEYTITLES, COLUMNHEAD_KEYTITLES
221 } keytitle_type;
222
223 typedef struct {
224     TBOOLEAN visible;           /* Do we show this key at all? */
225     t_key_region region;        /* if so: where? */
226     t_key_ext_region margin;    /* if exterior: where outside? */
227     struct position user_pos;   /* if user specified position, this is it */
228     VERT_JUSTIFY vpos;          /* otherwise these guide auto-positioning */
229     JUSTIFY hpos;
230     t_key_sample_positioning just;
231     t_key_stack_direction stack_dir;
232     double swidth;              /* 'width' of the linestyle sample line in the key */
233     double vert_factor;         /* user specified vertical spacing multiplier */
234     double width_fix;           /* user specified additional (+/-) width of key titles */
235     double height_fix;
236     keytitle_type auto_titles;  /* auto title curves unless plotted 'with notitle' */
237     TBOOLEAN reverse;           /* key back to front */
238     TBOOLEAN invert;            /* key top to bottom */
239     TBOOLEAN enhanced;          /* enable/disable enhanced text of key titles */
240     struct lp_style_type box;   /* linetype of box around key:  */
241     char title[MAX_LINE_LEN+1]; /* title line for the key as a whole */
242 } legend_key;
243
244 extern legend_key keyT;
245
246 # define DEFAULT_KEYBOX_LP { 0, LT_NODRAW, 0, 1.0, 1.0, 0 }
247
248 #define DEFAULT_KEY_POSITION { graph, graph, graph, 0.9, 0.9, 0. }
249
250 #define DEFAULT_KEY_PROPS \
251                 { TRUE, \
252                 GPKEY_AUTO_INTERIOR_LRTBC, GPKEY_RMARGIN, \
253                 DEFAULT_KEY_POSITION, \
254                 JUST_TOP, RIGHT, \
255                 GPKEY_RIGHT, GPKEY_VERTICAL, \
256                 4.0, 1.0, 0.0, 0.0, \
257                 FILENAME_KEYTITLES, \
258                 FALSE, FALSE, TRUE, \
259                 DEFAULT_KEYBOX_LP, \
260                 "" }
261
262 /* bounding box position, in terminal coordinates */
263 typedef struct {
264     int xleft;
265     int xright;
266     int ybot;
267     int ytop;
268 } BoundingBox;
269
270
271 /*
272  * EAM Jan 2006 - Move colorbox structure definition to here from color.h
273  * in order to be able to use struct position
274  */
275
276 #define SMCOLOR_BOX_NO      'n'
277 #define SMCOLOR_BOX_DEFAULT 'd'
278 #define SMCOLOR_BOX_USER    'u'
279
280 typedef struct {
281   char where;
282     /* where
283         SMCOLOR_BOX_NO .. do not draw the colour box
284         SMCOLOR_BOX_DEFAULT .. draw it at default position and size
285         SMCOLOR_BOX_USER .. draw it at the position given by user
286     */
287   char rotation; /* 'v' or 'h' vertical or horizontal box */
288   char border; /* if non-null, a border will be drawn around the box (default) */
289   int border_lt_tag;
290   int layer; /* front or back */
291   struct position origin;
292   struct position size;
293 } color_box_struct;
294
295 extern color_box_struct color_box;
296 extern color_box_struct default_color_box;
297
298 extern BoundingBox plot_bounds; /* Plot Boundary */
299 extern BoundingBox canvas;      /* Writable area on terminal */
300 extern BoundingBox *clip_area;  /* Current clipping box */
301
302 extern float xsize;             /* x scale factor for size */
303 extern float ysize;             /* y scale factor for size */
304 extern float zsize;             /* z scale factor for size */
305 extern float xoffset;           /* x origin setting */
306 extern float yoffset;           /* y origin setting */
307 extern float aspect_ratio;      /* 1.0 for square */
308 extern int aspect_ratio_3D;     /* 2 for equal scaling of x and y; 3 for z also */
309
310 /* plot border autosizing overrides, in characters (-1: autosize) */
311 extern t_position lmargin, bmargin, rmargin, tmargin;
312 #define DEFAULT_MARGIN_POSITION {character, character, character, -1, -1, -1}
313
314 extern FILE *table_outfile;
315 extern TBOOLEAN table_mode;
316
317 extern struct arrow_def *first_arrow;
318
319 extern struct text_label *first_label;
320
321 extern struct linestyle_def *first_linestyle;
322
323 extern struct arrowstyle_def *first_arrowstyle;
324
325 #ifdef EAM_OBJECTS
326 extern struct object *first_object;
327 #endif
328
329 extern text_label title;
330
331 extern text_label timelabel;
332 #ifndef DEFAULT_TIMESTAMP_FORMAT
333 /* asctime() format */
334 # define DEFAULT_TIMESTAMP_FORMAT "%a %b %d %H:%M:%S %Y"
335 #endif
336 extern int timelabel_rotate;
337 extern int timelabel_bottom;
338
339 extern TBOOLEAN polar;
340
341 #define ZERO 1e-8               /* default for 'zero' set option */
342 extern double zero;             /* zero threshold, not 0! */
343
344 extern double pointsize;
345
346 #define SOUTH           1 /* 0th bit */
347 #define WEST            2 /* 1th bit */
348 #define NORTH           4 /* 2th bit */
349 #define EAST            8 /* 3th bit */
350 #define border_east     (draw_border & EAST)
351 #define border_west     (draw_border & WEST)
352 #define border_south    (draw_border & SOUTH)
353 #define border_north    (draw_border & NORTH)
354 #define border_complete ((draw_border & 15) == 15)
355 extern int draw_border;
356 extern int border_layer;
357
358 extern struct lp_style_type border_lp;
359 extern const struct lp_style_type default_border_lp;
360
361 extern TBOOLEAN clip_lines1;
362 extern TBOOLEAN clip_lines2;
363 extern TBOOLEAN clip_points;
364
365 #define SAMPLES 100             /* default number of samples for a plot */
366 extern int samples_1;
367 extern int samples_2;
368
369 extern double ang2rad; /* 1 or pi/180 */
370
371 extern enum PLOT_STYLE data_style;
372 extern enum PLOT_STYLE func_style;
373
374 extern TBOOLEAN parametric;
375
376 /* If last plot was a 3d one. */
377 extern TBOOLEAN is_3d_plot;
378
379 /* A macro to check whether 2D functionality is allowed in the last plot:
380    either the plot is a 2D plot, or it is a suitably oriented 3D plot (e.g. map).
381 */
382 #define ALMOST2D      \
383     ( !is_3d_plot ||  \
384       ( fabs(fmod(surface_rot_z,90.0))<0.1  \
385         && (surface_rot_x>179.9 || surface_rot_x<0.1) ) )
386
387 #ifdef WITH_IMAGE
388 extern TBOOLEAN is_cb_plot;
389 #endif
390
391 /* Plot layer definitions are collected here. */
392 /* Someday they might actually be used.       */
393 #define LAYER_BEHIND     -1
394 #define LAYER_BACK        0
395 #define LAYER_FRONT       1
396 #define LAYER_PLOTLABELS 99
397
398 /* Functions exported by gadgets.c */
399
400 /* moved here from util3d: */
401 void draw_clip_line __PROTO((int, int, int, int));
402 void draw_clip_arrow __PROTO((int, int, int, int, int));
403 int clip_line __PROTO((int *, int *, int *, int *));
404 int clip_point __PROTO((unsigned int, unsigned int));
405 void clip_put_text __PROTO((unsigned int, unsigned int, char *));
406
407 /* moved here from graph3d: */
408 void clip_move __PROTO((unsigned int x, unsigned int y));
409 void clip_vector __PROTO((unsigned int x, unsigned int y));
410
411 /* Common routines for setting line or text color from t_colorspec */
412 void apply_pm3dcolor __PROTO((struct t_colorspec *tc, const struct termentry *t));
413 void reset_textcolor __PROTO((const struct t_colorspec *tc, const struct termentry *t));
414
415 extern fill_style_type default_fillstyle;
416
417 #ifdef EAM_OBJECTS
418 extern struct object default_rectangle;
419 #define DEFAULT_RECTANGLE_STYLE { NULL, -1, 0, OBJ_RECTANGLE,   \
420         {FS_SOLID, 100, 0, LT_BLACK},                           \
421         {1, LT_BACKGROUND, 0, 1.0, 0.0},                        \
422         {{0, {0,0.,0.,0.}, {0,0.,0.,0.}, {0,0.,0.,0.}, {0,0.,0.,0.}}} }
423 #endif
424
425 /* filledcurves style options set by 'set style [data|func] filledcurves opts' */
426 extern filledcurves_opts filledcurves_opts_data;
427 extern filledcurves_opts filledcurves_opts_func;
428
429 /* Prefer line styles over plain line types */
430 extern TBOOLEAN prefer_line_styles;
431
432 #ifdef EAM_HISTOGRAMS
433 extern histogram_style histogram_opts;
434 #endif
435
436 void default_arrow_style __PROTO((struct arrow_style_type *arrow));
437
438 #ifdef EAM_DATASTRINGS
439 void free_labels __PROTO((struct text_label *tl));
440 #endif
441
442 void get_offsets __PROTO((struct text_label *this_label,
443         struct termentry *t, int *htic, int *vtic));
444 void write_label __PROTO((unsigned int x, unsigned int y, struct text_label *label));
445
446 #endif /* GNUPLOT_GADGETS_H */