include/graphics.h
Classes
Name | |
---|---|
struct | graphics contains all the graphics elements |
struct | coordinates coordinates of a point in space |
struct | commands_panel contains an SDL button a an array of SDL rectangles to handle the command panel |
Types
Name | |
---|---|
typedef struct graphics | graphics_t contains all the graphics elements |
typedef struct coordinates | coordinates_t coordinates of a point in space |
typedef struct commands_panel | commands_panel_t contains an SDL button a an array of SDL rectangles to handle the command panel |
Functions
Name | |
---|---|
void | end_sdl(char ok, char const * msg, SDL_Window * window, SDL_Renderer * renderer)ends the SDL elements and handles errors |
graphics_t * | init_sdl()initialises the sdl components and returns them in a struct |
commands_panel_t * | init_commands_panel(int w, int h)initialises the commands_panel structure |
SDL_Texture * | load_texture_from_image(char * file_image_name, SDL_Window * window, SDL_Renderer * renderer)loads a texture from an image |
SDL_Texture * | create_texture_for_text(char * text, TTF_Font * font, SDL_Renderer * renderer)creates a texture for a text |
SDL_Rect * | crea_rect(int x, int y, int width, int height)create a pointer to a rectangle |
SDL_Rect * | crea_rect_in_rect(SDL_Rect * button, float i, float j)create a pointer to a rectangle inside another rectangle |
void | texturing(SDL_Texture * my_texture, SDL_Window * window, SDL_Renderer * renderer)displays the textures on the renderer |
void | display_cell(SDL_Texture * texture, SDL_Window * window, SDL_Renderer * renderer, int id)displays a cell on the board given an id |
int | get_cell_id_from_mouse_position(graphics_t * g, int x, int y)returns the id of the cell clicked on with the mouse |
void | display_board(graphics_t * g, cell_t ** cell_tab)displays current state of the board |
int | is_in(SDL_Rect * button, int x, int y)checks if a position (x, y) is in a rectangle button |
void | home_menu(graphics_t * g, SDL_Rect * text_box, SDL_Rect * button_1, SDL_Rect * button_2, SDL_Texture * text, int r1, int r2)shows the home menu |
void | display_game(graphics_t * g, SDL_Rect * text_box, SDL_Rect * confirm, SDL_Texture * text, int r, cell_t ** cell_tab, int direction_state)displays the user interface during the game |
Types Documentation
typedef graphics_t
typedef struct graphics graphics_t;
contains all the graphics elements
typedef coordinates_t
typedef struct coordinates coordinates_t;
coordinates of a point in space
typedef commands_panel_t
typedef struct commands_panel commands_panel_t;
contains an SDL button a an array of SDL rectangles to handle the command panel
Functions Documentation
function end_sdl
void end_sdl(
char ok,
char const * msg,
SDL_Window * window,
SDL_Renderer * renderer
)
ends the SDL elements and handles errors
function init_sdl
graphics_t * init_sdl()
initialises the sdl components and returns them in a struct
function init_commands_panel
commands_panel_t * init_commands_panel(
int w,
int h
)
initialises the commands_panel structure
function load_texture_from_image
SDL_Texture * load_texture_from_image(
char * file_image_name,
SDL_Window * window,
SDL_Renderer * renderer
)
loads a texture from an image
function create_texture_for_text
SDL_Texture * create_texture_for_text(
char * text,
TTF_Font * font,
SDL_Renderer * renderer
)
creates a texture for a text
function crea_rect
SDL_Rect * crea_rect(
int x,
int y,
int width,
int height
)
create a pointer to a rectangle
function crea_rect_in_rect
SDL_Rect * crea_rect_in_rect(
SDL_Rect * button,
float i,
float j
)
create a pointer to a rectangle inside another rectangle
function texturing
void texturing(
SDL_Texture * my_texture,
SDL_Window * window,
SDL_Renderer * renderer
)
displays the textures on the renderer
function display_cell
void display_cell(
SDL_Texture * texture,
SDL_Window * window,
SDL_Renderer * renderer,
int id
)
displays a cell on the board given an id
function get_cell_id_from_mouse_position
int get_cell_id_from_mouse_position(
graphics_t * g,
int x,
int y
)
returns the id of the cell clicked on with the mouse
function display_board
void display_board(
graphics_t * g,
cell_t ** cell_tab
)
displays current state of the board
function is_in
int is_in(
SDL_Rect * button,
int x,
int y
)
checks if a position (x, y) is in a rectangle button
function home_menu
void home_menu(
graphics_t * g,
SDL_Rect * text_box,
SDL_Rect * button_1,
SDL_Rect * button_2,
SDL_Texture * text,
int r1,
int r2
)
shows the home menu
function display_game
void display_game(
graphics_t * g,
SDL_Rect * text_box,
SDL_Rect * confirm,
SDL_Texture * text,
int r,
cell_t ** cell_tab,
int direction_state
)
displays the user interface during the game
Source code
/* name : graphics.h
* authors : eloi petit, matheo thomas, domitille vale
* date : 18-06-24
*/
#include <SDL2/SDL.h>
#include <SDL2/SDL_render.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_video.h>
#include "init.h"
#ifndef graphics_h
#define graphics_h
/* Struct definitions */
typedef struct graphics {
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *board;
SDL_Texture *white;
SDL_Texture *black;
SDL_Texture *red;
SDL_Texture *config_1;
SDL_Texture *config_2;
SDL_Texture *commands;
TTF_Font * font;
struct commands_panel* commands_panel;
} graphics_t;
typedef struct coordinates {
int x;
int y;
} coordinates_t;
typedef struct commands_panel {
SDL_Rect *button;
SDL_Rect *tab_dir[6];
} commands_panel_t;
/* Functions definitions */
void end_sdl(char ok, char const *msg, SDL_Window *window, SDL_Renderer *renderer);
graphics_t *init_sdl();
commands_panel_t *init_commands_panel(int w, int h);
SDL_Texture* load_texture_from_image(char * file_image_name, SDL_Window *window, SDL_Renderer *renderer );
SDL_Texture* create_texture_for_text(char * text, TTF_Font * font, SDL_Renderer *renderer );
SDL_Rect* crea_rect(int x, int y, int width, int height);
SDL_Rect* crea_rect_in_rect(SDL_Rect *button, float i, float j);
void texturing(SDL_Texture* my_texture, SDL_Window* window, SDL_Renderer* renderer);
void display_cell(SDL_Texture *texture, SDL_Window *window, SDL_Renderer *renderer, int id);
int get_cell_id_from_mouse_position(graphics_t *g, int x, int y);
void display_board(graphics_t *g, cell_t **cell_tab);
int is_in (SDL_Rect* button,int x,int y);
void home_menu(graphics_t *g, SDL_Rect* text_box,SDL_Rect* button_1,SDL_Rect* button_2,SDL_Texture * text,int r1,int r2);
void display_game(graphics_t *g,SDL_Rect* text_box,SDL_Rect* confirm,SDL_Texture * text, int r, cell_t **cell_tab, int direction_state);
#endif