GrAPiC
Graphics for Algo/Prog in C/C++
grapic Namespace Reference

Functions

void winInit (const char *name, int w, int h, int posx=-1, int posy=-1)
 Initialize the window with a size w,h and a position (posx,posy). If posx<0 or posy<0, the position is centered. More...
 
void winClear ()
 Clear the window with the default background color. More...
 
bool winHasFinished ()
 return true if the application should be closed (because of 'ESC' or 'q' key pressed for instance) More...
 
void winClearEvent ()
 Clear the event queue of the window. More...
 
void winSetPosition (int w, int h, int ps, int py, bool fullscreen)
 Change the size (w,h), the position(ps,py) or the fullscreen on/off Set a negative parameter to let him as it is. More...
 
bool winDisplay ()
 Display the window. All drawing is hidden until this function is not called. More...
 
void winQuit ()
 Quit and close all things. More...
 
void savePerformanceMode (bool reduceFPS)
 If set to true, limit the framerate (to monitor framerate) to save ressources on low end pcs. More...
 
float framesPerSecond ()
 Returns the average number of frames per second. More...
 
unsigned int lastFrameTime ()
 Returns the time elapsed between the last frame in milliseconds. It can be used to sync animations with the frame rate. More...
 
void color (unsigned char _r=255, unsigned char _g=255, unsigned char _b=255, unsigned char _a=255)
 Change the default color (unsigned char values between 0 and 255) More...
 
void colorf (float _r=1.f, float _g=1.f, float _b=1.f, float _a=1.f)
 Change the default color (float values between 0.f and 1.f) More...
 
void backgroundColor (unsigned char _r=255, unsigned char _g=255, unsigned char _b=255, unsigned char _a=255)
 Change the default background color (the color used to clear the screen) More...
 
void backgroundColorf (float _r=1.f, float _g=1.f, float _b=1.f, float _a=1.f)
 Change the default background color (the color used to clear the screen) More...
 
void circle (int xc, int yc, int radius)
 Draw a circle from (xmin,ymin) to (xmax,ymax) More...
 
void circleFill (int xc, int yc, int radius)
 Draw a filled circle from (xmin,ymin) to (xmax,ymax) More...
 
void ellipse (int xc, int yc, int horizontal, int vertical)
 Draw an ellipse at (xc, yc), horizontal radius and vertical radius, rotation optional (Thanks to Anass LAHNIN) More...
 
void ellipseFill (int xc, int yc, int horizontal, int vertical)
 Draw a filled ellipse at (xc, yc), horizontal radius and vertical radius, rotation optional (a bit long when drawing at angle != {90*k, k∈ℤ}) More...
 
void rectangle (int xmin, int ymin, int xmax, int ymax)
 Draw a rectangle from (xmin,ymin) to (xmax,ymax) More...
 
void rectangleFill (int xmin, int ymin, int xmax, int ymax)
 Draw a filled rectangle from (xmin,ymin) to (xmax,ymax) More...
 
void line (int x1, int y1, int x2, int y2)
 Draw a line from (x1,y1) to (x2,y2) More...
 
