From 172fc25127f57b6b405de41c02987ad8c3a40c95 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 24 Apr 2020 19:34:31 +0200 Subject: Libx update, click close should work --- minilibx-linux/=README= | 41 --------------------------------- minilibx-linux/Makefile.gen | 2 +- minilibx-linux/Makefile.mk | 2 +- minilibx-linux/README.md | 41 +++++++++++++++++++++++++++++++++ minilibx-linux/configure | 1 + minilibx-linux/man/man1/mlx_pixel_put.1 | 13 +++++++---- minilibx-linux/mlx.h | 4 ++++ minilibx-linux/mlx_mouse.c | 26 +++++++++++++++++++++ src/ft_hooks_and_loops.c | 3 ++- 9 files changed, 84 insertions(+), 49 deletions(-) delete mode 100644 minilibx-linux/=README= create mode 100644 minilibx-linux/README.md create mode 100644 minilibx-linux/mlx_mouse.c diff --git a/minilibx-linux/=README= b/minilibx-linux/=README= deleted file mode 100644 index 65d5429..0000000 --- a/minilibx-linux/=README= +++ /dev/null @@ -1,41 +0,0 @@ - -This is the MinilibX, a simple X-Window (X11R6) programming API -in C, designed for students, suitable for X-beginners. - - -Contents - - - source code in C to create the mlx library - - man pages (in man/ directory) - - a test program (in test/ directory) is built - with the library - - a public include file mlx.h - - a tiny configure script to generate an appropriate Makefile.gen - - -Requirements - - - MinilibX only support TrueColor visual type (8,15,16,24 or 32 bits depth) - - gcc - - X11 include files - - XShm extension must be present - - -Compile MinilibX - - - run ./configure or make - both will make a few tests, create Makefile.gen - and then automatically run make on this generated Makefile.gen . - libmlx.a and libmlx_$(HOSTTYPE).a are created. - test/mlx-test binary is also created. - - -Install MinilibX - - - no installation script is provided. You may want to install - - libmlx.a and/or libmlx_$(HOSTTYPE).a in /usr/X11/lib or /usr/local/lib - - mlx.h in /usr/X11/include or /usr/local/include - - man/man3/mlx*.1 in /usr/X11/man/man3 or /usr/local/man/man3 - - - Olivier CROUZET - 2014-01-06 - diff --git a/minilibx-linux/Makefile.gen b/minilibx-linux/Makefile.gen index f1b7b36..629a0a4 100644 --- a/minilibx-linux/Makefile.gen +++ b/minilibx-linux/Makefile.gen @@ -28,7 +28,7 @@ SRC = mlx_init.c mlx_new_window.c mlx_pixel_put.c mlx_loop.c \ mlx_put_image_to_window.c mlx_get_color_value.c mlx_clear_window.c \ mlx_xpm.c mlx_int_str_to_wordtab.c mlx_destroy_window.c \ mlx_int_param_event.c mlx_int_set_win_event_mask.c mlx_hook.c \ - mlx_rgb.c mlx_destroy_image.c mlx_screen_size.c + mlx_rgb.c mlx_destroy_image.c mlx_mouse.c mlx_screen_size.c OBJ =$(SRC:.c=.o) CFLAGS = -O3 -I$(INC) diff --git a/minilibx-linux/Makefile.mk b/minilibx-linux/Makefile.mk index 8aec9f8..4b4deb8 100644 --- a/minilibx-linux/Makefile.mk +++ b/minilibx-linux/Makefile.mk @@ -28,7 +28,7 @@ SRC = mlx_init.c mlx_new_window.c mlx_pixel_put.c mlx_loop.c \ mlx_put_image_to_window.c mlx_get_color_value.c mlx_clear_window.c \ mlx_xpm.c mlx_int_str_to_wordtab.c mlx_destroy_window.c \ mlx_int_param_event.c mlx_int_set_win_event_mask.c mlx_hook.c \ - mlx_rgb.c mlx_destroy_image.c mlx_screen_size.c + mlx_rgb.c mlx_destroy_image.c mlx_mouse.c mlx_screen_size.c OBJ =$(SRC:.c=.o) CFLAGS = -O3 -I$(INC) diff --git a/minilibx-linux/README.md b/minilibx-linux/README.md new file mode 100644 index 0000000..65d5429 --- /dev/null +++ b/minilibx-linux/README.md @@ -0,0 +1,41 @@ + +This is the MinilibX, a simple X-Window (X11R6) programming API +in C, designed for students, suitable for X-beginners. + + +Contents + + - source code in C to create the mlx library + - man pages (in man/ directory) + - a test program (in test/ directory) is built + with the library + - a public include file mlx.h + - a tiny configure script to generate an appropriate Makefile.gen + + +Requirements + + - MinilibX only support TrueColor visual type (8,15,16,24 or 32 bits depth) + - gcc + - X11 include files + - XShm extension must be present + + +Compile MinilibX + + - run ./configure or make + both will make a few tests, create Makefile.gen + and then automatically run make on this generated Makefile.gen . + libmlx.a and libmlx_$(HOSTTYPE).a are created. + test/mlx-test binary is also created. + + +Install MinilibX + + - no installation script is provided. You may want to install + - libmlx.a and/or libmlx_$(HOSTTYPE).a in /usr/X11/lib or /usr/local/lib + - mlx.h in /usr/X11/include or /usr/local/include + - man/man3/mlx*.1 in /usr/X11/man/man3 or /usr/local/man/man3 + + + Olivier CROUZET - 2014-01-06 - diff --git a/minilibx-linux/configure b/minilibx-linux/configure index 2f9b0be..04fcdc4 100755 --- a/minilibx-linux/configure +++ b/minilibx-linux/configure @@ -15,6 +15,7 @@ for inc in \ /usr/X11R5/include \ /usr/X11R4/include \ \ + /usr/include \ /usr/include/X11 \ /usr/include/X11R6 \ /usr/include/X11R5 \ diff --git a/minilibx-linux/man/man1/mlx_pixel_put.1 b/minilibx-linux/man/man1/mlx_pixel_put.1 index f4d131e..258df58 100644 --- a/minilibx-linux/man/man1/mlx_pixel_put.1 +++ b/minilibx-linux/man/man1/mlx_pixel_put.1 @@ -63,11 +63,14 @@ to create the original color. Theses three values must be set inside the integer to display the right color. The three least significant bytes of this integer are filled as shown in the picture below: -.nf - | 0 | R | G | B | color integer - +---+---+---+---+ -.fi - +.TS +allbox; +c s s s s +r c c c c. +Color Integer +Interpretation \[*a] R G B +Bit numbers 31..24 23..16 15..8 7..0 +.TE While filling the integer, make sure you avoid endian problems. Remember that the "blue" byte should always be the least significant one. diff --git a/minilibx-linux/mlx.h b/minilibx-linux/mlx.h index af6af12..951871c 100644 --- a/minilibx-linux/mlx.h +++ b/minilibx-linux/mlx.h @@ -126,6 +126,10 @@ int mlx_do_key_autorepeatoff(void *mlx_ptr); int mlx_do_key_autorepeaton(void *mlx_ptr); int mlx_do_sync(void *mlx_ptr); +int mlx_mouse_move(void *mlx_ptr, void *win_ptr, int x, int y); +int mlx_mouse_hide(void *mlx_ptr, void *win_ptr); +int mlx_mouse_show(void *mlx_ptr, void *win_ptr); + int mlx_get_screen_size(void *mlx_ptr, int *sizex, int *sizey); #endif /* MLX_H */ diff --git a/minilibx-linux/mlx_mouse.c b/minilibx-linux/mlx_mouse.c new file mode 100644 index 0000000..0ada4e4 --- /dev/null +++ b/minilibx-linux/mlx_mouse.c @@ -0,0 +1,26 @@ +#include "mlx_int.h" + +int mlx_mouse_move(t_xvar *xvar, t_win_list *win, int x, int y) +{ + XWarpPointer(xvar->display, None, win->window, 0, 0, 0, 0, x, y); + return (0); +} + +int mlx_mouse_hide(t_xvar *xvar, t_win_list *win) +{ + static char data[1] = {0}; + Cursor cursor; + Pixmap blank; + XColor dummy; + + blank = XCreateBitmapFromData(xvar->display, win->window, data, 1, 1); + cursor = XCreatePixmapCursor(xvar->display, blank, blank, &dummy, &dummy, 0, 0); + XDefineCursor(xvar->display, win->window, cursor); + XFreePixmap(xvar->display, blank); + XFreeCursor(xvar->display, cursor); +} + +int mlx_mouse_show(t_xvar *xvar, t_win_list *win) +{ + XUndefineCursor(xvar->display, win->window); +} diff --git a/src/ft_hooks_and_loops.c b/src/ft_hooks_and_loops.c index b8bdd36..c1ab352 100644 --- a/src/ft_hooks_and_loops.c +++ b/src/ft_hooks_and_loops.c @@ -13,13 +13,14 @@ #include #include #include +#include void ft_hooks_and_loops(t_win *wl, t_cub *cl) { mlx_hook(wl->winptr, 2, (1L << 0), ft_key_event, cl); mlx_hook(wl->winptr, 3, (1L << 1), ft_key_release, cl); + mlx_hook(wl->winptr, DestroyNotify, StructureNotifyMask, ft_click_close, cl); mlx_loop_hook(wl->wlx, ft_key_loop, cl); - mlx_hook(wl->winptr, 17, 0L, ft_click_close, cl); mlx_loop(wl->wlx); } -- cgit v1.2.3