tgrekov-fdf
HIVE fdf May 2024
Loading...
Searching...
No Matches
fdf_mlx.c File Reference

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fdf_mlx.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/13 07:32:01 by tgrekov #+# #+# */
/* Updated: 2024/06/24 08:50:27 by tgrekov ### ########.fr */
/* */
/* ************************************************************************** */

Definition in file fdf_mlx.c.

#include <stdlib.h>
#include <MLX42.h>
#include <ft_printf.h>
#include "../fdf.h"
#include "map.h"
Include dependency graph for fdf_mlx.c:

Go to the source code of this file.

Functions

void draw_line (mlx_image_t *img, int x1, int y1, int *p2)
 Multi-directional implementation of the Bresenham incremental error line drawing algorithm.
 
int project_map (t_map map, int *size)
 Project map and attempt to automatically scale to viewport.
 
static void keyhook (mlx_key_data_t key_data, void *arg)
 Runs when a key is pressed to check whether the escape key was used, so the window can be closed.
 
static void lines_from_point (mlx_image_t *img, t_map map, int x, int y)
 Checks if adjacent points are available, and draws lines to them.
 
static void fdf_row (void *data)
 Draw rows in between frames if the image isn't complete.
 
static int fdf_mlx (mlx_t *mlx, t_loop_data d, int *size)
 Bulk of mlx functions used in fdf, to set up the key press and drawing hooks, set up the image, start the rendering, etc.
 
int fdf (t_map map)
 Initialize mlx, run map projection and scaling, execute mlx, and cleanup.
 

Function Documentation

◆ draw_line()

void draw_line ( mlx_image_t img,
int  x1,
int  y1,
int *  p2 
)

Multi-directional implementation of the Bresenham incremental error line drawing algorithm.

Parameters
imgMlx image pointer
x1Starting x position
y1Starting y position
p2Ending [x, y] position

Definition at line 32 of file draw_line.c.

References abs(), and err().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fdf()

int fdf ( t_map  map)

Initialize mlx, run map projection and scaling, execute mlx, and cleanup.

Parameters
map
Return values
intExit status, 0 on success

Definition at line 131 of file fdf_mlx.c.

References fdf_mlx(), ft_printf(), s_loop_data::map, and project_map().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fdf_mlx()

static int fdf_mlx ( mlx_t mlx,
t_loop_data  d,
int *  size 
)
static

Bulk of mlx functions used in fdf, to set up the key press and drawing hooks, set up the image, start the rendering, etc.

Parameters
mlx
d
sizeWindow size to resize to
Return values
int

Definition at line 96 of file fdf_mlx.c.

References fdf_row(), ft_printf(), s_loop_data::img, keyhook(), and s_loop_data::y.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fdf_row()

static void fdf_row ( void *  data)
static

Draw rows in between frames if the image isn't complete.

Parameters
dataloop data

Definition at line 68 of file fdf_mlx.c.

References s_map::height, s_loop_data::img, lines_from_point(), s_loop_data::map, and s_loop_data::y.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ keyhook()

static void keyhook ( mlx_key_data_t  key_data,
void *  arg 
)
static

Runs when a key is pressed to check whether the escape key was used, so the window can be closed.

Parameters
key_data
argMlx instance pointer

Definition at line 36 of file fdf_mlx.c.

Here is the caller graph for this function:

◆ lines_from_point()

static void lines_from_point ( mlx_image_t img,
t_map  map,
int  x,
int  y 
)
static

Checks if adjacent points are available, and draws lines to them.

Parameters
imgMlx image pointer
map
x
y

Definition at line 51 of file fdf_mlx.c.

References draw_line(), s_map::height, s_map::point, s_point::projected, and s_map::width.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ project_map()

int project_map ( t_map  map,
int *  size 
)

Project map and attempt to automatically scale to viewport.

Parameters
map
size
Return values
int0 if scaling was successful, 1 if map was too large

Definition at line 121 of file project_map.c.

References calc_size(), s_map::height, project(), and s_map::width.

Here is the call graph for this function:
Here is the caller graph for this function: