SDL_Button
ghada
-
varfendell Messages postés 3259 Date d'inscription Statut Membre Dernière intervention -
varfendell Messages postés 3259 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
SVP j'ai un probleme dans mon code SDL en faite je n'ai pas pu lancer une autre interface ou bien entrer des modifications sur l'interface existante lors de l'appui d'un bouton.
Càd j'ai pu détecter l'evenement(l'appui sur le 2eme bouton)mais lorsque je clique sur ce bouton il quitte.Alors?ça sera gentil si quelqu un me donne une soluton car cela m'enerve et je me sens vraiment bloquée.
Voici mon code:
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_ttf.h>
#include <string>
#include <SDL/SDL_mouse.h>
#define HAUTEUR 50
#define LARGEUR 200
void boutons(SDL_Surface* ecran,SDL_Surface* bouton,int x,int y)
{
SDL_Rect offset;
//SDL_Event event;
//int continuer = 1;
offset.x = x;
offset.y = y;
bouton= SDL_CreateRGBSurface(SDL_HWSURFACE, 200, 80, 32, 0, 0, 0, 0);
SDL_SetAlpha(bouton, SDL_SRCALPHA, 140);
SDL_FillRect(bouton, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
SDL_BlitSurface(bouton, NULL, ecran, &offset);
/*switch(event.type)
{
case SDL_QUIT:
continuer = 0;
break;
case SDL_MOUSEBUTTONUP:
if (event.button.button == SDL_BUTTON_RIGHT) /* On arrête le programme si on a fait un clic droit */
// continuer = 0;
// break;
//}
}
void text(SDL_Surface *ecran,SDL_Surface *texte, int x,int y,const char *message)
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
TTF_Font *police = NULL;
SDL_Color couleurNoire = {255, 255, 255};
const char* fontname="goodfish.ttf";
printf("dans la fonction texte\n");
if(!TTF_WasInit())
{
int init = TTF_Init();
if(init ==-1)
printf("TTF_Init: %s\n", TTF_GetError());
}
/* Ecriture du texte dans la SDL_Surface "texte" en mode Blended (optimal) */
police = TTF_OpenFont(fontname,60);//initialisztion de TTF
printf("la taille du font =%d\n",TTF_FontHeight(police));
if(police==NULL)
{
printf("erreur de chargement de la police%s erreur=%s\n",fontname,SDL_GetError());
}
else
{
printf("chargement de la police\n");
texte = TTF_RenderText_Blended(police, message, couleurNoire);
if (texte==NULL)
{
printf("texte null\n");
}
else
{
printf("texte non nul\n");
SDL_BlitSurface(texte, NULL, ecran, &offset); /* Blit du texte par-dessus */
printf("texte applied\n");
}
TTF_CloseFont(police);
}
}
int main(int argc, char *argv[])
{
int fenetre = 0;
SDL_Surface *ecran = NULL,*imageDeFont = NULL,*bouton=NULL,*texte = NULL;
SDL_Rect positionFont,position ;
positionFont.x = 0;
positionFont.y = 0;
SDL_Event event;
int continuer = 1;
SDL_Init(SDL_INIT_VIDEO);
/* Chargement d'une image Bitmap dans une surface */
ecran = SDL_SetVideoMode(1500, 1500, 32, SDL_HWSURFACE| SDL_DOUBLEBUF);
SDL_WM_SetCaption("Menu de configuration", NULL);
imageDeFont = SDL_LoadBMP("font d'ecran.bmp");
/*icone du menu*/
SDL_WM_SetIcon(SDL_LoadBMP("icone de menu.bmp"), NULL);
/* On blitte par-dessus l'écran */
SDL_BlitSurface(imageDeFont, NULL, ecran, &positionFont);
/*Boutons*/
boutons(ecran , bouton ,50 ,80);
boutons(ecran , bouton ,300 ,80);
boutons(ecran , bouton ,550,80);
boutons(ecran , bouton ,800 ,80);
boutons(ecran , bouton ,1050 ,80);
/*Texts*/
printf("appel de la fonction texte\n");
text(ecran ,texte ,180 ,250 ,"Nom");
text(ecran ,texte ,180 ,400 ,"Prenom");
text(ecran ,texte ,180,550 ,"Login");
text(ecran ,texte ,70,80 ,"Info");
text(ecran ,texte ,300,80 ,"Video");
text(ecran ,texte ,550,80 ,"Audio");
text(ecran ,texte ,800,80 ,"Reseau");
text(ecran ,texte ,1100,80 ,"STB");
printf("aprés l'appel de la fonction texte\n");
SDL_Flip(ecran);
while(continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
break;
case SDL_MOUSEBUTTONDOWN:
{
if(event.button.x >= 300 && event.button.x <= 500 && event.button.y >= 80 && event.button.y <= 160)
{
return 1;
continuer = 0;
printf("appel de la fonction texte\n");
text(ecran ,texte ,180 ,250 ,"Type Video");
text(ecran ,texte ,180 ,400 ,"Format Video");
text(ecran ,texte ,180,550 ,"Resolution");
text(ecran ,texte ,180,700 ,"Soutitrage");
text(ecran ,texte ,360,700 ,"Langage de soutitrage");
}
break;
}
}
}
}
SVP j'ai un probleme dans mon code SDL en faite je n'ai pas pu lancer une autre interface ou bien entrer des modifications sur l'interface existante lors de l'appui d'un bouton.
Càd j'ai pu détecter l'evenement(l'appui sur le 2eme bouton)mais lorsque je clique sur ce bouton il quitte.Alors?ça sera gentil si quelqu un me donne une soluton car cela m'enerve et je me sens vraiment bloquée.
Voici mon code:
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_ttf.h>
#include <string>
#include <SDL/SDL_mouse.h>
#define HAUTEUR 50
#define LARGEUR 200
void boutons(SDL_Surface* ecran,SDL_Surface* bouton,int x,int y)
{
SDL_Rect offset;
//SDL_Event event;
//int continuer = 1;
offset.x = x;
offset.y = y;
bouton= SDL_CreateRGBSurface(SDL_HWSURFACE, 200, 80, 32, 0, 0, 0, 0);
SDL_SetAlpha(bouton, SDL_SRCALPHA, 140);
SDL_FillRect(bouton, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
SDL_BlitSurface(bouton, NULL, ecran, &offset);
/*switch(event.type)
{
case SDL_QUIT:
continuer = 0;
break;
case SDL_MOUSEBUTTONUP:
if (event.button.button == SDL_BUTTON_RIGHT) /* On arrête le programme si on a fait un clic droit */
// continuer = 0;
// break;
//}
}
void text(SDL_Surface *ecran,SDL_Surface *texte, int x,int y,const char *message)
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
TTF_Font *police = NULL;
SDL_Color couleurNoire = {255, 255, 255};
const char* fontname="goodfish.ttf";
printf("dans la fonction texte\n");
if(!TTF_WasInit())
{
int init = TTF_Init();
if(init ==-1)
printf("TTF_Init: %s\n", TTF_GetError());
}
/* Ecriture du texte dans la SDL_Surface "texte" en mode Blended (optimal) */
police = TTF_OpenFont(fontname,60);//initialisztion de TTF
printf("la taille du font =%d\n",TTF_FontHeight(police));
if(police==NULL)
{
printf("erreur de chargement de la police%s erreur=%s\n",fontname,SDL_GetError());
}
else
{
printf("chargement de la police\n");
texte = TTF_RenderText_Blended(police, message, couleurNoire);
if (texte==NULL)
{
printf("texte null\n");
}
else
{
printf("texte non nul\n");
SDL_BlitSurface(texte, NULL, ecran, &offset); /* Blit du texte par-dessus */
printf("texte applied\n");
}
TTF_CloseFont(police);
}
}
int main(int argc, char *argv[])
{
int fenetre = 0;
SDL_Surface *ecran = NULL,*imageDeFont = NULL,*bouton=NULL,*texte = NULL;
SDL_Rect positionFont,position ;
positionFont.x = 0;
positionFont.y = 0;
SDL_Event event;
int continuer = 1;
SDL_Init(SDL_INIT_VIDEO);
/* Chargement d'une image Bitmap dans une surface */
ecran = SDL_SetVideoMode(1500, 1500, 32, SDL_HWSURFACE| SDL_DOUBLEBUF);
SDL_WM_SetCaption("Menu de configuration", NULL);
imageDeFont = SDL_LoadBMP("font d'ecran.bmp");
/*icone du menu*/
SDL_WM_SetIcon(SDL_LoadBMP("icone de menu.bmp"), NULL);
/* On blitte par-dessus l'écran */
SDL_BlitSurface(imageDeFont, NULL, ecran, &positionFont);
/*Boutons*/
boutons(ecran , bouton ,50 ,80);
boutons(ecran , bouton ,300 ,80);
boutons(ecran , bouton ,550,80);
boutons(ecran , bouton ,800 ,80);
boutons(ecran , bouton ,1050 ,80);
/*Texts*/
printf("appel de la fonction texte\n");
text(ecran ,texte ,180 ,250 ,"Nom");
text(ecran ,texte ,180 ,400 ,"Prenom");
text(ecran ,texte ,180,550 ,"Login");
text(ecran ,texte ,70,80 ,"Info");
text(ecran ,texte ,300,80 ,"Video");
text(ecran ,texte ,550,80 ,"Audio");
text(ecran ,texte ,800,80 ,"Reseau");
text(ecran ,texte ,1100,80 ,"STB");
printf("aprés l'appel de la fonction texte\n");
SDL_Flip(ecran);
while(continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
break;
case SDL_MOUSEBUTTONDOWN:
{
if(event.button.x >= 300 && event.button.x <= 500 && event.button.y >= 80 && event.button.y <= 160)
{
return 1;
continuer = 0;
printf("appel de la fonction texte\n");
text(ecran ,texte ,180 ,250 ,"Type Video");
text(ecran ,texte ,180 ,400 ,"Format Video");
text(ecran ,texte ,180,550 ,"Resolution");
text(ecran ,texte ,180,700 ,"Soutitrage");
text(ecran ,texte ,360,700 ,"Langage de soutitrage");
}
break;
}
}
}
}
1 réponse
Bonjour,
Re-poste ton problème de manière compréhensible en mettant ton code entre les balise approprié pour qu'on puisse comprendre quelque chose et je t'aiderais.
Re-poste ton problème de manière compréhensible en mettant ton code entre les balise approprié pour qu'on puisse comprendre quelque chose et je t'aiderais.
c'est plus compréhensible pour nous d'avoir <code> <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'> <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='fr'> <head> <title>cartographie Orange</title> <link rel='stylesheet' type='text/css' href='Cartes.css'> <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' /> <script type='text/javascript' src='http://maps.google.com/maps/api/js?sensor=true'></script> <script type='text/javascript' src='temp.js'></script> </head> <body> <script> window.onload = function() { var maCarte = new Carte(9, 3, 3, 'ROADMAP'); maCarte.addTrait('un petit cable', 'one', 1, 3, 1, 2); } </script> <div id='map' class='map' style='width:85%; height:75%' > </div> </body> </html>plutot qu'un gros
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='fr'>
<head>
<title>cartographie Orange</title>
<link rel='stylesheet' type='text/css' href='Cartes.css'>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
<script type='text/javascript' src='http://maps.google.com/maps/api/js?sensor=true'></script>
<script type='text/javascript' src='temp.js'></script>
</head>
<body>
<script>
window.onload = function() {
var maCarte = new Carte(9, 3, 3, 'ROADMAP');
maCarte.addTrait('un petit cable', 'one', 1, 3, 1, 2);
}
</script>
<div id='map' class='map' style='width:85%; height:75%' >
</div>
</body>
</html>