home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / EMXLIB8F.ZIP / EMX / LIB / GRAPH / GBOX.C next >
Encoding:
C/C++ Source or Header  |  1993-01-02  |  1.5 KB  |  69 lines

  1. /* gbox.c (emx+gcc) -- Copyright (c) 1987-1993 by Eberhard Mattes */
  2.  
  3. #include <stdlib.h>
  4. #include <graph.h>
  5. #define INCL_VIO
  6. #include <os2emx.h>
  7. #include "graph2.h"
  8.  
  9. void g_box (int x0, int y0, int x1, int y1, int color, int fill_flag)
  10. {
  11.   int temp, dx, dy;
  12.  
  13.   if (y0 > y1)
  14.     {
  15.       temp = y0; y0 = y1; y1 = temp;
  16.     }
  17.   if (x0 > x1)
  18.     {
  19.       temp = x0; x0 = x1; x1 = temp;
  20.     }
  21.   if (x0 > _g_clipx1 || x1 < _g_clipx0 || y0 > _g_clipy1 || y1 < _g_clipy0)
  22.     return;
  23.   if (fill_flag)
  24.     {
  25.       if (y0 < _g_clipy0)
  26.         y0 = _g_clipy0;
  27.       if (y1 > _g_clipy1)
  28.         y1 = _g_clipy1;
  29.       if (x0 < _g_clipx0)
  30.         x0 = _g_clipx0;
  31.       if (x1 > _g_clipx1)
  32.         x1 = _g_clipx1;
  33.       GLOCK;
  34.       if (x1-x0 >= 3 || y1-y0 <= 4)
  35.         {
  36.           for (; y0 <= y1; ++y0)
  37.             g_hline (y0, x0, x1, color);
  38.         }
  39.       else
  40.         {
  41.           for (; x0 <= x1; ++x0)
  42.             g_vline (x0, y0, y1, color);
  43.         }
  44.       GUNLOCK;
  45.     }
  46.   else
  47.     {
  48.       dx = x1-x0; dy = y1-y0;
  49.       if (dx == 0)
  50.         g_vline (x0, y0, y1, color);
  51.       else if (dy == 0)
  52.         g_hline (y0, x0, x1, color);
  53.       else
  54.         {
  55.           if (dx != 1 || dy == 1)
  56.             {
  57.               g_hline (y0, x0, x1, color);
  58.               g_hline (y1, x0, x1, color);
  59.               ++y0; --y1;
  60.             }
  61.           if (dy != 1)
  62.             {
  63.               g_vline (x0, y0, y1, color);
  64.               g_vline (x1, y0, y1, color);
  65.             }
  66.         }
  67.     }
  68. }
  69.