-
Notifications
You must be signed in to change notification settings - Fork 0
/
TP7Paint.c
651 lines (537 loc) · 28.1 KB
/
TP7Paint.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
#include "raylib.h"
#include "stdlib.h"
#define NB_OUTILS 7
#define NB_COULEUR 24
#define NB_CURSEUR 4
#define HISTORIQUE 9
int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 1200;
const int screenHeight = 700;
InitWindow(screenWidth, screenHeight, "raylib Paint by Vinciane Leclercq");
//variable de taille de la zone de dessin
int xDessin = 25, yDessin = 25, widthDessin = screenWidth - 50, heightDessin = screenHeight -50;
//creer les element graphique
// Rectangle zoneDeDessin = { xDessin, yDessin, widthDessin, heightDessin };
Rectangle barreOutils = { 5, 5, screenWidth - 10, 75 };
//creer la toile pour dessiner
RenderTexture2D dessin = LoadRenderTexture(widthDessin, heightDessin);
//initialise le fond de la zone de dessin à blanc
BeginTextureMode(dessin);
ClearBackground(WHITE);
EndTextureMode();
//------------------- les outils de la barre d'outils -----------------
//Outils a choisir
char* outils[NB_OUTILS] = {
"ENREGISTRER", "DEPLACER", "DESSINER_ROND", "DESSINER_CARREE", "EFFACER", "SEAU", "PIPETTE" };
//creation des rectangles outils
Rectangle outilsRec[NB_OUTILS];
for (int i = 0; i < NB_OUTILS; i++)
{
outilsRec[i].x = 10 + 70*i;
outilsRec[i].y = 10;
outilsRec[i].width = 65;
outilsRec[i].height = 65;
}
//Tableau des icons outils
Image outilsIcon[NB_OUTILS];
outilsIcon[0] = LoadImage("png/001-save.png");
outilsIcon[1] = LoadImage("png/001-cursor.png");
outilsIcon[2] = LoadImage("png/001-brush.png");
outilsIcon[3] = LoadImage("png/002-brush-1.png");
outilsIcon[4] = LoadImage("png/006-eraser.png");
outilsIcon[5] = LoadImage("png/003-bucket.png");
outilsIcon[6] = LoadImage("png/001-dropper.png");
//Tableau de Texture pour les icons
Texture2D outilsTexture[NB_OUTILS];
for (int i = 0; i < NB_OUTILS; i++)
{
outilsTexture[i] = LoadTextureFromImage(outilsIcon[i]);
UnloadImage(outilsIcon[i]);
}
//---------------- les curseurs -----------------------
//initialisation du tableu contenant le Image des curseurs
Image curseur[NB_CURSEUR];
curseur[0] = LoadImage("png/001-cursor.png");
curseur[1] = LoadImage("png/001-eraser.png");
curseur[2] = LoadImage("png/001-paint-bucket.png");
curseur[3] = LoadImage("png/001-pipette.png");
//convertissement des curseurs en texture
Texture2D curseurTexture[NB_CURSEUR];
for (int i = 0; i < NB_CURSEUR; i++)
{
curseurTexture[i] = LoadTextureFromImage(curseur[i]);
UnloadImage(curseur[i]);
}
//---------------- les couleurs de la barre d'outils ---------------
//couleurs à choisir
Color choixCouleur[NB_COULEUR] = {
YELLOW, GOLD, ORANGE, PINK, RED, MAROON, GREEN, LIME, DARKGREEN,
SKYBLUE, BLUE, DARKBLUE, PURPLE, VIOLET, DARKPURPLE, BEIGE, BROWN, DARKBROWN,
LIGHTGRAY, GRAY, DARKGRAY, BLACK, WHITE, RAYWHITE };
//Tableau de rectangle pour les couleurs
Rectangle couleurRec[NB_COULEUR];
for (int i = 0; i < NB_COULEUR; i++)
{
if (i > 11)
{
couleurRec[i].x = screenWidth - 8 - 5 - 24 - (i-12)*(24+8);
couleurRec[i].y = 5 + 16 + 24;
couleurRec[i].width = 24;
couleurRec[i].height = 24;
}
else
{
couleurRec[i].x = screenWidth - 8 - 5 - 24 - i*(24+8);
couleurRec[i].y = 5 + 8;
couleurRec[i].width = 24;
couleurRec[i].height = 24;
}
}
//---------------------- les couleurs selectionnées ---------------------
//Rectangles pour la couleur click-Droit click-gauche
Rectangle couleurDroit = { screenWidth - 421 - 8, 10, 65, 65 };
Rectangle couleurGauche = { screenWidth - 421 - 18 - 65, 10, 65, 65 };
// variable
int couleurSousSouris = -1; // pas de couleur
int couleurSelectionneeDroit = 22; // noir
int couleurSelectionneeGauche = 21; // blanc
// couleur des boutons de la souris
Color cDroit = choixCouleur[couleurSelectionneeDroit];
Color cGauche = choixCouleur[couleurSelectionneeGauche];
//-------------------- le peinceau ------------------------
int taillePeinceau = 20;
//souris
Vector2 positionSouris = { 500.0f, 400.0f };
//souris en mémoire
Vector2 positionAvant = positionSouris;
//---------------------la gestion des differents outils---------------------
// initialisation du tableau permettant de savoir sous quel mode l'utilisateur est
bool modeOutils[NB_OUTILS];
for (int i = 0; i < NB_OUTILS; i++)
{
if (i == 1) modeOutils[i] = true; // mode initial sur pinceau
else modeOutils[i] = false;
}
int outilsSousSouris = -1; // -1 pas d'outils
int outilsSelectionnee = 2; // initialisation avec le pinceau selectionné
int outilAvant = outilsSelectionnee;
//--------------------le mode camera-----------------------
//initialisation de la camera
Camera2D deplacement = { 0 };
deplacement.target = (Vector2){ //positionnement au milieu de la zone de dessin
(xDessin + widthDessin/2) * 1.0f,
(yDessin + heightDessin/2) * 1.0f };
deplacement.offset = (Vector2){ screenWidth/2, screenHeight/2 };
deplacement.rotation = 0.0f;
deplacement.zoom = 1.0f;
// calcule la position et la taille de la zone de travail en prenant en compte le zoom
float dessinZoomWidth = widthDessin * deplacement.zoom;
float dessinZoomHeight = heightDessin * deplacement.zoom;
float dessinZoomX = (screenWidth - dessinZoomWidth) / 2;
float dessinZoomY = (screenHeight - dessinZoomHeight) / 2;
//target en mémoire
Vector2 targetAvant = deplacement.target;
// calcule la position de la souris
Vector2 posSourisDessin = {
(positionSouris.x - (1 - deplacement.zoom) * widthDessin / 2) / deplacement.zoom,
(positionSouris.y - (1 - deplacement.zoom) * heightDessin / 2) / deplacement.zoom };
Vector2 posAvantSourisDessin = posSourisDessin;
//---------------------------l'historique--------------------------------
//variable qui récupère le geste de la souris
int mouvementPresent = GESTURE_NONE;
int mouvementPrecedent = mouvementPresent;
//variable permettant de savoir si un deplacement dans l'historique est en cours
bool ctrlZ_Active = false;
bool ctrlY_Active = false;
bool entreDansLhistorique = false;
//premiere image (blanche) de l'historique
Image blankHistorique = GetTextureData(dessin.texture);
//tableau d'image pour l'historique
Image* historique = malloc(10*sizeof(Image));
historique[0] = blankHistorique;
//emplacement de l'image afficher dans l'historique
int indiceHistorique = 0;
Texture2D textureHistorique;
//---------------------------l'outil pipette & seau------------------------
// image sous forme d'un pixel unique
Image pixel;
//rvariable pour récupérer l'image avec la couleur remplacer pour le pot de peinture
Image* couleurRemplacee;
Texture2D textureCouleurRemplacee;
//couleur récupérer par la pipette
Color* couleurPipette;
//couleur récupérer par le pot de peinture
Color* couleurSeau;
//---------------------------la sauvegarde---------------------------
// indiquateur pour permettre d'afficher le message de sauvegarde ou non
bool messageDeSauvegarde = false;
int compteur = 0;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
positionSouris = GetMousePosition();
mouvementPrecedent = mouvementPresent;
mouvementPresent = GetGestureDetected();
//action entre la souris et les outils
for (int i = 0; i < NB_OUTILS; i++)
{
if (CheckCollisionPointRec(positionSouris, outilsRec[i]))
{
outilsSousSouris = i;
//choix de l'outils avec la souris
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) && GetGestureDetected() == GESTURE_TAP)
{
outilAvant = outilsSelectionnee;
outilsSelectionnee = i;
}
break; // sort de la boucle, gain de temps
}
else outilsSousSouris = -1; // aucun outils
}
//action entre la souris et les couleurs
for (int i = 0; i < NB_COULEUR; i ++)
{
if (CheckCollisionPointRec(positionSouris, couleurRec[i]))
{
couleurSousSouris = i;
//choix des couleurs en fonctions du bouton de la souris
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) && GetGestureDetected() == GESTURE_TAP)
{
couleurSelectionneeGauche = i;
cGauche = choixCouleur[couleurSelectionneeGauche];
}
else if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON) && GetGestureDetected() == GESTURE_TAP)
{
couleurSelectionneeDroit = i;
cDroit = choixCouleur[couleurSelectionneeDroit];
}
break;
}
else couleurSousSouris = -1; // aucune couleur
}
// récupération des couleurs choisies
// action pour un click gauche appuyé
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) && (GetGestureDetected() == GESTURE_DRAG))
{
if (outilsSelectionnee == 1) // pour l'outils deplacement
{
deplacement.target.x = targetAvant.x + (positionAvant.x - positionSouris.x);
deplacement.target.y = targetAvant.y + (positionAvant.y - positionSouris.y);
}
posSourisDessin.x = (positionSouris.x - (screenWidth - deplacement.zoom * widthDessin) / 2 ) / deplacement.zoom - (screenWidth/2 - deplacement.target.x);
posSourisDessin.y = (positionSouris.y - (screenHeight - heightDessin * deplacement.zoom) / 2 ) / deplacement.zoom - (screenHeight/2 - deplacement.target.y);
//recupération des coordonée en fonction du zoom de la zone de dessin
dessinZoomWidth = widthDessin * deplacement.zoom;
dessinZoomHeight = heightDessin * deplacement.zoom;
dessinZoomX = (screenWidth - dessinZoomWidth) / 2 + (screenWidth/2 - deplacement.target.x)*deplacement.zoom;
dessinZoomY = (screenHeight - dessinZoomHeight) / 2 + (screenHeight/2 - deplacement.target.y)*deplacement.zoom;
if(CheckCollisionPointRec(positionSouris, (Rectangle){ dessinZoomX, dessinZoomY, dessinZoomWidth, dessinZoomHeight }))
{
switch (outilsSelectionnee)
{
case 2 : // outil pinceau rond
BeginTextureMode(dessin);
DrawCircle(posAvantSourisDessin.x, posAvantSourisDessin.y, taillePeinceau, cGauche);
DrawLineEx(posAvantSourisDessin, posSourisDessin,2 * taillePeinceau, cGauche);
DrawCircle(posSourisDessin.x, posSourisDessin.y, taillePeinceau, cGauche);
EndTextureMode();
break;
case 3 : // outils peinceau carré
BeginTextureMode(dessin);
DrawRectangle(posSourisDessin.x - taillePeinceau/2, posSourisDessin.y - taillePeinceau/2, taillePeinceau, taillePeinceau, cGauche);
DrawLineEx(posAvantSourisDessin, posSourisDessin, taillePeinceau, cGauche);
EndTextureMode();
break;
case 4 : // outil gomme
BeginTextureMode(dessin);
DrawCircle(posAvantSourisDessin.x, posAvantSourisDessin.y, taillePeinceau, WHITE);
DrawLineEx((Vector2){ posAvantSourisDessin.x, posAvantSourisDessin.y}, (Vector2){ posSourisDessin.x, posSourisDessin.y },2 * taillePeinceau, WHITE);
DrawCircle(posSourisDessin.x, posSourisDessin.y, taillePeinceau, WHITE);
EndTextureMode();
break;
}
}
}
// action du click droit
if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON) && (GetGestureDetected() == GESTURE_DRAG))
{
posSourisDessin.x = (positionSouris.x - (screenWidth - deplacement.zoom * widthDessin) / 2 ) / deplacement.zoom - (screenWidth/2 - deplacement.target.x);
posSourisDessin.y = (positionSouris.y - (screenHeight - heightDessin * deplacement.zoom) / 2 ) / deplacement.zoom - (screenHeight/2 - deplacement.target.y);
if(CheckCollisionPointRec(positionSouris, (Rectangle){ dessinZoomX, dessinZoomY, dessinZoomWidth, dessinZoomHeight }))
{
switch (outilsSelectionnee)
{
case 2 : // outils pinceau rond
BeginTextureMode(dessin);
DrawCircle(posAvantSourisDessin.x, posAvantSourisDessin.y, taillePeinceau, cDroit);
DrawLineEx(posAvantSourisDessin, posSourisDessin,2 * taillePeinceau, cDroit);
DrawCircle(posSourisDessin.x, posSourisDessin.y, taillePeinceau, cDroit);
EndTextureMode();
break;
case 3 : // our peinceau carré
BeginTextureMode(dessin);
DrawRectangle(posSourisDessin.x - taillePeinceau/2, posSourisDessin.y - taillePeinceau/2, taillePeinceau, taillePeinceau, cDroit);
DrawLineEx(posAvantSourisDessin, posSourisDessin, taillePeinceau, cDroit);
EndTextureMode();
break;
}
}
}
//action de la pipette
if (outilsSelectionnee == 6 && CheckCollisionPointRec(positionSouris, (Rectangle){ dessinZoomX, dessinZoomY, dessinZoomWidth, dessinZoomHeight })) //pipette
{
//recupération du pixel sur lequel la souris est placée
pixel = ImageFromImage(historique[indiceHistorique], (Rectangle){ posSourisDessin.x ,posSourisDessin.y, 1, 1 });
couleurPipette = GetImageData(pixel); //recupération de la couleur du pixel
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))cGauche = *couleurPipette;
else if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON))cDroit = *couleurPipette;
UnloadImage(pixel);
}
// action du pot de peinture
/*if (outilsSelectionnee == 5 && CheckCollisionPointRec(positionSouris, (Rectangle){ dessinZoomX, dessinZoomY, dessinZoomWidth, dessinZoomHeight }) && !CheckCollisionPointRec(positionSouris, barreOutils))//outil seau de remplissage
{
pixel = ImageFromImage(historique[indiceHistorique], (Rectangle){ posSourisDessin.x ,posSourisDessin.y, 1, 1 });
couleurSeau = GetImageData(pixel); //recupération de la couleur a replacer
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
{
entreDansLhistorique = true;
//recupération de l'image presente pour ne pas l'écraser dans l'historique
*couleurRemplacee = historique[indiceHistorique];
//remplace la couleur selectionner par la souris par la couleur dans le click gauche
ImageColorReplace(couleurRemplacee, *couleurSeau, cGauche);
textureCouleurRemplacee = LoadTextureFromImage(*couleurRemplacee);
BeginTextureMode(dessin);
DrawTexture(textureCouleurRemplacee, 0, 0, WHITE); //dessine la nouvelle texture sur le dessin
EndTextureMode();
UnloadTexture(textureCouleurRemplacee);
}
else if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON))
{
entreDansLhistorique = true;
//recupération de l'image presente pour ne pas l'écraser dans l'historique
*couleurRemplacee = historique[indiceHistorique];
//remplace la couleur selectionner par la souris par la couleur dans le click droit
ImageColorReplace(couleurRemplacee, *couleurSeau, cDroit);
textureCouleurRemplacee = LoadTextureFromImage(*couleurRemplacee);
BeginTextureMode(dessin);
DrawTexture(textureCouleurRemplacee, 0, 0, WHITE); //dessine la nouvelle texture sur le dessin
EndTextureMode();
UnloadTexture(textureCouleurRemplacee);
}
UnloadImage(pixel);
}*/
//actions de la mollette de la souris
if (outilsSelectionnee == 1)
{
// zoom
deplacement.zoom += ((float)GetMouseWheelMove()*-0.05f);
if (deplacement.zoom > 3.0f) deplacement.zoom = 3.0f;
else if (deplacement.zoom < 0.1f) deplacement.zoom = 0.1f;
}
else
{
//taille du peinceau
taillePeinceau += GetMouseWheelMove()*-5;
if (taillePeinceau < 2) taillePeinceau = 2;
if (taillePeinceau > 50) taillePeinceau = 50;
}
//gestion de l'historique
if ((mouvementPrecedent == GESTURE_DRAG && mouvementPresent != GESTURE_DRAG) || entreDansLhistorique == true)
{
if (indiceHistorique < HISTORIQUE - 1 ) // ajout de la texture du dessin à la suite du tableau
{
indiceHistorique++;
historique[indiceHistorique] = GetTextureData(dessin.texture);
ImageFlipVertical(&historique[indiceHistorique]);
for (int i = indiceHistorique + 1; i < HISTORIQUE; i++) UnloadImage(historique[i]);
}
else
{ // decalage de chaque image du tableau et ajout de l'image presente à la fin du tableau
//UnloadImage(historique[1]);
for (int i = 2; i < HISTORIQUE; i++)
{
historique[i - 1] = historique[i];
}
historique[HISTORIQUE - 1] = GetTextureData(dessin.texture);
ImageFlipVertical(&historique[HISTORIQUE-1]);
}
entreDansLhistorique = false;
}
// gestion du crtl-z W = Z sur le QWERTY
if (IsKeyDown(KEY_W) && IsKeyDown(KEY_LEFT_CONTROL))
{
if (indiceHistorique != 0 && ctrlZ_Active == false)
{
indiceHistorique--;
textureHistorique = LoadTextureFromImage(historique[indiceHistorique]);
BeginTextureMode(dessin);
DrawTexture(textureHistorique, 0, 0, WHITE);
EndTextureMode();
UnloadTexture(textureHistorique);
}
ctrlZ_Active = true;
}
else ctrlZ_Active = false;
//gestion du ctrl-Y
if (IsKeyDown(KEY_Y) && IsKeyDown(KEY_LEFT_CONTROL))
{
if(indiceHistorique != HISTORIQUE - 1 && ctrlY_Active == false)
{
indiceHistorique++;
textureHistorique = LoadTextureFromImage(historique[indiceHistorique]);
BeginTextureMode(dessin);
DrawTexture(textureHistorique, 0, 0, WHITE);
EndTextureMode();
UnloadTexture(textureHistorique);
}
ctrlY_Active = true;
}
else ctrlY_Active = false;
// outils de sauvegarde
if (outilsSelectionnee == 0)
{
if (compteur == 0)
{
Image sauvegarde = GetTextureData(dessin.texture);
ImageFlipVertical(&sauvegarde);
ExportImage(sauvegarde, "my_painting.png");
UnloadImage(sauvegarde);
messageDeSauvegarde = true;
}
else if (compteur > 150)
{
outilsSelectionnee = outilAvant;
}
}
if(messageDeSauvegarde)
{
// montre le un message de sauvegarde pendant 2 secondes
compteur++;
if (compteur > 240)
{
messageDeSauvegarde = false;
compteur = 0;
}
}
//recupération des coordonée en fonction du zoom de la zone de dessin
dessinZoomWidth = widthDessin * deplacement.zoom;
dessinZoomHeight = heightDessin * deplacement.zoom;
dessinZoomX = (screenWidth - dessinZoomWidth) / 2 + (screenWidth/2 - deplacement.target.x)*deplacement.zoom;
dessinZoomY = (screenHeight - dessinZoomHeight) / 2 + (screenHeight/2 - deplacement.target.y)*deplacement.zoom;
//récuperation des coordonnées de la souris en fonction du zoom et du déplacement
posSourisDessin.x = ((positionSouris.x - (screenWidth - deplacement.zoom * widthDessin) / 2 ) / deplacement.zoom) - (screenWidth/2 - deplacement.target.x);
posSourisDessin.y = ((positionSouris.y - (screenHeight - heightDessin * deplacement.zoom) / 2 ) / deplacement.zoom) - (screenHeight/2 - deplacement.target.y);
// valeur tampon
posAvantSourisDessin = posSourisDessin;
positionAvant = positionSouris;
targetAvant = deplacement.target;
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(GRAY);
BeginMode2D(deplacement);
//dessine le dessin
DrawTextureRec(dessin.texture, (Rectangle){ 0, 0, dessin.texture.width, -dessin.texture.height }, (Vector2){ 25, 25 }, WHITE);
EndMode2D();
if (outilsSelectionnee == 1)
{ // curseur de l'outils deplacement
DrawTexture(curseurTexture[0], positionSouris.x, positionSouris.y, WHITE);
}
//dessine la forme du peinceau sous la souris
if(CheckCollisionPointRec(positionSouris, (Rectangle){ dessinZoomX, dessinZoomY, dessinZoomWidth, dessinZoomHeight }))
{
switch (outilsSelectionnee)
{
case 2 : // outils peinceau rond
if(IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) DrawCircleLines(positionSouris.x, positionSouris.y, taillePeinceau, cDroit);
else DrawCircleLines(GetMouseX(), GetMouseY(), taillePeinceau * deplacement.zoom, cGauche);
break;
case 3 : // outils peinceau carré
if(IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) DrawRectangleLines(positionSouris.x - (taillePeinceau / 2 * deplacement.zoom), positionSouris.y - (taillePeinceau / 2 * deplacement.zoom), taillePeinceau * deplacement.zoom, taillePeinceau * deplacement.zoom, cDroit);
else DrawRectangleLines(positionSouris.x - (taillePeinceau / 2 * deplacement.zoom), positionSouris.y - (taillePeinceau / 2 * deplacement.zoom), taillePeinceau * deplacement.zoom , taillePeinceau * deplacement.zoom, cGauche);
break;
case 4 : // outil gomme
DrawCircleLines(GetMouseX(), GetMouseY(), taillePeinceau * deplacement.zoom, BLACK);
DrawTexture(curseurTexture[1], positionSouris.x + taillePeinceau/2 + 2, positionSouris.y + taillePeinceau/2 + 2, WHITE);
break;
case 5 : // ourils seau de remplissage
DrawTexture(curseurTexture[2], positionSouris.x - 24, positionSouris.y - 24, WHITE);
break;
case 6 : // outils pipette
DrawTexture(curseurTexture[3], positionSouris.x, positionSouris.y - 24, WHITE);
break;
}
}
if (messageDeSauvegarde == true) // affichage du message de sauvegarde
{
DrawRectangle(screenWidth / 2 - 310, screenHeight / 2 - 20, 620, 80, Fade(BLACK, 0.7f));
DrawText("dessin Sauvegardé!", screenWidth / 2 - 290, screenHeight / 2 - 10, 60, WHITE);
}
// affichage du message ctrl-z
if (IsKeyDown(KEY_W) && IsKeyDown(KEY_LEFT_CONTROL) )
{
DrawRectangle(0, screenHeight - 80, 250, 80, Fade(BLACK, 0.7f));
DrawText("CTRL+Z", 20, screenHeight -60, 40, WHITE);
}
// affichage du message ctrl-y
if (IsKeyDown(KEY_Y) && IsKeyDown(KEY_LEFT_CONTROL) )
{
DrawRectangle(0, screenHeight - 80, 250, 80, Fade(BLACK, 0.7f));
DrawText("CTRL+Y", 20, screenHeight -60, 40, WHITE);
}
// dessine la barre d'outils
DrawRectangleRec(barreOutils, RAYWHITE);
DrawRectangleLines(5, 5, screenWidth - 10, 75, GRAY);
//dessine les outils
for (int i = 0; i < NB_OUTILS; i++)
{
DrawRectangleRec(outilsRec[i], RAYWHITE);
DrawTexture(outilsTexture[i], outilsRec[i].x + 15, outilsRec[i].y + 15, WHITE);
DrawRectangleLines(outilsRec[i].x, outilsRec[i].y, outilsRec[i].width, outilsRec[i].height, GRAY);
}
if (outilsSousSouris >= 0) DrawRectangleRec(outilsRec[outilsSousSouris], Fade(GRAY, 0.3f));
DrawRectangleLines(outilsRec[outilsSelectionnee].x - 1, outilsRec[outilsSelectionnee].y - 1, outilsRec[outilsSelectionnee].width + 2, outilsRec[outilsSelectionnee].height + 2, BLACK);
//dessine les couleurs
for (int i = 0; i < NB_COULEUR; i++)
{
DrawRectangleRec(couleurRec[i], choixCouleur[i]);
DrawRectangleLines(couleurRec[i].x, couleurRec[i].y, couleurRec[i].width, couleurRec[i].height, GRAY);
}
if (couleurSousSouris >= 0) DrawRectangleRec(couleurRec[couleurSousSouris], Fade(WHITE, 0.6f));
//dessine les couleurs selectionnées
DrawRectangleRec(couleurDroit, cDroit);
DrawRectangleLines(couleurDroit.x, couleurDroit.y, couleurDroit.width, couleurDroit.height, GRAY);
DrawRectangleRec(couleurGauche, cGauche);
DrawRectangleLines(couleurGauche.x, couleurGauche.y, couleurGauche.width, couleurGauche.height, GRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
for (int i = 0; i < NB_OUTILS; i++)
{
UnloadTexture(outilsTexture[i]);
}
for (int i = 0; i < NB_CURSEUR; i++)
{
UnloadTexture(curseurTexture[i]);
}
//unload la render texture
UnloadImage(blankHistorique);
UnloadImage(historique[indiceHistorique]);
UnloadImage(pixel);
UnloadImage(couleurRemplacee[0]);
UnloadTexture(textureCouleurRemplacee);
UnloadRenderTexture(dessin);
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}