/*
A simple example of using the gfx library.
CSE 20211
9/7/2011
by Prof. Thain

Extended by R. Ansari, december 2024
*/

#include <stdio.h>
#include <string.h>
#include "gfx.h"

/*---- Declaration des fonctions de ce fichier  */
int atest();
int btest();

/*  Main program - programme principal de test 
   Appel : ./example_gfx -a    OR ./example_gfx -b  */ 
int main(int narg, char* arg[])
{
  int rc=0;
  char opt='a';
  if (narg>1 && strcmp(arg[1],"-b")==0)  opt='b';
  if (opt == 'b') rc=btest();
  else rc=atest();
  return rc;
}

/* premiere fonction de test */
int atest()
{
  int ysize = 350;
  int xsize = 350;
  printf("--- example_gfx , atest ----- \n");
  char c;
  
  // Open a new window for drawing.
  gfx_open(xsize,ysize,"Example Graphics Program (atest)");
  
  // Set the current drawing color to green.
  gfx_color(0,200,100);
  
  // Draw a triangle on the screen.
  gfx_line(100,100,200,100);
  gfx_line(200,100,150,150);
  gfx_line(150,150,100,100);
  
  // Draw  filled / non filled  rectangles with different colors 
  gfx_color_p(gfx_grey);
  gfx_fillrect(20,20,50,20);
  gfx_color_p(gfx_purple);
  gfx_fillrect(30,50,50,20);
  gfx_color_p(gfx_orange);
  gfx_rect(130,40,70,30);
  
  // Draw  filled / non filled  circles with different colors 
  gfx_color_p(gfx_blue);
  gfx_fillcircle(85,85,15);
  gfx_color_p(gfx_darkgrey);
  gfx_fillcircle(185,85,15);
  gfx_color_p(gfx_green);
  gfx_circle(225,150,20);
  
  // Draw  filled / non filled  circles with different colors 
  gfx_color_p(gfx_white);
  gfx_string(50,200,"example gfx test program");
  gfx_string(80,230,"Hello");
  
  while(1) {
    // Wait for the user to press a character.
    c = gfx_wait();
    
    // Quit if it is the letter q.
    if(c=='q') break;
  }

  return 0;
}

/* Seconde fonction de test */
int btest()
{
  int ysize = 300;
  int xsize = 250;
  printf("--- example_gfx , btest ----- \n");
  char c;
  
  // Open a new window for drawing.
  gfx_open_c(xsize,ysize,"Example Graphics Program (btest)", gfx_wheat);

  // Select drawing color 
  gfx_color_p(gfx_darkgrey);
  // Draw a rectangle , with upper-left corner at (25,25), width=height=200 
  gfx_rect(25,25,200,200);
  // Draw some lines 
  for(int i=1; i<8; i++) {
    gfx_line(25,25+i*25,225,25+i*25);
    gfx_line(25+i*25,25,25+i*25,225);
  }

  // Draw  filled  circles with different colors
  // Select drawing color black 
  gfx_color_p(gfx_black);
  gfx_fillcircle(125+13,75+13,10);
  gfx_fillcircle(150+13,100+13,10);
  // Select drawing color black 
  gfx_color_p(gfx_white);
  gfx_fillcircle(150+13,75+13,10);
  gfx_fillcircle(125+13,100+13,10);  
  

  
  // Draw some text  , with different colors 
  gfx_color_p(gfx_red);
  gfx_string(50,250,"example gfx test program (btest)");
  gfx_color_p(gfx_orange);
  gfx_string(50,275,"Damier / Othello");
  
  while(1) {
    // Wait for the user to press a character.
    c = gfx_wait();
    
    // Quit if it is the letter q.
    if(c=='q') break;
  }
  printf("--- type <CR> to close window...\n");
  getchar();
  gfx_close();
  return 0;
}
