Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / libx / object / xline.c
blob99ce50b0235b95862fb76bf3e1232dca5f9649fd
1 /*
2 * ZeX/OS
3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <libx/base.h>
21 void xline (unsigned x1, unsigned y1, unsigned x2, unsigned y2, unsigned color)
22 {// x1 = 450, y1 = 200, x1 = 500, y2 = 250 -- ok
23 // x1 = 450, y1 = 250, x1 = 500, y2 = 200 -- spatne
25 float opacnex = 1;
26 float opacney = 1;
28 /* vektor s(delkax, delkay) */
29 int delkax = 0;
30 int delkay = 0;
32 if (x1 > x2) {
33 opacnex = -1;
34 delkax = (signed) x1 - (signed) x2;
35 } else
36 delkax = (signed) x2 - (signed) x1;
38 if (y1 > y2) {
39 opacney = -1;
40 delkay = (signed) y1 - (signed) y2;
41 } else
42 delkay = (signed) y2 - (signed) y1;
44 int a = 0;
45 int b = 0;
47 if (delkax == 0) {
48 for (b = y1; b <= ((signed) y1+delkay); b ++)
49 xpixel (x1, b, color);
51 return;
54 if (delkay == 0) {
55 for (a = x1; a <= ((signed) x1+delkax); a ++)
56 xpixel (a, y1, color);
58 return;
61 /* parametricka rovnice */
62 float i = 0;
63 unsigned last_x = 0;
64 unsigned last_y = 0;
66 while (i < 1) {
67 float x = (float) x1 + (float) delkax * i * opacnex;
68 float y = (float) y1 + (float) delkay * i * opacney;
70 if (last_x != x && last_y != y)
71 xpixel ((unsigned) x, (unsigned) y, color);
73 last_x = (unsigned) x;
74 last_y = (unsigned) y;
76 i += 0.01f;