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