sdl bouton
C
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
int creabouton(int positionx, int positiony, int w, int h, SDL_Surface* ecran, int couleura, int couleurb, int couleurc)
{
int continuer = 1, i = 0, resultat = 0, j = 0, resultat2 = 0, j2 = 0;
SDL_Event event;
SDL_Surface *bouton = NULL, *degrader = NULL;
SDL_Rect position, position2;
position.x = positionx;
position.y = positiony;
position2.x = positionx;
position2.y = positiony;
bouton = SDL_CreateRGBSurface(SDL_HWSURFACE, w, h, 32, 0, 0, 0, 0);
SDL_FillRect(bouton, NULL, SDL_MapRGB(ecran->format, couleura, couleurb, couleurc));
SDL_BlitSurface(bouton, NULL, ecran, &position);
resultat2 = (4*h)/100;
resultat = (4*w)/100;
for(i = 0; i < resultat || i < resultat2; i++)
{
if(i < resultat)
{
degrader = SDL_CreateRGBSurface(SDL_HWSURFACE, 1, h, 32, 0, 0, 0,0);
SDL_FillRect(degrader, NULL, SDL_MapRGB(bouton->format, j, j, j));
SDL_BlitSurface(degrader, NULL, ecran, &position);
position.x++;
j += 255/resultat;
}
if(i < resultat2)
{
degrader = SDL_CreateRGBSurface(SDL_HWSURFACE, w, 1, 32, 0, 0, 0,0);
SDL_FillRect(degrader, NULL, SDL_MapRGB(bouton->format, j2, j2, j2));
SDL_BlitSurface(degrader, NULL, ecran, &position2);
position2.y++;
j2 += 255/resultat2;
}
}
SDL_Flip(ecran);
while(continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
break;
case SDL_MOUSEBUTTONDOWN:
if(event.button.x >= positionx && event.button.x <= (positionx + w) && event.button.y >= positiony && event.button.y <= (positiony + h))
{
return 1;
continuer = 0;
}
break;
}
}
}
int main ( int argc, char** argv )
{
int fenetre = 0;
SDL_Surface *ecran = NULL;
SDL_Init(SDL_INIT_VIDEO);
SDL_Event event;
ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE);
SDL_WM_SetIcon(SDL_LoadBMP("icon.bmp"), NULL);
SDL_WM_SetCaption("Fenetre avec bouton a martin", NULL);
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
fenetre = creabouton(200, 300, 210, 100, ecran, 0, 0, 0);
SDL_Flip(ecran);
if(fenetre == 1)
{
fenetre = 0;
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 033, 50));
fenetre = creabouton(640/2, 480/2, 40, 40, ecran, 25, 250, 0);
SDL_Flip(ecran);
}
if(fenetre == 1)
{
fenetre = 0;
fenetre = creabouton(0, 0, 400, 360, ecran, 255, 0, 255);
}
SDL_Quit();
}
Also in C:
- Title
- delete string function in c
- Category
- C
- Title
- read a binary file c
- Category
- C
- Title
- remove an element from a set
- Category
- C
- Title
- can we write a program without main in c
- Category
- C
- Title
- how to print in c
- Category
- C
- Title
- accessing elements 2D array using pointers
- Category
- C
- Title
- diferencia entre * y & en c
- Category
- C
- Title
- assert() in c
- Category
- C
- Title
- C largest unsigned int
- Category
- C
- Title
- how to pass an array to a thread in c?
- Category
- C
- Title
- measure time in c
- Category
- C
- Title
- error 403
- Category
- C
- Title
- sleep in c programming
- Category
- C
- Title
- arduino knn
- Category
- C
- Title
- last element from list javascript
- Category
- C
- Title
- factors using recursion
- Category
- C
- Title
- arduino digital read
- Category
- C
- Title
- how to download file in powershell
- Category
- C
- Title
- xmlns='' was not expected
- Category
- C
- Title
- how to write function in c
- Category
- C
- Title
- kadane's algorithm
- Category
- C
- Title
- find string in all files powershell
- Category
- C
- Title
- for loop c
- Category
- C
- Title
- what is the meaningof noremap
- Category
- C
- Title
- c copy string
- Category
- C
- Title
- add border to image android
- Category
- C
- Title
- compare two chars c
- Category
- C
- Title
- code in c skipping over scanf
- Category
- C
- Title
- declaring a volatile in c
- Category
- C
- Title
- how to call the tkinter insert command from another class
- Category
- C
- Title
- declare character array statically?
- Category
- C
- Title
- set timezone in debian terminal
- Category
- C
- Title
- how to check the size of a file in linux c
- Category
- C
- Title
- msdos
- Category
- C
- Title
- vbnet create and write on file
- Category
- C
- Title
- remove element queue
- Category
- C
- Title
- primo
- Category
- C
- Title
- boolean function c
- Category
- C
- Title
- get regedit value cmd
- Category
- C
- Title
- -> operator
- Category
- C
- Title
- restapi
- Category
- C
- Title
- how to only show tenths place in c
- Category
- C
- Title
- c defined value sum
- Category
- C
- Title
- Couldn't create temporary file to work with
- Category
- C
- Title
- how to change the mapping from jkil to wasd in vim
- Category
- C
- Title
- how to free memory in c
- Category
- C
- Title
- where is my vimrc
- Category
- C
- Title
- variadic function in c
- Category
- C
- Title
- 233 pounds to inr
- Category
- C
- Title
- mĂșltiplos entre dos numeros en c
- Category
- C
- Title
- keras conv2d batchnorm
- Category
- C
- Title
- a enum data type in c with loop
- Category
- C
- Title
- how to put a struct in another struct C
- Category
- C
- Title
- c hello world
- Category
- C
- Title
- version of libgcc
- Category
- C
- Title
- c substring
- Category
- C
- Title
- use of matplotlib inline
- Category
- C
- Title
- c check if array is empty
- Category
- C
- Title
- mongodb delete all documents
- Category
- C
- Title
- typedef vs #define
- Category
- C
- Title
- '&&' within '||'
- Category
- C
- Title
- oop244
- Category
- C
- Title
- c matrix sintax
- Category
- C
- Title
- c program to find the sum of given number using recursion
- Category
- C
- Title
- CL/cl.h: No such file or directory
- Category
- C
- Title
- Fibonacci program c pthread
- Category
- C
- Title
- networkx remove attributes
- Category
- C
- Title
- what is x:Name Xamarin forms
- Category
- C
- Title
- docker logs follow
- Category
- C
- Title
- xamarin command listview button
- Category
- C
- Title
- c value set to zero __memmove_avx_unaligned_erms
- Category
- C
- Title
- read files in c
- Category
- C
- Title
- sue murry
- Category
- C
- Title
- a enum data type in c
- Category
- C
- Title
- uninstall elgg from hostgtor
- Category
- C
- Title
- typedef in c
- Category
- C
- Title
- cantidad de digitos recursiva
- Category
- C
- Title
- docker run port mapping
- Category
- C
- Title
- how can i remove a specific item from an array
- Category
- C
- Title
- full screen on c
- Category
- C
- Title
- hostbuilder add environment variables
- Category
- C
- Title
- how to create an array of char in c++
- Category
- C
- Title
- what is stdin in c
- Category
- C
- Title
- get a remote branch git
- Category
- C
- Title
- get_session` is not available when using TensorFlow 2.0.
- Category
- C
- Title
- iterate through map
- Category
- C
- Title
- hello world
- Category
- C
- Title
- print integer to stdout using write or putchar?
- Category
- C
- Title
- passing 'const char *' to parameter of type 'char *' discards qualifiers
- Category
- C
- Title
- csrf_exempt
- Category
- C
- Title
- confirm sweet alert
- Category
- C
- Title
- changing tuple values
- Category
- C
- Title
- too few arguments to function in c
- Category
- C
- Title
- entete c/c++
- Category
- C
- Title
- arduino digital input pins
- Category
- C
- Title
- c producer consumer pthread semaphore
- Category
- C
- Title
- multiplication in c
- Category
- C
- Title
- C/c drop mime
- Category
- C
- Title
- c isdigit function
- Category
- C
- Title
- python web crawler
- Category
- C