Debian Codegraph @

engine/video/intern_video.h

raw
1 // ____ _ __
2 // / __ )____ _____ | | / /___ ___________
3 // / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
4 // / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
5 // /_____/\____/____/ |__/|__/\__,_/_/ /____/
6 //
7 // A futuristic real-time strategy game.
8 // This file is part of Bos Wars.
9 //
10 //*@file intern_video.h @brief The video headerfile for video sources only. */
11 //
12 // (c) Copyright 1999-2002 by Stephan Rasenbergver.
13 //
14 // This program is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; only version 2 of the License.
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 // 02111-1307, USA.
27 //
28
29 #ifndef __INTERN_VIDEO_H__
30 #define __INTERN_VIDEO_H__
31
32 //@{
33
34 /*----------------------------------------------------------------------------
35 -- Documentation
36 ----------------------------------------------------------------------------*/
37
38 /**
39 ** @file intern_video.h
40 **
41 ** THIS HEADER FILE SHOULD ONLY BE INCLUDED BY SOURCE-FILES IN VIDEO !!!
42 **
43 ** This delivers an interface to basic video operations in video.c, while
44 ** keeping these detailed operations out of the main include-file video.h
45 **
46 ** @todo FIXME: Currently some interfaces listed in video.h should be
47 ** moved in here, this includes possible "extern" declarations in
48 ** source-files themselves.
49 ** The doxygen docs looks not good, but now contains all info.
50 */
51
52 /*----------------------------------------------------------------------------
53 -- Includes
54 ----------------------------------------------------------------------------*/
55
56
57 /*----------------------------------------------------------------------------
58 -- Declarations
59 ----------------------------------------------------------------------------*/
60
61
62 /*----------------------------------------------------------------------------
63 -- Variables
64 ----------------------------------------------------------------------------*/
65
66 // Direct acces to clipping rectangle for macro CLIP_RECTANGLE
67 extern int ClipX1; /// current clipping top left
68 extern int ClipY1; /// current clipping top left
69 extern int ClipX2; /// current clipping bottom right
70 extern int ClipY2; /// current clipping bottom right
71
72 /*----------------------------------------------------------------------------
73 -- Macros
74 ----------------------------------------------------------------------------*/
75
76 /**
77 ** Clip rectangle area to clipping rectangle.
78 ** This means given arguments can be changed to take the clipping
79 ** rectangle into account.
80 **
81 ** @todo FIXME: not easy to debug, but making it a function needs:
82 ** - pointers to be able to alter given arguments
83 ** - special return value to denote 'outside' clipping region
84 ** (which is now handled by a simple return in caller function)
85 **
86 ** @param x int X screen pixel position
87 ** @param y int Y screen pixel position
88 ** (return value of X and Y can be made larger)
89 ** @param width unsigned int width to display
90 ** @param height unsigned int height to display
91 ** (return value of width and height can be made smaller)
92 */
93 #define CLIP_RECTANGLE(x, y, width, height) { \
94 int f; \
95 if (x < ClipX1) { \
96 f = ClipX1 - x; \
97 if (width <= f) { \
98 return; \
99 } \
100 width -= f; \
101 x = ClipX1; \
102 } \
103 if ((x + width) > ClipX2 + 1) { \
104 if (x > ClipX2) { \
105 return; \
106 } \
107 width = ClipX2 - x + 1; \
108 } \
109 if (y < ClipY1) { \
110 f = ClipY1 - y; \
111 if (height <= f) { \
112 return; \
113 } \
114 height -= f; \
115 y = ClipY1; \
116 } \
117 if ((y + height) > ClipY2 + 1) { \
118 if (y > ClipY2) { \
119 return; \
120 } \
121 height = ClipY2 - y + 1; \
122 } \
123 }
124
125 /**
126 ** Clip rectangle area (just like CLIP_RECTANGLE), but also return offsets
127 ** (these offsets can be used to skip data when used for sprites and such)
128 **
129 ** @todo FIXME: not easy to debug, but making it a function needs:
130 ** - pointers to be able to alter given arguments
131 ** - special return value to denote 'outside' clipping region
132 ** (which is now handled by a simple return in caller function)
133 **
134 ** @param x int X screen position
135 ** @param y int Y screen position
136 ** (return value of X and Y can be made larger)
137 ** @param width int width to display
138 ** @param height int height to display
139 ** (return value of width and height can be made smaller)
140 ** returns:
141 ** @param ofsx int offset X from start of sprite data
142 ** @param ofsy int offset Y from start of sprite data
143 ** @param endx int offset to skip the remaining data at the
144 ** end of each horizontal line of the sprite.
145 **
146 ** @note there was no need for 'endy', as it isn't used to draw sprites..
147 */
148 #define CLIP_RECTANGLE_OFS(x, y, width, height, ofsx, ofsy, endx) { \
149 if (y < ClipY1) { \
150 ofsy = ClipY1 - y; \
151 if (height <= ofsy) { \
152 return; \
153 } \
154 height -= ofsy; \
155 y = ClipY1; \
156 } else { \
157 ofsy = 0; \
158 } \
159 if ((y + height) > ClipY2 + 1) { \
160 if (y > ClipY2) { \
161 return; \
162 } \
163 height = ClipY2 - y + 1; \
164 } \
165 if (x < ClipX1) { \
166 ofsx = ClipX1 - x; \
167 if (width <= ofsx) { \
168 return; \
169 } \
170 width -= ofsx; \
171 x = ClipX1; \
172 } else { \
173 ofsx = 0; \
174 } \
175 if ((x + width) > ClipX2 + 1) { \
176 if (x > ClipX2) { \
177 return; \
178 } \
179 endx = (x + width) - (ClipX2 + 1); \
180 width = ClipX2 - x + 1; \
181 } else { \
182 endx = 0; \
183 } \
184 }
185
186
187 /*----------------------------------------------------------------------------
188 -- Functions
189 ----------------------------------------------------------------------------*/
190
191
192 //@}
193
194 #endif // !__INTERN_VIDEO_H__