1 | /* |
---|
2 | * libcaca ASCII-Art library |
---|
3 | * Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> |
---|
4 | * All Rights Reserved |
---|
5 | * |
---|
6 | * $Id: box.c 185 2003-11-16 00:33:35Z sam $ |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or modify |
---|
9 | * it under the terms of the GNU General Public License as published by |
---|
10 | * the Free Software Foundation; either version 2 of the License, or |
---|
11 | * (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
21 | */ |
---|
22 | |
---|
23 | #include "config.h" |
---|
24 | |
---|
25 | #include <stdlib.h> |
---|
26 | |
---|
27 | #include "caca.h" |
---|
28 | #include "caca_internals.h" |
---|
29 | |
---|
30 | void caca_draw_box(int x1, int y1, int x2, int y2, char c) |
---|
31 | { |
---|
32 | caca_draw_line(x1, y1, x1, y2, c); |
---|
33 | caca_draw_line(x1, y2, x2, y2, c); |
---|
34 | caca_draw_line(x2, y2, x2, y1, c); |
---|
35 | caca_draw_line(x2, y1, x1, y1, c); |
---|
36 | } |
---|
37 | |
---|
38 | void caca_draw_thin_box(int x1, int y1, int x2, int y2) |
---|
39 | { |
---|
40 | int x, y, xmax, ymax; |
---|
41 | |
---|
42 | if(x1 > x2) |
---|
43 | { |
---|
44 | int tmp = x1; |
---|
45 | x1 = x2; x2 = tmp; |
---|
46 | } |
---|
47 | |
---|
48 | if(y1 > y2) |
---|
49 | { |
---|
50 | int tmp = y1; |
---|
51 | y1 = y2; y2 = tmp; |
---|
52 | } |
---|
53 | |
---|
54 | xmax = caca_get_width() - 1; |
---|
55 | ymax = caca_get_height() - 1; |
---|
56 | |
---|
57 | if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) |
---|
58 | return; |
---|
59 | |
---|
60 | /* Draw edges */ |
---|
61 | if(y1 >= 0) |
---|
62 | for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++) |
---|
63 | caca_putchar(x, y1, '-'); |
---|
64 | |
---|
65 | if(y2 <= ymax) |
---|
66 | for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++) |
---|
67 | caca_putchar(x, y2, '-'); |
---|
68 | |
---|
69 | if(x1 >= 0) |
---|
70 | for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++) |
---|
71 | caca_putchar(x1, y, '|'); |
---|
72 | |
---|
73 | if(x2 <= xmax) |
---|
74 | for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++) |
---|
75 | caca_putchar(x2, y, '|'); |
---|
76 | |
---|
77 | /* Draw corners */ |
---|
78 | if(x1 >= 0 && y1 >= 0) |
---|
79 | caca_putchar(x1, y1, ','); |
---|
80 | |
---|
81 | if(x1 >= 0 && y2 <= ymax) |
---|
82 | caca_putchar(x1, y2, '`'); |
---|
83 | |
---|
84 | if(x2 <= xmax && y1 >= 0) |
---|
85 | caca_putchar(x2, y1, '.'); |
---|
86 | |
---|
87 | if(x2 <= xmax && y2 <= ymax) |
---|
88 | caca_putchar(x2, y2, '\''); |
---|
89 | } |
---|
90 | |
---|
91 | void caca_fill_box(int x1, int y1, int x2, int y2, char c) |
---|
92 | { |
---|
93 | int x, y, xmax, ymax; |
---|
94 | |
---|
95 | if(x1 > x2) |
---|
96 | { |
---|
97 | int tmp = x1; |
---|
98 | x1 = x2; x2 = tmp; |
---|
99 | } |
---|
100 | |
---|
101 | if(y1 > y2) |
---|
102 | { |
---|
103 | int tmp = y1; |
---|
104 | y1 = y2; y2 = tmp; |
---|
105 | } |
---|
106 | |
---|
107 | xmax = caca_get_width() - 1; |
---|
108 | ymax = caca_get_height() - 1; |
---|
109 | |
---|
110 | if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) |
---|
111 | return; |
---|
112 | |
---|
113 | if(x1 < 0) x1 = 0; |
---|
114 | if(y1 < 0) y1 = 0; |
---|
115 | if(x2 > xmax) x2 = xmax; |
---|
116 | if(y2 > ymax) y2 = ymax; |
---|
117 | |
---|
118 | for(y = y1; y <= y2; y++) |
---|
119 | for(x = x1; x <= x2; x++) |
---|
120 | caca_putchar(x, y, c); |
---|
121 | } |
---|
122 | |
---|