-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdraw.c
198 lines (146 loc) · 5.42 KB
/
draw.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include "draw.h"
struct winsize ww;
void Texto(int AnchoPlano,int AltoPlano);
void Caracter(short AnchoPlano,short AltoPlano);
typedef struct{
short Xcursor;
short Ycursor;
}Coordenada;
Coordenada draw;
Coordenada caracteres;
//Bucles
short l,i,j;
//Tecla
char T;
//Matriz del dibujo
char plano[1000][1000];
//Id del caracter igual al caracter inicial (#)
short C = 0;
//Caracteres
char Caracteres[]="# a b c d e f g h i j k m n l o p q r s t u v w x y z A B C D E F G H I J K M N L O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 @ : ; ¿ ? ¡ ! / \\ ( ) [ ] { } < > « » ═ ║ ╔ ╗ ╚ ╝ ╠ ╣ ╦ ╩ ╬ ╭ ╮ ╰ ╯ ╳ ▁ ▂ ▃ ▄ ▅ ▆ ▇ ▉ ▒ ░ ▚ ▞ ■ □ ▢ ▤ ▥ ▦ ▧ ▨ ▩";
//Variable auxiliar
short aux;
//Para saber en que caracter empezar a imprimir la paleta de caracteres
short Contador;
void Dibujo(){
//Ubicacion inicial del cursor
draw.Xcursor = 2;
draw.Ycursor = 3;
ioctl(0, TIOCGWINSZ, &ww);
//Ancho y largo dentro del marco
const short AnchoPlano = ww.ws_col;
const short AltoPlano = ww.ws_row-2;
Gotoxy(draw.Xcursor,draw.Ycursor);
do{
//Actualizacion de dibujo en pantalla
for(i=2;i<AnchoPlano;i++){for(j=3;j<AltoPlano;j++){if(plano[i][j]!='\0'){Gotoxy(i,j); printf("%c", plano[i][j] );}}}
//Actualizacion de cursor
Gotoxy(draw.Xcursor,draw.Ycursor);
//Pidiendo tecla por... teclado :V
T = Getch();
//Controles
switch(T){
case ARRIBA :draw.Ycursor--; break;
case PRINT_ARRIBA :plano[draw.Xcursor][draw.Ycursor]=Caracteres[C]; draw.Ycursor--; break;
case ABAJO :draw.Ycursor++; break;
case PRINT_ABAJO :plano[draw.Xcursor][draw.Ycursor]=Caracteres[C]; draw.Ycursor++; break;
case IZQUIERDA :draw.Xcursor--; break;
case PRINT_IZQUIERDA :plano[draw.Xcursor][draw.Ycursor]=Caracteres[C]; draw.Xcursor--; break;
case DERECHA :draw.Xcursor++; break;
case PRINT_DERECHA :plano[draw.Xcursor][draw.Ycursor]=Caracteres[C]; draw.Xcursor++; break;
case PRINT :plano[draw.Xcursor][draw.Ycursor]=Caracteres[C]; break;
case RESET :for(i=1;i<AnchoPlano;i++){
for(j=1;j<AltoPlano;j++){
if (plano[i][j]){ Gotoxy(i,j); printf(" "); }
plano[i][j] = '\0';
}
}break;
case TEXTO :Texto(AnchoPlano,AltoPlano); break;
case DELETE :plano[draw.Xcursor][draw.Ycursor]='\0';
Gotoxy(draw.Xcursor,draw.Ycursor);printf(" "); break;
case CARACTERES :Caracter(AnchoPlano,AltoPlano);
}
//Teletransportacion de cursor :V
if(draw.Ycursor < 3 ) { draw.Ycursor=AltoPlano-1; }
if(draw.Xcursor < 2 ) { draw.Xcursor=AnchoPlano-1; }
if(draw.Ycursor > AltoPlano-1 ) { draw.Ycursor=3; }
if(draw.Xcursor > AnchoPlano-1 ) { draw.Xcursor=2; }
}while(T !=EXIT);
}
void Texto(int AnchoPlano,int AltoPlano){
//Ubiacion inicial del cursor al abrir el mapa de caracteres
caracteres.Xcursor = 3;
caracteres.Ycursor = 1;
draw.Xcursor--;
char T;
int Xinicio = draw.Xcursor-1;
int Yinicio = draw.Ycursor-1;
Gotoxy(draw.Xcursor+1,draw.Ycursor);
do {
T=Getch();
plano[draw.Xcursor+1][draw.Ycursor]=T;
/*if (T==9) {printf("\t"); }
else*/ if (T==-61){printf("%s","ñ"); }
else {printf("%c",T); }
//Permite borrar caracteres
if (T == DELETE && draw.Ycursor != AltoPlano-1){
plano[draw.Xcursor][draw.Ycursor]='\0';
Gotoxy(draw.Xcursor,draw.Ycursor);
printf(" ");
if (draw.Xcursor != Xinicio+1) draw.Xcursor--;
//else if (draw.Ycursor >=) draw.Ycursor--
}
//else if (T == DELETE && draw.Ycursor >= AltoPlano-1){ draw.Ycursor=3; draw.Xcursor=Xinicio;}
//Permite los saltos de linea
if (T == ENTER && draw.Ycursor != AltoPlano-1){ draw.Ycursor++; draw.Xcursor=Xinicio;}
else if (T == ENTER && draw.Ycursor >= AltoPlano-1){ draw.Ycursor=3; draw.Xcursor=Xinicio;}
//Permite que no se baya del marco
if (draw.Xcursor >= AnchoPlano-2 && draw.Ycursor != AltoPlano-1){draw.Xcursor=Xinicio; draw.Ycursor++;}
else if (draw.Xcursor >= AnchoPlano-2 && draw.Ycursor >= AltoPlano-1){draw.Xcursor=Xinicio; draw.Ycursor=3;}
if(T!=DELETE)draw.Xcursor++;
Gotoxy(draw.Xcursor+1,draw.Ycursor);
}while(T!=EXIT);
}
void Caracter(short AnchoPlano,short AltoPlano){
if ( Contador == '\0' ){ Contador = 0; }
Gotoxy(1,1);
Textcolor(Black,BG_White);
printf("< ");
for (i = Contador; i < AnchoPlano-2; i++)
{
printf("%c", Caracteres[i]);
}
Gotoxy(AnchoPlano,1);
printf(">");
if (caracteres.Xcursor == '\0'){ caracteres.Xcursor = 3; }
Gotoxy(caracteres.Xcursor,1);
do{
T = Getch();
if (T == DERECHA && caracteres.Xcursor <= AnchoPlano-6 ){ caracteres.Xcursor+=2; }
else if (T == IZQUIERDA && caracteres.Xcursor >= 2 ){ caracteres.Xcursor-=2; }
//Permite el moviomiento
if (T == DERECHA && caracteres.Xcursor == AnchoPlano-4 && Contador <= 230){
Contador+=2;
Gotoxy(3,1);
for (i = Contador; i < AnchoPlano-2; i++)
{
printf("%c", Caracteres[i]);
}
}
if (T == ENTER){ C = caracteres.Xcursor-1+Contador;}
Gotoxy(caracteres.Xcursor+2,caracteres.Ycursor);
}while(T != ENTER);
//Imprecion de la barra original
ioctl(0, TIOCGWINSZ, &ww);
const short AnchoBarra = ww.ws_col+1;
for (short i = 1; i < AnchoBarra; i++)
{
Gotoxy(i,1);
Textcolor(Black,BG_White);
printf(" ");;
}
Gotoxy((AnchoBarra/2)-4,1);
printf("Chardraw");
Gotoxy(AnchoBarra,1);
Textcolor(White,none);
}