Commit dbd583f9bfb815600fa8c6653ce63634dba43b90
1 parent
0e3aac2d
ajout projet
Showing
37 changed files
with
396 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
1 | +# | ||
2 | +# Makefile pour la bibliotheque graphique | ||
3 | +# | ||
4 | + | ||
5 | +SOURCES = $(wildcard *.c) | ||
6 | +OBJETS = $(SOURCES:.c=.o) | ||
7 | +CIBLE = libgraph.a | ||
8 | + | ||
9 | +# | ||
10 | +# Nom de la cible principale | ||
11 | +# | ||
12 | + | ||
13 | +all: $(CIBLE) | ||
14 | + | ||
15 | +# | ||
16 | +# Cible de nettoyage | ||
17 | +# | ||
18 | + | ||
19 | +clean: | ||
20 | + rm -f core *.o $(CIBLE) | ||
21 | + | ||
22 | +# | ||
23 | +# Dependances pour la bibliotheque | ||
24 | +# | ||
25 | + | ||
26 | +$(CIBLE): $(OBJETS) | ||
27 | + $(AR) rs $@ $? | ||
28 | + | ||
29 | +$(CIBLE:.a=).o: $(CIBLE:.a=).c $(CIBLE:.a=).h |
No preview for this file type
@@ -0,0 +1,180 @@ | @@ -0,0 +1,180 @@ | ||
1 | +/**** Bibliotheque graphique ****/ | ||
2 | + | ||
3 | +/** Fichiers d'inclusion **/ | ||
4 | + | ||
5 | +#include <SDL/SDL.h> | ||
6 | + | ||
7 | +#include "libgraph.h" | ||
8 | + | ||
9 | +/** Types **/ | ||
10 | + | ||
11 | +typedef struct { int r,v,b; } couleur; | ||
12 | + | ||
13 | +/** Constantes **/ | ||
14 | + | ||
15 | +#define BITS_PAR_PIXEL 32 | ||
16 | + | ||
17 | +static const couleur couleurs[]={ | ||
18 | + {255,255,255}, | ||
19 | + {0,0,0}, | ||
20 | + {255,0,0}, | ||
21 | + {0,255,0}, | ||
22 | + {0,0,255}, | ||
23 | + {255,105,180}, | ||
24 | + {150,150,150}, | ||
25 | + {-1,-1,-1} | ||
26 | + }; | ||
27 | + | ||
28 | +/** Variables globales **/ | ||
29 | + | ||
30 | +static SDL_Surface *surface; | ||
31 | + | ||
32 | +/** Fonctions **/ | ||
33 | + | ||
34 | +/* Initialisation de la surface dessinable */ | ||
35 | + | ||
36 | +unsigned char creerSurface(int largeur,int hauteur,char *titre){ | ||
37 | +SDL_Init(SDL_INIT_VIDEO); | ||
38 | +SDL_WM_SetCaption(titre,titre); | ||
39 | +surface=SDL_SetVideoMode(largeur,hauteur,BITS_PAR_PIXEL,SDL_DOUBLEBUF); | ||
40 | +return (surface!=NULL); | ||
41 | +} | ||
42 | + | ||
43 | +/* Fermeture de la surface dessinable */ | ||
44 | + | ||
45 | +void fermerSurface(void){ | ||
46 | +if(surface!=NULL) SDL_FreeSurface(surface); | ||
47 | +SDL_Quit(); | ||
48 | +} | ||
49 | + | ||
50 | +/* Creation d'une couleur */ | ||
51 | + | ||
52 | +static int creerCouleur(int ncouleur){ | ||
53 | +couleur c=couleurs[ncouleur]; | ||
54 | +return SDL_MapRGB(surface->format,c.r,c.v,c.b); | ||
55 | +} | ||
56 | + | ||
57 | +/* Dessin d'un rectangle plein */ | ||
58 | + | ||
59 | +void rectanglePlein(int x,int y,int l,int h,int c){ | ||
60 | +SDL_Rect rectangle={x,y,l,h}; | ||
61 | +SDL_FillRect(surface,&rectangle,creerCouleur(c)); | ||
62 | +//SDL_Flip(surface); | ||
63 | +} | ||
64 | + | ||
65 | +/* Manipulation de lutins */ | ||
66 | + | ||
67 | +static SDL_Surface *lutins[MAX_LUTINS]; | ||
68 | +static int lutins_nb=0; | ||
69 | + | ||
70 | +static void configurerLutin(SDL_Surface *lutin,int ncouleur){ | ||
71 | +couleur c=couleurs[ncouleur]; | ||
72 | +int fond=SDL_MapRGB(lutin->format,c.r,c.v,c.b); | ||
73 | +SDL_SetColorKey(lutin,SDL_SRCCOLORKEY|SDL_RLEACCEL,fond); | ||
74 | +} | ||
75 | + | ||
76 | +int chargerLutin(char *fichier,int couleur){ | ||
77 | +if(lutins_nb>=MAX_LUTINS) return -2; | ||
78 | +SDL_Surface *lutin=SDL_LoadBMP(fichier); | ||
79 | +if(lutin!=NULL){ | ||
80 | + lutins[lutins_nb++]=lutin; | ||
81 | + if(couleur>=0) configurerLutin(lutin,couleur); | ||
82 | + return lutins_nb-1; | ||
83 | + } | ||
84 | +return -1; | ||
85 | +} | ||
86 | + | ||
87 | +void afficherLutin(int lutin,int x,int y){ | ||
88 | +SDL_Rect position; | ||
89 | +position.x=x; | ||
90 | +position.y=y; | ||
91 | +SDL_BlitSurface(lutins[lutin],NULL,surface,&position); | ||
92 | +} | ||
93 | + | ||
94 | +int creerLutin(int x,int y,int largeur,int hauteur,int couleur){ | ||
95 | +if(lutins_nb>=MAX_LUTINS) return -2; | ||
96 | +int rmask,gmask,bmask,amask; | ||
97 | +#if SDL_BYTEORDER == SDL_BIG_ENDIAN | ||
98 | +rmask=0xff000000; gmask=0x00ff0000; bmask=0x0000ff00; amask=0x000000ff; | ||
99 | +#else | ||
100 | +rmask=0x000000ff; gmask=0x0000ff00; bmask=0x00ff0000; amask=0xff000000; | ||
101 | +#endif | ||
102 | +if(couleur<0) amask=0x00000000; | ||
103 | +SDL_Surface *lutin=SDL_CreateRGBSurface(0,largeur,hauteur,BITS_PAR_PIXEL,rmask,gmask,bmask,amask); | ||
104 | +SDL_Rect fenetre; | ||
105 | +fenetre.x=x; | ||
106 | +fenetre.y=y; | ||
107 | +fenetre.h=hauteur; | ||
108 | +fenetre.w=largeur; | ||
109 | +SDL_BlitSurface(surface,&fenetre,lutin,NULL); | ||
110 | +lutins[lutins_nb++]=lutin; | ||
111 | +if(couleur>=0) configurerLutin(lutin,couleur); | ||
112 | +return lutins_nb-1; | ||
113 | +} | ||
114 | + | ||
115 | +void tailleLutin(int lutin,int *largeur,int *hauteur){ | ||
116 | +*largeur=lutins[lutin]->w; | ||
117 | +*hauteur=lutins[lutin]->h; | ||
118 | +} | ||
119 | + | ||
120 | +int sauverLutin(int lutin,char *nom){ return SDL_SaveBMP(lutins[lutin],nom); } | ||
121 | + | ||
122 | +/* Manipulation de copie de surface en BMP */ | ||
123 | + | ||
124 | +int sauverSurface(char *fichier){ return SDL_SaveBMP(surface,fichier); } | ||
125 | + | ||
126 | +unsigned char chargerSurface(char *fichier){ | ||
127 | +SDL_Surface *image=SDL_LoadBMP(fichier); | ||
128 | +if(image!=NULL){ | ||
129 | + SDL_BlitSurface(image,NULL,surface,NULL); | ||
130 | + SDL_Flip(surface); | ||
131 | + } | ||
132 | +return (image!=NULL); | ||
133 | +} | ||
134 | + | ||
135 | +void majSurface(void){ SDL_Flip(surface); } | ||
136 | + | ||
137 | +/* Trouver la couleur d'un pixel */ | ||
138 | + | ||
139 | +int couleurPixel(int x,int y){ | ||
140 | +int bpp=surface->format->BytesPerPixel; | ||
141 | +Uint32 *p=(Uint32 *)(surface->pixels+y*surface->pitch+x*bpp); | ||
142 | +Uint8 r,v,b; | ||
143 | +SDL_GetRGB(*p,surface->format,&r,&v,&b); | ||
144 | +int i=0; | ||
145 | +while(1){ | ||
146 | + if(couleurs[i].r<0) break; | ||
147 | + if(r==couleurs[i].r && v==couleurs[i].v && b==couleurs[i].b) break; | ||
148 | + i++; | ||
149 | + } | ||
150 | +if(couleurs[i].r<0) return -1; else return i; | ||
151 | +} | ||
152 | + | ||
153 | +/* Fonction de traitement des événements */ | ||
154 | + | ||
155 | +unsigned char lireTouche(unsigned char *bas,char *touche,void **detail){ | ||
156 | +static SDL_keysym _detail; | ||
157 | +SDL_Event event; | ||
158 | +while(SDL_PollEvent(&event)){ | ||
159 | + if(event.type==SDL_KEYDOWN || event.type==SDL_KEYUP){ | ||
160 | + *bas=(event.type==SDL_KEYDOWN)?1:0; | ||
161 | + char* nom=SDL_GetKeyName(event.key.keysym.sym); | ||
162 | + if(strlen(nom)==1 && nom[0]>=32 && nom[0]<128) *touche=nom[0]; else *touche=0; | ||
163 | + _detail=event.key.keysym; | ||
164 | + *detail=&_detail; | ||
165 | + return 1; | ||
166 | + } | ||
167 | + } | ||
168 | +return 0; | ||
169 | +} | ||
170 | + | ||
171 | +void attendreEvenement(void){ | ||
172 | +SDL_Event event; | ||
173 | +while(SDL_WaitEvent(&event)) | ||
174 | + switch(event.type){ | ||
175 | + case SDL_KEYDOWN: | ||
176 | + case SDL_MOUSEBUTTONDOWN: | ||
177 | + case SDL_QUIT: | ||
178 | + return; | ||
179 | + } | ||
180 | +} |
@@ -0,0 +1,33 @@ | @@ -0,0 +1,33 @@ | ||
1 | +/**** Bibliotheque graphique (definitions) ****/ | ||
2 | + | ||
3 | +/** Constantes **/ | ||
4 | + | ||
5 | +#define COULEUR_BLANC 0 | ||
6 | +#define COULEUR_NOIR 1 | ||
7 | +#define COULEUR_ROUGE 2 | ||
8 | +#define COULEUR_VERT 3 | ||
9 | +#define COULEUR_BLEU 4 | ||
10 | +#define COULEUR_ROSE 5 | ||
11 | +#define COULEUR_GRIS 6 | ||
12 | + | ||
13 | +#define MAX_LUTINS 16 | ||
14 | + | ||
15 | +/** Prototypes **/ | ||
16 | + | ||
17 | +unsigned char creerSurface(int largeur,int hauteur,char *titre); | ||
18 | +unsigned char chargerSurface(char *fichier); | ||
19 | +int sauverSurface(char *fichier); | ||
20 | +void majSurface(void); | ||
21 | +void fermerSurface(void); | ||
22 | + | ||
23 | +void rectanglePlein(int x,int y,int l,int h,int c); | ||
24 | +int couleurPixel(int x,int y); | ||
25 | + | ||
26 | +int chargerLutin(char *fichier,int couleur); | ||
27 | +void afficherLutin(int lutin,int x,int y); | ||
28 | +int creerLutin(int x,int y,int largeur,int hauteur,int couleur); | ||
29 | +int sauverLutin(int lutin,char *nom); | ||
30 | +void tailleLutin(int lutin,int *largeur,int *hauteur); | ||
31 | + | ||
32 | +unsigned char lireTouche(unsigned char *bas,char *touche,void **detail); | ||
33 | +void attendreEvenement(void); |
No preview for this file type
@@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
1 | +# | ||
2 | +# Makefile pour la bibliotheque graphique | ||
3 | +# | ||
4 | + | ||
5 | +SOURCES = $(wildcard *.c) | ||
6 | +OBJETS = $(SOURCES:.c=.o) | ||
7 | +CIBLE = libListe.a | ||
8 | + | ||
9 | +# | ||
10 | +# Nom de la cible principale | ||
11 | +# | ||
12 | + | ||
13 | +all: $(CIBLE) | ||
14 | + | ||
15 | +# | ||
16 | +# Cible de nettoyage | ||
17 | +# | ||
18 | + | ||
19 | +clean: | ||
20 | + rm -f core *.o $(CIBLE) | ||
21 | + | ||
22 | +# | ||
23 | +# Dependances pour la bibliotheque | ||
24 | +# | ||
25 | + | ||
26 | +$(CIBLE): $(OBJETS) | ||
27 | + $(AR) rs $@ $? | ||
28 | + | ||
29 | +$(CIBLE:.a=).o: $(CIBLE:.a=).c $(CIBLE:.a=).h |
@@ -0,0 +1,49 @@ | @@ -0,0 +1,49 @@ | ||
1 | +#include <stdio.h> | ||
2 | +#include <stdlib.h> | ||
3 | +#include "libFile.h" | ||
4 | +#include <string.h> | ||
5 | + | ||
6 | +int taille(liste_t *l) | ||
7 | +{ | ||
8 | + return l->nombre; | ||
9 | +} | ||
10 | + | ||
11 | +int enfiler (liste_t *l, element_t e, int taille){ | ||
12 | +element_t nouveau=malloc(taille); | ||
13 | +memcpy(nouveau,e,taille); | ||
14 | +if (l->nombre >= l->alloue) | ||
15 | + { | ||
16 | + l->contenu = realloc(l->contenu, l->alloue+100); | ||
17 | + l->alloue+=100; | ||
18 | + } | ||
19 | +l->contenu[l->nombre++]=nouveau; | ||
20 | +return 0; | ||
21 | +} | ||
22 | + | ||
23 | +void affichage(element_t e) | ||
24 | +{ | ||
25 | + liste_t *l=e; | ||
26 | + printf("%d",l->contenu); | ||
27 | +} | ||
28 | + | ||
29 | +int afficher(liste_t *l, void(*affichage)(element_t)) { | ||
30 | +int i; | ||
31 | +for(i=0; i<taille(l); i++) affichage(l->contenu[i]); | ||
32 | +return 0; | ||
33 | +} | ||
34 | + | ||
35 | +int defiler(liste_t *l) | ||
36 | +{ | ||
37 | + int i; | ||
38 | + | ||
39 | + if(taille(l)>=1) | ||
40 | + { | ||
41 | + free(l->contenu[0]); | ||
42 | + for(i=0; i < taille(l); i++) | ||
43 | + { | ||
44 | + l->contenu[i]=l->contenu[i+1]; | ||
45 | + } | ||
46 | + l->nombre--; | ||
47 | + } | ||
48 | + return 0; | ||
49 | +} |
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +typedef void *element_t; | ||
2 | + | ||
3 | + typedef struct { | ||
4 | + element_t *contenu; | ||
5 | + int nombre; | ||
6 | + int alloue; | ||
7 | +} liste_t; | ||
8 | + | ||
9 | +int taille(liste_t *l); | ||
10 | +int enfiler (liste_t *l, element_t e, int taille); | ||
11 | +int afficher (liste_t *l, void(*affichage)(element_t)); | ||
12 | +int defiler(liste_t *l); | ||
13 | +void affichage(element_t e); |
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
@@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
1 | +REPERTOIRES = Graphique Liste Testliste | ||
2 | +COMPILE = $(REPERTOIRES:%=all-%) | ||
3 | +DEVERMINE = $(REPERTOIRES:%=debug-%) | ||
4 | +NETTOYAGE = $(REPERTOIRES:%=clean-%) | ||
5 | +export CFLAGS += -Wall | ||
6 | + | ||
7 | +all: $(COMPILE) | ||
8 | +$(COMPILE): | ||
9 | + $(MAKE) -C $(@:all-%=%) | ||
10 | + | ||
11 | +debug: $(DEVERMINE) | ||
12 | +$(DEVERMINE): CFLAGS += -g -DDEVERMINE | ||
13 | +$(DEVERMINE): | ||
14 | + $(MAKE) -C $(@:debug-%=%) | ||
15 | + | ||
16 | +clean: $(NETTOYAGE) | ||
17 | +$(NETTOYAGE): | ||
18 | + $(MAKE) -C $(@:clean-%=%) clean | ||
19 | + | ||
20 | +all-Main: all-Bibliotheque | ||
21 | +debug-Main: debug-Bibliotheque | ||
22 | + | ||
23 | +.PHONY: $(COMPILE) $(DEVERMINE) $(NETTOYAGE) | ||
24 | +.PHONY: all debug clean |
@@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
1 | +SOURCES = $(wildcard *.c) | ||
2 | +OBJETS = $(SOURCES:.c=.o) | ||
3 | +BIBLIOTHEQUES = -L ../Liste -lListe | ||
4 | +EXECUTABLE = projet | ||
5 | +CFLAGS += -Wall -I ../Liste | ||
6 | + | ||
7 | +all: $(EXECUTABLE) | ||
8 | +$(EXECUTABLE): $(OBJETS) | ||
9 | + $(CC) -o $@ $^ $(BIBLIOTHEQUES) | ||
10 | + | ||
11 | +clean: | ||
12 | + rm -rf $(EXECUTABLE) *.o |
No preview for this file type
@@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
1 | +#include <stdio.h> | ||
2 | +#include <stdlib.h> | ||
3 | +#include "libFile.h" | ||
4 | +#include <string.h> | ||
5 | + | ||
6 | + | ||
7 | +int main(){ | ||
8 | + | ||
9 | +liste_t desnombres={NULL,0,0}; | ||
10 | + | ||
11 | +int petit = 10; | ||
12 | +int moyen = 100; | ||
13 | +int grand = 1000; | ||
14 | + | ||
15 | +enfiler(&desnombres,&petit,sizeof(int)); | ||
16 | +enfiler(&desnombres,&moyen,sizeof(int)); | ||
17 | +enfiler(&desnombres,&grand,sizeof(int)); | ||
18 | +enfiler(&desnombres,&petit,sizeof(int)); | ||
19 | + | ||
20 | +afficher(&desnombres,affichage); | ||
21 | + | ||
22 | +defiler(&desnombres); | ||
23 | + | ||
24 | +afficher(&desnombres,affichage); | ||
25 | + | ||
26 | +return 0; | ||
27 | +} |
No preview for this file type