58 lines
940 B
C
58 lines
940 B
C
#include<stdio.h>
|
|
#include<stdlib.h>
|
|
#include<graph.h>
|
|
|
|
struct rectangle {
|
|
int x;
|
|
int y;
|
|
int xx;
|
|
int yy;
|
|
};
|
|
|
|
typedef struct rectangle rect;
|
|
|
|
void drawRect(rect Rekt) {
|
|
DessinerRectangle(Rekt.x, Rekt.y, Rekt.xx-Rekt.x, Rekt.yy-Rekt.y);
|
|
}
|
|
|
|
int main(int argc, char * argv[]) {
|
|
InitialiserGraphique();
|
|
CreerFenetre(100,100,1200,700);
|
|
|
|
rect Rekt = {100,100,200,200};
|
|
int state = 0;
|
|
|
|
couleur white = CouleurParNom("white");
|
|
|
|
drawRect(Rekt);
|
|
|
|
while (1) {
|
|
if (ToucheEnAttente()) {
|
|
int key = Touche();
|
|
if (key == XK_Escape) return EXIT_SUCCESS;
|
|
}
|
|
|
|
if (SourisCliquee()) {
|
|
if (state == 0) {
|
|
Rekt.x = _X;
|
|
Rekt.y = _Y;
|
|
state = 1;
|
|
} else {
|
|
if (_X < Rekt.x ) {
|
|
Rekt.xx = Rekt.x;
|
|
Rekt.x = _X;
|
|
} else Rekt.xx = _X;
|
|
if (_Y < Rekt.y ) {
|
|
Rekt.yy = Rekt.y;
|
|
Rekt.y = _Y;
|
|
} else Rekt.yy = _Y;
|
|
state = 0;
|
|
drawRect(Rekt);
|
|
}
|
|
}
|
|
}
|
|
FermerGraphique();
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|