gr.c

Go to the documentation of this file.
00001 #include "Buzz_inc.h"
00002 #include "externs.h"
00003 #include <assert.h>
00004 
00005 /** Unknown function
00006  * \deprecated This function is probably depricated
00007  */
00008 int
00009 grInitMouse (void)
00010 {
00011     return gxSUCCESS;
00012 }
00013 
00014 /** Unknown function
00015  * \deprecated This function is probably depricated
00016  */
00017 void
00018 grSetMousePos (int x, int y)
00019 {
00020 }
00021 
00022 int
00023 grGetMouseButtons (void)
00024 {
00025     int val;
00026 
00027     val = av_mouse_pressed_latched || av_mouse_pressed_cur;
00028     av_mouse_pressed_latched = 0;
00029     return (val);
00030 }
00031 
00032 int
00033 grGetMousePressedPos (int *xp, int *yp)
00034 {
00035     *xp = av_mouse_pressed_x / 2;
00036     *yp = av_mouse_pressed_y / 2;
00037     return (0);
00038 }
00039 
00040 int
00041 grGetMouseCurPos (int *xp, int *yp)
00042 {
00043     *xp = av_mouse_cur_x / 2;
00044     *yp = av_mouse_cur_y / 2;
00045     return (0);
00046 }
00047 
00048 static int gr_fg_color; /**< current foreground color to use */
00049 static int gr_bg_color; /**< current background color to use */
00050 
00051 void
00052 gr_set_color_map (unsigned char *map)
00053 {
00054     memcpy (pal, map, 256 * 3);
00055 }
00056 
00057 void
00058 gr_sync (void)
00059 {
00060     av_sync ();
00061 }
00062 
00063 void
00064 gr_maybe_sync (void)
00065 {
00066     if (screen_dirty)
00067         av_sync ();
00068 }
00069 
00070 /** set foreground color
00071  * 
00072  * \param color the color code to use
00073  * 
00074  * \li 6 = red
00075  * \li 1 = white
00076  */
00077 void
00078 grSetColor (int color)
00079 {
00080     gr_fg_color = color;
00081 }
00082 
00083 /** set background color
00084  * 
00085  * \param color the color code to use
00086  */
00087 void
00088 grSetBkColor (int color)
00089 {
00090     gr_bg_color = color;
00091 }
00092 
00093 void
00094 grClearArea (int x1, int y1, int x2, int y2)
00095 {
00096     int y, t;
00097     SDL_Rect r;
00098 
00099     assert(0 <= x1 && x1 < MAX_X);
00100     assert(0 <= x2 && x2 < MAX_X);
00101     assert(0 <= y1 && y1 < MAX_Y);
00102     assert(0 <= y2 && y2 < MAX_Y);
00103 
00104     if (x1 > x2) { t = x1; x1 = x2; x2 = t; }
00105     if (y1 > y2) { t = y1; y1 = y2; y2 = t; }
00106 
00107     for (y = y1; y <= y2; ++y) {
00108         memset(&screen[y * MAX_X + x1], gr_bg_color, x2-x1+1);
00109     }
00110 
00111     r.x = x1;
00112     r.y = y1;
00113     r.h = y2-y1+1;
00114     r.w = x2-x1+1;
00115     av_need_update(&r);
00116 }
00117 
00118 static int gr_cur_x, gr_cur_y;
00119 
00120 void
00121 grMoveTo (int x, int y)
00122 {
00123     gr_cur_x = x;
00124     gr_cur_y = y;
00125 }
00126 
00127 inline void
00128 grPutPixel (int x, int y, int color)
00129 {
00130     screen[y * MAX_X + x] = color;
00131 }
00132 
00133 //#define abs(a) (((a) >= 0) ? (a) : (0))
00134 #define swap(a,b) (t = a, a = b, b = t)
00135 void
00136 grLineTo (int x_arg, int y_arg)
00137 {
00138     int deltax, deltay;
00139     int error;
00140     int ystep;
00141     int x, y;
00142     int x0, y0, x1, y1;
00143     int steep;
00144     int t;
00145 
00146     x0 = gr_cur_x;
00147     y0 = gr_cur_y;
00148 
00149     x1 = x_arg;
00150     y1 = y_arg;
00151 
00152     steep = abs(y1 - y0) > abs(x1 - x0);
00153     if (steep) {
00154         swap(x0, y0);
00155         swap(x1, y1);
00156     }
00157     if (x0 > x1) {
00158         swap(x0, x1);
00159         swap(y0, y1);
00160     }
00161 
00162     deltax = x1 - x0;
00163     deltay = abs (y1 - y0);
00164     error = 0;
00165 
00166     y = y0;
00167     if (y0 < y1) {
00168         ystep = 1;
00169     } else {
00170         ystep = -1;
00171     }
00172 
00173     for (x = x0; x <= x1; x++) {
00174         if (steep) {
00175             grPutPixel (y, x, gr_fg_color);
00176         } else {
00177             grPutPixel (x, y, gr_fg_color);
00178         }
00179         error = error + deltay;
00180         if (2 * error >= deltax) {
00181             y = y + ystep;
00182             error = error - deltax;
00183         }
00184     }
00185 
00186     gr_cur_x = x_arg;
00187     gr_cur_y = y_arg;
00188 }
00189 
00190 void
00191 grLineRel (int dx, int dy)
00192 {
00193     grLineTo (gr_cur_x + dx, gr_cur_y + dy);
00194 }
00195 
00196 void
00197 grMoveRel (int dx, int dy)
00198 {
00199     grMoveTo (gr_cur_x + dx, gr_cur_y + dy);
00200 }
00201 
00202 
00203 void
00204 grDrawRect (int x1, int y1, int x2, int y2, int mode)
00205 {
00206     SDL_Rect r;
00207     int t;
00208 
00209     assert (mode == grOUTLINE);
00210 
00211     if (x1 > x2) { t = x1; x1 = x2; x2 = t;}
00212     if (y1 > y2) { t = y1; y1 = y2; y2 = t;}
00213 
00214     grMoveTo (x1, y1);
00215     grLineTo (x2, y1);
00216     grLineTo (x2, y2);
00217     grLineTo (x1, y2);
00218     grLineTo (x1, y1);
00219     r.x = x1; r.y = y1;
00220     r.w = x2-x1+1; r.h = y2-y1+1;
00221 }
00222 
00223 void
00224 grDrawLine (int x1, int y1, int x2, int y2)
00225 {
00226     grMoveTo (x1, y1);
00227     grLineTo (x2, y2);
00228 }
00229 
00230 inline int
00231 grGetPixel (int x, int y)
00232 {
00233     assert(x >= 0 && x < MAX_X);
00234     assert(y >= 0 && y < MAX_Y);
00235 
00236     return screen[y * MAX_X + x];
00237 }

Generated on Fri Sep 28 00:35:27 2007 for raceintospace by  doxygen 1.5.3