void ventana_alerta(char *ptr) { SDL_Rect pos; pos.x=200;pos.y=230; SDL_BlitSurface(window_alerta,NULL,screen,&pos); print_on_screen(ptr,280,260,fcolor,font); pos.x=440;pos.y=340; SDL_BlitSurface(boton_ok[0],NULL,screen,&pos); SDL_Flip(screen); SDL_Event evento; while(1) { SDL_WaitEvent(&evento); if(evento.type==SDL_MOUSEMOTION) { if(posicion_cursor(440,505,340,363,evento.motion.x,evento.motion.y)) SDL_BlitSurface(boton_ok[1],NULL,screen,&pos); else SDL_BlitSurface(boton_ok[0],NULL,screen,&pos); SDL_Flip(screen); } else if(evento.type==SDL_MOUSEBUTTONDOWN) { if(posicion_cursor(440,505,340,363,evento.button.x,evento.button.y)) { draw_interface_principal(); print_arbol(A,0); SDL_Flip(screen); return; } } if(evento.type==SDL_KEYDOWN && evento.key.keysym.sym==27) { draw_interface_principal(); draw_menu_botones(); SDL_Flip(screen); return; } } }
void print_arbol(ARBOL A,int n) { if(A==NULL) return; if(A->der!=NULL) { SDL_Rect posi; posi.y=(A->pos).y+10; posi.x=(A->pos).x+20; SDL_BlitSurface(flechader[n],NULL,screen,&posi); } if(A->izq!=NULL) { SDL_Rect posi; posi.y=(A->pos).y+10; posi.x=(A->pos).x-((flechaizq[n]->w-20)); SDL_BlitSurface(flechaizq[n],NULL,screen,&posi); } SDL_BlitSurface(nodo_img,NULL,screen,&(A->pos)); char c[5]; sprintf(c,"%d",A->dato); print_on_screen(&c[0],A->pos.x+6,A->pos.y+6,fcolor,arbol_ttf); //SDL_Flip(screen); print_arbol(A->izq,n+1); print_arbol(A->der,n+1); }
void menu_principal() { SDL_Rect pos; pos.x=0; pos.y=0; SDL_BlitSurface(img_principal,NULL,screen,&pos); SDL_Flip(screen); SDL_Event evento; int i=0; while(1) { SDL_WaitEvent(&evento); if(evento.type==SDL_MOUSEBUTTONDOWN) { if(posicion_cursor(200,680,90,190,evento.button.x,evento.button.y)) { SDL_BlitSurface(fondo,NULL,screen,&pos); draw_interface_principal(); calcular_posiciones(A,70,450,450,0); print_arbol(A,0); SDL_Flip(screen); return; } else if(posicion_cursor(200,680,200,290,evento.button.x,evento.button.y)) { ventana_explicacion(); return; } else if(posicion_cursor(200,680,300,390,evento.button.x,evento.button.y)) { ventana_ayuda(); return; } else if(posicion_cursor(200,680,400,490,evento.button.x,evento.button.y)) { ventana_acerca(); return; } else if(posicion_cursor(200,680,500,590,evento.button.x,evento.button.y)) { SDL_Quit(); exit(0); } } } }
void imprimir(abb_t* arbol){ print_arbol(arbol->raiz); }
//FUNCIONES AUXILIARES void print_arbol(nodo_t* nodo){ if(!nodo)return; print_arbol(nodo->nodo_izquierdo); printf("%s\n",nodo->clave); print_arbol(nodo->nodo_derecho); }
int main(int argc, char *argv[]) { //inicializando SDL if(SDL_Init(SDL_INIT_VIDEO)<0) { printf("Error al establecer modo video\n");exit(1);} SDL_WM_SetCaption("Prueba_botones",NULL); screen=SDL_SetVideoMode(ancho,alto,24,SDL_SWSURFACE); if(screen==NULL) { printf("No se establecio el modo de video\n"); exit(1); } //font TTF_Init(); font_num=TTF_OpenFont("fonts/quid.ttf",60); if(font_num==NULL) printf("Error al cargar font\n"); font_menu=TTF_OpenFont("fonts/font_menu.ttf",80); if(font_menu==NULL) printf("Error al cargar font_menu\n"); font=TTF_OpenFont("fonts/FUAA.ttf",34); if(font==NULL) printf("Error en font\n"); font_op=TTF_OpenFont("fonts/FUAA.ttf",20); arbol_ttf=TTF_OpenFont("fonts/arbol.ttf",25); if(arbol_ttf==NULL) printf("Error al cargar arbol\n"); recorrido_ttf=TTF_OpenFont("fonts/arbol.ttf",17); fcolor.r=0; fcolor.g=0; fcolor.b=0; //principal A=NULL; int opcion=-1,n,dato; SDL_Rect pos; cargando_interface(); menu_principal(); draw_interface_principal(); SDL_Event evento; while(opcion!=0) { SDL_WaitEvent(&evento); if(evento.type==SDL_MOUSEMOTION) { if(posicion_cursor(20,85,12,35,evento.motion.x,evento.motion.y)) { pos.x=20; pos.y=12; SDL_BlitSurface(boton_insertar[1],NULL,screen,&pos); } else if(posicion_cursor(145,210,12,35,evento.motion.x,evento.motion.y)) { pos.x=145; pos.y=12; SDL_BlitSurface(boton_eliminar[1],NULL,screen,&pos); } else if(posicion_cursor(270,335,12,35,evento.motion.x,evento.motion.y)) { pos.x=270; pos.y=12; SDL_BlitSurface(boton_recorridos[1],NULL,screen,&pos); } else if(posicion_cursor(820,885,12,35,evento.motion.x,evento.motion.y)) { pos.x=820; pos.y=12; SDL_BlitSurface(boton_salir[1],NULL,screen,&pos); } else draw_menu_botones(); SDL_Flip(screen); } else if(evento.type==SDL_MOUSEBUTTONDOWN) { if(posicion_cursor(820,885,12,35,evento.button.x,evento.button.y)) { menu_principal(); } else if(posicion_cursor(20,85,12,35,evento.button.x,evento.button.y)) { dato=mini_ventana("Insertar dato: ",1); if(bandera!=0 && nivel_superado(A,0,dato)) ventana_alerta("La rama supero el maximo"); else { if(bandera!=0) insertar_arbol(&A,dato); calcular_posiciones(A,70,450,450,0); } print_arbol(A,0); SDL_Flip(screen); } else if(posicion_cursor(145,210,12,35,evento.button.x,evento.button.y)) { dato=mini_ventana("Eliminar dato: ",2); eliminar(&A,dato); draw_interface_principal(); calcular_posiciones(A,70,450,450,0); print_arbol(A,0); SDL_Flip(screen); } else if(posicion_cursor(270,335,12,35,evento.button.x,evento.button.y)) { ventana_recorridos(); } } else if(evento.type==SDL_KEYDOWN) { switch(evento.key.keysym.sym) { case SDLK_1: { dato=mini_ventana("Insertar dato: ",1); if(bandera!=0 && nivel_superado(A,0,dato)) ventana_alerta("La rama supero el maximo"); else { if(bandera!=0) insertar_arbol(&A,dato); calcular_posiciones(A,70,450,450,0); } print_arbol(A,0); SDL_Flip(screen); break; } case SDLK_2: { dato=mini_ventana("Eliminar dato: ",2); eliminar(&A,dato); draw_interface_principal(); calcular_posiciones(A,70,450,450,0); print_arbol(A,0); SDL_Flip(screen); break; } case SDLK_4: { menu_principal(); break; } case SDLK_3: { ventana_recorridos(); break; } } } } SDL_Quit(); return 0; }
void ventana_recorridos() { SDL_Rect pos; char c[40]; pos.x=300; pos.y=251; SDL_BlitSurface(mini_window,NULL,screen,&pos); sprintf(c,"Recorridos :"); print_on_screen(&c[0],370,260,fcolor,font); pos.x+=110;pos.y+=50; SDL_BlitSurface(tipos_recorridos[0][0],NULL,screen,&pos); pos.y+=30; SDL_BlitSurface(tipos_recorridos[1][0],NULL,screen,&pos); pos.y+=30; SDL_BlitSurface(tipos_recorridos[2][0],NULL,screen,&pos); pos.x+=119;pos.y+=34; SDL_BlitSurface(boton_cancelar[0],NULL,screen,&pos); SDL_Flip(screen); int n=1; SDL_Event evento; while(n) { SDL_WaitEvent(&evento); if(evento.type==SDL_MOUSEMOTION) { if(posicion_cursor(410,410+tipos_recorridos[0][0]->w,301,301+tipos_recorridos[0][0]->h,evento.motion.x,evento.motion.y)) { pos.x=410; pos.y=301; SDL_BlitSurface(tipos_recorridos[0][1],NULL,screen,&pos); } else if(posicion_cursor(410,410+tipos_recorridos[1][0]->w,331,331+tipos_recorridos[1][0]->h,evento.motion.x,evento.motion.y)) { pos.x=410; pos.y=331, SDL_BlitSurface(tipos_recorridos[1][1],NULL,screen,&pos); } else if(posicion_cursor(410,410+tipos_recorridos[1][0]->w,361,361+tipos_recorridos[1][0]->h,evento.motion.x,evento.motion.y)) { pos.x=410; pos.y=361; SDL_BlitSurface(tipos_recorridos[2][1],NULL,screen,&pos); } else if(posicion_cursor(529,529+boton_cancelar[0]->w,395,395+boton_cancelar[0]->h,evento.motion.x,evento.motion.y)) { pos.x=529; pos.y=395; SDL_BlitSurface(boton_cancelar[1],NULL,screen,&pos); } else { pos.x=410; pos.y=301; SDL_BlitSurface(tipos_recorridos[0][0],NULL,screen,&pos); pos.x=410; pos.y=331, SDL_BlitSurface(tipos_recorridos[1][0],NULL,screen,&pos); pos.x=410; pos.y=361; SDL_BlitSurface(tipos_recorridos[2][0],NULL,screen,&pos); pos.x=529; pos.y=395; SDL_BlitSurface(boton_cancelar[0],NULL,screen,&pos); } SDL_Flip(screen); } else if(evento.type==SDL_MOUSEBUTTONDOWN) { if(posicion_cursor(410,410+tipos_recorridos[0][0]->w,301,301+tipos_recorridos[0][0]->h,evento.button.x,evento.button.y)) { draw_interface_principal(); print_arbol(A,0); SDL_Rect recta_pos={0,600,900,80}; SDL_FillRect(screen,&recta_pos,SDL_MapRGBA(screen->format,183,181,182,0)); char c[40]; sprintf(c,"Recorrido Inorder :"); print_on_screen(&c[0],30,600,fcolor,font_op);distancia=0; SDL_Flip(screen); inorden(A); return; } else if(posicion_cursor(410,410+tipos_recorridos[1][0]->w,331,331+tipos_recorridos[1][0]->h,evento.button.x,evento.button.y)) { draw_interface_principal(); print_arbol(A,0); SDL_Rect recta_pos={0,600,900,80}; SDL_FillRect(screen,&recta_pos,SDL_MapRGBA(screen->format,183,181,182,0)); char c[40]; sprintf(c,"Recorrido Preorder :"); print_on_screen(&c[0],30,600,fcolor,font_op);distancia=0; SDL_Flip(screen); preorden(A); return; } else if(posicion_cursor(410,410+tipos_recorridos[1][0]->w,361,361+tipos_recorridos[1][0]->h,evento.button.x,evento.button.y)) { draw_interface_principal(); print_arbol(A,0); SDL_Rect recta_pos={0,600,900,80}; SDL_FillRect(screen,&recta_pos,SDL_MapRGBA(screen->format,183,181,182,0)); char c[40]; sprintf(c,"Recorrido Posorder :"); print_on_screen(&c[0],30,600,fcolor,font_op);distancia=0; SDL_Flip(screen); postorden(A); return; } else if(posicion_cursor(529,529+boton_cancelar[0]->w,395,395+boton_cancelar[0]->h,evento.button.x,evento.button.y)) { draw_interface_principal(); print_arbol(A,0); SDL_Flip(screen); return; } } else if(evento.type==SDL_KEYDOWN && evento.key.keysym.sym==27) { draw_interface_principal(); draw_menu_botones(); print_arbol(A,0); SDL_Flip(screen); return; } } SDL_Flip(screen); }