Documentation de la bibliothèque MLV-3.1.0

beginner/08_mouse_keyboard_input_box_timer.c

Ce programme montre comment il est possible d'ajouter un minuteur lorsque l'utilisateur est invité à cliquer ou appuyer sur une touche du clavier

#include <MLV/MLV_all.h>
//
// Cette fonction réinitialise l'acran puis affiche un texte donnée en
// parametre à l'écran.
//
void afficher_texte( char* texte ){
int size_interline = 9;
10, 10, texte, size_interline,
);
}
//
// Attention !
// Pour pouvoir compiler ce programme sous windows et sous macintosh,
// il faut, pour la déclaration du main, respecter strictement la syntaxe
// suivante :
//
int main( int argc, char *argv[] ){
int unicode, mouse_x, mouse_y;
int temps_attente = 5;
// taille de l'écran
int width = 640, height = 480;
MLV_Event event;
//
// Créé et affiche la fenêtre
//
"beginner - 8 - mouse keyboard timer", "mouse keyboard timer",
width, height
);
//
// Tant que le temps imparti n'est pas écoulé, l'utilisateur est invité à
// appuyer sur une touche du clavier
//
afficher_texte(
"Vous passerez à l'écran suivant en:\n - appuyant sur une touche du clavier\n - attendant quelques secondes."
);
event = MLV_wait_keyboard_or_seconds( &sym, &mod, &unicode, temps_attente );
if( event == MLV_KEY ){
afficher_texte( "Vous avez choisi le clavier." );
}else{
afficher_texte( "Le temps est écoulé." );
}
//
// Tant que le temps imparti n'est pas écoulé, l'utilisateur est invité à
// cliquer sur le bouton gauche de la souris
//
afficher_texte(
"Vous passerez à l'écran suivant en:\n - cliquant sur la souris\n - attendant quelques secondes."
);
event = MLV_wait_mouse_or_seconds( &mouse_x, &mouse_y, temps_attente );
if( event == MLV_MOUSE_BUTTON ){
afficher_texte( "Vous avez choisi la souris." );
}else{
afficher_texte( "Le temps est écoulé." );
}
//
// L'utilisateur est invité à appuyer sur une touche du clavier ou à
// cliquer sur le bouton gauche de la souris.
//
afficher_texte(
"Vous passerez à l'écran suivant en:\n - appuyant sur une touche du clavier\n - cliquant sur la souris."
);
event = MLV_wait_keyboard_or_mouse( &sym, &mod, &unicode, &mouse_x, &mouse_y );
if( event == MLV_MOUSE_BUTTON ){
afficher_texte( "Vous avez choisi la souris." );
}else{
afficher_texte( "Vous avez choisi le clavier." );
}
//
// Tant que le temps imparti n'est pas écoulé, l'utilisateur est invité à
// appuyer sur une touche du clavier ou à cliquer sur le bouton gauche de
// la souris.
//
afficher_texte(
"Vous passerez à l'écran suivant en:\n - appuyant sur une touche du clavier\n - cliquant sur la souris\n - attendant quelques secondes."
);
&sym, &mod, &unicode, &mouse_x, &mouse_y, temps_attente
);
if( event == MLV_MOUSE_BUTTON ){
afficher_texte( "Vous avez choisi la souris." );
}else if( event == MLV_KEY ){
afficher_texte( "Vous avez choisi le clavier." );
}else{
afficher_texte( "Le temps est écoulé." );
}
//
// Tant que le temps imparti n'est pas écoulé, l'utilisateur est invité à
// écrire un mot dans la boîte de saisi.
//
afficher_texte(
"Vous passerez à l'écran suivant en:\n - entrant un mot dans la boîte de dialogue;\n - attendant quelques secondes."
);
char* text;
3000,
10, 100, 100, 30,
"Mot : ", &text
);
if( event == MLV_INPUT_BOX ){
afficher_texte( "Vous avez choisi la boîte de saisie." );
}else{
afficher_texte( "Le temps est écoulé." );
}
if( text ){
free( text );
}
//
// Ferme la fenêtre
//
return 0;
}
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012,2013, 2016 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
MLV_TEXT_LEFT
@ MLV_TEXT_LEFT
Definition: MLV_text.h:46
MLV_wait_milliseconds
void MLV_wait_milliseconds(int milliseconds)
Le programme s'intérompt pendant un nombre de milli-secondes donné en paramètre.
MLV_create_window
void MLV_create_window(const char *window_name, const char *icone_name, unsigned int width, unsigned int height)
Créé une fenêtre dont la taille, et les différents noms sont passés en paramètres.
MLV_Event
MLV_Event
Énumère les différents types d'évènement de la bibliothèque MLV.
Definition: MLV_event.h:46
MLV_Keyboard_button
MLV_Keyboard_button
Énumère l'ensemble des codes des touches du clavier.
Definition: MLV_keyboard.h:50
MLV_wait_keyboard_or_mouse_or_seconds
MLV_Event MLV_wait_keyboard_or_mouse_or_seconds(MLV_Keyboard_button *sym, MLV_Keyboard_modifier *mod, int *unicode, int *mouse_x, int *mouse_y, int seconds)
Suspend l'exécution jusqu'à ce que l'utilisateur appuie sur une touche du clavier,...
MLV_free_window
void MLV_free_window()
Ferme la fenêtre de la bibliothèque MLV.
MLV_COLOR_RED
#define MLV_COLOR_RED
Definition: MLV_color.h:1297
MLV_update_window
void MLV_update_window()
Met à jour l'affichage de la fenêtre.
MLV_KEY
@ MLV_KEY
Definition: MLV_event.h:48
MLV_COLOR_GREEN
#define MLV_COLOR_GREEN
Definition: MLV_color.h:931
MLV_INPUT_BOX
@ MLV_INPUT_BOX
Definition: MLV_event.h:49
MLV_wait_input_box_or_milliseconds
MLV_Event MLV_wait_input_box_or_milliseconds(int milliseconds, int top_left_corner_X, int top_left_corner_Y, int width, int height, MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor, const char *informativeMessage, char **text,...)
Cette fonction suspend l'exécution du programme, affiche une boîte de saisie et attends que l'utilisa...
MLV_wait_keyboard_or_mouse
MLV_Event MLV_wait_keyboard_or_mouse(MLV_Keyboard_button *sym, MLV_Keyboard_modifier *mod, int *unicode, int *mouse_x, int *mouse_y)
Suspend l'exécution jusqu'à ce que l'utilisateur appuie sur une touche du clavier ou sur le bouton ga...
MLV_all.h
Fichier d'entête principal incluant tous les autres fichiers entêtes de la bibliothèque MLV.
MLV_clear_window
void MLV_clear_window(MLV_Color color)
Éfface la fenêtre et la remplace par un monochrome de la couleur donnée en paramètre.
MLV_draw_adapted_text_box
void MLV_draw_adapted_text_box(int x, int y, const char *message, int sizeInterligne, MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor, MLV_Text_justification text_justification,...)
Dessine une boîte contenant du texte.
MLV_MOUSE_BUTTON
@ MLV_MOUSE_BUTTON
Definition: MLV_event.h:51
MLV_wait_mouse_or_seconds
MLV_Event MLV_wait_mouse_or_seconds(int *x, int *y, int seconds)
Suspend l'exécution jusqu'à ce que l'utilisateur clique sur le bouton gauche de la souris où jusqu'à ...
MLV_Keyboard_modifier
MLV_Keyboard_modifier
Énumère l'ensemble des codes associées aux différents modes du clavier.
Definition: MLV_keyboard.h:299
MLV_wait_keyboard_or_seconds
MLV_Event MLV_wait_keyboard_or_seconds(MLV_Keyboard_button *sym, MLV_Keyboard_modifier *mod, int *unicode, int seconds)
Suspend l'exécution jusqu'à ce que l'utilisateur appuie sur une touche du clavier ou jusq'à ce q'un n...
MLV_COLOR_BLACK
#define MLV_COLOR_BLACK
Definition: MLV_color.h:379