IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SDL Discussion :

boucle while pour un bouton


Sujet :

SDL

  1. #1
    Membre éclairé
    Homme Profil pro
    sans emploi
    Inscrit en
    Février 2014
    Messages
    365
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : sans emploi
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2014
    Messages : 365
    Par défaut boucle while pour un bouton
    Bonjour
    Comment placer la boucle while pour qu'à chaque clique sur le bouton suivant la fenêtre affiche un nouveau chiffre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    // instruction préprocesseur: recopier le code qui se trouve dans le ficher
    //========================================================================
    #include <SDL.h>
    #include <SDL_image.h>
    #include <SDL_ttf.h>
    #include <stdio.h>
    #include <time.h>	// srand()
    #include <sstream>
    #include <regex>
    #include <string>       // classe std::string, fonction std::stof
    #include <iostream>     // fonction std::cout
     
     
    // declaration, initialisation de variables
    //=========================================
     
    // dimension ecran
    const int SCREEN_WIDTH = 640;
    const int SCREEN_HEIGHT = 640;
     
    // The window we'll be rendering to
    SDL_Window* gWindow = NULL;
    // The window renderer
    SDL_Renderer* gRenderer = NULL;
    // Globally used font
    TTF_Font *font = NULL;
    SDL_Color couleur_texte = {6, 49, 196};
    // affichage cadre plus texte
    SDL_Rect* clip = NULL;
    double angle = 0.0;
    SDL_Point* center = NULL;
    SDL_RendererFlip flip = SDL_FLIP_NONE;
     
    // definition d'une classe pour créer des objets rectangles à l'écran
    //===================================================================
    class cadre_A
    {
    	// données privées: non accessible de l'extérieur de la classe
    	private:
     
    	// données, fonctions membres publiques
    	public:
    	std::string texte;
    	SDL_Surface* surface_texte;
    	SDL_Texture* texture_texte;
    	SDL_Rect texture_bouton;
     
    	// dimensions texture
    	int texture_width;
    	int texture_height;
     
    	// rectangle du cadre
    	//SDL_Rect rectangle_cadre = {int x_rectangle_cadre, int y_rectangle_cadre, int width_rectangle_cadre,int height_rectangle_cadre};
    	SDL_Rect rectangle_cadre;
    	int x_rectangle_cadre;
    	int y_rectangle_cadre;
    	int width_rectangle_cadre;
    	int height_rectangle_cadre;
     
    	// constructeur par défaut
    	// cadre_A(); syntaxe non valide
    	cadre_A() = default;	// ou cadre_A() {};
    	// destructeur
    	~cadre_A();
     
    	// déclaration de fonctions membres
    	// render texte
    	void render_texte(std::string texte_bis);
    	// definition rectangle cadre
    	void definition_rectangle_cadre (int x_rectangle_cadre_bis, int y_rectangle_cadre_bis, int width_rectangle_cadre_bis, int height_rectangle_cadre_bis);
    	// affichage cadre
    	void affichage_cadre_plus_texte ();
    };
     
    // defintion de fonctions membres
    cadre_A::~cadre_A()
    {
    	//Deallocate
    	SDL_DestroyTexture( texture_texte );
    	texture_texte = NULL;
    	texture_width = 0;
    	texture_height = 0;
    }
     
    void cadre_A::definition_rectangle_cadre (int x_rectangle_cadre_bis, int y_rectangle_cadre_bis, int width_rectangle_cadre_bis, int height_rectangle_cadre_bis)
    {
    	x_rectangle_cadre = x_rectangle_cadre_bis;
    	y_rectangle_cadre = y_rectangle_cadre_bis;
    	width_rectangle_cadre = width_rectangle_cadre_bis;
    	height_rectangle_cadre = height_rectangle_cadre_bis;
    	SDL_Rect rectangle_cadre = { x_rectangle_cadre, y_rectangle_cadre, width_rectangle_cadre, height_rectangle_cadre };
    	SDL_SetRenderDrawColor( gRenderer, 255, 20, 147, 1 );	
    	SDL_RenderFillRect( gRenderer, &rectangle_cadre );
    }
     
    void cadre_A::render_texte(std::string texte_bis)
    {
    	texte = texte_bis;
     
    	surface_texte = TTF_RenderText_Blended_Wrapped(font, texte.c_str(), couleur_texte, this->width_rectangle_cadre);
    	texture_texte = SDL_CreateTextureFromSurface( gRenderer, surface_texte);
    	texture_width = surface_texte->w;
        texture_height = surface_texte->h;
    }
     
    void cadre_A::affichage_cadre_plus_texte ()
    {
    	//Set rendering space and render to screen
        SDL_Rect texture_bouton = { x_rectangle_cadre+(width_rectangle_cadre-texture_width)/2, y_rectangle_cadre+(height_rectangle_cadre-texture_height)/2, texture_width, texture_height };
    	// definition couleur de remplissage du rectangle bouton
    	SDL_SetRenderDrawColor( gRenderer, 255, 20, 147, 1 );	
    	SDL_RenderFillRect( gRenderer, &texture_bouton );
        //Render to screen
    	SDL_RenderCopyEx( gRenderer, texture_texte, clip, &texture_bouton, angle, center, flip );
    }
     
    // fonction principale
    //====================
    int main( int argc, char* args[] )
    {
    	// declaration de variables
    	//=========================
    	int height_cadre_bouton = SCREEN_HEIGHT/14;	
    	int marge_verticale1 = 30;
    	int width1 = 200;
     
    	// declaration des 3 variables
    	int nombre1;
     
    	// constantes 
    	const int MAX=10;
    	const int MIN=1;
     
    	// fonction qui donne un chiffre au hasard
    	srand(time(NULL));
     
    	//Initialize SDL
        SDL_Init( SDL_INIT_VIDEO );
    	//Set texture filtering to linear
    	SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" );
    	//Create window
    	gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
    	//Create vsynced renderer for window
    	gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
    	//Initialize renderer color
    	SDL_SetRenderDrawColor( gRenderer,127, 255, 0, 1 );
    	//Initialize PNG loading
    	int imgFlags = IMG_INIT_PNG;
    	IMG_Init( imgFlags );
    	//Initialize SDL_ttf
    	TTF_Init();
        //Open the font
    	font = TTF_OpenFont( "arial.ttf", 25 );
     
    	//Render the prompt
        bool bouton_suivant_clique = false;
     
        nombre1=(rand()%(MAX-MIN+1))+MIN;
    	std::string nombre1_string = std::to_string(nombre1);
     
    	//Clear screen
    	SDL_SetRenderDrawColor( gRenderer,127, 255, 0, 1 );
    	SDL_RenderClear( gRenderer );
     
    	cadre_A cadre_calcul;
        cadre_calcul.definition_rectangle_cadre (0, 0, width1, height_cadre_bouton);
    	cadre_calcul.render_texte(nombre1_string);	
    	cadre_calcul.affichage_cadre_plus_texte();
     
    	cadre_A cadre_suivant;
    	cadre_suivant.definition_rectangle_cadre (0, cadre_calcul.y_rectangle_cadre+marge_verticale1, width1, height_cadre_bouton);
    	cadre_suivant.render_texte("Suivant");
    	cadre_suivant.affichage_cadre_plus_texte();
     
    	//Main loop flag
    	bool quit = false;
     
    	//Event handler
    	SDL_Event e;
     
    	//While application is running
    	while( !quit )
    	{
    		//The rerender text flag
    		bool renderText = false;
            bool bouton_egal_clique = false;
     
    		//Handle events on queue
    		while( SDL_PollEvent( &e ) != 0 )
    		{
    			//User requests quit
    			if( e.type == SDL_QUIT )
    			{
    				quit = true;
    			}
     
                else if( /*e.type == SDL_MOUSEMOTION ||*/ e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP )
    			{
    				//Get mouse position
    				int x, y;
    				SDL_GetMouseState( &x, &y );
     
    				//Check if mouse is in button
    				bool inside = true;
     
    				//Mouse is left of the button
    				if(
    					(
    					x > cadre_suivant.x_rectangle_cadre &
    				    x < cadre_suivant.x_rectangle_cadre + cadre_suivant.width_rectangle_cadre &
    					y > cadre_suivant.y_rectangle_cadre &
    					y < cadre_suivant.y_rectangle_cadre + cadre_suivant.height_rectangle_cadre
    					)
     
    				  )
    				{
    					bouton_suivant_clique = true;
     
    				    // verification
    					std::cout << "suivant = true" << std::endl;
    				}
    				else{bouton_suivant_clique = false;}
    			}
            }
     
    		//Clear screen
    	    SDL_SetRenderDrawColor( gRenderer,127, 255, 0, 1 );
    		SDL_RenderClear( gRenderer );
     
    		cadre_calcul.definition_rectangle_cadre (0, 0, width1, height_cadre_bouton);
    		cadre_calcul.affichage_cadre_plus_texte();		
     
    		cadre_suivant.definition_rectangle_cadre (0, cadre_calcul.y_rectangle_cadre+height_cadre_bouton+marge_verticale1, width1, height_cadre_bouton);
    		cadre_suivant.affichage_cadre_plus_texte();		
     
    		//Update screen
    		SDL_RenderPresent( gRenderer );
    	}
     
    	//Free resources and close SDL
     
    	//Free global font
    	TTF_CloseFont( font );
    	font = NULL;
     
    	//Destroy window	
    	SDL_DestroyRenderer( gRenderer );
    	SDL_DestroyWindow( gWindow );
    	gWindow = NULL;
    	gRenderer = NULL;
     
    	//Quit SDL subsystems
    	TTF_Quit();
    	IMG_Quit();
    	SDL_Quit();
     
    	return 0;
    }
    Cordialement

  2. #2
    Expert confirmé
    Avatar de Mat.M
    Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2006
    Messages
    8 526
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2006
    Messages : 8 526
    Par défaut
    bonjour d'une part faire une liste d'instances de classe cadre_A avec mettons std::list<cadre_A > ou std::vector<cadre_A> ainsi ça permet de faire des tableaux dynamiques de boutons.
    Ensuite rajouter une méthode à cadre_A qui gère le clic souris X et Y.
    Cette méthode est à appeler dans le code après SDL_PollEvent
    Si X et Y sont des coordonnées inscrites dans le rectangle d'une instance de cadre_A alors agir en conséquence.


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    //Mouse is left of the button
    				if(
    					(
    					x > cadre_suivant.x_rectangle_cadre &
    				    x < cadre_suivant.x_rectangle_cadre + cadre_suivant.width_rectangle_cadre &
    					y > cadre_suivant.y_rectangle_cadre &
    					y < cadre_suivant.y_rectangle_cadre + cadre_suivant.height_rectangle_cadre
    					)
     
    				  )
    				{
    enlever le if et à la place donc appeler une méthode class_A::proceder_click_souris(int X,int Y).
    ET placer le if dans cette méthode à moins qu'une méthode de la SDL permette de savoir si un point X Y est inscrit dans un rectangle regarder la doc de la SDL

  3. #3
    Membre éclairé
    Homme Profil pro
    sans emploi
    Inscrit en
    Février 2014
    Messages
    365
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : sans emploi
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2014
    Messages : 365
    Par défaut
    J'ai rajouté un paramètre à la méthode
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    	// méthode qui gère le clic souris X et Y
    	void proceder_click_souris(int x_bis, int y_bis, cadre_A cadre_suivant_bis);
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    // instruction préprocesseur: recopier le code qui se trouve dans le ficher
    //========================================================================
    #include <SDL.h>
    #include <SDL_image.h>
    #include <SDL_ttf.h>
    #include <stdio.h>
    #include <time.h>	// srand()
    #include <sstream>
    #include <regex>
    #include <string>       // classe std::string, fonction std::stof
    #include <iostream>     // fonction std::cout
    #include <list>
     
     
    // declaration, initialisation de variables
    //=========================================
     
    // dimension ecran
    const int SCREEN_WIDTH = 640;
    const int SCREEN_HEIGHT = 640;
     
    // The window we'll be rendering to
    SDL_Window* gWindow = NULL;
    // The window renderer
    SDL_Renderer* gRenderer = NULL;
    // Globally used font
    TTF_Font *font = NULL;
    SDL_Color couleur_texte = {6, 49, 196};
    // affichage cadre plus texte
    SDL_Rect* clip = NULL;
    double angle = 0.0;
    SDL_Point* center = NULL;
    SDL_RendererFlip flip = SDL_FLIP_NONE;
     
    // definition d'une classe pour créer des objets rectangles à l'écran
    //===================================================================
    class cadre_A
    {
    	// données privées: non accessible de l'extérieur de la classe
    	private:
     
    	// données, fonctions membres publiques
    	public:
    	std::string texte;
    	SDL_Surface* surface_texte;
    	SDL_Texture* texture_texte;
    	SDL_Rect texture_bouton;
     
    	// dimensions texture
    	int texture_width;
    	int texture_height;
     
    	// rectangle du cadre
    	//SDL_Rect rectangle_cadre = {int x_rectangle_cadre, int y_rectangle_cadre, int width_rectangle_cadre,int height_rectangle_cadre};
    	SDL_Rect rectangle_cadre;
    	int x_rectangle_cadre;
    	int y_rectangle_cadre;
    	int width_rectangle_cadre;
    	int height_rectangle_cadre;
     
    	// constructeur par défaut
    	// cadre_A(); syntaxe non valide
    	cadre_A() = default;	// ou cadre_A() {};
    	// destructeur
    	~cadre_A();
     
    	// déclaration de fonctions membres
    	// render texte
    	void render_texte(std::string texte_bis);
    	// definition rectangle cadre
    	void definition_rectangle_cadre (int x_rectangle_cadre_bis, int y_rectangle_cadre_bis, int width_rectangle_cadre_bis, int height_rectangle_cadre_bis);
    	// affichage cadre
    	void affichage_cadre_plus_texte ();
    	// méthode qui gère le clic souris X et Y
    	void proceder_click_souris(int x_bis, int y_bis, cadre_A cadre_suivant_bis);
    };
     
    // defintion de fonctions membres
    cadre_A::~cadre_A()
    {
    	//Deallocate
    	SDL_DestroyTexture( texture_texte );
    	texture_texte = NULL;
    	texture_width = 0;
    	texture_height = 0;
    }
     
    void cadre_A::definition_rectangle_cadre (int x_rectangle_cadre_bis, int y_rectangle_cadre_bis, int width_rectangle_cadre_bis, int height_rectangle_cadre_bis)
    {
    	x_rectangle_cadre = x_rectangle_cadre_bis;
    	y_rectangle_cadre = y_rectangle_cadre_bis;
    	width_rectangle_cadre = width_rectangle_cadre_bis;
    	height_rectangle_cadre = height_rectangle_cadre_bis;
    	SDL_Rect rectangle_cadre = { x_rectangle_cadre, y_rectangle_cadre, width_rectangle_cadre, height_rectangle_cadre };
    	SDL_SetRenderDrawColor( gRenderer, 255, 20, 147, 1 );	
    	SDL_RenderFillRect( gRenderer, &rectangle_cadre );
    }
     
    void cadre_A::render_texte(std::string texte_bis)
    {
    	texte = texte_bis;
     
    	surface_texte = TTF_RenderText_Blended_Wrapped(font, texte.c_str(), couleur_texte, this->width_rectangle_cadre);
    	texture_texte = SDL_CreateTextureFromSurface( gRenderer, surface_texte);
    	texture_width = surface_texte->w;
        texture_height = surface_texte->h;
    }
     
    void cadre_A::affichage_cadre_plus_texte ()
    {
    	//Set rendering space and render to screen
        SDL_Rect texture_bouton = { x_rectangle_cadre+(width_rectangle_cadre-texture_width)/2, y_rectangle_cadre+(height_rectangle_cadre-texture_height)/2, texture_width, texture_height };
    	// definition couleur de remplissage du rectangle bouton
    	SDL_SetRenderDrawColor( gRenderer, 255, 20, 147, 1 );	
    	SDL_RenderFillRect( gRenderer, &texture_bouton );
        //Render to screen
    	SDL_RenderCopyEx( gRenderer, texture_texte, clip, &texture_bouton, angle, center, flip );
    }
     
    void cadre_A::proceder_click_souris(int x_bis, int y_bis, cadre_A cadre_suivant_bis)
    {
    	if((
    		x_bis > cadre_suivant_bis.x_rectangle_cadre &
    		x_bis < cadre_suivant_bis.x_rectangle_cadre + cadre_suivant_bis.width_rectangle_cadre &
    		y_bis > cadre_suivant_bis.y_rectangle_cadre &
    		y_bis < cadre_suivant_bis.y_rectangle_cadre + cadre_suivant_bis.height_rectangle_cadre
    		))
    	{
    		// Si x et y sont des coordonnées inscrites dans le rectangle d'une instance de cadre_A alors agir en conséquence
    		std::cout << "suivant = true" << std::endl;
     
    		// instructions ...
    	}
     
    }
     
    // fonction principale
    //====================
    int main( int argc, char* args[] )
    {
    	// declaration de variables
    	//=========================
    	int height_cadre_bouton = SCREEN_HEIGHT/14;	
    	int marge_verticale1 = 30;
    	int width1 = 200;
     
    	// declaration des 3 variables
    	int nombre1;
     
    	// constantes 
    	const int MAX=10;
    	const int MIN=1;
     
    	// fonction qui donne un chiffre au hasard
    	srand(time(NULL));
     
    	//Initialize SDL
        SDL_Init( SDL_INIT_VIDEO );
    	//Set texture filtering to linear
    	SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" );
    	//Create window
    	gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
    	//Create vsynced renderer for window
    	gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
    	//Initialize renderer color
    	SDL_SetRenderDrawColor( gRenderer,127, 255, 0, 1 );
    	//Initialize PNG loading
    	int imgFlags = IMG_INIT_PNG;
    	IMG_Init( imgFlags );
    	//Initialize SDL_ttf
    	TTF_Init();
        //Open the font
    	font = TTF_OpenFont( "arial.ttf", 25 );
     
    	//Render the prompt
        bool bouton_suivant_clique = false;
     
        nombre1=(rand()%(MAX-MIN+1))+MIN;
    	std::string nombre1_string = std::to_string(nombre1);
     
    	//Clear screen
    	SDL_SetRenderDrawColor( gRenderer,127, 255, 0, 1 );
    	SDL_RenderClear( gRenderer );
     
    	cadre_A cadre_calcul;
        cadre_calcul.definition_rectangle_cadre (0, 0, width1, height_cadre_bouton);
    	cadre_calcul.render_texte(nombre1_string);	
    	cadre_calcul.affichage_cadre_plus_texte();
     
    	cadre_A cadre_suivant;
    	cadre_suivant.definition_rectangle_cadre (0, cadre_calcul.y_rectangle_cadre+marge_verticale1, width1, height_cadre_bouton);
    	cadre_suivant.render_texte("Suivant");
    	cadre_suivant.affichage_cadre_plus_texte();
     
    	// tableaux dynamiques de bouton
    	std::list<cadre_A > list_cadre_A;
    	list_cadre_A.push_back(cadre_calcul);
    	list_cadre_A.push_back(cadre_suivant);
     
    	//Main loop flag
    	bool quit = false;
     
    	//Event handler
    	SDL_Event e;
     
    	//While application is running
    	while( !quit )
    	{
    		//The rerender text flag
    		bool renderText = false;
            bool bouton_egal_clique = false;
     
    		//Handle events on queue
    		while( SDL_PollEvent( &e ) != 0 )
    		{
    			//User requests quit
    			if( e.type == SDL_QUIT )
    			{
    				quit = true;
    			}
     
                else if( /*e.type == SDL_MOUSEMOTION ||*/ e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP )
    			{
    				//Get mouse position
    				int x, y;
    				SDL_GetMouseState( &x, &y );
     
    				//Check if mouse is in button
    				bool inside = true;
     
    				// appel de la methode de vérification du clic du bouton suivant
    				cadre_A::proceder_click_souris(x, y, cadre_suivant);
     
    			}
            }
     
    		//Clear screen
    	    SDL_SetRenderDrawColor( gRenderer,127, 255, 0, 1 );
    		SDL_RenderClear( gRenderer );
     
    		cadre_calcul.definition_rectangle_cadre (0, 0, width1, height_cadre_bouton);
    		cadre_calcul.affichage_cadre_plus_texte();		
     
    		cadre_suivant.definition_rectangle_cadre (0, cadre_calcul.y_rectangle_cadre+height_cadre_bouton+marge_verticale1, width1, height_cadre_bouton);
    		cadre_suivant.affichage_cadre_plus_texte();		
     
    		//Update screen
    		SDL_RenderPresent( gRenderer );
    	}
     
    	//Free resources and close SDL
     
    	//Free global font
    	TTF_CloseFont( font );
    	font = NULL;
     
    	//Destroy window	
    	SDL_DestroyRenderer( gRenderer );
    	SDL_DestroyWindow( gWindow );
    	gWindow = NULL;
    	gRenderer = NULL;
     
    	//Quit SDL subsystems
    	TTF_Quit();
    	IMG_Quit();
    	SDL_Quit();
     
    	return 0;
    }
    le message d'erreur suivant apparait
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     error: cannot call member function 'void cadre_A::proceder_click_souris(int, int, cadre_A)' without object
      230 |     cadre_A::proceder_click_souris(x, y, cadre_suivant);

  4. #4
    Expert confirmé
    Avatar de Mat.M
    Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2006
    Messages
    8 526
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2006
    Messages : 8 526
    Par défaut
    salut non pas besoin de passer en paramètre une classe à process_click car c'est la classe elle-même qui gère le clic

  5. #5
    Membre éclairé
    Homme Profil pro
    sans emploi
    Inscrit en
    Février 2014
    Messages
    365
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : sans emploi
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2014
    Messages : 365
    Par défaut
    merci
    voila ce que ca donne
    je vois pas comment rédiger la partie
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    // instructions pour afficher un nouveau chiffre
    dans la méthode
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    void cadre_A::proceder_click_souris(int x_bis, int y_bis)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    // instruction préprocesseur: recopier le code qui se trouve dans le ficher
    //========================================================================
    #include <SDL.h>
    #include <SDL_image.h>
    #include <SDL_ttf.h>
    #include <stdio.h>
    #include <time.h>	// srand()
    #include <sstream>
    #include <regex>
    #include <string>       // classe std::string, fonction std::stof
    #include <iostream>     // fonction std::cout
    #include <list>
     
     
    // declaration, initialisation de variables
    //=========================================
     
    // dimension ecran
    const int SCREEN_WIDTH = 640;
    const int SCREEN_HEIGHT = 640;
     
    // The window we'll be rendering to
    SDL_Window* gWindow = NULL;
    // The window renderer
    SDL_Renderer* gRenderer = NULL;
    // Globally used font
    TTF_Font *font = NULL;
    SDL_Color couleur_texte = {6, 49, 196};
    // affichage cadre plus texte
    SDL_Rect* clip = NULL;
    double angle = 0.0;
    SDL_Point* center = NULL;
    SDL_RendererFlip flip = SDL_FLIP_NONE;
     
    // definition d'une classe pour créer des objets rectangles à l'écran
    //===================================================================
    class cadre_A
    {
    	// données privées: non accessible de l'extérieur de la classe
    	private:
     
    	// données, fonctions membres publiques
    	public:
    	std::string texte;
    	SDL_Surface* surface_texte;
    	SDL_Texture* texture_texte;
    	SDL_Rect texture_bouton;
     
    	// dimensions texture
    	int texture_width;
    	int texture_height;
     
    	// rectangle du cadre
    	//SDL_Rect rectangle_cadre = {int x_rectangle_cadre, int y_rectangle_cadre, int width_rectangle_cadre,int height_rectangle_cadre};
    	SDL_Rect rectangle_cadre;
    	int x_rectangle_cadre;
    	int y_rectangle_cadre;
    	int width_rectangle_cadre;
    	int height_rectangle_cadre;
     
    	// constructeur par défaut
    	// cadre_A(); syntaxe non valide
    	cadre_A() = default;	// ou cadre_A() {};
    	// destructeur
    	~cadre_A();
     
    	// déclaration de fonctions membres
    	// render texte
    	void render_texte(std::string texte_bis);
    	// definition rectangle cadre
    	void definition_rectangle_cadre (int x_rectangle_cadre_bis, int y_rectangle_cadre_bis, int width_rectangle_cadre_bis, int height_rectangle_cadre_bis);
    	// affichage cadre
    	void affichage_cadre_plus_texte ();
    	// méthode qui gère le clic souris X et Y
    	void proceder_click_souris(int x_bis, int y_bis);
    };
     
    // defintion de fonctions membres
    cadre_A::~cadre_A()
    {
    	//Deallocate
    	SDL_DestroyTexture( texture_texte );
    	texture_texte = NULL;
    	texture_width = 0;
    	texture_height = 0;
    }
     
    void cadre_A::definition_rectangle_cadre (int x_rectangle_cadre_bis, int y_rectangle_cadre_bis, int width_rectangle_cadre_bis, int height_rectangle_cadre_bis)
    {
    	x_rectangle_cadre = x_rectangle_cadre_bis;
    	y_rectangle_cadre = y_rectangle_cadre_bis;
    	width_rectangle_cadre = width_rectangle_cadre_bis;
    	height_rectangle_cadre = height_rectangle_cadre_bis;
    	SDL_Rect rectangle_cadre = { x_rectangle_cadre, y_rectangle_cadre, width_rectangle_cadre, height_rectangle_cadre };
    	SDL_SetRenderDrawColor( gRenderer, 255, 20, 147, 1 );	
    	SDL_RenderFillRect( gRenderer, &rectangle_cadre );
    }
     
    void cadre_A::render_texte(std::string texte_bis)
    {
    	texte = texte_bis;
     
    	surface_texte = TTF_RenderText_Blended_Wrapped(font, texte.c_str(), couleur_texte, this->width_rectangle_cadre);
    	texture_texte = SDL_CreateTextureFromSurface( gRenderer, surface_texte);
    	texture_width = surface_texte->w;
        texture_height = surface_texte->h;
    }
     
    void cadre_A::affichage_cadre_plus_texte ()
    {
    	//Set rendering space and render to screen
        SDL_Rect texture_bouton = { x_rectangle_cadre+(width_rectangle_cadre-texture_width)/2, y_rectangle_cadre+(height_rectangle_cadre-texture_height)/2, texture_width, texture_height };
    	// definition couleur de remplissage du rectangle bouton
    	SDL_SetRenderDrawColor( gRenderer, 255, 20, 147, 1 );	
    	SDL_RenderFillRect( gRenderer, &texture_bouton );
        //Render to screen
    	SDL_RenderCopyEx( gRenderer, texture_texte, clip, &texture_bouton, angle, center, flip );
    }
     
    void cadre_A::proceder_click_souris(int x_bis, int y_bis)
    {
    	if((
    		x_bis > this->x_rectangle_cadre &
    		x_bis < this->x_rectangle_cadre + this->width_rectangle_cadre &
    		y_bis > this->y_rectangle_cadre &
    		y_bis < this->y_rectangle_cadre + this->height_rectangle_cadre
    		))
    	{
    		// Si x et y sont des coordonnées inscrites dans le rectangle d'une instance de cadre_A alors agir en conséquence
    		std::cout << "suivant = true" << std::endl;
     
    		// instructions pour afficher un nouveau chiffre
     
    	}
     
    }
     
    // fonction principale
    //====================
    int main( int argc, char* args[] )
    {
    	// declaration de variables
    	//=========================
    	int height_cadre_bouton = SCREEN_HEIGHT/14;	
    	int marge_verticale1 = 30;
    	int width1 = 200;
     
    	// declaration des 3 variables
    	int nombre1;
     
    	// constantes 
    	const int MAX=10;
    	const int MIN=1;
     
    	// fonction qui donne un chiffre au hasard
    	srand(time(NULL));
     
    	//Initialize SDL
        SDL_Init( SDL_INIT_VIDEO );
    	//Set texture filtering to linear
    	SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" );
    	//Create window
    	gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
    	//Create vsynced renderer for window
    	gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
    	//Initialize renderer color
    	SDL_SetRenderDrawColor( gRenderer,127, 255, 0, 1 );
    	//Initialize PNG loading
    	int imgFlags = IMG_INIT_PNG;
    	IMG_Init( imgFlags );
    	//Initialize SDL_ttf
    	TTF_Init();
        //Open the font
    	font = TTF_OpenFont( "arial.ttf", 25 );
     
    	//Render the prompt
        bool bouton_suivant_clique = false;
     
        nombre1=(rand()%(MAX-MIN+1))+MIN;
    	std::string nombre1_string = std::to_string(nombre1);
     
    	//Clear screen
    	SDL_SetRenderDrawColor( gRenderer,127, 255, 0, 1 );
    	SDL_RenderClear( gRenderer );
     
    	cadre_A cadre_calcul;
        cadre_calcul.definition_rectangle_cadre (0, 0, width1, height_cadre_bouton);
    	cadre_calcul.render_texte(nombre1_string);	
    	cadre_calcul.affichage_cadre_plus_texte();
     
    	cadre_A cadre_suivant;
    	cadre_suivant.definition_rectangle_cadre (0, cadre_calcul.y_rectangle_cadre+marge_verticale1, width1, height_cadre_bouton);
    	cadre_suivant.render_texte("Suivant");
    	cadre_suivant.affichage_cadre_plus_texte();
     
    	// tableaux dynamiques de bouton
    	std::list<cadre_A > list_cadre_A;
    	list_cadre_A.push_back(cadre_calcul);
    	list_cadre_A.push_back(cadre_suivant);
     
    	//Main loop flag
    	bool quit = false;
     
    	//Event handler
    	SDL_Event e;
     
    	//While application is running
    	while( !quit )
    	{
    		//The rerender text flag
    		bool renderText = false;
            bool bouton_egal_clique = false;
     
    		//Handle events on queue
    		while( SDL_PollEvent( &e ) != 0 )
    		{
    			//User requests quit
    			if( e.type == SDL_QUIT )
    			{
    				quit = true;
    			}
     
                else if( /*e.type == SDL_MOUSEMOTION ||*/ e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP )
    			{
    				//Get mouse position
    				int x, y;
    				SDL_GetMouseState( &x, &y );
     
    				//Check if mouse is in button
    				bool inside = true;
     
    				// appel de la methode de vérification du clic du bouton suivant
    				cadre_suivant.proceder_click_souris(x, y);
    				cadre_calcul.render_texte(nombre1_string);	
    				cadre_calcul.affichage_cadre_plus_texte();
    			}
            }
     
    		//Clear screen
    	    SDL_SetRenderDrawColor( gRenderer,127, 255, 0, 1 );
    		SDL_RenderClear( gRenderer );
     
    		cadre_calcul.definition_rectangle_cadre (0, 0, width1, height_cadre_bouton);
    		cadre_calcul.affichage_cadre_plus_texte();		
     
    		cadre_suivant.definition_rectangle_cadre (0, cadre_calcul.y_rectangle_cadre+height_cadre_bouton+marge_verticale1, width1, height_cadre_bouton);
    		cadre_suivant.affichage_cadre_plus_texte();		
     
    		//Update screen
    		SDL_RenderPresent( gRenderer );
    	}
     
    	//Free resources and close SDL
     
    	//Free global font
    	TTF_CloseFont( font );
    	font = NULL;
     
    	//Destroy window	
    	SDL_DestroyRenderer( gRenderer );
    	SDL_DestroyWindow( gWindow );
    	gWindow = NULL;
    	gRenderer = NULL;
     
    	//Quit SDL subsystems
    	TTF_Quit();
    	IMG_Quit();
    	SDL_Quit();
     
    	return 0;
    }

  6. #6
    Expert confirmé
    Avatar de Mat.M
    Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2006
    Messages
    8 526
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2006
    Messages : 8 526
    Par défaut
    salut ça semble être bon après il faut agir en conséquence si le rectangle est bien cliqué

  7. #7
    Membre éclairé
    Homme Profil pro
    sans emploi
    Inscrit en
    Février 2014
    Messages
    365
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : sans emploi
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2014
    Messages : 365
    Par défaut
    merci Mat.M ça fonctionne
    voici le code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    // instruction préprocesseur: recopier le code qui se trouve dans le ficher
    //========================================================================
    #include <SDL.h>
    #include <SDL_image.h>
    #include <SDL_ttf.h>
    #include <stdio.h>
    #include <time.h>	// srand()
    #include <sstream>
    #include <regex>
    #include <string>       // classe std::string, fonction std::stof
    #include <iostream>     // fonction std::cout
    #include <list>
     
     
    // declaration, initialisation de variables
    //=========================================
     
    // dimension ecran
    const int SCREEN_WIDTH = 640;
    const int SCREEN_HEIGHT = 640;
     
    // The window we'll be rendering to
    SDL_Window* gWindow = NULL;
    // The window renderer
    SDL_Renderer* gRenderer = NULL;
    // Globally used font
    TTF_Font *font = NULL;
    SDL_Color couleur_texte = {6, 49, 196};
    // affichage cadre plus texte
    SDL_Rect* clip = NULL;
    double angle = 0.0;
    SDL_Point* center = NULL;
    SDL_RendererFlip flip = SDL_FLIP_NONE;
     
    // definition d'une classe pour créer des objets rectangles à l'écran
    //===================================================================
    class cadre_A
    {
    	// données privées: non accessible de l'extérieur de la classe
    	private:
     
    	// données, fonctions membres publiques
    	public:
    	std::string texte;
    	SDL_Surface* surface_texte;
    	SDL_Texture* texture_texte;
    	SDL_Rect texture_bouton;
     
    	// dimensions texture
    	int texture_width;
    	int texture_height;
     
    	// rectangle du cadre
    	//SDL_Rect rectangle_cadre = {int x_rectangle_cadre, int y_rectangle_cadre, int width_rectangle_cadre,int height_rectangle_cadre};
    	SDL_Rect rectangle_cadre;
    	int x_rectangle_cadre;
    	int y_rectangle_cadre;
    	int width_rectangle_cadre;
    	int height_rectangle_cadre;
     
    	// constructeur par défaut
    	// cadre_A(); syntaxe non valide
    	cadre_A() = default;	// ou cadre_A() {};
    	// destructeur
    	~cadre_A();
     
    	// déclaration de fonctions membres
    	// render texte
    	void render_texte(std::string texte_bis);
    	// definition rectangle cadre
    	void definition_rectangle_cadre (int x_rectangle_cadre_bis, int y_rectangle_cadre_bis, int width_rectangle_cadre_bis, int height_rectangle_cadre_bis);
    	// affichage cadre
    	void affichage_cadre_plus_texte ();
    	// méthode qui gère le clic souris X et Y
    	bool proceder_click_souris(int x_bis, int y_bis);
    };
     
    // defintion de fonctions membres
    cadre_A::~cadre_A()
    {
    	//Deallocate
    	SDL_DestroyTexture( texture_texte );
    	texture_texte = NULL;
    	texture_width = 0;
    	texture_height = 0;
    }
     
    void cadre_A::definition_rectangle_cadre (int x_rectangle_cadre_bis, int y_rectangle_cadre_bis, int width_rectangle_cadre_bis, int height_rectangle_cadre_bis)
    {
    	x_rectangle_cadre = x_rectangle_cadre_bis;
    	y_rectangle_cadre = y_rectangle_cadre_bis;
    	width_rectangle_cadre = width_rectangle_cadre_bis;
    	height_rectangle_cadre = height_rectangle_cadre_bis;
    	SDL_Rect rectangle_cadre = { x_rectangle_cadre, y_rectangle_cadre, width_rectangle_cadre, height_rectangle_cadre };
    	SDL_SetRenderDrawColor( gRenderer, 255, 20, 147, 1 );	
    	SDL_RenderFillRect( gRenderer, &rectangle_cadre );
    }
     
    void cadre_A::render_texte(std::string texte_bis)
    {
    	texte = texte_bis;
     
    	surface_texte = TTF_RenderText_Blended_Wrapped(font, texte.c_str(), couleur_texte, this->width_rectangle_cadre);
    	texture_texte = SDL_CreateTextureFromSurface( gRenderer, surface_texte);
    	texture_width = surface_texte->w;
        texture_height = surface_texte->h;
    }
     
    void cadre_A::affichage_cadre_plus_texte ()
    {
    	//Set rendering space and render to screen
        SDL_Rect texture_bouton = { x_rectangle_cadre+(width_rectangle_cadre-texture_width)/2, y_rectangle_cadre+(height_rectangle_cadre-texture_height)/2, texture_width, texture_height };
    	// definition couleur de remplissage du rectangle bouton
    	SDL_SetRenderDrawColor( gRenderer, 255, 20, 147, 1 );	
    	SDL_RenderFillRect( gRenderer, &texture_bouton );
        //Render to screen
    	SDL_RenderCopyEx( gRenderer, texture_texte, clip, &texture_bouton, angle, center, flip );
    }
     
    bool cadre_A::proceder_click_souris(int x_bis, int y_bis)
    {
    	if((
    		x_bis > this->x_rectangle_cadre &
    		x_bis < this->x_rectangle_cadre + this->width_rectangle_cadre &
    		y_bis > this->y_rectangle_cadre &
    		y_bis < this->y_rectangle_cadre + this->height_rectangle_cadre
    		))
    	{
    		// Si x et y sont des coordonnées inscrites dans le rectangle d'une instance de cadre_A alors agir en conséquence
    		return 1;	// <=> true
    	}
    	else
    	{
    		return 0;	// <=> false
    	}
    }
     
    // fonction principale
    //====================
    int main( int argc, char* args[] )
    {
    	// declaration de variables
    	//=========================
    	int height_cadre_bouton = SCREEN_HEIGHT/14;	
    	int marge_verticale1 = 30;
    	int width1 = 200;
     
    	// declaration des 3 variables
    	int nombre1;
     
    	// constantes 
    	const int MAX=10;
    	const int MIN=1;
     
    	// fonction qui donne un chiffre au hasard
    	srand(time(NULL));
     
    	//Initialize SDL
        SDL_Init( SDL_INIT_VIDEO );
    	//Set texture filtering to linear
    	SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" );
    	//Create window
    	gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
    	//Create vsynced renderer for window
    	gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
    	//Initialize renderer color
    	SDL_SetRenderDrawColor( gRenderer,127, 255, 0, 1 );
    	//Initialize PNG loading
    	int imgFlags = IMG_INIT_PNG;
    	IMG_Init( imgFlags );
    	//Initialize SDL_ttf
    	TTF_Init();
        //Open the font
    	font = TTF_OpenFont( "arial.ttf", 25 );
     
    	//Render the prompt
     
        nombre1=(rand()%(MAX-MIN+1))+MIN;
    	std::string nombre1_string = std::to_string(nombre1);
     
    	//Clear screen
    	SDL_SetRenderDrawColor( gRenderer,127, 255, 0, 1 );
    	SDL_RenderClear( gRenderer );
     
    	cadre_A cadre_calcul;
        cadre_calcul.definition_rectangle_cadre (0, 0, width1, height_cadre_bouton);
    	cadre_calcul.render_texte(nombre1_string);	
    	cadre_calcul.affichage_cadre_plus_texte();
     
    	cadre_A cadre_suivant;
    	cadre_suivant.definition_rectangle_cadre (0, cadre_calcul.y_rectangle_cadre+marge_verticale1, width1, height_cadre_bouton);
    	cadre_suivant.render_texte("Suivant");
    	cadre_suivant.affichage_cadre_plus_texte();
     
    	// tableaux dynamiques de bouton
    	std::list<cadre_A > list_cadre_A;
    	list_cadre_A.push_back(cadre_calcul);
    	list_cadre_A.push_back(cadre_suivant);
     
    	//Main loop flag
    	bool quit = false;
     
    	//Event handler
    	SDL_Event e;
     
    	//While application is running
    	while( !quit )
    	{
    		//The rerender text flag
    		bool renderText = false;
            bool bouton_egal_clique = false;
     
    		//Handle events on queue
    		while( SDL_PollEvent( &e ) != 0 )
    		{
    			//User requests quit
    			if( e.type == SDL_QUIT )
    			{
    				quit = true;
    			}
     
                else if( /*e.type == SDL_MOUSEMOTION ||*/ e.type == SDL_MOUSEBUTTONDOWN /*|| e.type == SDL_MOUSEBUTTONUP*/ )
    			{
    				//Get mouse position
    				int x, y;
    				SDL_GetMouseState( &x, &y );
     
    				// appel de la methode de vérification du clic du bouton suivant
    				if (cadre_suivant.proceder_click_souris(x, y))
    				{
    					std::cout << "cadre_suivant.proceder_click_souris(x, y)" << std::endl;
    					nombre1=(rand()%(MAX-MIN+1))+MIN;
    					nombre1_string = std::to_string(nombre1);
    					std::cout << nombre1_string << std::endl;
    					cadre_calcul.render_texte(nombre1_string);	
    				}
    			}
            }
     
    		//Clear screen
    	    SDL_SetRenderDrawColor( gRenderer,127, 255, 0, 1 );
    		SDL_RenderClear( gRenderer );
     
    		cadre_calcul.definition_rectangle_cadre (0, 0, width1, height_cadre_bouton);
    		cadre_calcul.affichage_cadre_plus_texte();		
     
    		cadre_suivant.definition_rectangle_cadre (0, cadre_calcul.y_rectangle_cadre+height_cadre_bouton+marge_verticale1, width1, height_cadre_bouton);
    		cadre_suivant.affichage_cadre_plus_texte();		
     
    		//Update screen
    		SDL_RenderPresent( gRenderer );
    	}
     
    	//Free resources and close SDL
     
    	//Free global font
    	TTF_CloseFont( font );
    	font = NULL;
     
    	//Destroy window	
    	SDL_DestroyRenderer( gRenderer );
    	SDL_DestroyWindow( gWindow );
    	gWindow = NULL;
    	gRenderer = NULL;
     
    	//Quit SDL subsystems
    	TTF_Quit();
    	IMG_Quit();
    	SDL_Quit();
     
    	return 0;
    }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [PHP 5.0] Optimisation boucle while pour envoi d'e-mails
    Par renaud26 dans le forum Langage
    Réponses: 1
    Dernier message: 18/02/2010, 08h22
  2. 2 boucle while pour même mysql_fetch_array
    Par babali33 dans le forum Langage
    Réponses: 3
    Dernier message: 29/04/2009, 15h52
  3. [MySQL] boucle while pour requête : erreur
    Par marcello06 dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 16/09/2008, 06h41
  4. Probleme dans une boucle while pour remplir une JTable
    Par sky88 dans le forum Composants
    Réponses: 3
    Dernier message: 27/03/2008, 14h01
  5. Réponses: 6
    Dernier message: 28/04/2006, 09h16

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo