17
17
int i = 0 ;
18
18
int ms_g = 0 ;
19
19
20
+ void key_act_d (mlx_t * mlx , keys_t key , double * n , double op )
21
+ {
22
+ if (mlx_is_key_down (mlx , key ))
23
+ * n += op ;
24
+ }
25
+
26
+ void key_act_i (mlx_t * mlx , keys_t key , int * n , int op )
27
+ {
28
+ if (mlx_is_key_down (mlx , key ))
29
+ * n = op ;
30
+ }
31
+
20
32
void key_hook (void * dta )
21
33
{
22
34
t_dta * tmp ;
35
+ int32_t x ;
36
+ int32_t y ;
23
37
24
38
tmp = (t_dta * )dta ;
25
39
if (mlx_is_key_down (tmp -> mlx , MLX_KEY_ESCAPE ))
26
40
mlx_close_window (tmp -> mlx );
27
- if (mlx_is_key_down (tmp -> mlx , MLX_KEY_MINUS ))
28
- tmp -> iter = tmp -> iter / 1.1 + 1 ;
29
- if (mlx_is_key_down (tmp -> mlx , MLX_KEY_EQUAL ))
30
- tmp -> iter = tmp -> iter * 1.1 + 1 ;
31
- if (mlx_is_key_down (tmp -> mlx , MLX_KEY_UP ))
32
- tmp -> ys += 0.02 * tmp -> scale ;
33
- if (mlx_is_key_down (tmp -> mlx , MLX_KEY_DOWN ))
34
- tmp -> ys -= 0.02 * tmp -> scale ;
35
- if (mlx_is_key_down (tmp -> mlx , MLX_KEY_LEFT ))
36
- tmp -> xs -= 0.02 * tmp -> scale ;
37
- if (mlx_is_key_down (tmp -> mlx , MLX_KEY_RIGHT ))
38
- tmp -> xs += 0.02 * tmp -> scale ;
39
41
if (mlx_is_key_down (tmp -> mlx , MLX_KEY_R ))
40
42
populate_dta (tmp );
43
+ key_act_i (tmp -> mlx , MLX_KEY_MINUS , & tmp -> iter , tmp -> iter / 1.1 + 1 );
44
+ key_act_i (tmp -> mlx , MLX_KEY_EQUAL , & tmp -> iter , tmp -> iter * 1.1 );
45
+ key_act_i (tmp -> mlx , MLX_KEY_C , & tmp -> cs , tmp -> cs % (254 * 6 ) + 6 );
46
+ key_act_d (tmp -> mlx , MLX_KEY_UP , & tmp -> ys , 0.02 * tmp -> scale );
47
+ key_act_d (tmp -> mlx , MLX_KEY_DOWN , & tmp -> ys , -0.02 * tmp -> scale );
48
+ key_act_d (tmp -> mlx , MLX_KEY_LEFT , & tmp -> xs , -0.02 * tmp -> scale );
49
+ key_act_d (tmp -> mlx , MLX_KEY_RIGHT , & tmp -> xs , 0.02 * tmp -> scale );
41
50
if (mlx_is_mouse_down (tmp -> mlx , MLX_MOUSE_BUTTON_RIGHT ))
42
- tmp -> cs = (tmp -> cs % (254 * 6 )) + 6 ;
43
- // clock_t diff;
44
- // clock_t start = clock();
51
+ {
52
+ mlx_get_mouse_pos (tmp -> mlx , & x , & y );
53
+ tmp -> re = (x - WIDTH / 2 ) * tmp -> scale / WIDTH ;
54
+ tmp -> im = (HEIGHT / 2 - y ) * tmp -> scale / HEIGHT ;
55
+ }
56
+ clock_t diff ;
57
+ clock_t start = clock ();
45
58
calculate_window (tmp );
46
- // diff = clock() - start;
47
- // int msec = diff * 1000 / CLOCKS_PER_SEC;
48
- // ms_g += msec%1000;
49
- // i++;
50
- // printf("Time taken %d seconds %d milliseconds av: %d\n ", msec/1000, msec %1000, ms_g / i);
59
+ diff = clock () - start ;
60
+ int msec = diff * 1000 / CLOCKS_PER_SEC ;
61
+ ms_g += msec %1000 ;
62
+ i ++ ;
63
+ printf ("%d milliseconds, av: %d\nScale: %f, %d iter\nXparam %f, Yparam %f\n\n " , msec %1000 , ms_g / i , tmp -> scale , tmp -> iter , tmp -> re , tmp -> im );
51
64
52
65
}
53
66
@@ -63,14 +76,14 @@ void scroll_hook(double xdelta, double ydelta, void *param)
63
76
if (ydelta > 0 )
64
77
{
65
78
tmp -> scale /= 1.2 ;
66
- tmp -> xs += (( x - WIDTH / 2 ) * tmp -> scale ) / WIDTH * 0.2 ;
67
- tmp -> ys += (( HEIGHT / 2 - y ) * tmp -> scale ) / HEIGHT * 0.2 ;
79
+ tmp -> xs += (x - WIDTH / 2 ) * tmp -> scale / WIDTH * 0.2 ;
80
+ tmp -> ys += (HEIGHT / 2 - y ) * tmp -> scale / HEIGHT * 0.2 ;
68
81
}
69
82
if (ydelta < 0 )
70
83
{
71
84
tmp -> scale *= 1.2 ;
72
- tmp -> xs += (( x - WIDTH / 2 ) * tmp -> scale ) / WIDTH * - (1 - 1 / 1.2 );
73
- tmp -> ys += (( HEIGHT / 2 - y ) * tmp -> scale ) / HEIGHT * - (1 - 1 / 1.2 );
85
+ tmp -> xs += (x - WIDTH / 2 ) * tmp -> scale / WIDTH * - (1 - 1 / 1.2 );
86
+ tmp -> ys += (HEIGHT / 2 - y ) * tmp -> scale / HEIGHT * - (1 - 1 / 1.2 );
74
87
}
75
88
}
76
89
0 commit comments