1 | /* |
---|
2 | * libee ASCII-Art library |
---|
3 | * Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> |
---|
4 | * All Rights Reserved |
---|
5 | * |
---|
6 | * $Id: box.c 151 2003-11-11 10:22:19Z 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 | #ifdef USE_SLANG |
---|
26 | # include <slang.h> |
---|
27 | #elif USE_NCURSES |
---|
28 | # include <curses.h> |
---|
29 | #endif |
---|
30 | |
---|
31 | #include <stdlib.h> |
---|
32 | |
---|
33 | #include "ee.h" |
---|
34 | |
---|
35 | void ee_draw_box(int x1, int y1, int x2, int y2, char c) |
---|
36 | { |
---|
37 | ee_draw_line(x1, y1, x1, y2, c); |
---|
38 | ee_draw_line(x1, y2, x2, y2, c); |
---|
39 | ee_draw_line(x2, y2, x2, y1, c); |
---|
40 | ee_draw_line(x2, y1, x1, y1, c); |
---|
41 | } |
---|
42 | |
---|
43 | void ee_draw_thin_box(int x1, int y1, int x2, int y2) |
---|
44 | { |
---|
45 | int x, y, xmax, ymax; |
---|
46 | |
---|
47 | if(x1 > x2) |
---|
48 | { |
---|
49 | int tmp = x1; |
---|
50 | x1 = x2; x2 = tmp; |
---|
51 | } |
---|
52 | |
---|
53 | if(y1 > y2) |
---|
54 | { |
---|
55 | int tmp = y1; |
---|
56 | y1 = y2; y2 = tmp; |
---|
57 | } |
---|
58 | |
---|
59 | xmax = ee_get_width() - 1; |
---|
60 | ymax = ee_get_height() - 1; |
---|
61 | |
---|
62 | if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) |
---|
63 | return; |
---|
64 | |
---|
65 | /* Draw edges */ |
---|
66 | if(y1 >= 0) |
---|
67 | for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++) |
---|
68 | ee_putchar(x, y1, '-'); |
---|
69 | |
---|
70 | if(y2 < ymax) |
---|
71 | for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++) |
---|
72 | ee_putchar(x, y2, '-'); |
---|
73 | |
---|
74 | if(x1 >= 0) |
---|
75 | for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++) |
---|
76 | ee_putchar(x1, y, '|'); |
---|
77 | |
---|
78 | if(x2 < xmax) |
---|
79 | for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++) |
---|
80 | ee_putchar(x2, y, '|'); |
---|
81 | |
---|
82 | /* Draw corners */ |
---|
83 | if(x1 >= 0 && y1 >= 0) |
---|
84 | ee_putchar(x1, y1, ','); |
---|
85 | |
---|
86 | if(x1 >= 0 && y2 <= ymax) |
---|
87 | ee_putchar(x1, y2, '`'); |
---|
88 | |
---|
89 | if(x2 <= xmax && y1 >= 0) |
---|
90 | ee_putchar(x2, y1, '.'); |
---|
91 | |
---|
92 | if(x2 <= xmax && y2 <= ymax) |
---|
93 | ee_putchar(x2, y2, '\''); |
---|
94 | } |
---|
95 | |
---|
96 | void ee_fill_box(int x1, int y1, int x2, int y2, char c) |
---|
97 | { |
---|
98 | int x, y, xmax, ymax; |
---|
99 | |
---|
100 | if(x1 > x2) |
---|
101 | { |
---|
102 | int tmp = x1; |
---|
103 | x1 = x2; x2 = tmp; |
---|
104 | } |
---|
105 | |
---|
106 | if(y1 > y2) |
---|
107 | { |
---|
108 | int tmp = y1; |
---|
109 | y1 = y2; y2 = tmp; |
---|
110 | } |
---|
111 | |
---|
112 | xmax = ee_get_width() - 1; |
---|
113 | ymax = ee_get_height() - 1; |
---|
114 | |
---|
115 | if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) |
---|
116 | return; |
---|
117 | |
---|
118 | if(x1 < 0) x1 = 0; |
---|
119 | if(y1 < 0) y1 = 0; |
---|
120 | if(x2 > xmax) x2 = xmax; |
---|
121 | if(y2 > ymax) y2 = ymax; |
---|
122 | |
---|
123 | for(y = y1; y <= y2; y++) |
---|
124 | for(x = x1; x <= x2; x++) |
---|
125 | ee_putchar(x, y, c); |
---|
126 | } |
---|
127 | |
---|