Debian Codegraph @

2dlib/pen.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/2dlib/pen.cpp $
21 * $Revision: 5 $
22 * $Date: 12/19/97 5:28p $
23 * $Author: Samir $
24 *
25 * line and rectangle drawing
26 *
27 * $Log: /DescentIII/Main/2dlib/pen.cpp $
28 *
29 * 5 12/19/97 5:28p Samir
30 * Took out old rasterization code. Moved to renderer library.
31 *
32 * 4 12/19/97 5:23p Samir
33 * Cleaned up a lot of code to call renderer code.
34 *
35 * 3 12/19/97 12:31p Samir
36 * Better renderer support.
37 *
38 * 21 6/16/97 4:45p Samir
39 * Added rendering line hooks.
40 *
41 * 20 6/12/97 6:29p Samir
42 *
43 * 19 6/06/97 12:18p Samir
44 * OpenGL HACKS to call renderer for some drawing functions. Must fix.
45 *
46 * 18 5/29/97 5:59p Samir
47 * Convert clipping from fix math to float math.
48 *
49 * 17 4/11/97 3:56 PM Jeremy
50 * replaced calls of ddgr_H/Vline to gr_h/vline
51 *
52 * 16 4/08/97 12:53p Samir
53 * Fixed hline clipping fuckup.
54 *
55 * 15 4/08/97 11:30a Jason
56 * made circles not draw if they are touching the edge ofthe viewport
57 *
58 * 14 4/08/97 10:42a Jason
59 * fixed bug with hline
60 *
61 * 13 4/01/97 4:37p Samir
62 * Simply better circle functions using viewport line and pixel functions.
63 * made an hline function that clips and a setpixel function that clips.
64 *
65 * 12 4/01/97 3:56p Samir
66 * Cheap clipping for scanlines. Should fix this so it's cleaner.
67 *
68 * 11 4/01/97 1:51p Samir
69 * Fixed clipping of circles.
70 *
71 * 10 4/01/97 1:40p Samir
72 * Circle functions
73 *
74 * 9 3/27/97 11:11a Samir
75 * Moved code from ddgr library to 2dlib because it was ANSI compliant and
76 * should work on all systems
77 *
78 * 8 2/28/97 2:52 PM Jeremy
79 * removed inline declaration of grViewport::clip_line
80 *
81 * 7 2/27/97 6:14p Samir
82 * moved higher level ddgr pen code to this library.
83 *
84 * 6 2/07/97 6:04p Matt
85 * Renamed vm_FixMulDiv() to FixMulDiv()
86 *
87 * 5 2/04/97 11:14a Samir
88 * Improved clipping system by adding a separate clipport based off of the
89 * viewport's rectangle in it's parent surface
90 *
91 * $NoKeywords: $
92 */
93
94 #include "lib2d.h"cxx . . $ `<file>/2dlib/lib2d.h`/
95 #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/
96
97 #define CLIP_LEFTcxx . . $ `2dlib/pen.cpp:97:9`! (vp_InitLeft + vp_Left)
98 #define CLIP_TOPcxx . . $ `2dlib/pen.cpp:98:9`! (vp_InitTop + vp_Top)
99 #define CLIP_RIGHTcxx . . $ `2dlib/pen.cpp:99:9`! (vp_InitLeft + vp_Right)
100 #define CLIP_BOTTOMcxx . . $ `2dlib/pen.cpp:100:9`! (vp_InitTop + vp_Bottom)
101
102 void grViewportcxx . . $ grViewport#::hlinecxx . . $ grViewport#hline(10de3014ec658f6e).(ddgr_colorcxx . . $ ddgr_color# col, int x1, int x2, int y1) {
103 ASSERTcxx . . $ `misc/pserror.h:246:9`!(vp_Locked);
104
105 x1 = global_xcxx . . $ grViewport#global_x(7ccb52b1bfe01045).(x1);
106 y1 = global_ycxx . . $ grViewport#global_y(7ccb52b1bfe01045).(y1);
107 x2 = global_xcxx . . $ grViewport#global_x(7ccb52b1bfe01045).(x2);
108
109 if (x1 > x2) {
110 int t = x2;
111 x2 = x1;
112 x1 = t;
113 }
114
115 if (y1 < CLIP_TOPcxx . . $ `2dlib/pen.cpp:98:9`!)
116 return;
117 if (y1 > CLIP_BOTTOMcxx . . $ `2dlib/pen.cpp:100:9`!)
118 return;
119 if (x1 > CLIP_RIGHTcxx . . $ `2dlib/pen.cpp:99:9`!)
120 return;
121 if (x2 < CLIP_LEFTcxx . . $ `2dlib/pen.cpp:97:9`!)
122 return;
123 if (x1 < CLIP_LEFTcxx . . $ `2dlib/pen.cpp:97:9`!)
124 x1 = CLIP_LEFTcxx . . $ `2dlib/pen.cpp:97:9`!;
125 if (x2 > CLIP_RIGHTcxx . . $ `2dlib/pen.cpp:99:9`!)
126 x2 = CLIP_RIGHTcxx . . $ `2dlib/pen.cpp:99:9`!;
127
128 rend_SetFlatColorcxx . . $ rend_SetFlatColor(cb2f890c2fdad230).(col);
129 rend_DrawLinecxx . . $ rend_DrawLine(748afa4755bc9595).(x1, y1, x2, y1);
130 }
131
132 // grViewport::line
133 // draws a clipped line
134
135 void grViewportcxx . . $ grViewport#::linecxx . . $ grViewport#line(fe09a4b73d8d396f).(ddgr_colorcxx . . $ ddgr_color# color, int x1, int y1, int x2, int y2) {
136 int xa, ya, xb, yb;
137 ASSERTcxx . . $ `misc/pserror.h:246:9`!(vp_Locked);
138
139 xa = global_xcxx . . $ grViewport#global_x(7ccb52b1bfe01045).(x1);
140 ya = global_ycxx . . $ grViewport#global_y(7ccb52b1bfe01045).(y1);
141 xb = global_xcxx . . $ grViewport#global_x(7ccb52b1bfe01045).(x2);
142 yb = global_ycxx . . $ grViewport#global_y(7ccb52b1bfe01045).(y2);
143
144 rend_SetFlatColorcxx . . $ rend_SetFlatColor(cb2f890c2fdad230).(color);
145 rend_DrawLinecxx . . $ rend_DrawLine(748afa4755bc9595).(x1, y1, x2, y2);
146 }
147
148 void grViewportcxx . . $ grViewport#::rectcxx . . $ grViewport#rect(fe09a4b73d8d396f).(ddgr_colorcxx . . $ ddgr_color# color, int l, int t, int r, int b) {
149 ASSERTcxx . . $ `misc/pserror.h:246:9`!(vp_Locked);
150
151 l = global_xcxx . . $ grViewport#global_x(7ccb52b1bfe01045).(l);
152 t = global_ycxx . . $ grViewport#global_y(7ccb52b1bfe01045).(t);
153 r = global_xcxx . . $ grViewport#global_x(7ccb52b1bfe01045).(r);
154 b = global_ycxx . . $ grViewport#global_y(7ccb52b1bfe01045).(b);
155
156 rend_SetFlatColorcxx . . $ rend_SetFlatColor(cb2f890c2fdad230).(color);
157 rend_DrawLinecxx . . $ rend_DrawLine(748afa4755bc9595).(l, t, r, t);
158 rend_DrawLinecxx . . $ rend_DrawLine(748afa4755bc9595).(r, t, r, b);
159 rend_DrawLinecxx . . $ rend_DrawLine(748afa4755bc9595).(l, b, r, b);
160 rend_DrawLinecxx . . $ rend_DrawLine(748afa4755bc9595).(l, t, l, b);
161 }
162
163 void grViewportcxx . . $ grViewport#::fillrectcxx . . $ grViewport#fillrect(fe09a4b73d8d396f).(ddgr_colorcxx . . $ ddgr_color# color, int l, int t, int r, int b) {
164 ASSERTcxx . . $ `misc/pserror.h:246:9`!(vp_Locked);
165
166 l = global_xcxx . . $ grViewport#global_x(7ccb52b1bfe01045).(l);
167 t = global_ycxx . . $ grViewport#global_y(7ccb52b1bfe01045).(t);
168 r = global_xcxx . . $ grViewport#global_x(7ccb52b1bfe01045).(r);
169 b = global_ycxx . . $ grViewport#global_y(7ccb52b1bfe01045).(b);
170
171 rend_FillRectcxx . . $ rend_FillRect(fe09a4b73d8d396f).(color, l, t, r, b);
172 }
173
174 void grViewportcxx . . $ grViewport#::circlecxx . . $ grViewport#circle(10de3014ec658f6e).(ddgr_colorcxx . . $ ddgr_color# col, int xc, int yc, int r) {
175 ASSERTcxx . . $ `misc/pserror.h:246:9`!(vp_Locked);
176
177 xc = global_xcxx . . $ grViewport#global_x(7ccb52b1bfe01045).(xc);
178 yc = global_ycxx . . $ grViewport#global_y(7ccb52b1bfe01045).(yc);
179
180 rend_SetFlatColorcxx . . $ rend_SetFlatColor(cb2f890c2fdad230).(col);
181 rend_DrawCirclecxx . . $ rend_DrawCircle(b1146eedae1e1d0b).(xc, yc, r);
182 }
183
184 void grViewportcxx . . $ grViewport#::fillcirclecxx . . $ grViewport#fillcircle(10de3014ec658f6e).(ddgr_colorcxx . . $ ddgr_color# col, int xc, int yc, int r) {
185 ASSERTcxx . . $ `misc/pserror.h:246:9`!(vp_Locked);
186
187 xc = global_xcxx . . $ grViewport#global_x(7ccb52b1bfe01045).(xc);
188 yc = global_ycxx . . $ grViewport#global_y(7ccb52b1bfe01045).(yc);
189
190 rend_FillCirclecxx . . $ rend_FillCircle(10de3014ec658f6e).(col, xc, yc, r);
191 }