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 192 2003-11-16 12:28:29Z sam $ |
---|
7 | * |
---|
8 | * This library is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU Lesser General Public |
---|
10 | * License as published by the Free Software Foundation; either |
---|
11 | * version 2 of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This library 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 GNU |
---|
16 | * Lesser General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU Lesser General Public |
---|
19 | * License along with this library; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
---|
21 | * 02111-1307 USA |
---|
22 | */ |
---|
23 | |
---|
24 | #include "config.h" |
---|
25 | |
---|
26 | #include <stdlib.h> |
---|
27 | |
---|
28 | #include "caca.h" |
---|
29 | #include "caca_internals.h" |
---|
30 | |
---|
31 | void caca_draw_box(int x1, int y1, int x2, int y2, char c) |
---|
32 | { |
---|
33 | caca_draw_line(x1, y1, x1, y2, c); |
---|
34 | caca_draw_line(x1, y2, x2, y2, c); |
---|
35 | caca_draw_line(x2, y2, x2, y1, c); |
---|
36 | caca_draw_line(x2, y1, x1, y1, c); |
---|
37 | } |
---|
38 | |
---|
39 | void caca_draw_thin_box(int x1, int y1, int x2, int y2) |
---|
40 | { |
---|
41 | int x, y, xmax, ymax; |
---|
42 | |
---|
43 | if(x1 > x2) |
---|
44 | { |
---|
45 | int tmp = x1; |
---|
46 | x1 = x2; x2 = tmp; |
---|
47 | } |
---|
48 | |
---|
49 | if(y1 > y2) |
---|
50 | { |
---|
51 | int tmp = y1; |
---|
52 | y1 = y2; y2 = tmp; |
---|
53 | } |
---|
54 | |
---|
55 | xmax = caca_get_width() - 1; |
---|
56 | ymax = caca_get_height() - 1; |
---|
57 | |
---|
58 | if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) |
---|
59 | return; |
---|
60 | |
---|
61 | /* Draw edges */ |
---|
62 | if(y1 >= 0) |
---|
63 | for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++) |
---|
64 | caca_putchar(x, y1, '-'); |
---|
65 | |
---|
66 | if(y2 <= ymax) |
---|
67 | for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++) |
---|
68 | caca_putchar(x, y2, '-'); |
---|
69 | |
---|
70 | if(x1 >= 0) |
---|
71 | for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++) |
---|
72 | caca_putchar(x1, y, '|'); |
---|
73 | |
---|
74 | if(x2 <= xmax) |
---|
75 | for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++) |
---|
76 | caca_putchar(x2, y, '|'); |
---|
77 | |
---|
78 | /* Draw corners */ |
---|
79 | if(x1 >= 0 && y1 >= 0) |
---|
80 | caca_putchar(x1, y1, ','); |
---|
81 | |
---|
82 | if(x1 >= 0 && y2 <= ymax) |
---|
83 | caca_putchar(x1, y2, '`'); |
---|
84 | |
---|
85 | if(x2 <= xmax && y1 >= 0) |
---|
86 | caca_putchar(x2, y1, '.'); |
---|
87 | |
---|
88 | if(x2 <= xmax && y2 <= ymax) |
---|
89 | caca_putchar(x2, y2, '\''); |
---|
90 | } |
---|
91 | |
---|
92 | void caca_fill_box(int x1, int y1, int x2, int y2, char c) |
---|
93 | { |
---|
94 | int x, y, xmax, ymax; |
---|
95 | |
---|
96 | if(x1 > x2) |
---|
97 | { |
---|
98 | int tmp = x1; |
---|
99 | x1 = x2; x2 = tmp; |
---|
100 | } |
---|
101 | |
---|
102 | if(y1 > y2) |
---|
103 | { |
---|
104 | int tmp = y1; |
---|
105 | y1 = y2; y2 = tmp; |
---|
106 | } |
---|
107 | |
---|
108 | xmax = caca_get_width() - 1; |
---|
109 | ymax = caca_get_height() - 1; |
---|
110 | |
---|
111 | if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) |
---|
112 | return; |
---|
113 | |
---|
114 | if(x1 < 0) x1 = 0; |
---|
115 | if(y1 < 0) y1 = 0; |
---|
116 | if(x2 > xmax) x2 = xmax; |
---|
117 | if(y2 > ymax) y2 = ymax; |
---|
118 | |
---|
119 | for(y = y1; y <= y2; y++) |
---|
120 | for(x = x1; x <= x2; x++) |
---|
121 | caca_putchar(x, y, c); |
---|
122 | } |
---|
123 | |
---|