r109: reorganized header files
[ctsim.git] / include / sgp.h
1 /*****************************************************************************
2 **  This is part of the CTSim program
3 **  Copyright (C) 1983-2000 Kevin Rosenberg
4 **
5 **  $Id: sgp.h,v 1.10 2000/06/19 19:04:05 kevin Exp $
6 **
7 **  This program is free software; you can redistribute it and/or modify
8 **  it under the terms of the GNU General Public License (version 2) as
9 **  published by the Free Software Foundation.
10 **
11 **  This program is distributed in the hope that it will be useful,
12 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 **  GNU General Public License for more details.
15 **
16 **  You should have received a copy of the GNU General Public License
17 **  along with this program; if not, write to the Free Software
18 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 ******************************************************************************/
20
21 /*----------------------------------------------------------------------*/
22 /*                 Standard Graphics Package Header File                */
23 /*----------------------------------------------------------------------*/
24
25 #ifndef __H_SGP
26 #define __H_SGP
27
28 #if HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include "ctsupport.h"
33
34 #if HAVE_G2_H
35 extern "C" {
36 #include "g2.h"
37 #include "g2_X11.h"
38 }
39 #endif
40
41 /* device names */
42
43 #define CRTDEV  1
44 #define PRTDEV  2
45 #define MEMDEV  4
46 #define FILEDEV 8
47
48 /* linestyles */
49
50 #define LS_NOLINE 0
51 #define LS_SOLID  0xffff
52 #define LS_DASH1  0xff00
53 #define LS_DASH2  0xf0f0
54 #define LS_DASH3  0xcccc
55 #define LS_DASH4  0xff3e
56 #define LS_DOTTED 0xaaaa
57
58 #define MAXDASH    4
59 #define MAXCOLOR   63
60
61 /* data structures */
62
63 struct sgp_window_st {
64     int pw_xsize;         /* Physical Window size */
65    int pw_ysize;
66    char title[256];
67    int g2_id;
68     double xw_min;    /* Window extents */
69     double yw_min;
70     double xw_max;
71     double yw_max;
72     double xv_min;    /* Viewport extents */
73     double yv_min;
74     double xv_max;
75     double yv_max;
76     double view[4];   /* Viewport array for clip_rect() */
77     double curx;      /* Current stylus position in world coords */
78     double cury;
79     int recalc_mc_to_ndc;
80     int recalc_ndc_to_mc;
81     GRFMTX_2D wc_to_ndc_x;     /* World coord to NDC matrix */
82     GRFMTX_2D mc_to_ndc_x;     /* Master to NDC */
83     GRFMTX_2D ndc_to_mc_x;     /* NDC to Master */
84     GRFMTX_2D ctm_2_x;         /* Current transfromation matrix */
85
86     int phys_curx;
87     int phys_cury;
88 };
89
90 typedef struct sgp_window_st SGP_WINDOW;
91 typedef struct sgp_window_st *SGP_ID;
92
93 struct device_st {
94         int open;                       /* TRUE if device is open for output */
95         int xsize, ysize;               /* Size of device in pixels */
96         int xmin, ymin;                 /* smallest coordinates */
97         int xmax, ymax;                 /* Maximum coordinates */
98         int colormax;                   /* Maximum color number of device */
99         int style;                      /* Current linestyle of device */
100         int width;                      /* Current width of device */
101         int color;                      /* Current color of device */
102         int icurx, icury;               /* Current position */
103         int icwidth, icheight;          /* Size of characters in pixels */
104         int cfore, cback;               /* Character foregnd & backgnd colors */
105         float asp;                      /* Aspect ratio.  Multipy x coord */
106         int (*dotfunc)(int x1, int y1, int color);              /* Dot function for device */
107         int (*linefunc)(int x1, int y1, int x2, int y2, int color);             /* Line function for device */
108         unsigned int nbytes;            /* Size of buffer in bytes */
109         char *buf;                      /* Pointer to buffer */
110         unsigned int bufseg, bufoff;    /* Buffer memory location */
111         int mode;                       /* Device mode */
112 };
113
114 struct charsp_st {
115         float width, height;            /* size of characters in NDC */
116         float textangle;                /* text angle in radians */
117         float charupangle;              /* character up angle */
118         int font;                       /* font for characters */
119         int updir, textdir;             /* text direct & character orientation */
120         int fore, back;                 /* foreground & background color */
121                                         /* if back = -1, then transparent back */
122 };
123
124 struct state_st {
125         int foregnd, backgnd;           /* current foregound & background colors */
126         int linestyle;                  /* current 16 bit linestyle */
127         int linewidth;                  /* current width of line (in pixels) */
128         int marktype;                   /* current marker type */
129         int markcolor;                  /* current marker color */
130         float xndc, yndc;               /* current position in NDC */
131 };
132
133 typedef struct device_st DEVICE;
134 typedef struct charsp_st CHARSPEC;
135 typedef struct state_st GRFSTATE;
136
137 struct point    {double x, y, z;};
138
139
140 /* Constants */
141
142 /* Flagcodes for motion directions */
143 #define XPLUS   001     /* right */
144 #define XMINUS  002     /* left */
145 #define YPLUS   004     /* up */
146 #define YMINUS  010     /* down */
147
148 /* Codes for marker symbols */
149 #define POINT    0      /* small dot */
150 #define SQUARE   1      /* empty square */
151 #define FSQUARE  2      /* filled square */
152 #define DIAMOND  3      /* empty diamond */
153 #define FDIAMOND 4      /* filled diamond */
154 #define CROSS    5      /* cross */
155 #define XCROSS   6      /* x */
156 #define CERCLE   7      /* open circle */
157 #define FCERCLE  8      /* filled circle */
158 #define BSQUARE  9      /* big open square */
159 #define BDIAMOND 10     /* big open diamond */
160
161 #define NMARKERS 11     /* Number of available symbol types */
162
163 /*-------------------------------------------------------------------------*/
164
165 #define PSET   0                /* codes for raster merging */
166 #define PRESET 1
167 #define OR     2
168 #define AND    3
169 #define XOR    4
170
171 /*-------------------------------------------------------------------------*/
172
173 /* circle.cpp */
174 void sgp2_draw_circle(const double r);
175 void sgp2_draw_arc(double start, double stop, const double r);
176
177 /* ctm.cpp */
178 void ctm_xlat_pre_2(double x, double y);
179 void ctm_xlat_post_2(double x, double y);
180 void ctm_scale_pre_2(double sx, double sy);
181 void ctm_scale_post_2(double sx, double sy);
182 void ctm_rotate_pre_2(double theta);
183 void ctm_rotate_post_2(double theta);
184 void ctm_shear_pre_2(double shrx, double shry);
185 void ctm_shear_post_2(double shrx, double shry);
186 void xlat_gmtx_2(GRFMTX_2D m, double x, double y);
187 void scale_gmtx_2(GRFMTX_2D m, double sx, double sy);
188 void shear_gmtx_2(GRFMTX_2D m, double shrx, double shry);
189 void rotate_gmtx_2(GRFMTX_2D m, double theta);
190 void ident_gmtx_2(GRFMTX_2D m);
191 void mult_gmtx_2(GRFMTX_2D a, GRFMTX_2D b, GRFMTX_2D c);
192 void invert_gmtx_2(GRFMTX_2D a, GRFMTX_2D b);
193 double determ_gmtx_2(GRFMTX_2D a);
194
195 /* drawbox.cpp */
196 void sgp2_draw_rect (double xmin, double ymin, double xmax, double ymax);
197
198 /* sgp.cpp */
199 SGP_ID sgp2_init (int xsize, int ysize, const char *title);
200 void sgp2_close (SGP_ID gid);
201 void sgp2_set_active_win (SGP_ID);
202 SGP_ID sgp2_get_active_win (void);
203 void sgp2_clear (void);
204 void sgp2_window(double xmin, double ymin, double xmax, double ymax);
205 void sgp2_viewport(double xmin, double ymin, double xmax, double ymax);
206 void sgp2_frame_vpt(void);
207 void calc_wc_to_ndc(void);
208 void calc_ndc_to_mc(void);
209 void wc_to_ndc(double xw, double yw, double *xn, double *yn);
210 void ndc_to_wc(double xn, double yn, double *xw, double *yw);
211 void sgp2_color(int icol);
212 void sgp2_line_style(int style);
213 void sgp2_line_abs(double x, double y);
214 void sgp2_move_abs(double x, double y);
215 void sgp2_line_rel(double x, double y);
216 void sgp2_move_rel(double x, double y);
217 void sgp2_draw_text(char *message);
218 void sgp2_polyline_abs(double x[], double y[], int n);
219 void sgp2_mark_abs(double x, double y);
220 void sgp2_mark_rel(double x, double y);
221 void sgp2_point_abs(double x, double y);
222 void sgp2_point_rel(double x, double y);
223 void charsize(double wid, double height);
224 void textangle(double angle);
225 void ctm_clr_2(void);
226 void ctm_get_2(GRFMTX_2D m);
227 void ctm_set_2(GRFMTX_2D m);
228 void ctm_pre_mult_2(GRFMTX_2D m);
229 void ctm_post_mult_2(GRFMTX_2D m);
230
231 /* sgpdrive.cpp */
232 int _sgp2_init_dev(SGP_ID gid);
233 int initdevice(int dev, int mode, int xsize, int ysize);
234 int opendevice(int dev);
235 void closedevice(int dev);
236 void termdevice(int dev);
237 void _sgp2_stylus(SGP_ID gid, double x, double y, int beam);
238 void pntndc (SGP_ID gid, double x, double y);
239 void markndc (SGP_ID gid, double x, double y);
240 GRFSTATE *inqstate(void);
241 void gp_set_aspect(int dev, double asp);
242 void setlinestyle(int style);
243 void setlinewidth(int wid);
244 DEVICE *inqdev(int dev);
245 void _sgp2_set_text(SGP_ID gid, double width, double height, double textangle, int font);
246 void settextclr(int fore, int back);
247 void setcolor(int fore);
248 void setbackg(int back);
249 int initmarker(int marker, int color);
250 int settextdir(int direction);
251 void _sgp2_dev_text(SGP_ID gid, char *message);
252 void termgrf2(void);
253 void flushdevice(int dev);
254
255 /* sgptext.cpp */
256 void wrtsymbol(int sym, int x, int y, DEVICE *dev);
257 void wrtchar(int ch, int x, int y, CHARSPEC *cspec, DEVICE *dev);
258 void wrttext(char txtstr[], int x, int y, CHARSPEC *cspec, DEVICE *dev);
259 void crtcolor(int mode, int *f, int *b);
260
261
262 #endif