void put_pixel (int x, int y, unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
 Draw a pixel on (x,y) with color (r,g,b,a) More...
 
void point (int x, int y)
 Draw a point at (x,y) More...
 
void points (int p[][2], int n)
 Draw an array of n points. More...
 
void grid (int xmin, int ymin, int xmax, int ymax, int nx, int ny)
 Draw a grid from (xmin,ymin) to (xmax,ymax) with nx columns and ny rows. More...
 
int irand (int rmin=0, int rmax=100)
 return a random number (integer) between rmin to rmax included More...
 
float frand (float rmin=0.f, float rmax=1.f)
 return a random number (float) between rmin to rmax included More...
 
float elapsedTime ()
 return the time elapsed since the beginning of the process in second More...
 
int isKeyPressed (int key)
 return the number of time the key 'key' has been pressed since the last call to this function. More...
 
void setKeyRepeatMode (bool repeat)
 (de)Activate the repeat mode: when the user presses continuously on the key touch is repeated. It has to be set at the beguinning of the program. More...
 
void delay (int d)
 Stop the program during d milliseconds. More...
 
bool isMousePressed (int button)
 return true if the mouse button 'button' is pressed More...
 
void mousePos (int &x, int &y)
 After this function (x,y) store the mouse position. More...
 
void mousePosGlobal (int &x, int &y)
 After this function (x,y) store the mouse position. More...
 
bool winManageEvent ()
 Manage standard event like key 'ESC', quit, etc. More...
 
void fontSize (int s)
 Change the default size of the font. More...
 
void selectFont (const char *path)
 Changes the default font to the a the given path (must be a .ttf file) More...
 
void print (int x, int y, const char *txt)
 Print the text txt , up left corner is (x,y) More...
 
void print (int x, int y, int nb)
 Print the integer nb, up left corner is (x,y) More...
 
void print (int x, int y, float nb)
 Print the float nb, up left corner is (x,y) More...
 
void pressSpace (bool isPrint=true)
 Stop the program until key 'space'is pressed. More...
 
Image image (const char *filename, bool transparency=false, unsigned char r=255, unsigned char g=255, unsigned b=255, unsigned char a=255)
 Return an image loaded from the file filename. More...
 
Image image (int w, int h)
 Return an image of width=w and height=h. More...
 
Image image_copy (const Image &im)
 Return a copy of the image. It duplicates the image. It is useful since an affectation shares the same image. More...
 
void image_savePNG (const Image &im, const char *filename)
 Save the image into the file: format is PNG. More...
 
void image_draw (Image &im, int x, int y, int w=-1, int h=-1)
 Draw the image at position (x,y) with width=w and height=h (if w<0 or h<0 the original size of the image is used) More...
 
void image_draw (Image &im, int x, int y, int w, int h, float angle, float flip=SDL_FLIP_NONE)
 Draw the image at position (x,y) with width=w and height=h (if w<0 or h<0 the original size of the image is used); angle indicate the angle of rotation and flip: 0=no flip, 1=horizontal flip, 2=vertical flip. More...
 
unsigned char image_get (const Image &im, int x, int y, int c=0)
 return the color component c of the pixel (x,y) of the image im. c must be 0 for the red component, 1 for the green component, 2 for the blue component or 3 for the alpha/opacity component. More...
 
void image_set (Image &im, int x, int y, unsigned char r, unsigned char g, unsigned b, unsigned char a)
 Set the pixel (x,y) of the image im with the color c. More...
 
int image_width (const Image &im)
 return the width of the image More...
 
int image_height (const Image &im)
 return the height of the image More...
 
bool image_isInit (const Image &im)
 return true if the image is initialized More...
 
void image_printInfo (const Image &im)
 Print the informations of the image im. More...
 
void menu_add (Menu &m, const std::string &str)
 Add a line to the menu m with the text str. More...
 
void menu_change (Menu &m, int i, const std::string &str)
 Change the text of a line in the menu. More...
 
int menu_has_changed (Menu &m)
 Check if the menu item was changed. More...
 
void menu_draw (Menu &m, int xmin=5, int ymin=5, int xmax=-1, int ymax=-1)
 Draw the menu on the screen. See menu_add for an example of usage. More...
 
int menu_select (const Menu &m)
 return the line selected in the menu. See menu_add for an example of usage. More...
 
void menu_setSelect (Menu &m, int s)
 modifies selected line of the menu. See menu_add for an example of usage. More...
 
int caseToPixel (const Menu &m, int c, int ymin, int ymax)
 return the pixel from a line of the menu More...
 
void plot_clear (Plot &p)
 Clear the data stored. More...
 
void plot_setSize (Plot &p, const int n)
 Define the size of the stored value of the funtion (<0 means infinity) More...
 
void plot_add (Plot &p, float x, float y, int curve_n=0)
 Add a point (x,y=f(x)) to the curve number curve_n. More...
 
void plot_draw (const Plot &p, int xmin, int ymin, int xmax, int ymax, bool clearOrNot=true)
 Draw the curve in the rectangle (xmin,ymin,xmax,ymax); clear the rectangle if clearOrNot is true. More...
 
void triangle (int x1, int y1, int x2, int y2, int x3, int y3)
 Draw a triangle from the vertices (x1, y1), (x2, y2) and (x3, y3). (Code provided by Bastien DOIGNIES, many thanks) More...
 
void regular_polygone (int x, int y, unsigned int apotheme, unsigned int line_number)
 Draw a regular polygon with line_numbers edges centred on (x, y). (Code provided by Bastien DOIGNIES, many thanks) More...
 
void triangleFill (int x1, int y1, int x2, int y2, int x3, int y3)
 Draw a filled triangle from the vertices (x1, y1), (x2, y2), (x3, y3) More...
 
void regular_polygonFill (int x, int y, unsigned int apotheme, unsigned int line_number)
 Draw a filled regular polygon with line_numbers edges centred on (x, y). (Code provided by Bastien DOIGNIES, many thanks) More...
 
bool isInTriangle (float px, float py, float ax, float ay, float bx, float by, float cx, float cy)
 Decide if a point (px, py) is inside the triangle (ax, ay), (bx, by), (cx, xy). (Code provided by Bastien DOIGNIES, many thanks) More...
 
void polygonFill (int p[][2], unsigned int number)
 Draw a simple(no edge-crossing) and without holes filled polygon. More...
 
void polygon (int p[][2], unsigned int number)
 Draw a polygon. (Code provided by Bastien DOIGNIES, many thanks) More...
 
void qToQuit (bool enable)
 Permet à l'utilisateur d'activer/désactiver la fermeture de la fenêtre sur l'appui de la touche 'q'. More...