File: 08_mouse_keyboard_input_box_timer.c

package info (click to toggle)
mlv 3.1.0-8
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 10,596 kB
  • sloc: ansic: 18,982; sh: 4,760; makefile: 381; objc: 246; xml: 92
file content (171 lines) | stat: -rw-r--r-- 5,222 bytes parent folder | download | duplicates (3)
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
/**
 *
 * Ce programme montre comment il est possible d'ajouter un minuteur lorsque 
 * l'utilisateur est invité à cliquer ou appuyer sur une touche du clavier
 *
 *------------------------------------------------------------------------------
 *
 * TODO
 * 
 *------------------------------------------------------------------------------
 */

#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;
	MLV_clear_window( MLV_COLOR_BLACK );
	MLV_draw_adapted_text_box (
		10, 10, texte, size_interline,
		MLV_COLOR_BLACK, MLV_COLOR_GREEN, MLV_COLOR_BLACK,
        MLV_TEXT_LEFT
	);
	MLV_update_window();
}

//
// 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[] ){

	MLV_Keyboard_button sym;
	MLV_Keyboard_modifier mod;
	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
	//
	MLV_create_window(
		"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é." );
	}
	MLV_wait_milliseconds( 1500 );

	//
	// 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é." );
	}
	MLV_wait_milliseconds( 1500 );

	//
	// 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." );
	}
	MLV_wait_milliseconds( 1500 );
	
	//
	// 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."
	);
	event = MLV_wait_keyboard_or_mouse_or_seconds(
		&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é." );
	}
	MLV_wait_milliseconds( 1500 );

	//
	// 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;
	event = MLV_wait_input_box_or_milliseconds(                                         
    	3000,                                                           
    	10, 100, 100, 30,
    	MLV_COLOR_RED, MLV_COLOR_GREEN, MLV_COLOR_BLACK,
    	"Mot : ", &text
	);
	if( event == MLV_INPUT_BOX ){
		afficher_texte( "Vous avez choisi la boîte de saisie." );
	}else{
		afficher_texte( "Le temps est écoulé." );
	}
	MLV_wait_milliseconds( 1500 );
	if( text ){
		free( text ); 
	}

	//
	// Ferme la fenêtre
	//
	MLV_free_window();

	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/>.
 */