cub3d/src/keyhooks.c
2023-10-25 13:56:45 +02:00

147 lines
4.0 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* keyhooks.c |o_o || | */
/* +:+ +:+ +:+ */
/* By: houtworm <codam@houtworm.net> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/13 08:32:24 by houtworm #+# #+# */
/* Updated: 2022/12/29 03:51:56 by djonker \___)=(___/ */
/* */
/* ************************************************************************** */
#include "../fractol.h"
void keyhookmove(void *param)
{
t_varlist *vl;
vl = param;
if (mlx_is_key_down(vl->mlx, MLX_KEY_LEFT) && vl->xmin > -32)
{
justmove(vl, 'l');
vl->redraw = 1;
}
if (mlx_is_key_down(vl->mlx, MLX_KEY_RIGHT) && vl->xmax < 32)
{
justmove(vl, 'r');
vl->redraw = 1;
}
if (mlx_is_key_down(vl->mlx, MLX_KEY_UP) && vl->ymin > -32)
{
justmove(vl, 'u');
vl->redraw = 1;
}
if (mlx_is_key_down(vl->mlx, MLX_KEY_DOWN) && vl->ymax < 32)
{
justmove(vl, 'd');
vl->redraw = 1;
}
}
void keyhook(mlx_key_data_t kd, void *param)
{
t_varlist *vl;
vl = param;
if (kd.key == MLX_KEY_S && kd.action == MLX_PRESS)
vl->cshi++;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_R))
resetfractal(vl);
else if (kd.key == MLX_KEY_P && kd.action == MLX_PRESS)
vl->psycho++;
else if (kd.key == MLX_KEY_I && kd.action == MLX_PRESS)
vl->info++;
else if (kd.key == MLX_KEY_H && kd.action == MLX_PRESS)
vl->help++;
else if (kd.key == MLX_KEY_X && kd.action == MLX_PRESS)
vl->cschemeid++;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_N))
vl->power = vl->power + 1;
else if (kd.key == MLX_KEY_C && kd.action == MLX_PRESS && vl->cscale != 128)
vl->cscale = (vl->cscale) * 2;
else if (kd.key == MLX_KEY_D && kd.action == MLX_PRESS && vl->cscale != 2)
vl->cscale = (vl->cscale) / 2;
else
return ;
setcolorscheme(vl);
redrawimage(vl);
}
void resizehook(int x, int y, void *param)
{
t_varlist *vl;
vl = param;
vl->h = y;
vl->w = x;
vl->mlx->height = y;
vl->mlx->width = x;
if (vl->w > vl->h)
{
vl->xmax = vl->xmin + (vl->ymax - vl->ymin) * vl->w / vl->h;
}
else
{
vl->ymax = vl->ymin + (vl->xmax - vl->xmin) * vl->h / vl->w;
}
redrawimage(vl);
}
void keyhookfractal(void *param)
{
t_varlist *vl;
vl = param;
if (mlx_is_key_down(vl->mlx, MLX_KEY_1))
vl->fractalid = 1;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_2))
vl->fractalid = 2;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_3))
vl->fractalid = 3;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_4))
vl->fractalid = 4;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_5))
vl->fractalid = 5;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_6))
vl->fractalid = 6;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_7))
vl->fractalid = 7;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_8))
vl->fractalid = 8;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_9))
vl->fractalid = 9;
else
return ;
redrawimage(vl);
}
void keyhookextra(void *param)
{
t_varlist *vl;
vl = param;
if (mlx_is_key_down(vl->mlx, MLX_KEY_ESCAPE))
{
mlx_close_window(vl->mlx);
return ;
}
else if (mlx_is_key_down(vl->mlx, MLX_KEY_A))
vl->iter++;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_Z) && vl->iter > 0)
vl->iter--;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_F) && vl->julre < 4)
vl->julre = vl->julre + 0.01;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_V) && vl->julre > -4)
vl->julre = vl->julre - 0.01;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_G) && vl->julim < 4)
vl->julim = vl->julim + 0.01;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_B) && vl->julim > -4)
vl->julim = vl->julim - 0.01;
else if (vl->psycho % 2)
vl->cshi++;
else if (vl->redraw == 0)
return ;
redrawimage(vl);
}