add recent minilibx linux as submodule
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +1,6 @@
|
|||||||
[submodule "libs/libft"]
|
[submodule "libs/libft"]
|
||||||
path = libs/libft
|
path = libs/libft
|
||||||
url = git@bitbucket.org:hugogogo/libft.git
|
url = git@bitbucket.org:hugogogo/libft.git
|
||||||
|
[submodule "libs/minilibx-linux"]
|
||||||
|
path = libs/minilibx-linux
|
||||||
|
url = https://github.com/42Paris/minilibx-linux.git
|
||||||
|
|||||||
9
Makefile
9
Makefile
@@ -8,6 +8,7 @@ NAME = cube3d
|
|||||||
VPATH = $(D_SRCS)
|
VPATH = $(D_SRCS)
|
||||||
EXT = c
|
EXT = c
|
||||||
CC = gcc
|
CC = gcc
|
||||||
|
OS = $(shell uname)
|
||||||
|
|
||||||
# sources
|
# sources
|
||||||
D_SRCS = srcs \
|
D_SRCS = srcs \
|
||||||
@@ -40,7 +41,11 @@ INCLUDES = -I$(D_HEADERS) -I$(D_LFT) -I$(D_LMLX)
|
|||||||
# libraries
|
# libraries
|
||||||
D_LIB = libs
|
D_LIB = libs
|
||||||
D_LFT = $(D_LIB)/libft
|
D_LFT = $(D_LIB)/libft
|
||||||
D_LMLX = $(D_LIB)/minilibx-linux-master
|
ifeq (${OS}, Linux)
|
||||||
|
D_LMLX = $(D_LIB)/minilibx-linux
|
||||||
|
else
|
||||||
|
D_LMLX = $(D_LIB)/minilibx-linux
|
||||||
|
endif
|
||||||
|
|
||||||
# objects
|
# objects
|
||||||
D_OBJS = builds
|
D_OBJS = builds
|
||||||
@@ -72,6 +77,7 @@ $(OBJS): $(HEADERS:%=$(D_HEADERS)/%)
|
|||||||
|
|
||||||
$(NAME): $(OBJS)
|
$(NAME): $(OBJS)
|
||||||
make -C $(D_LFT)
|
make -C $(D_LFT)
|
||||||
|
make -C $(D_LMLX)
|
||||||
$(CC) $(OBJS) -o $@ $(LFLAGS) $(CFLAGS)
|
$(CC) $(OBJS) -o $@ $(LFLAGS) $(CFLAGS)
|
||||||
|
|
||||||
leaks: $(NAME)
|
leaks: $(NAME)
|
||||||
@@ -82,6 +88,7 @@ clean:
|
|||||||
|
|
||||||
fclean: clean
|
fclean: clean
|
||||||
make fclean -C $(D_LFT)
|
make fclean -C $(D_LFT)
|
||||||
|
make clean -C $(D_LMLX)
|
||||||
rm -f $(NAME)
|
rm -f $(NAME)
|
||||||
|
|
||||||
re: fclean all
|
re: fclean all
|
||||||
|
|||||||
1
libs/minilibx-linux
Submodule
1
libs/minilibx-linux
Submodule
Submodule libs/minilibx-linux added at 7dc53a411a
@@ -1,22 +0,0 @@
|
|||||||
##
|
|
||||||
## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
|
|
||||||
##
|
|
||||||
## Made by Olivier Crouzet
|
|
||||||
## Login <ol@epitech.net>
|
|
||||||
##
|
|
||||||
## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet
|
|
||||||
## Last update Tue May 15 15:44:41 2007 Olivier Crouzet
|
|
||||||
##
|
|
||||||
|
|
||||||
## Please use configure script
|
|
||||||
|
|
||||||
|
|
||||||
all : do_configure
|
|
||||||
|
|
||||||
do_configure :
|
|
||||||
./configure
|
|
||||||
|
|
||||||
clean :
|
|
||||||
./configure clean
|
|
||||||
|
|
||||||
re : clean all
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
INC=/usr/include
|
|
||||||
HT=Linux
|
|
||||||
DOCP=do_cp
|
|
||||||
##
|
|
||||||
## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
|
|
||||||
##
|
|
||||||
## Made by Olivier Crouzet
|
|
||||||
## Login <ol@epitech.net>
|
|
||||||
##
|
|
||||||
## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet
|
|
||||||
## Last update Tue May 15 15:41:20 2007 Olivier Crouzet
|
|
||||||
##
|
|
||||||
|
|
||||||
## Please use configure script
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CC = gcc
|
|
||||||
|
|
||||||
NAME = libmlx.a
|
|
||||||
|
|
||||||
SRC = mlx_init.c mlx_new_window.c mlx_pixel_put.c mlx_loop.c \
|
|
||||||
mlx_mouse_hook.c mlx_key_hook.c mlx_expose_hook.c mlx_loop_hook.c \
|
|
||||||
mlx_int_anti_resize_win.c mlx_int_do_nothing.c \
|
|
||||||
mlx_int_wait_first_expose.c mlx_int_get_visual.c \
|
|
||||||
mlx_flush_event.c mlx_string_put.c mlx_set_font.c \
|
|
||||||
mlx_new_image.c mlx_get_data_addr.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_mouse.c mlx_screen_size.c \
|
|
||||||
mlx_destroy_display.c
|
|
||||||
|
|
||||||
OBJ =$(SRC:.c=.o)
|
|
||||||
CFLAGS = -O3 -I$(INC)
|
|
||||||
|
|
||||||
all : $(NAME) $(DOCP)
|
|
||||||
|
|
||||||
$(NAME) : $(OBJ)
|
|
||||||
ar -r $(NAME) $(OBJ)
|
|
||||||
ranlib $(NAME)
|
|
||||||
|
|
||||||
do_cp :
|
|
||||||
cp $(NAME) libmlx_$(HT).a
|
|
||||||
|
|
||||||
|
|
||||||
clean :
|
|
||||||
rm -f $(OBJ) $(NAME) libmlx_$(HT).a *~ core *.core
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
##
|
|
||||||
## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
|
|
||||||
##
|
|
||||||
## Made by Olivier Crouzet
|
|
||||||
## Login <ol@epitech.net>
|
|
||||||
##
|
|
||||||
## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet
|
|
||||||
## Last update Tue May 15 15:41:20 2007 Olivier Crouzet
|
|
||||||
##
|
|
||||||
|
|
||||||
## Please use configure script
|
|
||||||
|
|
||||||
|
|
||||||
INC =%%%%
|
|
||||||
HT =%%%%
|
|
||||||
DOCP =%%%%
|
|
||||||
|
|
||||||
CC = gcc
|
|
||||||
|
|
||||||
NAME = libmlx.a
|
|
||||||
|
|
||||||
SRC = mlx_init.c mlx_new_window.c mlx_pixel_put.c mlx_loop.c \
|
|
||||||
mlx_mouse_hook.c mlx_key_hook.c mlx_expose_hook.c mlx_loop_hook.c \
|
|
||||||
mlx_int_anti_resize_win.c mlx_int_do_nothing.c \
|
|
||||||
mlx_int_wait_first_expose.c mlx_int_get_visual.c \
|
|
||||||
mlx_flush_event.c mlx_string_put.c mlx_set_font.c \
|
|
||||||
mlx_new_image.c mlx_get_data_addr.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_mouse.c mlx_screen_size.c \
|
|
||||||
mlx_destroy_display.c
|
|
||||||
|
|
||||||
OBJ =$(SRC:.c=.o)
|
|
||||||
CFLAGS = -O3 -I$(INC)
|
|
||||||
|
|
||||||
all : $(NAME) $(DOCP)
|
|
||||||
|
|
||||||
$(NAME) : $(OBJ)
|
|
||||||
ar -r $(NAME) $(OBJ)
|
|
||||||
ranlib $(NAME)
|
|
||||||
|
|
||||||
do_cp :
|
|
||||||
cp $(NAME) libmlx_$(HT).a
|
|
||||||
|
|
||||||
|
|
||||||
clean :
|
|
||||||
rm -f $(OBJ) $(NAME) libmlx_$(HT).a *~ core *.core
|
|
||||||
@@ -1,43 +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
|
|
||||||
- make
|
|
||||||
- X11 include files (package xorg)
|
|
||||||
- XShm extension must be present (package libxext-dev)
|
|
||||||
- Utility functions from BSD systems - development files (package libbsd-dev)
|
|
||||||
- **e.g. _sudo apt-get install gcc make xorg libxext-dev libbsd-dev_ (Debian/Ubuntu)**
|
|
||||||
|
|
||||||
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 -
|
|
||||||
95
libs/minilibx-linux-master/configure
vendored
95
libs/minilibx-linux-master/configure
vendored
@@ -1,95 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
|
|
||||||
if [ -n "$1" -a "$1" = "--help" ] ; then
|
|
||||||
echo "Usage : $0\n Auto-configure and make MinilibX"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
conf_inc=NO
|
|
||||||
|
|
||||||
for inc in \
|
|
||||||
/usr/X11/include \
|
|
||||||
/usr/X11R6/include \
|
|
||||||
/usr/X11R5/include \
|
|
||||||
/usr/X11R4/include \
|
|
||||||
\
|
|
||||||
/usr/include \
|
|
||||||
/usr/include/X11 \
|
|
||||||
/usr/include/X11R6 \
|
|
||||||
/usr/include/X11R5 \
|
|
||||||
/usr/include/X11R4 \
|
|
||||||
\
|
|
||||||
/usr/local/X11/include \
|
|
||||||
/usr/local/X11R6/include \
|
|
||||||
/usr/local/X11R5/include \
|
|
||||||
/usr/local/X11R4/include \
|
|
||||||
\
|
|
||||||
/usr/local/include/X11 \
|
|
||||||
/usr/local/include/X11R6 \
|
|
||||||
/usr/local/include/X11R5 \
|
|
||||||
/usr/local/include/X11R4 \
|
|
||||||
\
|
|
||||||
/usr/X386/include \
|
|
||||||
/usr/x386/include \
|
|
||||||
/usr/XFree86/include/X11 \
|
|
||||||
\
|
|
||||||
/usr/include \
|
|
||||||
/usr/local/include \
|
|
||||||
/usr/athena/include \
|
|
||||||
/usr/local/x11r5/include \
|
|
||||||
/usr/lpp/Xamples/include \
|
|
||||||
\
|
|
||||||
/usr/openwin/include \
|
|
||||||
/usr/openwin/share/include
|
|
||||||
do
|
|
||||||
if [ -f "$inc/X11/Xlib.h" -a -f "$inc/X11/extensions/XShm.h" ]; then
|
|
||||||
conf_inc=$inc
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
if [ "$conf_inc" = "NO" ]; then
|
|
||||||
echo "Can't find a suitable X11 include directory."
|
|
||||||
exit
|
|
||||||
else
|
|
||||||
echo "X11 include dir : $conf_inc"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$HOSTTYPE" ]; then
|
|
||||||
conf_ht=`uname -s`
|
|
||||||
else
|
|
||||||
conf_ht=$HOSTTYPE
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$conf_ht" ]; then
|
|
||||||
conf_docp=""
|
|
||||||
else
|
|
||||||
conf_docp="do_cp"
|
|
||||||
echo "lib_$conf_ht generation"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
/bin/echo "INC=$conf_inc" > Makefile.gen
|
|
||||||
/bin/echo "HT=$conf_ht" >> Makefile.gen
|
|
||||||
/bin/echo "DOCP=$conf_docp" >> Makefile.gen
|
|
||||||
cat Makefile.mk | grep -v %%%% >> Makefile.gen
|
|
||||||
|
|
||||||
/bin/echo "INC=$conf_inc" > test/Makefile.gen
|
|
||||||
/bin/echo "HT=$conf_ht" >> test/Makefile.gen
|
|
||||||
/bin/echo "DOCP=$conf_docp" >> test/Makefile.gen
|
|
||||||
cat test/Makefile.mk | grep -v %%%% >> test/Makefile.gen
|
|
||||||
|
|
||||||
|
|
||||||
if [ -n "$1" -a "$1" = "clean" ] ; then
|
|
||||||
echo "Now make it clean."
|
|
||||||
make -f Makefile.gen clean
|
|
||||||
(cd test ; make -f Makefile.gen clean)
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Now make it."
|
|
||||||
make -f Makefile.gen all
|
|
||||||
(cd test ; make -f Makefile.gen all )
|
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
.TH MiniLibX 3 "September 19, 2002"
|
|
||||||
.SH NAME
|
|
||||||
MiniLibX - Handle events
|
|
||||||
.SH SYNOPSYS
|
|
||||||
|
|
||||||
.nf
|
|
||||||
.I int
|
|
||||||
.fi
|
|
||||||
.B mlx_loop
|
|
||||||
(
|
|
||||||
.I void *mlx_ptr
|
|
||||||
);
|
|
||||||
|
|
||||||
.nf
|
|
||||||
.I int
|
|
||||||
.fi
|
|
||||||
.B mlx_key_hook
|
|
||||||
(
|
|
||||||
.I void *win_ptr, int (*funct_ptr)(), void *param
|
|
||||||
);
|
|
||||||
|
|
||||||
.nf
|
|
||||||
.I int
|
|
||||||
.fi
|
|
||||||
.B mlx_mouse_hook
|
|
||||||
(
|
|
||||||
.I void *win_ptr, int (*funct_ptr)(), void *param
|
|
||||||
);
|
|
||||||
|
|
||||||
.nf
|
|
||||||
.I int
|
|
||||||
.fi
|
|
||||||
.B mlx_expose_hook
|
|
||||||
(
|
|
||||||
.I void *win_ptr, int (*funct_ptr)(), void *param
|
|
||||||
);
|
|
||||||
|
|
||||||
.nf
|
|
||||||
.I int
|
|
||||||
.fi
|
|
||||||
.B mlx_loop_hook
|
|
||||||
(
|
|
||||||
.I void *mlx_ptr, int (*funct_ptr)(), void *param
|
|
||||||
);
|
|
||||||
|
|
||||||
.SH X-WINDOW EVENTS
|
|
||||||
|
|
||||||
The X-Window system is bi-directionnal. On one hand, the program sends orders to
|
|
||||||
the screen to display pixels, images, and so on. On the other hand,
|
|
||||||
it can get information from the keyboard and mouse associated to
|
|
||||||
the screen. To do so, the program receives "events" from the keyboard or the
|
|
||||||
mouse.
|
|
||||||
|
|
||||||
.SH DESCRIPTION
|
|
||||||
|
|
||||||
To receive events, you must use
|
|
||||||
.B mlx_loop
|
|
||||||
(). This function never returns. It is an infinite loop that waits for
|
|
||||||
an event, and then calls a user-defined function associated with this event.
|
|
||||||
A single parameter is needed, the connection identifier
|
|
||||||
.I mlx_ptr
|
|
||||||
(see the
|
|
||||||
.B mlx manual).
|
|
||||||
|
|
||||||
You can assign different functions to the three following events:
|
|
||||||
.br
|
|
||||||
- A key is pressed
|
|
||||||
.br
|
|
||||||
- The mouse button is pressed
|
|
||||||
.br
|
|
||||||
- A part of the window should be re-drawn
|
|
||||||
(this is called an "expose" event, and it is your program's job to handle it).
|
|
||||||
.br
|
|
||||||
|
|
||||||
Each window can define a different function for the same event.
|
|
||||||
|
|
||||||
The three functions
|
|
||||||
.B mlx_key_hook
|
|
||||||
(),
|
|
||||||
.B mlx_mouse_hook
|
|
||||||
() and
|
|
||||||
.B mlx_expose_hook
|
|
||||||
() work exactly the same way.
|
|
||||||
.I funct_ptr
|
|
||||||
is a pointer to the function you want to be called
|
|
||||||
when an event occurs. This assignment is specific to the window defined by the
|
|
||||||
.I win_ptr
|
|
||||||
identifier. The
|
|
||||||
.I param
|
|
||||||
adress will be passed to the function everytime it is called, and should be
|
|
||||||
used to store the parameters it might need.
|
|
||||||
|
|
||||||
The syntax for the
|
|
||||||
.B mlx_loop_hook
|
|
||||||
() function is identical to the previous ones, but the given function will be
|
|
||||||
called when no event occurs.
|
|
||||||
|
|
||||||
When it catches an event, the MiniLibX calls the corresponding function
|
|
||||||
with fixed parameters:
|
|
||||||
.nf
|
|
||||||
|
|
||||||
expose_hook(void *param);
|
|
||||||
key_hook(int keycode,void *param);
|
|
||||||
mouse_hook(int button,int x,int y,void *param);
|
|
||||||
loop_hook(void *param);
|
|
||||||
|
|
||||||
.fi
|
|
||||||
These function names are arbitrary. They here are used to distinguish
|
|
||||||
parameters according to the event. These functions are NOT part of the
|
|
||||||
MiniLibX.
|
|
||||||
|
|
||||||
.I param
|
|
||||||
is the address specified in the mlx_*_hook calls. This address is never
|
|
||||||
used nor modified by the MiniLibX. On key and mouse events, additional
|
|
||||||
information is passed:
|
|
||||||
.I keycode
|
|
||||||
tells you which key is pressed (look for the X11 include file "keysymdef.h"),
|
|
||||||
(
|
|
||||||
.I x
|
|
||||||
,
|
|
||||||
.I y
|
|
||||||
) are the coordinates of the mouse click in the window, and
|
|
||||||
.I button
|
|
||||||
tells you which mouse button was pressed.
|
|
||||||
|
|
||||||
.SH GOING FURTHER WITH EVENTS
|
|
||||||
The MiniLibX provides a much generic access to all X-Window events. The
|
|
||||||
.I mlx.h
|
|
||||||
include define
|
|
||||||
.B mlx_hook()
|
|
||||||
in the same manner mlx_*_hook functions work. The event and mask values
|
|
||||||
will be taken from the X11 include file "X.h".
|
|
||||||
|
|
||||||
See source code of mlx_int_param_event.c to find out how the MiniLibX will
|
|
||||||
call your own function for a specific event.
|
|
||||||
|
|
||||||
.SH SEE ALSO
|
|
||||||
mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3)
|
|
||||||
|
|
||||||
.SH AUTHOR
|
|
||||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
.TH MiniLibX 3 "September 19, 2002"
|
|
||||||
.SH NAME
|
|
||||||
MiniLibX - Managing windows
|
|
||||||
.SH SYNOPSYS
|
|
||||||
|
|
||||||
.nf
|
|
||||||
.I void *
|
|
||||||
.fi
|
|
||||||
.B mlx_new_window
|
|
||||||
(
|
|
||||||
.I void *mlx_ptr, int size_x, int size_y, char *title
|
|
||||||
);
|
|
||||||
|
|
||||||
.nf
|
|
||||||
.I int
|
|
||||||
.fi
|
|
||||||
.B mlx_clear_window
|
|
||||||
(
|
|
||||||
.I void *mlx_ptr, void *win_ptr
|
|
||||||
);
|
|
||||||
|
|
||||||
.nf
|
|
||||||
.I int
|
|
||||||
.fi
|
|
||||||
.B mlx_destroy_window
|
|
||||||
(
|
|
||||||
.I void *mlx_ptr, void *win_ptr
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
.SH DESCRIPTION
|
|
||||||
The
|
|
||||||
.B mlx_new_window
|
|
||||||
() function creates a new window on the screen, using the
|
|
||||||
.I size_x
|
|
||||||
and
|
|
||||||
.I size_y
|
|
||||||
parameters to determine its size, and
|
|
||||||
.I title
|
|
||||||
as the text that should be displayed in the window's title bar.
|
|
||||||
The
|
|
||||||
.I mlx_ptr
|
|
||||||
parameter is the connection identifier returned by
|
|
||||||
.B mlx_init
|
|
||||||
() (see the
|
|
||||||
.B mlx
|
|
||||||
man page).
|
|
||||||
.B mlx_new_window
|
|
||||||
() returns a
|
|
||||||
.I void *
|
|
||||||
window identifier that can be used by other MiniLibX calls.
|
|
||||||
Note that the MiniLibX
|
|
||||||
can handle an arbitrary number of separate windows.
|
|
||||||
|
|
||||||
.B mlx_clear_window
|
|
||||||
() and
|
|
||||||
.B mlx_destroy_window
|
|
||||||
() respectively clear (in black) and destroy the given window. They both have
|
|
||||||
the same parameters:
|
|
||||||
.I mlx_ptr
|
|
||||||
is the screen connection identifier, and
|
|
||||||
.I win_ptr
|
|
||||||
is a window identifier.
|
|
||||||
|
|
||||||
.SH RETURN VALUES
|
|
||||||
If
|
|
||||||
.B mlx_new_window()
|
|
||||||
fails to create a new window (for wathever reason), it will return NULL,
|
|
||||||
otherwise a non-null pointer is returned as a window identifier.
|
|
||||||
.B mlx_clear_window
|
|
||||||
and
|
|
||||||
.B mlx_destroy_window
|
|
||||||
right now return nothing.
|
|
||||||
|
|
||||||
.SH SEE ALSO
|
|
||||||
mlx(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3)
|
|
||||||
|
|
||||||
.SH AUTHOR
|
|
||||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
.TH MiniLibX 3 "September 19, 2002"
|
|
||||||
.SH NAME
|
|
||||||
MiniLibX - Drawing inside windows
|
|
||||||
.SH SYNOPSYS
|
|
||||||
|
|
||||||
.nf
|
|
||||||
.I int
|
|
||||||
.fi
|
|
||||||
.B mlx_pixel_put
|
|
||||||
(
|
|
||||||
.I void *mlx_ptr, void *win_ptr, int x, int y, int color
|
|
||||||
);
|
|
||||||
|
|
||||||
.nf
|
|
||||||
.I int
|
|
||||||
.fi
|
|
||||||
.B mlx_string_put
|
|
||||||
(
|
|
||||||
.I void *mlx_ptr, void *win_ptr, int x, int y, int color, char *string
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
.SH DESCRIPTION
|
|
||||||
The
|
|
||||||
.B mlx_pixel_put
|
|
||||||
() function draws a defined pixel in the window
|
|
||||||
.I win_ptr
|
|
||||||
using the (
|
|
||||||
.I x
|
|
||||||
,
|
|
||||||
.I y
|
|
||||||
) coordinates, and the specified
|
|
||||||
.I color
|
|
||||||
\&. The origin (0,0) is the upper left corner of the window, the x and y axis
|
|
||||||
respectively pointing right and down. The connection
|
|
||||||
identifier,
|
|
||||||
.I mlx_ptr
|
|
||||||
, is needed (see the
|
|
||||||
.B mlx
|
|
||||||
man page).
|
|
||||||
|
|
||||||
Parameters for
|
|
||||||
.B mlx_string_put
|
|
||||||
() have the same meaning. Instead of a simple pixel, the specified
|
|
||||||
.I string
|
|
||||||
will be displayed at (
|
|
||||||
.I x
|
|
||||||
,
|
|
||||||
.I y
|
|
||||||
).
|
|
||||||
|
|
||||||
In both functions, it is impossible to display anything outside the
|
|
||||||
specified window, nor display in another window in front of the selected one.
|
|
||||||
|
|
||||||
.SH COLOR MANAGEMENT
|
|
||||||
The
|
|
||||||
.I color
|
|
||||||
parameter has an integer type. The displayed color needs to be encoded
|
|
||||||
in this integer, following a defined scheme. All displayable colors
|
|
||||||
can be split in 3 basic colors: red, green and blue. Three associated
|
|
||||||
values, in the 0-255 range, represent how much of each color is mixed up
|
|
||||||
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:
|
|
||||||
|
|
||||||
.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.
|
|
||||||
|
|
||||||
|
|
||||||
.SH SEE ALSO
|
|
||||||
mlx(3), mlx_new_window(3), mlx_new_image(3), mlx_loop(3)
|
|
||||||
|
|
||||||
|
|
||||||
.SH AUTHOR
|
|
||||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
.TH MiniLibX 3 "September 19, 2002"
|
|
||||||
.SH NAME
|
|
||||||
MiniLibX - Simple X-Window Interface Library for students
|
|
||||||
.SH SYNOPSYS
|
|
||||||
#include <mlx.h>
|
|
||||||
|
|
||||||
.nf
|
|
||||||
.I void *
|
|
||||||
.fi
|
|
||||||
.B mlx_init
|
|
||||||
();
|
|
||||||
|
|
||||||
.SH DESCRIPTION
|
|
||||||
MiniLibX is an easy way to create graphical software,
|
|
||||||
without any X-Window programming knowledge. It provides
|
|
||||||
simple window creation, a drawing tool, image and basic events
|
|
||||||
management.
|
|
||||||
|
|
||||||
.SH X-WINDOW CONCEPT
|
|
||||||
|
|
||||||
X-Window is a network-oriented graphical system for Unix.
|
|
||||||
It is based on two main parts:
|
|
||||||
.br
|
|
||||||
On one side, your software wants to draw something on the screen and/or
|
|
||||||
get keyboard & mouse entries.
|
|
||||||
.br
|
|
||||||
On the other side, the X-Server manages the screen, keyboard and mouse
|
|
||||||
(It is often refered to as a "display").
|
|
||||||
.br
|
|
||||||
A network connection must be established between these two entities to send
|
|
||||||
drawing orders (from the software to the X-Server), and keyboard/mouse
|
|
||||||
events (from the X-Server to the software).
|
|
||||||
|
|
||||||
.SH INCLUDE FILE
|
|
||||||
.B mlx.h
|
|
||||||
should be included for a correct use of the MiniLibX API.
|
|
||||||
It only contains function prototypes, no structure is needed.
|
|
||||||
|
|
||||||
.SH LIBRARY FUNCTIONS
|
|
||||||
.P
|
|
||||||
First of all, you need to initialize the connection
|
|
||||||
between your software and the display.
|
|
||||||
Once this connection is established, you'll be able to
|
|
||||||
use other MiniLibX functions to send the X-Server messages,
|
|
||||||
like "I want to draw a yellow pixel in this window" or "did the
|
|
||||||
user hit a key?".
|
|
||||||
.P
|
|
||||||
The
|
|
||||||
.B mlx_init
|
|
||||||
function will create this connection. No parameters are needed, ant it will
|
|
||||||
return a
|
|
||||||
.I "void *"
|
|
||||||
identifier, used for further calls to the library routines.
|
|
||||||
.P
|
|
||||||
All other MiniLibX functions are described in the following man pages:
|
|
||||||
|
|
||||||
.TP 20
|
|
||||||
.B mlx_new_window
|
|
||||||
: manage windows
|
|
||||||
.TP 20
|
|
||||||
.B mlx_pixel_put
|
|
||||||
: draw inside window
|
|
||||||
.TP 20
|
|
||||||
.B mlx_new_image
|
|
||||||
: manipulate images
|
|
||||||
.TP 20
|
|
||||||
.B mlx_loop
|
|
||||||
: handle keyboard or mouse events
|
|
||||||
|
|
||||||
.SH LINKING MiniLibX
|
|
||||||
To use MiniLibX functions, you'll need to link
|
|
||||||
your software with several libraries, including the MiniLibX library itself.
|
|
||||||
To do this, simply add the following arguments at linking time:
|
|
||||||
|
|
||||||
.B -lmlx -lXext -lX11
|
|
||||||
|
|
||||||
You may also need to specify the path to these libraries, using
|
|
||||||
the
|
|
||||||
.B -L
|
|
||||||
flag.
|
|
||||||
|
|
||||||
|
|
||||||
.SH RETURN VALUES
|
|
||||||
If
|
|
||||||
.B mlx_init()
|
|
||||||
fails to set up the connection to the X server, it will return NULL, otherwise
|
|
||||||
a non-null pointer is returned as a connection identifier.
|
|
||||||
|
|
||||||
.SH SEE ALSO
|
|
||||||
mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3)
|
|
||||||
|
|
||||||
.SH AUTHOR
|
|
||||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
|
||||||
@@ -1,192 +0,0 @@
|
|||||||
.TH MiniLibX 3 "September 19, 2002"
|
|
||||||
.SH NAME
|
|
||||||
MiniLibX - Manipulating images
|
|
||||||
.SH SYNOPSYS
|
|
||||||
|
|
||||||
.nf
|
|
||||||
.I void *
|
|
||||||
.fi
|
|
||||||
.B mlx_new_image
|
|
||||||
(
|
|
||||||
.I void *mlx_ptr, int width, int height
|
|
||||||
);
|
|
||||||
|
|
||||||
.nf
|
|
||||||
.I char *
|
|
||||||
.fi
|
|
||||||
.B mlx_get_data_addr
|
|
||||||
(
|
|
||||||
.I void *img_ptr, int *bits_per_pixel, int *size_line, int *endian
|
|
||||||
);
|
|
||||||
|
|
||||||
.nf
|
|
||||||
.I int
|
|
||||||
.fi
|
|
||||||
.B mlx_put_image_to_window
|
|
||||||
(
|
|
||||||
.I void *mlx_ptr, void *win_ptr, void *img_ptr, int x, int y
|
|
||||||
);
|
|
||||||
|
|
||||||
.nf
|
|
||||||
.I unsigned int
|
|
||||||
.fi
|
|
||||||
.B mlx_get_color_value
|
|
||||||
(
|
|
||||||
.I void *mlx_ptr, int color
|
|
||||||
);
|
|
||||||
|
|
||||||
.nf
|
|
||||||
.I void *
|
|
||||||
.fi
|
|
||||||
.B mlx_xpm_to_image
|
|
||||||
(
|
|
||||||
.I void *mlx_ptr, char **xpm_data, int *width, int *height
|
|
||||||
);
|
|
||||||
|
|
||||||
.nf
|
|
||||||
.I void *
|
|
||||||
.fi
|
|
||||||
.B mlx_xpm_file_to_image
|
|
||||||
(
|
|
||||||
.I void *mlx_ptr, char *filename, int *width, int *height
|
|
||||||
);
|
|
||||||
|
|
||||||
.nf
|
|
||||||
.I int
|
|
||||||
.fi
|
|
||||||
.B mlx_destroy_image
|
|
||||||
(
|
|
||||||
.I void *mlx_ptr, void *img_ptr
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
.SH DESCRIPTION
|
|
||||||
|
|
||||||
.B mlx_new_image
|
|
||||||
() creates a new image in memory. It returns a
|
|
||||||
.I void *
|
|
||||||
identifier needed to manipulate this image later. It only needs
|
|
||||||
the size of the image to be created, using the
|
|
||||||
.I width
|
|
||||||
and
|
|
||||||
.I height
|
|
||||||
parameters, and the
|
|
||||||
.I mlx_ptr
|
|
||||||
connection identifier (see the
|
|
||||||
.B mlx
|
|
||||||
manual).
|
|
||||||
|
|
||||||
The user can draw inside the image (see below), and
|
|
||||||
can dump the image inside a specified window at any time to
|
|
||||||
display it on the screen. This is done using
|
|
||||||
.B mlx_put_image_to_window
|
|
||||||
(). Three identifiers are needed here, for the connection to the
|
|
||||||
display, the window to use, and the image (respectively
|
|
||||||
.I mlx_ptr
|
|
||||||
,
|
|
||||||
.I win_ptr
|
|
||||||
and
|
|
||||||
.I img_ptr
|
|
||||||
). The (
|
|
||||||
.I x
|
|
||||||
,
|
|
||||||
.I y
|
|
||||||
) coordinates define where the image should be placed in the window.
|
|
||||||
|
|
||||||
.B mlx_get_data_addr
|
|
||||||
() returns information about the created image, allowing a user
|
|
||||||
to modify it later. The
|
|
||||||
.I img_ptr
|
|
||||||
parameter specifies the image to use. The three next parameters should
|
|
||||||
be the addresses of three different valid integers.
|
|
||||||
.I bits_per_pixel
|
|
||||||
will be filled with the number of bits needed to represent a pixel color
|
|
||||||
(also called the depth of the image).
|
|
||||||
.I size_line
|
|
||||||
is the number of bytes used to store one line of the image in memory.
|
|
||||||
This information is needed to move from one line to another in the image.
|
|
||||||
.I endian
|
|
||||||
tells you wether the pixel color in the image needs to be stored in
|
|
||||||
little endian (
|
|
||||||
.I endian
|
|
||||||
== 0), or big endian (
|
|
||||||
.I endian
|
|
||||||
== 1).
|
|
||||||
|
|
||||||
.B mlx_get_data_addr
|
|
||||||
returns a
|
|
||||||
.I char *
|
|
||||||
address that represents the begining of the memory area where the image
|
|
||||||
is stored. From this adress, the first
|
|
||||||
.I bits_per_pixel
|
|
||||||
bits represent the color of the first pixel in the first line of
|
|
||||||
the image. The second group of
|
|
||||||
.I bits_per_pixel
|
|
||||||
bits represent the second pixel of the first line, and so on.
|
|
||||||
Add
|
|
||||||
.I size_line
|
|
||||||
to the adress to get the begining of the second line. You can reach any
|
|
||||||
pixels of the image that way.
|
|
||||||
|
|
||||||
.B mlx_destroy_image
|
|
||||||
destroys the given image (
|
|
||||||
.I img_ptr
|
|
||||||
).
|
|
||||||
|
|
||||||
.SH STORING COLOR INSIDE IMAGES
|
|
||||||
|
|
||||||
Depending on the display, the number of bits used to store a pixel color
|
|
||||||
can change. The user usually represents a color in RGB mode, using
|
|
||||||
one byte for each component (see
|
|
||||||
.B mlx_pixel_put
|
|
||||||
manual). This must be translated to fit the
|
|
||||||
.I bits_per_pixel
|
|
||||||
requirement of the image, and make the color understandable to the X-Server.
|
|
||||||
That is the purpose of the
|
|
||||||
.B mlx_get_color_value
|
|
||||||
() function. It takes a standard RGB
|
|
||||||
.I color
|
|
||||||
parameter, and returns an
|
|
||||||
.I unsigned int
|
|
||||||
value.
|
|
||||||
The
|
|
||||||
.I bits_per_pixel
|
|
||||||
least significant bits of this value can be stored in the image.
|
|
||||||
|
|
||||||
Keep in mind that the least significant bits position depends on the local
|
|
||||||
computer's endian. If the endian of the image (in fact the endian of
|
|
||||||
the X-Server's computer) differs from the local endian, then the value should
|
|
||||||
be transformed before being used.
|
|
||||||
|
|
||||||
.SH XPM IMAGES
|
|
||||||
|
|
||||||
The
|
|
||||||
.B mlx_xpm_to_image
|
|
||||||
() and
|
|
||||||
.B mlx_xpm_file_to_image
|
|
||||||
() functions will create a new image the same way.
|
|
||||||
They will fill it using the specified
|
|
||||||
.I xpm_data
|
|
||||||
or
|
|
||||||
.I filename
|
|
||||||
, depending on which function is used.
|
|
||||||
Note that MiniLibX does not use the standard
|
|
||||||
Xpm library to deal with xpm images. You may not be able to
|
|
||||||
read all types of xpm images. It however handles transparency.
|
|
||||||
|
|
||||||
.SH RETURN VALUES
|
|
||||||
The three functions that create images,
|
|
||||||
.B mlx_new_image()
|
|
||||||
,
|
|
||||||
.B mlx_xpm_to_image()
|
|
||||||
and
|
|
||||||
.B mlx_xpm_file_to_image()
|
|
||||||
, will return NULL if an error occurs. Otherwise they return a non-null pointer
|
|
||||||
as an image identifier.
|
|
||||||
|
|
||||||
|
|
||||||
.SH SEE ALSO
|
|
||||||
mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_loop(3)
|
|
||||||
|
|
||||||
.SH AUTHOR
|
|
||||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_clear_window.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Thu Sep 7 19:46:15 2000 Charlie Root
|
|
||||||
** Last update Tue Sep 25 17:11:19 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_clear_window(t_xvar *xvar,t_win_list *win)
|
|
||||||
{
|
|
||||||
XClearWindow(xvar->display,win->window);
|
|
||||||
if (xvar->do_flush)
|
|
||||||
XFlush(xvar->display);
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* mlx_destroy_display.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: mg <mg@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2020/10/03 18:56:35 by mg #+# #+# */
|
|
||||||
/* Updated: 2020/10/04 01:55:35 by mg ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
int mlx_destroy_display(t_xvar *xvar)
|
|
||||||
{
|
|
||||||
XCloseDisplay(xvar->display);
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_destroy_image.c for MinilibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Tue Mar 12 10:25:15 2002 Charlie Root
|
|
||||||
** Last update Tue May 15 16:45:54 2007 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_destroy_image(t_xvar *xvar, t_img *img)
|
|
||||||
{
|
|
||||||
if (img->type == MLX_TYPE_SHM_PIXMAP ||
|
|
||||||
img->type == MLX_TYPE_SHM)
|
|
||||||
{
|
|
||||||
XShmDetach(xvar->display, &(img->shm));
|
|
||||||
shmdt(img->shm.shmaddr);
|
|
||||||
/* shmctl IPC_RMID already done */
|
|
||||||
}
|
|
||||||
XDestroyImage(img->image); /* For image & shm-image. Also free img->data */
|
|
||||||
XFreePixmap(xvar->display, img->pix);
|
|
||||||
if (img->gc)
|
|
||||||
XFreeGC(xvar->display, img->gc);
|
|
||||||
free(img);
|
|
||||||
if (xvar->do_flush)
|
|
||||||
XFlush(xvar->display);
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_destroy_window.c for MinilibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Tue Mar 12 10:25:15 2002 Charlie Root
|
|
||||||
** Last update Tue May 15 16:46:08 2007 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_destroy_window(t_xvar *xvar,t_win_list *win)
|
|
||||||
{
|
|
||||||
t_win_list *w;
|
|
||||||
t_win_list *prev;
|
|
||||||
t_win_list first;
|
|
||||||
|
|
||||||
first.next = xvar->win_list;
|
|
||||||
prev = &first;
|
|
||||||
w = prev->next;
|
|
||||||
while (w)
|
|
||||||
{
|
|
||||||
if (w==win)
|
|
||||||
prev->next = w->next;
|
|
||||||
else
|
|
||||||
prev = w;
|
|
||||||
w = w->next;
|
|
||||||
}
|
|
||||||
xvar->win_list = first.next;
|
|
||||||
XDestroyWindow(xvar->display,win->window);
|
|
||||||
XFreeGC(xvar->display,win->gc);
|
|
||||||
free(win);
|
|
||||||
if (xvar->do_flush)
|
|
||||||
XFlush(xvar->display);
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_expose_hook.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Thu Aug 3 11:49:06 2000 Charlie Root
|
|
||||||
** Last update Fri Feb 23 17:07:42 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_expose_hook(t_win_list *win,int (*funct)(),void *param)
|
|
||||||
{
|
|
||||||
win->hooks[Expose].hook = funct;
|
|
||||||
win->hooks[Expose].param = param;
|
|
||||||
win->hooks[Expose].mask = ExposureMask;
|
|
||||||
}
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <X11/extensions/Xrandr.h>
|
|
||||||
|
|
||||||
/* global for independant extension */
|
|
||||||
|
|
||||||
RRMode saved_mode = 0;
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_ext_fullscreen(t_xvar *xvar, t_win_list *win, int fullscreen)
|
|
||||||
{
|
|
||||||
XWindowAttributes watt;
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
XRRScreenResources *res;
|
|
||||||
XRROutputInfo *o_info;
|
|
||||||
XRRCrtcInfo *crtc;
|
|
||||||
RRMode mode_candidate;
|
|
||||||
int idx_output;
|
|
||||||
int idx_candidate;
|
|
||||||
|
|
||||||
if (!XGetWindowAttributes(xvar->display, win->window, &watt))
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
res = XRRGetScreenResources(xvar->display, xvar->root);
|
|
||||||
o_info = NULL;
|
|
||||||
idx_output = -1;
|
|
||||||
i = res->noutput;
|
|
||||||
while (i--)
|
|
||||||
{
|
|
||||||
o_info = XRRGetOutputInfo(xvar->display, res, res->outputs[i]);
|
|
||||||
if (o_info->connection == RR_Connected)
|
|
||||||
{
|
|
||||||
idx_output = i;
|
|
||||||
i = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
XRRFreeOutputInfo(o_info);
|
|
||||||
}
|
|
||||||
if (!o_info)
|
|
||||||
{
|
|
||||||
XRRFreeScreenResources(res);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
idx_candidate = -1;
|
|
||||||
i = o_info->nmode;
|
|
||||||
while (i--)
|
|
||||||
{
|
|
||||||
j = res->nmode;
|
|
||||||
while (j--)
|
|
||||||
if (res->modes[j].id == o_info->modes[i])
|
|
||||||
if (res->modes[j].width >= watt.width && res->modes[j].height >= watt.height &&
|
|
||||||
(idx_candidate == -1 || res->modes[idx_candidate].width > res->modes[j].width ||
|
|
||||||
res->modes[idx_candidate].height > res->modes[j].height) )
|
|
||||||
idx_candidate = i;
|
|
||||||
}
|
|
||||||
if (idx_candidate < 0)
|
|
||||||
{
|
|
||||||
XRRFreeOutputInfo(o_info);
|
|
||||||
XRRFreeScreenResources(res);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
if (!fullscreen && saved_mode == -1)
|
|
||||||
idx_candidate = 0; /* if no clue, uses first mode, usually part of npreferred */
|
|
||||||
mode_candidate = o_info->modes[idx_candidate];
|
|
||||||
if (!fullscreen)
|
|
||||||
mode_candidate = saved_mode;
|
|
||||||
|
|
||||||
crtc = XRRGetCrtcInfo(xvar->display, res, o_info->crtc);
|
|
||||||
saved_mode = crtc->mode;
|
|
||||||
|
|
||||||
i = XRRSetCrtcConfig(xvar->display, res, o_info->crtc, CurrentTime, 0, 0, mode_candidate,
|
|
||||||
crtc->rotation, &res->outputs[idx_output], 1);
|
|
||||||
if (fullscreen)
|
|
||||||
printf("found mode : %d x %d\n Status %d\n", res->modes[idx_candidate].width, res->modes[idx_candidate].height, i);
|
|
||||||
else
|
|
||||||
printf("back previous mode\n");
|
|
||||||
|
|
||||||
XMoveWindow(xvar->display, win->window, 0, 0);
|
|
||||||
XMapRaised(xvar->display, win->window);
|
|
||||||
|
|
||||||
if (fullscreen)
|
|
||||||
{
|
|
||||||
// XGrabPointer(xvar->display, win->window, True, 0, GrabModeAsync, GrabModeAsync, win->window, 0L, CurrentTime);
|
|
||||||
XGrabKeyboard(xvar->display, win->window, False, GrabModeAsync, GrabModeAsync, CurrentTime);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
XUngrabPointer(xvar->display, CurrentTime);
|
|
||||||
XUngrabKeyboard(xvar->display, CurrentTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
XSync(xvar->display, False);
|
|
||||||
sleep(1);
|
|
||||||
|
|
||||||
XRRFreeCrtcInfo(crtc);
|
|
||||||
XRRFreeOutputInfo(o_info);
|
|
||||||
XRRFreeScreenResources(res);
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_flush_event.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Wed Aug 2 18:58:11 2000 Charlie Root
|
|
||||||
** Last update Fri Feb 23 17:08:48 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_flush_event(t_xvar *xvar)
|
|
||||||
{
|
|
||||||
XEvent ev;
|
|
||||||
|
|
||||||
while (XPending(xvar->display))
|
|
||||||
{
|
|
||||||
XNextEvent(xvar->display,&ev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_get_color_value.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Mon Jul 31 19:01:33 2000 Charlie Root
|
|
||||||
** Last update Thu Oct 4 15:04:13 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_get_color_value(t_xvar *xvar,int color)
|
|
||||||
{
|
|
||||||
return(mlx_int_get_good_color(xvar,color));
|
|
||||||
}
|
|
||||||
|
|
||||||
int mlx_int_get_good_color(t_xvar *xvar,int color)
|
|
||||||
{
|
|
||||||
XColor xc;
|
|
||||||
|
|
||||||
if (xvar->depth>=24)
|
|
||||||
return (color);
|
|
||||||
xc.red = (color>>8)&0xFF00;
|
|
||||||
xc.green = color&0xFF00;
|
|
||||||
xc.blue = (color<<8)&0xFF00;
|
|
||||||
xc.pixel = ((xc.red>>(16-xvar->decrgb[1]))<<xvar->decrgb[0])+
|
|
||||||
((xc.green>>(16-xvar->decrgb[3]))<<xvar->decrgb[2])+
|
|
||||||
((xc.blue>>(16-xvar->decrgb[5]))<<xvar->decrgb[4]);
|
|
||||||
return (xc.pixel);
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_get_data_addr.c for MiniLibX in raytraceur
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Mon Aug 14 15:45:57 2000 Charlie Root
|
|
||||||
** Last update Thu Sep 27 19:05:25 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
char *mlx_get_data_addr(t_img *img,int *bits_per_pixel,
|
|
||||||
int *size_line,int *endian)
|
|
||||||
{
|
|
||||||
*bits_per_pixel = img->bpp;
|
|
||||||
*size_line = img->size_line;
|
|
||||||
*endian = img->image->byte_order;
|
|
||||||
return (img->data);
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_hook.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Thu Aug 3 11:49:06 2000 Charlie Root
|
|
||||||
** Last update Fri Jan 28 17:05:28 2005 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_hook(t_win_list *win, int x_event, int x_mask,
|
|
||||||
int (*funct)(),void *param)
|
|
||||||
{
|
|
||||||
win->hooks[x_event].hook = funct;
|
|
||||||
win->hooks[x_event].param = param;
|
|
||||||
win->hooks[x_event].mask = x_mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_do_key_autorepeatoff(t_xvar *xvar)
|
|
||||||
{
|
|
||||||
XAutoRepeatOff(xvar->display);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mlx_do_key_autorepeaton(t_xvar *xvar)
|
|
||||||
{
|
|
||||||
XAutoRepeatOn(xvar->display);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_do_sync(t_xvar *xvar)
|
|
||||||
{
|
|
||||||
XSync(xvar->display, False);
|
|
||||||
}
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_init.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Mon Jul 31 16:52:42 2000 Charlie Root
|
|
||||||
** Last update Fri Jan 28 17:05:09 2005 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_init()
|
|
||||||
{
|
|
||||||
t_xvar *xvar;
|
|
||||||
|
|
||||||
if (!(xvar = malloc(sizeof(*xvar))))
|
|
||||||
return ((void*)0);
|
|
||||||
if ((xvar->display = XOpenDisplay("")) == 0)
|
|
||||||
{
|
|
||||||
free(xvar);
|
|
||||||
return ((void*)0);
|
|
||||||
}
|
|
||||||
xvar->screen = DefaultScreen(xvar->display);
|
|
||||||
xvar->root = DefaultRootWindow(xvar->display);
|
|
||||||
xvar->cmap = DefaultColormap(xvar->display,xvar->screen);
|
|
||||||
xvar->depth = DefaultDepth(xvar->display,xvar->screen);
|
|
||||||
if (mlx_int_get_visual(xvar)==-1)
|
|
||||||
{
|
|
||||||
printf(ERR_NO_TRUECOLOR);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
xvar->win_list = 0;
|
|
||||||
xvar->loop_hook = 0;
|
|
||||||
xvar->loop_param = (void *)0;
|
|
||||||
xvar->do_flush = 1;
|
|
||||||
xvar->wm_delete_window = XInternAtom (xvar->display, "WM_DELETE_WINDOW", False);
|
|
||||||
mlx_int_deal_shm(xvar);
|
|
||||||
if (xvar->private_cmap)
|
|
||||||
xvar->cmap = XCreateColormap(xvar->display,xvar->root,
|
|
||||||
xvar->visual,AllocNone);
|
|
||||||
mlx_int_rgb_conversion(xvar);
|
|
||||||
return (xvar);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** pshm_format of -1 : Not XYBitmap|XYPixmap|ZPixmap
|
|
||||||
** alpha libX need a check of the DISPLAY env var, or shm is allowed
|
|
||||||
** in remote Xserver connections.
|
|
||||||
*/
|
|
||||||
|
|
||||||
int mlx_int_deal_shm(t_xvar *xvar)
|
|
||||||
{
|
|
||||||
int use_pshm;
|
|
||||||
int bidon;
|
|
||||||
char *dpy;
|
|
||||||
char buff[33];
|
|
||||||
|
|
||||||
xvar->use_xshm = XShmQueryVersion(xvar->display,&bidon,&bidon,&(use_pshm));
|
|
||||||
if (xvar->use_xshm && use_pshm)
|
|
||||||
xvar->pshm_format = XShmPixmapFormat(xvar->display);
|
|
||||||
else
|
|
||||||
xvar->pshm_format = -1;
|
|
||||||
gethostname(buff,32);
|
|
||||||
dpy = getenv(ENV_DISPLAY);
|
|
||||||
if (dpy && strlen(dpy) && *dpy!=':' && strncmp(dpy,buff,strlen(buff)) &&
|
|
||||||
strncmp(dpy,LOCALHOST,strlen(LOCALHOST)) )
|
|
||||||
{
|
|
||||||
xvar->pshm_format = -1;
|
|
||||||
xvar->use_xshm = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
** TrueColor Visual is needed to have *_mask correctly set
|
|
||||||
*/
|
|
||||||
|
|
||||||
int mlx_int_rgb_conversion(t_xvar *xvar)
|
|
||||||
{
|
|
||||||
bzero(xvar->decrgb,sizeof(int)*6);
|
|
||||||
while (!(xvar->visual->red_mask&1))
|
|
||||||
{ xvar->visual->red_mask >>= 1; xvar->decrgb[0] ++; }
|
|
||||||
while (xvar->visual->red_mask&1)
|
|
||||||
{ xvar->visual->red_mask >>= 1; xvar->decrgb[1] ++; }
|
|
||||||
while (!(xvar->visual->green_mask&1))
|
|
||||||
{ xvar->visual->green_mask >>= 1; xvar->decrgb[2] ++; }
|
|
||||||
while (xvar->visual->green_mask&1)
|
|
||||||
{ xvar->visual->green_mask >>= 1; xvar->decrgb[3] ++; }
|
|
||||||
while (!(xvar->visual->blue_mask&1))
|
|
||||||
{ xvar->visual->blue_mask >>= 1; xvar->decrgb[4] ++; }
|
|
||||||
while (xvar->visual->blue_mask&1)
|
|
||||||
{ xvar->visual->blue_mask >>= 1; xvar->decrgb[5] ++; }
|
|
||||||
}
|
|
||||||
@@ -1,138 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_int.h for mlx in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Mon Jul 31 16:45:48 2000 Charlie Root
|
|
||||||
** Last update Wed May 25 16:44:16 2011 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Internal settings for MiniLibX
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef MLX_INT_H
|
|
||||||
|
|
||||||
# define MLX_INT_H
|
|
||||||
|
|
||||||
# include <stdlib.h>
|
|
||||||
# include <stdio.h>
|
|
||||||
# include <string.h>
|
|
||||||
# include <unistd.h>
|
|
||||||
# include <fcntl.h>
|
|
||||||
# include <sys/mman.h>
|
|
||||||
# include <X11/Xlib.h>
|
|
||||||
# include <X11/Xutil.h>
|
|
||||||
# include <sys/ipc.h>
|
|
||||||
# include <sys/shm.h>
|
|
||||||
# include <X11/extensions/XShm.h>
|
|
||||||
# include <X11/XKBlib.h>
|
|
||||||
/* #include <X11/xpm.h> */
|
|
||||||
|
|
||||||
|
|
||||||
# define MLX_TYPE_SHM_PIXMAP 3
|
|
||||||
# define MLX_TYPE_SHM 2
|
|
||||||
# define MLX_TYPE_XIMAGE 1
|
|
||||||
|
|
||||||
# define MLX_MAX_EVENT LASTEvent
|
|
||||||
|
|
||||||
|
|
||||||
# define ENV_DISPLAY "DISPLAY"
|
|
||||||
# define LOCALHOST "localhost"
|
|
||||||
# define ERR_NO_TRUECOLOR "MinilibX Error : No TrueColor Visual available.\n"
|
|
||||||
# define WARN_SHM_ATTACH "MinilibX Warning : X server can't attach shared memory.\n"
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct s_xpm_col
|
|
||||||
{
|
|
||||||
int name;
|
|
||||||
int col;
|
|
||||||
} t_xpm_col;
|
|
||||||
|
|
||||||
|
|
||||||
struct s_col_name
|
|
||||||
{
|
|
||||||
char *name;
|
|
||||||
int color;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct s_event_list
|
|
||||||
{
|
|
||||||
int mask;
|
|
||||||
int (*hook)();
|
|
||||||
void *param;
|
|
||||||
} t_event_list;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct s_win_list
|
|
||||||
{
|
|
||||||
Window window;
|
|
||||||
GC gc;
|
|
||||||
struct s_win_list *next;
|
|
||||||
int (*mouse_hook)();
|
|
||||||
int (*key_hook)();
|
|
||||||
int (*expose_hook)();
|
|
||||||
void *mouse_param;
|
|
||||||
void *key_param;
|
|
||||||
void *expose_param;
|
|
||||||
t_event_list hooks[MLX_MAX_EVENT];
|
|
||||||
} t_win_list;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct s_img
|
|
||||||
{
|
|
||||||
XImage *image;
|
|
||||||
Pixmap pix;
|
|
||||||
GC gc;
|
|
||||||
int size_line;
|
|
||||||
int bpp;
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
int type;
|
|
||||||
int format;
|
|
||||||
char *data;
|
|
||||||
XShmSegmentInfo shm;
|
|
||||||
} t_img;
|
|
||||||
|
|
||||||
typedef struct s_xvar
|
|
||||||
{
|
|
||||||
Display *display;
|
|
||||||
Window root;
|
|
||||||
int screen;
|
|
||||||
int depth;
|
|
||||||
Visual *visual;
|
|
||||||
Colormap cmap;
|
|
||||||
int private_cmap;
|
|
||||||
t_win_list *win_list;
|
|
||||||
int (*loop_hook)();
|
|
||||||
void *loop_param;
|
|
||||||
int use_xshm;
|
|
||||||
int pshm_format;
|
|
||||||
int do_flush;
|
|
||||||
int decrgb[6];
|
|
||||||
Atom wm_delete_window;
|
|
||||||
} t_xvar;
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_do_nothing();
|
|
||||||
int mlx_get_color_value();
|
|
||||||
int mlx_int_get_good_color();
|
|
||||||
int mlx_int_find_in_pcm();
|
|
||||||
int mlx_int_anti_resize_win();
|
|
||||||
int mlx_int_wait_first_expose();
|
|
||||||
int mlx_int_rgb_conversion();
|
|
||||||
int mlx_int_deal_shm();
|
|
||||||
void *mlx_int_new_xshm_image();
|
|
||||||
char **mlx_int_str_to_wordtab();
|
|
||||||
void *mlx_new_image();
|
|
||||||
int shm_att_pb();
|
|
||||||
int mlx_int_get_visual(t_xvar *xvar);
|
|
||||||
int mlx_int_set_win_event_mask(t_xvar *xvar);
|
|
||||||
int mlx_int_str_str_cote(char *str,char *find,int len);
|
|
||||||
int mlx_int_str_str(char *str,char *find,int len);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_int_anti_resize_win.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Tue Aug 8 14:31:05 2000 Charlie Root
|
|
||||||
** Last update Tue Sep 25 15:56:58 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_anti_resize_win(t_xvar *xvar,Window win,int w,int h)
|
|
||||||
{
|
|
||||||
XSizeHints hints;
|
|
||||||
long toto;
|
|
||||||
|
|
||||||
XGetWMNormalHints(xvar->display,win,&hints,&toto);
|
|
||||||
hints.width = w;
|
|
||||||
hints.height = h;
|
|
||||||
hints.min_width = w;
|
|
||||||
hints.min_height = h;
|
|
||||||
hints.max_width = w;
|
|
||||||
hints.max_height = h;
|
|
||||||
hints.flags = PPosition | PSize | PMinSize | PMaxSize;
|
|
||||||
XSetWMNormalHints(xvar->display,win,&hints);
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_int_do_nothing.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Tue Aug 8 12:58:24 2000 Charlie Root
|
|
||||||
** Last update Tue Sep 25 15:56:22 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_do_nothing(void *param)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_int_get_visual.c for MinilibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Wed Oct 3 17:01:51 2001 Charlie Root
|
|
||||||
** Last update Thu Oct 4 15:00:45 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** We need a private colormap for non-default Visual.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_get_visual(t_xvar *xvar)
|
|
||||||
{
|
|
||||||
XVisualInfo *vi;
|
|
||||||
XVisualInfo template;
|
|
||||||
int nb_item;
|
|
||||||
|
|
||||||
xvar->private_cmap = 0;
|
|
||||||
xvar->visual = DefaultVisual(xvar->display,xvar->screen);
|
|
||||||
if (xvar->visual->class == TrueColor)
|
|
||||||
return (0);
|
|
||||||
template.class = TrueColor;
|
|
||||||
template.depth = xvar->depth;
|
|
||||||
if (!(vi = XGetVisualInfo(xvar->display,VisualDepthMask|VisualClassMask,
|
|
||||||
&template,&nb_item)) )
|
|
||||||
return (-1);
|
|
||||||
xvar->visual = vi->visual;
|
|
||||||
xvar->private_cmap = 1;
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_int_param_event.c for MinilibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Mon Jul 31 16:37:50 2000 Charlie Root
|
|
||||||
** Last update Wed Oct 6 13:14:52 2004 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
int mlx_int_param_undef()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int mlx_int_param_KeyPress(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
|
||||||
{
|
|
||||||
win->hooks[KeyPress].hook(XkbKeycodeToKeysym(xvar->display,
|
|
||||||
ev->xkey.keycode, 0, 0),
|
|
||||||
win->hooks[KeyPress].param);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mlx_int_param_KeyRelease(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
|
||||||
{
|
|
||||||
win->hooks[KeyRelease].hook(XkbKeycodeToKeysym(xvar->display,
|
|
||||||
ev->xkey.keycode, 0, 0),
|
|
||||||
win->hooks[KeyRelease].param);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mlx_int_param_ButtonPress(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
|
||||||
{
|
|
||||||
win->hooks[ButtonPress].hook(ev->xbutton.button,ev->xbutton.x,ev->xbutton.y,
|
|
||||||
win->hooks[ButtonPress].param);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mlx_int_param_ButtonRelease(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
|
||||||
{
|
|
||||||
win->hooks[ButtonRelease].hook(ev->xbutton.button,
|
|
||||||
ev->xbutton.x, ev->xbutton.y,
|
|
||||||
win->hooks[ButtonRelease].param);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mlx_int_param_MotionNotify(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
|
||||||
{
|
|
||||||
win->hooks[MotionNotify].hook(ev->xbutton.x,ev->xbutton.y,
|
|
||||||
win->hooks[MotionNotify].param);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mlx_int_param_Expose(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
|
||||||
{
|
|
||||||
if (!ev->xexpose.count)
|
|
||||||
win->hooks[Expose].hook(win->hooks[Expose].param);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_param_generic(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
|
||||||
{
|
|
||||||
win->hooks[ev->type].hook(win->hooks[ev->type].param);
|
|
||||||
}
|
|
||||||
|
|
||||||
int (*(mlx_int_param_event[]))() =
|
|
||||||
{
|
|
||||||
mlx_int_param_undef, /* 0 */
|
|
||||||
mlx_int_param_undef,
|
|
||||||
mlx_int_param_KeyPress,
|
|
||||||
mlx_int_param_KeyRelease, /* 3 */
|
|
||||||
mlx_int_param_ButtonPress,
|
|
||||||
mlx_int_param_ButtonRelease,
|
|
||||||
mlx_int_param_MotionNotify, /* 6 */
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_Expose, /* 12 */
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic,
|
|
||||||
mlx_int_param_generic
|
|
||||||
};
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_int_set_win_event_mask.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Thu Aug 3 11:49:06 2000 Charlie Root
|
|
||||||
** Last update Fri Feb 23 17:07:42 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_set_win_event_mask(t_xvar *xvar)
|
|
||||||
{
|
|
||||||
t_win_list *win;
|
|
||||||
int mask;
|
|
||||||
int i;
|
|
||||||
XSetWindowAttributes xwa;
|
|
||||||
|
|
||||||
win = xvar->win_list;
|
|
||||||
while (win)
|
|
||||||
{
|
|
||||||
xwa.event_mask = 0;
|
|
||||||
i = MLX_MAX_EVENT;
|
|
||||||
while (i--)
|
|
||||||
xwa.event_mask |= win->hooks[i].mask;
|
|
||||||
XChangeWindowAttributes(xvar->display, win->window, CWEventMask, &xwa);
|
|
||||||
win = win->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_int_wait_first_expose.c for minilibx in
|
|
||||||
**
|
|
||||||
** Made by olivier crouzet
|
|
||||||
** Login <ol@epita.fr>
|
|
||||||
**
|
|
||||||
** Started on Tue Oct 17 09:26:45 2000 olivier crouzet
|
|
||||||
** Last update Fri Feb 23 17:27:10 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_wait_first_expose(t_xvar *xvar,Window win)
|
|
||||||
{
|
|
||||||
XEvent ev;
|
|
||||||
|
|
||||||
XWindowEvent(xvar->display,win,ExposureMask,&ev);
|
|
||||||
XPutBackEvent(xvar->display,&ev);
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_key_hook.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Thu Aug 3 11:49:06 2000 Charlie Root
|
|
||||||
** Last update Fri Feb 23 17:10:09 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_key_hook(t_win_list *win,int (*funct)(),void *param)
|
|
||||||
{
|
|
||||||
win->hooks[KeyRelease].hook = funct;
|
|
||||||
win->hooks[KeyRelease].param = param;
|
|
||||||
win->hooks[KeyRelease].mask = KeyReleaseMask;
|
|
||||||
}
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_xpm.c for minilibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Fri Dec 8 11:07:24 2000 Charlie Root
|
|
||||||
** Last update Thu Oct 4 16:00:22 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_int_xpm_f_image(t_xvar *xvar,int *width,int *height,
|
|
||||||
int (*xpm_func)(),void *param)
|
|
||||||
{
|
|
||||||
XImage *img1;
|
|
||||||
XImage *img2;
|
|
||||||
t_img *im2;
|
|
||||||
XpmAttributes xpm_att;
|
|
||||||
|
|
||||||
xpm_att.visual = xvar->visual;
|
|
||||||
xpm_att.colormap = xvar->cmap;
|
|
||||||
xpm_att.depth = xvar->depth;
|
|
||||||
xpm_att.bitmap_format = ZPixmap;
|
|
||||||
xpm_att.valuemask = XpmDepth|XpmBitmapFormat|XpmVisual|XpmColormap;
|
|
||||||
if (xpm_func(xvar->display,param,&img1,&img2,&xpm_att))
|
|
||||||
return ((void *)0);
|
|
||||||
if (img2)
|
|
||||||
XDestroyImage(img2);
|
|
||||||
|
|
||||||
if (!(im2 = (void *)mlx_new_image(xvar,img1->width,img1->height)))
|
|
||||||
{
|
|
||||||
XDestroyImage(img1);
|
|
||||||
return ((void *)0);
|
|
||||||
}
|
|
||||||
*width = img1->width;
|
|
||||||
*height = img1->height;
|
|
||||||
if (mlx_int_egal_img(im2->image,img1))
|
|
||||||
{
|
|
||||||
bcopy(img1->data,im2->data,img1->height*img1->bytes_per_line);
|
|
||||||
XDestroyImage(img1);
|
|
||||||
return (im2);
|
|
||||||
}
|
|
||||||
if (im2->type==MLX_TYPE_SHM_PIXMAP)
|
|
||||||
{
|
|
||||||
XFreePixmap(xvar->display,im2->pix);
|
|
||||||
im2->pix = XCreatePixmap(xvar->display,xvar->root,
|
|
||||||
*width,*height,xvar->depth);
|
|
||||||
}
|
|
||||||
if (im2->type>MLX_TYPE_XIMAGE)
|
|
||||||
{
|
|
||||||
XShmDetach(xvar->display,&(im2->shm));
|
|
||||||
shmdt(im2->data);
|
|
||||||
}
|
|
||||||
XDestroyImage(im2->image);
|
|
||||||
im2->image = img1;
|
|
||||||
im2->data = img1->data;
|
|
||||||
im2->type = MLX_TYPE_XIMAGE;
|
|
||||||
im2->size_line = img1->bytes_per_line;
|
|
||||||
im2->bpp = img1->bits_per_pixel;
|
|
||||||
return (im2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_egal_img(XImage *img1,XImage *img2)
|
|
||||||
{
|
|
||||||
if (img1->width!=img2->width || img1->height!=img2->height ||
|
|
||||||
img1->xoffset!=img2->xoffset || img1->format!=img2->format ||
|
|
||||||
img1->byte_order!=img2->byte_order ||
|
|
||||||
img1->bitmap_unit!=img2->bitmap_unit ||
|
|
||||||
img1->bitmap_bit_order!=img2->bitmap_bit_order ||
|
|
||||||
img1->bitmap_pad!=img2->bitmap_pad || img1->depth!=img2->depth ||
|
|
||||||
img1->bytes_per_line!=img2->bytes_per_line ||
|
|
||||||
img1->bits_per_pixel!=img2->bits_per_pixel ||
|
|
||||||
img1->red_mask!=img2->red_mask || img1->green_mask!=img2->green_mask ||
|
|
||||||
img1->blue_mask!=img2->blue_mask )
|
|
||||||
return (0);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_xpm_file_to_image(t_xvar *xvar,char *filename,
|
|
||||||
int *width,int *height)
|
|
||||||
{
|
|
||||||
return (mlx_int_xpm_f_image(xvar,width,height,XpmReadFileToImage,filename));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_xpm_to_image(t_xvar *xvar,char **data,int *width,int *height)
|
|
||||||
{
|
|
||||||
return (mlx_int_xpm_f_image(xvar,width,height,XpmCreateImageFromData,(void *)data));
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_loop.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Wed Aug 2 18:58:11 2000 Charlie Root
|
|
||||||
** Last update Fri Sep 30 14:47:41 2005 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
extern int (*(mlx_int_param_event[]))();
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_loop(t_xvar *xvar)
|
|
||||||
{
|
|
||||||
XEvent ev;
|
|
||||||
t_win_list *win;
|
|
||||||
|
|
||||||
mlx_int_set_win_event_mask(xvar);
|
|
||||||
xvar->do_flush = 0;
|
|
||||||
while (42)
|
|
||||||
{
|
|
||||||
while (!xvar->loop_hook || XPending(xvar->display))
|
|
||||||
{
|
|
||||||
XNextEvent(xvar->display,&ev);
|
|
||||||
win = xvar->win_list;
|
|
||||||
while (win && (win->window!=ev.xany.window))
|
|
||||||
win = win->next;
|
|
||||||
if (win && ev.type < MLX_MAX_EVENT)
|
|
||||||
{
|
|
||||||
if (ev.type == ClientMessage && (Atom)ev.xclient.data.l[0] == xvar->wm_delete_window)
|
|
||||||
XDestroyWindow(xvar->display, win->window);
|
|
||||||
if (win->hooks[ev.type].hook)
|
|
||||||
mlx_int_param_event[ev.type](xvar, &ev, win);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
XSync(xvar->display, False);
|
|
||||||
xvar->loop_hook(xvar->loop_param);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_loop_hook.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Thu Aug 3 11:49:06 2000 Charlie Root
|
|
||||||
** Last update Fri Feb 23 17:11:39 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_loop_hook(t_xvar *xvar,int (*funct)(),void *param)
|
|
||||||
{
|
|
||||||
xvar->loop_hook = funct;
|
|
||||||
xvar->loop_param = param;
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
#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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Queries the position of the mouse pointer relative to the origin of the
|
|
||||||
** specified window and saves it to the provided location.
|
|
||||||
**
|
|
||||||
** If the pointer is not on the same screen as the specified window, both
|
|
||||||
** win_x_return and win_y_return are set to zero and the function returns 0.
|
|
||||||
*/
|
|
||||||
|
|
||||||
int mlx_mouse_get_pos(t_xvar *xvar, t_win_list *win, \
|
|
||||||
int *win_x_return, int *win_y_return)
|
|
||||||
{
|
|
||||||
Window root_return;
|
|
||||||
Window child_return;
|
|
||||||
int root_x_return;
|
|
||||||
int root_y_return;
|
|
||||||
unsigned mask_return;
|
|
||||||
|
|
||||||
return (XQueryPointer(xvar->display, win->window, \
|
|
||||||
&root_return, &child_return, &root_x_return, &root_y_return, \
|
|
||||||
win_x_return, win_y_return, &mask_return));
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_mouse_hook.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Thu Aug 3 11:49:06 2000 Charlie Root
|
|
||||||
** Last update Fri Feb 23 17:11:05 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_mouse_hook(t_win_list *win,int (*funct)(),void *param)
|
|
||||||
{
|
|
||||||
win->hooks[ButtonPress].hook = funct;
|
|
||||||
win->hooks[ButtonPress].param = param;
|
|
||||||
win->hooks[ButtonPress].mask = ButtonPressMask;
|
|
||||||
}
|
|
||||||
@@ -1,155 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_new_image.c for MiniLibX in raytraceur
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Mon Aug 14 15:29:14 2000 Charlie Root
|
|
||||||
** Last update Wed May 25 16:46:31 2011 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
** To handle X errors
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define X_ShmAttach 1
|
|
||||||
|
|
||||||
int mlx_X_error;
|
|
||||||
|
|
||||||
int shm_att_pb(Display *d,XErrorEvent *ev)
|
|
||||||
{
|
|
||||||
if (ev->request_code==146 && ev->minor_code==X_ShmAttach)
|
|
||||||
write(2,WARN_SHM_ATTACH,strlen(WARN_SHM_ATTACH));
|
|
||||||
mlx_X_error = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Data malloc : width+32 ( bitmap_pad=32 ), *4 = *32 / 8bit
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_int_new_xshm_image(t_xvar *xvar,int width,int height,int format)
|
|
||||||
{
|
|
||||||
t_img *img;
|
|
||||||
int (*save_handler)();
|
|
||||||
|
|
||||||
if (!(img = malloc(sizeof(*img))))
|
|
||||||
return ((void *)0);
|
|
||||||
bzero(img,sizeof(*img));
|
|
||||||
img->data = 0;
|
|
||||||
img->image = XShmCreateImage(xvar->display,xvar->visual,xvar->depth,
|
|
||||||
format,img->data,&(img->shm),width,height);
|
|
||||||
if (!img->image)
|
|
||||||
{
|
|
||||||
free(img);
|
|
||||||
return ((void *)0);
|
|
||||||
}
|
|
||||||
img->width = width;
|
|
||||||
img->height = height;
|
|
||||||
img->size_line = img->image->bytes_per_line;
|
|
||||||
img->bpp = img->image->bits_per_pixel;
|
|
||||||
img->format = format;
|
|
||||||
img->shm.shmid = shmget(IPC_PRIVATE,(width+32)*height*4,IPC_CREAT|0777);
|
|
||||||
if (img->shm.shmid==-1)
|
|
||||||
{
|
|
||||||
XDestroyImage(img->image);
|
|
||||||
free(img);
|
|
||||||
return ((void *)0);
|
|
||||||
}
|
|
||||||
img->data = img->shm.shmaddr = img->image->data = shmat(img->shm.shmid,0,0);
|
|
||||||
if (img->data==(void *)-1)
|
|
||||||
{
|
|
||||||
shmctl(img->shm.shmid,IPC_RMID,0);
|
|
||||||
XDestroyImage(img->image);
|
|
||||||
free(img);
|
|
||||||
return ((void *)0);
|
|
||||||
}
|
|
||||||
img->shm.readOnly = False;
|
|
||||||
mlx_X_error = 0;
|
|
||||||
save_handler = XSetErrorHandler(shm_att_pb);
|
|
||||||
if (!XShmAttach(xvar->display,&(img->shm)) ||
|
|
||||||
0&XSync(xvar->display,False) || mlx_X_error)
|
|
||||||
{
|
|
||||||
XSetErrorHandler(save_handler);
|
|
||||||
shmdt(img->data);
|
|
||||||
shmctl(img->shm.shmid,IPC_RMID,0);
|
|
||||||
XDestroyImage(img->image);
|
|
||||||
free(img);
|
|
||||||
return ((void *)0);
|
|
||||||
}
|
|
||||||
XSetErrorHandler(save_handler);
|
|
||||||
shmctl(img->shm.shmid,IPC_RMID,0);
|
|
||||||
if (xvar->pshm_format==format)
|
|
||||||
{
|
|
||||||
img->pix = XShmCreatePixmap(xvar->display,xvar->root,img->shm.shmaddr,
|
|
||||||
&(img->shm),width,height,xvar->depth);
|
|
||||||
img->type = MLX_TYPE_SHM_PIXMAP;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
img->pix = XCreatePixmap(xvar->display,xvar->root,
|
|
||||||
width,height,xvar->depth);
|
|
||||||
img->type = MLX_TYPE_SHM;
|
|
||||||
}
|
|
||||||
if (xvar->do_flush)
|
|
||||||
XFlush(xvar->display);
|
|
||||||
return (img);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_int_new_image(t_xvar *xvar,int width, int height,int format)
|
|
||||||
{
|
|
||||||
t_img *img;
|
|
||||||
|
|
||||||
if (!(img = malloc(sizeof(*img))) ||
|
|
||||||
!(img->data = malloc((width+32)*height*4)))
|
|
||||||
return ((void *)0);
|
|
||||||
bzero(img->data,(width+32)*height*4);
|
|
||||||
img->image = XCreateImage(xvar->display,xvar->visual,xvar->depth,format,0,
|
|
||||||
img->data,width,height,32,0);
|
|
||||||
if (!img->image)
|
|
||||||
{
|
|
||||||
free(img->data);
|
|
||||||
free(img);
|
|
||||||
return ((void *)0);
|
|
||||||
}
|
|
||||||
img->gc = 0;
|
|
||||||
img->size_line = img->image->bytes_per_line;
|
|
||||||
img->bpp = img->image->bits_per_pixel;
|
|
||||||
img->width = width;
|
|
||||||
img->height = height;
|
|
||||||
img->pix = XCreatePixmap(xvar->display,xvar->root,width,height,xvar->depth);
|
|
||||||
img->format = format;
|
|
||||||
img->type = MLX_TYPE_XIMAGE;
|
|
||||||
if (xvar->do_flush)
|
|
||||||
XFlush(xvar->display);
|
|
||||||
return (img);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_new_image(t_xvar *xvar,int width, int height)
|
|
||||||
{
|
|
||||||
t_img *img;
|
|
||||||
|
|
||||||
if (xvar->use_xshm)
|
|
||||||
if (img = mlx_int_new_xshm_image(xvar,width,height,ZPixmap))
|
|
||||||
return (img);
|
|
||||||
return (mlx_int_new_image(xvar,width,height,ZPixmap));
|
|
||||||
}
|
|
||||||
|
|
||||||
void *mlx_new_image2(t_xvar *xvar,int width, int height)
|
|
||||||
{
|
|
||||||
t_img *img;
|
|
||||||
|
|
||||||
if (xvar->use_xshm)
|
|
||||||
if (img = mlx_int_new_xshm_image(xvar,width,height,XYPixmap))
|
|
||||||
return (img);
|
|
||||||
return (mlx_int_new_image(xvar,width,height,XYPixmap));
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_new_window.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Mon Jul 31 17:29:02 2000 Charlie Root
|
|
||||||
** Last update Thu Oct 4 15:44:43 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
** We do not use White/BlackPixel macro, TrueColor Visual make sure
|
|
||||||
** 0 is black & -1 is white
|
|
||||||
**
|
|
||||||
** With mlx_int_wait_first_expose, no flush is needed.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_new_window(t_xvar *xvar,int size_x,int size_y,char *title)
|
|
||||||
{
|
|
||||||
t_win_list *new_win;
|
|
||||||
XSetWindowAttributes xswa;
|
|
||||||
XGCValues xgcv;
|
|
||||||
|
|
||||||
xswa.background_pixel = 0;
|
|
||||||
xswa.border_pixel = -1;
|
|
||||||
xswa.colormap = xvar->cmap;
|
|
||||||
/*
|
|
||||||
xswa.event_mask = ButtonPressMask | ButtonReleaseMask | ExposureMask |
|
|
||||||
KeyPressMask | KeyReleaseMask | StructureNotifyMask;
|
|
||||||
*/
|
|
||||||
/* xswa.event_mask = ExposureMask; */
|
|
||||||
xswa.event_mask = 0xFFFFFF; /* all events */
|
|
||||||
if (!(new_win = malloc(sizeof(*new_win))))
|
|
||||||
return ((void *)0);
|
|
||||||
new_win->window = XCreateWindow(xvar->display,xvar->root,0,0,size_x,size_y,
|
|
||||||
0,CopyFromParent,InputOutput,xvar->visual,
|
|
||||||
CWEventMask|CWBackPixel|CWBorderPixel|
|
|
||||||
CWColormap,&xswa);
|
|
||||||
mlx_int_anti_resize_win(xvar,new_win->window,size_x,size_y);
|
|
||||||
XStoreName(xvar->display,new_win->window,title);
|
|
||||||
XSetWMProtocols(xvar->display, new_win->window, &(xvar->wm_delete_window), 1);
|
|
||||||
xgcv.foreground = -1;
|
|
||||||
xgcv.function = GXcopy;
|
|
||||||
xgcv.plane_mask = AllPlanes;
|
|
||||||
new_win->gc = XCreateGC(xvar->display,new_win->window,
|
|
||||||
GCFunction|GCPlaneMask|GCForeground,&xgcv);
|
|
||||||
new_win->next = xvar->win_list;
|
|
||||||
xvar->win_list = new_win;
|
|
||||||
/*
|
|
||||||
new_win->mouse_hook = mlx_int_do_nothing;
|
|
||||||
new_win->key_hook = mlx_int_do_nothing;
|
|
||||||
new_win->expose_hook = mlx_int_do_nothing;
|
|
||||||
*/
|
|
||||||
bzero(&(new_win->hooks), sizeof(new_win->hooks));
|
|
||||||
XMapRaised(xvar->display,new_win->window);
|
|
||||||
mlx_int_wait_first_expose(xvar,new_win->window);
|
|
||||||
return (new_win);
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_pixel_put.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Mon Jul 31 19:01:33 2000 Charlie Root
|
|
||||||
** Last update Tue Sep 25 17:09:49 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_pixel_put(t_xvar *xvar,t_win_list *win,
|
|
||||||
int x,int y,int color)
|
|
||||||
{
|
|
||||||
XGCValues xgcv;
|
|
||||||
|
|
||||||
xgcv.foreground = mlx_int_get_good_color(xvar,color);
|
|
||||||
XChangeGC(xvar->display,win->gc,GCForeground,&xgcv);
|
|
||||||
XDrawPoint(xvar->display,win->window,win->gc,x,y);
|
|
||||||
if (xvar->do_flush)
|
|
||||||
XFlush(xvar->display);
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_put_image_to_window.c for MiniLibX in raytraceur
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Mon Aug 14 15:55:49 2000 Charlie Root
|
|
||||||
** Last update Sun Oct 2 09:53:00 2005 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_put_image_to_window(t_xvar *xvar,t_win_list *win,t_img *img,
|
|
||||||
int x,int y)
|
|
||||||
{
|
|
||||||
GC gc;
|
|
||||||
|
|
||||||
gc = win->gc;
|
|
||||||
if (img->gc)
|
|
||||||
{
|
|
||||||
gc = img->gc;
|
|
||||||
XSetClipOrigin(xvar->display, gc, x, y);
|
|
||||||
}
|
|
||||||
if (img->type==MLX_TYPE_SHM)
|
|
||||||
XShmPutImage(xvar->display,img->pix, win->gc, img->image,0,0,0,0,
|
|
||||||
img->width,img->height,False);
|
|
||||||
if (img->type==MLX_TYPE_XIMAGE)
|
|
||||||
XPutImage(xvar->display,img->pix, win->gc, img->image,0,0,0,0,
|
|
||||||
img->width,img->height);
|
|
||||||
XCopyArea(xvar->display,img->pix,win->window, gc,
|
|
||||||
0,0,img->width,img->height,x,y);
|
|
||||||
if (xvar->do_flush)
|
|
||||||
XFlush(xvar->display);
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
int mlx_get_screen_size(void *mlx_ptr, int *sizex, int *sizey)
|
|
||||||
{
|
|
||||||
XWindowAttributes xwAttr;
|
|
||||||
Status ret;
|
|
||||||
t_xvar *xvar;
|
|
||||||
|
|
||||||
xvar = mlx_ptr;
|
|
||||||
ret = XGetWindowAttributes(xvar->display, xvar->root, &xwAttr);
|
|
||||||
(*sizex) = xwAttr.width;
|
|
||||||
(*sizey) = xwAttr.height;
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* mlx_set_font.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: amalliar <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2020/09/30 13:30:47 by amalliar #+# #+# */
|
|
||||||
/* Updated: 2020/09/30 17:08:36 by amalliar ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Allows to specify the font that will be used by mlx_string_put.
|
|
||||||
**
|
|
||||||
** Note: only fixed-width bitmap fonts are supported by Xlib, refer to xfontsel
|
|
||||||
** utility to get valid font names for this function.
|
|
||||||
*/
|
|
||||||
|
|
||||||
void mlx_set_font(t_xvar *xvar, t_win_list *win, char *name)
|
|
||||||
{
|
|
||||||
static Font font = 0;
|
|
||||||
|
|
||||||
if (font)
|
|
||||||
XUnloadFont(xvar->display, font);
|
|
||||||
font = XLoadFont(xvar->display, name);
|
|
||||||
XSetFont(xvar->display, win->gc, font);
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
/*
|
|
||||||
** mlx_string_put.c for MiniLibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Mon Jul 31 19:01:33 2000 Charlie Root
|
|
||||||
** Last update Tue Sep 25 17:11:47 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_string_put(t_xvar *xvar,t_win_list *win,
|
|
||||||
int x,int y,int color,char *string)
|
|
||||||
{
|
|
||||||
XGCValues xgcv;
|
|
||||||
|
|
||||||
xgcv.foreground = mlx_int_get_good_color(xvar,color);
|
|
||||||
XChangeGC(xvar->display,win->gc,GCForeground,&xgcv);
|
|
||||||
XDrawString(xvar->display,win->window,win->gc,x,y,string,strlen(string));
|
|
||||||
if (xvar->do_flush)
|
|
||||||
XFlush(xvar->display);
|
|
||||||
}
|
|
||||||
@@ -1,342 +0,0 @@
|
|||||||
/*
|
|
||||||
** xpm-read.c for MinilibX in
|
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Tue Dec 11 15:25:27 2001 olivier crouzet
|
|
||||||
** Last update Sat Oct 1 14:56:13 2005 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
extern struct s_col_name mlx_col_name[];
|
|
||||||
|
|
||||||
|
|
||||||
#define RETURN { if (colors) free(colors); if (tab) free(tab); \
|
|
||||||
if (colors_direct) free(colors_direct); \
|
|
||||||
if (img) {XDestroyImage(img->image); \
|
|
||||||
XFreePixmap(xvar->display,img->pix);free(img);} \
|
|
||||||
return ((void *)0);}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char *mlx_int_get_line(char *ptr,int *pos,int size)
|
|
||||||
{
|
|
||||||
int pos2;
|
|
||||||
int pos3;
|
|
||||||
int pos4;
|
|
||||||
|
|
||||||
if ((pos2 = mlx_int_str_str(ptr+*pos,"\"",size-*pos))==-1)
|
|
||||||
return ((char *)0);
|
|
||||||
if ((pos3 = mlx_int_str_str(ptr+*pos+pos2+1,"\"",size-*pos-pos2-1))==-1)
|
|
||||||
return ((char *)0);
|
|
||||||
*(ptr+*pos+pos2) = 0;
|
|
||||||
*(ptr+*pos+pos2+1+pos3) = 0;
|
|
||||||
pos4 = *pos+pos2+1;
|
|
||||||
*pos += pos2+pos3+2;
|
|
||||||
return (ptr+pos4);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
unsigned int strlcpy_is_not_posix(char *dest, char *src, unsigned int size)
|
|
||||||
{
|
|
||||||
unsigned count;
|
|
||||||
unsigned i;
|
|
||||||
|
|
||||||
count = 0;
|
|
||||||
while (src[count] != '\0')
|
|
||||||
++count;
|
|
||||||
i = 0;
|
|
||||||
while (src[i] != '\0' && i < (size - 1))
|
|
||||||
{
|
|
||||||
dest[i] = src[i];
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
dest[i] = '\0';
|
|
||||||
return (count);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *mlx_int_static_line(char **xpm_data,int *pos,int size)
|
|
||||||
{
|
|
||||||
static char *copy = 0;
|
|
||||||
static int len = 0;
|
|
||||||
int len2;
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
str = xpm_data[(*pos)++];
|
|
||||||
if ((len2 = strlen(str))>len)
|
|
||||||
{
|
|
||||||
if (copy)
|
|
||||||
free(copy);
|
|
||||||
if (!(copy = malloc(len2+1)))
|
|
||||||
return ((char *)0);
|
|
||||||
len = len2;
|
|
||||||
}
|
|
||||||
strlcpy_is_not_posix(copy, str, len2);
|
|
||||||
|
|
||||||
return (copy);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_get_col_name(char *str,int size)
|
|
||||||
{
|
|
||||||
int result;
|
|
||||||
|
|
||||||
result = 0;
|
|
||||||
while (size--)
|
|
||||||
result = (result<<8)+*(str++);
|
|
||||||
|
|
||||||
return (result);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mlx_int_get_text_rgb(char *name, char *end)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char buff[64];
|
|
||||||
|
|
||||||
if (*name == '#')
|
|
||||||
return (strtol(name+1,0,16));
|
|
||||||
if (end)
|
|
||||||
{
|
|
||||||
snprintf(buff, 64, "%s %s", name, end);
|
|
||||||
name = buff;
|
|
||||||
}
|
|
||||||
i = 0;
|
|
||||||
while (mlx_col_name[i].name)
|
|
||||||
{
|
|
||||||
if (!strcasecmp(mlx_col_name[i].name, name))
|
|
||||||
return (mlx_col_name[i].color);
|
|
||||||
i ++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_xpm_set_pixel(t_img *img, char *data, int opp, int col, int x)
|
|
||||||
{
|
|
||||||
int dec;
|
|
||||||
unsigned int ucol;
|
|
||||||
|
|
||||||
if (opp == 4 && img->image->byte_order)
|
|
||||||
ucol = col | 0x000000FF;
|
|
||||||
else if (opp == 4)
|
|
||||||
ucol = col | 0xFF000000;
|
|
||||||
else
|
|
||||||
ucol = col;
|
|
||||||
dec = opp;
|
|
||||||
while (dec--)
|
|
||||||
{
|
|
||||||
if (img->image->byte_order)
|
|
||||||
*(data+x*opp+dec) = ucol&0xFF;
|
|
||||||
else
|
|
||||||
*(data+x*opp+opp-dec-1) = ucol&0xFF;
|
|
||||||
ucol >>= 8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_int_parse_xpm(t_xvar *xvar,void *info,int info_size,char *(*f)())
|
|
||||||
{
|
|
||||||
int pos;
|
|
||||||
char *line;
|
|
||||||
char **tab;
|
|
||||||
char *data;
|
|
||||||
char *clip_data;
|
|
||||||
int nc;
|
|
||||||
int opp;
|
|
||||||
int cpp;
|
|
||||||
int col;
|
|
||||||
int rgb_col;
|
|
||||||
int col_name;
|
|
||||||
int method;
|
|
||||||
int x;
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
t_img *img;
|
|
||||||
t_xpm_col *colors;
|
|
||||||
int *colors_direct;
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
XImage *clip_img;
|
|
||||||
XGCValues xgcv;
|
|
||||||
Pixmap clip_pix;
|
|
||||||
|
|
||||||
colors = 0;
|
|
||||||
colors_direct = 0;
|
|
||||||
img = 0;
|
|
||||||
tab = 0;
|
|
||||||
pos = 0;
|
|
||||||
if (!(line = f(info,&pos,info_size)) ||
|
|
||||||
!(tab = mlx_int_str_to_wordtab(line)) || !(width = atoi(tab[0])) ||
|
|
||||||
!(height = atoi(tab[1])) || !(nc = atoi(tab[2])) ||
|
|
||||||
!(cpp = atoi(tab[3])) )
|
|
||||||
RETURN;
|
|
||||||
free(tab);
|
|
||||||
tab = 0;
|
|
||||||
|
|
||||||
method = 0;
|
|
||||||
if (cpp<=2)
|
|
||||||
{
|
|
||||||
method = 1;
|
|
||||||
if (!(colors_direct = malloc((cpp==2?65536:256)*sizeof(int))))
|
|
||||||
RETURN;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (!(colors = malloc(nc*sizeof(*colors))))
|
|
||||||
RETURN;
|
|
||||||
|
|
||||||
clip_data = 0;
|
|
||||||
|
|
||||||
i = nc;
|
|
||||||
while (i--)
|
|
||||||
{
|
|
||||||
if (!(line = f(info,&pos,info_size)) ||
|
|
||||||
!(tab = mlx_int_str_to_wordtab(line+cpp)) )
|
|
||||||
RETURN;
|
|
||||||
j = 0;
|
|
||||||
while (tab[j] && strcmp(tab[j++],"c"));
|
|
||||||
|
|
||||||
if (!tab[j])
|
|
||||||
RETURN;
|
|
||||||
|
|
||||||
if ((rgb_col = mlx_int_get_text_rgb(tab[j], tab[j+1]))==-1)
|
|
||||||
{
|
|
||||||
if (!(clip_data = malloc(4*width*height)) || /* ok, nice size .. */
|
|
||||||
!(clip_img = XCreateImage(xvar->display, xvar->visual,
|
|
||||||
1, XYPixmap, 0, clip_data,
|
|
||||||
width, height, 8, (width+7)/8)) )
|
|
||||||
RETURN;
|
|
||||||
memset(clip_data, 0xFF, 4*width*height);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (method)
|
|
||||||
colors_direct[mlx_int_get_col_name(line,cpp)] =
|
|
||||||
rgb_col>=0?mlx_get_color_value(xvar, rgb_col):rgb_col;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
colors[i].name = mlx_int_get_col_name(line,cpp);
|
|
||||||
colors[i].col = rgb_col>=0?mlx_get_color_value(xvar,rgb_col):rgb_col;
|
|
||||||
}
|
|
||||||
free(tab);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(img = mlx_new_image(xvar,width,height)))
|
|
||||||
RETURN;
|
|
||||||
opp = img->bpp/8;
|
|
||||||
|
|
||||||
|
|
||||||
i = height;
|
|
||||||
data = img->data;
|
|
||||||
while (i--)
|
|
||||||
{
|
|
||||||
if (!(line = f(info,&pos,info_size)))
|
|
||||||
RETURN;
|
|
||||||
x = 0;
|
|
||||||
while (x<width)
|
|
||||||
{
|
|
||||||
col = 0;
|
|
||||||
col_name = mlx_int_get_col_name(line+cpp*x,cpp);
|
|
||||||
if (method)
|
|
||||||
col = colors_direct[col_name];
|
|
||||||
else
|
|
||||||
{
|
|
||||||
j = nc;
|
|
||||||
while (j--)
|
|
||||||
if (colors[j].name==col_name)
|
|
||||||
{
|
|
||||||
col = colors[j].col;
|
|
||||||
j = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (col==-1)
|
|
||||||
XPutPixel(clip_img, x, height-1-i, 0);
|
|
||||||
else
|
|
||||||
mlx_int_xpm_set_pixel(img, data, opp, col, x);
|
|
||||||
x ++;
|
|
||||||
}
|
|
||||||
data += img->size_line;
|
|
||||||
}
|
|
||||||
if (clip_data)
|
|
||||||
{
|
|
||||||
if (!(clip_pix = XCreatePixmap(xvar->display, xvar->root,
|
|
||||||
width, height, 1)) )
|
|
||||||
RETURN;
|
|
||||||
img->gc = XCreateGC(xvar->display, clip_pix, 0, &xgcv);
|
|
||||||
XPutImage(xvar->display, clip_pix, img->gc, clip_img,
|
|
||||||
0, 0, 0, 0, width, height);
|
|
||||||
XFreeGC(xvar->display, img->gc);
|
|
||||||
xgcv.clip_mask = clip_pix;
|
|
||||||
xgcv.function = GXcopy;
|
|
||||||
xgcv.plane_mask = AllPlanes;
|
|
||||||
img->gc = XCreateGC(xvar->display, xvar->root, GCClipMask|GCFunction|
|
|
||||||
GCPlaneMask, &xgcv);
|
|
||||||
XSync(xvar->display, False);
|
|
||||||
XDestroyImage(clip_img);
|
|
||||||
}
|
|
||||||
if (colors)
|
|
||||||
free(colors);
|
|
||||||
if (colors_direct)
|
|
||||||
free(colors_direct);
|
|
||||||
return (img);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_file_get_rid_comment(char *ptr, int size)
|
|
||||||
{
|
|
||||||
int com_begin;
|
|
||||||
int com_end;
|
|
||||||
|
|
||||||
while ((com_begin = mlx_int_str_str_cote(ptr,"/*",size))!=-1)
|
|
||||||
{
|
|
||||||
com_end = mlx_int_str_str(ptr+com_begin+2,"*/",size-com_begin-2);
|
|
||||||
memset(ptr+com_begin,' ',com_end+4);
|
|
||||||
}
|
|
||||||
while ((com_begin = mlx_int_str_str_cote(ptr,"//",size))!=-1)
|
|
||||||
{
|
|
||||||
com_end = mlx_int_str_str(ptr+com_begin+2,"\n",size-com_begin-2);
|
|
||||||
memset(ptr+com_begin,' ',com_end+3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx_xpm_file_to_image(t_xvar *xvar,char *file,int *width,int *height)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
int size;
|
|
||||||
char *ptr;
|
|
||||||
t_img *img;
|
|
||||||
|
|
||||||
fd = -1;
|
|
||||||
if ((fd = open(file,O_RDONLY))==-1 || (size = lseek(fd,0,SEEK_END))==-1 ||
|
|
||||||
(ptr = mmap(0,size,PROT_WRITE|PROT_READ,MAP_PRIVATE,fd,0))==
|
|
||||||
(void *)MAP_FAILED)
|
|
||||||
{
|
|
||||||
if (fd>=0)
|
|
||||||
close(fd);
|
|
||||||
return ((void *)0);
|
|
||||||
}
|
|
||||||
mlx_int_file_get_rid_comment(ptr, size);
|
|
||||||
if (img = mlx_int_parse_xpm(xvar,ptr,size,mlx_int_get_line))
|
|
||||||
{
|
|
||||||
*width = img->width;
|
|
||||||
*height = img->height;
|
|
||||||
}
|
|
||||||
munmap(ptr,size);
|
|
||||||
close(fd);
|
|
||||||
return (img);
|
|
||||||
}
|
|
||||||
|
|
||||||
void *mlx_xpm_to_image(t_xvar *xvar,char **xpm_data,int *width,int *height)
|
|
||||||
{
|
|
||||||
t_img *img;
|
|
||||||
|
|
||||||
if (img = mlx_int_parse_xpm(xvar,xpm_data,0,mlx_int_static_line))
|
|
||||||
{
|
|
||||||
*width = img->width;
|
|
||||||
*height = img->height;
|
|
||||||
}
|
|
||||||
return (img);
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
#!/usr/bin/perl
|
|
||||||
#
|
|
||||||
## rgb2c.pl for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
|
|
||||||
##
|
|
||||||
## Made by Olivier Crouzet
|
|
||||||
## Login <ol@epitech.net>
|
|
||||||
##
|
|
||||||
## Started on Tue Oct 5 16:33:46 2004 Olivier Crouzet
|
|
||||||
## Last update Tue Oct 5 16:36:11 2004 Olivier Crouzet
|
|
||||||
##
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Generate a .c file with encoded colors, from the XFree86 rgb.txt file.
|
|
||||||
#
|
|
||||||
|
|
||||||
open(RGB, "/usr/X11/lib/X11/rgb.txt");
|
|
||||||
|
|
||||||
|
|
||||||
printf("/*\n** This is a generated file with rgb2c.pl and rgb.txt from\n");
|
|
||||||
printf("** the XFree86 distribution.\n*/\n\n");
|
|
||||||
printf("struct s_col_name mlx_col_name[] =\n{\n");
|
|
||||||
|
|
||||||
while (<RGB>)
|
|
||||||
{
|
|
||||||
@tab = split;
|
|
||||||
if ($tab[0] ne "!")
|
|
||||||
{
|
|
||||||
$color = $tab[3];
|
|
||||||
if ("$tab[4]" ne "")
|
|
||||||
{
|
|
||||||
$color = "$tab[3] $tab[4]";
|
|
||||||
}
|
|
||||||
printf(" { \"%s\" , 0x%x },\n", $color, $tab[0]*65536+$tab[1]*256+$tab[2]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf(" { 0, 0 }\n};\n");
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
INC=/usr/include
|
|
||||||
HT=Linux
|
|
||||||
DOCP=do_cp
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
INCLIB=$(INC)/../lib
|
|
||||||
|
|
||||||
CC=gcc
|
|
||||||
|
|
||||||
CFLAGS= -I$(INC) -O3 -I..
|
|
||||||
|
|
||||||
NAME= mlx-test
|
|
||||||
SRC = main.c
|
|
||||||
OBJ = $(SRC:.c=.o)
|
|
||||||
|
|
||||||
all :$(NAME)
|
|
||||||
|
|
||||||
$(NAME) :$(OBJ)
|
|
||||||
$(CC) -o $(NAME) $(OBJ) -L.. -lmlx -L$(INCLIB) -lXext -lX11 -lm -lbsd
|
|
||||||
|
|
||||||
clean :
|
|
||||||
rm -f $(NAME) $(OBJ) *~ core *.core
|
|
||||||
|
|
||||||
|
|
||||||
re : clean all
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
INC=%%%%
|
|
||||||
|
|
||||||
INCLIB=$(INC)/../lib
|
|
||||||
|
|
||||||
CC=gcc
|
|
||||||
|
|
||||||
CFLAGS= -I$(INC) -O3 -I..
|
|
||||||
|
|
||||||
NAME= mlx-test
|
|
||||||
SRC = main.c
|
|
||||||
OBJ = $(SRC:.c=.o)
|
|
||||||
|
|
||||||
all :$(NAME)
|
|
||||||
|
|
||||||
$(NAME) :$(OBJ)
|
|
||||||
$(CC) -o $(NAME) $(OBJ) -L.. -lmlx -L$(INCLIB) -lXext -lX11 -lm -lbsd
|
|
||||||
|
|
||||||
clean :
|
|
||||||
rm -f $(NAME) $(OBJ) *~ core *.core
|
|
||||||
|
|
||||||
|
|
||||||
re : clean all
|
|
||||||
@@ -1,287 +0,0 @@
|
|||||||
|
|
||||||
#include "mlx.h"
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
#define WIN1_SX 242
|
|
||||||
#define WIN1_SY 242
|
|
||||||
#define IM1_SX 42
|
|
||||||
#define IM1_SY 42
|
|
||||||
#define IM3_SX 242
|
|
||||||
#define IM3_SY 242
|
|
||||||
|
|
||||||
void *mlx;
|
|
||||||
void *win1;
|
|
||||||
void *win2;
|
|
||||||
void *win3;
|
|
||||||
void *im1;
|
|
||||||
void *im2;
|
|
||||||
void *im3;
|
|
||||||
void *im4;
|
|
||||||
int bpp1;
|
|
||||||
int bpp2;
|
|
||||||
int bpp3;
|
|
||||||
int bpp4;
|
|
||||||
int sl1;
|
|
||||||
int sl2;
|
|
||||||
int sl3;
|
|
||||||
int sl4;
|
|
||||||
int endian1;
|
|
||||||
int endian2;
|
|
||||||
int endian3;
|
|
||||||
int endian4;
|
|
||||||
char *data1;
|
|
||||||
char *data2;
|
|
||||||
char *data3;
|
|
||||||
char *data4;
|
|
||||||
int xpm1_x;
|
|
||||||
int xpm1_y;
|
|
||||||
|
|
||||||
int local_endian;
|
|
||||||
|
|
||||||
int color_map_1(void *win,int w,int h);
|
|
||||||
int color_map_2(unsigned char *data,int bpp,int sl,int w,int h,int endian, int type);
|
|
||||||
|
|
||||||
int expose_win1(void *p)
|
|
||||||
{
|
|
||||||
mlx_put_image_to_window(mlx,win1,im3,0,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int expose_win2(void *p)
|
|
||||||
{
|
|
||||||
mlx_put_image_to_window(mlx,win2,im4,0,0);
|
|
||||||
mlx_put_image_to_window(mlx,win2,im2,0,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int key_win1(int key,void *p)
|
|
||||||
{
|
|
||||||
printf("Key in Win1 : %d\n",key);
|
|
||||||
if (key==0xFF1B)
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int key_win2(int key,void *p)
|
|
||||||
{
|
|
||||||
printf("Key in Win2 : %d\n",key);
|
|
||||||
if (key==0xFF1B)
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int key_win3(int key,void *p)
|
|
||||||
{
|
|
||||||
printf("Key in Win3 : %d\n",key);
|
|
||||||
if (key==0xFF1B)
|
|
||||||
mlx_destroy_window(mlx,win3);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mouse_win1(int button,int x,int y, void *p)
|
|
||||||
{
|
|
||||||
printf("Mouse in Win1, button %d at %dx%d.\n",button,x,y);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mouse_win2(int button,int x,int y, void *p)
|
|
||||||
{
|
|
||||||
printf("Mouse in Win2, button %d at %dx%d.\n",button,x,y);
|
|
||||||
}
|
|
||||||
|
|
||||||
int mouse_win3(int x,int y, void *p)
|
|
||||||
{
|
|
||||||
printf("Mouse moving in Win3, at %dx%d.\n",x,y);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
int a;
|
|
||||||
|
|
||||||
printf("MinilibX Test Program\n");
|
|
||||||
a = 0x11223344;
|
|
||||||
if (((unsigned char *)&a)[0] == 0x11)
|
|
||||||
local_endian = 1;
|
|
||||||
else
|
|
||||||
local_endian = 0;
|
|
||||||
printf(" => Local Endian : %d\n",local_endian);
|
|
||||||
|
|
||||||
printf(" => Connection ...");
|
|
||||||
if (!(mlx = mlx_init()))
|
|
||||||
{
|
|
||||||
printf(" !! KO !!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
printf("OK (use_xshm %d pshm_format %d)\n",((t_xvar *)mlx)->use_xshm,((t_xvar *)mlx)->pshm_format);
|
|
||||||
|
|
||||||
printf(" => Window1 %dx%d \"Title 1\" ...",WIN1_SX,WIN1_SY);
|
|
||||||
if (!(win1 = mlx_new_window(mlx,WIN1_SX,WIN1_SY,"Title1")))
|
|
||||||
{
|
|
||||||
printf(" !! KO !!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
printf("OK\n");
|
|
||||||
|
|
||||||
printf(" => Colormap sans event ...");
|
|
||||||
color_map_1(win1,WIN1_SX,WIN1_SY);
|
|
||||||
printf("OK\n");
|
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
printf(" => Clear Window ...");
|
|
||||||
mlx_clear_window(mlx,win1);
|
|
||||||
printf("OK\n");
|
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
printf(" => Image1 ZPixmap %dx%d ...",IM1_SX,IM1_SY);
|
|
||||||
if (!(im1 = mlx_new_image(mlx,IM1_SX,IM1_SY)))
|
|
||||||
{
|
|
||||||
printf(" !! KO !!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
data1 = mlx_get_data_addr(im1,&bpp1,&sl1,&endian1);
|
|
||||||
printf("OK (bpp1: %d, sizeline1: %d endian: %d type: %d)\n",bpp1,sl1,endian1,
|
|
||||||
((t_img *)im1)->type);
|
|
||||||
|
|
||||||
printf(" => Fill Image1 ...");
|
|
||||||
color_map_2(data1,bpp1,sl1,IM1_SX,IM1_SY,endian1, 1);
|
|
||||||
printf("OK (pixmap : %d)\n",(int)((t_img *)im1)->pix);
|
|
||||||
|
|
||||||
printf(" => Put Image1 ...");
|
|
||||||
mlx_put_image_to_window(mlx,win1,im1,20,20);
|
|
||||||
printf("OK\n");
|
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
printf(" => Destroy Image1 ... ");
|
|
||||||
mlx_destroy_image(mlx, im1);
|
|
||||||
printf("OK\n");
|
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
printf(" => Image3 ZPixmap %dx%d ...",IM3_SX,IM3_SY);
|
|
||||||
if (!(im3 = mlx_new_image(mlx,IM3_SX,IM3_SY)))
|
|
||||||
{
|
|
||||||
printf(" !! KO !!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
data3 = mlx_get_data_addr(im3,&bpp3,&sl3,&endian3);
|
|
||||||
printf("OK (bpp3 %d, sizeline3 %d endian3 %d type %d)\n",bpp3,sl3,endian3,
|
|
||||||
((t_img *)im3)->type);
|
|
||||||
|
|
||||||
printf(" => Fill Image3 ...");
|
|
||||||
color_map_2(data3,bpp3,sl3,IM3_SX,IM3_SY,endian3, 1);
|
|
||||||
printf("OK (pixmap : %d)\n",(int)((t_img *)im3)->pix);
|
|
||||||
|
|
||||||
printf(" => Put Image3 ...");
|
|
||||||
mlx_put_image_to_window(mlx,win1,im3,20,20);
|
|
||||||
printf("OK\n");
|
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
printf(" => String ...");
|
|
||||||
mlx_string_put(mlx,win1,5,WIN1_SY/2,0xFF99FF,"String output");
|
|
||||||
mlx_string_put(mlx,win1,15,WIN1_SY/2+20,0x00FFFF,"MinilibX test");
|
|
||||||
printf("OK\n");
|
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
printf(" => Xpm from file ...");
|
|
||||||
if (!(im2 = mlx_xpm_file_to_image(mlx,"open.xpm",&xpm1_x,&xpm1_y)))
|
|
||||||
{
|
|
||||||
printf(" !! KO !!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
data2 = mlx_get_data_addr(im2,&bpp2,&sl2,&endian2);
|
|
||||||
printf("OK (xpm %dx%d)(img bpp2: %d, sizeline2: %d endian: %d type: %d)\n",
|
|
||||||
xpm1_x,xpm1_y,bpp2,sl2,endian2,((t_img *)im2)->type);
|
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
printf(" => Put xpm ...");
|
|
||||||
mlx_put_image_to_window(mlx,win1,im2,0,0);
|
|
||||||
mlx_put_image_to_window(mlx,win1,im2,100,100);
|
|
||||||
printf("OK\n");
|
|
||||||
sleep(2);
|
|
||||||
|
|
||||||
printf(" => 2nd window,");
|
|
||||||
win2 = mlx_new_window(mlx,WIN1_SX,WIN1_SY,"Title2");
|
|
||||||
if (!(im4 = mlx_new_image(mlx,IM3_SX, IM3_SY)))
|
|
||||||
{
|
|
||||||
printf(" !! KO !!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
data4 = mlx_get_data_addr(im4,&bpp4,&sl4,&endian4);
|
|
||||||
color_map_2(data4,bpp4,sl4,IM3_SX,IM3_SY,endian4, 2);
|
|
||||||
|
|
||||||
printf(" 3rd window, Installing hooks ...");
|
|
||||||
win3 = mlx_new_window(mlx,WIN1_SX,WIN1_SY,"Title3");
|
|
||||||
mlx_expose_hook(win1,expose_win1,0);
|
|
||||||
mlx_mouse_hook(win1,mouse_win1,0);
|
|
||||||
mlx_key_hook(win1,key_win1,0);
|
|
||||||
mlx_expose_hook(win2,expose_win2,0);
|
|
||||||
mlx_mouse_hook(win2,mouse_win2,0);
|
|
||||||
mlx_key_hook(win2,key_win2,0);
|
|
||||||
mlx_key_hook(win3,key_win3,0);
|
|
||||||
|
|
||||||
mlx_hook(win3, MotionNotify, PointerMotionMask, mouse_win3, 0);
|
|
||||||
|
|
||||||
printf("OK\nNow in Loop. Just play. Esc in 3 to destroy, 1&2 to quit.\n");
|
|
||||||
|
|
||||||
mlx_loop(mlx);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int color_map_1(void *win,int w,int h)
|
|
||||||
{
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
int color;
|
|
||||||
|
|
||||||
x = w;
|
|
||||||
while (x--)
|
|
||||||
{
|
|
||||||
y = h;
|
|
||||||
while (y--)
|
|
||||||
{
|
|
||||||
color = (x*255)/w+((((w-x)*255)/w)<<16)+(((y*255)/h)<<8);
|
|
||||||
mlx_pixel_put(mlx,win,x,y,color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int color_map_2(unsigned char *data,int bpp,int sl,int w,int h,int endian, int type)
|
|
||||||
{
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
int opp;
|
|
||||||
int dec;
|
|
||||||
int color;
|
|
||||||
int color2;
|
|
||||||
unsigned char *ptr;
|
|
||||||
|
|
||||||
opp = bpp/8;
|
|
||||||
printf("(opp : %d) ",opp);
|
|
||||||
y = h;
|
|
||||||
while (y--)
|
|
||||||
{
|
|
||||||
ptr = data+y*sl;
|
|
||||||
x = w;
|
|
||||||
while (x--)
|
|
||||||
{
|
|
||||||
if (type==2)
|
|
||||||
color = (y*255)/w+((((w-x)*255)/w)<<16)
|
|
||||||
+(((y*255)/h)<<8);
|
|
||||||
else
|
|
||||||
color = (x*255)/w+((((w-x)*255)/w)<<16)+(((y*255)/h)<<8);
|
|
||||||
color2 = mlx_get_color_value(mlx,color);
|
|
||||||
dec = opp;
|
|
||||||
while (dec--)
|
|
||||||
if (endian==local_endian)
|
|
||||||
{
|
|
||||||
if (endian)
|
|
||||||
*(ptr+x*opp+dec) = ((unsigned char *)(&color2))[4-opp+dec];
|
|
||||||
else
|
|
||||||
*(ptr+x*opp+dec) = ((unsigned char *)(&color2))[dec];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (endian)
|
|
||||||
*(ptr+x*opp+dec) = ((unsigned char *)(&color2))[opp-1-dec];
|
|
||||||
else
|
|
||||||
*(ptr+x*opp+dec) = ((unsigned char *)(&color2))[3-dec];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Binary file not shown.
@@ -1,31 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx.h"
|
|
||||||
|
|
||||||
|
|
||||||
void *mlx;
|
|
||||||
void *win1;
|
|
||||||
void *win2;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int gere_mouse(int x,int y,int button,void*toto)
|
|
||||||
{
|
|
||||||
printf("Mouse event - new win\n");
|
|
||||||
mlx_destroy_window(mlx,win1);
|
|
||||||
win1 = mlx_new_window(mlx,random()%500,random()%500,"new win");
|
|
||||||
mlx_mouse_hook(win1,gere_mouse,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
srandom(time(0));
|
|
||||||
mlx = mlx_init();
|
|
||||||
win1 = mlx_new_window(mlx,300,300,"win1");
|
|
||||||
win2 = mlx_new_window(mlx,600,600,"win2");
|
|
||||||
mlx_mouse_hook(win1,gere_mouse,0);
|
|
||||||
mlx_mouse_hook(win2,gere_mouse,0);
|
|
||||||
mlx_loop(mlx);
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,230 +0,0 @@
|
|||||||
/* XPM */
|
|
||||||
static char *open[] = {
|
|
||||||
/* width height num_colors chars_per_pixel */
|
|
||||||
" 45 55 168 2",
|
|
||||||
/* colors */
|
|
||||||
".. s None c None",
|
|
||||||
".# c #450304",
|
|
||||||
".a c #ce7e7c",
|
|
||||||
".b c #b94344",
|
|
||||||
".c c #b65254",
|
|
||||||
".d c #780204",
|
|
||||||
".e c #b04c4c",
|
|
||||||
".f c #b00204",
|
|
||||||
".g c #8a8a64",
|
|
||||||
".h c #969a24",
|
|
||||||
".i c #b6b60c",
|
|
||||||
".j c #cac614",
|
|
||||||
".k c #cece34",
|
|
||||||
".l c #cace54",
|
|
||||||
".m c #caca94",
|
|
||||||
".n c #c24e4c",
|
|
||||||
".o c #aa0204",
|
|
||||||
".p c #9e4244",
|
|
||||||
".q c #bc0204",
|
|
||||||
".r c #a40204",
|
|
||||||
".s c #9e262c",
|
|
||||||
".t c #8c3a3c",
|
|
||||||
".u c #5c1414",
|
|
||||||
".v c #5b0204",
|
|
||||||
".w c #700204",
|
|
||||||
".x c #722214",
|
|
||||||
".y c #b52624",
|
|
||||||
".z c #8e3234",
|
|
||||||
".A c #b60204",
|
|
||||||
".B c #c20204",
|
|
||||||
".C c #860204",
|
|
||||||
".D c #560304",
|
|
||||||
".E c #800204",
|
|
||||||
".F c #9e0204",
|
|
||||||
".G c #920204",
|
|
||||||
".H c #620204",
|
|
||||||
".I c #a41314",
|
|
||||||
".J c #996a6c",
|
|
||||||
".K c #920d09",
|
|
||||||
".L c #c80204",
|
|
||||||
".M c #690204",
|
|
||||||
".N c #980204",
|
|
||||||
".O c #984c4c",
|
|
||||||
".P c #e2dedc",
|
|
||||||
".Q c #ae5e5c",
|
|
||||||
".R c #bc6a6c",
|
|
||||||
".S c #a21a1c",
|
|
||||||
".T c #8a0a04",
|
|
||||||
".U c #671e1c",
|
|
||||||
".V c #941b1c",
|
|
||||||
".W c #b8b4b4",
|
|
||||||
".X c #e8e6e4",
|
|
||||||
".Y c #ccb4b4",
|
|
||||||
".Z c #c07c7c",
|
|
||||||
".0 c #f3f2eb",
|
|
||||||
".1 c #b49696",
|
|
||||||
".2 c #521614",
|
|
||||||
".3 c #9e5a5c",
|
|
||||||
".4 c #d4d4d4",
|
|
||||||
".5 c #a7a5a1",
|
|
||||||
".6 c #dec4c4",
|
|
||||||
".7 c #e4d6d4",
|
|
||||||
".8 c #f4f2f4",
|
|
||||||
".9 c #cccac4",
|
|
||||||
"#. c #9a161c",
|
|
||||||
"## c #8c0204",
|
|
||||||
"#a c #862c2c",
|
|
||||||
"#b c #7e5e5c",
|
|
||||||
"#c c #a39694",
|
|
||||||
"#d c #6b6667",
|
|
||||||
"#e c #322624",
|
|
||||||
"#f c #b09e9c",
|
|
||||||
"#g c #b23234",
|
|
||||||
"#h c #500304",
|
|
||||||
"#i c #222224",
|
|
||||||
"#j c #2e322c",
|
|
||||||
"#k c #925c5c",
|
|
||||||
"#l c #721a1c",
|
|
||||||
"#m c #6e6e6c",
|
|
||||||
"#n c #0a0a0c",
|
|
||||||
"#o c #b2b2b4",
|
|
||||||
"#p c #8e6264",
|
|
||||||
"#q c #884444",
|
|
||||||
"#r c #8c5c5c",
|
|
||||||
"#s c #121214",
|
|
||||||
"#t c #b2aeac",
|
|
||||||
"#u c #c21e1c",
|
|
||||||
"#v c #6e0e0c",
|
|
||||||
"#w c #623e3c",
|
|
||||||
"#x c #b64e4c",
|
|
||||||
"#y c #bc3634",
|
|
||||||
"#z c #624e1c",
|
|
||||||
"#A c #6e727c",
|
|
||||||
"#B c #824e4c",
|
|
||||||
"#C c #8b8d87",
|
|
||||||
"#D c #a09674",
|
|
||||||
"#E c #766844",
|
|
||||||
"#F c #7a663c",
|
|
||||||
"#G c #828c90",
|
|
||||||
"#H c #beb6a4",
|
|
||||||
"#I c #3a0204",
|
|
||||||
"#J c #8e9298",
|
|
||||||
"#K c #562529",
|
|
||||||
"#L c #7c3838",
|
|
||||||
"#M c #bab294",
|
|
||||||
"#N c #7e4644",
|
|
||||||
"#O c #929a9c",
|
|
||||||
"#P c #762a2c",
|
|
||||||
"#Q c #a60e0c",
|
|
||||||
"#R c #ae1e1c",
|
|
||||||
"#S c #460a0c",
|
|
||||||
"#T c #a6aaa4",
|
|
||||||
"#U c #6a4a4c",
|
|
||||||
"#V c #784c50",
|
|
||||||
"#W c #761214",
|
|
||||||
"#X c #9e1e1c",
|
|
||||||
"#Y c #988c90",
|
|
||||||
"#Z c #821e1c",
|
|
||||||
"#0 c #7a1618",
|
|
||||||
"#1 c #7a6e74",
|
|
||||||
"#2 c #7e7a77",
|
|
||||||
"#3 c #808688",
|
|
||||||
"#4 c #828284",
|
|
||||||
"#5 c #828279",
|
|
||||||
"#6 c #827a64",
|
|
||||||
"#7 c #7e765c",
|
|
||||||
"#8 c #864a34",
|
|
||||||
"#9 c #825a44",
|
|
||||||
"a. c #766e54",
|
|
||||||
"a# c #7e7e74",
|
|
||||||
"aa c #806464",
|
|
||||||
"ab c #7e724c",
|
|
||||||
"ac c #766634",
|
|
||||||
"ad c #765a2c",
|
|
||||||
"ae c #8e7e54",
|
|
||||||
"af c #a69e8c",
|
|
||||||
"ag c #c7c2ac",
|
|
||||||
"ah c #9a2a1c",
|
|
||||||
"ai c #aa3a3c",
|
|
||||||
"aj c #979894",
|
|
||||||
"ak c #70684c",
|
|
||||||
"al c #62522c",
|
|
||||||
"am c #6e5e3c",
|
|
||||||
"an c #92866c",
|
|
||||||
"ao c #968e6c",
|
|
||||||
"ap c #826e54",
|
|
||||||
"aq c #84765c",
|
|
||||||
"ar c #86522c",
|
|
||||||
"as c #7e4624",
|
|
||||||
"at c #7e3614",
|
|
||||||
"au c #6e5254",
|
|
||||||
"av c #712e2c",
|
|
||||||
"aw c #7a5654",
|
|
||||||
"ax c #82727c",
|
|
||||||
"ay c #a63634",
|
|
||||||
"az c #8a6a6c",
|
|
||||||
"aA c #863534",
|
|
||||||
"aB c #5c1a18",
|
|
||||||
"aC c #6a2c2c",
|
|
||||||
"aD c #5e0e14",
|
|
||||||
"aE c #868684",
|
|
||||||
"aF c #922624",
|
|
||||||
"aG c #901614",
|
|
||||||
"aH c #c21614",
|
|
||||||
"aI c #520e0c",
|
|
||||||
"aJ c #805654",
|
|
||||||
"aK c #b00c0c",
|
|
||||||
"aL c #c2221c",
|
|
||||||
/* pixels */
|
|
||||||
"..........................................................................................",
|
|
||||||
"..........................................................................................",
|
|
||||||
".....................................#.a.#................................................",
|
|
||||||
"...................................#.b.c.#.#.#.#...........#.d............................",
|
|
||||||
".................................#.e.f.f.#.g.h.i.j.k.l.m...f.n............................",
|
|
||||||
".................................d.f.o.f.#.#.#.d.d.#.#.#...f.f.d..........................",
|
|
||||||
".................................p.q.q.r.s.t.u.v.w.x.d.d.#.d.r.y.d........................",
|
|
||||||
".................................z.A.B.q.C.D.E.F.G.E.H.E.I.F.q.A.d........................",
|
|
||||||
".................................J.G.f.G.w.K.f.L.B.B.r.M.f.B.L.A.d........................",
|
|
||||||
".................................d.w.N.M.O.P.Q.B.B.o.R.S.E.q.q.T.d........................",
|
|
||||||
".................................d.U.M.V.W.X.Y.q.B.Z.0.1.E.r.N.d..........................",
|
|
||||||
".................................d.2.r.3.4.5.6.A.f.7.8.9#.###a.#..........................",
|
|
||||||
"................................#b.d.L#c#d#e#f.N.V.5#d.4#g.E.d............................",
|
|
||||||
"...............................d#h.r.L#f#i#j#k.M#l#m#n#o.b.r.d............................",
|
|
||||||
"...............................d#h##.q#g#p#q##.q.N#r#s#t#u.q#v.#..........................",
|
|
||||||
"..............#j................#w.w.C.r.q##.r.B.f.T#x#y.L.r.M.d..........................",
|
|
||||||
"............#j#z#j#A#A#j.........d.D.r.M.C.f.r.r.r.q.B.C.N.E#B............................",
|
|
||||||
"..........#j#C#D#E#z#F#G#j.......d.d.#.G##.w.M.M.C.C.d.G.r.u.d............................",
|
|
||||||
"....................#E#H#C#j.........d#I.w.F.f.o.o.o.N.M.#.d..............................",
|
|
||||||
"......................#E#j#J#j......#K.M.#.#.v.w.M.v.##h.H#L.d............................",
|
|
||||||
"..........................#M#j.......v.F.q.r.d.w.w.C.E.M.v.M#N.d..........................",
|
|
||||||
"..........................#E#O#j#j#K##.f.L.L.L.B.q.f##.M.v.w.w#P.d.#...d.d................",
|
|
||||||
"............................#C#E.#.v.o.B.L.L.q.q.q.q.N.M.D#h.M.N.r#Q#R#S.H.J.#............",
|
|
||||||
"............................#j#T#U.C.q.q.o.G.F.f.q.A.N.d.v.v##.o.q.L.r.C.A###k............",
|
|
||||||
"..............................#C#V.N.A.N.f.q.F.C.E.f.F.E.H#n#W.K.I#X#a.z.V.q.d#p.d........",
|
|
||||||
"................................#Y.r.K#Z.K.q.A.G.w#0#b#1#2#3#4#5#5#6#6#7#8.q.G#9..........",
|
|
||||||
"..................#j#oa..5#j..#J#Ja##4#4aa.o.A##.E.xabacadae#Daf#M#Magah.r.qai.#..........",
|
|
||||||
"................aja#akalamanaoapaqaaarasat.r.o.E.w.T.T.E.H.#...........#.d.d.#............",
|
|
||||||
"...........E....#j#j#C#M#j#n#naa#V.O.f.N.F.q.G.d.w.r.C.d.H.#...............#..............",
|
|
||||||
"...........#.F.F.J#n#n#n#n#n#nauav#p.q.N.d.d.w.M.F.F.E.d.U................................",
|
|
||||||
".........E.F.E.E.d.z#n.d#n#n#naw.Uax.r##.d.w.D.M.r.N.E.w.d................................",
|
|
||||||
".........E.F.......d.Fay.E.F#naz.2#A.D#h.r.f.w##.r##.d.H.M................................",
|
|
||||||
".........F.#...........E.E.F.baAaB#A.#.E.f.r.w.N.N.E.waC.#................................",
|
|
||||||
".........F.#...............d.F.E#K#d.H.G.F.G.w.N##.d.D.#..................................",
|
|
||||||
".........F.#....................#Aau.v.E##.w.E.E.w.H.d.......d..av.d......................",
|
|
||||||
".........E.#..................#j#GaC.M.H.M.d.d.w.H.#.d.d.#aC.w.C##.E.d....................",
|
|
||||||
"...........F.................5#O...#aD.w.d.w.H.D.M######.G.F.o.f.o.N.3....................",
|
|
||||||
"...........F.E...........5aEakak.....#.##h#h.v.N.o.f.q.L.L.L.L.L.q.faF....................",
|
|
||||||
"...........E.E......#E#C.5aq#j.....#.v.N.F.d.N.r.F.r.F#Q.I.o.q.L.L.L.y....................",
|
|
||||||
".............E.....................#.E.B.qaG.d.d.d.....#.#.....d#x.b......................",
|
|
||||||
".............E.F...................E.w.L.LaG.#............................................",
|
|
||||||
"...............E.E.................EaA.q.qaG.#............................................",
|
|
||||||
"...............E.F.E.................E.r.r#Z.#............................................",
|
|
||||||
".................E.F.E...............E.G.NaA..............................................",
|
|
||||||
".................E#uaH.................w.dav..............................................",
|
|
||||||
"...................E.E.............EaI.M.w.v.#............................................",
|
|
||||||
"...................................E.D.d.E.waJ............................................",
|
|
||||||
".....................................C.N.N##.M............................................",
|
|
||||||
"..................................#W.f.q.A.f.G#q..........................................",
|
|
||||||
".....................................q.L.L.L.q.V.#........................................",
|
|
||||||
"...................................#.daK.q.qaL.d..........................................",
|
|
||||||
".......................................#.#.#..............................................",
|
|
||||||
"..........................................................................................",
|
|
||||||
"..........................................................................................",
|
|
||||||
".........................................................................................."
|
|
||||||
};
|
|
||||||
File diff suppressed because it is too large
Load Diff
34
libs/minilibx_mms_20200219/Makefile
Normal file
34
libs/minilibx_mms_20200219/Makefile
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
MODULE_SRC= mlx_image.swift mlx_window.swift mlx_init.swift
|
||||||
|
MODULE_OBJ=$(MODULE_SRC:.swift=.swiftmodule)
|
||||||
|
|
||||||
|
SRC= interface.swift $(MODULE_SRC)
|
||||||
|
OBJ=$(SRC:.swift=.o)
|
||||||
|
|
||||||
|
C_SRC= mlx_xpm.c mlx_png.c mlx_string_put.c
|
||||||
|
C_OBJ=$(C_SRC:.c=.o)
|
||||||
|
CFLAGS=-O3
|
||||||
|
|
||||||
|
NAME=libmlx.dylib
|
||||||
|
|
||||||
|
INC=-I.
|
||||||
|
#OPTI=-Ounchecked
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(MODULE_OBJ) $(OBJ) $(C_OBJ)
|
||||||
|
swiftc $(OPTI) $(INC) -o $(NAME) -emit-library $(OBJ) $(C_OBJ) -lz
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%.o: %.swift
|
||||||
|
swiftc $(OPTI) $(INC) -parse-as-library -c $< -o $@
|
||||||
|
|
||||||
|
%.swiftmodule: %.swift
|
||||||
|
swiftc $(OPTI) $(INC) -parse-as-library -c $< -o $@ -emit-module -module-name $(patsubst %.swift,%,$<) -module-link-name $(patsubst %.swift,%,$<)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(NAME) $(OBJ) $(MODULE_OBJ) $(C_OBJ) *.swiftdoc *~
|
||||||
|
|
||||||
3526
libs/minilibx_mms_20200219/font.c
Normal file
3526
libs/minilibx_mms_20200219/font.c
Normal file
File diff suppressed because it is too large
Load Diff
292
libs/minilibx_mms_20200219/interface.swift
Normal file
292
libs/minilibx_mms_20200219/interface.swift
Normal file
@@ -0,0 +1,292 @@
|
|||||||
|
|
||||||
|
import Cocoa
|
||||||
|
|
||||||
|
import mlx_window
|
||||||
|
import mlx_image
|
||||||
|
import mlx_init
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func _mlx_bridge<T : AnyObject>(obj : T) -> UnsafeRawPointer {
|
||||||
|
return UnsafeRawPointer(Unmanaged.passUnretained(obj).toOpaque())
|
||||||
|
}
|
||||||
|
|
||||||
|
func _mlx_bridge_retained<T : AnyObject>(obj : T) -> UnsafeRawPointer {
|
||||||
|
return UnsafeRawPointer(Unmanaged.passRetained(obj).toOpaque())
|
||||||
|
}
|
||||||
|
|
||||||
|
func _mlx_bridge<T : AnyObject>(ptr : UnsafeRawPointer) -> T {
|
||||||
|
return Unmanaged<T>.fromOpaque(ptr).takeUnretainedValue()
|
||||||
|
}
|
||||||
|
|
||||||
|
func _mlx_bridge_transfer<T : AnyObject>(ptr : UnsafeRawPointer) -> T {
|
||||||
|
return Unmanaged<T>.fromOpaque(ptr).takeRetainedValue()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let MLX_SYNC_IMAGE_WRITABLE = Int32(1)
|
||||||
|
let MLX_SYNC_WIN_FLUSH_CMD = Int32(2)
|
||||||
|
let MLX_SYNC_WIN_CMD_COMPLETED = Int32(3)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// C decl
|
||||||
|
|
||||||
|
|
||||||
|
@_cdecl("mlx_init")
|
||||||
|
public func mlx_init_swift() -> UnsafeRawPointer
|
||||||
|
{
|
||||||
|
let mm = MlxMain()
|
||||||
|
return (_mlx_bridge_retained(obj:mm))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@_cdecl("mlx_loop")
|
||||||
|
public func mlx_loop_swift(_ mlxptr:UnsafeRawPointer)
|
||||||
|
{
|
||||||
|
let mlx:MlxMain = _mlx_bridge(ptr:mlxptr)
|
||||||
|
mlx.inLoop = true
|
||||||
|
NSApp.run()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@_cdecl("mlx_new_window")
|
||||||
|
public func mlx_new_window_swift(_ mlxptr:UnsafeRawPointer, Width w:UInt32, Height h:UInt32, Title t:UnsafePointer<CChar>) -> UnsafeRawPointer
|
||||||
|
{
|
||||||
|
let mlx:MlxMain = _mlx_bridge(ptr:mlxptr)
|
||||||
|
let mw = MlxWin(device: mlx.device, width: Int(w), height: Int(h), title: String(cString: t))
|
||||||
|
mw.setNotifs()
|
||||||
|
mw.initMetal()
|
||||||
|
mlx.addWinToList(mw)
|
||||||
|
return (_mlx_bridge_retained(obj:mw))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@_cdecl("mlx_key_hook")
|
||||||
|
public func mlx_key_hook_swift(_ winptr:UnsafeRawPointer, _ fctptr:UnsafeMutableRawPointer, _ paramptr:UnsafeMutableRawPointer) -> Int32
|
||||||
|
{
|
||||||
|
let win:MlxWin = _mlx_bridge(ptr:winptr)
|
||||||
|
win.addHook(index: 3, fct: fctptr, param: paramptr)
|
||||||
|
return (Int32(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@_cdecl("mlx_mouse_hook")
|
||||||
|
public func mlx_mouse_hook_swift(_ winptr:UnsafeRawPointer, _ fctptr:UnsafeMutableRawPointer, _ paramptr:UnsafeMutableRawPointer) -> Int32
|
||||||
|
{
|
||||||
|
let win:MlxWin = _mlx_bridge(ptr:winptr)
|
||||||
|
win.addHook(index: 4, fct: fctptr, param: paramptr)
|
||||||
|
return (Int32(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@_cdecl("mlx_hook")
|
||||||
|
public func mlx_hook_swift(_ winptr:UnsafeRawPointer, _ xevent:Int32, _ xmask:Int32, _ fctptr:UnsafeMutableRawPointer, _ paramptr:UnsafeMutableRawPointer) -> Int32
|
||||||
|
{
|
||||||
|
let win:MlxWin = _mlx_bridge(ptr:winptr)
|
||||||
|
win.addHook(index: Int(xevent), fct: fctptr, param: paramptr)
|
||||||
|
return (Int32(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@_cdecl("mlx_expose_hook")
|
||||||
|
public func mlx_expose_hook_swift(_ winptr:UnsafeRawPointer, _ fctptr:UnsafeMutableRawPointer, _ paramptr:UnsafeMutableRawPointer) -> Int32
|
||||||
|
{
|
||||||
|
let win:MlxWin = _mlx_bridge(ptr:winptr)
|
||||||
|
win.addHook(index: 12, fct: fctptr, param: paramptr)
|
||||||
|
return (Int32(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@_cdecl("mlx_loop_hook")
|
||||||
|
public func mlx_loop_hook_swift(_ mlxptr:UnsafeRawPointer, _ fctptr:UnsafeMutableRawPointer, _ paramptr:UnsafeMutableRawPointer) -> Int32
|
||||||
|
{
|
||||||
|
let mlx:MlxMain = _mlx_bridge(ptr:mlxptr)
|
||||||
|
mlx.addLoopHook(fctptr, paramptr)
|
||||||
|
return (Int32(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@_cdecl("mlx_do_key_autorepeatoff")
|
||||||
|
public func mlx_do_key_autorepeatoff_swift(_ mlxptr:UnsafeRawPointer)
|
||||||
|
{
|
||||||
|
let mlx:MlxMain = _mlx_bridge(ptr:mlxptr)
|
||||||
|
mlx.winList.forEach{ $0.setKeyRepeat(0) }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@_cdecl("mlx_do_key_autorepeaton")
|
||||||
|
public func mlx_do_key_autorepeatoon_swift(_ mlxptr:UnsafeRawPointer)
|
||||||
|
{
|
||||||
|
let mlx:MlxMain = _mlx_bridge(ptr:mlxptr)
|
||||||
|
mlx.winList.forEach{ $0.setKeyRepeat(1) }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@_cdecl("mlx_clear_window")
|
||||||
|
public func mlx_clear_window_swift(_ mlxptr:UnsafeRawPointer, _ winptr:UnsafeRawPointer)
|
||||||
|
{
|
||||||
|
let win:MlxWin = _mlx_bridge(ptr:winptr)
|
||||||
|
win.clearWin()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@_cdecl("mlx_pixel_put")
|
||||||
|
public func mlx_pixel_put_swift(_ mlxptr:UnsafeRawPointer, _ winptr:UnsafeRawPointer, _ x:Int32, _ y:Int32, _ color:UInt32)
|
||||||
|
{
|
||||||
|
let win:MlxWin = _mlx_bridge(ptr:winptr)
|
||||||
|
win.pixelPut(x, y, color)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@_cdecl("mlx_get_color_value")
|
||||||
|
public func mlx_get_color_value(_ mlxptr:UnsafeRawPointer, _ color:UInt32) -> UInt32
|
||||||
|
{
|
||||||
|
return color
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@_cdecl("mlx_new_image")
|
||||||
|
public func mlx_new_image(_ mlxptr:UnsafeRawPointer, _ width:Int32, _ height:Int32) -> UnsafeRawPointer
|
||||||
|
{
|
||||||
|
let mlx:MlxMain = _mlx_bridge(ptr:mlxptr)
|
||||||
|
let img = MlxImg(d:mlx.device, w:Int(width), h:Int(height))
|
||||||
|
mlx.addImgToList(img)
|
||||||
|
/// print(CFGetRetainCount(img))
|
||||||
|
return (_mlx_bridge_retained(obj:img))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@_cdecl("mlx_get_data_addr")
|
||||||
|
public func mlx_get_data_addr_swift(_ imgptr:UnsafeRawPointer, _ bpp:UnsafeMutablePointer<Int32>, _ sizeline:UnsafeMutablePointer<Int32>, _ endian:UnsafeMutablePointer<Int32>) -> UnsafeMutablePointer<UInt32>
|
||||||
|
{
|
||||||
|
let img:MlxImg = _mlx_bridge(ptr:imgptr)
|
||||||
|
bpp.pointee = 32
|
||||||
|
sizeline.pointee = Int32(img.texture_sizeline)
|
||||||
|
endian.pointee = Int32(0)
|
||||||
|
return img.texture_data
|
||||||
|
}
|
||||||
|
|
||||||
|
@_cdecl("mlx_put_image_to_window")
|
||||||
|
public func mlx_put_image_to_window_swift(_ mlxptr:UnsafeRawPointer, _ winptr:UnsafeRawPointer, _ imgptr:UnsafeRawPointer, _ x:Int32, _ y:Int32) -> Int32
|
||||||
|
{
|
||||||
|
let win:MlxWin = _mlx_bridge(ptr:winptr)
|
||||||
|
let img:MlxImg = _mlx_bridge(ptr:imgptr)
|
||||||
|
win.putImage(image:img, x:x, y:y)
|
||||||
|
return Int32(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
@_cdecl("mlx_put_image_to_window_scale")
|
||||||
|
public func mlx_put_image_to_window_scale_swift(_ mlxptr:UnsafeRawPointer, _ winptr:UnsafeRawPointer, _ imgptr:UnsafeRawPointer, _ sx:Int32, _ sy:Int32, _ sw:Int32, _ sh:Int32, _ dx:Int32, _ dy:Int32, _ dw:Int32, _ dh:Int32, _ color:UInt32) -> Int32
|
||||||
|
{
|
||||||
|
let win:MlxWin = _mlx_bridge(ptr:winptr)
|
||||||
|
let img:MlxImg = _mlx_bridge(ptr:imgptr)
|
||||||
|
win.putImageScale(image:img, sx:sx, sy:sy, sw:sw, sh:sh, dx:dx, dy:dy, dw:dw, dh:dh, c:color)
|
||||||
|
return Int32(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
@_cdecl("mlx_do_sync")
|
||||||
|
public func mlx_do_sync_swift(_ mlxptr:UnsafeRawPointer) -> Int32
|
||||||
|
{
|
||||||
|
let mlx:MlxMain = _mlx_bridge(ptr:mlxptr)
|
||||||
|
mlx.winList.forEach { $0.flushImages() }
|
||||||
|
mlx.winList.forEach { $0.waitForGPU() }
|
||||||
|
return Int32(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
@_cdecl("mlx_sync")
|
||||||
|
public func mlx_sync_swift(_ what:Int32, _ param:UnsafeRawPointer) -> Int32
|
||||||
|
{
|
||||||
|
switch what
|
||||||
|
{
|
||||||
|
case MLX_SYNC_IMAGE_WRITABLE:
|
||||||
|
let img:MlxImg = _mlx_bridge(ptr:param); while img.onGPU > 0 {}
|
||||||
|
case MLX_SYNC_WIN_FLUSH_CMD:
|
||||||
|
let win:MlxWin = _mlx_bridge(ptr:param); win.flushImages()
|
||||||
|
case MLX_SYNC_WIN_CMD_COMPLETED:
|
||||||
|
let win:MlxWin = _mlx_bridge(ptr:param); win.flushImages(); win.waitForGPU()
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
return Int32(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
@_cdecl("mlx_destroy_window")
|
||||||
|
public func mlx_destroy_window_swift(_ mlxptr:UnsafeRawPointer, _ winptr:UnsafeRawPointer) -> Int32
|
||||||
|
{
|
||||||
|
let mlx:MlxMain = _mlx_bridge(ptr:mlxptr)
|
||||||
|
/// bridge_transfer to get the retain, at end of this func should release the MlxWin object, because no ref anymore.
|
||||||
|
let win:MlxWin = _mlx_bridge_transfer(ptr:winptr)
|
||||||
|
win.delNotifs()
|
||||||
|
win.flushImages()
|
||||||
|
win.waitForGPU()
|
||||||
|
win.destroyWinE()
|
||||||
|
mlx.winList.removeAll(where: { $0 === win} )
|
||||||
|
return Int32(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
@_cdecl("mlx_destroy_image")
|
||||||
|
public func mlx_destroy_image_swift(_ mlxptr:UnsafeRawPointer, _ imgptr:UnsafeRawPointer) -> Int32
|
||||||
|
{
|
||||||
|
let mlx:MlxMain = _mlx_bridge(ptr:mlxptr)
|
||||||
|
/// bridge_transfer to get the retain, at end of this func should release the MlxImg object, because no ref anymore.
|
||||||
|
let img:MlxImg = _mlx_bridge_transfer(ptr:imgptr)
|
||||||
|
mlx.winList.forEach { $0.flushImages() }
|
||||||
|
while img.onGPU > 0 {}
|
||||||
|
mlx.imgList.removeAll(where: { $0 === img} )
|
||||||
|
return Int32(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@_cdecl("mlx_get_screen_size")
|
||||||
|
public func mlx_get_screen_size_swift(_ mlxptr:UnsafeRawPointer, _ sizex:UnsafeMutablePointer<Int32>, _ sizey:UnsafeMutablePointer<Int32>) -> Int32
|
||||||
|
{
|
||||||
|
/// let mlx:MlxMain = _mlx_bridge(ptr:mlxptr)
|
||||||
|
sizex.pointee = Int32(NSScreen.main!.frame.size.width)
|
||||||
|
sizey.pointee = Int32(NSScreen.main!.frame.size.height)
|
||||||
|
return Int32(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@_cdecl("mlx_mouse_hide")
|
||||||
|
public func mlx_mouse_hide_swift() -> Int32
|
||||||
|
{
|
||||||
|
NSCursor.hide()
|
||||||
|
return Int32(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
@_cdecl("mlx_mouse_show")
|
||||||
|
public func mlx_mouse_show_swift() -> Int32
|
||||||
|
{
|
||||||
|
NSCursor.unhide()
|
||||||
|
return Int32(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@_cdecl("mlx_mouse_move")
|
||||||
|
public func mlx_mouse_move_swift(_ winptr:UnsafeRawPointer, _ x:Int32, _ y:Int32) -> Int32
|
||||||
|
{
|
||||||
|
let win:MlxWin = _mlx_bridge(ptr:winptr)
|
||||||
|
let frame = win.getWinEFrame()
|
||||||
|
/// let sframe = win.getScreenFrame()
|
||||||
|
var pt = CGPoint()
|
||||||
|
pt.x = frame.origin.x + CGFloat(x)
|
||||||
|
/// pt.y = sframe.size.y - frame.size.y - frame.origin.y + 1 + y
|
||||||
|
pt.y = frame.origin.y + frame.size.height - 1.0 - CGFloat(y)
|
||||||
|
CGWarpMouseCursorPosition(pt)
|
||||||
|
CGAssociateMouseAndMouseCursorPosition(UInt32(1))
|
||||||
|
return Int32(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@_cdecl("mlx_mouse_get_pos")
|
||||||
|
public func mlx_mouse_get_pos_swift(_ winptr:UnsafeRawPointer, _ x:UnsafeMutablePointer<Int32>, _ y:UnsafeMutablePointer<Int32>) -> Int32
|
||||||
|
{
|
||||||
|
let win:MlxWin = _mlx_bridge(ptr:winptr)
|
||||||
|
let frame = win.getWinEFrame()
|
||||||
|
let point = win.getMouseLoc()
|
||||||
|
x.pointee = Int32(point.x)
|
||||||
|
y.pointee = Int32(frame.size.height - 1.0 - point.y)
|
||||||
|
return Int32(0)
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
.TH MiniLibX 3 "September 19, 2002"
|
.TH MiniLibX 3 "September 19, 2002"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
MiniLibX - Simple X-Window Interface Library for students
|
MiniLibX - Simple Window Interface Library for students
|
||||||
.SH SYNOPSYS
|
.SH SYNOPSYS
|
||||||
#include <mlx.h>
|
#include <mlx.h>
|
||||||
|
|
||||||
@@ -12,11 +12,12 @@ MiniLibX - Simple X-Window Interface Library for students
|
|||||||
|
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
MiniLibX is an easy way to create graphical software,
|
MiniLibX is an easy way to create graphical software,
|
||||||
without any X-Window programming knowledge. It provides
|
without any X-Window/X11 programming knowledge under Unix/Linux, nor
|
||||||
|
any AppKit programming knowledge under MacOS. It provides
|
||||||
simple window creation, a drawing tool, image and basic events
|
simple window creation, a drawing tool, image and basic events
|
||||||
management.
|
management.
|
||||||
|
|
||||||
.SH X-WINDOW CONCEPT
|
.SH Unix/Linux: X-WINDOW CONCEPT
|
||||||
|
|
||||||
X-Window is a network-oriented graphical system for Unix.
|
X-Window is a network-oriented graphical system for Unix.
|
||||||
It is based on two main parts:
|
It is based on two main parts:
|
||||||
@@ -30,6 +31,14 @@ On the other side, the X-Server manages the screen, keyboard and mouse
|
|||||||
A network connection must be established between these two entities to send
|
A network connection must be established between these two entities to send
|
||||||
drawing orders (from the software to the X-Server), and keyboard/mouse
|
drawing orders (from the software to the X-Server), and keyboard/mouse
|
||||||
events (from the X-Server to the software).
|
events (from the X-Server to the software).
|
||||||
|
.br
|
||||||
|
Nowadays, most of the time, both run on the same computer.
|
||||||
|
|
||||||
|
.SH MacOS: WINDOW SERVER AND GPU
|
||||||
|
|
||||||
|
Your software interacts directly with the Window server who handles the
|
||||||
|
cohabitation on the screen with other software and the event system,
|
||||||
|
and interacts with the GPU to handle all drawing stuff.
|
||||||
|
|
||||||
.SH INCLUDE FILE
|
.SH INCLUDE FILE
|
||||||
.B mlx.h
|
.B mlx.h
|
||||||
@@ -41,9 +50,9 @@ It only contains function prototypes, no structure is needed.
|
|||||||
First of all, you need to initialize the connection
|
First of all, you need to initialize the connection
|
||||||
between your software and the display.
|
between your software and the display.
|
||||||
Once this connection is established, you'll be able to
|
Once this connection is established, you'll be able to
|
||||||
use other MiniLibX functions to send the X-Server messages,
|
use other MiniLibX functions to send and receive the messages from
|
||||||
like "I want to draw a yellow pixel in this window" or "did the
|
the display, like "I want to draw a yellow pixel in this window" or
|
||||||
user hit a key?".
|
"did the user hit a key?".
|
||||||
.P
|
.P
|
||||||
The
|
The
|
||||||
.B mlx_init
|
.B mlx_init
|
||||||
@@ -68,12 +77,20 @@ All other MiniLibX functions are described in the following man pages:
|
|||||||
: handle keyboard or mouse events
|
: handle keyboard or mouse events
|
||||||
|
|
||||||
.SH LINKING MiniLibX
|
.SH LINKING MiniLibX
|
||||||
To use MiniLibX functions, you'll need to link
|
To use MiniLibX functions, you may need to link
|
||||||
your software with several libraries, including the MiniLibX library itself.
|
your software with several libraries, including the MiniLibX library itself.
|
||||||
To do this, simply add the following arguments at linking time:
|
On Unix/Linux, simply add the following arguments at linking time:
|
||||||
|
|
||||||
.B -lmlx -lXext -lX11
|
.B -lmlx -lXext -lX11
|
||||||
|
|
||||||
|
On MacOS, the dynamic Metal library will find on its own the missing components:
|
||||||
|
|
||||||
|
.B -lmlx
|
||||||
|
|
||||||
|
and still on MacOS, the static OpenGL version will need:
|
||||||
|
|
||||||
|
.B -lmlx -framework OpenGL -framework AppKit -lz
|
||||||
|
|
||||||
You may also need to specify the path to these libraries, using
|
You may also need to specify the path to these libraries, using
|
||||||
the
|
the
|
||||||
.B -L
|
.B -L
|
||||||
@@ -83,11 +100,11 @@ flag.
|
|||||||
.SH RETURN VALUES
|
.SH RETURN VALUES
|
||||||
If
|
If
|
||||||
.B mlx_init()
|
.B mlx_init()
|
||||||
fails to set up the connection to the X server, it will return NULL, otherwise
|
fails to set up the connection to the display, it will return NULL, otherwise
|
||||||
a non-null pointer is returned as a connection identifier.
|
a non-null pointer is returned as a connection identifier.
|
||||||
|
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3)
|
mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3)
|
||||||
|
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
Copyright ol@ - 2002-2019 - Olivier Crouzet
|
||||||
@@ -43,9 +43,9 @@ MiniLibX - Handle events
|
|||||||
.I void *mlx_ptr, int (*funct_ptr)(), void *param
|
.I void *mlx_ptr, int (*funct_ptr)(), void *param
|
||||||
);
|
);
|
||||||
|
|
||||||
.SH X-WINDOW EVENTS
|
.SH EVENTS
|
||||||
|
|
||||||
The X-Window system is bi-directionnal. On one hand, the program sends orders to
|
The graphical system is bi-directionnal. On one hand, the program sends orders to
|
||||||
the screen to display pixels, images, and so on. On the other hand,
|
the screen to display pixels, images, and so on. On the other hand,
|
||||||
it can get information from the keyboard and mouse associated to
|
it can get information from the keyboard and mouse associated to
|
||||||
the screen. To do so, the program receives "events" from the keyboard or the
|
the screen. To do so, the program receives "events" from the keyboard or the
|
||||||
@@ -69,7 +69,8 @@ You can assign different functions to the three following events:
|
|||||||
- The mouse button is pressed
|
- The mouse button is pressed
|
||||||
.br
|
.br
|
||||||
- A part of the window should be re-drawn
|
- A part of the window should be re-drawn
|
||||||
(this is called an "expose" event, and it is your program's job to handle it).
|
(this is called an "expose" event, and it is your program's job to handle it in the
|
||||||
|
Unix/Linux X11 environment, but at the opposite it never happens on MacOS).
|
||||||
.br
|
.br
|
||||||
|
|
||||||
Each window can define a different function for the same event.
|
Each window can define a different function for the same event.
|
||||||
@@ -114,7 +115,8 @@ is the address specified in the mlx_*_hook calls. This address is never
|
|||||||
used nor modified by the MiniLibX. On key and mouse events, additional
|
used nor modified by the MiniLibX. On key and mouse events, additional
|
||||||
information is passed:
|
information is passed:
|
||||||
.I keycode
|
.I keycode
|
||||||
tells you which key is pressed (look for the X11 include file "keysymdef.h"),
|
tells you which key is pressed (with X11, look for the include file "keysymdef.h",
|
||||||
|
with MacOS, just try :) ),
|
||||||
(
|
(
|
||||||
.I x
|
.I x
|
||||||
,
|
,
|
||||||
@@ -124,18 +126,19 @@ tells you which key is pressed (look for the X11 include file "keysymdef.h"),
|
|||||||
tells you which mouse button was pressed.
|
tells you which mouse button was pressed.
|
||||||
|
|
||||||
.SH GOING FURTHER WITH EVENTS
|
.SH GOING FURTHER WITH EVENTS
|
||||||
The MiniLibX provides a much generic access to all X-Window events. The
|
The MiniLibX provides a much generic access to other available events. The
|
||||||
.I mlx.h
|
.I mlx.h
|
||||||
include define
|
include define
|
||||||
.B mlx_hook()
|
.B mlx_hook()
|
||||||
in the same manner mlx_*_hook functions work. The event and mask values
|
in the same manner mlx_*_hook functions work. The event and mask values
|
||||||
will be taken from the X11 include file "X.h".
|
will be taken from the X11 include file "X.h". Some MacOS events are mapped
|
||||||
|
to these values, when it makes sense, and the mask is not used in MacOS.
|
||||||
|
|
||||||
See source code of mlx_int_param_event.c to find out how the MiniLibX will
|
See source code of the MiniLibX to find out how it will
|
||||||
call your own function for a specific event.
|
call your own function for a specific event.
|
||||||
|
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3)
|
mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3)
|
||||||
|
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
Copyright ol@ - 2002-2019 - Olivier Crouzet
|
||||||
@@ -51,6 +51,14 @@ MiniLibX - Manipulating images
|
|||||||
.I void *mlx_ptr, char *filename, int *width, int *height
|
.I void *mlx_ptr, char *filename, int *width, int *height
|
||||||
);
|
);
|
||||||
|
|
||||||
|
.nf
|
||||||
|
.I void *
|
||||||
|
.fi
|
||||||
|
.B mlx_png_file_to_image
|
||||||
|
(
|
||||||
|
.I void *mlx_ptr, char *filename, int *width, int *height
|
||||||
|
);
|
||||||
|
|
||||||
.nf
|
.nf
|
||||||
.I int
|
.I int
|
||||||
.fi
|
.fi
|
||||||
@@ -141,7 +149,7 @@ one byte for each component (see
|
|||||||
.B mlx_pixel_put
|
.B mlx_pixel_put
|
||||||
manual). This must be translated to fit the
|
manual). This must be translated to fit the
|
||||||
.I bits_per_pixel
|
.I bits_per_pixel
|
||||||
requirement of the image, and make the color understandable to the X-Server.
|
requirement of the image, and make the color understandable to the display.
|
||||||
That is the purpose of the
|
That is the purpose of the
|
||||||
.B mlx_get_color_value
|
.B mlx_get_color_value
|
||||||
() function. It takes a standard RGB
|
() function. It takes a standard RGB
|
||||||
@@ -151,19 +159,23 @@ parameter, and returns an
|
|||||||
value.
|
value.
|
||||||
The
|
The
|
||||||
.I bits_per_pixel
|
.I bits_per_pixel
|
||||||
least significant bits of this value can be stored in the image.
|
least significant bits of this value can be stored in the image. You can
|
||||||
|
avoid using this function if there is no conversion needed (eg. in case of
|
||||||
|
24 bits depth, or 32 bits depth).
|
||||||
|
|
||||||
Keep in mind that the least significant bits position depends on the local
|
Keep in mind that the least significant bits position depends on the local
|
||||||
computer's endian. If the endian of the image (in fact the endian of
|
computer's endian. If the endian of the image differs from the local endian
|
||||||
the X-Server's computer) differs from the local endian, then the value should
|
(which shoud only occurs in a X11 network environment), then the value should
|
||||||
be transformed before being used.
|
be transformed before being used.
|
||||||
|
|
||||||
.SH XPM IMAGES
|
.SH XPM AND PNG IMAGES
|
||||||
|
|
||||||
The
|
The
|
||||||
.B mlx_xpm_to_image
|
.B mlx_xpm_to_image
|
||||||
() and
|
() ,
|
||||||
.B mlx_xpm_file_to_image
|
.B mlx_xpm_file_to_image
|
||||||
|
() and
|
||||||
|
.B mlx_png_file_to_image
|
||||||
() functions will create a new image the same way.
|
() functions will create a new image the same way.
|
||||||
They will fill it using the specified
|
They will fill it using the specified
|
||||||
.I xpm_data
|
.I xpm_data
|
||||||
@@ -171,16 +183,18 @@ or
|
|||||||
.I filename
|
.I filename
|
||||||
, depending on which function is used.
|
, depending on which function is used.
|
||||||
Note that MiniLibX does not use the standard
|
Note that MiniLibX does not use the standard
|
||||||
Xpm library to deal with xpm images. You may not be able to
|
Xpm and png libraries to deal with xpm and png images. You may not be able to
|
||||||
read all types of xpm images. It however handles transparency.
|
read all types of xpm and png images. It however handles transparency.
|
||||||
|
|
||||||
.SH RETURN VALUES
|
.SH RETURN VALUES
|
||||||
The three functions that create images,
|
The four functions that create images,
|
||||||
.B mlx_new_image()
|
.B mlx_new_image()
|
||||||
,
|
,
|
||||||
.B mlx_xpm_to_image()
|
.B mlx_xpm_to_image()
|
||||||
and
|
,
|
||||||
.B mlx_xpm_file_to_image()
|
.B mlx_xpm_file_to_image()
|
||||||
|
and
|
||||||
|
.B mlx_png_file_to_image()
|
||||||
, will return NULL if an error occurs. Otherwise they return a non-null pointer
|
, will return NULL if an error occurs. Otherwise they return a non-null pointer
|
||||||
as an image identifier.
|
as an image identifier.
|
||||||
|
|
||||||
@@ -189,4 +203,4 @@ as an image identifier.
|
|||||||
mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_loop(3)
|
mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_loop(3)
|
||||||
|
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
Copyright ol@ - 2002-2019 - Olivier Crouzet
|
||||||
@@ -76,4 +76,4 @@ right now return nothing.
|
|||||||
mlx(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3)
|
mlx(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3)
|
||||||
|
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
Copyright ol@ - 2002-2019 - Olivier Crouzet
|
||||||
@@ -49,8 +49,9 @@ will be displayed at (
|
|||||||
.I y
|
.I y
|
||||||
).
|
).
|
||||||
|
|
||||||
In both functions, it is impossible to display anything outside the
|
Both functions will discard any display outside the window. This makes
|
||||||
specified window, nor display in another window in front of the selected one.
|
.B mlx_pixel_put
|
||||||
|
slow. Consider using images instead.
|
||||||
|
|
||||||
.SH COLOR MANAGEMENT
|
.SH COLOR MANAGEMENT
|
||||||
The
|
The
|
||||||
@@ -72,10 +73,13 @@ this integer are filled as shown in the picture below:
|
|||||||
While filling the integer, make sure you avoid endian problems. Remember
|
While filling the integer, make sure you avoid endian problems. Remember
|
||||||
that the "blue" byte should always be the least significant one.
|
that the "blue" byte should always be the least significant one.
|
||||||
|
|
||||||
|
Depending on hardware capabilities, the most significant bit can handle
|
||||||
|
transparency. Beware, at the opposite of the OpenGL classics, it does
|
||||||
|
not represent opacity.
|
||||||
|
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
mlx(3), mlx_new_window(3), mlx_new_image(3), mlx_loop(3)
|
mlx(3), mlx_new_window(3), mlx_new_image(3), mlx_loop(3)
|
||||||
|
|
||||||
|
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
Copyright ol@ - 2002-2019 - Olivier Crouzet
|
||||||
157
libs/minilibx_mms_20200219/mlx.h
Normal file
157
libs/minilibx_mms_20200219/mlx.h
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
/*
|
||||||
|
** mlx.h for MinilibX in
|
||||||
|
**
|
||||||
|
** Made by Charlie Root
|
||||||
|
** Login <ol@42.fr>
|
||||||
|
**
|
||||||
|
** Started on Mon Jul 31 16:37:50 2000 Charlie Root
|
||||||
|
** Last update Tue Oct 14 16:23:28 2019 Olivier Crouzet
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
** MinilibX - Please report bugs
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
**
|
||||||
|
** This library is a simple framework to help 42 students
|
||||||
|
** create simple graphical apps.
|
||||||
|
** It only provides the minimum functions, it's students' job
|
||||||
|
** to create the missing pieces for their own project :)
|
||||||
|
**
|
||||||
|
** The MinilibX can load XPM and PNG images.
|
||||||
|
** Please note that both image loaders are incomplete, some
|
||||||
|
** image may not load.
|
||||||
|
**
|
||||||
|
** For historical reasons, the alpha byte represent transparency
|
||||||
|
** instead of opacity.
|
||||||
|
** Also, for compatibility reasons, prototypes may show inconsistant
|
||||||
|
** types.
|
||||||
|
**
|
||||||
|
** Only the dynamic library is available. It must be placed in an appropriate path.
|
||||||
|
** ./ is one of them. You can also use DYLD_LIBRARY_PATH
|
||||||
|
**
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef MLX_H
|
||||||
|
|
||||||
|
#define MLX_H
|
||||||
|
|
||||||
|
|
||||||
|
void *mlx_init();
|
||||||
|
/*
|
||||||
|
** needed before everything else.
|
||||||
|
** return (void *)0 if failed
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Basic actions
|
||||||
|
*/
|
||||||
|
|
||||||
|
void *mlx_new_window(void *mlx_ptr, int size_x, int size_y, char *title);
|
||||||
|
/*
|
||||||
|
** return void *0 if failed
|
||||||
|
*/
|
||||||
|
int mlx_clear_window(void *mlx_ptr, void *win_ptr);
|
||||||
|
int mlx_pixel_put(void *mlx_ptr, void *win_ptr, int x, int y, int color);
|
||||||
|
/*
|
||||||
|
** origin for x & y is top left corner of the window
|
||||||
|
** y down is positive
|
||||||
|
** color is 0xAARRGGBB format
|
||||||
|
** x and y must fit into the size of the window, no control is done on the values
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Image stuff
|
||||||
|
*/
|
||||||
|
|
||||||
|
void *mlx_new_image(void *mlx_ptr,int width,int height);
|
||||||
|
/*
|
||||||
|
** return void *0 if failed
|
||||||
|
*/
|
||||||
|
char *mlx_get_data_addr(void *img_ptr, int *bits_per_pixel,
|
||||||
|
int *size_line, int *endian);
|
||||||
|
/*
|
||||||
|
** endian : 0 = graphical sever is little endian, 1 = big endian
|
||||||
|
** usefull in a network environment where graphical app show on a remote monitor that can have a different endian
|
||||||
|
*/
|
||||||
|
int mlx_put_image_to_window(void *mlx_ptr, void *win_ptr, void *img_ptr,
|
||||||
|
int x, int y);
|
||||||
|
unsigned int mlx_get_color_value(void *mlx_ptr, int color);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** dealing with Events
|
||||||
|
*/
|
||||||
|
|
||||||
|
int mlx_mouse_hook (void *win_ptr, int (*funct_ptr)(), void *param);
|
||||||
|
int mlx_key_hook (void *win_ptr, int (*funct_ptr)(), void *param);
|
||||||
|
int mlx_expose_hook (void *win_ptr, int (*funct_ptr)(), void *param);
|
||||||
|
|
||||||
|
int mlx_loop_hook (void *mlx_ptr, int (*funct_ptr)(), void *param);
|
||||||
|
int mlx_loop (void *mlx_ptr);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** hook funct are called as follow :
|
||||||
|
**
|
||||||
|
** expose_hook(void *param);
|
||||||
|
** key_hook(int keycode, void *param);
|
||||||
|
** mouse_hook(int button, int x,int y, void *param);
|
||||||
|
** loop_hook(void *param);
|
||||||
|
**
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Usually asked...
|
||||||
|
** mlx_string_put display may vary in size between OS and between mlx implementations
|
||||||
|
*/
|
||||||
|
|
||||||
|
int mlx_string_put(void *mlx_ptr, void *win_ptr, int x, int y, int color,
|
||||||
|
char *string);
|
||||||
|
void *mlx_xpm_to_image(void *mlx_ptr, char **xpm_data,
|
||||||
|
int *width, int *height);
|
||||||
|
void *mlx_xpm_file_to_image(void *mlx_ptr, char *filename,
|
||||||
|
int *width, int *height);
|
||||||
|
void *mlx_png_file_to_image(void *mlx_ptr, char *file, int *width, int *height);
|
||||||
|
|
||||||
|
int mlx_destroy_window(void *mlx_ptr, void *win_ptr);
|
||||||
|
|
||||||
|
int mlx_destroy_image(void *mlx_ptr, void *img_ptr);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** generic hook system for all events, and minilibX functions that
|
||||||
|
** can be hooked. Some macro and defines from X11/X.h are needed here.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int mlx_hook(void *win_ptr, int x_event, int x_mask,
|
||||||
|
int (*funct)(), void *param);
|
||||||
|
|
||||||
|
int mlx_mouse_hide();
|
||||||
|
int mlx_mouse_show();
|
||||||
|
int mlx_mouse_move(void *win_ptr, int x, int y);
|
||||||
|
int mlx_mouse_get_pos(void *win_ptr, int *x, int *y);
|
||||||
|
|
||||||
|
int mlx_do_key_autorepeatoff(void *mlx_ptr);
|
||||||
|
int mlx_do_key_autorepeaton(void *mlx_ptr);
|
||||||
|
int mlx_do_sync(void *mlx_ptr);
|
||||||
|
|
||||||
|
#define MLX_SYNC_IMAGE_WRITABLE 1
|
||||||
|
#define MLX_SYNC_WIN_FLUSH_CMD 2
|
||||||
|
#define MLX_SYNC_WIN_CMD_COMPLETED 3
|
||||||
|
int mlx_sync(int cmd, void *param);
|
||||||
|
/*
|
||||||
|
** image_writable can loop forever if no flush occurred. Flush is always done by mlx_loop.
|
||||||
|
** cmd_completed first flush then wait for completion.
|
||||||
|
** mlx_do_sync equals cmd_completed for all windows.
|
||||||
|
** cmd is one of the define, param will be img_ptr or win_ptr accordingly
|
||||||
|
*/
|
||||||
|
|
||||||
|
int mlx_get_screen_size(void *mlx_ptr, int *sizex, int *sizey);
|
||||||
|
|
||||||
|
#endif /* MLX_H */
|
||||||
48
libs/minilibx_mms_20200219/mlx_image.swift
Normal file
48
libs/minilibx_mms_20200219/mlx_image.swift
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
|
||||||
|
|
||||||
|
import Metal
|
||||||
|
|
||||||
|
|
||||||
|
public class MlxImg
|
||||||
|
{
|
||||||
|
public var texture: MTLTexture
|
||||||
|
/// var texture_buff: MTLBuffer
|
||||||
|
|
||||||
|
public var texture_sizeline: Int
|
||||||
|
public var texture_data: UnsafeMutablePointer<UInt32>
|
||||||
|
public var texture_width: Int
|
||||||
|
public var texture_height: Int
|
||||||
|
|
||||||
|
public var onGPU = 0
|
||||||
|
|
||||||
|
convenience public init(d device:MTLDevice, w width:Int, h height:Int)
|
||||||
|
{
|
||||||
|
self.init(d:device, w:width, h:height, t:0)
|
||||||
|
}
|
||||||
|
|
||||||
|
public init(d device:MTLDevice, w width:Int, h height:Int, t target:Int)
|
||||||
|
{
|
||||||
|
texture_width = width
|
||||||
|
texture_height = height
|
||||||
|
texture_sizeline = width * 4
|
||||||
|
texture_sizeline = 256 * (texture_sizeline / 256 + (texture_sizeline%256 >= 1 ? 1 : 0) )
|
||||||
|
|
||||||
|
let textureDesc = MTLTextureDescriptor()
|
||||||
|
textureDesc.width = texture_width
|
||||||
|
textureDesc.height = texture_height
|
||||||
|
textureDesc.usage = .shaderRead
|
||||||
|
if (target == 1)
|
||||||
|
{
|
||||||
|
textureDesc.usage = .renderTarget
|
||||||
|
textureDesc.storageMode = .private
|
||||||
|
}
|
||||||
|
textureDesc.pixelFormat = MTLPixelFormat.bgra8Unorm
|
||||||
|
let texture_buff = device.makeBuffer(length: texture_sizeline * height)!
|
||||||
|
texture = texture_buff.makeTexture(descriptor:textureDesc, offset:0, bytesPerRow:texture_sizeline)!
|
||||||
|
|
||||||
|
let tmpptr = texture_buff.contents()
|
||||||
|
texture_data = tmpptr.assumingMemoryBound(to:UInt32.self)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
100
libs/minilibx_mms_20200219/mlx_init.swift
Normal file
100
libs/minilibx_mms_20200219/mlx_init.swift
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
|
||||||
|
import Cocoa
|
||||||
|
import Metal
|
||||||
|
import mlx_window
|
||||||
|
import mlx_image
|
||||||
|
|
||||||
|
|
||||||
|
func _mlx_bridge<T : AnyObject>(obj : T) -> UnsafeMutableRawPointer? {
|
||||||
|
return UnsafeMutableRawPointer(Unmanaged.passUnretained(obj).toOpaque())
|
||||||
|
}
|
||||||
|
|
||||||
|
func _mlx_bridge<T : AnyObject>(ptr : UnsafeRawPointer) -> T {
|
||||||
|
return Unmanaged<T>.fromOpaque(ptr).takeUnretainedValue()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class MlxMain {
|
||||||
|
|
||||||
|
public var winList = [MlxWin]()
|
||||||
|
public var imgList = [MlxImg]()
|
||||||
|
var myMlxApp:NSApplication?
|
||||||
|
public var device:MTLDevice!
|
||||||
|
var loopHook:UnsafeMutableRawPointer?
|
||||||
|
var loopParam:UnsafeMutableRawPointer
|
||||||
|
var loopHookTimer:CFRunLoopTimer?
|
||||||
|
public var inLoop = false
|
||||||
|
|
||||||
|
public init(_ flag:Int = 0)
|
||||||
|
{
|
||||||
|
/// make app with top menubar
|
||||||
|
myMlxApp = NSApplication.shared
|
||||||
|
if (flag == 1)
|
||||||
|
{
|
||||||
|
NSApp.setActivationPolicy(NSApplication.ActivationPolicy.prohibited) /// for non clickable win, no top menu
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSApp.setActivationPolicy(NSApplication.ActivationPolicy.regular)
|
||||||
|
}
|
||||||
|
|
||||||
|
device = MTLCreateSystemDefaultDevice()!
|
||||||
|
loopParam = UnsafeMutableRawPointer(&inLoop) /// dummy addr init
|
||||||
|
|
||||||
|
/// Add observer anyway to flush pixels every loop. If loop_hook exists, call it.
|
||||||
|
var ocontext = CFRunLoopObserverContext(version:0, info:_mlx_bridge(obj:self), retain:nil, release:nil, copyDescription:nil)
|
||||||
|
let observer = CFRunLoopObserverCreate(kCFAllocatorDefault, CFRunLoopActivity.beforeWaiting.rawValue, true, 0, createOCallback(), &ocontext)
|
||||||
|
CFRunLoopAddObserver(CFRunLoopGetMain(), observer, CFRunLoopMode.commonModes)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public func addWinToList(_ win:MlxWin)
|
||||||
|
{ winList.append(win) }
|
||||||
|
public func addImgToList(_ img:MlxImg)
|
||||||
|
{ imgList.append(img) }
|
||||||
|
|
||||||
|
|
||||||
|
func doCallLoopHook()
|
||||||
|
{
|
||||||
|
/// if (loopHook != nil)
|
||||||
|
/// {
|
||||||
|
_ = (unsafeBitCast(loopHook!,to:(@convention(c)(UnsafeRawPointer)->Void).self))(loopParam)
|
||||||
|
/// }
|
||||||
|
}
|
||||||
|
|
||||||
|
func createOCallback() -> CFRunLoopObserverCallBack
|
||||||
|
{
|
||||||
|
return { (cfRunloopObserver, cfrunloopactivity, info) -> Void in
|
||||||
|
let mlx:MlxMain = _mlx_bridge(ptr:info!)
|
||||||
|
mlx.winList.forEach { $0.flushImages() }
|
||||||
|
/// mlx.doCallLoopHook()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func createTCallback() -> CFRunLoopTimerCallBack
|
||||||
|
{
|
||||||
|
return { (cfRunloopTimer, info) -> Void in
|
||||||
|
let mlx:MlxMain = _mlx_bridge(ptr:info!)
|
||||||
|
mlx.doCallLoopHook()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func addLoopHook(_ f:UnsafeMutableRawPointer?, _ p:UnsafeMutableRawPointer)
|
||||||
|
{
|
||||||
|
var tcontext = CFRunLoopTimerContext(version:0, info:_mlx_bridge(obj:self), retain:nil, release:nil, copyDescription:nil)
|
||||||
|
if (loopHook != nil)
|
||||||
|
{
|
||||||
|
CFRunLoopTimerInvalidate(loopHookTimer)
|
||||||
|
}
|
||||||
|
|
||||||
|
loopHook = f
|
||||||
|
loopParam = p
|
||||||
|
if (loopHook != nil)
|
||||||
|
{
|
||||||
|
loopHookTimer = CFRunLoopTimerCreate(kCFAllocatorDefault, 0.0, 0.0001, 0, 0, createTCallback(), &tcontext)
|
||||||
|
CFRunLoopAddTimer(CFRunLoopGetMain(), loopHookTimer, CFRunLoopMode.commonModes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
431
libs/minilibx_mms_20200219/mlx_png.c
Normal file
431
libs/minilibx_mms_20200219/mlx_png.c
Normal file
@@ -0,0 +1,431 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <err.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#include "zlib.h"
|
||||||
|
|
||||||
|
#include "mlx.h"
|
||||||
|
|
||||||
|
#define UNIQ_BPP 4
|
||||||
|
|
||||||
|
#define PNG_MAGIC_SIZE 8
|
||||||
|
unsigned char magic[PNG_MAGIC_SIZE] = {137, 80, 78, 71, 13, 10, 26, 10};
|
||||||
|
#define PNG_HDR_SIZE 13
|
||||||
|
|
||||||
|
#define Z_CHUNK 32768
|
||||||
|
|
||||||
|
#define ERR_MAGIC_SIZE 1
|
||||||
|
#define ERR_MAGIC_WRONG 2
|
||||||
|
#define ERR_STRUCT_INCOMPLETE 3
|
||||||
|
#define ERR_STRUCT_HDR 4
|
||||||
|
#define ERR_STRUCT_END 5
|
||||||
|
#define ERR_STRUCT_CRC 6
|
||||||
|
#define ERR_STRUCT_INCIMPL 7
|
||||||
|
#define ERR_STRUCT_DAT 8
|
||||||
|
#define ERR_STRUCT_MISSCHK 9
|
||||||
|
#define ERR_ZLIB 10
|
||||||
|
#define ERR_DATA_MISMATCH 11
|
||||||
|
#define ERR_DATA_FILTER 12
|
||||||
|
#define ERR_MALLOC 13
|
||||||
|
char *(mipng_err[]) =
|
||||||
|
{
|
||||||
|
"No error",
|
||||||
|
"Not enough size for magic",
|
||||||
|
"Wrong magic",
|
||||||
|
"Incomplete chunk structure",
|
||||||
|
"Duplicate or incorrect header",
|
||||||
|
"Duplicate or incorrect end",
|
||||||
|
"Invalid CRC in chunk",
|
||||||
|
"Incorrect header or configuration not implemented",
|
||||||
|
"Non consecutive dat chunks",
|
||||||
|
"Missing header/dat/end chunk(s)",
|
||||||
|
"Zlib inflate error",
|
||||||
|
"Inflated data size mismatch",
|
||||||
|
"Unknown scanline filter",
|
||||||
|
"Can't malloc"
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct png_info_s
|
||||||
|
{
|
||||||
|
unsigned int width;
|
||||||
|
unsigned int height;
|
||||||
|
int depth;
|
||||||
|
int color;
|
||||||
|
int interlace;
|
||||||
|
int bpp;
|
||||||
|
} png_info_t;
|
||||||
|
|
||||||
|
|
||||||
|
int mipng_is_type(unsigned char *ptr, char *type)
|
||||||
|
{
|
||||||
|
if (ptr[4] == type[0] && ptr[5] == type[1] && ptr[6] == type[2] && ptr[7] == type[3])
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned char mipng_defilter_none(unsigned char *buff, int pos, int a, int b, int c)
|
||||||
|
{ return (buff[pos]); }
|
||||||
|
unsigned char mipng_defilter_sub(unsigned char *buff, int pos, int a, int b, int c)
|
||||||
|
{ return (buff[pos]+(unsigned int)a); }
|
||||||
|
unsigned char mipng_defilter_up(unsigned char *buff, int pos, int a, int b, int c)
|
||||||
|
{ return (buff[pos]+(unsigned int)b); }
|
||||||
|
unsigned char mipng_defilter_average(unsigned char *buff, int pos, int a, int b, int c)
|
||||||
|
{ return (buff[pos]+((unsigned int)a+(unsigned int)b)/2); }
|
||||||
|
unsigned char mipng_defilter_paeth(unsigned char *buff, int pos, int a, int b, int c)
|
||||||
|
{
|
||||||
|
int p;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
p = a + b - c;
|
||||||
|
if (abs(b - c) <= abs(a - c) && abs(b - c) <= abs(a + b - c - c))
|
||||||
|
result = a;
|
||||||
|
else
|
||||||
|
if (abs(a - c) <= abs(a + b - c - c))
|
||||||
|
result = b;
|
||||||
|
else
|
||||||
|
result = c;
|
||||||
|
return (buff[pos]+result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
unsigned char (*(mipng_defilter[]))(unsigned char *buff, int pos, int a, int b, int c) =
|
||||||
|
{
|
||||||
|
mipng_defilter_none,
|
||||||
|
mipng_defilter_sub,
|
||||||
|
mipng_defilter_up,
|
||||||
|
mipng_defilter_average,
|
||||||
|
mipng_defilter_paeth
|
||||||
|
};
|
||||||
|
|
||||||
|
// only work for mlx mac or img 32bpp
|
||||||
|
int mipng_fill_img(void *img, unsigned char *buf, png_info_t *pi)
|
||||||
|
{
|
||||||
|
unsigned int current_filter;
|
||||||
|
int ipos;
|
||||||
|
int bpos;
|
||||||
|
int ilen;
|
||||||
|
int iline;
|
||||||
|
int blen;
|
||||||
|
int bpp;
|
||||||
|
int endian;
|
||||||
|
unsigned char tmp;
|
||||||
|
unsigned char *ibuf;
|
||||||
|
|
||||||
|
ibuf = (unsigned char *)mlx_get_data_addr(img, &bpp, &iline, &endian);
|
||||||
|
// iline = img->width * UNIQ_BPP;
|
||||||
|
// ilen = img->width * img->height * UNIQ_BPP;
|
||||||
|
ilen = iline*pi->height;
|
||||||
|
ipos = 0;
|
||||||
|
blen = pi->width * pi->height * pi->bpp + pi->height; // ??? why + pi->height ??
|
||||||
|
bpos = 0;
|
||||||
|
while (ipos < ilen && bpos < blen)
|
||||||
|
{
|
||||||
|
if (ipos % iline == 0)
|
||||||
|
{
|
||||||
|
// printf("ipos %d iline %d pi->width %d bpos %d\n", ipos, iline, pi->width, bpos);
|
||||||
|
if ((current_filter = buf[bpos++]) > 4)
|
||||||
|
{
|
||||||
|
return (ERR_DATA_FILTER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ibuf[ipos] = mipng_defilter[current_filter](buf, bpos,
|
||||||
|
ipos%iline>3?ibuf[ipos-UNIQ_BPP]:0,
|
||||||
|
(ipos>=iline)?ibuf[ipos-iline]:0,
|
||||||
|
(ipos>=iline && ipos%iline>3)?ibuf[ipos-iline-UNIQ_BPP]:0);
|
||||||
|
ipos ++;
|
||||||
|
bpos ++;
|
||||||
|
if (pi->depth == 16)
|
||||||
|
bpos ++;
|
||||||
|
if (ipos % 4 == 3 && pi->color == 2) // no alpha
|
||||||
|
ibuf[ipos++] = 0xFF;
|
||||||
|
if (ipos % iline == pi->width * 4)
|
||||||
|
ipos += iline-pi->width*4;
|
||||||
|
}
|
||||||
|
if (ipos != ilen || bpos != blen)
|
||||||
|
{
|
||||||
|
// printf("fill err ipos %d vs %d, bpos %d vs %d\n", ipos, ilen, bpos, blen);
|
||||||
|
return (ERR_DATA_MISMATCH);
|
||||||
|
}
|
||||||
|
ipos = 0;
|
||||||
|
while (ipos < ilen)
|
||||||
|
{
|
||||||
|
tmp = ibuf[ipos];
|
||||||
|
ibuf[ipos] = ibuf[ipos+2];
|
||||||
|
ibuf[ipos+2] = tmp;
|
||||||
|
ibuf[ipos+3] = 0xFF - ibuf[ipos+3];
|
||||||
|
ipos += UNIQ_BPP;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mipng_data(void *img, unsigned char *dat, png_info_t *pi)
|
||||||
|
{
|
||||||
|
unsigned int len;
|
||||||
|
int b_pos;
|
||||||
|
unsigned char *buffer;
|
||||||
|
int ret;
|
||||||
|
int z_ret;
|
||||||
|
unsigned z_have;
|
||||||
|
z_stream z_strm;
|
||||||
|
unsigned char z_out[Z_CHUNK];
|
||||||
|
|
||||||
|
b_pos = 0;
|
||||||
|
if (!(buffer = malloc((long long)pi->width*(long long)pi->height*(long long)pi->bpp + pi->height)))
|
||||||
|
return (ERR_MALLOC);
|
||||||
|
z_strm.zalloc = Z_NULL;
|
||||||
|
z_strm.zfree = Z_NULL;
|
||||||
|
z_strm.opaque = Z_NULL;
|
||||||
|
z_strm.avail_in = 0;
|
||||||
|
z_strm.next_in = Z_NULL;
|
||||||
|
z_ret = inflateInit(&z_strm);
|
||||||
|
if (z_ret != Z_OK)
|
||||||
|
{
|
||||||
|
free(buffer);
|
||||||
|
return (ERR_ZLIB);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (mipng_is_type(dat, "IDAT"))
|
||||||
|
{
|
||||||
|
len = *((unsigned int *)dat);
|
||||||
|
len = ntohl(len);
|
||||||
|
z_strm.avail_in = len;
|
||||||
|
z_strm.next_in = dat + 8;
|
||||||
|
z_strm.avail_out = 0;
|
||||||
|
while (z_strm.avail_out == 0)
|
||||||
|
{
|
||||||
|
z_strm.avail_out = Z_CHUNK;
|
||||||
|
z_strm.next_out = z_out;
|
||||||
|
z_ret = inflate(&z_strm, Z_NO_FLUSH);
|
||||||
|
// printf("inflate ret %d avail_out %d\n", z_ret, z_strm.avail_out);
|
||||||
|
if (z_ret != Z_OK && z_ret != Z_STREAM_END)
|
||||||
|
{
|
||||||
|
inflateEnd(&z_strm);
|
||||||
|
free(buffer);
|
||||||
|
return (ERR_ZLIB);
|
||||||
|
}
|
||||||
|
if (b_pos + Z_CHUNK - z_strm.avail_out > pi->width*pi->height*pi->bpp+pi->height)
|
||||||
|
{
|
||||||
|
inflateEnd(&z_strm);
|
||||||
|
free(buffer);
|
||||||
|
return (ERR_DATA_MISMATCH);
|
||||||
|
}
|
||||||
|
bcopy(z_out, buffer+b_pos, Z_CHUNK - z_strm.avail_out);
|
||||||
|
b_pos += Z_CHUNK - z_strm.avail_out;
|
||||||
|
}
|
||||||
|
dat += len + 4 + 4 + 4;
|
||||||
|
}
|
||||||
|
inflateEnd(&z_strm);
|
||||||
|
if (b_pos != pi->width*pi->height*pi->bpp+pi->height)
|
||||||
|
{
|
||||||
|
// printf("pb : bpos %d vs expected %d\n", b_pos, img->width*img->height*pi->bpp+img->height);
|
||||||
|
free(buffer);
|
||||||
|
return (ERR_DATA_MISMATCH);
|
||||||
|
}
|
||||||
|
ret = mipng_fill_img(img, buffer, pi);
|
||||||
|
free(buffer);
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int mipng_magic(unsigned char *ptr, int size)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (size < PNG_MAGIC_SIZE)
|
||||||
|
return (ERR_MAGIC_SIZE);
|
||||||
|
i = 0;
|
||||||
|
while (i < PNG_MAGIC_SIZE)
|
||||||
|
if (*(ptr++) != magic[i++])
|
||||||
|
return (ERR_MAGIC_WRONG);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned long crc_table[256] = { 0, 0x77073096, 0xee0e612c, 0x990951ba, 0x76dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0xedb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x9b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x1db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x6b6b51f, 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0xf00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x86d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x3b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x4db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, 0xd6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0xa00ae27, 0x7d079eb1, 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x26d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x5005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0xcb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0xbdbdf21, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d };
|
||||||
|
|
||||||
|
// From http://www.w3.org/TR/PNG/#D-CRCAppendix
|
||||||
|
int mipng_crc(unsigned char *ptr, int len)
|
||||||
|
{
|
||||||
|
unsigned int file_crc;
|
||||||
|
unsigned long crc;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
file_crc = *((unsigned int *)(ptr+4+4+len));
|
||||||
|
file_crc = ntohl(file_crc);
|
||||||
|
|
||||||
|
crc = 0xffffffffL;
|
||||||
|
i = 0;
|
||||||
|
while (i < len+4)
|
||||||
|
crc = crc_table[(crc ^ ptr[(i++)+4]) & 0xff] ^ (crc >> 8);
|
||||||
|
crc ^= 0xffffffffL;
|
||||||
|
|
||||||
|
if (file_crc != crc)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mipng_structure(unsigned char *ptr, int size, unsigned char **hdr, unsigned char **dat)
|
||||||
|
{
|
||||||
|
unsigned int len;
|
||||||
|
int dat_state;
|
||||||
|
int end;
|
||||||
|
|
||||||
|
dat_state = 0;
|
||||||
|
*hdr = NULL;
|
||||||
|
*dat = NULL;
|
||||||
|
end = 0;
|
||||||
|
while (size)
|
||||||
|
{
|
||||||
|
if (size >= 4) // length present
|
||||||
|
{
|
||||||
|
len = *((unsigned int *)ptr);
|
||||||
|
len = ntohl(len);
|
||||||
|
if (size < 4 + 4 + 4 + len)
|
||||||
|
return (ERR_STRUCT_INCOMPLETE);
|
||||||
|
if (mipng_crc(ptr, len))
|
||||||
|
return (ERR_STRUCT_CRC);
|
||||||
|
// printf("found chunk len %d type %c%c%c%c\n", len, *(ptr+4), *(ptr+5), *(ptr+6), *(ptr+7));
|
||||||
|
if (mipng_is_type(ptr, "IHDR"))
|
||||||
|
{
|
||||||
|
if (*hdr || len != PNG_HDR_SIZE)
|
||||||
|
return (ERR_STRUCT_HDR);
|
||||||
|
*hdr = ptr;
|
||||||
|
}
|
||||||
|
if (mipng_is_type(ptr, "IEND"))
|
||||||
|
{
|
||||||
|
if (len != 0 || size != 4+4+4)
|
||||||
|
return (ERR_STRUCT_END);
|
||||||
|
end = 1;
|
||||||
|
}
|
||||||
|
if (mipng_is_type(ptr, "IDAT"))
|
||||||
|
{
|
||||||
|
if (dat_state == 0)
|
||||||
|
{
|
||||||
|
dat_state = 1;
|
||||||
|
*dat = ptr;
|
||||||
|
}
|
||||||
|
if (dat_state == 2)
|
||||||
|
return (ERR_STRUCT_DAT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (dat_state == 1)
|
||||||
|
dat_state = 2;
|
||||||
|
size -= 4+4+4+len;
|
||||||
|
ptr += 4+4+4+len;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return (ERR_STRUCT_INCOMPLETE);
|
||||||
|
}
|
||||||
|
if (*hdr == 0 || *dat == 0 || end == 0)
|
||||||
|
return (ERR_STRUCT_MISSCHK);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mipng_verif_hdr(unsigned char *hdr, png_info_t *pi)
|
||||||
|
{
|
||||||
|
unsigned int compress;
|
||||||
|
unsigned int filter;
|
||||||
|
|
||||||
|
hdr += 8;
|
||||||
|
pi->width = ntohl(*((unsigned long *)hdr));
|
||||||
|
pi->height = ntohl(*((unsigned long *)(hdr+4)));
|
||||||
|
pi->depth = *(hdr+8);
|
||||||
|
pi->color = *(hdr+9);
|
||||||
|
compress = *(hdr+10);
|
||||||
|
filter = *(hdr+11);
|
||||||
|
pi->interlace = *(hdr+12);
|
||||||
|
if (pi->width <= 0 || pi->height <= 0 || (pi->depth != 8 && pi->depth != 16)
|
||||||
|
|| (pi->color != 2 && pi->color != 6) || compress != 0 || filter != 0 || pi->interlace != 0)
|
||||||
|
return (ERR_STRUCT_INCIMPL);
|
||||||
|
pi->bpp = pi->depth / 8;
|
||||||
|
if (pi->color == 2)
|
||||||
|
pi->bpp *= 3;
|
||||||
|
if (pi->color == 6)
|
||||||
|
pi->bpp *= 4;
|
||||||
|
// printf("hdr info : %d x %d, depth %d, col type %d, comp %d, filter %d, interlace %d\nbpp is %d\n",
|
||||||
|
// pi->width, pi->height, pi->depth, pi->color, compress, filter, pi->interlace, pi->bpp);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void *mlx_int_parse_png(void *xvar, unsigned char *fptr, int size, int *width, int *height)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
unsigned char *hdr;
|
||||||
|
unsigned char *dat;
|
||||||
|
png_info_t pi;
|
||||||
|
void *img;
|
||||||
|
|
||||||
|
if ((err = mipng_magic(fptr, size)))
|
||||||
|
{
|
||||||
|
warnx("mlx PNG error : %s", mipng_err[err]);
|
||||||
|
return ((void *)0);
|
||||||
|
}
|
||||||
|
fptr += PNG_MAGIC_SIZE;
|
||||||
|
size -= PNG_MAGIC_SIZE;
|
||||||
|
if ((err = mipng_structure(fptr, size, &hdr, &dat)))
|
||||||
|
{
|
||||||
|
warnx("mlx PNG error : %s", mipng_err[err]);
|
||||||
|
return ((void *)0);
|
||||||
|
}
|
||||||
|
if ((err = mipng_verif_hdr(hdr, &pi)))
|
||||||
|
{
|
||||||
|
warnx("mlx PNG error : %s", mipng_err[err]);
|
||||||
|
return ((void *)0);
|
||||||
|
}
|
||||||
|
if (!(img = mlx_new_image(xvar, pi.width, pi.height)))
|
||||||
|
{
|
||||||
|
warnx("mlx PNG error : Can't create mlx image");
|
||||||
|
return ((void *)0);
|
||||||
|
}
|
||||||
|
*width = pi.width;
|
||||||
|
*height = pi.height;
|
||||||
|
if ((err = mipng_data(img, dat, &pi)))
|
||||||
|
{
|
||||||
|
mlx_destroy_image(xvar, img);
|
||||||
|
warnx("mlx PNG error : %s", mipng_err[err]);
|
||||||
|
return ((void *)0);
|
||||||
|
}
|
||||||
|
return (img);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void *mlx_png_file_to_image(void *xvar, char *file, int *width, int *height)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
int size;
|
||||||
|
unsigned char *ptr;
|
||||||
|
void *img;
|
||||||
|
|
||||||
|
if ((fd = open(file, O_RDONLY)) == -1 || (size = lseek(fd, 0, SEEK_END)) == -1 ||
|
||||||
|
(ptr = mmap(0, size, PROT_READ, MAP_PRIVATE, fd, 0)) == (void *)MAP_FAILED)
|
||||||
|
{
|
||||||
|
if (fd >= 0)
|
||||||
|
close(fd);
|
||||||
|
warnx("Can't map png file '%s'", file);
|
||||||
|
return ((void *)0);
|
||||||
|
}
|
||||||
|
if (!(img = mlx_int_parse_png(xvar, ptr, size, width, height)))
|
||||||
|
{
|
||||||
|
*width = 0;
|
||||||
|
*height = 0;
|
||||||
|
}
|
||||||
|
munmap(ptr,size);
|
||||||
|
close(fd);
|
||||||
|
return (img);
|
||||||
|
}
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
** the XFree86 distribution.
|
** the XFree86 distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "mlx_int.h"
|
|
||||||
|
|
||||||
struct s_col_name mlx_col_name[] =
|
struct s_col_name mlx_col_name[] =
|
||||||
{
|
{
|
||||||
72
libs/minilibx_mms_20200219/mlx_string_put.c
Normal file
72
libs/minilibx_mms_20200219/mlx_string_put.c
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
|
||||||
|
#include "mlx.h"
|
||||||
|
|
||||||
|
#include "font.c"
|
||||||
|
|
||||||
|
#define ATLAS_NB_CHAR 95
|
||||||
|
|
||||||
|
#define FONT_WIDTH ((font_atlas.width/(ATLAS_NB_CHAR))-2)
|
||||||
|
|
||||||
|
|
||||||
|
int mlx_put_image_to_window_scale(void *mlx_ptr, void *win_ptr, void *img_ptr, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, unsigned int color);
|
||||||
|
|
||||||
|
void mlx_int_fill(unsigned char *data, int sl)
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
j = 0;
|
||||||
|
while (j < font_atlas.height)
|
||||||
|
{
|
||||||
|
i = 0;
|
||||||
|
while (i < font_atlas.width)
|
||||||
|
{
|
||||||
|
data[j*sl+i*4] = font_atlas.pixel_data[j*font_atlas.width*font_atlas.bytes_per_pixel+i*4+2];
|
||||||
|
data[j*sl+i*4+1] = font_atlas.pixel_data[j*font_atlas.width*font_atlas.bytes_per_pixel+i*4+1];
|
||||||
|
data[j*sl+i*4+2] = font_atlas.pixel_data[j*font_atlas.width*font_atlas.bytes_per_pixel+i*4];
|
||||||
|
data[j*sl+i*4+3] = 0xFF - font_atlas.pixel_data[j*font_atlas.width*font_atlas.bytes_per_pixel+i*4+3];
|
||||||
|
i ++;
|
||||||
|
}
|
||||||
|
j ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mlx_string_put(void *mlx_ptr, void *win_ptr, int x, int y, int color, char *string)
|
||||||
|
{
|
||||||
|
static void *font = (void *)0;
|
||||||
|
static unsigned char *data = (void *)0;
|
||||||
|
static int size_line = 0;
|
||||||
|
int bpp;
|
||||||
|
int endian;
|
||||||
|
int pos;
|
||||||
|
int val;
|
||||||
|
int dest_w;
|
||||||
|
int dest_h;
|
||||||
|
|
||||||
|
if (font == (void *)0)
|
||||||
|
{
|
||||||
|
font = mlx_new_image(mlx_ptr, font_atlas.width, font_atlas.height);
|
||||||
|
data = (unsigned char *)mlx_get_data_addr(font, &bpp, &size_line, &endian);
|
||||||
|
mlx_int_fill(data, size_line);
|
||||||
|
}
|
||||||
|
|
||||||
|
color = (color&0xFFFFFF)|0xFF000000;
|
||||||
|
|
||||||
|
// dest_w = (FONT_WIDTH*5)/7; /// ratio with X11 standard mlx_string_put
|
||||||
|
// dest_h = (font_atlas.height*5)/7;
|
||||||
|
dest_w = FONT_WIDTH;
|
||||||
|
dest_h = font_atlas.height;
|
||||||
|
y = y - (dest_h*3)/4;
|
||||||
|
|
||||||
|
pos = 0;
|
||||||
|
while (*string)
|
||||||
|
{
|
||||||
|
if (*string >= 32 && *string <= 127)
|
||||||
|
val = *string - 32;
|
||||||
|
else
|
||||||
|
val = 31;
|
||||||
|
mlx_put_image_to_window_scale(mlx_ptr, win_ptr, font, val*(FONT_WIDTH+2), 0, FONT_WIDTH, font_atlas.height, x+pos*dest_w, y, dest_w, dest_h, color);
|
||||||
|
pos ++;
|
||||||
|
string ++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
541
libs/minilibx_mms_20200219/mlx_window.swift
Normal file
541
libs/minilibx_mms_20200219/mlx_window.swift
Normal file
@@ -0,0 +1,541 @@
|
|||||||
|
|
||||||
|
import Cocoa
|
||||||
|
import Metal
|
||||||
|
import MetalKit
|
||||||
|
import Darwin
|
||||||
|
|
||||||
|
import mlx_image
|
||||||
|
|
||||||
|
|
||||||
|
class WinEvent: NSWindow
|
||||||
|
{
|
||||||
|
var eventFuncts = [UnsafeMutableRawPointer?]()
|
||||||
|
var eventParams = [UnsafeMutableRawPointer]()
|
||||||
|
|
||||||
|
var keyrepeat = 1
|
||||||
|
var keyflag:UInt32 = 0
|
||||||
|
|
||||||
|
var size_y:Int
|
||||||
|
|
||||||
|
init(frame rect:CGRect)
|
||||||
|
{
|
||||||
|
for _ in 0...31
|
||||||
|
{
|
||||||
|
eventFuncts.append(Optional.none)
|
||||||
|
eventParams.append(UnsafeMutableRawPointer(&keyrepeat)) /// dummy address here, null not needed
|
||||||
|
}
|
||||||
|
|
||||||
|
let wsm = NSWindow.StyleMask(rawValue: NSWindow.StyleMask.titled.rawValue|NSWindow.StyleMask.closable.rawValue|NSWindow.StyleMask.miniaturizable.rawValue)
|
||||||
|
let bck = NSWindow.BackingStoreType.buffered
|
||||||
|
size_y = Int(rect.size.height)
|
||||||
|
super.init(contentRect: rect, styleMask: wsm, backing: bck, defer: false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setNotifs()
|
||||||
|
{
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(exposeNotification(_:)), name: NSWindow.didBecomeKeyNotification, object: nil)
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(deminiaturizeNotification(_:)), name: NSWindow.didDeminiaturizeNotification, object: nil)
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(closeNotification(_:)), name: NSWindow.willCloseNotification, object: nil)
|
||||||
|
|
||||||
|
/***
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:win selector:@selector(exposeNotification:) name:@"NSWindowDidBecomeKeyNotification" object:win];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:win selector:@selector(deminiaturizeNotification:) name:@"NSWindowDidDeminiaturizeNotification" object:win];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:win selector:@selector(closeNotification:) name:@"NSWindowWillCloseNotification" object:win];
|
||||||
|
***/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func delNotifs()
|
||||||
|
{
|
||||||
|
NotificationCenter.default.removeObserver(self, name: NSWindow.willCloseNotification, object: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func setKeyRepeat(_ mode:Int)
|
||||||
|
{
|
||||||
|
keyrepeat = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func addHook(index idx:Int, fct fptr:UnsafeMutableRawPointer?, param pptr:UnsafeMutableRawPointer)
|
||||||
|
{
|
||||||
|
eventFuncts[idx] = fptr;
|
||||||
|
eventParams[idx] = pptr;
|
||||||
|
if (idx == 6 || idx == 32)
|
||||||
|
{
|
||||||
|
if (fptr != nil) /// == nullptr)
|
||||||
|
{ self.acceptsMouseMovedEvents = true }
|
||||||
|
else { self.acceptsMouseMovedEvents = false }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
override func keyDown(with event: NSEvent)
|
||||||
|
{
|
||||||
|
/// print("got keydown with code: \(event.keyCode) ")
|
||||||
|
if (event.isARepeat && keyrepeat == 0)
|
||||||
|
{ return }
|
||||||
|
if (eventFuncts[2] != nil)
|
||||||
|
{
|
||||||
|
_ = unsafeBitCast(eventFuncts[2],to:(@convention(c)(Int32, UnsafeRawPointer)->Int32).self)(Int32(event.keyCode), eventParams[2])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
override func keyUp(with event: NSEvent)
|
||||||
|
{
|
||||||
|
/// print("got keyup with code: \(event.keyCode) and calling key hook")
|
||||||
|
if (event.isARepeat && keyrepeat == 0)
|
||||||
|
{ return }
|
||||||
|
if (eventFuncts[3] != nil)
|
||||||
|
{
|
||||||
|
_ = unsafeBitCast(eventFuncts[3],to:(@convention(c)(Int32, UnsafeRawPointer)->Int32).self)(Int32(event.keyCode), eventParams[3])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func get_mouse_button(with ev:NSEvent) -> Int
|
||||||
|
{
|
||||||
|
switch (ev.type) {
|
||||||
|
case NSEvent.EventType.leftMouseDown,
|
||||||
|
NSEvent.EventType.leftMouseUp,
|
||||||
|
NSEvent.EventType.leftMouseDragged:
|
||||||
|
return 1;
|
||||||
|
case NSEvent.EventType.rightMouseDown,
|
||||||
|
NSEvent.EventType.rightMouseUp,
|
||||||
|
NSEvent.EventType.rightMouseDragged:
|
||||||
|
return 2;
|
||||||
|
case NSEvent.EventType.otherMouseDown,
|
||||||
|
NSEvent.EventType.otherMouseUp,
|
||||||
|
NSEvent.EventType.otherMouseDragged:
|
||||||
|
return 3;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func mouse(with event: NSEvent, index idx:Int, type t:Int)
|
||||||
|
{
|
||||||
|
var thepoint:NSPoint
|
||||||
|
var button:Int
|
||||||
|
|
||||||
|
thepoint = event.locationInWindow
|
||||||
|
button = get_mouse_button(with:event)
|
||||||
|
/// button = event.buttonNumber
|
||||||
|
/// print(" mouse down button \(event.buttonNumber) at location \(thepoint.x) x \(thepoint.y)")
|
||||||
|
if (eventFuncts[idx] != nil)
|
||||||
|
{
|
||||||
|
if (t == 0)
|
||||||
|
{ _ = unsafeBitCast(eventFuncts[idx],to:(@convention(c)(Int32, Int32, Int32, UnsafeRawPointer)->Int32).self)(Int32(button), Int32(thepoint.x), Int32(size_y-1-Int(thepoint.y)), eventParams[idx]) }
|
||||||
|
if (t == 1)
|
||||||
|
{ _ = unsafeBitCast(eventFuncts[idx],to:(@convention(c)(Int32, Int32, UnsafeRawPointer)->Int32).self)(Int32(thepoint.x), Int32(size_y-1-Int(thepoint.y)), eventParams[idx]) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override func mouseDown(with event: NSEvent) { mouse(with:event, index:4, type:0) }
|
||||||
|
override func rightMouseDown(with event: NSEvent) { mouse(with:event, index:4, type:0) }
|
||||||
|
override func otherMouseDown(with event: NSEvent) { mouse(with:event, index:4, type:0) }
|
||||||
|
|
||||||
|
override func mouseUp(with event: NSEvent) { mouse(with:event, index:5, type:0) }
|
||||||
|
override func rightMouseUp(with event: NSEvent) { mouse(with:event, index:5, type:0) }
|
||||||
|
override func otherMouseUp(with event: NSEvent) { mouse(with:event, index:5, type:0) }
|
||||||
|
|
||||||
|
override func mouseMoved(with event: NSEvent) { mouse(with:event, index:6, type:1) }
|
||||||
|
override func mouseDragged(with event: NSEvent) { mouse(with:event, index:6, type:1) }
|
||||||
|
override func rightMouseDragged(with event: NSEvent) { mouse(with:event, index:6, type:1) }
|
||||||
|
override func otherMouseDragged(with event: NSEvent) { mouse(with:event, index:6, type:1) }
|
||||||
|
|
||||||
|
|
||||||
|
override func scrollWheel(with event: NSEvent)
|
||||||
|
{
|
||||||
|
var thepoint:NSPoint
|
||||||
|
var button = 0;
|
||||||
|
|
||||||
|
thepoint = event.locationInWindow
|
||||||
|
if (event.deltaY > 0.2) { button = 4; }
|
||||||
|
if (event.deltaY < -0.2) { button = 5; }
|
||||||
|
if (event.deltaX > 0.2) { button = 6; }
|
||||||
|
if (event.deltaX < -0.2) { button = 7; }
|
||||||
|
if (button != 0 && eventFuncts[4] != nil)
|
||||||
|
{
|
||||||
|
_ = unsafeBitCast(eventFuncts[4],to:(@convention(c)(Int32, Int32, Int32, UnsafeRawPointer)->Int32).self)(Int32(button), Int32(thepoint.x), Int32(thepoint.y), eventParams[4])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
override func flagsChanged(with event: NSEvent)
|
||||||
|
{
|
||||||
|
var flag:UInt32
|
||||||
|
var the_key:Int32
|
||||||
|
var val:UInt32
|
||||||
|
|
||||||
|
flag = UInt32(event.modifierFlags.rawValue)
|
||||||
|
val = (keyflag|flag)&(~(keyflag&flag))
|
||||||
|
if (val == 0)
|
||||||
|
{ return } /// no change - can happen when loosing focus on special key pressed, then re-pressed later
|
||||||
|
the_key = 1
|
||||||
|
while (((val >> (the_key-1)) & 0x01)==0)
|
||||||
|
{ the_key += 1 }
|
||||||
|
if (flag > keyflag && eventFuncts[2] != nil)
|
||||||
|
{ _ = unsafeBitCast(eventFuncts[2],to:(@convention(c)(Int32, UnsafeRawPointer)->Int32).self)(0xFF+the_key, eventParams[2]) }
|
||||||
|
if (flag < keyflag && eventFuncts[3] != nil)
|
||||||
|
{ _ = unsafeBitCast(eventFuncts[3],to:(@convention(c)(Int32, UnsafeRawPointer)->Int32).self)(0xFF+the_key, eventParams[3]) }
|
||||||
|
keyflag = flag
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@objc func exposeNotification(_ notification:Notification)
|
||||||
|
{
|
||||||
|
if (eventFuncts[12] != nil)
|
||||||
|
{
|
||||||
|
_ = unsafeBitCast(eventFuncts[12],to:(@convention(c)(UnsafeRawPointer)->Int32).self)(eventParams[12])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func closeNotification(_ notification:Notification)
|
||||||
|
{
|
||||||
|
if (eventFuncts[17] != nil)
|
||||||
|
{
|
||||||
|
_ = unsafeBitCast(eventFuncts[17],to:(@convention(c)(UnsafeRawPointer)->Int32).self)(eventParams[17])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func deminiaturizeNotification(_ notification:Notification)
|
||||||
|
{
|
||||||
|
exposeNotification(notification)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct textureList
|
||||||
|
{
|
||||||
|
var uniformBuffer: MTLBuffer!
|
||||||
|
var uniform_data:UnsafeMutablePointer<Float>
|
||||||
|
unowned var image:MlxImg
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class MlxWin
|
||||||
|
{
|
||||||
|
let vrect: CGRect
|
||||||
|
var winE: WinEvent
|
||||||
|
var mlayer: CAMetalLayer
|
||||||
|
|
||||||
|
unowned var device: MTLDevice
|
||||||
|
var commandQueue: MTLCommandQueue!
|
||||||
|
var pipelineState: MTLRenderPipelineState!
|
||||||
|
var vertexBuffer: MTLBuffer!
|
||||||
|
|
||||||
|
var texture_list: Array<textureList> = Array()
|
||||||
|
var texture_list_count = 0
|
||||||
|
|
||||||
|
var pixel_image:MlxImg
|
||||||
|
var pixel_count:Int
|
||||||
|
|
||||||
|
var drawable_image: MlxImg
|
||||||
|
var uniq_renderPassDescriptor: MTLRenderPassDescriptor
|
||||||
|
var mtl_origin_null : MTLOrigin
|
||||||
|
var mtl_size_all : MTLSize
|
||||||
|
var doClear = false
|
||||||
|
var GPUbatch = 0
|
||||||
|
|
||||||
|
|
||||||
|
public init(device d:MTLDevice, width w:Int, height h:Int, title t:String)
|
||||||
|
{
|
||||||
|
vrect = CGRect(x: 100, y: 100, width: w, height: h)
|
||||||
|
winE = WinEvent(frame: vrect)
|
||||||
|
|
||||||
|
device = d
|
||||||
|
mlayer = CAMetalLayer()
|
||||||
|
mlayer.device = device
|
||||||
|
mlayer.pixelFormat = .bgra8Unorm
|
||||||
|
mlayer.framebufferOnly = true
|
||||||
|
mlayer.contentsScale = 1.0 /// winE.screen!.backingScaleFactor
|
||||||
|
mlayer.frame = vrect
|
||||||
|
winE.contentView! = NSView(frame: vrect)
|
||||||
|
winE.contentView!.wantsLayer = true
|
||||||
|
winE.contentView!.layer = mlayer
|
||||||
|
winE.title = t
|
||||||
|
winE.isReleasedWhenClosed = false
|
||||||
|
winE.makeKeyAndOrderFront(nil)
|
||||||
|
|
||||||
|
|
||||||
|
/// drawable_image = MlxImg(d: device, w:Int(CGFloat(vrect.size.width)*winE.screen!.backingScaleFactor), h:Int(CGFloat(vrect.size.height)*winE.screen!.backingScaleFactor), t:1)
|
||||||
|
drawable_image = MlxImg(d: device, w:Int(vrect.size.width), h:Int(vrect.size.height), t:1)
|
||||||
|
pixel_image = MlxImg(d: device, w:Int(vrect.size.width), h:Int(vrect.size.height))
|
||||||
|
for i in 0...(pixel_image.texture_height*pixel_image.texture_sizeline/4-1)
|
||||||
|
{ pixel_image.texture_data[i] = UInt32(0xFF000000) }
|
||||||
|
pixel_count = 0
|
||||||
|
|
||||||
|
mtl_origin_null = MTLOriginMake(0,0,0)
|
||||||
|
mtl_size_all = MTLSizeMake(drawable_image.texture.width, drawable_image.texture.height, 1)
|
||||||
|
|
||||||
|
uniq_renderPassDescriptor = MTLRenderPassDescriptor()
|
||||||
|
uniq_renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColor(red: 0.0, green: 0.0, blue: 0.0, alpha:0.0)
|
||||||
|
uniq_renderPassDescriptor.colorAttachments[0].texture = drawable_image.texture
|
||||||
|
uniq_renderPassDescriptor.colorAttachments[0].storeAction = .store
|
||||||
|
uniq_renderPassDescriptor.colorAttachments[0].loadAction = .load
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// winEvent calls
|
||||||
|
public func getWinEFrame() -> NSRect { return winE.frame }
|
||||||
|
public func getScreenFrame() -> NSRect { return winE.screen!.frame }
|
||||||
|
public func getMouseLoc() -> NSPoint { return winE.mouseLocationOutsideOfEventStream }
|
||||||
|
public func addHook(index idx:Int, fct fptr:UnsafeMutableRawPointer, param pptr:UnsafeMutableRawPointer)
|
||||||
|
{ winE.addHook(index: idx, fct: fptr, param: pptr) }
|
||||||
|
public func setKeyRepeat(_ mode:Int) { winE.setKeyRepeat(mode) }
|
||||||
|
public func destroyWinE() { winE.close() }
|
||||||
|
public func setNotifs() { winE.setNotifs() }
|
||||||
|
public func delNotifs() { winE.delNotifs() }
|
||||||
|
|
||||||
|
|
||||||
|
public func initMetal()
|
||||||
|
{
|
||||||
|
commandQueue = device.makeCommandQueue()!
|
||||||
|
|
||||||
|
/// vertex buffer & shaders stay the always the same.
|
||||||
|
let lib = try! device.makeLibrary(source: shaders, options: nil)
|
||||||
|
let vertexFunction = lib.makeFunction(name: "basic_vertex_function")
|
||||||
|
let fragmentFunction = lib.makeFunction(name: "basic_fragment_function")
|
||||||
|
let pipelineDesc = MTLRenderPipelineDescriptor()
|
||||||
|
pipelineDesc.colorAttachments[0].pixelFormat = .bgra8Unorm
|
||||||
|
pipelineDesc.colorAttachments[0].isBlendingEnabled = true
|
||||||
|
pipelineDesc.colorAttachments[0].rgbBlendOperation = .add
|
||||||
|
pipelineDesc.colorAttachments[0].alphaBlendOperation = .add
|
||||||
|
pipelineDesc.colorAttachments[0].sourceRGBBlendFactor = .oneMinusSourceAlpha
|
||||||
|
pipelineDesc.colorAttachments[0].sourceAlphaBlendFactor = .oneMinusSourceAlpha
|
||||||
|
pipelineDesc.colorAttachments[0].destinationRGBBlendFactor = .sourceAlpha
|
||||||
|
pipelineDesc.colorAttachments[0].destinationAlphaBlendFactor = .sourceAlpha
|
||||||
|
pipelineDesc.vertexFunction = vertexFunction
|
||||||
|
pipelineDesc.fragmentFunction = fragmentFunction
|
||||||
|
pipelineState = try! device.makeRenderPipelineState(descriptor: pipelineDesc)
|
||||||
|
|
||||||
|
let vertexData: [Float] = [
|
||||||
|
-1.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0,
|
||||||
|
-1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0,
|
||||||
|
1.0, -1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0,
|
||||||
|
1.0, -1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0,
|
||||||
|
-1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0,
|
||||||
|
1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0 ]
|
||||||
|
var dataSize = vertexData.count * MemoryLayout.size(ofValue: vertexData[0])
|
||||||
|
vertexBuffer = device.makeBuffer(bytes: vertexData, length: dataSize, options: [])
|
||||||
|
|
||||||
|
let uniformData: [Float] = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Float(vrect.size.width), Float(vrect.size.height), 0.0, 0.0, 0.0, 0.0,
|
||||||
|
1.0, 1.0, 1.0, 1.0 ]
|
||||||
|
dataSize = uniformData.count * MemoryLayout.size(ofValue: uniformData[0])
|
||||||
|
for _ in 0...255
|
||||||
|
{
|
||||||
|
let uniformBuffer = device.makeBuffer(bytes: uniformData, length: dataSize, options: [])!
|
||||||
|
let uniform_data = (uniformBuffer.contents()).assumingMemoryBound(to:Float.self)
|
||||||
|
texture_list.append(textureList(uniformBuffer:uniformBuffer, uniform_data:uniform_data, image:pixel_image))
|
||||||
|
}
|
||||||
|
|
||||||
|
self.clearWin();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public func clearWin()
|
||||||
|
{
|
||||||
|
/// discard previous put_images, doClear become first operation in next render pass.
|
||||||
|
var i = 0
|
||||||
|
while i < texture_list_count
|
||||||
|
{
|
||||||
|
texture_list[i].image.onGPU -= 1
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
texture_list_count = 0
|
||||||
|
doClear = true
|
||||||
|
/// next flush images should call draw(), even if there is no image to put
|
||||||
|
}
|
||||||
|
|
||||||
|
func flushPixels()
|
||||||
|
{
|
||||||
|
if (pixel_count > 0)
|
||||||
|
{
|
||||||
|
pixel_count = 0
|
||||||
|
self.putImage(image:pixel_image, x:0, y:0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func flushImages()
|
||||||
|
{
|
||||||
|
flushPixels()
|
||||||
|
if (texture_list_count > 0 || doClear)
|
||||||
|
{
|
||||||
|
self.draw()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func waitForGPU()
|
||||||
|
{
|
||||||
|
while (GPUbatch > 0) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public func pixelPut(_ x:Int32, _ y:Int32, _ color:UInt32)
|
||||||
|
{
|
||||||
|
if (pixel_count == 0)
|
||||||
|
{
|
||||||
|
while (pixel_image.onGPU > 0)
|
||||||
|
{
|
||||||
|
if (GPUbatch > 0) { waitForGPU() }
|
||||||
|
else { flushImages() }
|
||||||
|
}
|
||||||
|
for i in 0...pixel_image.texture_height*pixel_image.texture_sizeline/4-1
|
||||||
|
{ pixel_image.texture_data[i] = UInt32(0xFF000000) }
|
||||||
|
}
|
||||||
|
let t = (x&(Int32(vrect.size.width-1)-x))&(y&(Int32(vrect.size.height-1)-y))
|
||||||
|
if t >= 0
|
||||||
|
{
|
||||||
|
pixel_image.texture_data[Int(y)*pixel_image.texture_sizeline/4+Int(x)] = color
|
||||||
|
pixel_count += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func putImage(image img:MlxImg, x posx:Int32, y posy:Int32)
|
||||||
|
{
|
||||||
|
flushPixels()
|
||||||
|
putImageScale(image:img, sx:0, sy:0, sw:Int32(img.texture_width), sh:Int32(img.texture_height),
|
||||||
|
dx:posx, dy:posy, dw:Int32(img.texture_width), dh:Int32(img.texture_height),
|
||||||
|
c:UInt32(0xFFFFFFFF))
|
||||||
|
}
|
||||||
|
|
||||||
|
public func putImageScale(image img:MlxImg, sx src_x:Int32, sy src_y:Int32, sw src_w:Int32, sh src_h:Int32, dx dest_x:Int32, dy dest_y:Int32, dw dest_w:Int32, dh dest_h:Int32, c color:UInt32)
|
||||||
|
{
|
||||||
|
flushPixels()
|
||||||
|
if (texture_list_count == 0) /// means I just draw
|
||||||
|
{
|
||||||
|
waitForGPU() /// to be able to write again in uniforms
|
||||||
|
}
|
||||||
|
texture_list[texture_list_count].uniform_data[0] = Float(img.texture_width)
|
||||||
|
texture_list[texture_list_count].uniform_data[1] = Float(img.texture_height)
|
||||||
|
texture_list[texture_list_count].uniform_data[2] = Float(src_x)
|
||||||
|
texture_list[texture_list_count].uniform_data[3] = Float(src_y)
|
||||||
|
texture_list[texture_list_count].uniform_data[4] = Float(src_w)
|
||||||
|
texture_list[texture_list_count].uniform_data[5] = Float(src_h)
|
||||||
|
|
||||||
|
texture_list[texture_list_count].uniform_data[8] = Float(dest_x)
|
||||||
|
texture_list[texture_list_count].uniform_data[9] = Float(dest_y)
|
||||||
|
texture_list[texture_list_count].uniform_data[10] = Float(dest_w)
|
||||||
|
texture_list[texture_list_count].uniform_data[11] = Float(dest_h)
|
||||||
|
|
||||||
|
texture_list[texture_list_count].uniform_data[12] = Float((color>>16)&0xFF)/255.0;
|
||||||
|
texture_list[texture_list_count].uniform_data[13] = Float((color>>8)&0xFF)/255.0;
|
||||||
|
texture_list[texture_list_count].uniform_data[14] = Float((color>>0)&0xFF)/255.0;
|
||||||
|
texture_list[texture_list_count].uniform_data[15] = Float((color>>24)&0xFF)/255.0;
|
||||||
|
|
||||||
|
texture_list[texture_list_count].image = img
|
||||||
|
img.onGPU += 1
|
||||||
|
|
||||||
|
texture_list_count += 1
|
||||||
|
if (texture_list_count == 255) /// keep 1 slot for put_pixels image
|
||||||
|
{
|
||||||
|
flushImages()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func draw()
|
||||||
|
{
|
||||||
|
var commandBuffer = commandQueue.makeCommandBuffer()!
|
||||||
|
|
||||||
|
/// clear if asked
|
||||||
|
if (doClear)
|
||||||
|
{
|
||||||
|
uniq_renderPassDescriptor.colorAttachments[0].loadAction = .clear
|
||||||
|
let commandEncoder = commandBuffer.makeRenderCommandEncoder(descriptor: uniq_renderPassDescriptor)!
|
||||||
|
commandEncoder.endEncoding()
|
||||||
|
uniq_renderPassDescriptor.colorAttachments[0].loadAction = .load
|
||||||
|
doClear = false
|
||||||
|
}
|
||||||
|
|
||||||
|
/// then draw the images if any.
|
||||||
|
var i = 0
|
||||||
|
while i < texture_list_count
|
||||||
|
{
|
||||||
|
let commandEncoder = commandBuffer.makeRenderCommandEncoder(descriptor: uniq_renderPassDescriptor)!
|
||||||
|
commandEncoder.setRenderPipelineState(pipelineState)
|
||||||
|
commandEncoder.setVertexBuffer(vertexBuffer, offset: 0, index: 0)
|
||||||
|
commandEncoder.setVertexBuffer(texture_list[i].uniformBuffer, offset: 0, index: 1)
|
||||||
|
commandEncoder.setFragmentTexture(texture_list[i].image.texture, index: 0)
|
||||||
|
commandEncoder.drawPrimitives(type: .triangleStrip, vertexStart: 0, vertexCount: 6, instanceCount:2)
|
||||||
|
commandEncoder.endEncoding()
|
||||||
|
({ j in
|
||||||
|
commandBuffer.addCompletedHandler { cb in self.texture_list[j].image.onGPU -= 1 }
|
||||||
|
})(i)
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
texture_list_count = 0
|
||||||
|
commandBuffer.addCompletedHandler { cb in self.GPUbatch -= 1 }
|
||||||
|
commandBuffer.commit()
|
||||||
|
GPUbatch += 1
|
||||||
|
|
||||||
|
/// finally copy to MTLdrawable to present, using a new commandqueue
|
||||||
|
commandBuffer = commandQueue.makeCommandBuffer()!
|
||||||
|
let curdraw = mlayer.nextDrawable()!
|
||||||
|
|
||||||
|
let commandBEncoder = commandBuffer.makeBlitCommandEncoder()!
|
||||||
|
commandBEncoder.copy(from:drawable_image.texture, sourceSlice:0, sourceLevel:0, sourceOrigin: mtl_origin_null, sourceSize: mtl_size_all, to:curdraw.texture, destinationSlice:0, destinationLevel:0, destinationOrigin: mtl_origin_null)
|
||||||
|
commandBEncoder.endEncoding()
|
||||||
|
|
||||||
|
commandBuffer.addCompletedHandler { cb in self.GPUbatch -= 1 }
|
||||||
|
commandBuffer.present(curdraw)
|
||||||
|
commandBuffer.commit()
|
||||||
|
GPUbatch += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let shaders = """
|
||||||
|
#include <metal_stdlib>
|
||||||
|
using namespace metal;
|
||||||
|
|
||||||
|
struct VertexIn {
|
||||||
|
float4 position;
|
||||||
|
float4 UV;
|
||||||
|
};
|
||||||
|
struct VertexOut {
|
||||||
|
float4 position [[ position ]];
|
||||||
|
float4 color;
|
||||||
|
float2 UV;
|
||||||
|
};
|
||||||
|
struct uniforms {
|
||||||
|
packed_float2 origin_size;
|
||||||
|
packed_float2 origin_pos;
|
||||||
|
packed_float2 origin_sub;
|
||||||
|
packed_float2 dest_size;
|
||||||
|
packed_float2 dest_pos;
|
||||||
|
packed_float2 dest_sub;
|
||||||
|
packed_float4 color;
|
||||||
|
};
|
||||||
|
vertex VertexOut basic_vertex_function(const device VertexIn *vertices [[ buffer(0) ]], constant uniforms& uni [[ buffer(1) ]],
|
||||||
|
uint vertexID [[ vertex_id ]])
|
||||||
|
{
|
||||||
|
VertexOut vOut;
|
||||||
|
float4 start = float4((2.0*uni.dest_pos.x)/(uni.dest_size.x-1.0) - 1.0, 1.0 - (2.0*uni.dest_pos.y)/(uni.dest_size.y-1.0) - (uni.dest_sub.y*2.0)/uni.dest_size.y, 0.0, 0.0);
|
||||||
|
/* vOut.position = (start + (vertices[vertexID].position + 1.0) * float4(uni.dest_sub, 0.0, 0.0))/float4(uni.dest_size, 1.0, 1.0); */
|
||||||
|
|
||||||
|
vOut.position = float4(start.x+((vertices[vertexID].position.x + 1.0)*uni.dest_sub.x)/(uni.dest_size.x),
|
||||||
|
start.y+((vertices[vertexID].position.y + 1.0)*uni.dest_sub.y)/(uni.dest_size.y), 0.0, 1.0);
|
||||||
|
|
||||||
|
vOut.UV = (uni.origin_pos + float2(vertices[vertexID].UV.x, vertices[vertexID].UV.y)*(uni.origin_sub-1.0))/(uni.origin_size-1.0);
|
||||||
|
vOut.color = uni.color;
|
||||||
|
return vOut;
|
||||||
|
}
|
||||||
|
fragment float4 basic_fragment_function(VertexOut vIn [[ stage_in ]], texture2d<float> texture [[ texture(0) ]])
|
||||||
|
{
|
||||||
|
constexpr sampler textureSampler(address::clamp_to_edge);
|
||||||
|
return vIn.color*texture.sample(textureSampler, vIn.UV);
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
384
libs/minilibx_mms_20200219/mlx_xpm.c
Normal file
384
libs/minilibx_mms_20200219/mlx_xpm.c
Normal file
@@ -0,0 +1,384 @@
|
|||||||
|
// mlx xpm
|
||||||
|
// by ol
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "mlx.h"
|
||||||
|
|
||||||
|
typedef struct s_xpm_col
|
||||||
|
{
|
||||||
|
int name;
|
||||||
|
int col;
|
||||||
|
} t_xpm_col;
|
||||||
|
|
||||||
|
|
||||||
|
struct s_col_name
|
||||||
|
{
|
||||||
|
char *name;
|
||||||
|
int color;
|
||||||
|
};
|
||||||
|
|
||||||
|
//extern struct s_col_name mlx_col_name[];
|
||||||
|
#include "mlx_rgb.c"
|
||||||
|
|
||||||
|
|
||||||
|
#define RETURN { if (colors) free(colors); if (tab) free(tab); \
|
||||||
|
if (colors_direct) free(colors_direct); \
|
||||||
|
if (img) mlx_destroy_image(xvar, img); \
|
||||||
|
return ((void *)0); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// str 2 wordtab & co
|
||||||
|
|
||||||
|
int mlx_int_str_str(char *str,char *find,int len)
|
||||||
|
{
|
||||||
|
int len_f;
|
||||||
|
int pos;
|
||||||
|
char *s;
|
||||||
|
char *f;
|
||||||
|
|
||||||
|
len_f = strlen(find);
|
||||||
|
if (len_f>len)
|
||||||
|
return (-1);
|
||||||
|
pos = 0;
|
||||||
|
while (*(str+len_f-1))
|
||||||
|
{
|
||||||
|
s = str;
|
||||||
|
f = find;
|
||||||
|
while (*(f++) == *(s++))
|
||||||
|
if (!*f)
|
||||||
|
return (pos);
|
||||||
|
str ++;
|
||||||
|
pos ++;
|
||||||
|
}
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int mlx_int_str_str_cote(char *str,char *find,int len)
|
||||||
|
{
|
||||||
|
int len_f;
|
||||||
|
int pos;
|
||||||
|
char *s;
|
||||||
|
char *f;
|
||||||
|
int cote;
|
||||||
|
|
||||||
|
len_f = strlen(find);
|
||||||
|
if (len_f>len)
|
||||||
|
return (-1);
|
||||||
|
cote = 0;
|
||||||
|
pos = 0;
|
||||||
|
while (*(str+len_f-1))
|
||||||
|
{
|
||||||
|
if (*str=='"')
|
||||||
|
cote = 1-cote;
|
||||||
|
if (!cote)
|
||||||
|
{
|
||||||
|
s = str;
|
||||||
|
f = find;
|
||||||
|
while (*(f++) == *(s++))
|
||||||
|
if (!*f)
|
||||||
|
return (pos);
|
||||||
|
}
|
||||||
|
str ++;
|
||||||
|
pos ++;
|
||||||
|
}
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char **mlx_int_str_to_wordtab(char *str)
|
||||||
|
{
|
||||||
|
char **tab;
|
||||||
|
int pos;
|
||||||
|
int nb_word;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
len = strlen(str);
|
||||||
|
nb_word = 0;
|
||||||
|
pos = 0;
|
||||||
|
while (pos<len)
|
||||||
|
{
|
||||||
|
while (*(str+pos)==' ' || *(str+pos)=='\t')
|
||||||
|
pos ++;
|
||||||
|
if (*(str+pos))
|
||||||
|
nb_word ++;
|
||||||
|
while (*(str+pos) && *(str+pos)!=' ' && *(str+pos)!='\t')
|
||||||
|
pos ++;
|
||||||
|
}
|
||||||
|
if (!(tab = malloc((1+nb_word)*sizeof(*tab))))
|
||||||
|
return ((char **)0);
|
||||||
|
nb_word = 0;
|
||||||
|
pos = 0;
|
||||||
|
while (pos<len)
|
||||||
|
{
|
||||||
|
while (*(str+pos)==' ' || *(str+pos)=='\t')
|
||||||
|
{
|
||||||
|
*(str+pos) = 0;
|
||||||
|
pos ++;
|
||||||
|
}
|
||||||
|
if (*(str+pos))
|
||||||
|
{
|
||||||
|
tab[nb_word] = str+pos;
|
||||||
|
nb_word ++;
|
||||||
|
}
|
||||||
|
while (*(str+pos) && *(str+pos)!=' ' && *(str+pos)!='\t')
|
||||||
|
pos ++;
|
||||||
|
}
|
||||||
|
tab[nb_word] = 0;
|
||||||
|
return (tab);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// back to mlx_xpm
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
char *mlx_int_get_line(char *ptr,int *pos,int size)
|
||||||
|
{
|
||||||
|
int pos2;
|
||||||
|
int pos3;
|
||||||
|
int pos4;
|
||||||
|
|
||||||
|
if ((pos2 = mlx_int_str_str(ptr+*pos,"\"",size-*pos))==-1)
|
||||||
|
return ((char *)0);
|
||||||
|
if ((pos3 = mlx_int_str_str(ptr+*pos+pos2+1,"\"",size-*pos-pos2-1))==-1)
|
||||||
|
return ((char *)0);
|
||||||
|
*(ptr+*pos+pos2) = 0;
|
||||||
|
*(ptr+*pos+pos2+1+pos3) = 0;
|
||||||
|
pos4 = *pos+pos2+1;
|
||||||
|
*pos += pos2+pos3+2;
|
||||||
|
return (ptr+pos4);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
char *mlx_int_static_line(char **xpm_data,int *pos,int size)
|
||||||
|
{
|
||||||
|
static char *copy = 0;
|
||||||
|
static int len = 0;
|
||||||
|
int len2;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
str = xpm_data[(*pos)++];
|
||||||
|
if ((len2 = strlen(str))>len)
|
||||||
|
{
|
||||||
|
if (copy)
|
||||||
|
free(copy);
|
||||||
|
if (!(copy = malloc(len2+1)))
|
||||||
|
return ((char *)0);
|
||||||
|
len = len2;
|
||||||
|
}
|
||||||
|
/* strcpy(copy,str); */
|
||||||
|
strlcpy(copy, str, len2+1);
|
||||||
|
return (copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mlx_int_get_col_name(char *str,int size)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
|
result = 0;
|
||||||
|
while (size--)
|
||||||
|
result = (result<<8)+*(str++);
|
||||||
|
return (result);
|
||||||
|
}
|
||||||
|
|
||||||
|
int mlx_int_get_text_rgb(char *name, char *end)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char buff[64];
|
||||||
|
|
||||||
|
if (*name == '#')
|
||||||
|
return (strtol(name+1,0,16));
|
||||||
|
if (end)
|
||||||
|
{
|
||||||
|
snprintf(buff, 64, "%s %s", name, end);
|
||||||
|
name = buff;
|
||||||
|
}
|
||||||
|
i = 0;
|
||||||
|
while (mlx_col_name[i].name)
|
||||||
|
{
|
||||||
|
if (!strcasecmp(mlx_col_name[i].name, name))
|
||||||
|
return (mlx_col_name[i].color);
|
||||||
|
i ++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mlx_int_xpm_set_pixel(char *data, int opp, int col, int x)
|
||||||
|
{
|
||||||
|
*((unsigned int *)(data+4*x)) = col;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void *mlx_int_parse_xpm(void *xvar,void *info,int info_size,char *(*f)(), int *width, int *height)
|
||||||
|
{
|
||||||
|
int pos;
|
||||||
|
char *line;
|
||||||
|
char **tab;
|
||||||
|
char *data;
|
||||||
|
char *clip_data;
|
||||||
|
int nc;
|
||||||
|
int opp;
|
||||||
|
int sl;
|
||||||
|
int endian;
|
||||||
|
int cpp;
|
||||||
|
int col;
|
||||||
|
int rgb_col;
|
||||||
|
int col_name;
|
||||||
|
int method;
|
||||||
|
int x;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
void *img;
|
||||||
|
t_xpm_col *colors;
|
||||||
|
int *colors_direct;
|
||||||
|
|
||||||
|
colors = 0;
|
||||||
|
colors_direct = 0;
|
||||||
|
img = 0;
|
||||||
|
tab = 0;
|
||||||
|
pos = 0;
|
||||||
|
if (!(line = f(info,&pos,info_size)) ||
|
||||||
|
!(tab = mlx_int_str_to_wordtab(line)) || !(*width = atoi(tab[0])) ||
|
||||||
|
!(*height = atoi(tab[1])) || !(nc = atoi(tab[2])) ||
|
||||||
|
!(cpp = atoi(tab[3])) )
|
||||||
|
RETURN;
|
||||||
|
free(tab);
|
||||||
|
tab = 0;
|
||||||
|
|
||||||
|
method = 0;
|
||||||
|
if (cpp<=2)
|
||||||
|
{
|
||||||
|
method = 1;
|
||||||
|
if (!(colors_direct = malloc((cpp==2?65536:256)*sizeof(int))))
|
||||||
|
RETURN;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (!(colors = malloc(nc*sizeof(*colors))))
|
||||||
|
RETURN;
|
||||||
|
|
||||||
|
clip_data = 0;
|
||||||
|
|
||||||
|
i = nc;
|
||||||
|
while (i--)
|
||||||
|
{
|
||||||
|
if (!(line = f(info,&pos,info_size)) ||
|
||||||
|
!(tab = mlx_int_str_to_wordtab(line+cpp)) )
|
||||||
|
RETURN;
|
||||||
|
j = 0;
|
||||||
|
while (tab[j] && strcmp(tab[j++],"c"));
|
||||||
|
|
||||||
|
if (!tab[j])
|
||||||
|
RETURN;
|
||||||
|
|
||||||
|
rgb_col = mlx_int_get_text_rgb(tab[j], tab[j+1]);
|
||||||
|
if (method)
|
||||||
|
colors_direct[mlx_int_get_col_name(line,cpp)] = rgb_col;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
colors[i].name = mlx_int_get_col_name(line,cpp);
|
||||||
|
colors[i].col = rgb_col;
|
||||||
|
}
|
||||||
|
free(tab);
|
||||||
|
tab = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(img = mlx_new_image(xvar,*width,*height)))
|
||||||
|
RETURN;
|
||||||
|
data = mlx_get_data_addr(img, &opp, &sl, &endian);
|
||||||
|
opp = 4;
|
||||||
|
|
||||||
|
i = *height;
|
||||||
|
while (i--)
|
||||||
|
{
|
||||||
|
if (!(line = f(info,&pos,info_size)))
|
||||||
|
RETURN;
|
||||||
|
x = 0;
|
||||||
|
while (x<*width)
|
||||||
|
{
|
||||||
|
col = 0;
|
||||||
|
col_name = mlx_int_get_col_name(line+cpp*x,cpp);
|
||||||
|
if (method)
|
||||||
|
col = colors_direct[col_name];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
j = nc;
|
||||||
|
while (j--)
|
||||||
|
if (colors[j].name==col_name)
|
||||||
|
{
|
||||||
|
col = colors[j].col;
|
||||||
|
j = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (col==-1)
|
||||||
|
col = 0xFF000000;
|
||||||
|
mlx_int_xpm_set_pixel(data, opp, col, x);
|
||||||
|
x ++;
|
||||||
|
}
|
||||||
|
data += sl; //img->width*4;
|
||||||
|
}
|
||||||
|
if (colors)
|
||||||
|
free(colors);
|
||||||
|
if (colors_direct)
|
||||||
|
free(colors_direct);
|
||||||
|
return (img);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mlx_int_file_get_rid_comment(char *ptr, int size)
|
||||||
|
{
|
||||||
|
int com_begin;
|
||||||
|
int com_end;
|
||||||
|
|
||||||
|
while ((com_begin = mlx_int_str_str_cote(ptr,"/*",size))!=-1)
|
||||||
|
{
|
||||||
|
com_end = mlx_int_str_str(ptr+com_begin+2,"*/",size-com_begin-2);
|
||||||
|
memset(ptr+com_begin,' ',com_end+4);
|
||||||
|
}
|
||||||
|
while ((com_begin = mlx_int_str_str_cote(ptr,"//",size))!=-1)
|
||||||
|
{
|
||||||
|
com_end = mlx_int_str_str(ptr+com_begin+2,"\n",size-com_begin-2);
|
||||||
|
memset(ptr+com_begin,' ',com_end+3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void *mlx_xpm_file_to_image(void *xvar,char *file,int *width,int *height)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
int size;
|
||||||
|
char *ptr;
|
||||||
|
void *img;
|
||||||
|
|
||||||
|
if ((fd = open(file,O_RDONLY))==-1 || (size = lseek(fd,0,SEEK_END))==-1 ||
|
||||||
|
(ptr = mmap(0,size,PROT_WRITE|PROT_READ,MAP_PRIVATE,fd,0))==
|
||||||
|
(void *)MAP_FAILED)
|
||||||
|
{
|
||||||
|
if (fd>=0)
|
||||||
|
close(fd);
|
||||||
|
return ((void *)0);
|
||||||
|
}
|
||||||
|
mlx_int_file_get_rid_comment(ptr, size);
|
||||||
|
img = mlx_int_parse_xpm(xvar,ptr,size,mlx_int_get_line, width, height);
|
||||||
|
munmap(ptr,size);
|
||||||
|
close(fd);
|
||||||
|
return (img);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *mlx_xpm_to_image(void *xvar,char **xpm_data,int *width,int *height)
|
||||||
|
{
|
||||||
|
return (mlx_int_parse_xpm(xvar,xpm_data,0,mlx_int_static_line, width, height));
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
BIN
libs/minilibx_opengl_20191021/._font.xcf
Normal file
BIN
libs/minilibx_opengl_20191021/._font.xcf
Normal file
Binary file not shown.
24
libs/minilibx_opengl_20191021/Makefile
Normal file
24
libs/minilibx_opengl_20191021/Makefile
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
NOM=libmlx.a
|
||||||
|
SRC= mlx_shaders.c mlx_new_window.m mlx_init_loop.m mlx_new_image.m mlx_xpm.c mlx_int_str_to_wordtab.c
|
||||||
|
SRC+= mlx_png.c mlx_mouse.m
|
||||||
|
OBJ1=$(SRC:.c=.o)
|
||||||
|
OBJ=$(OBJ1:.m=.o)
|
||||||
|
CFLAGS+=-O2
|
||||||
|
|
||||||
|
# add to match string put with X11 in size and position
|
||||||
|
CFLAGS+= -DSTRINGPUTX11
|
||||||
|
|
||||||
|
all: $(NOM)
|
||||||
|
|
||||||
|
$(NOM): $(OBJ)
|
||||||
|
ar -r $(NOM) $(OBJ)
|
||||||
|
ranlib $(NOM)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(NOM) $(OBJ) *~
|
||||||
|
rm -f mlx_app
|
||||||
|
|
||||||
|
re: clean all
|
||||||
3525
libs/minilibx_opengl_20191021/font.c
Normal file
3525
libs/minilibx_opengl_20191021/font.c
Normal file
File diff suppressed because it is too large
Load Diff
BIN
libs/minilibx_opengl_20191021/font.xcf
Normal file
BIN
libs/minilibx_opengl_20191021/font.xcf
Normal file
Binary file not shown.
@@ -2,10 +2,10 @@
|
|||||||
** mlx.h for MinilibX in
|
** mlx.h for MinilibX in
|
||||||
**
|
**
|
||||||
** Made by Charlie Root
|
** Made by Charlie Root
|
||||||
** Login <ol@epitech.net>
|
** Login <ol@staff.42.fr>
|
||||||
**
|
**
|
||||||
** Started on Mon Jul 31 16:37:50 2000 Charlie Root
|
** Started on Mon Jul 31 16:37:50 2000 Charlie Root
|
||||||
** Last update Tue May 15 16:23:28 2007 Olivier Crouzet
|
** Last update Tue Oct 01 16:23:28 2014 Olivier Crouzet
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -16,14 +16,29 @@
|
|||||||
/*
|
/*
|
||||||
** FR msg - FR msg - FR msg
|
** FR msg - FR msg - FR msg
|
||||||
**
|
**
|
||||||
|
** MacOSX
|
||||||
|
** La MinilibX utilise 2 frameworks Mac : OpenGL et AppKit
|
||||||
|
** qu'il faut ajouter a la compilation :
|
||||||
|
** -framework OpenGL -framework AppKit
|
||||||
|
**
|
||||||
|
** UNIX / Linux
|
||||||
** La MinilibX utilise 2 librairies supplementaires qu'il
|
** La MinilibX utilise 2 librairies supplementaires qu'il
|
||||||
** est necessaire de rajouter a la compilation :
|
** est necessaire de rajouter a la compilation :
|
||||||
** -lmlx -lXext -lX11
|
** -lmlx -lXext -lX11
|
||||||
**
|
**
|
||||||
** La MinilibX permet le chargement des images de type Xpm.
|
** La MinilibX permet le chargement des images de type Xpm.
|
||||||
** Notez que cette implementation est incomplete.
|
** Notez que cette implementation est incomplete.
|
||||||
** Merci de communiquer tout probleme de chargement d'image
|
**
|
||||||
** de ce type.
|
** Il y a des differences entre X11 et MacOS.
|
||||||
|
** les numeros des touches ne sont pas les memes,
|
||||||
|
** les numeros des boutons souris ne sont pas les memes.
|
||||||
|
** Egalement l'expose est gere differemment, et sous MacOS
|
||||||
|
** il est preferable d'entrer le plus tot possible dans mlx_loop,
|
||||||
|
** il est normal que les fenetres n'apparaissent pas avant mlx_loop
|
||||||
|
** (ou bien forcez avec mlx_do_sync mais c'est pas genial).
|
||||||
|
** Sous MacOS, l'octet Alpha est pris en compte dans toutes les
|
||||||
|
** images, et represente la transparence et non l'opacite comme
|
||||||
|
** c'est normalement le cas.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -63,18 +78,16 @@ int mlx_pixel_put(void *mlx_ptr, void *win_ptr, int x, int y, int color);
|
|||||||
void *mlx_new_image(void *mlx_ptr,int width,int height);
|
void *mlx_new_image(void *mlx_ptr,int width,int height);
|
||||||
/*
|
/*
|
||||||
** return void *0 if failed
|
** return void *0 if failed
|
||||||
** obsolete : image2 data is stored using bit planes
|
|
||||||
** void *mlx_new_image2(void *mlx_ptr,int width,int height);
|
|
||||||
*/
|
*/
|
||||||
char *mlx_get_data_addr(void *img_ptr, int *bits_per_pixel,
|
char *mlx_get_data_addr(void *img_ptr, int *bits_per_pixel,
|
||||||
int *size_line, int *endian);
|
int *size_line, int *endian);
|
||||||
/*
|
/*
|
||||||
** endian : 0 = sever X is little endian, 1 = big endian
|
** endian : 0 = sever X is little endian, 1 = big endian
|
||||||
** for mlx_new_image2, 2nd arg of mlx_get_data_addr is number_of_planes
|
** endian : useless on macos, client and graphical framework have the same endian
|
||||||
*/
|
*/
|
||||||
int mlx_put_image_to_window(void *mlx_ptr, void *win_ptr, void *img_ptr,
|
int mlx_put_image_to_window(void *mlx_ptr, void *win_ptr, void *img_ptr,
|
||||||
int x, int y);
|
int x, int y);
|
||||||
int mlx_get_color_value(void *mlx_ptr, int color);
|
unsigned int mlx_get_color_value(void *mlx_ptr, int color);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -106,17 +119,16 @@ int mlx_loop (void *mlx_ptr);
|
|||||||
|
|
||||||
int mlx_string_put(void *mlx_ptr, void *win_ptr, int x, int y, int color,
|
int mlx_string_put(void *mlx_ptr, void *win_ptr, int x, int y, int color,
|
||||||
char *string);
|
char *string);
|
||||||
void mlx_set_font(void *mlx_ptr, void *win_ptr, char *name);
|
|
||||||
void *mlx_xpm_to_image(void *mlx_ptr, char **xpm_data,
|
void *mlx_xpm_to_image(void *mlx_ptr, char **xpm_data,
|
||||||
int *width, int *height);
|
int *width, int *height);
|
||||||
void *mlx_xpm_file_to_image(void *mlx_ptr, char *filename,
|
void *mlx_xpm_file_to_image(void *mlx_ptr, char *filename,
|
||||||
int *width, int *height);
|
int *width, int *height);
|
||||||
|
void *mlx_png_file_to_image(void *mlx_ptr, char *file, int *width, int *height);
|
||||||
|
|
||||||
int mlx_destroy_window(void *mlx_ptr, void *win_ptr);
|
int mlx_destroy_window(void *mlx_ptr, void *win_ptr);
|
||||||
|
|
||||||
int mlx_destroy_image(void *mlx_ptr, void *img_ptr);
|
int mlx_destroy_image(void *mlx_ptr, void *img_ptr);
|
||||||
|
|
||||||
int mlx_destroy_dispaly(void *mlx_ptr);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** generic hook system for all events, and minilibX functions that
|
** generic hook system for all events, and minilibX functions that
|
||||||
** can be hooked. Some macro and defines from X11/X.h are needed here.
|
** can be hooked. Some macro and defines from X11/X.h are needed here.
|
||||||
@@ -125,15 +137,13 @@ int mlx_destroy_dispaly(void *mlx_ptr);
|
|||||||
int mlx_hook(void *win_ptr, int x_event, int x_mask,
|
int mlx_hook(void *win_ptr, int x_event, int x_mask,
|
||||||
int (*funct)(), void *param);
|
int (*funct)(), void *param);
|
||||||
|
|
||||||
|
int mlx_mouse_hide();
|
||||||
|
int mlx_mouse_show();
|
||||||
|
int mlx_mouse_move(void *win_ptr, int x, int y);
|
||||||
|
int mlx_mouse_get_pos(void *win_ptr, int *x, int *y);
|
||||||
|
|
||||||
int mlx_do_key_autorepeatoff(void *mlx_ptr);
|
int mlx_do_key_autorepeatoff(void *mlx_ptr);
|
||||||
int mlx_do_key_autorepeaton(void *mlx_ptr);
|
int mlx_do_key_autorepeaton(void *mlx_ptr);
|
||||||
int mlx_do_sync(void *mlx_ptr);
|
int mlx_do_sync(void *mlx_ptr);
|
||||||
|
|
||||||
int mlx_mouse_get_pos(void *mlx_ptr, void *win_ptr, int *x, int *y);
|
|
||||||
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 */
|
#endif /* MLX_H */
|
||||||
192
libs/minilibx_opengl_20191021/mlx_init_loop.m
Normal file
192
libs/minilibx_opengl_20191021/mlx_init_loop.m
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
// mlx_init_loop.m
|
||||||
|
// By Ol
|
||||||
|
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
#import <OpenGL/gl3.h>
|
||||||
|
#import <AppKit/NSOpenGLView.h>
|
||||||
|
|
||||||
|
#include "mlx_int.h"
|
||||||
|
#include "mlx_new_window.h"
|
||||||
|
|
||||||
|
#include "font.c"
|
||||||
|
|
||||||
|
|
||||||
|
void do_loop_hook2(CFRunLoopTimerRef observer, void * info)
|
||||||
|
{
|
||||||
|
((mlx_ptr_t *)info)->loop_hook(((mlx_ptr_t *)info)->loop_hook_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void do_loop_flush(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void * info)
|
||||||
|
{
|
||||||
|
mlx_ptr_t *mlx_ptr;
|
||||||
|
mlx_win_list_t *win;
|
||||||
|
|
||||||
|
mlx_ptr = (mlx_ptr_t *)info;
|
||||||
|
win = mlx_ptr->win_list;
|
||||||
|
while (win)
|
||||||
|
{
|
||||||
|
if (win->nb_flush > 0 && win->pixmgt)
|
||||||
|
{
|
||||||
|
[(id)win->winid selectGLContext];
|
||||||
|
[(id)win->winid mlx_gl_draw];
|
||||||
|
glFlush();
|
||||||
|
win->nb_flush = 0;
|
||||||
|
}
|
||||||
|
win = win->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void *mlx_init()
|
||||||
|
{
|
||||||
|
mlx_ptr_t *new_mlx;
|
||||||
|
int bidon;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if ((new_mlx = malloc(sizeof(*new_mlx))) == NULL)
|
||||||
|
return ((void *)0);
|
||||||
|
new_mlx->win_list = NULL;
|
||||||
|
new_mlx->img_list = NULL;
|
||||||
|
new_mlx->loop_hook = NULL;
|
||||||
|
new_mlx->loop_hook_data = NULL;
|
||||||
|
new_mlx->main_loop_active = 0;
|
||||||
|
|
||||||
|
new_mlx->appid = [NSApplication sharedApplication];
|
||||||
|
|
||||||
|
// super magic trick to detach app from terminal, get menubar & key input events
|
||||||
|
for (NSRunningApplication * app in [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.finder"])
|
||||||
|
{
|
||||||
|
[app activateWithOptions:NSApplicationActivateIgnoringOtherApps];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
usleep(100000);
|
||||||
|
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||||
|
(void) TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||||
|
usleep(100000);
|
||||||
|
[[NSRunningApplication currentApplication] activateWithOptions:NSApplicationActivateIgnoringOtherApps];
|
||||||
|
|
||||||
|
// load font
|
||||||
|
new_mlx->font = mlx_new_image(new_mlx, (FONT_WIDTH+2)*95, FONT_HEIGHT);
|
||||||
|
i = 0;
|
||||||
|
while (i < 4*(FONT_WIDTH+2)*95*FONT_HEIGHT)
|
||||||
|
{
|
||||||
|
new_mlx->font->buffer[i+0] = font_atlas.pixel_data[i+2];
|
||||||
|
new_mlx->font->buffer[i+1] = font_atlas.pixel_data[i+1];
|
||||||
|
new_mlx->font->buffer[i+2] = font_atlas.pixel_data[i+0];
|
||||||
|
((unsigned char *)new_mlx->font->buffer)[i+3] = 0xFF-font_atlas.pixel_data[i+3];
|
||||||
|
i += 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef STRINGPUTX11
|
||||||
|
new_mlx->font->vertexes[2] = FONT_WIDTH/1.4;
|
||||||
|
new_mlx->font->vertexes[4] = FONT_WIDTH/1.4;
|
||||||
|
new_mlx->font->vertexes[5] = (-FONT_HEIGHT-1)/1.4;
|
||||||
|
new_mlx->font->vertexes[7] = (-FONT_HEIGHT-1)/1.4;
|
||||||
|
#else
|
||||||
|
new_mlx->font->vertexes[2] = FONT_WIDTH;
|
||||||
|
new_mlx->font->vertexes[4] = FONT_WIDTH;
|
||||||
|
new_mlx->font->vertexes[5] = -FONT_HEIGHT-1;
|
||||||
|
new_mlx->font->vertexes[7] = -FONT_HEIGHT-1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ((void *)new_mlx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mlx_loop(mlx_ptr_t *mlx_ptr)
|
||||||
|
{
|
||||||
|
CFRunLoopObserverRef observer;
|
||||||
|
CFRunLoopObserverContext ocontext = {.version = 0, .info = mlx_ptr, .retain = NULL, .release = NULL, .copyDescription = NULL};
|
||||||
|
|
||||||
|
mlx_ptr->main_loop_active = 1;
|
||||||
|
|
||||||
|
observer = CFRunLoopObserverCreate(NULL, kCFRunLoopBeforeTimers, true, 0, do_loop_flush, &ocontext);
|
||||||
|
CFRunLoopAddObserver(CFRunLoopGetMain(), observer, kCFRunLoopCommonModes);
|
||||||
|
|
||||||
|
// [[[MlxLoopHookObj alloc] initWithPtr:mlx_ptr] performSelector:@selector(do_loop_hook) withObject:nil afterDelay:0.0];
|
||||||
|
|
||||||
|
[NSApp run];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mlx_pixel_put(mlx_ptr_t *mlx_ptr, mlx_win_list_t *win_ptr, int x, int y, int color)
|
||||||
|
{
|
||||||
|
if (!win_ptr->pixmgt)
|
||||||
|
return ;
|
||||||
|
[(id)(win_ptr->winid) selectGLContext];
|
||||||
|
[(id)(win_ptr->winid) pixelPutColor:color X:x Y:y];
|
||||||
|
win_ptr->nb_flush ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mlx_int_loop_once()
|
||||||
|
{
|
||||||
|
NSEvent *event;
|
||||||
|
NSDate *thedate;
|
||||||
|
|
||||||
|
thedate = [NSDate dateWithTimeIntervalSinceNow:0.1];
|
||||||
|
while (42)
|
||||||
|
{
|
||||||
|
event = [NSApp nextEventMatchingMask:NSEventMaskAny
|
||||||
|
untilDate:thedate
|
||||||
|
inMode:NSDefaultRunLoopMode
|
||||||
|
dequeue:YES];
|
||||||
|
if (event == nil)
|
||||||
|
{
|
||||||
|
[thedate release];
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
[NSApp sendEvent:event];
|
||||||
|
[NSApp updateWindows];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mlx_do_sync(mlx_ptr_t *mlx_ptr)
|
||||||
|
{
|
||||||
|
mlx_win_list_t *win;
|
||||||
|
|
||||||
|
win = mlx_ptr->win_list;
|
||||||
|
while (win)
|
||||||
|
{
|
||||||
|
if (win->pixmgt)
|
||||||
|
{
|
||||||
|
[(id)(win->winid) selectGLContext];
|
||||||
|
[(id)(win->winid) mlx_gl_draw];
|
||||||
|
glFlush();
|
||||||
|
if (!mlx_ptr->main_loop_active)
|
||||||
|
mlx_int_loop_once();
|
||||||
|
}
|
||||||
|
win = win->next;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mlx_loop_hook(mlx_ptr_t *mlx_ptr, void (*fct)(void *), void *param)
|
||||||
|
{
|
||||||
|
CFRunLoopTimerContext tcontext = {0, mlx_ptr, NULL, NULL, NULL};
|
||||||
|
CFRunLoopTimerRef timer;
|
||||||
|
|
||||||
|
if (mlx_ptr->loop_hook != NULL)
|
||||||
|
{
|
||||||
|
CFRunLoopTimerInvalidate(mlx_ptr->loop_timer);
|
||||||
|
[(id)(mlx_ptr->loop_timer) release];
|
||||||
|
}
|
||||||
|
|
||||||
|
mlx_ptr->loop_hook = fct;
|
||||||
|
mlx_ptr->loop_hook_data = param;
|
||||||
|
|
||||||
|
if (fct)
|
||||||
|
{
|
||||||
|
timer = CFRunLoopTimerCreate(kCFAllocatorDefault, 0.0, 0.0001, 0, 0, &do_loop_hook2, &tcontext);
|
||||||
|
mlx_ptr->loop_timer = timer;
|
||||||
|
CFRunLoopAddTimer(CFRunLoopGetMain(), timer, kCFRunLoopCommonModes);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
102
libs/minilibx_opengl_20191021/mlx_int.h
Normal file
102
libs/minilibx_opengl_20191021/mlx_int.h
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
//
|
||||||
|
// mlx_int.h for minilibx
|
||||||
|
//
|
||||||
|
// ol@staff.42.fr
|
||||||
|
//
|
||||||
|
// include opengl needed before mlx_int.h
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#define MAX_EVENT 32
|
||||||
|
#define MAX_PIXEL_NB 200000
|
||||||
|
#define UNIQ_BPP 4
|
||||||
|
|
||||||
|
#define FONT_WIDTH 10
|
||||||
|
#define FONT_HEIGHT 20
|
||||||
|
|
||||||
|
|
||||||
|
typedef int (*func_t)();
|
||||||
|
|
||||||
|
/* structs */
|
||||||
|
|
||||||
|
typedef struct glsl_info_s
|
||||||
|
{
|
||||||
|
GLuint pixel_vshader;
|
||||||
|
GLuint pixel_fshader;
|
||||||
|
GLuint pixel_program;
|
||||||
|
GLint loc_pixel_position;
|
||||||
|
GLint loc_pixel_texture;
|
||||||
|
GLint loc_pixel_winhalfsize;
|
||||||
|
|
||||||
|
GLuint image_vshader;
|
||||||
|
GLuint image_fshader;
|
||||||
|
GLuint image_program;
|
||||||
|
GLint loc_image_position;
|
||||||
|
GLint loc_image_winhalfsize;
|
||||||
|
GLint loc_image_texture;
|
||||||
|
GLint loc_image_pos;
|
||||||
|
GLint loc_image_size;
|
||||||
|
|
||||||
|
GLuint font_vshader;
|
||||||
|
GLuint font_fshader;
|
||||||
|
GLuint font_program;
|
||||||
|
GLint loc_font_position;
|
||||||
|
GLint loc_font_winhalfsize;
|
||||||
|
GLint loc_font_texture;
|
||||||
|
GLint loc_font_color;
|
||||||
|
GLint loc_font_posinwin;
|
||||||
|
GLint loc_font_posinatlas;
|
||||||
|
GLint loc_font_atlassize;
|
||||||
|
} glsl_info_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct mlx_img_list_s
|
||||||
|
{
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
char *buffer;
|
||||||
|
GLfloat vertexes[8];
|
||||||
|
struct mlx_img_list_s *next;
|
||||||
|
} mlx_img_list_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct mlx_img_ctx_s
|
||||||
|
{
|
||||||
|
GLuint texture;
|
||||||
|
GLuint vbuffer;
|
||||||
|
mlx_img_list_t *img;
|
||||||
|
struct mlx_img_ctx_s *next;
|
||||||
|
} mlx_img_ctx_t;
|
||||||
|
|
||||||
|
typedef struct mlx_win_list_s
|
||||||
|
{
|
||||||
|
void *winid;
|
||||||
|
mlx_img_ctx_t *img_list;
|
||||||
|
int nb_flush;
|
||||||
|
int pixmgt;
|
||||||
|
struct mlx_win_list_s *next;
|
||||||
|
} mlx_win_list_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct mlx_ptr_s
|
||||||
|
{
|
||||||
|
void *appid;
|
||||||
|
mlx_win_list_t *win_list;
|
||||||
|
mlx_img_list_t *img_list;
|
||||||
|
void (*loop_hook)(void *);
|
||||||
|
void *loop_hook_data;
|
||||||
|
void *loop_timer;
|
||||||
|
mlx_img_list_t *font;
|
||||||
|
int main_loop_active;
|
||||||
|
} mlx_ptr_t;
|
||||||
|
|
||||||
|
// proto
|
||||||
|
|
||||||
|
int mlx_shaders(glsl_info_t *glsl);
|
||||||
|
char **mlx_int_str_to_wordtab(char *str);
|
||||||
|
int mlx_int_str_str(char *str,char *find,int len);
|
||||||
|
int mlx_int_str_str_cote(char *str,char *find,int len);
|
||||||
|
int mlx_destroy_image(mlx_ptr_t *mlx_ptr, mlx_img_list_t *img_ptr);
|
||||||
|
void *mlx_new_image();
|
||||||
|
void *mlx_xpm_to_image(mlx_ptr_t *xvar,char **xpm_data,int *width,int *height);
|
||||||
|
int mlx_do_sync(mlx_ptr_t *mlx_ptr);
|
||||||
@@ -1,16 +1,10 @@
|
|||||||
/*
|
//
|
||||||
** mlx_int_str_to_wordtab.c for MinilibX in
|
// str 2 wordtab & co
|
||||||
**
|
// by ol
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Wed Sep 13 11:36:09 2000 Charlie Root
|
|
||||||
** Last update Fri Dec 14 11:02:09 2001 Charlie Root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "mlx_int.h"
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
int mlx_int_str_str(char *str,char *find,int len)
|
int mlx_int_str_str(char *str,char *find,int len)
|
||||||
{
|
{
|
||||||
52
libs/minilibx_opengl_20191021/mlx_mouse.m
Normal file
52
libs/minilibx_opengl_20191021/mlx_mouse.m
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
#import <OpenGL/gl3.h>
|
||||||
|
|
||||||
|
#include "mlx_int.h"
|
||||||
|
#include "mlx_new_window.h"
|
||||||
|
|
||||||
|
int mlx_mouse_hide()
|
||||||
|
{
|
||||||
|
// CGDisplayHideCursor(kCGDirectMainDisplay);
|
||||||
|
[NSCursor hide];
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int mlx_mouse_show()
|
||||||
|
{
|
||||||
|
// CGDisplayShowCursor(kCGDirectMainDisplay);
|
||||||
|
[NSCursor unhide];
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int mlx_mouse_move(mlx_win_list_t *win, int x, int y)
|
||||||
|
{
|
||||||
|
CGPoint point;
|
||||||
|
NSRect pos;
|
||||||
|
id thewin;
|
||||||
|
|
||||||
|
thewin = [(id)(win->winid) win];
|
||||||
|
pos = [thewin frame];
|
||||||
|
// printf("got win pos %f %f\n", pos.origin.x, pos.origin.y);
|
||||||
|
point.x = pos.origin.x + x;
|
||||||
|
point.y = NSHeight([[thewin screen] frame]) - NSHeight([(id)(win->winid) frame]) - pos.origin.y + 1 + y;
|
||||||
|
CGWarpMouseCursorPosition(point);
|
||||||
|
CGAssociateMouseAndMouseCursorPosition(true);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mlx_mouse_get_pos(mlx_win_list_t *win, int *x, int *y)
|
||||||
|
{
|
||||||
|
CGPoint point;
|
||||||
|
id thewin;
|
||||||
|
NSRect pos;
|
||||||
|
|
||||||
|
thewin = [(id)(win->winid) win];
|
||||||
|
pos = [(id)(win->winid) frame];
|
||||||
|
point = [thewin mouseLocationOutsideOfEventStream];
|
||||||
|
*x = point.x;
|
||||||
|
*y = NSHeight(pos) - 1 - point.y;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
198
libs/minilibx_opengl_20191021/mlx_new_image.m
Normal file
198
libs/minilibx_opengl_20191021/mlx_new_image.m
Normal file
@@ -0,0 +1,198 @@
|
|||||||
|
// mlx_new_image
|
||||||
|
//
|
||||||
|
// by Ol
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
#import <OpenGL/gl3.h>
|
||||||
|
|
||||||
|
#include "mlx_int.h"
|
||||||
|
#include "mlx_new_window.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void *mlx_new_image(mlx_ptr_t *mlx_ptr, int width, int height)
|
||||||
|
{
|
||||||
|
mlx_img_list_t *newimg;
|
||||||
|
|
||||||
|
// if (mlx_ptr->win_list == NULL)
|
||||||
|
// return (NULL); // need at leat one window created to have openGL context and create texture
|
||||||
|
if ((newimg = malloc(sizeof(*newimg))) == NULL)
|
||||||
|
return ((void *)0);
|
||||||
|
newimg->next = mlx_ptr->img_list;
|
||||||
|
mlx_ptr->img_list = newimg;
|
||||||
|
newimg->width = width;
|
||||||
|
newimg->height = height;
|
||||||
|
newimg->vertexes[0] = 0.0; newimg->vertexes[1] = 0.0;
|
||||||
|
newimg->vertexes[2] = width; newimg->vertexes[3] = 0.0;
|
||||||
|
newimg->vertexes[4] = width; newimg->vertexes[5] = -height;
|
||||||
|
newimg->vertexes[6] = 0.0; newimg->vertexes[7] = -height;
|
||||||
|
newimg->buffer = malloc(UNIQ_BPP*width*height);
|
||||||
|
bzero(newimg->buffer, UNIQ_BPP*width*height);
|
||||||
|
|
||||||
|
return (newimg);
|
||||||
|
}
|
||||||
|
|
||||||
|
mlx_img_ctx_t *add_img_to_ctx(mlx_img_list_t *img, mlx_win_list_t *win)
|
||||||
|
{
|
||||||
|
mlx_img_ctx_t *imgctx;
|
||||||
|
|
||||||
|
imgctx = win->img_list;
|
||||||
|
while (imgctx)
|
||||||
|
{
|
||||||
|
if (imgctx->img == img)
|
||||||
|
return (imgctx);
|
||||||
|
imgctx = imgctx->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
imgctx = malloc(sizeof(*imgctx));
|
||||||
|
imgctx->img = img;
|
||||||
|
imgctx->next = win->img_list;
|
||||||
|
win->img_list = imgctx;
|
||||||
|
|
||||||
|
glGenTextures(1, &(imgctx->texture));
|
||||||
|
glBindTexture(GL_TEXTURE_2D, imgctx->texture);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexImage2D(
|
||||||
|
GL_TEXTURE_2D, 0, /* target, level of detail */
|
||||||
|
GL_RGBA8, /* internal format */
|
||||||
|
img->width, img->height, 0, /* width, height, border */
|
||||||
|
GL_BGRA, GL_UNSIGNED_BYTE, /* external format, type */
|
||||||
|
img->buffer /* pixels */
|
||||||
|
);
|
||||||
|
|
||||||
|
glGenBuffers(1, &(imgctx->vbuffer));
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, imgctx->vbuffer);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(img->vertexes), img->vertexes, GL_DYNAMIC_DRAW); // 4 points buff
|
||||||
|
|
||||||
|
return (imgctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mlx_put_image_to_window(mlx_ptr_t *mlx_ptr, mlx_win_list_t *win_ptr, mlx_img_list_t *img_ptr, int x, int y)
|
||||||
|
{
|
||||||
|
mlx_img_ctx_t *imgctx;
|
||||||
|
|
||||||
|
if (!win_ptr->pixmgt)
|
||||||
|
return ;
|
||||||
|
|
||||||
|
[(id)(win_ptr->winid) selectGLContext];
|
||||||
|
imgctx = add_img_to_ctx(img_ptr, win_ptr);
|
||||||
|
|
||||||
|
// update texture
|
||||||
|
glBindTexture(GL_TEXTURE_2D, imgctx->texture);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, img_ptr->width, img_ptr->height, 0,
|
||||||
|
GL_BGRA, GL_UNSIGNED_BYTE, img_ptr->buffer);
|
||||||
|
|
||||||
|
[(id)(win_ptr->winid) mlx_gl_draw_img:img_ptr andCtx:imgctx andX:x andY:y];
|
||||||
|
|
||||||
|
win_ptr->nb_flush ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// assume here 32bpp little endian
|
||||||
|
|
||||||
|
char *mlx_get_data_addr(mlx_img_list_t *img_ptr, int *bits_per_pixel, int *size_line, int *endian)
|
||||||
|
{
|
||||||
|
*bits_per_pixel = UNIQ_BPP*8;
|
||||||
|
*size_line = img_ptr->width*UNIQ_BPP;
|
||||||
|
*endian = 0; // little endian for now on mac-intel
|
||||||
|
return (img_ptr->buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int mlx_get_color_value(mlx_ptr_t *mlx_ptr, int color)
|
||||||
|
{
|
||||||
|
return (color);
|
||||||
|
}
|
||||||
|
|
||||||
|
int mlx_string_put(mlx_ptr_t *mlx_ptr, mlx_win_list_t *win_ptr, int x, int y, int color, unsigned char *string)
|
||||||
|
{
|
||||||
|
mlx_img_ctx_t *imgctx;
|
||||||
|
int gX;
|
||||||
|
int gY;
|
||||||
|
|
||||||
|
if (!win_ptr->pixmgt)
|
||||||
|
return(0);
|
||||||
|
|
||||||
|
#ifdef STRINGPUTX11
|
||||||
|
y -= (FONT_HEIGHT * 2)/3;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
[(id)(win_ptr->winid) selectGLContext];
|
||||||
|
|
||||||
|
imgctx = add_img_to_ctx(mlx_ptr->font, win_ptr);
|
||||||
|
|
||||||
|
while (*string)
|
||||||
|
{
|
||||||
|
if (*string >= 32 && *string <= 127)
|
||||||
|
{
|
||||||
|
gX = (FONT_WIDTH+2)*(*string-32);
|
||||||
|
gY = 0;
|
||||||
|
// printf("put char %c pos %d %d\n", *string, gX, gY);
|
||||||
|
[(id)(win_ptr->winid) mlx_gl_draw_font:mlx_ptr->font andCtx:imgctx andX:x andY:y andColor:color glyphX:gX glyphY:gY];
|
||||||
|
#ifdef STRINGPUTX11
|
||||||
|
x += FONT_WIDTH/1.4;
|
||||||
|
#else
|
||||||
|
x += FONT_WIDTH;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
string ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
win_ptr->nb_flush ++;
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int mlx_destroy_image(mlx_ptr_t *mlx_ptr, mlx_img_list_t *img_todel)
|
||||||
|
{
|
||||||
|
mlx_img_ctx_t ctx_first;
|
||||||
|
mlx_img_ctx_t *ctx;
|
||||||
|
mlx_img_ctx_t *ctx_to_del;
|
||||||
|
mlx_img_list_t img_first;
|
||||||
|
mlx_img_list_t *img;
|
||||||
|
mlx_win_list_t *win;
|
||||||
|
|
||||||
|
img_first.next = mlx_ptr->img_list;
|
||||||
|
img = &img_first;
|
||||||
|
while (img && img->next)
|
||||||
|
{
|
||||||
|
if (img->next == img_todel)
|
||||||
|
img->next = img->next->next;
|
||||||
|
img = img->next;
|
||||||
|
}
|
||||||
|
mlx_ptr->img_list = img_first.next;
|
||||||
|
|
||||||
|
|
||||||
|
win = mlx_ptr->win_list;
|
||||||
|
while (win)
|
||||||
|
{
|
||||||
|
ctx_first.next = win->img_list;
|
||||||
|
ctx = &ctx_first;
|
||||||
|
while (ctx && ctx->next)
|
||||||
|
{
|
||||||
|
if (ctx->next->img == img_todel)
|
||||||
|
{
|
||||||
|
[(id)(win->winid) selectGLContext];
|
||||||
|
glDeleteBuffers(1, &(ctx->next->vbuffer));
|
||||||
|
glDeleteTextures(1, &(ctx->next->texture));
|
||||||
|
ctx_to_del = ctx->next;
|
||||||
|
ctx->next = ctx->next->next;
|
||||||
|
free(ctx_to_del);
|
||||||
|
}
|
||||||
|
ctx = ctx->next;
|
||||||
|
}
|
||||||
|
win->img_list = ctx_first.next;
|
||||||
|
win = win->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
free(img_todel->buffer);
|
||||||
|
free(img_todel);
|
||||||
|
|
||||||
|
// printf("destroy image done.\n");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
57
libs/minilibx_opengl_20191021/mlx_new_window.h
Normal file
57
libs/minilibx_opengl_20191021/mlx_new_window.h
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
//
|
||||||
|
// mlx_int.h for minilibx
|
||||||
|
//
|
||||||
|
// ol@staff.42.fr
|
||||||
|
//
|
||||||
|
// include opengl needed before mlx_int.h
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
#import "mlx_int.h"
|
||||||
|
|
||||||
|
@interface NSWindowEvent : NSWindow
|
||||||
|
{
|
||||||
|
func_t event_funct[MAX_EVENT];
|
||||||
|
void *(event_param[MAX_EVENT]);
|
||||||
|
int keyrepeat;
|
||||||
|
int keyflag;
|
||||||
|
int size_x;
|
||||||
|
int size_y;
|
||||||
|
}
|
||||||
|
- (NSWindowEvent *) initWithContentRect:(NSRect)rect styleMask:(NSUInteger)winstyle backing:(NSBackingStoreType)bck defer:(BOOL) dfr;
|
||||||
|
- (void) setEvent:(int)event andFunc:(func_t)func andParam:(void *)param;
|
||||||
|
- (void) setKeyRepeat:(int)mode;
|
||||||
|
- (void) exposeNotification:(NSNotification *)note;
|
||||||
|
- (void) closeNotification:(NSNotification *)note;
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@interface MlxWin : NSOpenGLView
|
||||||
|
{
|
||||||
|
NSWindowEvent *win;
|
||||||
|
NSOpenGLContext *ctx;
|
||||||
|
glsl_info_t glsl;
|
||||||
|
int openglwin;
|
||||||
|
|
||||||
|
int size_x;
|
||||||
|
int size_y;
|
||||||
|
|
||||||
|
int pixel_nb;
|
||||||
|
GLuint pixel_vbuffer;
|
||||||
|
GLuint pixel_texture;
|
||||||
|
unsigned int *pixtexbuff;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) initWithRect: (NSRect)rect andTitle: (NSString *)title pfaAttrs: (NSOpenGLPixelFormatAttribute *)attrs;
|
||||||
|
- (void) selectGLContext;
|
||||||
|
- (void) flushGLContext;
|
||||||
|
- (void) pixelPutColor: (int)color X:(int)x Y:(int)y;
|
||||||
|
- (void) mlx_gl_draw;
|
||||||
|
- (void) mlx_gl_draw_img:(mlx_img_list_t *)img andCtx:(mlx_img_ctx_t *)imgctx andX:(int)x andY:(int)y;
|
||||||
|
- (void) mlx_gl_draw_font:(mlx_img_list_t *)img andCtx:(mlx_img_ctx_t *)imgctx andX:(int)x andY:(int)y andColor:(int)color glyphX:(int)gx glyphY:(int)gy;
|
||||||
|
- (NSOpenGLContext *) ctx;
|
||||||
|
- (NSWindowEvent *) win;
|
||||||
|
- (void) setEvent:(int)event andFunc:(func_t)func andParam:(void *)param;
|
||||||
|
- (void) setKeyRepeat:(int)mode;
|
||||||
|
- (void) ctxNeedsUpdate;
|
||||||
|
@end
|
||||||
766
libs/minilibx_opengl_20191021/mlx_new_window.m
Normal file
766
libs/minilibx_opengl_20191021/mlx_new_window.m
Normal file
@@ -0,0 +1,766 @@
|
|||||||
|
// mlx_new_window.m
|
||||||
|
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
#import <OpenGL/gl3.h>
|
||||||
|
#import <AppKit/NSOpenGLView.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "mlx_int.h"
|
||||||
|
#include "mlx_new_window.h"
|
||||||
|
|
||||||
|
|
||||||
|
NSOpenGLPixelFormatAttribute pfa_attrs[] =
|
||||||
|
{
|
||||||
|
NSOpenGLPFADepthSize, 32,
|
||||||
|
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersionLegacy,
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
static const GLfloat pixel_vertexes[8] =
|
||||||
|
{
|
||||||
|
-1.0 , -1.0,
|
||||||
|
1.0, -1.0,
|
||||||
|
1.0, 1.0,
|
||||||
|
-1.0, 1.0
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int get_mouse_button(NSEventType eventtype)
|
||||||
|
{
|
||||||
|
switch (eventtype) {
|
||||||
|
case NSEventTypeLeftMouseDown:
|
||||||
|
case NSEventTypeLeftMouseUp:
|
||||||
|
case NSEventTypeLeftMouseDragged:
|
||||||
|
return 1;
|
||||||
|
case NSEventTypeRightMouseDown:
|
||||||
|
case NSEventTypeRightMouseUp:
|
||||||
|
case NSEventTypeRightMouseDragged:
|
||||||
|
return 2;
|
||||||
|
case NSEventTypeOtherMouseDown:
|
||||||
|
case NSEventTypeOtherMouseUp:
|
||||||
|
case NSEventTypeOtherMouseDragged:
|
||||||
|
return 3;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// classes for window & events
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@implementation NSWindowEvent
|
||||||
|
|
||||||
|
- (NSWindowEvent *) initWithContentRect:(NSRect)rect styleMask:(NSUInteger)winstyle backing:(NSBackingStoreType)bck defer:(BOOL) dfr
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if ((self = [super initWithContentRect:rect
|
||||||
|
styleMask:winstyle
|
||||||
|
backing:bck
|
||||||
|
defer:dfr]))
|
||||||
|
{
|
||||||
|
i = MAX_EVENT;
|
||||||
|
while (i--)
|
||||||
|
{
|
||||||
|
event_funct[i] = NULL;
|
||||||
|
event_param[i] = NULL;
|
||||||
|
}
|
||||||
|
keyrepeat = 0;
|
||||||
|
keyflag = 0;
|
||||||
|
size_x = rect.size.width;
|
||||||
|
size_y = rect.size.height;
|
||||||
|
}
|
||||||
|
return (self);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) setEvent:(int)event andFunc:(func_t)func andParam:(void *)param
|
||||||
|
{
|
||||||
|
event_funct[event] = func;
|
||||||
|
event_param[event] = param;
|
||||||
|
if (event == 6 || event == 32) // motion notify && high precision motion notify
|
||||||
|
{
|
||||||
|
if (func == NULL)
|
||||||
|
[self setAcceptsMouseMovedEvents:NO];
|
||||||
|
else
|
||||||
|
[self setAcceptsMouseMovedEvents:YES];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) setKeyRepeat:(int)mode
|
||||||
|
{
|
||||||
|
keyrepeat = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) acceptsFirstResponder
|
||||||
|
{
|
||||||
|
return (YES);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) flagsChanged:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
unsigned int flag;
|
||||||
|
int the_key;
|
||||||
|
unsigned int val;
|
||||||
|
|
||||||
|
flag = [theEvent modifierFlags];
|
||||||
|
// printf("Key flag changed: %x => %x\n", keyflag, flag);
|
||||||
|
// printf("**mlx flag low part : %d - %x\n", flag&0xFFFF, flag&0xFFFF);
|
||||||
|
|
||||||
|
if (!(val = (keyflag|flag)&(~(keyflag&flag))))
|
||||||
|
return ; // no change - can happen when loosing focus on special key pressed, then re-pressed later
|
||||||
|
the_key = 1;
|
||||||
|
while (((val >> (the_key-1)) & 0x01)==0)
|
||||||
|
the_key ++;
|
||||||
|
if (flag > keyflag && event_funct[2] != NULL)
|
||||||
|
event_funct[2](0xFF+the_key, event_param[2]);
|
||||||
|
if (flag < keyflag && event_funct[3] != NULL)
|
||||||
|
event_funct[3](0xFF+the_key, event_param[3]);
|
||||||
|
/*
|
||||||
|
if (event_funct[2] != NULL)
|
||||||
|
{
|
||||||
|
if (!(keyflag & NSAlphaShiftKeyMask) && (flag&NSAlphaShiftKeyMask)) event_funct[2](0xFF+1, event_param[2]);
|
||||||
|
if (!(keyflag & NSShiftKeyMask) && (flag&NSShiftKeyMask)) event_funct[2](0xFF+2, event_param[2]);
|
||||||
|
if (!(keyflag & NSControlKeyMask) && (flag&NSControlKeyMask)) event_funct[2](0xFF+3, event_param[2]);
|
||||||
|
if (!(keyflag & NSAlternateKeyMask) && (flag&NSAlternateKeyMask)) event_funct[2](0xFF+4, event_param[2]);
|
||||||
|
if (!(keyflag & NSCommandKeyMask) && (flag&NSCommandKeyMask)) event_funct[2](0xFF+5, event_param[2]);
|
||||||
|
if (!(keyflag & NSNumericPadKeyMask) && (flag&NSNumericPadKeyMask)) event_funct[2](0xFF+6, event_param[2]);
|
||||||
|
if (!(keyflag & NSHelpKeyMask) && (flag&NSHelpKeyMask)) event_funct[2](0xFF+7, event_param[2]);
|
||||||
|
if (!(keyflag & NSFunctionKeyMask) && (flag&NSFunctionKeyMask)) event_funct[2](0xFF+8, event_param[2]);
|
||||||
|
}
|
||||||
|
if (event_funct[3] != NULL)
|
||||||
|
{
|
||||||
|
if ((keyflag & NSShiftKeyMask) && !(flag&NSShiftKeyMask)) event_funct[3](NSShiftKeyMask, event_param[3]);
|
||||||
|
|
||||||
|
if ((keyflag & NSAlphaShiftKeyMask) && !(flag&NSAlphaShiftKeyMask)) event_funct[3](0xFF+1, event_param[3]);
|
||||||
|
if ((keyflag & NSShiftKeyMask) && !(flag&NSShiftKeyMask)) event_funct[3](0xFF+2, event_param[3]);
|
||||||
|
if ((keyflag & NSControlKeyMask) && !(flag&NSControlKeyMask)) event_funct[3](0xFF+3, event_param[3]);
|
||||||
|
if ((keyflag & NSAlternateKeyMask) && !(flag&NSAlternateKeyMask)) event_funct[3](0xFF+4, event_param[3]);
|
||||||
|
if ((keyflag & NSCommandKeyMask) && !(flag&NSCommandKeyMask)) event_funct[3](0xFF+5, event_param[3]);
|
||||||
|
if ((keyflag & NSNumericPadKeyMask) && !(flag&NSNumericPadKeyMask)) event_funct[3](0xFF+6, event_param[3]);
|
||||||
|
if ((keyflag & NSHelpKeyMask) && !(flag&NSHelpKeyMask)) event_funct[3](0xFF+7, event_param[3]);
|
||||||
|
if ((keyflag & NSFunctionKeyMask) && !(flag&NSFunctionKeyMask)) event_funct[3](0xFF+8, event_param[3]);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
keyflag = flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) keyDown:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
if (keyrepeat==0 && [theEvent isARepeat])
|
||||||
|
return ;
|
||||||
|
// printf("Key Down: %d\n", [theEvent keyCode]);
|
||||||
|
if (event_funct[2] != NULL)
|
||||||
|
event_funct[2]([theEvent keyCode], event_param[2]);
|
||||||
|
// else [super keyDown: theEvent];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) keyUp:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
// printf("Key Up: %d\n", [theEvent keyCode]);
|
||||||
|
if (event_funct[3] != NULL)
|
||||||
|
event_funct[3]([theEvent keyCode], event_param[3]);
|
||||||
|
// else [super keyUp: theEvent];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) mouseDown:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
int button;
|
||||||
|
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
button = get_mouse_button([theEvent type]);
|
||||||
|
// printf("Mouse pressed bt %d pos: %f, %f\n", button, thepoint.x, thepoint.y);
|
||||||
|
if (event_funct[4] != NULL)
|
||||||
|
event_funct[4](button, (int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[4]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) rightMouseDown:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
int button;
|
||||||
|
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
button = get_mouse_button([theEvent type]);
|
||||||
|
// printf("Mouse pressed bt %d pos: %f, %f\n", button, thepoint.x, thepoint.y);
|
||||||
|
if (event_funct[4] != NULL)
|
||||||
|
event_funct[4](button, (int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[4]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) otherMouseDown:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
int button;
|
||||||
|
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
button = get_mouse_button([theEvent type]);
|
||||||
|
// printf("Mouse pressed bt %d pos: %f, %f\n", button, thepoint.x, thepoint.y);
|
||||||
|
if (event_funct[4] != NULL)
|
||||||
|
event_funct[4](button, (int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[4]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) mouseUp:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
int button;
|
||||||
|
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
button = get_mouse_button([theEvent type]);
|
||||||
|
// printf("Mouse release bt %d pos: %f, %f\n", button, thepoint.x, thepoint.y);
|
||||||
|
if (event_funct[5] != NULL)
|
||||||
|
event_funct[5](button, (int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[5]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) rightMouseUp:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
int button;
|
||||||
|
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
button = get_mouse_button([theEvent type]);
|
||||||
|
// printf("Mouse release bt %d pos: %f, %f\n", button, thepoint.x, thepoint.y);
|
||||||
|
if (event_funct[5] != NULL)
|
||||||
|
event_funct[5](button, (int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[5]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) otherMouseUp:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
int button;
|
||||||
|
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
button = get_mouse_button([theEvent type]);
|
||||||
|
// printf("Mouse release bt %d pos: %f, %f\n", button, thepoint.x, thepoint.y);
|
||||||
|
if (event_funct[5] != NULL)
|
||||||
|
event_funct[5](button, (int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[5]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) mouseMoved:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
// printf("Mouse moved pos: %f, %f\n", thepoint.x, thepoint.y);
|
||||||
|
if (event_funct[6] != NULL)
|
||||||
|
event_funct[6]((int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[6]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) mouseDragged:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
// printf("Mouse moved pos: %f, %f\n", thepoint.x, thepoint.y);
|
||||||
|
if (event_funct[6] != NULL)
|
||||||
|
event_funct[6]((int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[6]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) rightMouseDragged:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
// printf("Mouse moved pos: %f, %f\n", thepoint.x, thepoint.y);
|
||||||
|
if (event_funct[6] != NULL)
|
||||||
|
event_funct[6]((int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[6]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) otherMouseDragged:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
// printf("Mouse moved pos: %f, %f\n", thepoint.x, thepoint.y);
|
||||||
|
if (event_funct[6] != NULL)
|
||||||
|
event_funct[6]((int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[6]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) scrollWheel:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
NSPoint thepoint;
|
||||||
|
int button;
|
||||||
|
float sens;
|
||||||
|
|
||||||
|
if (event_funct[4] == NULL)
|
||||||
|
return ;
|
||||||
|
|
||||||
|
button = 0;
|
||||||
|
thepoint = [theEvent locationInWindow];
|
||||||
|
sens = [theEvent deltaY];
|
||||||
|
if (sens > 0.2)
|
||||||
|
button = 4;
|
||||||
|
if (sens < -0.2)
|
||||||
|
button = 5;
|
||||||
|
sens = [theEvent deltaX];
|
||||||
|
if (sens > 0.2)
|
||||||
|
button = 6;
|
||||||
|
if (sens < -0.2)
|
||||||
|
button = 7;
|
||||||
|
if (button != 0)
|
||||||
|
event_funct[4](button, (int)(thepoint.x), size_y - 1 - (int)(thepoint.y), event_param[4]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) exposeNotification:(NSNotification *)note
|
||||||
|
{
|
||||||
|
// printf("Expose...\n");
|
||||||
|
if (event_funct[12] != NULL)
|
||||||
|
event_funct[12](event_param[12]);
|
||||||
|
// printf("Expose done.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) closeNotification:(NSNotification *)note
|
||||||
|
{
|
||||||
|
if (event_funct[17] != NULL)
|
||||||
|
event_funct[17](event_param[17]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) deminiaturizeNotification:(NSNotification *)note
|
||||||
|
{
|
||||||
|
// if (event_funct[??] != NULL)
|
||||||
|
// event_funct[??](event_param[??]);
|
||||||
|
[self exposeNotification:note];
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@implementation MlxWin
|
||||||
|
|
||||||
|
- (id) initWithRect: (NSRect)rect andTitle: (NSString *)title pfaAttrs: (NSOpenGLPixelFormatAttribute *)attrs
|
||||||
|
{
|
||||||
|
NSOpenGLPixelFormat* pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
|
||||||
|
|
||||||
|
if ((self = [super initWithFrame:rect pixelFormat:pixFmt]) != nil)
|
||||||
|
{
|
||||||
|
NSUInteger windowStyle = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable;
|
||||||
|
|
||||||
|
win = [[NSWindowEvent alloc] initWithContentRect:rect
|
||||||
|
styleMask:windowStyle
|
||||||
|
backing:NSBackingStoreBuffered // NSBackingStoreNonretained
|
||||||
|
defer:NO];
|
||||||
|
[win setContentView:self];
|
||||||
|
[win setTitle:title];
|
||||||
|
[win setKeyRepeat:1];
|
||||||
|
[win makeKeyAndOrderFront:self];
|
||||||
|
|
||||||
|
// printf("init ctx: current %p ", [NSOpenGLContext currentContext]);
|
||||||
|
|
||||||
|
// ctx = [[NSOpenGLContext alloc] initWithFormat:pixFmt shareContext:[NSOpenGLContext currentContext]]; //other_context];
|
||||||
|
// [ctx setView:self];
|
||||||
|
// [ctx makeCurrentContext];
|
||||||
|
|
||||||
|
[[self openGLContext] makeCurrentContext];
|
||||||
|
[[self openGLContext] setView:self];
|
||||||
|
[self prepareOpenGL];
|
||||||
|
|
||||||
|
[self setNextKeyView:self];
|
||||||
|
|
||||||
|
// [[NSNotificationCenter defaultCenter] addObserver:win selector:@selector(exposeNotification:) name:@"NSWindowDidExposeNotification" object:nil];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:win selector:@selector(exposeNotification:) name:@"NSWindowDidBecomeKeyNotification" object:win];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:win selector:@selector(deminiaturizeNotification:) name:@"NSWindowDidDeminiaturizeNotification" object:win];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:win selector:@selector(closeNotification:) name:@"NSWindowWillCloseNotification" object:win];
|
||||||
|
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ctxNeedsUpdate:)
|
||||||
|
// name:NSViewGlobalFrameDidChangeNotification
|
||||||
|
// object:nil];
|
||||||
|
|
||||||
|
size_x = rect.size.width;
|
||||||
|
size_y = rect.size.height;
|
||||||
|
|
||||||
|
glClearColor(0, 0, 0, 0);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
glFlush();
|
||||||
|
|
||||||
|
//[win makeKeyAndOrderFront:nil];
|
||||||
|
// BOOL r = [win isKeyWindow];
|
||||||
|
// if (r==YES) printf("keywindow ok\n"); else printf("keywindow KO\n");
|
||||||
|
|
||||||
|
// Window controller subclass to set title
|
||||||
|
// NSWindowController* windowController = [[NSWindowController alloc] initWithWindow:win];
|
||||||
|
// [windowController windowTitleForDocumentDisplayName:title];
|
||||||
|
// [windowController showWindow:nil];
|
||||||
|
// MlxWinController *mlxWinCont = [[MlxWinController alloc] initWin:win andTitle:title];
|
||||||
|
|
||||||
|
// after nswindowcontroller who will retake first responder
|
||||||
|
// BOOL r = [win makeFirstResponder:nil];
|
||||||
|
// if (r==YES) printf("responder ok\n"); else printf("responder KO\n");
|
||||||
|
|
||||||
|
[pixFmt release];
|
||||||
|
}
|
||||||
|
return (self);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (int) pixel_management
|
||||||
|
{
|
||||||
|
bzero(&glsl, sizeof(glsl)); // so gldelete[shader/program] go silent on error.
|
||||||
|
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
glGenBuffers(1, &pixel_vbuffer);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, pixel_vbuffer);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(pixel_vertexes), pixel_vertexes, GL_DYNAMIC_DRAW); // 4 points buff
|
||||||
|
// pixel_ptr = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
||||||
|
|
||||||
|
glGenTextures(1, &pixel_texture);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, pixel_texture);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
pixtexbuff = malloc(sizeof(unsigned int)*size_x*size_y);
|
||||||
|
pixel_nb = size_x*size_y;
|
||||||
|
while (pixel_nb--) pixtexbuff[pixel_nb] = 0xFF000000;
|
||||||
|
pixel_nb = 0;
|
||||||
|
glTexImage2D(
|
||||||
|
GL_TEXTURE_2D, 0, /* target, level of detail */
|
||||||
|
GL_RGBA8, /* internal format */
|
||||||
|
size_x, size_y, 0, /* width, height, border */
|
||||||
|
GL_BGRA, GL_UNSIGNED_BYTE, /* external format, type */
|
||||||
|
pixtexbuff /* pixels */
|
||||||
|
);
|
||||||
|
// printf("pix tex err? 0x%x\n", glGetError());
|
||||||
|
|
||||||
|
if (mlx_shaders(&glsl))
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
glUseProgram(glsl.pixel_program);
|
||||||
|
glsl.loc_pixel_texture = glGetUniformLocation(glsl.pixel_program, "texture");
|
||||||
|
//glsl.loc_pixel_winhalfsize = glGetUniformLocation(glsl.pixel_program, "winhalfsize");
|
||||||
|
glsl.loc_pixel_position = glGetAttribLocation(glsl.pixel_program, "position");
|
||||||
|
// printf("err? 0x%x\n", glGetError());
|
||||||
|
|
||||||
|
glUseProgram(glsl.image_program);
|
||||||
|
glsl.loc_image_texture = glGetUniformLocation(glsl.image_program, "texture");
|
||||||
|
glsl.loc_image_pos = glGetUniformLocation(glsl.image_program, "imagepos");
|
||||||
|
glsl.loc_image_size = glGetUniformLocation(glsl.image_program, "imagesize");
|
||||||
|
glsl.loc_image_winhalfsize = glGetUniformLocation(glsl.image_program, "winhalfsize");
|
||||||
|
glsl.loc_image_position = glGetAttribLocation(glsl.image_program, "position");
|
||||||
|
// printf("err? 0x%x\n", glGetError());
|
||||||
|
|
||||||
|
glUseProgram(glsl.font_program);
|
||||||
|
glsl.loc_font_texture = glGetUniformLocation(glsl.font_program, "texture");
|
||||||
|
glsl.loc_font_color = glGetUniformLocation(glsl.font_program, "color");
|
||||||
|
glsl.loc_font_posinwin = glGetUniformLocation(glsl.font_program, "fontposinwin");
|
||||||
|
glsl.loc_font_posinatlas = glGetUniformLocation(glsl.font_program, "fontposinatlas");
|
||||||
|
glsl.loc_font_atlassize = glGetUniformLocation(glsl.font_program, "fontatlassize");
|
||||||
|
glsl.loc_font_winhalfsize = glGetUniformLocation(glsl.font_program, "winhalfsize");
|
||||||
|
glsl.loc_font_position = glGetAttribLocation(glsl.font_program, "position");
|
||||||
|
// printf("err? 0x%x\n", glGetError());
|
||||||
|
|
||||||
|
glFlush();
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) ctxNeedsUpdate
|
||||||
|
{
|
||||||
|
// printf("Context update\n");
|
||||||
|
[ctx update];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) selectGLContext
|
||||||
|
{
|
||||||
|
if ([NSOpenGLContext currentContext] != [self openGLContext])
|
||||||
|
{
|
||||||
|
// printf("ctx: %p => %p\n", [NSOpenGLContext currentContext], [self openGLContext]);
|
||||||
|
[[self openGLContext] makeCurrentContext];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) flushGLContext
|
||||||
|
{
|
||||||
|
[[self openGLContext] flushBuffer];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSOpenGLContext *) ctx
|
||||||
|
{
|
||||||
|
return (ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSWindowEvent *) win
|
||||||
|
{
|
||||||
|
return (win);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) pixelPutColor: (int)color X:(int)x Y:(int)y
|
||||||
|
{
|
||||||
|
pixel_nb ++;
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, pixel_vbuffer);
|
||||||
|
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, 1, 1, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)(&color));
|
||||||
|
|
||||||
|
if (pixel_nb >= MAX_PIXEL_NB)
|
||||||
|
[self mlx_gl_draw];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) destroyPixelManagement
|
||||||
|
{
|
||||||
|
free(pixtexbuff);
|
||||||
|
[self selectGLContext];
|
||||||
|
glDeleteBuffers(1, &pixel_vbuffer);
|
||||||
|
glDeleteTextures(1, &pixel_texture);
|
||||||
|
glDeleteProgram(glsl.pixel_program);
|
||||||
|
glDeleteProgram(glsl.image_program);
|
||||||
|
glDeleteShader(glsl.pixel_vshader);
|
||||||
|
glDeleteShader(glsl.pixel_fshader);
|
||||||
|
glDeleteShader(glsl.image_vshader);
|
||||||
|
glDeleteShader(glsl.image_fshader);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) destroyMe
|
||||||
|
{
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:win];
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||||
|
// [ctx release];
|
||||||
|
[win close];
|
||||||
|
[self release];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) setEvent:(int)event andFunc:(func_t)func andParam:(void *)param
|
||||||
|
{
|
||||||
|
[win setEvent:event andFunc:func andParam:param];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) setKeyRepeat:(int)mode
|
||||||
|
{
|
||||||
|
[win setKeyRepeat:mode];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) clearWin
|
||||||
|
{
|
||||||
|
glClearColor(0, 0, 0, 0);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) mlx_gl_draw_img:(mlx_img_list_t *)img andCtx:(mlx_img_ctx_t *)imgctx andX:(int)x andY:(int)y
|
||||||
|
{
|
||||||
|
|
||||||
|
if (pixel_nb >0)
|
||||||
|
[self mlx_gl_draw];
|
||||||
|
|
||||||
|
glUseProgram(glsl.image_program);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, imgctx->texture);
|
||||||
|
glUniform1i(glsl.loc_image_texture, 0);
|
||||||
|
|
||||||
|
glUniform2f(glsl.loc_image_winhalfsize, size_x/2, size_y/2);
|
||||||
|
glUniform2f(glsl.loc_image_pos, x, size_y - y);
|
||||||
|
glUniform2f(glsl.loc_image_size, img->width, -img->height);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, imgctx->vbuffer);
|
||||||
|
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2*sizeof(GLfloat), (void*)0);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); // src alpha 0xFF : keep dst
|
||||||
|
glBlendEquation(GL_FUNC_ADD);
|
||||||
|
|
||||||
|
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||||
|
glDisableVertexAttribArray(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) mlx_gl_draw_font:(mlx_img_list_t *)img andCtx:(mlx_img_ctx_t *)imgctx andX:(int)x andY:(int)y andColor:(int)color glyphX:(int)gx glyphY:(int)gy
|
||||||
|
{
|
||||||
|
GLfloat color_tab[4];
|
||||||
|
|
||||||
|
if (pixel_nb >0)
|
||||||
|
[self mlx_gl_draw];
|
||||||
|
|
||||||
|
color_tab[0] = ((float)((color&0xFF0000)>>16))/255.0;
|
||||||
|
color_tab[1] = ((float)((color&0xFF00)>>8))/255.0;
|
||||||
|
color_tab[2] = ((float)((color&0xFF)>>0))/255.0;
|
||||||
|
color_tab[3] = 1.0;
|
||||||
|
glUseProgram(glsl.font_program);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, imgctx->texture);
|
||||||
|
glUniform1i(glsl.loc_font_texture, 0);
|
||||||
|
glUniform4fv(glsl.loc_font_color, 1, color_tab);
|
||||||
|
|
||||||
|
glUniform2f(glsl.loc_font_winhalfsize, size_x/2, size_y/2);
|
||||||
|
glUniform2f(glsl.loc_font_posinwin, x, size_y - 1 - y);
|
||||||
|
glUniform2f(glsl.loc_font_posinatlas, gx, gy);
|
||||||
|
glUniform2f(glsl.loc_font_atlassize, img->width, img->height);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, imgctx->vbuffer);
|
||||||
|
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2*sizeof(GLfloat), (void*)0);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); // src alpha 0xFF : keep dst
|
||||||
|
glBlendEquation(GL_FUNC_ADD);
|
||||||
|
|
||||||
|
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||||
|
glDisableVertexAttribArray(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) mlx_gl_draw
|
||||||
|
{
|
||||||
|
if (pixel_nb <= 0)
|
||||||
|
return ;
|
||||||
|
|
||||||
|
glUseProgram(glsl.pixel_program);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, pixel_vbuffer);
|
||||||
|
glUniform1i(glsl.loc_pixel_texture, 0);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, pixel_vbuffer);
|
||||||
|
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2*sizeof(GLfloat), (void*)0);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); // src alpha 0xFF : keep dst
|
||||||
|
glBlendEquation(GL_FUNC_ADD);
|
||||||
|
|
||||||
|
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||||
|
glDisableVertexAttribArray(0);
|
||||||
|
|
||||||
|
pixel_nb = size_x*size_y;
|
||||||
|
while (pixel_nb--) pixtexbuff[pixel_nb] = 0xFF000000;
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, size_x, size_y, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixtexbuff);
|
||||||
|
pixel_nb = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
// mlx API
|
||||||
|
|
||||||
|
|
||||||
|
void *mlx_new_window(mlx_ptr_t *mlx_ptr, int size_x, int size_y, char *title)
|
||||||
|
{
|
||||||
|
mlx_win_list_t *newwin;
|
||||||
|
NSString *str;
|
||||||
|
|
||||||
|
if ((newwin = malloc(sizeof(*newwin))) == NULL)
|
||||||
|
return ((void *)0);
|
||||||
|
newwin->img_list = NULL;
|
||||||
|
newwin->next = mlx_ptr->win_list;
|
||||||
|
newwin->nb_flush = 0;
|
||||||
|
newwin->pixmgt = 1;
|
||||||
|
mlx_ptr->win_list = newwin;
|
||||||
|
|
||||||
|
NSRect windowRect = NSMakeRect(100, 100, size_x, size_y);
|
||||||
|
str = [NSString stringWithCString:title encoding:NSASCIIStringEncoding];
|
||||||
|
newwin->winid = [[MlxWin alloc] initWithRect:windowRect andTitle:str pfaAttrs:pfa_attrs];
|
||||||
|
if (newwin->winid)
|
||||||
|
if (![(id)(newwin->winid) pixel_management])
|
||||||
|
{
|
||||||
|
[(id)(newwin->winid) destroyPixelManagement];
|
||||||
|
[(id)(newwin->winid) destroyMe];
|
||||||
|
}
|
||||||
|
return ((void *)newwin);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mlx_clear_window(mlx_ptr_t *mlx_ptr, mlx_win_list_t *win_ptr)
|
||||||
|
{
|
||||||
|
[(id)(win_ptr->winid) selectGLContext];
|
||||||
|
[(id)(win_ptr->winid) clearWin];
|
||||||
|
win_ptr->nb_flush ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mlx_expose_hook(mlx_win_list_t *win_ptr, int (*funct_ptr)(), void *param)
|
||||||
|
{
|
||||||
|
[(id)(win_ptr->winid) setEvent:12 andFunc:funct_ptr andParam:param];
|
||||||
|
}
|
||||||
|
|
||||||
|
void mlx_key_hook(mlx_win_list_t *win_ptr, int (*funct_ptr)(), void *param)
|
||||||
|
{
|
||||||
|
[(id)(win_ptr->winid) setEvent:3 andFunc:funct_ptr andParam:param];
|
||||||
|
}
|
||||||
|
|
||||||
|
void mlx_mouse_hook(mlx_win_list_t *win_ptr, int (*funct_ptr)(), void *param)
|
||||||
|
{
|
||||||
|
[(id)(win_ptr->winid) setEvent:4 andFunc:funct_ptr andParam:param];
|
||||||
|
}
|
||||||
|
|
||||||
|
void mlx_hook(mlx_win_list_t *win_ptr, int x_event, int x_mask, int (*funct_ptr)(), void *param)
|
||||||
|
{
|
||||||
|
[(id)(win_ptr->winid) setEvent:x_event andFunc:funct_ptr andParam:param];
|
||||||
|
}
|
||||||
|
|
||||||
|
int mlx_do_key_autorepeatoff(mlx_ptr_t *mlx_ptr)
|
||||||
|
{
|
||||||
|
mlx_win_list_t *win;
|
||||||
|
|
||||||
|
win = mlx_ptr->win_list;
|
||||||
|
while (win)
|
||||||
|
{
|
||||||
|
[(id)(win->winid) setKeyRepeat:0];
|
||||||
|
win = win->next;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int mlx_do_key_autorepeaton(mlx_ptr_t *mlx_ptr)
|
||||||
|
{
|
||||||
|
mlx_win_list_t *win;
|
||||||
|
|
||||||
|
win = mlx_ptr->win_list;
|
||||||
|
while (win)
|
||||||
|
{
|
||||||
|
[(id)(win->winid) setKeyRepeat:1];
|
||||||
|
win = win->next;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mlx_destroy_window(mlx_ptr_t *mlx_ptr, mlx_win_list_t *win_to_del)
|
||||||
|
{
|
||||||
|
mlx_win_list_t first;
|
||||||
|
mlx_win_list_t *win;
|
||||||
|
mlx_img_ctx_t *ctx;
|
||||||
|
mlx_img_ctx_t *ctx2;
|
||||||
|
|
||||||
|
first.next = mlx_ptr->win_list;
|
||||||
|
win = &first;
|
||||||
|
while (win && win->next)
|
||||||
|
{
|
||||||
|
if (win->next == win_to_del)
|
||||||
|
win->next = win->next->next;
|
||||||
|
win = win->next;
|
||||||
|
}
|
||||||
|
mlx_ptr->win_list = first.next;
|
||||||
|
|
||||||
|
if (win_to_del->pixmgt)
|
||||||
|
{
|
||||||
|
[(id)(win_to_del->winid) selectGLContext];
|
||||||
|
ctx = win_to_del->img_list; // should be null anyway if no pixel management
|
||||||
|
while (ctx)
|
||||||
|
{
|
||||||
|
glDeleteBuffers(1, &(ctx->vbuffer));
|
||||||
|
glDeleteTextures(1, &(ctx->texture));
|
||||||
|
ctx2 = ctx;
|
||||||
|
ctx = ctx->next;
|
||||||
|
free(ctx2);
|
||||||
|
}
|
||||||
|
[(id)(win_to_del->winid) destroyPixelManagement];
|
||||||
|
}
|
||||||
|
[(id)(win_to_del->winid) destroyMe];
|
||||||
|
free(win_to_del);
|
||||||
|
|
||||||
|
// printf("destroy window done.\n");
|
||||||
|
mlx_do_sync(mlx_ptr);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
21
libs/minilibx_opengl_20191021/mlx_opengl.h
Normal file
21
libs/minilibx_opengl_20191021/mlx_opengl.h
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
**
|
||||||
|
** mlx_opengl.h
|
||||||
|
**
|
||||||
|
** public include, use it after mlx.h
|
||||||
|
** designed only for minilibx_macos
|
||||||
|
**
|
||||||
|
*/
|
||||||
|
|
||||||
|
void *mlx_new_opengl_window(void *mlx_ptr, int size_x, int size_y, char *title);
|
||||||
|
|
||||||
|
/* create an opengl window. put_image & pixel_put & string_put do not work there. */
|
||||||
|
|
||||||
|
int mlx_opengl_swap_buffers(void *win_ptr);
|
||||||
|
|
||||||
|
/* the created window is double buffered. Use this funct to swap buffers */
|
||||||
|
/* this funct will call glFlush(). Don't call it. */
|
||||||
|
|
||||||
|
int mlx_opengl_window_set_context(void *win_ptr);
|
||||||
|
|
||||||
|
/* in case multiple opengl windows are present, change opengl active context */
|
||||||
57
libs/minilibx_opengl_20191021/mlx_opengl.m
Normal file
57
libs/minilibx_opengl_20191021/mlx_opengl.m
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
// mlx_opengl.m
|
||||||
|
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
#import <OpenGL/gl3.h>
|
||||||
|
#import <AppKit/NSOpenGLView.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "mlx_int.h"
|
||||||
|
#include "mlx_new_window.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
NSOpenGLPixelFormatAttribute pfa_attrs_opengl[] =
|
||||||
|
{
|
||||||
|
NSOpenGLPFADepthSize, 32,
|
||||||
|
NSOpenGLPFADoubleBuffer,
|
||||||
|
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion4_1Core,
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void *mlx_new_opengl_window(mlx_ptr_t *mlx_ptr, int size_x, int size_y, char *title)
|
||||||
|
{
|
||||||
|
mlx_win_list_t *newwin;
|
||||||
|
NSString *str;
|
||||||
|
|
||||||
|
if ((newwin = malloc(sizeof(*newwin))) == NULL)
|
||||||
|
return ((void *)0);
|
||||||
|
newwin->img_list = NULL;
|
||||||
|
newwin->next = mlx_ptr->win_list;
|
||||||
|
newwin->nb_flush = 0;
|
||||||
|
newwin->pixmgt = 0;
|
||||||
|
mlx_ptr->win_list = newwin;
|
||||||
|
|
||||||
|
NSRect windowRect = NSMakeRect(100, 100, size_x, size_y);
|
||||||
|
str = [NSString stringWithCString:title encoding:NSASCIIStringEncoding];
|
||||||
|
newwin->winid = [[MlxWin alloc] initWithRect:windowRect andTitle:str pfaAttrs:pfa_attrs_opengl];
|
||||||
|
|
||||||
|
return ((void *)newwin);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mlx_opengl_swap_buffers(mlx_win_list_t *win_ptr)
|
||||||
|
{
|
||||||
|
[(id)(win_ptr->winid) flushGLContext];
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int mlx_opengl_window_set_context(mlx_win_list_t *win_ptr)
|
||||||
|
{
|
||||||
|
[(id)(win_ptr->winid) selectGLContext];
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
418
libs/minilibx_opengl_20191021/mlx_png.c
Normal file
418
libs/minilibx_opengl_20191021/mlx_png.c
Normal file
@@ -0,0 +1,418 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <err.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#include "zlib.h"
|
||||||
|
|
||||||
|
#include <OpenGL/gl3.h>
|
||||||
|
#include "mlx_int.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define PNG_MAGIC_SIZE 8
|
||||||
|
unsigned char magic[PNG_MAGIC_SIZE] = {137, 80, 78, 71, 13, 10, 26, 10};
|
||||||
|
#define PNG_HDR_SIZE 13
|
||||||
|
|
||||||
|
#define Z_CHUNK 32768
|
||||||
|
|
||||||
|
#define ERR_MAGIC_SIZE 1
|
||||||
|
#define ERR_MAGIC_WRONG 2
|
||||||
|
#define ERR_STRUCT_INCOMPLETE 3
|
||||||
|
#define ERR_STRUCT_HDR 4
|
||||||
|
#define ERR_STRUCT_END 5
|
||||||
|
#define ERR_STRUCT_CRC 6
|
||||||
|
#define ERR_STRUCT_INCIMPL 7
|
||||||
|
#define ERR_STRUCT_DAT 8
|
||||||
|
#define ERR_STRUCT_MISSCHK 9
|
||||||
|
#define ERR_ZLIB 10
|
||||||
|
#define ERR_DATA_MISMATCH 11
|
||||||
|
#define ERR_DATA_FILTER 12
|
||||||
|
char *(mipng_err[]) =
|
||||||
|
{
|
||||||
|
"No error",
|
||||||
|
"Not enough size for magic",
|
||||||
|
"Wrong magic",
|
||||||
|
"Incomplete chunk structure",
|
||||||
|
"Duplicate or incorrect header",
|
||||||
|
"Duplicate or incorrect end",
|
||||||
|
"Invalid CRC in chunk",
|
||||||
|
"Incorrect header or configuration not implemented",
|
||||||
|
"Non consecutive dat chunks",
|
||||||
|
"Missing header/dat/end chunk(s)",
|
||||||
|
"Zlib inflate error",
|
||||||
|
"Inflated data size mismatch",
|
||||||
|
"Unknown scanline filter"
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct png_info_s
|
||||||
|
{
|
||||||
|
unsigned int width;
|
||||||
|
unsigned int height;
|
||||||
|
int depth;
|
||||||
|
int color;
|
||||||
|
int interlace;
|
||||||
|
int bpp;
|
||||||
|
} png_info_t;
|
||||||
|
|
||||||
|
|
||||||
|
int mipng_is_type(unsigned char *ptr, char *type)
|
||||||
|
{
|
||||||
|
if (ptr[4] == type[0] && ptr[5] == type[1] && ptr[6] == type[2] && ptr[7] == type[3])
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned char mipng_defilter_none(unsigned char *buff, int pos, int a, int b, int c)
|
||||||
|
{ return (buff[pos]); }
|
||||||
|
unsigned char mipng_defilter_sub(unsigned char *buff, int pos, int a, int b, int c)
|
||||||
|
{ return (buff[pos]+(unsigned int)a); }
|
||||||
|
unsigned char mipng_defilter_up(unsigned char *buff, int pos, int a, int b, int c)
|
||||||
|
{ return (buff[pos]+(unsigned int)b); }
|
||||||
|
unsigned char mipng_defilter_average(unsigned char *buff, int pos, int a, int b, int c)
|
||||||
|
{ return (buff[pos]+((unsigned int)a+(unsigned int)b)/2); }
|
||||||
|
unsigned char mipng_defilter_paeth(unsigned char *buff, int pos, int a, int b, int c)
|
||||||
|
{
|
||||||
|
int p;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
p = a + b - c;
|
||||||
|
if (abs(b - c) <= abs(a - c) && abs(b - c) <= abs(a + b - c - c))
|
||||||
|
result = a;
|
||||||
|
else
|
||||||
|
if (abs(a - c) <= abs(a + b - c - c))
|
||||||
|
result = b;
|
||||||
|
else
|
||||||
|
result = c;
|
||||||
|
return (buff[pos]+result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
unsigned char (*(mipng_defilter[]))(unsigned char *buff, int pos, int a, int b, int c) =
|
||||||
|
{
|
||||||
|
mipng_defilter_none,
|
||||||
|
mipng_defilter_sub,
|
||||||
|
mipng_defilter_up,
|
||||||
|
mipng_defilter_average,
|
||||||
|
mipng_defilter_paeth
|
||||||
|
};
|
||||||
|
|
||||||
|
// only work for mlx mac or img 32bpp
|
||||||
|
int mipng_fill_img(mlx_img_list_t *img, unsigned char *buf, png_info_t *pi)
|
||||||
|
{
|
||||||
|
unsigned int current_filter;
|
||||||
|
int ipos;
|
||||||
|
int bpos;
|
||||||
|
int ilen;
|
||||||
|
int iline;
|
||||||
|
int blen;
|
||||||
|
unsigned char tmp;
|
||||||
|
unsigned char *ibuf;
|
||||||
|
|
||||||
|
ibuf = (unsigned char *)img->buffer;
|
||||||
|
iline = img->width * UNIQ_BPP;
|
||||||
|
ilen = img->width * img->height * UNIQ_BPP;
|
||||||
|
blen = img->width * img->height * pi->bpp + img->height;
|
||||||
|
ipos = 0;
|
||||||
|
bpos = 0;
|
||||||
|
while (ipos < ilen && bpos < blen)
|
||||||
|
{
|
||||||
|
if ((ipos % iline) == 0)
|
||||||
|
{
|
||||||
|
if ((current_filter = buf[bpos++]) > 4)
|
||||||
|
return (ERR_DATA_FILTER);
|
||||||
|
}
|
||||||
|
ibuf[ipos] = mipng_defilter[current_filter](buf, bpos,
|
||||||
|
ipos%iline>3?ibuf[ipos-UNIQ_BPP]:0,
|
||||||
|
(ipos>=iline)?ibuf[ipos-iline]:0,
|
||||||
|
(ipos>=iline && ipos%iline>3)?ibuf[ipos-iline-UNIQ_BPP]:0);
|
||||||
|
ipos ++;
|
||||||
|
bpos ++;
|
||||||
|
if (pi->depth == 16)
|
||||||
|
bpos ++;
|
||||||
|
if (ipos % 4 == 3 && pi->color == 2) // no alpha
|
||||||
|
img->buffer[ipos++] = 0xFF;
|
||||||
|
}
|
||||||
|
if (ipos != ilen || bpos != blen)
|
||||||
|
{
|
||||||
|
// printf("fill err ipos %d vs %d, bpos %d vs %d\n", ipos, ilen, bpos, blen);
|
||||||
|
return (ERR_DATA_MISMATCH);
|
||||||
|
}
|
||||||
|
ipos = 0;
|
||||||
|
while (ipos < ilen)
|
||||||
|
{
|
||||||
|
tmp = ibuf[ipos];
|
||||||
|
ibuf[ipos] = ibuf[ipos+2];
|
||||||
|
ibuf[ipos+2] = tmp;
|
||||||
|
ibuf[ipos+3] = 0xFF - ibuf[ipos+3];
|
||||||
|
ipos += UNIQ_BPP;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mipng_data(mlx_img_list_t *img, unsigned char *dat, png_info_t *pi)
|
||||||
|
{
|
||||||
|
unsigned int len;
|
||||||
|
int b_pos;
|
||||||
|
unsigned char *buffer;
|
||||||
|
int ret;
|
||||||
|
int z_ret;
|
||||||
|
unsigned z_have;
|
||||||
|
z_stream z_strm;
|
||||||
|
unsigned char z_out[Z_CHUNK];
|
||||||
|
|
||||||
|
b_pos = 0;
|
||||||
|
if (!(buffer = malloc((long long)img->width*(long long)img->height*(long long)pi->bpp + img->height)))
|
||||||
|
err(1, "Can't malloc");
|
||||||
|
z_strm.zalloc = Z_NULL;
|
||||||
|
z_strm.zfree = Z_NULL;
|
||||||
|
z_strm.opaque = Z_NULL;
|
||||||
|
z_strm.avail_in = 0;
|
||||||
|
z_strm.next_in = Z_NULL;
|
||||||
|
z_ret = inflateInit(&z_strm);
|
||||||
|
if (z_ret != Z_OK)
|
||||||
|
return (ERR_ZLIB);
|
||||||
|
|
||||||
|
while (mipng_is_type(dat, "IDAT"))
|
||||||
|
{
|
||||||
|
len = *((unsigned int *)dat);
|
||||||
|
len = ntohl(len);
|
||||||
|
z_strm.avail_in = len;
|
||||||
|
z_strm.next_in = dat + 8;
|
||||||
|
z_strm.avail_out = 0;
|
||||||
|
while (z_strm.avail_out == 0)
|
||||||
|
{
|
||||||
|
z_strm.avail_out = Z_CHUNK;
|
||||||
|
z_strm.next_out = z_out;
|
||||||
|
z_ret = inflate(&z_strm, Z_NO_FLUSH);
|
||||||
|
// printf("inflate ret %d avail_out %d\n", z_ret, z_strm.avail_out);
|
||||||
|
if (z_ret != Z_OK && z_ret != Z_STREAM_END)
|
||||||
|
{
|
||||||
|
inflateEnd(&z_strm);
|
||||||
|
return (ERR_ZLIB);
|
||||||
|
}
|
||||||
|
if (b_pos + Z_CHUNK - z_strm.avail_out > img->width*img->height*pi->bpp+img->height)
|
||||||
|
{
|
||||||
|
inflateEnd(&z_strm);
|
||||||
|
return (ERR_DATA_MISMATCH);
|
||||||
|
}
|
||||||
|
bcopy(z_out, buffer+b_pos, Z_CHUNK - z_strm.avail_out);
|
||||||
|
b_pos += Z_CHUNK - z_strm.avail_out;
|
||||||
|
}
|
||||||
|
dat += len + 4 + 4 + 4;
|
||||||
|
}
|
||||||
|
inflateEnd(&z_strm);
|
||||||
|
if (b_pos != img->width*img->height*pi->bpp+img->height)
|
||||||
|
{
|
||||||
|
// printf("pb : bpos %d vs expected %d\n", b_pos, img->width*img->height*pi->bpp+img->height);
|
||||||
|
return (ERR_DATA_MISMATCH);
|
||||||
|
}
|
||||||
|
if ((ret = mipng_fill_img(img, buffer, pi)))
|
||||||
|
return (ret);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int mipng_magic(unsigned char *ptr, int size)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (size < PNG_MAGIC_SIZE)
|
||||||
|
return (ERR_MAGIC_SIZE);
|
||||||
|
i = 0;
|
||||||
|
while (i < PNG_MAGIC_SIZE)
|
||||||
|
if (*(ptr++) != magic[i++])
|
||||||
|
return (ERR_MAGIC_WRONG);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned long crc_table[256] = { 0, 0x77073096, 0xee0e612c, 0x990951ba, 0x76dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0xedb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x9b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x1db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x6b6b51f, 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0xf00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x86d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x3b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x4db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, 0xd6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0xa00ae27, 0x7d079eb1, 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x26d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x5005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0xcb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0xbdbdf21, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d };
|
||||||
|
|
||||||
|
// From http://www.w3.org/TR/PNG/#D-CRCAppendix
|
||||||
|
int mipng_crc(unsigned char *ptr, int len)
|
||||||
|
{
|
||||||
|
unsigned int file_crc;
|
||||||
|
unsigned long crc;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
file_crc = *((unsigned int *)(ptr+4+4+len));
|
||||||
|
file_crc = ntohl(file_crc);
|
||||||
|
|
||||||
|
crc = 0xffffffffL;
|
||||||
|
i = 0;
|
||||||
|
while (i < len+4)
|
||||||
|
crc = crc_table[(crc ^ ptr[(i++)+4]) & 0xff] ^ (crc >> 8);
|
||||||
|
crc ^= 0xffffffffL;
|
||||||
|
|
||||||
|
if (file_crc != crc)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mipng_structure(unsigned char *ptr, int size, unsigned char **hdr, unsigned char **dat)
|
||||||
|
{
|
||||||
|
unsigned int len;
|
||||||
|
int dat_state;
|
||||||
|
int end;
|
||||||
|
|
||||||
|
dat_state = 0;
|
||||||
|
*hdr = NULL;
|
||||||
|
*dat = NULL;
|
||||||
|
end = 0;
|
||||||
|
while (size)
|
||||||
|
{
|
||||||
|
if (size >= 4) // length present
|
||||||
|
{
|
||||||
|
len = *((unsigned int *)ptr);
|
||||||
|
len = ntohl(len);
|
||||||
|
if (size < 4 + 4 + 4 + len)
|
||||||
|
return (ERR_STRUCT_INCOMPLETE);
|
||||||
|
if (mipng_crc(ptr, len))
|
||||||
|
return (ERR_STRUCT_CRC);
|
||||||
|
// printf("found chunk len %d type %c%c%c%c\n", len, *(ptr+4), *(ptr+5), *(ptr+6), *(ptr+7));
|
||||||
|
if (mipng_is_type(ptr, "IHDR"))
|
||||||
|
{
|
||||||
|
if (*hdr || len != PNG_HDR_SIZE)
|
||||||
|
return (ERR_STRUCT_HDR);
|
||||||
|
*hdr = ptr;
|
||||||
|
}
|
||||||
|
if (mipng_is_type(ptr, "IEND"))
|
||||||
|
{
|
||||||
|
if (len != 0 || size != 4+4+4)
|
||||||
|
return (ERR_STRUCT_END);
|
||||||
|
end = 1;
|
||||||
|
}
|
||||||
|
if (mipng_is_type(ptr, "IDAT"))
|
||||||
|
{
|
||||||
|
if (dat_state == 0)
|
||||||
|
{
|
||||||
|
dat_state = 1;
|
||||||
|
*dat = ptr;
|
||||||
|
}
|
||||||
|
if (dat_state == 2)
|
||||||
|
return (ERR_STRUCT_DAT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (dat_state == 1)
|
||||||
|
dat_state = 2;
|
||||||
|
size -= 4+4+4+len;
|
||||||
|
ptr += 4+4+4+len;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return (ERR_STRUCT_INCOMPLETE);
|
||||||
|
}
|
||||||
|
if (*hdr == 0 || *dat == 0 || end == 0)
|
||||||
|
return (ERR_STRUCT_MISSCHK);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mipng_verif_hdr(unsigned char *hdr, png_info_t *pi)
|
||||||
|
{
|
||||||
|
unsigned int compress;
|
||||||
|
unsigned int filter;
|
||||||
|
|
||||||
|
hdr += 8;
|
||||||
|
pi->width = ntohl(*((unsigned long *)hdr));
|
||||||
|
pi->height = ntohl(*((unsigned long *)(hdr+4)));
|
||||||
|
pi->depth = *(hdr+8);
|
||||||
|
pi->color = *(hdr+9);
|
||||||
|
compress = *(hdr+10);
|
||||||
|
filter = *(hdr+11);
|
||||||
|
pi->interlace = *(hdr+12);
|
||||||
|
if (pi->width <= 0 || pi->height <= 0 || (pi->depth != 8 && pi->depth != 16)
|
||||||
|
|| (pi->color != 2 && pi->color != 6) || compress != 0 || filter != 0 || pi->interlace != 0)
|
||||||
|
return (ERR_STRUCT_INCIMPL);
|
||||||
|
pi->bpp = pi->depth / 8;
|
||||||
|
if (pi->color == 2)
|
||||||
|
pi->bpp *= 3;
|
||||||
|
if (pi->color == 6)
|
||||||
|
pi->bpp *= 4;
|
||||||
|
// printf("hdr info : %d x %d, depth %d, col type %d, comp %d, filter %d, interlace %d\nbpp is %d\n",
|
||||||
|
// pi->width, pi->height, pi->depth, pi->color, compress, filter, pi->interlace, pi->bpp);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mlx_img_list_t *mlx_int_parse_png(mlx_ptr_t *xvar, unsigned char *fptr, int size)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
unsigned char *hdr;
|
||||||
|
unsigned char *dat;
|
||||||
|
png_info_t pi;
|
||||||
|
mlx_img_list_t *img;
|
||||||
|
|
||||||
|
if ((err = mipng_magic(fptr, size)))
|
||||||
|
{
|
||||||
|
warnx("mlx PNG error : %s", mipng_err[err]);
|
||||||
|
return ((mlx_img_list_t *)0);
|
||||||
|
}
|
||||||
|
fptr += PNG_MAGIC_SIZE;
|
||||||
|
size -= PNG_MAGIC_SIZE;
|
||||||
|
if ((err = mipng_structure(fptr, size, &hdr, &dat)))
|
||||||
|
{
|
||||||
|
warnx("mlx PNG error : %s", mipng_err[err]);
|
||||||
|
return ((mlx_img_list_t *)0);
|
||||||
|
}
|
||||||
|
if ((err = mipng_verif_hdr(hdr, &pi)))
|
||||||
|
{
|
||||||
|
warnx("mlx PNG error : %s", mipng_err[err]);
|
||||||
|
return ((mlx_img_list_t *)0);
|
||||||
|
}
|
||||||
|
if (!(img = mlx_new_image(xvar, pi.width, pi.height)))
|
||||||
|
{
|
||||||
|
warnx("mlx PNG error : Can't create mlx image");
|
||||||
|
return ((mlx_img_list_t *)0);
|
||||||
|
}
|
||||||
|
if ((err = mipng_data(img, dat, &pi)))
|
||||||
|
{
|
||||||
|
mlx_destroy_image(xvar, img);
|
||||||
|
warnx("mlx PNG error : %s", mipng_err[err]);
|
||||||
|
return ((mlx_img_list_t *)0);
|
||||||
|
}
|
||||||
|
return (img);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void *mlx_png_file_to_image(mlx_ptr_t *xvar, char *file, int *width, int *height)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
int size;
|
||||||
|
unsigned char *ptr;
|
||||||
|
mlx_img_list_t *img;
|
||||||
|
|
||||||
|
if ((fd = open(file, O_RDONLY)) == -1 || (size = lseek(fd, 0, SEEK_END)) == -1 ||
|
||||||
|
(ptr = mmap(0, size, PROT_READ, MAP_PRIVATE, fd, 0)) == (void *)MAP_FAILED)
|
||||||
|
{
|
||||||
|
if (fd >= 0)
|
||||||
|
close(fd);
|
||||||
|
warnx("Can't map png file '%s'", file);
|
||||||
|
return ((void *)0);
|
||||||
|
}
|
||||||
|
if ((img = mlx_int_parse_png(xvar, ptr, size)))
|
||||||
|
{
|
||||||
|
*width = img->width;
|
||||||
|
*height = img->height;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*width = 0;
|
||||||
|
*height = 0;
|
||||||
|
}
|
||||||
|
munmap(ptr,size);
|
||||||
|
close(fd);
|
||||||
|
return (img);
|
||||||
|
}
|
||||||
4
libs/minilibx_opengl_20191021/mlx_png.h
Normal file
4
libs/minilibx_opengl_20191021/mlx_png.h
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void *mlx_png_file_to_image(void *xvar, char *file, int *width, int *height);
|
||||||
763
libs/minilibx_opengl_20191021/mlx_rgb.c
Normal file
763
libs/minilibx_opengl_20191021/mlx_rgb.c
Normal file
@@ -0,0 +1,763 @@
|
|||||||
|
/*
|
||||||
|
** This is a generated file with rgb2c.pl and rgb.txt from
|
||||||
|
** the XFree86 distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
struct s_col_name mlx_col_name[] =
|
||||||
|
{
|
||||||
|
{ "snow" , 0xfffafa },
|
||||||
|
{ "ghost white" , 0xf8f8ff },
|
||||||
|
{ "ghostwhite" , 0xf8f8ff },
|
||||||
|
{ "white smoke" , 0xf5f5f5 },
|
||||||
|
{ "whitesmoke" , 0xf5f5f5 },
|
||||||
|
{ "gainsboro" , 0xdcdcdc },
|
||||||
|
{ "floral white" , 0xfffaf0 },
|
||||||
|
{ "floralwhite" , 0xfffaf0 },
|
||||||
|
{ "old lace" , 0xfdf5e6 },
|
||||||
|
{ "oldlace" , 0xfdf5e6 },
|
||||||
|
{ "linen" , 0xfaf0e6 },
|
||||||
|
{ "antique white" , 0xfaebd7 },
|
||||||
|
{ "antiquewhite" , 0xfaebd7 },
|
||||||
|
{ "papaya whip" , 0xffefd5 },
|
||||||
|
{ "papayawhip" , 0xffefd5 },
|
||||||
|
{ "blanched almond" , 0xffebcd },
|
||||||
|
{ "blanchedalmond" , 0xffebcd },
|
||||||
|
{ "bisque" , 0xffe4c4 },
|
||||||
|
{ "peach puff" , 0xffdab9 },
|
||||||
|
{ "peachpuff" , 0xffdab9 },
|
||||||
|
{ "navajo white" , 0xffdead },
|
||||||
|
{ "navajowhite" , 0xffdead },
|
||||||
|
{ "moccasin" , 0xffe4b5 },
|
||||||
|
{ "cornsilk" , 0xfff8dc },
|
||||||
|
{ "ivory" , 0xfffff0 },
|
||||||
|
{ "lemon chiffon" , 0xfffacd },
|
||||||
|
{ "lemonchiffon" , 0xfffacd },
|
||||||
|
{ "seashell" , 0xfff5ee },
|
||||||
|
{ "honeydew" , 0xf0fff0 },
|
||||||
|
{ "mint cream" , 0xf5fffa },
|
||||||
|
{ "mintcream" , 0xf5fffa },
|
||||||
|
{ "azure" , 0xf0ffff },
|
||||||
|
{ "alice blue" , 0xf0f8ff },
|
||||||
|
{ "aliceblue" , 0xf0f8ff },
|
||||||
|
{ "lavender" , 0xe6e6fa },
|
||||||
|
{ "lavender blush" , 0xfff0f5 },
|
||||||
|
{ "lavenderblush" , 0xfff0f5 },
|
||||||
|
{ "misty rose" , 0xffe4e1 },
|
||||||
|
{ "mistyrose" , 0xffe4e1 },
|
||||||
|
{ "white" , 0xffffff },
|
||||||
|
{ "black" , 0x0 },
|
||||||
|
{ "dark slate" , 0x2f4f4f },
|
||||||
|
{ "darkslategray" , 0x2f4f4f },
|
||||||
|
{ "dark slate" , 0x2f4f4f },
|
||||||
|
{ "darkslategrey" , 0x2f4f4f },
|
||||||
|
{ "dim gray" , 0x696969 },
|
||||||
|
{ "dimgray" , 0x696969 },
|
||||||
|
{ "dim grey" , 0x696969 },
|
||||||
|
{ "dimgrey" , 0x696969 },
|
||||||
|
{ "slate gray" , 0x708090 },
|
||||||
|
{ "slategray" , 0x708090 },
|
||||||
|
{ "slate grey" , 0x708090 },
|
||||||
|
{ "slategrey" , 0x708090 },
|
||||||
|
{ "light slate" , 0x778899 },
|
||||||
|
{ "lightslategray" , 0x778899 },
|
||||||
|
{ "light slate" , 0x778899 },
|
||||||
|
{ "lightslategrey" , 0x778899 },
|
||||||
|
{ "gray" , 0xbebebe },
|
||||||
|
{ "grey" , 0xbebebe },
|
||||||
|
{ "light grey" , 0xd3d3d3 },
|
||||||
|
{ "lightgrey" , 0xd3d3d3 },
|
||||||
|
{ "light gray" , 0xd3d3d3 },
|
||||||
|
{ "lightgray" , 0xd3d3d3 },
|
||||||
|
{ "midnight blue" , 0x191970 },
|
||||||
|
{ "midnightblue" , 0x191970 },
|
||||||
|
{ "navy" , 0x80 },
|
||||||
|
{ "navy blue" , 0x80 },
|
||||||
|
{ "navyblue" , 0x80 },
|
||||||
|
{ "cornflower blue" , 0x6495ed },
|
||||||
|
{ "cornflowerblue" , 0x6495ed },
|
||||||
|
{ "dark slate" , 0x483d8b },
|
||||||
|
{ "darkslateblue" , 0x483d8b },
|
||||||
|
{ "slate blue" , 0x6a5acd },
|
||||||
|
{ "slateblue" , 0x6a5acd },
|
||||||
|
{ "medium slate" , 0x7b68ee },
|
||||||
|
{ "mediumslateblue" , 0x7b68ee },
|
||||||
|
{ "light slate" , 0x8470ff },
|
||||||
|
{ "lightslateblue" , 0x8470ff },
|
||||||
|
{ "medium blue" , 0xcd },
|
||||||
|
{ "mediumblue" , 0xcd },
|
||||||
|
{ "royal blue" , 0x4169e1 },
|
||||||
|
{ "royalblue" , 0x4169e1 },
|
||||||
|
{ "blue" , 0xff },
|
||||||
|
{ "dodger blue" , 0x1e90ff },
|
||||||
|
{ "dodgerblue" , 0x1e90ff },
|
||||||
|
{ "deep sky" , 0xbfff },
|
||||||
|
{ "deepskyblue" , 0xbfff },
|
||||||
|
{ "sky blue" , 0x87ceeb },
|
||||||
|
{ "skyblue" , 0x87ceeb },
|
||||||
|
{ "light sky" , 0x87cefa },
|
||||||
|
{ "lightskyblue" , 0x87cefa },
|
||||||
|
{ "steel blue" , 0x4682b4 },
|
||||||
|
{ "steelblue" , 0x4682b4 },
|
||||||
|
{ "light steel" , 0xb0c4de },
|
||||||
|
{ "lightsteelblue" , 0xb0c4de },
|
||||||
|
{ "light blue" , 0xadd8e6 },
|
||||||
|
{ "lightblue" , 0xadd8e6 },
|
||||||
|
{ "powder blue" , 0xb0e0e6 },
|
||||||
|
{ "powderblue" , 0xb0e0e6 },
|
||||||
|
{ "pale turquoise" , 0xafeeee },
|
||||||
|
{ "paleturquoise" , 0xafeeee },
|
||||||
|
{ "dark turquoise" , 0xced1 },
|
||||||
|
{ "darkturquoise" , 0xced1 },
|
||||||
|
{ "medium turquoise" , 0x48d1cc },
|
||||||
|
{ "mediumturquoise" , 0x48d1cc },
|
||||||
|
{ "turquoise" , 0x40e0d0 },
|
||||||
|
{ "cyan" , 0xffff },
|
||||||
|
{ "light cyan" , 0xe0ffff },
|
||||||
|
{ "lightcyan" , 0xe0ffff },
|
||||||
|
{ "cadet blue" , 0x5f9ea0 },
|
||||||
|
{ "cadetblue" , 0x5f9ea0 },
|
||||||
|
{ "medium aquamarine" , 0x66cdaa },
|
||||||
|
{ "mediumaquamarine" , 0x66cdaa },
|
||||||
|
{ "aquamarine" , 0x7fffd4 },
|
||||||
|
{ "dark green" , 0x6400 },
|
||||||
|
{ "darkgreen" , 0x6400 },
|
||||||
|
{ "dark olive" , 0x556b2f },
|
||||||
|
{ "darkolivegreen" , 0x556b2f },
|
||||||
|
{ "dark sea" , 0x8fbc8f },
|
||||||
|
{ "darkseagreen" , 0x8fbc8f },
|
||||||
|
{ "sea green" , 0x2e8b57 },
|
||||||
|
{ "seagreen" , 0x2e8b57 },
|
||||||
|
{ "medium sea" , 0x3cb371 },
|
||||||
|
{ "mediumseagreen" , 0x3cb371 },
|
||||||
|
{ "light sea" , 0x20b2aa },
|
||||||
|
{ "lightseagreen" , 0x20b2aa },
|
||||||
|
{ "pale green" , 0x98fb98 },
|
||||||
|
{ "palegreen" , 0x98fb98 },
|
||||||
|
{ "spring green" , 0xff7f },
|
||||||
|
{ "springgreen" , 0xff7f },
|
||||||
|
{ "lawn green" , 0x7cfc00 },
|
||||||
|
{ "lawngreen" , 0x7cfc00 },
|
||||||
|
{ "green" , 0xff00 },
|
||||||
|
{ "chartreuse" , 0x7fff00 },
|
||||||
|
{ "medium spring" , 0xfa9a },
|
||||||
|
{ "mediumspringgreen" , 0xfa9a },
|
||||||
|
{ "green yellow" , 0xadff2f },
|
||||||
|
{ "greenyellow" , 0xadff2f },
|
||||||
|
{ "lime green" , 0x32cd32 },
|
||||||
|
{ "limegreen" , 0x32cd32 },
|
||||||
|
{ "yellow green" , 0x9acd32 },
|
||||||
|
{ "yellowgreen" , 0x9acd32 },
|
||||||
|
{ "forest green" , 0x228b22 },
|
||||||
|
{ "forestgreen" , 0x228b22 },
|
||||||
|
{ "olive drab" , 0x6b8e23 },
|
||||||
|
{ "olivedrab" , 0x6b8e23 },
|
||||||
|
{ "dark khaki" , 0xbdb76b },
|
||||||
|
{ "darkkhaki" , 0xbdb76b },
|
||||||
|
{ "khaki" , 0xf0e68c },
|
||||||
|
{ "pale goldenrod" , 0xeee8aa },
|
||||||
|
{ "palegoldenrod" , 0xeee8aa },
|
||||||
|
{ "light goldenrod" , 0xfafad2 },
|
||||||
|
{ "lightgoldenrodyellow" , 0xfafad2 },
|
||||||
|
{ "light yellow" , 0xffffe0 },
|
||||||
|
{ "lightyellow" , 0xffffe0 },
|
||||||
|
{ "yellow" , 0xffff00 },
|
||||||
|
{ "gold" , 0xffd700 },
|
||||||
|
{ "light goldenrod" , 0xeedd82 },
|
||||||
|
{ "lightgoldenrod" , 0xeedd82 },
|
||||||
|
{ "goldenrod" , 0xdaa520 },
|
||||||
|
{ "dark goldenrod" , 0xb8860b },
|
||||||
|
{ "darkgoldenrod" , 0xb8860b },
|
||||||
|
{ "rosy brown" , 0xbc8f8f },
|
||||||
|
{ "rosybrown" , 0xbc8f8f },
|
||||||
|
{ "indian red" , 0xcd5c5c },
|
||||||
|
{ "indianred" , 0xcd5c5c },
|
||||||
|
{ "saddle brown" , 0x8b4513 },
|
||||||
|
{ "saddlebrown" , 0x8b4513 },
|
||||||
|
{ "sienna" , 0xa0522d },
|
||||||
|
{ "peru" , 0xcd853f },
|
||||||
|
{ "burlywood" , 0xdeb887 },
|
||||||
|
{ "beige" , 0xf5f5dc },
|
||||||
|
{ "wheat" , 0xf5deb3 },
|
||||||
|
{ "sandy brown" , 0xf4a460 },
|
||||||
|
{ "sandybrown" , 0xf4a460 },
|
||||||
|
{ "tan" , 0xd2b48c },
|
||||||
|
{ "chocolate" , 0xd2691e },
|
||||||
|
{ "firebrick" , 0xb22222 },
|
||||||
|
{ "brown" , 0xa52a2a },
|
||||||
|
{ "dark salmon" , 0xe9967a },
|
||||||
|
{ "darksalmon" , 0xe9967a },
|
||||||
|
{ "salmon" , 0xfa8072 },
|
||||||
|
{ "light salmon" , 0xffa07a },
|
||||||
|
{ "lightsalmon" , 0xffa07a },
|
||||||
|
{ "orange" , 0xffa500 },
|
||||||
|
{ "dark orange" , 0xff8c00 },
|
||||||
|
{ "darkorange" , 0xff8c00 },
|
||||||
|
{ "coral" , 0xff7f50 },
|
||||||
|
{ "light coral" , 0xf08080 },
|
||||||
|
{ "lightcoral" , 0xf08080 },
|
||||||
|
{ "tomato" , 0xff6347 },
|
||||||
|
{ "orange red" , 0xff4500 },
|
||||||
|
{ "orangered" , 0xff4500 },
|
||||||
|
{ "red" , 0xff0000 },
|
||||||
|
{ "hot pink" , 0xff69b4 },
|
||||||
|
{ "hotpink" , 0xff69b4 },
|
||||||
|
{ "deep pink" , 0xff1493 },
|
||||||
|
{ "deeppink" , 0xff1493 },
|
||||||
|
{ "pink" , 0xffc0cb },
|
||||||
|
{ "light pink" , 0xffb6c1 },
|
||||||
|
{ "lightpink" , 0xffb6c1 },
|
||||||
|
{ "pale violet" , 0xdb7093 },
|
||||||
|
{ "palevioletred" , 0xdb7093 },
|
||||||
|
{ "maroon" , 0xb03060 },
|
||||||
|
{ "medium violet" , 0xc71585 },
|
||||||
|
{ "mediumvioletred" , 0xc71585 },
|
||||||
|
{ "violet red" , 0xd02090 },
|
||||||
|
{ "violetred" , 0xd02090 },
|
||||||
|
{ "magenta" , 0xff00ff },
|
||||||
|
{ "violet" , 0xee82ee },
|
||||||
|
{ "plum" , 0xdda0dd },
|
||||||
|
{ "orchid" , 0xda70d6 },
|
||||||
|
{ "medium orchid" , 0xba55d3 },
|
||||||
|
{ "mediumorchid" , 0xba55d3 },
|
||||||
|
{ "dark orchid" , 0x9932cc },
|
||||||
|
{ "darkorchid" , 0x9932cc },
|
||||||
|
{ "dark violet" , 0x9400d3 },
|
||||||
|
{ "darkviolet" , 0x9400d3 },
|
||||||
|
{ "blue violet" , 0x8a2be2 },
|
||||||
|
{ "blueviolet" , 0x8a2be2 },
|
||||||
|
{ "purple" , 0xa020f0 },
|
||||||
|
{ "medium purple" , 0x9370db },
|
||||||
|
{ "mediumpurple" , 0x9370db },
|
||||||
|
{ "thistle" , 0xd8bfd8 },
|
||||||
|
{ "snow1" , 0xfffafa },
|
||||||
|
{ "snow2" , 0xeee9e9 },
|
||||||
|
{ "snow3" , 0xcdc9c9 },
|
||||||
|
{ "snow4" , 0x8b8989 },
|
||||||
|
{ "seashell1" , 0xfff5ee },
|
||||||
|
{ "seashell2" , 0xeee5de },
|
||||||
|
{ "seashell3" , 0xcdc5bf },
|
||||||
|
{ "seashell4" , 0x8b8682 },
|
||||||
|
{ "antiquewhite1" , 0xffefdb },
|
||||||
|
{ "antiquewhite2" , 0xeedfcc },
|
||||||
|
{ "antiquewhite3" , 0xcdc0b0 },
|
||||||
|
{ "antiquewhite4" , 0x8b8378 },
|
||||||
|
{ "bisque1" , 0xffe4c4 },
|
||||||
|
{ "bisque2" , 0xeed5b7 },
|
||||||
|
{ "bisque3" , 0xcdb79e },
|
||||||
|
{ "bisque4" , 0x8b7d6b },
|
||||||
|
{ "peachpuff1" , 0xffdab9 },
|
||||||
|
{ "peachpuff2" , 0xeecbad },
|
||||||
|
{ "peachpuff3" , 0xcdaf95 },
|
||||||
|
{ "peachpuff4" , 0x8b7765 },
|
||||||
|
{ "navajowhite1" , 0xffdead },
|
||||||
|
{ "navajowhite2" , 0xeecfa1 },
|
||||||
|
{ "navajowhite3" , 0xcdb38b },
|
||||||
|
{ "navajowhite4" , 0x8b795e },
|
||||||
|
{ "lemonchiffon1" , 0xfffacd },
|
||||||
|
{ "lemonchiffon2" , 0xeee9bf },
|
||||||
|
{ "lemonchiffon3" , 0xcdc9a5 },
|
||||||
|
{ "lemonchiffon4" , 0x8b8970 },
|
||||||
|
{ "cornsilk1" , 0xfff8dc },
|
||||||
|
{ "cornsilk2" , 0xeee8cd },
|
||||||
|
{ "cornsilk3" , 0xcdc8b1 },
|
||||||
|
{ "cornsilk4" , 0x8b8878 },
|
||||||
|
{ "ivory1" , 0xfffff0 },
|
||||||
|
{ "ivory2" , 0xeeeee0 },
|
||||||
|
{ "ivory3" , 0xcdcdc1 },
|
||||||
|
{ "ivory4" , 0x8b8b83 },
|
||||||
|
{ "honeydew1" , 0xf0fff0 },
|
||||||
|
{ "honeydew2" , 0xe0eee0 },
|
||||||
|
{ "honeydew3" , 0xc1cdc1 },
|
||||||
|
{ "honeydew4" , 0x838b83 },
|
||||||
|
{ "lavenderblush1" , 0xfff0f5 },
|
||||||
|
{ "lavenderblush2" , 0xeee0e5 },
|
||||||
|
{ "lavenderblush3" , 0xcdc1c5 },
|
||||||
|
{ "lavenderblush4" , 0x8b8386 },
|
||||||
|
{ "mistyrose1" , 0xffe4e1 },
|
||||||
|
{ "mistyrose2" , 0xeed5d2 },
|
||||||
|
{ "mistyrose3" , 0xcdb7b5 },
|
||||||
|
{ "mistyrose4" , 0x8b7d7b },
|
||||||
|
{ "azure1" , 0xf0ffff },
|
||||||
|
{ "azure2" , 0xe0eeee },
|
||||||
|
{ "azure3" , 0xc1cdcd },
|
||||||
|
{ "azure4" , 0x838b8b },
|
||||||
|
{ "slateblue1" , 0x836fff },
|
||||||
|
{ "slateblue2" , 0x7a67ee },
|
||||||
|
{ "slateblue3" , 0x6959cd },
|
||||||
|
{ "slateblue4" , 0x473c8b },
|
||||||
|
{ "royalblue1" , 0x4876ff },
|
||||||
|
{ "royalblue2" , 0x436eee },
|
||||||
|
{ "royalblue3" , 0x3a5fcd },
|
||||||
|
{ "royalblue4" , 0x27408b },
|
||||||
|
{ "blue1" , 0xff },
|
||||||
|
{ "blue2" , 0xee },
|
||||||
|
{ "blue3" , 0xcd },
|
||||||
|
{ "blue4" , 0x8b },
|
||||||
|
{ "dodgerblue1" , 0x1e90ff },
|
||||||
|
{ "dodgerblue2" , 0x1c86ee },
|
||||||
|
{ "dodgerblue3" , 0x1874cd },
|
||||||
|
{ "dodgerblue4" , 0x104e8b },
|
||||||
|
{ "steelblue1" , 0x63b8ff },
|
||||||
|
{ "steelblue2" , 0x5cacee },
|
||||||
|
{ "steelblue3" , 0x4f94cd },
|
||||||
|
{ "steelblue4" , 0x36648b },
|
||||||
|
{ "deepskyblue1" , 0xbfff },
|
||||||
|
{ "deepskyblue2" , 0xb2ee },
|
||||||
|
{ "deepskyblue3" , 0x9acd },
|
||||||
|
{ "deepskyblue4" , 0x688b },
|
||||||
|
{ "skyblue1" , 0x87ceff },
|
||||||
|
{ "skyblue2" , 0x7ec0ee },
|
||||||
|
{ "skyblue3" , 0x6ca6cd },
|
||||||
|
{ "skyblue4" , 0x4a708b },
|
||||||
|
{ "lightskyblue1" , 0xb0e2ff },
|
||||||
|
{ "lightskyblue2" , 0xa4d3ee },
|
||||||
|
{ "lightskyblue3" , 0x8db6cd },
|
||||||
|
{ "lightskyblue4" , 0x607b8b },
|
||||||
|
{ "slategray1" , 0xc6e2ff },
|
||||||
|
{ "slategray2" , 0xb9d3ee },
|
||||||
|
{ "slategray3" , 0x9fb6cd },
|
||||||
|
{ "slategray4" , 0x6c7b8b },
|
||||||
|
{ "lightsteelblue1" , 0xcae1ff },
|
||||||
|
{ "lightsteelblue2" , 0xbcd2ee },
|
||||||
|
{ "lightsteelblue3" , 0xa2b5cd },
|
||||||
|
{ "lightsteelblue4" , 0x6e7b8b },
|
||||||
|
{ "lightblue1" , 0xbfefff },
|
||||||
|
{ "lightblue2" , 0xb2dfee },
|
||||||
|
{ "lightblue3" , 0x9ac0cd },
|
||||||
|
{ "lightblue4" , 0x68838b },
|
||||||
|
{ "lightcyan1" , 0xe0ffff },
|
||||||
|
{ "lightcyan2" , 0xd1eeee },
|
||||||
|
{ "lightcyan3" , 0xb4cdcd },
|
||||||
|
{ "lightcyan4" , 0x7a8b8b },
|
||||||
|
{ "paleturquoise1" , 0xbbffff },
|
||||||
|
{ "paleturquoise2" , 0xaeeeee },
|
||||||
|
{ "paleturquoise3" , 0x96cdcd },
|
||||||
|
{ "paleturquoise4" , 0x668b8b },
|
||||||
|
{ "cadetblue1" , 0x98f5ff },
|
||||||
|
{ "cadetblue2" , 0x8ee5ee },
|
||||||
|
{ "cadetblue3" , 0x7ac5cd },
|
||||||
|
{ "cadetblue4" , 0x53868b },
|
||||||
|
{ "turquoise1" , 0xf5ff },
|
||||||
|
{ "turquoise2" , 0xe5ee },
|
||||||
|
{ "turquoise3" , 0xc5cd },
|
||||||
|
{ "turquoise4" , 0x868b },
|
||||||
|
{ "cyan1" , 0xffff },
|
||||||
|
{ "cyan2" , 0xeeee },
|
||||||
|
{ "cyan3" , 0xcdcd },
|
||||||
|
{ "cyan4" , 0x8b8b },
|
||||||
|
{ "darkslategray1" , 0x97ffff },
|
||||||
|
{ "darkslategray2" , 0x8deeee },
|
||||||
|
{ "darkslategray3" , 0x79cdcd },
|
||||||
|
{ "darkslategray4" , 0x528b8b },
|
||||||
|
{ "aquamarine1" , 0x7fffd4 },
|
||||||
|
{ "aquamarine2" , 0x76eec6 },
|
||||||
|
{ "aquamarine3" , 0x66cdaa },
|
||||||
|
{ "aquamarine4" , 0x458b74 },
|
||||||
|
{ "darkseagreen1" , 0xc1ffc1 },
|
||||||
|
{ "darkseagreen2" , 0xb4eeb4 },
|
||||||
|
{ "darkseagreen3" , 0x9bcd9b },
|
||||||
|
{ "darkseagreen4" , 0x698b69 },
|
||||||
|
{ "seagreen1" , 0x54ff9f },
|
||||||
|
{ "seagreen2" , 0x4eee94 },
|
||||||
|
{ "seagreen3" , 0x43cd80 },
|
||||||
|
{ "seagreen4" , 0x2e8b57 },
|
||||||
|
{ "palegreen1" , 0x9aff9a },
|
||||||
|
{ "palegreen2" , 0x90ee90 },
|
||||||
|
{ "palegreen3" , 0x7ccd7c },
|
||||||
|
{ "palegreen4" , 0x548b54 },
|
||||||
|
{ "springgreen1" , 0xff7f },
|
||||||
|
{ "springgreen2" , 0xee76 },
|
||||||
|
{ "springgreen3" , 0xcd66 },
|
||||||
|
{ "springgreen4" , 0x8b45 },
|
||||||
|
{ "green1" , 0xff00 },
|
||||||
|
{ "green2" , 0xee00 },
|
||||||
|
{ "green3" , 0xcd00 },
|
||||||
|
{ "green4" , 0x8b00 },
|
||||||
|
{ "chartreuse1" , 0x7fff00 },
|
||||||
|
{ "chartreuse2" , 0x76ee00 },
|
||||||
|
{ "chartreuse3" , 0x66cd00 },
|
||||||
|
{ "chartreuse4" , 0x458b00 },
|
||||||
|
{ "olivedrab1" , 0xc0ff3e },
|
||||||
|
{ "olivedrab2" , 0xb3ee3a },
|
||||||
|
{ "olivedrab3" , 0x9acd32 },
|
||||||
|
{ "olivedrab4" , 0x698b22 },
|
||||||
|
{ "darkolivegreen1" , 0xcaff70 },
|
||||||
|
{ "darkolivegreen2" , 0xbcee68 },
|
||||||
|
{ "darkolivegreen3" , 0xa2cd5a },
|
||||||
|
{ "darkolivegreen4" , 0x6e8b3d },
|
||||||
|
{ "khaki1" , 0xfff68f },
|
||||||
|
{ "khaki2" , 0xeee685 },
|
||||||
|
{ "khaki3" , 0xcdc673 },
|
||||||
|
{ "khaki4" , 0x8b864e },
|
||||||
|
{ "lightgoldenrod1" , 0xffec8b },
|
||||||
|
{ "lightgoldenrod2" , 0xeedc82 },
|
||||||
|
{ "lightgoldenrod3" , 0xcdbe70 },
|
||||||
|
{ "lightgoldenrod4" , 0x8b814c },
|
||||||
|
{ "lightyellow1" , 0xffffe0 },
|
||||||
|
{ "lightyellow2" , 0xeeeed1 },
|
||||||
|
{ "lightyellow3" , 0xcdcdb4 },
|
||||||
|
{ "lightyellow4" , 0x8b8b7a },
|
||||||
|
{ "yellow1" , 0xffff00 },
|
||||||
|
{ "yellow2" , 0xeeee00 },
|
||||||
|
{ "yellow3" , 0xcdcd00 },
|
||||||
|
{ "yellow4" , 0x8b8b00 },
|
||||||
|
{ "gold1" , 0xffd700 },
|
||||||
|
{ "gold2" , 0xeec900 },
|
||||||
|
{ "gold3" , 0xcdad00 },
|
||||||
|
{ "gold4" , 0x8b7500 },
|
||||||
|
{ "goldenrod1" , 0xffc125 },
|
||||||
|
{ "goldenrod2" , 0xeeb422 },
|
||||||
|
{ "goldenrod3" , 0xcd9b1d },
|
||||||
|
{ "goldenrod4" , 0x8b6914 },
|
||||||
|
{ "darkgoldenrod1" , 0xffb90f },
|
||||||
|
{ "darkgoldenrod2" , 0xeead0e },
|
||||||
|
{ "darkgoldenrod3" , 0xcd950c },
|
||||||
|
{ "darkgoldenrod4" , 0x8b6508 },
|
||||||
|
{ "rosybrown1" , 0xffc1c1 },
|
||||||
|
{ "rosybrown2" , 0xeeb4b4 },
|
||||||
|
{ "rosybrown3" , 0xcd9b9b },
|
||||||
|
{ "rosybrown4" , 0x8b6969 },
|
||||||
|
{ "indianred1" , 0xff6a6a },
|
||||||
|
{ "indianred2" , 0xee6363 },
|
||||||
|
{ "indianred3" , 0xcd5555 },
|
||||||
|
{ "indianred4" , 0x8b3a3a },
|
||||||
|
{ "sienna1" , 0xff8247 },
|
||||||
|
{ "sienna2" , 0xee7942 },
|
||||||
|
{ "sienna3" , 0xcd6839 },
|
||||||
|
{ "sienna4" , 0x8b4726 },
|
||||||
|
{ "burlywood1" , 0xffd39b },
|
||||||
|
{ "burlywood2" , 0xeec591 },
|
||||||
|
{ "burlywood3" , 0xcdaa7d },
|
||||||
|
{ "burlywood4" , 0x8b7355 },
|
||||||
|
{ "wheat1" , 0xffe7ba },
|
||||||
|
{ "wheat2" , 0xeed8ae },
|
||||||
|
{ "wheat3" , 0xcdba96 },
|
||||||
|
{ "wheat4" , 0x8b7e66 },
|
||||||
|
{ "tan1" , 0xffa54f },
|
||||||
|
{ "tan2" , 0xee9a49 },
|
||||||
|
{ "tan3" , 0xcd853f },
|
||||||
|
{ "tan4" , 0x8b5a2b },
|
||||||
|
{ "chocolate1" , 0xff7f24 },
|
||||||
|
{ "chocolate2" , 0xee7621 },
|
||||||
|
{ "chocolate3" , 0xcd661d },
|
||||||
|
{ "chocolate4" , 0x8b4513 },
|
||||||
|
{ "firebrick1" , 0xff3030 },
|
||||||
|
{ "firebrick2" , 0xee2c2c },
|
||||||
|
{ "firebrick3" , 0xcd2626 },
|
||||||
|
{ "firebrick4" , 0x8b1a1a },
|
||||||
|
{ "brown1" , 0xff4040 },
|
||||||
|
{ "brown2" , 0xee3b3b },
|
||||||
|
{ "brown3" , 0xcd3333 },
|
||||||
|
{ "brown4" , 0x8b2323 },
|
||||||
|
{ "salmon1" , 0xff8c69 },
|
||||||
|
{ "salmon2" , 0xee8262 },
|
||||||
|
{ "salmon3" , 0xcd7054 },
|
||||||
|
{ "salmon4" , 0x8b4c39 },
|
||||||
|
{ "lightsalmon1" , 0xffa07a },
|
||||||
|
{ "lightsalmon2" , 0xee9572 },
|
||||||
|
{ "lightsalmon3" , 0xcd8162 },
|
||||||
|
{ "lightsalmon4" , 0x8b5742 },
|
||||||
|
{ "orange1" , 0xffa500 },
|
||||||
|
{ "orange2" , 0xee9a00 },
|
||||||
|
{ "orange3" , 0xcd8500 },
|
||||||
|
{ "orange4" , 0x8b5a00 },
|
||||||
|
{ "darkorange1" , 0xff7f00 },
|
||||||
|
{ "darkorange2" , 0xee7600 },
|
||||||
|
{ "darkorange3" , 0xcd6600 },
|
||||||
|
{ "darkorange4" , 0x8b4500 },
|
||||||
|
{ "coral1" , 0xff7256 },
|
||||||
|
{ "coral2" , 0xee6a50 },
|
||||||
|
{ "coral3" , 0xcd5b45 },
|
||||||
|
{ "coral4" , 0x8b3e2f },
|
||||||
|
{ "tomato1" , 0xff6347 },
|
||||||
|
{ "tomato2" , 0xee5c42 },
|
||||||
|
{ "tomato3" , 0xcd4f39 },
|
||||||
|
{ "tomato4" , 0x8b3626 },
|
||||||
|
{ "orangered1" , 0xff4500 },
|
||||||
|
{ "orangered2" , 0xee4000 },
|
||||||
|
{ "orangered3" , 0xcd3700 },
|
||||||
|
{ "orangered4" , 0x8b2500 },
|
||||||
|
{ "red1" , 0xff0000 },
|
||||||
|
{ "red2" , 0xee0000 },
|
||||||
|
{ "red3" , 0xcd0000 },
|
||||||
|
{ "red4" , 0x8b0000 },
|
||||||
|
{ "deeppink1" , 0xff1493 },
|
||||||
|
{ "deeppink2" , 0xee1289 },
|
||||||
|
{ "deeppink3" , 0xcd1076 },
|
||||||
|
{ "deeppink4" , 0x8b0a50 },
|
||||||
|
{ "hotpink1" , 0xff6eb4 },
|
||||||
|
{ "hotpink2" , 0xee6aa7 },
|
||||||
|
{ "hotpink3" , 0xcd6090 },
|
||||||
|
{ "hotpink4" , 0x8b3a62 },
|
||||||
|
{ "pink1" , 0xffb5c5 },
|
||||||
|
{ "pink2" , 0xeea9b8 },
|
||||||
|
{ "pink3" , 0xcd919e },
|
||||||
|
{ "pink4" , 0x8b636c },
|
||||||
|
{ "lightpink1" , 0xffaeb9 },
|
||||||
|
{ "lightpink2" , 0xeea2ad },
|
||||||
|
{ "lightpink3" , 0xcd8c95 },
|
||||||
|
{ "lightpink4" , 0x8b5f65 },
|
||||||
|
{ "palevioletred1" , 0xff82ab },
|
||||||
|
{ "palevioletred2" , 0xee799f },
|
||||||
|
{ "palevioletred3" , 0xcd6889 },
|
||||||
|
{ "palevioletred4" , 0x8b475d },
|
||||||
|
{ "maroon1" , 0xff34b3 },
|
||||||
|
{ "maroon2" , 0xee30a7 },
|
||||||
|
{ "maroon3" , 0xcd2990 },
|
||||||
|
{ "maroon4" , 0x8b1c62 },
|
||||||
|
{ "violetred1" , 0xff3e96 },
|
||||||
|
{ "violetred2" , 0xee3a8c },
|
||||||
|
{ "violetred3" , 0xcd3278 },
|
||||||
|
{ "violetred4" , 0x8b2252 },
|
||||||
|
{ "magenta1" , 0xff00ff },
|
||||||
|
{ "magenta2" , 0xee00ee },
|
||||||
|
{ "magenta3" , 0xcd00cd },
|
||||||
|
{ "magenta4" , 0x8b008b },
|
||||||
|
{ "orchid1" , 0xff83fa },
|
||||||
|
{ "orchid2" , 0xee7ae9 },
|
||||||
|
{ "orchid3" , 0xcd69c9 },
|
||||||
|
{ "orchid4" , 0x8b4789 },
|
||||||
|
{ "plum1" , 0xffbbff },
|
||||||
|
{ "plum2" , 0xeeaeee },
|
||||||
|
{ "plum3" , 0xcd96cd },
|
||||||
|
{ "plum4" , 0x8b668b },
|
||||||
|
{ "mediumorchid1" , 0xe066ff },
|
||||||
|
{ "mediumorchid2" , 0xd15fee },
|
||||||
|
{ "mediumorchid3" , 0xb452cd },
|
||||||
|
{ "mediumorchid4" , 0x7a378b },
|
||||||
|
{ "darkorchid1" , 0xbf3eff },
|
||||||
|
{ "darkorchid2" , 0xb23aee },
|
||||||
|
{ "darkorchid3" , 0x9a32cd },
|
||||||
|
{ "darkorchid4" , 0x68228b },
|
||||||
|
{ "purple1" , 0x9b30ff },
|
||||||
|
{ "purple2" , 0x912cee },
|
||||||
|
{ "purple3" , 0x7d26cd },
|
||||||
|
{ "purple4" , 0x551a8b },
|
||||||
|
{ "mediumpurple1" , 0xab82ff },
|
||||||
|
{ "mediumpurple2" , 0x9f79ee },
|
||||||
|
{ "mediumpurple3" , 0x8968cd },
|
||||||
|
{ "mediumpurple4" , 0x5d478b },
|
||||||
|
{ "thistle1" , 0xffe1ff },
|
||||||
|
{ "thistle2" , 0xeed2ee },
|
||||||
|
{ "thistle3" , 0xcdb5cd },
|
||||||
|
{ "thistle4" , 0x8b7b8b },
|
||||||
|
{ "gray0" , 0x0 },
|
||||||
|
{ "grey0" , 0x0 },
|
||||||
|
{ "gray1" , 0x30303 },
|
||||||
|
{ "grey1" , 0x30303 },
|
||||||
|
{ "gray2" , 0x50505 },
|
||||||
|
{ "grey2" , 0x50505 },
|
||||||
|
{ "gray3" , 0x80808 },
|
||||||
|
{ "grey3" , 0x80808 },
|
||||||
|
{ "gray4" , 0xa0a0a },
|
||||||
|
{ "grey4" , 0xa0a0a },
|
||||||
|
{ "gray5" , 0xd0d0d },
|
||||||
|
{ "grey5" , 0xd0d0d },
|
||||||
|
{ "gray6" , 0xf0f0f },
|
||||||
|
{ "grey6" , 0xf0f0f },
|
||||||
|
{ "gray7" , 0x121212 },
|
||||||
|
{ "grey7" , 0x121212 },
|
||||||
|
{ "gray8" , 0x141414 },
|
||||||
|
{ "grey8" , 0x141414 },
|
||||||
|
{ "gray9" , 0x171717 },
|
||||||
|
{ "grey9" , 0x171717 },
|
||||||
|
{ "gray10" , 0x1a1a1a },
|
||||||
|
{ "grey10" , 0x1a1a1a },
|
||||||
|
{ "gray11" , 0x1c1c1c },
|
||||||
|
{ "grey11" , 0x1c1c1c },
|
||||||
|
{ "gray12" , 0x1f1f1f },
|
||||||
|
{ "grey12" , 0x1f1f1f },
|
||||||
|
{ "gray13" , 0x212121 },
|
||||||
|
{ "grey13" , 0x212121 },
|
||||||
|
{ "gray14" , 0x242424 },
|
||||||
|
{ "grey14" , 0x242424 },
|
||||||
|
{ "gray15" , 0x262626 },
|
||||||
|
{ "grey15" , 0x262626 },
|
||||||
|
{ "gray16" , 0x292929 },
|
||||||
|
{ "grey16" , 0x292929 },
|
||||||
|
{ "gray17" , 0x2b2b2b },
|
||||||
|
{ "grey17" , 0x2b2b2b },
|
||||||
|
{ "gray18" , 0x2e2e2e },
|
||||||
|
{ "grey18" , 0x2e2e2e },
|
||||||
|
{ "gray19" , 0x303030 },
|
||||||
|
{ "grey19" , 0x303030 },
|
||||||
|
{ "gray20" , 0x333333 },
|
||||||
|
{ "grey20" , 0x333333 },
|
||||||
|
{ "gray21" , 0x363636 },
|
||||||
|
{ "grey21" , 0x363636 },
|
||||||
|
{ "gray22" , 0x383838 },
|
||||||
|
{ "grey22" , 0x383838 },
|
||||||
|
{ "gray23" , 0x3b3b3b },
|
||||||
|
{ "grey23" , 0x3b3b3b },
|
||||||
|
{ "gray24" , 0x3d3d3d },
|
||||||
|
{ "grey24" , 0x3d3d3d },
|
||||||
|
{ "gray25" , 0x404040 },
|
||||||
|
{ "grey25" , 0x404040 },
|
||||||
|
{ "gray26" , 0x424242 },
|
||||||
|
{ "grey26" , 0x424242 },
|
||||||
|
{ "gray27" , 0x454545 },
|
||||||
|
{ "grey27" , 0x454545 },
|
||||||
|
{ "gray28" , 0x474747 },
|
||||||
|
{ "grey28" , 0x474747 },
|
||||||
|
{ "gray29" , 0x4a4a4a },
|
||||||
|
{ "grey29" , 0x4a4a4a },
|
||||||
|
{ "gray30" , 0x4d4d4d },
|
||||||
|
{ "grey30" , 0x4d4d4d },
|
||||||
|
{ "gray31" , 0x4f4f4f },
|
||||||
|
{ "grey31" , 0x4f4f4f },
|
||||||
|
{ "gray32" , 0x525252 },
|
||||||
|
{ "grey32" , 0x525252 },
|
||||||
|
{ "gray33" , 0x545454 },
|
||||||
|
{ "grey33" , 0x545454 },
|
||||||
|
{ "gray34" , 0x575757 },
|
||||||
|
{ "grey34" , 0x575757 },
|
||||||
|
{ "gray35" , 0x595959 },
|
||||||
|
{ "grey35" , 0x595959 },
|
||||||
|
{ "gray36" , 0x5c5c5c },
|
||||||
|
{ "grey36" , 0x5c5c5c },
|
||||||
|
{ "gray37" , 0x5e5e5e },
|
||||||
|
{ "grey37" , 0x5e5e5e },
|
||||||
|
{ "gray38" , 0x616161 },
|
||||||
|
{ "grey38" , 0x616161 },
|
||||||
|
{ "gray39" , 0x636363 },
|
||||||
|
{ "grey39" , 0x636363 },
|
||||||
|
{ "gray40" , 0x666666 },
|
||||||
|
{ "grey40" , 0x666666 },
|
||||||
|
{ "gray41" , 0x696969 },
|
||||||
|
{ "grey41" , 0x696969 },
|
||||||
|
{ "gray42" , 0x6b6b6b },
|
||||||
|
{ "grey42" , 0x6b6b6b },
|
||||||
|
{ "gray43" , 0x6e6e6e },
|
||||||
|
{ "grey43" , 0x6e6e6e },
|
||||||
|
{ "gray44" , 0x707070 },
|
||||||
|
{ "grey44" , 0x707070 },
|
||||||
|
{ "gray45" , 0x737373 },
|
||||||
|
{ "grey45" , 0x737373 },
|
||||||
|
{ "gray46" , 0x757575 },
|
||||||
|
{ "grey46" , 0x757575 },
|
||||||
|
{ "gray47" , 0x787878 },
|
||||||
|
{ "grey47" , 0x787878 },
|
||||||
|
{ "gray48" , 0x7a7a7a },
|
||||||
|
{ "grey48" , 0x7a7a7a },
|
||||||
|
{ "gray49" , 0x7d7d7d },
|
||||||
|
{ "grey49" , 0x7d7d7d },
|
||||||
|
{ "gray50" , 0x7f7f7f },
|
||||||
|
{ "grey50" , 0x7f7f7f },
|
||||||
|
{ "gray51" , 0x828282 },
|
||||||
|
{ "grey51" , 0x828282 },
|
||||||
|
{ "gray52" , 0x858585 },
|
||||||
|
{ "grey52" , 0x858585 },
|
||||||
|
{ "gray53" , 0x878787 },
|
||||||
|
{ "grey53" , 0x878787 },
|
||||||
|
{ "gray54" , 0x8a8a8a },
|
||||||
|
{ "grey54" , 0x8a8a8a },
|
||||||
|
{ "gray55" , 0x8c8c8c },
|
||||||
|
{ "grey55" , 0x8c8c8c },
|
||||||
|
{ "gray56" , 0x8f8f8f },
|
||||||
|
{ "grey56" , 0x8f8f8f },
|
||||||
|
{ "gray57" , 0x919191 },
|
||||||
|
{ "grey57" , 0x919191 },
|
||||||
|
{ "gray58" , 0x949494 },
|
||||||
|
{ "grey58" , 0x949494 },
|
||||||
|
{ "gray59" , 0x969696 },
|
||||||
|
{ "grey59" , 0x969696 },
|
||||||
|
{ "gray60" , 0x999999 },
|
||||||
|
{ "grey60" , 0x999999 },
|
||||||
|
{ "gray61" , 0x9c9c9c },
|
||||||
|
{ "grey61" , 0x9c9c9c },
|
||||||
|
{ "gray62" , 0x9e9e9e },
|
||||||
|
{ "grey62" , 0x9e9e9e },
|
||||||
|
{ "gray63" , 0xa1a1a1 },
|
||||||
|
{ "grey63" , 0xa1a1a1 },
|
||||||
|
{ "gray64" , 0xa3a3a3 },
|
||||||
|
{ "grey64" , 0xa3a3a3 },
|
||||||
|
{ "gray65" , 0xa6a6a6 },
|
||||||
|
{ "grey65" , 0xa6a6a6 },
|
||||||
|
{ "gray66" , 0xa8a8a8 },
|
||||||
|
{ "grey66" , 0xa8a8a8 },
|
||||||
|
{ "gray67" , 0xababab },
|
||||||
|
{ "grey67" , 0xababab },
|
||||||
|
{ "gray68" , 0xadadad },
|
||||||
|
{ "grey68" , 0xadadad },
|
||||||
|
{ "gray69" , 0xb0b0b0 },
|
||||||
|
{ "grey69" , 0xb0b0b0 },
|
||||||
|
{ "gray70" , 0xb3b3b3 },
|
||||||
|
{ "grey70" , 0xb3b3b3 },
|
||||||
|
{ "gray71" , 0xb5b5b5 },
|
||||||
|
{ "grey71" , 0xb5b5b5 },
|
||||||
|
{ "gray72" , 0xb8b8b8 },
|
||||||
|
{ "grey72" , 0xb8b8b8 },
|
||||||
|
{ "gray73" , 0xbababa },
|
||||||
|
{ "grey73" , 0xbababa },
|
||||||
|
{ "gray74" , 0xbdbdbd },
|
||||||
|
{ "grey74" , 0xbdbdbd },
|
||||||
|
{ "gray75" , 0xbfbfbf },
|
||||||
|
{ "grey75" , 0xbfbfbf },
|
||||||
|
{ "gray76" , 0xc2c2c2 },
|
||||||
|
{ "grey76" , 0xc2c2c2 },
|
||||||
|
{ "gray77" , 0xc4c4c4 },
|
||||||
|
{ "grey77" , 0xc4c4c4 },
|
||||||
|
{ "gray78" , 0xc7c7c7 },
|
||||||
|
{ "grey78" , 0xc7c7c7 },
|
||||||
|
{ "gray79" , 0xc9c9c9 },
|
||||||
|
{ "grey79" , 0xc9c9c9 },
|
||||||
|
{ "gray80" , 0xcccccc },
|
||||||
|
{ "grey80" , 0xcccccc },
|
||||||
|
{ "gray81" , 0xcfcfcf },
|
||||||
|
{ "grey81" , 0xcfcfcf },
|
||||||
|
{ "gray82" , 0xd1d1d1 },
|
||||||
|
{ "grey82" , 0xd1d1d1 },
|
||||||
|
{ "gray83" , 0xd4d4d4 },
|
||||||
|
{ "grey83" , 0xd4d4d4 },
|
||||||
|
{ "gray84" , 0xd6d6d6 },
|
||||||
|
{ "grey84" , 0xd6d6d6 },
|
||||||
|
{ "gray85" , 0xd9d9d9 },
|
||||||
|
{ "grey85" , 0xd9d9d9 },
|
||||||
|
{ "gray86" , 0xdbdbdb },
|
||||||
|
{ "grey86" , 0xdbdbdb },
|
||||||
|
{ "gray87" , 0xdedede },
|
||||||
|
{ "grey87" , 0xdedede },
|
||||||
|
{ "gray88" , 0xe0e0e0 },
|
||||||
|
{ "grey88" , 0xe0e0e0 },
|
||||||
|
{ "gray89" , 0xe3e3e3 },
|
||||||
|
{ "grey89" , 0xe3e3e3 },
|
||||||
|
{ "gray90" , 0xe5e5e5 },
|
||||||
|
{ "grey90" , 0xe5e5e5 },
|
||||||
|
{ "gray91" , 0xe8e8e8 },
|
||||||
|
{ "grey91" , 0xe8e8e8 },
|
||||||
|
{ "gray92" , 0xebebeb },
|
||||||
|
{ "grey92" , 0xebebeb },
|
||||||
|
{ "gray93" , 0xededed },
|
||||||
|
{ "grey93" , 0xededed },
|
||||||
|
{ "gray94" , 0xf0f0f0 },
|
||||||
|
{ "grey94" , 0xf0f0f0 },
|
||||||
|
{ "gray95" , 0xf2f2f2 },
|
||||||
|
{ "grey95" , 0xf2f2f2 },
|
||||||
|
{ "gray96" , 0xf5f5f5 },
|
||||||
|
{ "grey96" , 0xf5f5f5 },
|
||||||
|
{ "gray97" , 0xf7f7f7 },
|
||||||
|
{ "grey97" , 0xf7f7f7 },
|
||||||
|
{ "gray98" , 0xfafafa },
|
||||||
|
{ "grey98" , 0xfafafa },
|
||||||
|
{ "gray99" , 0xfcfcfc },
|
||||||
|
{ "grey99" , 0xfcfcfc },
|
||||||
|
{ "gray100" , 0xffffff },
|
||||||
|
{ "grey100" , 0xffffff },
|
||||||
|
{ "dark grey" , 0xa9a9a9 },
|
||||||
|
{ "darkgrey" , 0xa9a9a9 },
|
||||||
|
{ "dark gray" , 0xa9a9a9 },
|
||||||
|
{ "darkgray" , 0xa9a9a9 },
|
||||||
|
{ "dark blue" , 0x8b },
|
||||||
|
{ "darkblue" , 0x8b },
|
||||||
|
{ "dark cyan" , 0x8b8b },
|
||||||
|
{ "darkcyan" , 0x8b8b },
|
||||||
|
{ "dark magenta" , 0x8b008b },
|
||||||
|
{ "darkmagenta" , 0x8b008b },
|
||||||
|
{ "dark red" , 0x8b0000 },
|
||||||
|
{ "darkred" , 0x8b0000 },
|
||||||
|
{ "light green" , 0x90ee90 },
|
||||||
|
{ "lightgreen" , 0x90ee90 },
|
||||||
|
{ "none", -1 },
|
||||||
|
{ 0, 0 }
|
||||||
|
};
|
||||||
240
libs/minilibx_opengl_20191021/mlx_shaders.c
Normal file
240
libs/minilibx_opengl_20191021/mlx_shaders.c
Normal file
@@ -0,0 +1,240 @@
|
|||||||
|
// mlx_shaders.c
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <OpenGL/gl3.h>
|
||||||
|
#include "mlx_int.h"
|
||||||
|
|
||||||
|
|
||||||
|
void display_log(GLuint object, void (*param_func)(), void (*getlog_func)())
|
||||||
|
{
|
||||||
|
GLint log_length;
|
||||||
|
char *log;
|
||||||
|
|
||||||
|
param_func(object, GL_INFO_LOG_LENGTH, &log_length);
|
||||||
|
log = malloc(log_length);
|
||||||
|
getlog_func(object, log_length, NULL, log);
|
||||||
|
fprintf(stderr, "%s", log);
|
||||||
|
free(log);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mlx_shaders_pixel(glsl_info_t *glsl)
|
||||||
|
{
|
||||||
|
char *source;
|
||||||
|
int length;
|
||||||
|
GLint action_ok;
|
||||||
|
|
||||||
|
glsl->pixel_vshader = glCreateShader(GL_VERTEX_SHADER);
|
||||||
|
source = strdup("#version 110 \n"
|
||||||
|
"attribute vec2 position;"
|
||||||
|
"varying vec2 texcoord;"
|
||||||
|
"void main()"
|
||||||
|
"{"
|
||||||
|
" gl_Position = vec4( position, 0.0, 1.0);"
|
||||||
|
" texcoord = vec2(position[0]+1.0, 1.0 - position[1]) / 2.0;"
|
||||||
|
"}");
|
||||||
|
length = strlen(source);
|
||||||
|
glShaderSource(glsl->pixel_vshader, 1, (const GLchar**)&source, &length);
|
||||||
|
glCompileShader(glsl->pixel_vshader);
|
||||||
|
free(source);
|
||||||
|
|
||||||
|
glGetShaderiv(glsl->pixel_vshader, GL_COMPILE_STATUS, &action_ok);
|
||||||
|
if (!action_ok) {
|
||||||
|
fprintf(stderr, "Failed to compile pixel vshader :\n");
|
||||||
|
display_log(glsl->pixel_vshader, glGetShaderiv, glGetShaderInfoLog);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
glsl->pixel_fshader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
|
source = strdup("#version 110 \n"
|
||||||
|
"uniform sampler2D texture;"
|
||||||
|
"varying vec2 texcoord;"
|
||||||
|
"void main()"
|
||||||
|
"{"
|
||||||
|
" gl_FragColor = texture2D(texture, texcoord);"
|
||||||
|
"}");
|
||||||
|
length = strlen(source);
|
||||||
|
glShaderSource(glsl->pixel_fshader, 1, (const GLchar**)&source, &length);
|
||||||
|
glCompileShader(glsl->pixel_fshader);
|
||||||
|
free(source);
|
||||||
|
|
||||||
|
glGetShaderiv(glsl->pixel_fshader, GL_COMPILE_STATUS, &action_ok);
|
||||||
|
if (!action_ok) {
|
||||||
|
fprintf(stderr, "Failed to compile pixel fshader :\n");
|
||||||
|
display_log(glsl->pixel_fshader, glGetShaderiv, glGetShaderInfoLog);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
glsl->pixel_program = glCreateProgram();
|
||||||
|
glAttachShader(glsl->pixel_program, glsl->pixel_vshader);
|
||||||
|
glAttachShader(glsl->pixel_program, glsl->pixel_fshader);
|
||||||
|
glLinkProgram(glsl->pixel_program);
|
||||||
|
|
||||||
|
glGetProgramiv(glsl->pixel_program, GL_LINK_STATUS, &action_ok);
|
||||||
|
if (!action_ok) {
|
||||||
|
fprintf(stderr, "Failed to link pixel shader program:\n");
|
||||||
|
display_log(glsl->pixel_program, glGetProgramiv, glGetProgramInfoLog);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
glFlush();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mlx_shaders_image(glsl_info_t *glsl)
|
||||||
|
{
|
||||||
|
char *source;
|
||||||
|
int length;
|
||||||
|
GLint action_ok;
|
||||||
|
|
||||||
|
glsl->image_vshader = glCreateShader(GL_VERTEX_SHADER);
|
||||||
|
source = strdup("#version 110 \n"
|
||||||
|
"attribute vec2 position;"
|
||||||
|
"uniform vec2 winhalfsize;"
|
||||||
|
"uniform vec2 imagepos;"
|
||||||
|
"uniform vec2 imagesize;"
|
||||||
|
"varying vec2 texcoord;"
|
||||||
|
"void main()"
|
||||||
|
"{"
|
||||||
|
" texcoord = position / imagesize;"
|
||||||
|
" vec2 pos = position - winhalfsize + imagepos;"
|
||||||
|
" pos = pos / winhalfsize;"
|
||||||
|
" gl_Position = vec4( pos, 0.0, 1.0);"
|
||||||
|
"}");
|
||||||
|
length = strlen(source);
|
||||||
|
glShaderSource(glsl->image_vshader, 1, (const GLchar**)&source, &length);
|
||||||
|
glCompileShader(glsl->image_vshader);
|
||||||
|
free(source);
|
||||||
|
|
||||||
|
glGetShaderiv(glsl->image_vshader, GL_COMPILE_STATUS, &action_ok);
|
||||||
|
if (!action_ok) {
|
||||||
|
fprintf(stderr, "Failed to compile image vshader :\n");
|
||||||
|
display_log(glsl->image_vshader, glGetShaderiv, glGetShaderInfoLog);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
glsl->image_fshader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
|
source = strdup("#version 110 \n"
|
||||||
|
"uniform sampler2D texture;"
|
||||||
|
"varying vec2 texcoord;"
|
||||||
|
"void main()"
|
||||||
|
"{"
|
||||||
|
" gl_FragColor = texture2D(texture, texcoord);"
|
||||||
|
"}");
|
||||||
|
length = strlen(source);
|
||||||
|
glShaderSource(glsl->image_fshader, 1, (const GLchar**)&source, &length);
|
||||||
|
glCompileShader(glsl->image_fshader);
|
||||||
|
free(source);
|
||||||
|
|
||||||
|
glGetShaderiv(glsl->image_fshader, GL_COMPILE_STATUS, &action_ok);
|
||||||
|
if (!action_ok) {
|
||||||
|
fprintf(stderr, "Failed to compile image fshader :\n");
|
||||||
|
display_log(glsl->image_fshader, glGetShaderiv, glGetShaderInfoLog);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
glsl->image_program = glCreateProgram();
|
||||||
|
glAttachShader(glsl->image_program, glsl->image_vshader);
|
||||||
|
glAttachShader(glsl->image_program, glsl->image_fshader);
|
||||||
|
glLinkProgram(glsl->image_program);
|
||||||
|
|
||||||
|
glGetProgramiv(glsl->image_program, GL_LINK_STATUS, &action_ok);
|
||||||
|
if (!action_ok) {
|
||||||
|
fprintf(stderr, "Failed to link image shader program:\n");
|
||||||
|
display_log(glsl->image_program, glGetProgramiv, glGetProgramInfoLog);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
glFlush();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int mlx_shaders_font(glsl_info_t *glsl)
|
||||||
|
{
|
||||||
|
char *source;
|
||||||
|
int length;
|
||||||
|
GLint action_ok;
|
||||||
|
|
||||||
|
glsl->font_vshader = glCreateShader(GL_VERTEX_SHADER);
|
||||||
|
source = strdup("#version 110 \n"
|
||||||
|
"attribute vec2 position;"
|
||||||
|
"uniform vec2 winhalfsize;"
|
||||||
|
"uniform vec2 fontposinwin;"
|
||||||
|
"uniform vec2 fontposinatlas;"
|
||||||
|
"uniform vec2 fontatlassize;"
|
||||||
|
"varying vec2 texcoord;"
|
||||||
|
"void main()"
|
||||||
|
"{"
|
||||||
|
#ifdef STRINGPUTX11
|
||||||
|
" texcoord = (position * vec2(1.4, -1.4) + fontposinatlas ) / fontatlassize;"
|
||||||
|
#else
|
||||||
|
" texcoord = (position * vec2(1.0, -1.0) + fontposinatlas ) / fontatlassize;"
|
||||||
|
#endif
|
||||||
|
" vec2 pos = position - winhalfsize + fontposinwin;"
|
||||||
|
" pos = pos / winhalfsize;"
|
||||||
|
" gl_Position = vec4( pos, 0.0, 1.0);"
|
||||||
|
"}");
|
||||||
|
length = strlen(source);
|
||||||
|
glShaderSource(glsl->font_vshader, 1, (const GLchar**)&source, &length);
|
||||||
|
glCompileShader(glsl->font_vshader);
|
||||||
|
free(source);
|
||||||
|
|
||||||
|
glGetShaderiv(glsl->font_vshader, GL_COMPILE_STATUS, &action_ok);
|
||||||
|
if (!action_ok) {
|
||||||
|
fprintf(stderr, "Failed to compile font vshader :\n");
|
||||||
|
display_log(glsl->font_vshader, glGetShaderiv, glGetShaderInfoLog);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
glsl->font_fshader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
|
source = strdup("#version 110 \n"
|
||||||
|
"uniform sampler2D texture;"
|
||||||
|
"uniform vec4 color;"
|
||||||
|
"varying vec2 texcoord;"
|
||||||
|
"void main()"
|
||||||
|
"{"
|
||||||
|
" gl_FragColor = color * texture2D(texture, texcoord);"
|
||||||
|
"}");
|
||||||
|
length = strlen(source);
|
||||||
|
glShaderSource(glsl->font_fshader, 1, (const GLchar**)&source, &length);
|
||||||
|
glCompileShader(glsl->font_fshader);
|
||||||
|
free(source);
|
||||||
|
|
||||||
|
glGetShaderiv(glsl->font_fshader, GL_COMPILE_STATUS, &action_ok);
|
||||||
|
if (!action_ok) {
|
||||||
|
fprintf(stderr, "Failed to compile font fshader :\n");
|
||||||
|
display_log(glsl->font_fshader, glGetShaderiv, glGetShaderInfoLog);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
glsl->font_program = glCreateProgram();
|
||||||
|
glAttachShader(glsl->font_program, glsl->font_vshader);
|
||||||
|
glAttachShader(glsl->font_program, glsl->font_fshader);
|
||||||
|
glLinkProgram(glsl->font_program);
|
||||||
|
|
||||||
|
glGetProgramiv(glsl->font_program, GL_LINK_STATUS, &action_ok);
|
||||||
|
if (!action_ok) {
|
||||||
|
fprintf(stderr, "Failed to link font shader program:\n");
|
||||||
|
display_log(glsl->font_program, glGetProgramiv, glGetProgramInfoLog);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
glFlush();
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int mlx_shaders(glsl_info_t *glsl)
|
||||||
|
{
|
||||||
|
return (mlx_shaders_pixel(glsl) + mlx_shaders_image(glsl) + mlx_shaders_font(glsl));
|
||||||
|
}
|
||||||
@@ -1,23 +1,35 @@
|
|||||||
/*
|
// mlx xpm
|
||||||
** xpm-read.c for MinilibX in
|
// by ol
|
||||||
**
|
|
||||||
** Made by Charlie Root
|
|
||||||
** Login <ol@epitech.net>
|
|
||||||
**
|
|
||||||
** Started on Tue Dec 11 15:25:27 2001 olivier crouzet
|
|
||||||
** Last update Sat Oct 1 14:40:55 2005 Olivier Crouzet
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <OpenGL/gl3.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <string.h>
|
||||||
#include "mlx_int.h"
|
#include "mlx_int.h"
|
||||||
|
|
||||||
extern struct s_col_name mlx_col_name[];
|
typedef struct s_xpm_col
|
||||||
|
{
|
||||||
|
int name;
|
||||||
|
int col;
|
||||||
|
} t_xpm_col;
|
||||||
|
|
||||||
|
|
||||||
|
struct s_col_name
|
||||||
|
{
|
||||||
|
char *name;
|
||||||
|
int color;
|
||||||
|
};
|
||||||
|
|
||||||
|
//extern struct s_col_name mlx_col_name[];
|
||||||
|
#include "mlx_rgb.c"
|
||||||
|
|
||||||
|
|
||||||
#define RETURN { if (colors) free(colors); if (tab) free(tab); \
|
#define RETURN { if (colors) free(colors); if (tab) free(tab); \
|
||||||
if (colors_direct) free(colors_direct); \
|
if (colors_direct) free(colors_direct); \
|
||||||
if (img) {XDestroyImage(img->image); \
|
if (img) mlx_destroy_image(xvar, img); \
|
||||||
XFreePixmap(xvar->display,img->pix);free(img);} \
|
|
||||||
return ((void *)0); }
|
return ((void *)0); }
|
||||||
|
|
||||||
|
|
||||||
@@ -74,12 +86,18 @@ int mlx_int_get_col_name(char *str,int size)
|
|||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlx_int_get_text_rgb(char *name)
|
int mlx_int_get_text_rgb(char *name, char *end)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
char buff[64];
|
||||||
|
|
||||||
if (*name == '#')
|
if (*name == '#')
|
||||||
return (strtol(name+1,0,16));
|
return (strtol(name+1,0,16));
|
||||||
|
if (end)
|
||||||
|
{
|
||||||
|
snprintf(buff, 64, "%s %s", name, end);
|
||||||
|
name = buff;
|
||||||
|
}
|
||||||
i = 0;
|
i = 0;
|
||||||
while (mlx_col_name[i].name)
|
while (mlx_col_name[i].name)
|
||||||
{
|
{
|
||||||
@@ -91,8 +109,9 @@ int mlx_int_get_text_rgb(char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_xpm_set_pixel(t_img *img, char *data, int opp, int col, int x)
|
void mlx_int_xpm_set_pixel(mlx_img_list_t *img, char *data, int opp, int col, int x)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
int dec;
|
int dec;
|
||||||
|
|
||||||
dec = opp;
|
dec = opp;
|
||||||
@@ -104,10 +123,13 @@ int mlx_int_xpm_set_pixel(t_img *img, char *data, int opp, int col, int x)
|
|||||||
*(data+x*opp+opp-dec-1) = col&0xFF;
|
*(data+x*opp+opp-dec-1) = col&0xFF;
|
||||||
col >>= 8;
|
col >>= 8;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
// opp is 4, do it the simple way
|
||||||
|
*((unsigned int *)(data+4*x)) = col;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *mlx_int_parse_xpm(t_xvar *xvar,void *info,int info_size,char *(*f)())
|
void *mlx_int_parse_xpm(mlx_ptr_t *xvar,void *info,int info_size,char *(*f)())
|
||||||
{
|
{
|
||||||
int pos;
|
int pos;
|
||||||
char *line;
|
char *line;
|
||||||
@@ -124,14 +146,11 @@ void *mlx_int_parse_xpm(t_xvar *xvar,void *info,int info_size,char *(*f)())
|
|||||||
int x;
|
int x;
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
t_img *img;
|
mlx_img_list_t *img;
|
||||||
t_xpm_col *colors;
|
t_xpm_col *colors;
|
||||||
int *colors_direct;
|
int *colors_direct;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
XImage *clip_img;
|
|
||||||
XGCValues xgcv;
|
|
||||||
Pixmap clip_pix;
|
|
||||||
|
|
||||||
colors = 0;
|
colors = 0;
|
||||||
colors_direct = 0;
|
colors_direct = 0;
|
||||||
@@ -167,37 +186,42 @@ void *mlx_int_parse_xpm(t_xvar *xvar,void *info,int info_size,char *(*f)())
|
|||||||
RETURN;
|
RETURN;
|
||||||
j = 0;
|
j = 0;
|
||||||
while (tab[j] && strcmp(tab[j++],"c"));
|
while (tab[j] && strcmp(tab[j++],"c"));
|
||||||
|
|
||||||
if (!tab[j])
|
if (!tab[j])
|
||||||
RETURN;
|
RETURN;
|
||||||
|
|
||||||
if ((rgb_col = mlx_int_get_text_rgb(tab[j]))==-1)
|
rgb_col = mlx_int_get_text_rgb(tab[j], tab[j+1]);
|
||||||
|
/*
|
||||||
|
if ((rgb_col = mlx_int_get_text_rgb(tab[j], tab[j+1]))==-1)
|
||||||
{
|
{
|
||||||
if (!(clip_data = malloc(4*width*height)) || /* ok, nice size .. */
|
if (!(clip_data = malloc(4*width*height)) || // ok, nice size ..
|
||||||
!(clip_img = XCreateImage(xvar->display, xvar->visual,
|
!(clip_img = XCreateImage(xvar->display, xvar->visual,
|
||||||
1, XYPixmap, 0, clip_data,
|
1, XYPixmap, 0, clip_data,
|
||||||
width, height, 8, (width+7)/8)) )
|
width, height, 8, (width+7)/8)) )
|
||||||
RETURN;
|
RETURN;
|
||||||
memset(clip_data, 0xFF, 4*width*height);
|
memset(clip_data, 0xFF, 4*width*height);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
if (method)
|
if (method)
|
||||||
colors_direct[mlx_int_get_col_name(line,cpp)] =
|
colors_direct[mlx_int_get_col_name(line,cpp)] = rgb_col;
|
||||||
rgb_col>=0?mlx_get_color_value(xvar, rgb_col):rgb_col;
|
// rgb_col>=0?mlx_get_color_value(xvar, rgb_col):rgb_col;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
colors[i].name = mlx_int_get_col_name(line,cpp);
|
colors[i].name = mlx_int_get_col_name(line,cpp);
|
||||||
colors[i].col = rgb_col>=0?mlx_get_color_value(xvar,rgb_col):rgb_col;
|
colors[i].col = rgb_col; // rgb_col>=0?mlx_get_color_value(xvar,rgb_col):rgb_col;
|
||||||
}
|
}
|
||||||
free(tab);
|
free(tab);
|
||||||
|
tab = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(img = mlx_new_image(xvar,width,height)))
|
if (!(img = mlx_new_image(xvar,width,height)))
|
||||||
RETURN;
|
RETURN;
|
||||||
opp = img->bpp/8;
|
//opp = img->bpp/8;
|
||||||
|
opp = 4;
|
||||||
|
|
||||||
|
|
||||||
i = height;
|
i = height;
|
||||||
data = img->data;
|
data = img->buffer;
|
||||||
while (i--)
|
while (i--)
|
||||||
{
|
{
|
||||||
if (!(line = f(info,&pos,info_size)))
|
if (!(line = f(info,&pos,info_size)))
|
||||||
@@ -219,14 +243,18 @@ void *mlx_int_parse_xpm(t_xvar *xvar,void *info,int info_size,char *(*f)())
|
|||||||
j = 0;
|
j = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// if (col==-1)
|
||||||
|
// XPutPixel(clip_img, x, height-1-i, 0);
|
||||||
|
// else
|
||||||
if (col==-1)
|
if (col==-1)
|
||||||
XPutPixel(clip_img, x, height-1-i, 0);
|
col = 0xFF000000;
|
||||||
else
|
|
||||||
mlx_int_xpm_set_pixel(img, data, opp, col, x);
|
mlx_int_xpm_set_pixel(img, data, opp, col, x);
|
||||||
x ++;
|
x ++;
|
||||||
}
|
}
|
||||||
data += img->size_line;
|
// data += img->size_line;
|
||||||
|
data += img->width*4;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
if (clip_data)
|
if (clip_data)
|
||||||
{
|
{
|
||||||
if (!(clip_pix = XCreatePixmap(xvar->display, xvar->root,
|
if (!(clip_pix = XCreatePixmap(xvar->display, xvar->root,
|
||||||
@@ -244,6 +272,7 @@ void *mlx_int_parse_xpm(t_xvar *xvar,void *info,int info_size,char *(*f)())
|
|||||||
XSync(xvar->display, False);
|
XSync(xvar->display, False);
|
||||||
XDestroyImage(clip_img);
|
XDestroyImage(clip_img);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
if (colors)
|
if (colors)
|
||||||
free(colors);
|
free(colors);
|
||||||
if (colors_direct)
|
if (colors_direct)
|
||||||
@@ -252,7 +281,7 @@ void *mlx_int_parse_xpm(t_xvar *xvar,void *info,int info_size,char *(*f)())
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int mlx_int_file_get_rid_comment(char *ptr, int size)
|
void mlx_int_file_get_rid_comment(char *ptr, int size)
|
||||||
{
|
{
|
||||||
int com_begin;
|
int com_begin;
|
||||||
int com_end;
|
int com_end;
|
||||||
@@ -270,14 +299,13 @@ int mlx_int_file_get_rid_comment(char *ptr, int size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *mlx_xpm_file_to_image(t_xvar *xvar,char *file,int *width,int *height)
|
void *mlx_xpm_file_to_image(mlx_ptr_t *xvar,char *file,int *width,int *height)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int size;
|
int size;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
t_img *img;
|
mlx_img_list_t *img;
|
||||||
|
|
||||||
fd = -1;
|
|
||||||
if ((fd = open(file,O_RDONLY))==-1 || (size = lseek(fd,0,SEEK_END))==-1 ||
|
if ((fd = open(file,O_RDONLY))==-1 || (size = lseek(fd,0,SEEK_END))==-1 ||
|
||||||
(ptr = mmap(0,size,PROT_WRITE|PROT_READ,MAP_PRIVATE,fd,0))==
|
(ptr = mmap(0,size,PROT_WRITE|PROT_READ,MAP_PRIVATE,fd,0))==
|
||||||
(void *)MAP_FAILED)
|
(void *)MAP_FAILED)
|
||||||
@@ -287,7 +315,7 @@ void *mlx_xpm_file_to_image(t_xvar *xvar,char *file,int *width,int *height)
|
|||||||
return ((void *)0);
|
return ((void *)0);
|
||||||
}
|
}
|
||||||
mlx_int_file_get_rid_comment(ptr, size);
|
mlx_int_file_get_rid_comment(ptr, size);
|
||||||
if (img = mlx_int_parse_xpm(xvar,ptr,size,mlx_int_get_line))
|
if ((img = mlx_int_parse_xpm(xvar,ptr,size,mlx_int_get_line)))
|
||||||
{
|
{
|
||||||
*width = img->width;
|
*width = img->width;
|
||||||
*height = img->height;
|
*height = img->height;
|
||||||
@@ -297,11 +325,11 @@ void *mlx_xpm_file_to_image(t_xvar *xvar,char *file,int *width,int *height)
|
|||||||
return (img);
|
return (img);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *mlx_xpm_to_image(t_xvar *xvar,char **xpm_data,int *width,int *height)
|
void *mlx_xpm_to_image(mlx_ptr_t *xvar,char **xpm_data,int *width,int *height)
|
||||||
{
|
{
|
||||||
t_img *img;
|
mlx_img_list_t *img;
|
||||||
|
|
||||||
if (img = mlx_int_parse_xpm(xvar,xpm_data,0,mlx_int_static_line))
|
if ((img = mlx_int_parse_xpm(xvar,xpm_data,0,mlx_int_static_line)))
|
||||||
{
|
{
|
||||||
*width = img->width;
|
*width = img->width;
|
||||||
*height = img->height;
|
*height = img->height;
|
||||||
Reference in New Issue
Block a user