home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turbo Toolbox
/
Turbo_Toolbox.iso
/
tc20
/
cbar.c
< prev
next >
Wrap
Text File
|
1988-10-13
|
4KB
|
121 lines
/* CBAR.C
Beispielprogramm für das Einbinden von C-Routinen in
Turbo Prolog-Programme
Copyright (c) Borland International 1987,88
All Rights Reserved.
*/
#include <dos.h>
videodot(int x, int y, int color)
{ union REGS inr,outr;
inr.h.ah = 12; /* "Write pixel" */
inr.h.al = color;
inr.x.cx = x;
inr.x.dx = y;
_int86(16,&inr,&outr); /* BIOS-Interrupt: "Video services" */
}
/* Zeichnet eine Linie vom Punkt (x1, y1) nach (x2, y2) in der
angegebenen Farbe */
line(int x1, int y1, int x2, int y2, int color)
{ int xdelta; /* Gesamt-Veränderung X-Koordinaten */
int ydelta; /* dito für Y-Koordinaten */
int xstep; /* Schrittweite für X */
int ystep; /* dito für Y */
int change; /* Gesamt-Veränderung X oder Y */
xdelta = x2 - x1; /* X-Distanz */
ydelta = y2 - y1; /* Y-Distanz */
if (xdelta < 0)
{ xdelta = -xdelta; /* Linie von rechts nach links zeichnen */
xstep = -1;
}
else /* Linie von links nach rechts */
xstep = 1;
if (ydelta < 0)
{ ydelta = -ydelta; /* Linie von unten nach oben */
ystep = -1;
}
else /* Linie von oben nach unten */
ystep = 1;
if (xdelta > ydelta) /* x ändert sich schneller als y */
{ change = xdelta >> 1; /* xdelta * 2 */
while (x1 != x2) /* Zeichnen bis zum abschließenden Punkt */
{ videodot(x1, y1, color); /* ein Pixel */
x1 += xstep; /* nächste X-Koordinate */
change += ydelta; /* Gesamt-Veränderung */
if (change > xdelta)
{ y1 += ystep; /* nächste Y-Koordinate */
change -= xdelta; /* Zähler wieder auf den Anfang */
}
}
}
else /* y ändert sich schneller als x */
{
change = ydelta >> 1; /* ydelta * 2 */
while (y1 != y2) /* Zeichnen bis zum abschließenden Punkt */
{ videodot(x1, y1, color); /* ein Pixel */
y1 += ystep; /* nächste Y-Koordinate */
change += xdelta; /* Gesamt-Veränderung */
if (change > ydelta)
/* Y-Veränderung groß genug für Veränderung von X? */
{ x1 += xstep; /* ja - nächste X-Koordinate */
change -= ydelta; /* Zähler wieder auf den Anfang */
}
}
}
} /* line */
cbar_0(int x1, int y1, int width, int height, int color)
{ int count; /* Zähler für das Ausfüllen des Balkens */
int x2, y2, x3, y3, x4, y4; /* zusätzliche Punkte im Balken */
int wfactor; /* Anzahl Pixel für die Verschiebung nach rechts */
int hfactor; /* dito für die Verschiebung nach oben */
/*
Der Zusammenhang der X- und Y-Werte sieht so aus:
x1 x2 x3 x4
| | | |
| v | v
y2--|>/┌────|──┐
v/ │ v /│
y1->╔═══════╗/ │
║ │ ║ │
║ │ ║ │
║ │ ║ │
║ │ ║ │
║ │ ║ │
y3---->└────║──┘
║ / ║ /
y4->╚═══════╝/
*/
wfactor = width / 5; hfactor = height / 12;
x2 = x1 + wfactor; /* Position der einzelnen Eckpunkte */
x3 = x1 + width;
x4 = x3 + wfactor;
y2 = y1 - hfactor;
y3 = y1 + height - hfactor;
y4 = y1 + height;
line(x1, y1, x3, y1, 2); /* Vorderseite des Balkens */
line(x3, y1, x3, y4, 2);
line(x3, y4, x1, y4, 2);
line(x1, y4, x1, y1, 2);
line(x3, y1, x4, y2, 2); /* rechte Seitenfläche */
line(x4, y2, x4, y3, 2);
line(x4, y3, x3, y4, 2);
line(x1, y1, x2, y2, 2); /* obere Seitenfläche */
line(x2, y2, x4, y2, 2);
line(x1, y4, x2, y3, 3);
line(x2, y3, x4, y3, 3); /* Rückseite */
line(x2, y3, x2, y2, 3);
for (count = y1 + 1; count < y4; count++) /* Vorderseite füllen */
line(x1 + 1, count, x3, count, color);
} /* cbar_0 */