A voir également:
- Programme C
- Programme demarrage windows 10 - Guide
- Désinstaller programme windows 10 - Guide
- Cette action ne peut pas être réalisée car le fichier est ouvert dans un autre programme - Guide
- Forcer la fermeture d'un programme - Guide
- Programme démarrage windows 10 - Guide
2 réponses
Utilisateur anonyme
5 déc. 2013 à 12:52
5 déc. 2013 à 12:52
Bonjour, un peu plus de détails pourrait nous permettre de mieux résoudre ton soucis.
(échantillon de code, environnement de travail, IDE...)
Cordialement
(échantillon de code, environnement de travail, IDE...)
Cordialement
Voilà le code pour créer une fenetre dans la fenetre principal et la déplacé:
SDL_Surface window(int widthWindow, int heightWindow, int pixelWindow, int colorR, int colorG, int colorB, SDL_Surface *surface, SDL_Rect *positionWindow)
{
SDL_Surface *window = NULL, *stripMark =NULL, *mark = NULL, *strip[4] = {NULL}; /* Surface declaration */
SDL_Rect positionMark = {widthWindow - 10, 1}, positionStrip[4] = {{0, 0}, {0, heightWindow - 1}, {0, 0}, {widthWindow - 1, 0}}, positionStripMark = {1, 1}; /* Position declaration */
SDL_Event event;
int i = 0; /* Variable declaration */
int click = 0; /* Variable declaration */
int continuer = 0; /* Variable declaration */
mark = IMG_Load("mark10.bmp"); /* Loading image */
window = SDL_CreateRGBSurface(SDL_HWSURFACE, widthWindow, heightWindow, pixelWindow, 0, 0, 0, 0); /* Creation window */
SDL_FillRect(window, NULL, SDL_MapRGB(window -> format, colorR, colorG, colorB)); /* window -> parameter function */
stripMark = SDL_CreateRGBSurface(SDL_HWSURFACE, widthWindow, 10, 32, 0, 0, 0, 0); /* Creation stripMark */
SDL_FillRect(stripMark, NULL, SDL_MapRGB(stripMark -> format, 35, 70, 140)); /* stripMark -> blue */
for(i = 0 ; i < 4 ; i++)
{
strip[0] = SDL_CreateRGBSurface(SDL_HWSURFACE, widthWindow, 1, 32, 0, 0, 0, 0);
strip[1] = SDL_CreateRGBSurface(SDL_HWSURFACE, widthWindow, 1, 32, 0, 0, 0, 0);
strip[2] = SDL_CreateRGBSurface(SDL_HWSURFACE, 1, heightWindow, 32, 0, 0, 0, 0);
strip[3] = SDL_CreateRGBSurface(SDL_HWSURFACE, 1, heightWindow, 32, 0, 0, 0, 0);
SDL_FillRect(strip[i], NULL, SDL_MapRGB(strip[i] -> format, 150, 150, 150)); /* strip -> gray */
}
for(i = 0 ; i < 4 ; i++) /* Loop creation strip[i] */
{
SDL_BlitSurface(strip[i], NULL, window, &positionStrip[i]); /* Blit strip -> window */
}
while(continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
break;
case SDL_MOUSEBUTTONDOWN:
/* If the user click on the stripMark */
if((event.button.x >= positionWindow -> x + 1) && (event.button.x <= positionWindow -> x + WIDTH_WINDOW + 1) && (event.button.y >= positionWindow -> y + 1) && (event.button.y <= positionWindow -> y + HEIGHT_WINDOW + 1))
{
click = 1; /* Click enabled */
}
break;
case SDL_MOUSEMOTION:
if(click == 1) /* If click enabled */
{
/* If the window doesn't exceed the screen */
if((positionWindow -> x > 0) || (positionWindow -> x + widthWindow < WIDTH_WINDOW) || (positionWindow -> y > 0) || (positionWindow -> y + heightWindow < HEIGHT_WINDOW))
{
positionWindow -> x = event.motion.x - positionWindow -> x; /* Move window in x */
positionWindow -> y = event.motion.y - positionWindow -> y; /* Move window in y */
}
}
break;
case SDL_MOUSEBUTTONUP:
click = 0; /* Click disabled */
break;
}
SDL_FillRect(surface, NULL, SDL_MapRGB(surface -> format, 255, 255, 255)); /* surface -> white */
SDL_BlitSurface(stripMark, NULL, window, &positionStripMark); /* Blit stripMark -< window */
SDL_BlitSurface(mark, NULL, window, &positionMark); /* Blit mark -> window */
SDL_BlitSurface(window, NULL, surface, positionWindow); /* Blit window -> surface */
SDL_Flip(surface); /* Update surface */
}
return *window;
}
Sinon je code avec vim et je compile avec le compilateur c linux (commande cc)...
SDL_Surface window(int widthWindow, int heightWindow, int pixelWindow, int colorR, int colorG, int colorB, SDL_Surface *surface, SDL_Rect *positionWindow)
{
SDL_Surface *window = NULL, *stripMark =NULL, *mark = NULL, *strip[4] = {NULL}; /* Surface declaration */
SDL_Rect positionMark = {widthWindow - 10, 1}, positionStrip[4] = {{0, 0}, {0, heightWindow - 1}, {0, 0}, {widthWindow - 1, 0}}, positionStripMark = {1, 1}; /* Position declaration */
SDL_Event event;
int i = 0; /* Variable declaration */
int click = 0; /* Variable declaration */
int continuer = 0; /* Variable declaration */
mark = IMG_Load("mark10.bmp"); /* Loading image */
window = SDL_CreateRGBSurface(SDL_HWSURFACE, widthWindow, heightWindow, pixelWindow, 0, 0, 0, 0); /* Creation window */
SDL_FillRect(window, NULL, SDL_MapRGB(window -> format, colorR, colorG, colorB)); /* window -> parameter function */
stripMark = SDL_CreateRGBSurface(SDL_HWSURFACE, widthWindow, 10, 32, 0, 0, 0, 0); /* Creation stripMark */
SDL_FillRect(stripMark, NULL, SDL_MapRGB(stripMark -> format, 35, 70, 140)); /* stripMark -> blue */
for(i = 0 ; i < 4 ; i++)
{
strip[0] = SDL_CreateRGBSurface(SDL_HWSURFACE, widthWindow, 1, 32, 0, 0, 0, 0);
strip[1] = SDL_CreateRGBSurface(SDL_HWSURFACE, widthWindow, 1, 32, 0, 0, 0, 0);
strip[2] = SDL_CreateRGBSurface(SDL_HWSURFACE, 1, heightWindow, 32, 0, 0, 0, 0);
strip[3] = SDL_CreateRGBSurface(SDL_HWSURFACE, 1, heightWindow, 32, 0, 0, 0, 0);
SDL_FillRect(strip[i], NULL, SDL_MapRGB(strip[i] -> format, 150, 150, 150)); /* strip -> gray */
}
for(i = 0 ; i < 4 ; i++) /* Loop creation strip[i] */
{
SDL_BlitSurface(strip[i], NULL, window, &positionStrip[i]); /* Blit strip -> window */
}
while(continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
break;
case SDL_MOUSEBUTTONDOWN:
/* If the user click on the stripMark */
if((event.button.x >= positionWindow -> x + 1) && (event.button.x <= positionWindow -> x + WIDTH_WINDOW + 1) && (event.button.y >= positionWindow -> y + 1) && (event.button.y <= positionWindow -> y + HEIGHT_WINDOW + 1))
{
click = 1; /* Click enabled */
}
break;
case SDL_MOUSEMOTION:
if(click == 1) /* If click enabled */
{
/* If the window doesn't exceed the screen */
if((positionWindow -> x > 0) || (positionWindow -> x + widthWindow < WIDTH_WINDOW) || (positionWindow -> y > 0) || (positionWindow -> y + heightWindow < HEIGHT_WINDOW))
{
positionWindow -> x = event.motion.x - positionWindow -> x; /* Move window in x */
positionWindow -> y = event.motion.y - positionWindow -> y; /* Move window in y */
}
}
break;
case SDL_MOUSEBUTTONUP:
click = 0; /* Click disabled */
break;
}
SDL_FillRect(surface, NULL, SDL_MapRGB(surface -> format, 255, 255, 255)); /* surface -> white */
SDL_BlitSurface(stripMark, NULL, window, &positionStripMark); /* Blit stripMark -< window */
SDL_BlitSurface(mark, NULL, window, &positionMark); /* Blit mark -> window */
SDL_BlitSurface(window, NULL, surface, positionWindow); /* Blit window -> surface */
SDL_Flip(surface); /* Update surface */
}
return *window;
}
Sinon je code avec vim et je compile avec le compilateur c linux (commande cc)...