132 lines
4.1 KiB
C
132 lines
4.1 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* zoommove.c |o_o || | */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: houtworm <codam@houtworm.net> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/12/25 11:14:13 by houtworm #+# #+# */
|
|
/* Updated: 2023/03/09 20:30:01 by djonker \___)=(___/ */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "../fractol.h"
|
|
|
|
void justmove(t_varlist *vl, char dir)
|
|
{
|
|
if (dir == 'l')
|
|
{
|
|
vl->xmin = vl->xmin + vl->xscale * -1 / 100;
|
|
vl->xmax = vl->xmax + vl->xscale * -1 / 100;
|
|
}
|
|
if (dir == 'r')
|
|
{
|
|
vl->xmin = vl->xmin - vl->xscale * -1 / 100;
|
|
vl->xmax = vl->xmax - vl->xscale * -1 / 100;
|
|
}
|
|
if (dir == 'u')
|
|
{
|
|
vl->ymin = vl->ymin + vl->yscale * -1 / 100;
|
|
vl->ymax = vl->ymax + vl->yscale * -1 / 100;
|
|
}
|
|
if (dir == 'd')
|
|
{
|
|
vl->ymin = vl->ymin - vl->yscale * -1 / 100;
|
|
vl->ymax = vl->ymax - vl->yscale * -1 / 100;
|
|
}
|
|
}
|
|
|
|
void moveout(t_varlist *vl, long double zoomx, long double zoomy)
|
|
{
|
|
if (vl->xcur < 0)
|
|
{
|
|
vl->xmin = vl->xmin + zoomx * ((long double)vl->xcur * -1 / vl->w);
|
|
vl->xmax = vl->xmax + zoomx * ((long double)vl->xcur * -1 / vl->w);
|
|
}
|
|
else
|
|
{
|
|
vl->xmin = vl->xmin - zoomx * ((long double)vl->xcur / vl->w);
|
|
vl->xmax = vl->xmax - zoomx * ((long double)vl->xcur / vl->w);
|
|
}
|
|
if (vl->ycur < 0)
|
|
{
|
|
vl->ymin = vl->ymin + zoomy * ((long double)vl->ycur * -1 / vl->w);
|
|
vl->ymax = vl->ymax + zoomy * ((long double)vl->ycur * -1 / vl->w);
|
|
}
|
|
else
|
|
{
|
|
vl->ymin = vl->ymin - zoomy * ((long double)vl->ycur / vl->w);
|
|
vl->ymax = vl->ymax - zoomy * ((long double)vl->ycur / vl->w);
|
|
}
|
|
}
|
|
|
|
void movein(t_varlist *vl, long double zoomx, long double zoomy)
|
|
{
|
|
if (vl->xcur < 0)
|
|
{
|
|
vl->xmin = vl->xmin - zoomx * ((long double)vl->xcur * -1 / vl->w);
|
|
vl->xmax = vl->xmax - zoomx * ((long double)vl->xcur * -1 / vl->w);
|
|
}
|
|
else
|
|
{
|
|
vl->xmin = vl->xmin + zoomx * ((long double)vl->xcur / vl->w);
|
|
vl->xmax = vl->xmax + zoomx * ((long double)vl->xcur / vl->w);
|
|
}
|
|
if (vl->ycur < 0)
|
|
{
|
|
vl->ymin = vl->ymin - zoomy * ((long double)vl->ycur * -1 / vl->w);
|
|
vl->ymax = vl->ymax - zoomy * ((long double)vl->ycur * -1 / vl->w);
|
|
}
|
|
else
|
|
{
|
|
vl->ymin = vl->ymin + zoomy * ((long double)vl->ycur / vl->w);
|
|
vl->ymax = vl->ymax + zoomy * ((long double)vl->ycur / vl->w);
|
|
}
|
|
}
|
|
|
|
void zoomtomouse(t_varlist *vl)
|
|
{
|
|
long double zoomx;
|
|
long double zoomy;
|
|
|
|
vl->xscale = vl->xmin - vl->xmax;
|
|
vl->yscale = vl->ymax - vl->ymin;
|
|
zoomx = 0.9 * vl->xscale;
|
|
zoomy = 0.9 * vl->yscale;
|
|
vl->xmax = vl->xmax + (vl->xscale - zoomx) / 2;
|
|
vl->xmin = vl->xmax + zoomx;
|
|
vl->ymin = vl->ymin + (vl->yscale - zoomy) / 2;
|
|
vl->ymax = vl->ymin + zoomy;
|
|
mlx_get_mouse_pos(vl->mlx, &vl->xcur, &vl->ycur);
|
|
vl->xcur = vl->xcur - (vl->w / 2);
|
|
vl->ycur = vl->ycur - (vl->h / 2);
|
|
vl->xscale = vl->xmax - vl->xmin;
|
|
vl->yscale = vl->ymax - vl->ymin;
|
|
zoomx = 0.1111111111111111111111111111111111111111 * vl->xscale;
|
|
zoomy = 0.1111111111111111111111111111111111111111 * vl->yscale;
|
|
movein(vl, zoomx, zoomy);
|
|
}
|
|
|
|
void zoomfrommouse(t_varlist *vl)
|
|
{
|
|
long double zoomx;
|
|
long double zoomy;
|
|
|
|
vl->xscale = vl->xmin - vl->xmax;
|
|
vl->yscale = vl->ymax - vl->ymin;
|
|
zoomx = 1.1 * vl->xscale;
|
|
zoomy = 1.1 * vl->yscale;
|
|
vl->xmax = vl->xmax + (vl->xscale - zoomx) / 2;
|
|
vl->xmin = vl->xmax + zoomx;
|
|
vl->ymin = vl->ymin + (vl->yscale - zoomy) / 2;
|
|
vl->ymax = vl->ymin + zoomy;
|
|
mlx_get_mouse_pos(vl->mlx, &vl->xcur, &vl->ycur);
|
|
vl->xcur = vl->xcur - vl->w / 2;
|
|
vl->ycur = vl->ycur - vl->h / 2;
|
|
vl->xscale = vl->xmax - vl->xmin;
|
|
vl->yscale = vl->ymax - vl->ymin;
|
|
zoomx = 0.0909090909090909090909090909090909090909 * vl->xscale;
|
|
zoomy = 0.0909090909090909090909090909090909090909 * vl->yscale;
|
|
moveout(vl, zoomx, zoomy);
|
|
}
|