aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ft_convert_keycode.c36
-rw-r--r--src/ft_draw_scene.c2
-rw-r--r--src/ft_hooks_and_loops.c1
-rw-r--r--src/ft_init_lists.c7
-rw-r--r--src/ft_key_events.c35
-rw-r--r--src/ft_key_release.c43
6 files changed, 104 insertions, 20 deletions
diff --git a/src/ft_convert_keycode.c b/src/ft_convert_keycode.c
new file mode 100644
index 0000000..c676920
--- /dev/null
+++ b/src/ft_convert_keycode.c
@@ -0,0 +1,36 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_convert_keycode.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/17 19:00:20 by rbousset #+# #+# */
+/* Updated: 2020/02/17 19:00:21 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <cub3d.h>
+#include <stdint.h>
+
+int32_t
+ ft_convert_keycode(const int32_t tmp_code)
+{
+ uint16_t keycode;
+
+ keycode = UINT16_MAX;
+ (tmp_code == FT_W_KEY) ? (keycode = 0) : 0;
+ (tmp_code == FT_A_KEY) ? (keycode = 1) : 0;
+ (tmp_code == FT_S_KEY) ? (keycode = 2) : 0;
+ (tmp_code == FT_D_KEY) ? (keycode = 3) : 0;
+ (tmp_code == FT_L_ARR_KEY) ? (keycode = 4) : 0;
+ (tmp_code == FT_R_ARR_KEY) ? (keycode = 5) : 0;
+ (tmp_code == 3) ? (keycode = UINT16_MAX) : 0;
+ (tmp_code == 4) ? (keycode = UINT16_MAX) : 0;
+ (tmp_code == 5) ? (keycode = UINT16_MAX) : 0;
+ (tmp_code == FT_ESC_KEY) ? (keycode = FT_ESC_KEY) : 0;
+ (tmp_code == FT_F1_KEY) ? (keycode = FT_F1_KEY) : 0;
+ (tmp_code == FT_TAB_KEY) ? (keycode = FT_TAB_KEY) : 0;
+ return (keycode);
+}
+
diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c
index ec2cc89..966d357 100644
--- a/src/ft_draw_scene.c
+++ b/src/ft_draw_scene.c
@@ -18,7 +18,7 @@
void
ft_draw_scene(t_cub *clist)
{
- mlx_clear_window(clist->wlist->wlx, clist->wlist->winptr);
+ /* mlx_clear_window(clist->wlist->wlx, clist->wlist->winptr); */
clist->img.img = mlx_new_image(clist->wlist->wlx,
clist->wlist->x_size, clist->wlist->y_size);
clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp,
diff --git a/src/ft_hooks_and_loops.c b/src/ft_hooks_and_loops.c
index a494597..e7f9d58 100644
--- a/src/ft_hooks_and_loops.c
+++ b/src/ft_hooks_and_loops.c
@@ -18,6 +18,7 @@ void
ft_hooks_and_loops(t_win *wl, t_cub *cl)
{
mlx_hook(wl->winptr, 2, 1L << 0, ft_key_event, cl);
+ mlx_key_hook(wl->winptr, ft_key_release, cl);
mlx_hook(wl->winptr, 17, 0L, ft_click_close, cl);
mlx_loop(wl->wlx);
}
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index 95f0488..90b8638 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -67,6 +67,7 @@ static t_cub
*ft_init_cub(void)
{
t_cub *clist;
+ uint8_t i;
if (!(clist = (t_cub*)malloc(sizeof(t_cub))))
return (NULL);
@@ -74,6 +75,12 @@ static t_cub
!(clist->mlist = ft_init_map()))
return (NULL);
ft_bzero(clist->errmsg, 40);
+ i = 0;
+ while (i < 5)
+ {
+ clist->key_input[i] = -1;
+ i++;
+ }
clist->minimap = 0;
clist->f_rgb = ft_init_rgb();
clist->c_rgb = ft_init_rgb();
diff --git a/src/ft_key_events.c b/src/ft_key_events.c
index 267bccf..54f3033 100644
--- a/src/ft_key_events.c
+++ b/src/ft_key_events.c
@@ -15,25 +15,15 @@
#include <stdlib.h>
#include <stdint.h>
-static uint16_t
- ft_set_keycode(const uint16_t tmp_code)
+static void
+ ft_insert_key(uint16_t keycode, t_cub *clist)
{
- uint16_t keycode;
+ uint8_t i;
- keycode = UINT16_MAX;
- (tmp_code == FT_W_KEY) ? (keycode = 0) : 0;
- (tmp_code == FT_A_KEY) ? (keycode = 1) : 0;
- (tmp_code == FT_S_KEY) ? (keycode = 2) : 0;
- (tmp_code == FT_D_KEY) ? (keycode = 3) : 0;
- (tmp_code == FT_L_ARR_KEY) ? (keycode = 4) : 0;
- (tmp_code == FT_R_ARR_KEY) ? (keycode = 5) : 0;
- (tmp_code == 3) ? (keycode = UINT16_MAX) : 0;
- (tmp_code == 4) ? (keycode = UINT16_MAX) : 0;
- (tmp_code == 5) ? (keycode = UINT16_MAX) : 0;
- (tmp_code == FT_ESC_KEY) ? (keycode = FT_ESC_KEY) : 0;
- (tmp_code == FT_F1_KEY) ? (keycode = FT_F1_KEY) : 0;
- (tmp_code == FT_TAB_KEY) ? (keycode = FT_TAB_KEY) : 0;
- return (keycode);
+ i = 0;
+ while (i < 5 && clist->key_input[i] != keycode && clist->key_input[i] != -1)
+ i++;
+ clist->key_input[i] = keycode;
}
static void
@@ -53,7 +43,7 @@ int
ft_key_event(int keycode, t_cub *clist)
{
int (*fun_ptr[6])(t_cub*);
- const uint16_t tmp_code = keycode;
+ const int32_t tmp_code = keycode;
const float old_y = clist->plist->pos_y;
const float old_x = clist->plist->pos_x;
@@ -63,7 +53,14 @@ int
fun_ptr[3] = ft_d_key;
fun_ptr[4] = ft_left_key;
fun_ptr[5] = ft_right_key;
- keycode = ft_set_keycode(tmp_code);
+ keycode = ft_convert_keycode(tmp_code);
+ ft_insert_key(keycode, clist);
+ ft_printf("keys [%d][%d][%d][%d][%d]\n",
+ clist->key_input[0],
+ clist->key_input[1],
+ clist->key_input[2],
+ clist->key_input[3],
+ clist->key_input[4]);
if (keycode <= 5)
{
(*fun_ptr[keycode])(clist);
diff --git a/src/ft_key_release.c b/src/ft_key_release.c
new file mode 100644
index 0000000..e56b9d0
--- /dev/null
+++ b/src/ft_key_release.c
@@ -0,0 +1,43 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_key_release.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/17 18:43:56 by rbousset #+# #+# */
+/* Updated: 2020/02/17 18:43:59 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+#include <stdint.h>
+
+static void
+ ft_pop_key(uint16_t keycode, t_cub *clist)
+{
+ uint8_t i;
+
+ i = 0;
+ while (i < 5)
+ {
+ if (clist->key_input[i] != keycode)
+ clist->key_input[i] = -1;
+ i++;
+ }
+}
+
+int
+ ft_key_release(int keycode, t_cub *clist)
+{
+ keycode = ft_convert_keycode(keycode);
+ ft_pop_key(keycode, clist);
+ ft_printf("keys [%d][%d][%d][%d][%d]\n",
+ clist->key_input[0],
+ clist->key_input[1],
+ clist->key_input[2],
+ clist->key_input[3],
+ clist->key_input[4]);
+ return (0);
+}