VSGL2 - Very Simple Graphic Library 2  2.0
 All Classes Namespaces Files Functions Variables Macros Pages
Classes | Namespaces | Functions | Variables
vsgl2.cpp File Reference
#include <iostream>
#include <map>
#include "version.h"
#include "vsgl2.h"

Classes

struct  vsgl2_image
 

Namespaces

 vsgl2
 
 vsgl2::general
 
 vsgl2::video
 
 vsgl2::audio
 
 vsgl2::io
 
 vsgl2::ttf_fonts
 
 vsgl2::utils
 

Functions

void init ()
 Use this function to initiate the library, must be called first. More...
 
void close ()
 Close and free all the resources, must be called last. More...
 
void set_window (int w, int h, string title, int fullscreen=0)
 Use this function to create a window with the specified dimensions and a title, optionally in full screen. More...
 
void set_background_color (const Color &bg)
 Use this function to change the background color. More...
 
int get_window_width ()
 Use this function to get the width of the current window. More...
 
int get_window_height ()
 Use this function to get the height of the current window. More...
 
bool done ()
 Use this function to check when to stop the main loop. More...
 
void undone ()
 Use this function to reset the isDone glabal variable to its initial state (false) This can be useful when you want to use the done() function more then one time inside a program, i.e. in a video game to restart a new game. More...
 
void update ()
 Use this function to update the screen after drawing on it Typically called at the end of the main loop. More...
 
void draw_point (int x, int y, const Color &c)
 Use to draw a point at x,y coordinates. More...
 
void draw_rect (int x, int y, int w, int h, const Color &c)
 Use to draw a rectangle (only the border), use instead draw_filled_rect to draw a rectangle filled with color. More...
 
void draw_filled_rect (int x, int y, int w, int h, const Color &c)
 Use to draw a filled rectangle, use instead draw_rect to draw an empty rectangle with colored borders. More...
 
void draw_line (int x1, int y1, int x2, int y2, const Color &c)
 Use to draw a line. More...
 
void draw_image (string image, int x, int y, int w, int h, uint8_t alpha=255)
 Use to draw an image (BMP, PNG, JPG) More...
 
void play_music (string music)
 Use to play a music in a loop (WAVE, MOD, MIDI, OGG, MP3, FLAC, and any file that you use a command to play with). It can be typically used to play a background music. More...
 
void pause_music ()
 Use to pause the music that is currently playing. More...
 
void stop_music ()
 Use to stop the music that is currently playing. More...
 
void play_sound (string sound)
 Use to play a sound (WAVE, MOD, MIDI, OGG, MP3, FLAC, and any file that you use a command to play with). It can be typically used to play a sound effect linked to an user action (pressing a button...). More...
 
bool is_pressed (int key)
 Use to check if a button is pressed. More...
 
string read_text (string font, int dim, int x, int y, Color c, uint8_t max_length=0)
 Use to read text from the user, the return key stops the input. More...
 
int get_mouse_x ()
 Use to get the mouse x coordinate. More...
 
int get_mouse_y ()
 Use to get the mouse y coordinate. More...
 
int get_mouse_wheel_x ()
 Use to get the mouse wheel horizontal value,. More...
 
int get_mouse_wheel_y ()
 Use to get the mouse wheel vertical value,. More...
 
bool mouse_left_button_pressed ()
 Use to check if the mouse left button is pressed. More...
 
bool mouse_right_button_pressed ()
 Use to check if the mouse right button is pressed. More...
 
string load_font (string font, int dim)
 
void draw_text (string font, int dim, string text, int x, int y, Color c)
 Use this function to display a text on the screen with the desired font and dimension. More...
 
int text_width (string font, int dim, string text)
 Use this function to retrieve the width of a string, given the font, the dimension and the text. It can be useful because each character has a different size in general, so it could be very tricky to calculate the actual width of a string. More...
 
int text_height (string font, int dim, string text)
 Use this function to retrieve the height of a string, given the font, the dimension and the text. It can be useful because each character has a different size in general, so it could be very tricky to calculate the actual height of a string. More...
 
void wait_for_button_pressed ()
 Use this function to wait for any button to be pressed. More...
 
void delay (int milliseconds)
 Use this function to stop the execution for a given amount of milliseconds. More...
 
unsigned int ms_time ()
 Use this function to get the time from SDL initialization in milliseconds. More...
 
int take_screenshot (string filename)
 Use this function to take a screenshot of the window. More...
 

Variables

const int NUMBER_OF_CHANNELS = 16
 
SDL_Window * window
 
int width
 
int height
 
SDL_Renderer * renderer
 
bool isDone = false
 
map< string, vsgl2_imageimages
 
map< string, TTF_Font * > fonts
 
map< string, Mix_Chunk * > sounds
 
const Uint8 * currentKeyStates
 
int mouseX
 
int mouseY
 
int mouseWheelX
 
int mouseWheelY
 
Mix_Music * music
 
Color background_color