109 lines
2.7 KiB
C
109 lines
2.7 KiB
C
#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS
|
|
#include <imgui/cimgui.h>
|
|
#include <pthread.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
#include "read_events.h"
|
|
#include "read_file.h"
|
|
#include "ui.h"
|
|
|
|
const struct ImVec2 zero_vec2 = {0, 0};
|
|
|
|
ui_infos * init_ui(const char *name)
|
|
{
|
|
ui_infos *ret = (ui_infos *) malloc(sizeof(ui_infos));
|
|
ret->name = (char *) malloc(strlen(name) + 1);
|
|
strcpy(ret->name, name);
|
|
ret->file = fopen(name, "w+");
|
|
ret->is_recording = 0;
|
|
ret->args_rf = args_rf_init(ret->file, 1);
|
|
ret->nb_loop = 0;
|
|
ret->sleep_loop = 0;
|
|
return ret;
|
|
}
|
|
|
|
void free_ui(ui_infos *ptr)
|
|
{
|
|
if (ptr->args_rf != NULL) free(ptr->args_rf);
|
|
if (ptr->file != NULL) fclose(ptr->file);
|
|
if (ptr->name != NULL) free(ptr->name);
|
|
free(ptr);
|
|
}
|
|
|
|
int draw_ui(ui_infos *ptr)
|
|
{
|
|
/* en plein écran */
|
|
ImGuiViewport *vp = igGetMainViewport();
|
|
igSetNextWindowPos(vp->Pos, ImGuiCond_None, zero_vec2);
|
|
igSetNextWindowSize(vp->Size, ImGuiCond_None);
|
|
|
|
/*
|
|
* Choix du fichier
|
|
*
|
|
* Bouton enregistrement
|
|
*
|
|
* Bouton de rewind (bloqué si pas de fichiers)
|
|
*
|
|
* Liste déroulantes des fenetres pour savoir où faire les clics
|
|
*/
|
|
|
|
igBegin("Test", NULL, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration);
|
|
igText("Fichier : %s", ptr->name);
|
|
|
|
if (ptr->is_recording)
|
|
{
|
|
if (igButton("Arrêter l'enregistrement.", zero_vec2))
|
|
{
|
|
if (pthread_cancel(ptr->pid))
|
|
{
|
|
fprintf(stderr, "Erreur lors du cancel du thread listen.\n");
|
|
return -1;
|
|
}
|
|
|
|
ptr->is_recording = 0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (igButton("Lancer l'enregistrement.", zero_vec2))
|
|
{
|
|
ptr->is_recording = 1;
|
|
|
|
if (pthread_create(&ptr->pid, NULL, listen, ptr->file))
|
|
{
|
|
fprintf(stderr, "Erreur à la création du thread de listen.\n");
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
igSetNextItemWidth(100.0);
|
|
igInputInt("Temps de repos entre chaque clic (s)", &ptr->args_rf->time_sleep, 1, 10, 0);
|
|
if (ptr->args_rf->time_sleep <= 0) ptr->args_rf->time_sleep = 1;
|
|
|
|
igSetNextItemWidth(100.0);
|
|
igInputInt("Nombre de répétitions du fichier", &ptr->nb_loop, 1, 10, 0);
|
|
if (ptr->nb_loop < 0) ptr->nb_loop = 0;
|
|
|
|
igSetNextItemWidth(100.0);
|
|
igInputInt("Temps de repos entre chaque répétition (s)", &ptr->sleep_loop, 1, 10, 0);
|
|
if (ptr->sleep_loop < 0) ptr->sleep_loop = 0;
|
|
|
|
if (igButton("Replay", zero_vec2))
|
|
{
|
|
int i;
|
|
for (i = 0; i <= ptr->nb_loop; i++)
|
|
{
|
|
rewind(ptr->file);
|
|
readfile(ptr->args_rf);
|
|
sleep(ptr->sleep_loop);
|
|
}
|
|
}
|
|
}
|
|
|
|
igEnd();
|
|
|
|
return 0;
|
|
}
|