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