Programme C
Fereah
-
Fereah -
Fereah -
Bonjour,
Je suis actuellement entrain de coder un programme en C. Mon programme ne comporte pour l'instant que 4fonctions d'en une qui permet de déplacer des fenêtres (que j'ai crée à l'intérieur de la fenêtre principal) grâce à la souris.
Sauf que lorsque je déplace la souris, la fenêtre mais quelque ms (environ 50ms) a réagir. Alors comment ce fait-il que mon programme qui a que 4 fonctions rame déjà, alors que des gros programme comme word ou Photoshop qui comprennent beaucoup beaucoup beaucoup plus de fonction rame pas ou moins que le miens ?
Merci pour vos réponses...
<config /.net>
Je suis actuellement entrain de coder un programme en C. Mon programme ne comporte pour l'instant que 4fonctions d'en une qui permet de déplacer des fenêtres (que j'ai crée à l'intérieur de la fenêtre principal) grâce à la souris.
Sauf que lorsque je déplace la souris, la fenêtre mais quelque ms (environ 50ms) a réagir. Alors comment ce fait-il que mon programme qui a que 4 fonctions rame déjà, alors que des gros programme comme word ou Photoshop qui comprennent beaucoup beaucoup beaucoup plus de fonction rame pas ou moins que le miens ?
Merci pour vos réponses...
<config /.net>
A voir également:
- Programme C
- Programme demarrage windows - Guide
- Message programmé iphone - Guide
- Mettre en veille un programme - Guide
- Programme word gratuit - Guide
- Cette action ne peut pas être réalisée car le fichier est ouvert dans un autre programme - Guide
2 réponses
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)...