57 lines
1.1 KiB
C
57 lines
1.1 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <graph.h>
|
||
|
|
||
|
typedef struct rekt {
|
||
|
int x;
|
||
|
int y;
|
||
|
int w;
|
||
|
int h;
|
||
|
} rekt;
|
||
|
|
||
|
void drawRekt(rekt rectangle) {
|
||
|
DessinerRectangle(rectangle.x, rectangle.y, rectangle.w, rectangle.h);
|
||
|
}
|
||
|
|
||
|
rekt makeRekt() {
|
||
|
rekt toto;
|
||
|
char valid = 0;
|
||
|
while(valid != 2) {
|
||
|
if (SourisCliquee()) {
|
||
|
SourisPosition();
|
||
|
if (valid == 0) {
|
||
|
toto.x = _X;
|
||
|
toto.y = _Y;
|
||
|
valid = 1;
|
||
|
}
|
||
|
else if (valid == 1) {
|
||
|
toto.w = _X - toto.x;
|
||
|
toto.h = _Y - toto.y;
|
||
|
valid = 2;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (toto.w < 0) {
|
||
|
toto.w = -toto.w;
|
||
|
toto.x -= toto.w;
|
||
|
}
|
||
|
|
||
|
if (toto.h < 0) {
|
||
|
toto.h = -toto.h;
|
||
|
toto.y -= toto.h;
|
||
|
}
|
||
|
|
||
|
return toto;
|
||
|
}
|
||
|
|
||
|
int main(void) {
|
||
|
rekt rectangle_toto = {100, 100, 200, 50};
|
||
|
|
||
|
InitialiserGraphique();
|
||
|
CreerFenetre(100, 100, 1200, 700);
|
||
|
drawRekt(rectangle_toto);
|
||
|
drawRekt(makeRekt());
|
||
|
Touche();
|
||
|
FermerGraphique();
|
||
|
}
|