int main(int argc, char ** argv) { SDLS_init("test"); net_init("127.0.0.1",5000,5001); TTF_Font * ttfFont2= SDLS_loadFont("fonts\\arial.ttf",15); SDL_Texture *texture_text3= SDLS_loadText(ttfFont2,"utiliser les flèches du clavier...", 0,0,0); int quit=false; SDL_Event event; // handle events while (!quit) { SDL_WaitEvent(&event); // c'est bloquant... switch (event.type) { case SDL_QUIT: quit = true; break; case SDL_KEYDOWN: // sur l'utilisation du clavier on bouge la forme switch (event.key.keysym.sym) { case SDLK_LEFT: net_send("L"); break; case SDLK_RIGHT: net_send("R"); break; case SDLK_UP: net_send("U"); break; case SDLK_DOWN: net_send("D"); break; } } // couleur du fond en blanc SDLS_eraseWithBackgroundColor(255,255,255); SDLS_copyTexture(texture_text3,SDLS_getScreenWidth()-200,SDLS_getScreenHeight()-30); // test de modification des pixels, ici on assombrit toute l'image. // sombre(); //affichage du rendeder SDLS_displayAll(); } // cleanup SDL SDL_DestroyTexture(texture_text3); //Remove timer in case the call back was not called SDLS_cleanup(); return 0; }
int ihm1() { SDL_Texture *tmp_Tx; SDL_Event event; SDL_Rect rectLabelCoup = { 10 * CASE, 16 * CASE + 16, 0, 0 }; SDL_Rect rectSendMoves = { 7 * CASE, 17 * CASE, 64, 64 }; SDL_Rect rectReset = { 10 * CASE, 17 * CASE, 64, 64 }; SDL_Rect rectCoup = { 12 * CASE, 17 * CASE, CASE * 4, 64 }; SDL_Rect rectEmpty = { 0, 0, 64, 32 }; SDL_Rect rectUser = { 512, 32, 256, 32 }; SDL_Rect rectTime = { 3 * CASE, 17 * CASE, 2 * CASE, 32 }; SDL_Rect rectVoir = { 19 * CASE, 17 * CASE, 64, 64 }; SDL_Rect rectArret = { 16 * CASE, 17 * CASE, 64, 64 }; SDL_Rect rectSuivant = { 22 * CASE, 17 * CASE, 64, 64 }; Direction direction; int robotSelected; bool_t focusCoup, preFocusCoup; bool_t focusUser, preFocusUser; int userSelected; char message[256]; char move[3]; char timeChaine[32]; int lenCoups; char* labelCoup = "Veuillez entrer le nombre de coups :"; int x, y, i; /*initialisation*/ SDLS_init(768, 608, &win, &ren); if (TTF_Init() == -1) { fprintf(stderr, "Erreur d'initialisation de TTF_Init : %s\n", TTF_GetError()); } empty_Tx = IMG_LoadTexture(ren, "assets/inputField.png"); font = TTF_OpenFont("assets/dayrom.TTF", 12); /*** Show **/ displayAccueil(win, ren); SDLS_affiche_image("assets/pl.png", ren, 0, 0); awaitLoadingTexte("attente de session ", PHASE_SESSION); focusCoup = preFocusCoup = FALSE; focusUser = preFocusUser = FALSE; userSelected = robotSelected = -1; direction = NONE; lenCoups = 0; memset(message, 0, sizeof(message)); memset(moves, 0, sizeof(moves)); memset(move, 0, sizeof(move)); memset(coups, 0, sizeof(coups)); if (!quit) { awaitLoadingTexte("attente d'enigme ", PHASE_REFLEX); // display labelCoup tmp_Tx = txt2Texture(ren, font, &colorBlack, labelCoup); SDL_QueryTexture(tmp_Tx, NULL, NULL, &rectLabelCoup.w, &rectLabelCoup.h); SDL_RenderCopy(ren, tmp_Tx, NULL, &rectLabelCoup); SDL_RenderPresent(ren); TTF_CloseFont(font); font = TTF_OpenFont("assets/dayrom.TTF", 20); } SDL_StartTextInput(); int k, save_yUser; while (!quit) { SDL_WaitEvent(&event); switch (event.type) { case SDL_MOUSEBUTTONDOWN: // handle send moves or coups numbers of moves if (estContenu(&rectSendMoves, &event.motion)) { if (currentPhase == PHASE_REFLEX && strlen(coups) > 0) { send_request(sc, 3, SOLUTION, myName, coups); } else if (currentPhase == PHASE_ENCHERE && strlen(coups) > 0) { valideCoups = (valideCoups == -1) ? atoi(coups) : valideCoups; send_request(sc, 3, ENCHERE, myName, coups); } else if (currentPhase == PHASE_RESO && strlen(moves) > 0 && moiJoue) { send_request(sc, 3, SOLUTION, myName, moves); } else { if (!moiJoue && currentPhase == PHASE_RESO) { displayMsg("Ce n'est pas votre tour", FALSE); } else { displayMsg("coup ou deplacement est vide ", FALSE); } } } // handle btn reset /*|| estContenu(&rectCoup, &event.motion)*/ if (estContenu(&rectReset, &event.motion) || estContenu(&rectCoup, &event.motion)) { if (strlen(moves) > 0 || strlen(coups) > 0) { onclickReset(initPl, &initEnigme, coups, moves); } } // handle btn arret simulation if (estContenu(&rectArret, &event.motion)) { if (modeVisualisation) { arreterVisualisation(); displayMsg("arret de visualisation", FALSE); } } // handle btn voir simulation if (estContenu(&rectVoir, &event.motion)) { if (userSelected >= 0) { displayMsg("visalisation", FALSE); demarrerVisualisation(userSelected); } } // handle btn suivant (movement suivant de la simulation if (estContenu(&rectSuivant, &event.motion)) { if (modeVisualisation) { pasVisualisation(); displayMsg("pas suivant", FALSE); } } // handle focus coups focusCoup = FALSE; if (estContenu(&rectCoup, &event.motion)) { SDLS_affiche_image("assets/focusCoups.png", ren, rectCoup.x, rectCoup.y + CASE); memset(coups, 0, sizeof(coups)); lenCoups = 0; preFocusCoup = focusCoup = TRUE; } // handle select user save_yUser = rectUser.y; focusUser = FALSE; for (k = 0; k < bilan.list_users.nb; k++) { if (estContenu(&rectUser, &event.motion)) { if (userSelected > -1) { int y = rectUser.y; rectUser.y = save_yUser + CASE * userSelected; SDLS_affiche_image("assets/unfocusUser.png", ren, rectUser.x, rectUser.y); rectUser.y = y; } SDLS_affiche_image("assets/focusUser.png", ren, rectUser.x, rectUser.y); preFocusUser = focusUser = TRUE; userSelected = k; } rectUser.y = rectUser.y + CASE; } rectUser.y = save_yUser; //handle move robot if (!modeVisualisation) { x = event.motion.x / CASE; y = event.motion.y / CASE; for (i = 0; i < NB_ROBOT; ++i) { if (enigme.robots[i].x == x && enigme.robots[i].y == y) robotSelected = i; } if (robotSelected > -1) { direction = estDirection(&enigme, &event.motion, robotSelected, -1, 0) == TRUE ? Gauche : direction; direction = estDirection(&enigme, &event.motion, robotSelected, 1, 0) == TRUE ? Droit : direction; direction = estDirection(&enigme, &event.motion, robotSelected, 0, -1) == TRUE ? Haut : direction; direction = estDirection(&enigme, &event.motion, robotSelected, 0, 1) == TRUE ? Bas : direction; } if (direction != NONE) { update_pos_robot(pl, &enigme.robots[robotSelected], direction); /* update dans moves le nouveau deplacement de robot et le coups*/ move[0] = enigme.robots[robotSelected].c; move[1] = direction; strcat(moves, move); sprintf(coups, "%d", ((int) (strlen(moves) / 2))); //update view updateView(&rectCoup, &rectEmpty); robotSelected = -1; direction = NONE; } // handle unfocus if (preFocusCoup && !focusCoup) { SDLS_affiche_image("assets/unfocusCoups.png", ren, rectCoup.x, rectCoup.y + CASE); preFocusCoup = focusCoup; } if (preFocusUser && !focusUser) { rectUser.y = save_yUser + CASE * userSelected; SDLS_affiche_image("assets/unfocusUser.png", ren, rectUser.x, rectUser.y); rectUser.y = save_yUser; userSelected = -1; preFocusUser = focusUser; } } break; // handle entrer en dur le nb coups case SDL_TEXTINPUT: if (focusCoup && ((currentPhase & PHASE_REFLEX) || (currentPhase & PHASE_ENCHERE))) { int nb = estEntier(event.text.text); if (0 <= nb && nb <= 9) { if (lenCoups < 4) { coups[lenCoups++] = event.text.text[0]; tmp_Tx = txt2Texture(ren, font, &colorBlack, coups); displayCoup(tmp_Tx, rectCoup, &rectEmpty); SDL_RenderPresent(ren); } } } break; case SDL_QUIT: quit = TRUE; break; } // UPDATE Time memset(timeChaine, 0, 32); formatTime(SDL_GetTicks() - timeStart, timeChaine); SDLS_affiche_image("assets/emptyTT.png", ren, rectTime.x, rectTime.y); tmp_Tx = txt2Texture(ren, font, &colorBlack, timeChaine); SDL_QueryTexture(tmp_Tx, NULL, NULL, &rectTime.w, &rectTime.h); SDL_RenderCopy(ren, tmp_Tx, &rectEmpty, &rectTime); SDL_RenderPresent(ren); } TTF_CloseFont(font); SDL_DestroyRenderer(ren); SDL_DestroyWindow(win); send_request(sc, 2, SORT, myName); pthread_cancel(thread_com); pthread_cancel(thread_chat); SDL_Quit(); return 0; }