home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / tc20 / cbar.c < prev    next >
Text File  |  1988-10-13  |  4KB  |  121 lines

  1. /*      CBAR.C
  2.  
  3.     Beispielprogramm für das Einbinden von C-Routinen in
  4.     Turbo Prolog-Programme
  5.  
  6.         Copyright (c) Borland International 1987,88
  7.         All Rights Reserved.
  8. */
  9.  
  10. #include <dos.h>
  11.  
  12. videodot(int x, int y, int color)
  13. { union REGS inr,outr;
  14.  
  15.   inr.h.ah = 12;             /* "Write pixel" */
  16.   inr.h.al = color;
  17.   inr.x.cx = x;
  18.   inr.x.dx = y;
  19.   _int86(16,&inr,&outr); /* BIOS-Interrupt: "Video services" */
  20. }
  21.  
  22. /* Zeichnet eine Linie vom Punkt (x1, y1) nach (x2, y2) in der
  23.    angegebenen Farbe */
  24. line(int x1, int y1, int x2, int y2, int color)
  25. { int xdelta;  /* Gesamt-Veränderung X-Koordinaten */
  26.   int ydelta;  /* dito für Y-Koordinaten */
  27.   int xstep;   /* Schrittweite für X */
  28.   int ystep;   /* dito für Y */
  29.   int change;  /* Gesamt-Veränderung X oder Y */
  30.  
  31.   xdelta = x2 - x1;               /* X-Distanz */
  32.   ydelta = y2 - y1;               /* Y-Distanz */
  33.   if (xdelta < 0)
  34.   { xdelta = -xdelta;  /* Linie von rechts nach links zeichnen */
  35.     xstep = -1;
  36.   }
  37.   else /* Linie von links nach rechts */
  38.     xstep = 1;
  39.   if (ydelta < 0)
  40.   { ydelta = -ydelta; /* Linie von unten nach oben */
  41.     ystep = -1;
  42.   }
  43.   else /* Linie von oben nach unten */
  44.     ystep = 1;
  45.   if (xdelta > ydelta)    /* x ändert sich schneller als y */
  46.   { change = xdelta >> 1;  /* xdelta * 2 */
  47.     while (x1 != x2)           /* Zeichnen bis zum abschließenden Punkt */
  48.     { videodot(x1, y1, color);        /* ein Pixel */
  49.       x1 += xstep;                    /* nächste X-Koordinate */
  50.       change += ydelta;               /* Gesamt-Veränderung */
  51.       if (change > xdelta)
  52.       { y1 += ystep;       /* nächste Y-Koordinate */
  53.     change -= xdelta;  /* Zähler wieder auf den Anfang  */
  54.       }
  55.     }
  56.   }
  57.   else /* y ändert sich schneller als x */
  58.   {
  59.     change = ydelta >> 1;  /* ydelta * 2 */
  60.     while (y1 != y2)           /* Zeichnen bis zum abschließenden Punkt */
  61.     { videodot(x1, y1, color);        /* ein Pixel */
  62.       y1 += ystep;                    /* nächste Y-Koordinate */
  63.       change += xdelta;                       /* Gesamt-Veränderung */
  64.       if (change > ydelta)
  65.            /* Y-Veränderung groß genug für Veränderung von X? */
  66.       { x1 += xstep;            /* ja - nächste X-Koordinate */
  67.     change -= ydelta;       /* Zähler wieder auf den Anfang */
  68.       }
  69.     }
  70.   }
  71. } /* line */
  72.  
  73. cbar_0(int x1, int y1, int width, int height, int color)
  74. { int count;  /* Zähler für das Ausfüllen des Balkens */
  75.   int x2, y2, x3, y3, x4, y4;  /* zusätzliche Punkte im Balken */
  76.   int wfactor;    /* Anzahl Pixel für die Verschiebung nach rechts */
  77.   int hfactor;    /* dito für die Verschiebung nach oben */
  78. /*
  79.  
  80. Der Zusammenhang der X- und Y-Werte sieht so aus:
  81.  
  82.         x1 x2   x3 x4
  83.     |  |    |  |
  84.     |  v    |  v
  85.     y2--|>/┌────|──┐
  86.     v/ │    v /│
  87.     y1->╔═══════╗/ │
  88.     ║  │    ║  │
  89.     ║  │    ║  │
  90.     ║  │    ║  │
  91.     ║  │    ║  │
  92.     ║  │    ║  │
  93.     y3---->└────║──┘
  94.     ║ /    ║ /
  95.     y4->╚═══════╝/
  96.  
  97. */
  98.  
  99.   wfactor = width / 5;  hfactor = height / 12;
  100.   x2 = x1 + wfactor;       /* Position der einzelnen Eckpunkte */
  101.   x3 = x1 + width;
  102.   x4 = x3 + wfactor;
  103.   y2 = y1 - hfactor;
  104.   y3 = y1 + height - hfactor;
  105.   y4 = y1 + height;
  106.   line(x1, y1, x3, y1, 2);        /* Vorderseite des Balkens */
  107.   line(x3, y1, x3, y4, 2);
  108.   line(x3, y4, x1, y4, 2);
  109.   line(x1, y4, x1, y1, 2);
  110.   line(x3, y1, x4, y2, 2);        /* rechte Seitenfläche */
  111.   line(x4, y2, x4, y3, 2);
  112.   line(x4, y3, x3, y4, 2);
  113.   line(x1, y1, x2, y2, 2);        /* obere Seitenfläche */
  114.   line(x2, y2, x4, y2, 2);
  115.   line(x1, y4, x2, y3, 3);
  116.   line(x2, y3, x4, y3, 3);        /* Rückseite */
  117.   line(x2, y3, x2, y2, 3);
  118.   for (count = y1 + 1; count < y4; count++)         /* Vorderseite füllen */
  119.     line(x1 + 1, count, x3, count, color);
  120. } /* cbar_0 */
  121.