]> icculus.org git repositories - taylor/freespace2.git/blob - include/line.h
fix issue with looping audio streams
[taylor/freespace2.git] / include / line.h
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Graphics/Line.h $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Header file for line.cpp
16  *
17  * $Log$
18  * Revision 1.2  2002/06/09 04:41:13  relnev
19  * added copyright header
20  *
21  * Revision 1.1.1.1  2002/05/03 03:28:12  root
22  * Initial import.
23  *
24  * 
25  * 2     10/07/98 10:53a Dave
26  * Initial checkin.
27  * 
28  * 1     10/07/98 10:49a Dave
29  * 
30  * 10    5/06/98 5:30p John
31  * Removed unused cfilearchiver.  Removed/replaced some unused/little used
32  * graphics functions, namely gradient_h and _v and pixel_sp.   Put in new
33  * DirectX header files and libs that fixed the Direct3D alpha blending
34  * problems.
35  * 
36  * 9     3/10/98 4:18p John
37  * Cleaned up graphics lib.  Took out most unused gr functions.   Made D3D
38  * & Glide have popups and print screen.  Took out all >8bpp software
39  * support.  Made Fred zbuffer.  Made zbuffer allocate dynamically to
40  * support Fred.  Made zbuffering key off of functions rather than one
41  * global variable.
42  * 
43  * 8     10/03/97 9:10a John
44  * added better antialiased line drawer
45  * 
46  * 7     6/13/97 5:35p John
47  * added some antialiased bitmaps and lines
48  * 
49  * 6     11/26/96 6:50p John
50  * Added some more hicolor primitives.  Made windowed mode run as current
51  * bpp, if bpp is 8,16,or 32.
52  * 
53  * 5     10/26/96 2:56p John
54  * Got gradient code working.
55  * 
56  * 4     10/26/96 1:40p John
57  * Added some now primitives to the 2d library and
58  * cleaned up some old ones.
59  *
60  * $NoKeywords: $
61  */
62
63 #ifndef _LINE_H
64 #define _LINE_H
65
66
67 #define INT_EXCHG(a,b) do {                                              \
68     int __temp__ = (a);                                                 \
69     (a) = (b);                                                          \
70     (b) = __temp__;                                                     \
71 } while(0)
72
73 #define INT_SCALE(var,arg,num,den) ((var) = ((arg) * (num)) / (den))
74 //#define INT_SCALE(var,arg,num,den) ((var) = mul_div(arg, num, den))
75
76 #define INT_CLIPLINE(x1,y1,x2,y2,XMIN,YMIN,XMAX,YMAX,WHEN_OUTSIDE,WHEN_CLIPPED,WHEN_SWAPPED) do {                                    \
77         int temp;                                                  \
78                                                                         \
79     if(y1 > y2)                                                         \
80         { INT_EXCHG(y1,y2); INT_EXCHG(x1,x2); WHEN_SWAPPED; }                                 \
81     if((y2 < YMIN) || (y1 > YMAX))                    \
82         { WHEN_OUTSIDE; }                                               \
83     if(x1 < x2) {                                                       \
84         if((x2 < XMIN) || (x1 > XMAX)) {              \
85             WHEN_OUTSIDE;                                               \
86         }                                                               \
87         if(x1 < XMIN) {                                        \
88                         INT_SCALE(temp,(y2 - y1),(XMIN - x1),(x2 - x1));      \
89             if((y1 += temp) > YMAX) { WHEN_OUTSIDE; }          \
90             x1 = XMIN;                                         \
91             WHEN_CLIPPED;                                               \
92         }                                                               \
93         if(x2 > XMAX) {                                        \
94                         INT_SCALE(temp,(y2 - y1),(x2 - XMAX),(x2 - x1));      \
95             if((y2 -= temp) < YMIN) { WHEN_OUTSIDE; }          \
96             x2 = XMAX;                                         \
97             WHEN_CLIPPED;                                               \
98         }                                                               \
99         if(y1 < YMIN) {                                        \
100                         INT_SCALE(temp,(x2 - x1),(YMIN - y1),(y2 - y1));      \
101             x1 += temp;                                                 \
102             y1 = YMIN;                                         \
103             WHEN_CLIPPED;                                               \
104         }                                                               \
105         if(y2 > YMAX) {                                        \
106                         INT_SCALE(temp,(x2 - x1),(y2 - YMAX),(y2 - y1));      \
107             x2 -= temp;                                                 \
108             y2 = YMAX;                                         \
109             WHEN_CLIPPED;                                               \
110         }                                                               \
111     }                                                                   \
112     else {                                                              \
113         if((x1 < XMIN) || (x2 > XMAX)) {              \
114             WHEN_OUTSIDE;                                               \
115         }                                                               \
116         if(x1 > XMAX) {                                        \
117                         INT_SCALE(temp,(y2 - y1),(x1 - XMAX),(x1 - x2));      \
118             if((y1 += temp) > YMAX) { WHEN_OUTSIDE; }          \
119             x1 = XMAX;                                         \
120             WHEN_CLIPPED;                                               \
121         }                                                               \
122         if(x2 < XMIN) {                                        \
123                         INT_SCALE(temp,(y2 - y1),(XMIN - x2),(x1 - x2));      \
124             if((y2 -= temp) < YMIN) { WHEN_OUTSIDE; }          \
125             x2 = XMIN;                                         \
126             WHEN_CLIPPED;                                               \
127         }                                                               \
128         if(y1 < YMIN) {                                        \
129                         INT_SCALE(temp,(x1 - x2),(YMIN - y1),(y2 - y1));      \
130             x1 -= temp;                                                 \
131             y1 = YMIN;                                         \
132             WHEN_CLIPPED;                                               \
133         }                                                               \
134         if(y2 > YMAX) {                                        \
135                         INT_SCALE(temp,(x1 - x2),(y2 - YMAX),(y2 - y1));      \
136             x2 += temp;                                                 \
137             y2 = YMAX;                                         \
138             WHEN_CLIPPED;                                               \
139         }                                                               \
140     }                                                                   \
141 } while(0)
142
143
144 #endif  // _LINE_H