relais | salut je n'arrive pas a modifier la taille d'une surface rectangle=SDL_CreateRGBSurface
main.c
Code :
- #include <stdlib.h>
- #include <stdio.h>
- #include <math.h>
- #include <SDL/SDL.h>
- #include <stdlib.h>
- #include "main.h"
- void moteur(int*i);
- void animation(SDL_Surface *ecran);
- void traiterLesEvenements(input *in);
- int main(int argc,char *argv[])
- {
- input in;
- SDL_Init(SDL_INIT_VIDEO);
- SDL_Surface *ecran=NULL,*menu=NULL;
- ecran=SDL_SetVideoMode(600,500,32,SDL_HWSURFACE||SDL_DOUBLEBUF);
- menu=SDL_LoadBMP("menu.BMP" );
- SDL_Rect position;
- position.x=0;
- position.y=0;
- memset(&in,0,sizeof(in));
- while (!in.key[SDLK_ESCAPE] &&!in.quit)
- {
- traiterLesEvenements(&in);
- if (in.key[SDLK_1])
- {
- animation(ecran);
- }
- SDL_FillRect(ecran,NULL,SDL_MapRGB((*ecran).format,255,255,255));
- SDL_BlitSurface(menu,NULL,ecran,&position);
- SDL_Flip(ecran);
- }
- SDL_FreeSurface(menu);
- }
- void traiterLesEvenements(input *in)
- {
- SDL_Event event;
- while (SDL_PollEvent(&event))
- {
- switch (event.type)
- {
- case SDL_KEYDOWN:
- (*in).key[event.key.keysym.sym]=1;
- break;
- case SDL_KEYUP:
- (*in).key[event.key.keysym.sym]=0;
- break;
- case SDL_QUIT:
- (*in).quit=1;
- break;
- case SDL_MOUSEMOTION:
- (*in).mousex=event.motion.x;
- (*in).mousey=event.motion.y;
- break;
- case SDL_MOUSEBUTTONDOWN:
- (*in).mousebuttons[event.button.button-1]=1;
- break;
- case SDL_MOUSEBUTTONUP:
- (*in).mousebuttons[event.button.button-1]=0;
- break;
- }
- }
- }
- void animation(SDL_Surface *ecran)
- {
- input in;
- in.continu=0;
- int largeur=50,longeur=50;
- int *i=NULL,*j=&largeur;/*i et j permet de modifier la taille du rectangle */
- i=&longeur;
- SDL_Rect position1;
- SDL_Surface *rectangle=NULL;
- rectangle=SDL_CreateRGBSurface(SDL_HWSURFACE,longeur,largeur,32,0,0,0,0);
- memset(&in,0,sizeof(in));
- while (!in.continu)
- {
- position1.x=in.mousex;
- position1.y=in.mousey;
- if (in.key[SDLK_j])
- {
- in.continu=1;
- }
- if (in.key[SDLK_m])/*condition pour modifier la taille du rectangle*/
- {
- moteur(i);/*fonction pour changer la taille du rectanngle*/
- }
- traiterLesEvenements(&in);
- SDL_FillRect(ecran,NULL,SDL_MapRGB((*ecran).format,255,255,255));
- SDL_FillRect(rectangle,NULL,SDL_MapRGB((*ecran).format,0,0,0));
- SDL_BlitSurface(rectangle, NULL, ecran, &position1);
- SDL_Flip(ecran);
- }
- SDL_FreeSurface(rectangle);
- }
- void moteur(int *i)
- {
- *i=100;
- *j=100;
- }
|
main.h
Code :
- #ifndef MAIN_H_INCLUDED
- #define MAIN_H_INCLUDED
- #define TAILLE_BLOC 50
- #define NB_BLOC_LARGEUR 10
- #define NB_BLOC_LONGEUR 12
- #define LONGEUR_FENETRE NB_BLOC_LONGEUR*TAILLE_BLOC
- #define LARGEUR_FENETRE NB_BLOC_LARGEUR*TAILLE_BLOC
- typedef struct
- {
- char mousebuttons[6];
- char key[SDLK_LAST];
- int mousex,mousey,continu;
- char quit;
- }input;
- #endif
|
|