This commit is contained in:
mcolonna 2024-11-22 12:14:50 +01:00
commit 88c890c0e1
184 changed files with 13687 additions and 0 deletions

3
.gitignore vendored
View file

@ -50,3 +50,6 @@ modules.order
Module.symvers
Mkfile.old
dkms.conf
# Files
/cub3d

47
Libft/Makefile Normal file
View file

@ -0,0 +1,47 @@
# The interesting part
NAME = libft.a
SRCS = ./
INCLUDES = ./
FUNCTIONS = \
isalpha isdigit isalnum isascii isprint \
toupper tolower \
strncmp strlen strlcpy strlcat strchr strrchr strnstr strdup \
strmapi striteri substr strjoin strtrim split \
memset bzero memcpy memmove memchr memcmp calloc \
atoi itoa \
putchar_fd putstr_fd putendl_fd putnbr_fd
FUNCTIONS_BONUS = \
lstnew lstadd_front lstsize lstlast lstadd_back \
lstdelone lstclear lstiter lstmap
CODE = $(addprefix ft_, $(FUNCTIONS))
CODE_BONUS = $(addprefix ft_, $(FUNCTIONS_BONUS))
# It works and I probably won't change it for the rest of my life
C_FILES = $(addsuffix .c,$(addprefix $(SRCS),$(CODE)))
O_FILES = $(addsuffix .o,$(addprefix $(SRCS),$(CODE)))
C_FILES_BONUS = $(addsuffix .c,$(addprefix $(SRCS),$(CODE_BONUS)))
O_FILES_BONUS = $(addsuffix .o,$(addprefix $(SRCS),$(CODE_BONUS)))
CC = cc -Wall -Wextra -Werror
AR = ar rcs
MAKE = make
all : $(NAME)
$(NAME) : $(O_FILES)
$(AR) $(NAME) $(O_FILES)
%.o : %.c
$(CC) -I $(INCLUDES) -c $< -o $@
clean :
rm -f $(O_FILES) $(O_FILES_BONUS)
fclean : clean
rm -f $(NAME)
re : fclean all
bonus : $(O_FILES_BONUS)
$(AR) $(NAME) $(O_FILES_BONUS)
.PHONY : all clean fclean re bonus

50
Libft/ft_atoi.c Normal file
View file

@ -0,0 +1,50 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/28 17:45:41 by mcolonna #+# #+# */
/* Updated: 2023/10/09 12:03:52 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
static int is_in(char c, char *chars)
{
int i;
i = 0;
while (chars[i])
{
if (c == chars[i])
return (1);
i++;
}
return (0);
}
int ft_atoi(const char *nptr)
{
int sign;
int i;
int r;
sign = 1;
i = 0;
r = 0;
while (is_in(nptr[i], " \f\n\r\t\v"))
i++;
if (is_in(nptr[i], "+-"))
{
if (nptr[i] == '-')
sign *= -1;
i++;
}
while (is_in(nptr[i], "0123456789"))
{
r = r * 10 + (nptr[i] - '0');
i++;
}
return (r * sign);
}

18
Libft/ft_bzero.c Normal file
View file

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 13:10:31 by mcolonna #+# #+# */
/* Updated: 2023/10/03 13:12:35 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_bzero(void *s, size_t n)
{
ft_memset(s, '\0', n);
}

29
Libft/ft_calloc.c Normal file
View file

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 13:41:02 by mcolonna #+# #+# */
/* Updated: 2023/10/09 15:58:33 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
void *ft_calloc(size_t nmemb, size_t size)
{
void *dest;
int len;
if ((long)nmemb * (long)size > (long)INT_MAX)
return (NULL);
len = size * nmemb;
dest = malloc(len);
if (!dest)
return (NULL);
ft_bzero(dest, len);
return (dest);
}

18
Libft/ft_isalnum.c Normal file
View file

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/02 16:44:20 by mcolonna #+# #+# */
/* Updated: 2023/10/03 15:02:39 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalnum(int c)
{
return (ft_isdigit(c) || ft_isalpha(c));
}

16
Libft/ft_isalpha.c Normal file
View file

@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/02 16:44:20 by mcolonna #+# #+# */
/* Updated: 2023/10/02 16:46:27 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isalpha(int c)
{
return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
}

16
Libft/ft_isascii.c Normal file
View file

@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/02 16:44:20 by mcolonna #+# #+# */
/* Updated: 2023/10/02 16:50:28 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isascii(int c)
{
return ((c >= 0 && c <= 127));
}

16
Libft/ft_isdigit.c Normal file
View file

@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/02 16:44:20 by mcolonna #+# #+# */
/* Updated: 2023/10/02 16:47:07 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isdigit(int c)
{
return (c >= '0' && c <= '9');
}

16
Libft/ft_isprint.c Normal file
View file

@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/02 16:44:20 by mcolonna #+# #+# */
/* Updated: 2023/10/02 16:51:08 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isprint(int c)
{
return (c >= 32 && c <= 126);
}

67
Libft/ft_itoa.c Normal file
View file

@ -0,0 +1,67 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 13:51:10 by mcolonna #+# #+# */
/* Updated: 2023/10/04 16:49:44 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
static char get_digit_at(long pos_n, int i, int nb_len)
{
int w;
long ten_power;
w = nb_len - i - 1;
ten_power = 1;
while (w--)
ten_power *= 10;
return ('0' + pos_n / ten_power % 10);
}
static int get_nb_len(long pos_n)
{
int r;
long ten_powers;
r = 1;
ten_powers = 10;
while (pos_n >= ten_powers)
{
r++;
ten_powers *= 10;
}
return (r);
}
char *ft_itoa(int n)
{
long pos_n;
int sign;
int nb_len;
char *dest;
int i;
sign = (n >= 0) - (n < 0);
pos_n = (long)n * sign;
nb_len = get_nb_len(pos_n);
dest = malloc(((sign == -1) + nb_len + 1) * sizeof(char));
if (!dest)
return (NULL);
i = 0;
if (sign == -1)
dest[i++] = '-';
while (i - (sign == -1) < nb_len)
{
dest[i] = get_digit_at(pos_n, i - (sign == -1), nb_len);
i++;
}
dest[i] = '\0';
return (dest);
}

24
Libft/ft_lstadd_back.c Normal file
View file

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_back.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/04 16:24:03 by mcolonna #+# #+# */
/* Updated: 2023/10/05 12:56:42 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_back(t_list **lst, t_list *new)
{
t_list *last;
last = ft_lstlast(*lst);
if (last)
last->next = new;
else
*lst = new;
}

19
Libft/ft_lstadd_front.c Normal file
View file

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_front.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/04 16:19:20 by mcolonna #+# #+# */
/* Updated: 2023/10/04 16:20:44 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_front(t_list **lst, t_list *new)
{
new->next = *lst;
*lst = new;
}

25
Libft/ft_lstclear.c Normal file
View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/04 16:31:06 by mcolonna #+# #+# */
/* Updated: 2023/10/05 11:40:24 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstclear(t_list **lst, void (*del)(void *))
{
t_list *next;
while (*lst)
{
next = (*lst)->next;
ft_lstdelone(*lst, del);
*lst = next;
}
}

22
Libft/ft_lstdelone.c Normal file
View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/04 16:28:18 by mcolonna #+# #+# */
/* Updated: 2023/10/05 12:55:39 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
void ft_lstdelone(t_list *lst, void (*del)(void *))
{
if (!lst)
return ;
(*del)(lst->content);
free(lst);
}

22
Libft/ft_lstiter.c Normal file
View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/04 16:36:27 by mcolonna #+# #+# */
/* Updated: 2023/10/04 16:37:48 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstiter(t_list *lst, void (*f)(void *))
{
while (lst)
{
(*f)(lst->content);
lst = lst->next;
}
}

22
Libft/ft_lstlast.c Normal file
View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstlast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/04 16:22:57 by mcolonna #+# #+# */
/* Updated: 2023/10/05 12:53:31 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstlast(t_list *lst)
{
if (!lst)
return (NULL);
while (lst->next)
lst = lst->next;
return (lst);
}

38
Libft/ft_lstmap.c Normal file
View file

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/04 16:37:57 by mcolonna #+# #+# */
/* Updated: 2023/10/12 13:17:57 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *dest;
t_list *new;
void *new_content;
dest = NULL;
if (!lst)
return (NULL);
while (lst)
{
new_content = (*f)(lst->content);
new = ft_lstnew(new_content);
if (!new)
{
(*del)(new_content);
ft_lstclear(&dest, del);
return (NULL);
}
ft_lstadd_back(&dest, new);
lst = lst->next;
}
return (dest);
}

26
Libft/ft_lstnew.c Normal file
View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/04 16:14:54 by mcolonna #+# #+# */
/* Updated: 2023/10/04 16:51:08 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
t_list *ft_lstnew(void *content)
{
t_list *r;
r = malloc(sizeof(t_list));
if (!r)
return (NULL);
r->content = content;
r->next = NULL;
return (r);
}

26
Libft/ft_lstsize.c Normal file
View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstsize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/04 16:21:29 by mcolonna #+# #+# */
/* Updated: 2023/10/04 16:44:08 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_lstsize(t_list *lst)
{
int i;
i = 0;
while (lst)
{
lst = lst->next;
i++;
}
return (i);
}

28
Libft/ft_memchr.c Normal file
View file

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 13:28:00 by mcolonna #+# #+# */
/* Updated: 2023/10/03 15:31:16 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
size_t i;
const char *s2 = s;
i = 0;
while (i < n)
{
if (s2[i] == (char) c)
return ((void *) s + i);
i++;
}
return (NULL);
}

25
Libft/ft_memcmp.c Normal file
View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 13:37:06 by mcolonna #+# #+# */
/* Updated: 2023/10/09 12:00:22 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
if (n == 0)
return (0);
i = 0;
while (i < n - 1 && ((unsigned char *)s1)[i] == ((unsigned char *)s2)[i])
i++;
return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]);
}

30
Libft/ft_memcpy.c Normal file
View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 13:12:53 by mcolonna #+# #+# */
/* Updated: 2023/10/16 13:40:19 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memcpy(void *dest, const void *src, size_t n)
{
size_t i;
char *dest2;
char *src2;
dest2 = (char *)dest;
src2 = (char *)src;
i = 0;
while (i < n)
{
dest2[i] = src2[i];
i++;
}
return (dest);
}

31
Libft/ft_memmove.c Normal file
View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 13:17:41 by mcolonna #+# #+# */
/* Updated: 2023/10/12 10:44:37 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *dest, const void *src, size_t n)
{
size_t i;
if (!dest || !src)
return (NULL);
i = 0;
while (i < n)
{
if (dest < src)
((char *)dest)[i] = ((char *)src)[i];
else
((char *)dest)[n - i - 1] = ((char *)src)[n - i - 1];
i++;
}
return (dest);
}

28
Libft/ft_memset.c Normal file
View file

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 13:05:27 by mcolonna #+# #+# */
/* Updated: 2023/10/03 15:27:09 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memset(void *s, int c, size_t n)
{
size_t i;
char *dest;
dest = (char *)s;
i = 0;
while (i < n)
{
dest[i] = (char)c;
i++;
}
return (dest);
}

18
Libft/ft_putchar_fd.c Normal file
View file

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 14:25:02 by mcolonna #+# #+# */
/* Updated: 2023/10/03 14:29:09 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
}

20
Libft/ft_putendl_fd.c Normal file
View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 14:25:02 by mcolonna #+# #+# */
/* Updated: 2023/10/04 14:17:01 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include "libft.h"
void ft_putendl_fd(char *s, int fd)
{
write(fd, s, ft_strlen(s));
write(fd, "\n", 1);
}

40
Libft/ft_putnbr_fd.c Normal file
View file

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 14:32:29 by mcolonna #+# #+# */
/* Updated: 2023/10/09 17:23:02 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <limits.h>
#include "libft.h"
static void putunsigned(long nb, int fd)
{
if (nb == 0)
return ;
putunsigned(nb / 10, fd);
ft_putchar_fd((char)(nb % 10) + '0', fd);
}
void ft_putnbr_fd(int n, int fd)
{
long nb;
if (n < 0)
{
ft_putchar_fd('-', fd);
nb = -(long)n;
}
else
nb = n;
if (n == 0)
ft_putchar_fd('0', fd);
else
putunsigned(nb, fd);
}

19
Libft/ft_putstr_fd.c Normal file
View file

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 14:25:02 by mcolonna #+# #+# */
/* Updated: 2023/10/03 14:34:35 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include "libft.h"
void ft_putstr_fd(char *s, int fd)
{
write(fd, s, ft_strlen(s));
}

98
Libft/ft_split.c Normal file
View file

@ -0,0 +1,98 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 11:47:18 by mcolonna #+# #+# */
/* Updated: 2023/10/12 13:24:04 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
static int count_until(char const *s, char const c)
{
int i;
i = 0;
while (s[i] && s[i] != c)
i++;
return (i);
}
static int count_words(char const *s, char c)
{
int i;
int r;
int in_a_word;
i = 0;
r = 0;
in_a_word = 0;
while (s[i])
{
if (s[i] == c)
{
in_a_word = 0;
}
else if (!in_a_word)
{
in_a_word = 1;
r++;
}
i++;
}
return (r);
}
static char **free_array(char ***array, int size)
{
int i;
i = 0;
while (i < size)
{
free((*array)[i]);
(*array)[i] = NULL;
i++;
}
free(*array);
*array = NULL;
return (NULL);
}
static void ignore_sep(char const *s, char c, int *i)
{
while (s[*i] == c)
(*i)++;
}
char **ft_split(char const *s, char c)
{
int size;
char **dest;
int i;
int str_i;
int len_until;
size = count_words(s, c);
dest = malloc((size + 1) * sizeof(char *));
if (!dest)
return (NULL);
i = -1;
str_i = 0;
while (++i < size)
{
ignore_sep(s, c, &str_i);
len_until = count_until(s + str_i, c);
dest[i] = ft_substr(s, str_i, len_until);
if (!dest[i])
return (free_array(&dest, i));
str_i += len_until;
}
dest[i] = NULL;
return (dest);
}

29
Libft/ft_strchr.c Normal file
View file

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 10:43:17 by mcolonna #+# #+# */
/* Updated: 2023/10/10 13:17:35 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
char *ft_strchr(const char *s, int c)
{
int i;
i = 0;
while (s[i])
{
if (s[i] == c)
return ((char *)s + i);
i++;
}
if (s[i] == c)
return ((char *)s + i);
return (NULL);
}

35
Libft/ft_strdup.c Normal file
View file

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/30 09:18:39 by mcolonna #+# #+# */
/* Updated: 2023/10/03 11:27:46 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
char *ft_strdup(const char *s)
{
int len;
int i;
char *dest;
len = 0;
while (s[len])
len++;
dest = malloc((len + 1) * sizeof(char));
if (!dest)
return (NULL);
i = 0;
while (s[i])
{
dest[i] = s[i];
i++;
}
dest[i] = '\0';
return (dest);
}

25
Libft/ft_striteri.c Normal file
View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striteri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 11:08:18 by mcolonna #+# #+# */
/* Updated: 2023/10/04 11:10:28 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
void ft_striteri(char *s, void (*f)(unsigned int, char *))
{
unsigned int i;
i = 0;
while (s[i])
{
(*f)(i, s + i);
i++;
}
}

42
Libft/ft_strjoin.c Normal file
View file

@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 11:31:45 by mcolonna #+# #+# */
/* Updated: 2023/10/04 11:25:38 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
int len;
char *dest;
int i;
int j;
len = ft_strlen(s1) + ft_strlen(s2);
dest = malloc((len + 1) * sizeof(char));
if (!dest)
return (NULL);
i = 0;
while (s1[i])
{
dest[i] = s1[i];
i++;
}
j = 0;
while (s2[j])
{
dest[i] = s2[j];
i++;
j++;
}
dest[i] = '\0';
return (dest);
}

44
Libft/ft_strlcat.c Normal file
View file

@ -0,0 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/28 10:40:23 by mcolonna #+# #+# */
/* Updated: 2023/10/09 16:20:20 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static size_t min(size_t a, size_t b)
{
if (a < b)
return (a);
else
return (b);
}
size_t ft_strlcat(char *dest, const char *src, size_t size)
{
size_t dest_len;
size_t dest_i;
size_t src_i;
dest_len = min(ft_strlen(dest), size);
if (dest_len < size - 1)
{
dest_i = dest_len;
src_i = 0;
while (src[src_i] && size > 0 && dest_i < size - 1)
{
dest[dest_i] = src[src_i];
src_i++;
dest_i++;
}
if (size > 0)
dest[dest_i] = '\0';
}
return (dest_len + ft_strlen(src));
}

30
Libft/ft_strlcpy.c Normal file
View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/25 20:39:39 by mcolonna #+# #+# */
/* Updated: 2023/10/09 11:44:13 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcpy(char *dest, const char *src, size_t size)
{
size_t i;
i = 0;
while (src[i] && size > 0 && i < size - 1)
{
dest[i] = src[i];
i++;
}
if (i < size)
dest[i] = '\0';
while (src[i])
i++;
return (i);
}

23
Libft/ft_strlen.c Normal file
View file

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/24 13:10:16 by mcolonna #+# #+# */
/* Updated: 2023/10/10 14:09:44 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlen(const char *s)
{
int i;
i = 0;
while (s[i])
i++;
return (i);
}

32
Libft/ft_strmapi.c Normal file
View file

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 11:08:18 by mcolonna #+# #+# */
/* Updated: 2023/10/03 15:20:49 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *dest;
unsigned int i;
dest = malloc((ft_strlen(s) + 1) * sizeof(char));
if (!dest)
return (NULL);
i = 0;
while (s[i])
{
dest[i] = (*f)(i, s[i]);
i++;
}
dest[i] = '\0';
return (dest);
}

25
Libft/ft_strncmp.c Normal file
View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/10 12:21:33 by mcolonna #+# #+# */
/* Updated: 2023/10/10 14:39:03 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
unsigned int i;
if (n == 0)
return (0);
i = 0;
while (i < n - 1 && s1[i] && s1[i] == s2[i])
i++;
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
}

47
Libft/ft_strnstr.c Normal file
View file

@ -0,0 +1,47 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 10:50:23 by mcolonna #+# #+# */
/* Updated: 2023/10/09 16:09:21 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
// Return 1 if there is 'little' at the pos 'i' of 'big', or else 0.
static int match(const char *big, const char *little, size_t len, size_t i)
{
int j;
j = 0;
while (little[j])
{
if (len <= i || big[i] != little[j])
return (0);
i++;
j++;
}
return (1);
}
char *ft_strnstr(const char *big, const char *little, size_t len)
{
size_t i;
i = 0;
if (!little[0])
return ((char *)big);
if (!big[i] || i >= len)
return (NULL);
while (!match(big, little, len, i))
{
i++;
if (!big[i] || i >= len)
return (NULL);
}
return ((char *)big + i);
}

31
Libft/ft_strrchr.c Normal file
View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 10:43:17 by mcolonna #+# #+# */
/* Updated: 2023/10/10 13:16:58 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
char *ft_strrchr(const char *s, int c)
{
char *r;
int i;
r = NULL;
i = 0;
while (s[i])
{
if (s[i] == c)
r = (char *)s + i;
i++;
}
if (s[i] == c)
r = (char *)s + i;
return (r);
}

80
Libft/ft_strtrim.c Normal file
View file

@ -0,0 +1,80 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 11:39:33 by mcolonna #+# #+# */
/* Updated: 2023/10/04 13:07:54 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
static int is_in(char const c, char const *set)
{
int i;
i = 0;
while (set[i])
{
if (set[i] == c)
return (1);
i++;
}
return (0);
}
static size_t get_length(char const *s1, char const *set)
{
size_t i;
size_t r;
size_t tmp;
i = 0;
while (is_in(s1[i], set))
i++;
r = 0;
tmp = 0;
while (s1[i])
{
if (is_in(s1[i], set))
{
tmp++;
}
else
{
r += tmp;
tmp = 0;
r++;
}
i++;
}
return (r);
}
char *ft_strtrim(char const *s1, char const *set)
{
size_t len;
char *dest;
size_t start;
size_t i;
len = get_length(s1, set);
dest = malloc((len + 1) * sizeof(char));
if (!dest)
return (NULL);
start = 0;
while (is_in(s1[start], set))
start++;
i = 0;
while (i < len)
{
dest[i] = s1[start + i];
i++;
}
dest[i] = '\0';
return (dest);
}

41
Libft/ft_substr.c Normal file
View file

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/03 11:17:12 by mcolonna #+# #+# */
/* Updated: 2023/10/09 13:27:30 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *dest;
size_t s_len;
size_t dest_len;
size_t i;
s_len = ft_strlen(s);
if (s_len < start)
dest_len = 0;
else if (s_len < start + len)
dest_len = s_len - start;
else
dest_len = len;
dest = malloc((dest_len + 1) * sizeof(char));
if (!dest)
return (NULL);
i = 0;
while (i < dest_len)
{
dest[i] = s[start + i];
i++;
}
dest[i] = '\0';
return (dest);
}

18
Libft/ft_tolower.c Normal file
View file

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_tolower.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/02 16:53:06 by mcolonna #+# #+# */
/* Updated: 2023/10/02 16:58:02 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
int ft_tolower(int c)
{
if (c >= 'A' && c <= 'Z')
return (c - 'A' + 'a');
return (c);
}

18
Libft/ft_toupper.c Normal file
View file

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_toupper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/02 16:53:06 by mcolonna #+# #+# */
/* Updated: 2023/10/02 16:56:52 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
int ft_toupper(int c)
{
if (c >= 'a' && c <= 'z')
return (c - 'a' + 'A');
return (c);
}

196
Libft/libft.h Normal file
View file

@ -0,0 +1,196 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/02 11:46:15 by mcolonna #+# #+# */
/* Updated: 2023/10/10 14:11:08 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBFT_H
# define LIBFT_H
# include <stddef.h>
# include <limits.h>
///// CHAR /////
// (In libc) Return 1 if the char 'c' is a specific type of char, or else 0.
int ft_isalpha(int c); // A-Za-z
int ft_isdigit(int c); // 0-9
int ft_isalnum(int c); // A-Za-z0-9
int ft_isascii(int c); // (0)-(127)
int ft_isprint(int c); // (32)-(126)
// (In libc) Return the uppercase/lowercase version of the letter,
// or the char itself if it's not a letter.
int ft_toupper(int c);
int ft_tolower(int c);
///// STR /////
// (In libc) Compare 2 strings until n
int ft_strncmp(const char *s1, const char *s2, size_t n);
// (In libc) Return the length of the string 's'.
size_t ft_strlen(const char *s);
// (In libc) Copy/Append src on dst.
// 'dst' will be 'size' chars max, including \0,
// except if 'dst' is already longer for strlcat().
// 1. Never do more than size.
// 2. Always end by \0, except if it doesn't respect 1.
size_t ft_strlcpy(char *dst, const char *src, size_t size);
size_t ft_strlcat(char *dst, const char *src, size_t size);
// (In libc) Return a pointer to the first of last char 'c' in 's',
// or return NULL if there aren't any.
char *ft_strchr(const char *s, int c); // First char.
char *ft_strrchr(const char *s, int c); // Last char.
// (In libc) Return a pointer to the first occurence
// of string 'little' in string 'big'.
// Don't look chars after 'size'.
char *ft_strnstr(const char *big, const char *little, size_t len);
// (In libc) Return an malloced duplicate of 's'.
// Uses: malloc
// Error: return NULL
char *ft_strdup(const char *s);
// (Perso) Apply 'f' on each char of the string 's' and returns the result.
// Uses: malloc
// Error: return NULL
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
// (Perso) Call 'f' for each char of 's'.
void ft_striteri(char *s, void (*f)(unsigned int, char *));
// (Perso) Return the substring of 's' which starts at 'start'
// and is of length 'len'.
// Don't take chars after the end of the string.
// Uses: malloc
// Error: return NULL
char *ft_substr(char const *s, unsigned int start, size_t len);
// (Perso) Concatenate the two strings.
// Uses: malloc
// Error: return NULL
char *ft_strjoin(char const *s1, char const *s2);
// (Perso) Remove the characters 'set' from the beginning
// and the end of the string.
// Uses: malloc
// Error: return NULL
char *ft_strtrim(char const *s1, char const *set);
// (Perso) Split 's' by the chars 'c'.
// Return an array ended by NULL.
// Uses: malloc
// Error: return NULL
char **ft_split(char const *s, char c);
///// MEM /////
// (In libc) Fills 's' with 'n' times the char 'c'.
// Return 'c'.
void *ft_memset(void *s, int c, size_t n);
// (In libc) Just ft_memset(s, '\0', n) lol.
void ft_bzero(void *s, size_t n);
// (In libc) Copy 'n' bytes from 'src' to 'dest'.
// The 'src' and 'dest' areas mustn't overlap.
// Return 'dest'.
void *ft_memcpy(void *dest, const void *src, size_t n);
// (In libc) Same, but the areas can overlap.
// Return 'dest'.
void *ft_memmove(void *dest, const void *src, size_t n);
// (In libc) Find the character 'c' in 's', 's' being of length 'n'.
// NULL if none.
void *ft_memchr(const void *s, int c, size_t n);
// (In libc) Compare 'n' bytes of 's1' and 's2'.
int ft_memcmp(const void *s1, const void *s2, size_t n);
// (In libc) Alloc an array of 'size' elements with each element
// being of size 'size'.
// Uses: malloc
// Error: return NULL
void *ft_calloc(size_t nmemb, size_t size);
///// CAST /////
// (In libc) Cast a string to an int.
// /[ \f\n\r\t\v]*[-+]?[0-9]*.*/
int ft_atoi(const char *nptr);
// (Perso) Cast an int to a string.
// Uses: malloc
// Error: return NULL
char *ft_itoa(int n);
///// WRITE /////
// (Perso) Write the char/string on the file descriptor 'fd'.
// Uses: write
void ft_putchar_fd(char c, int fd);
void ft_putstr_fd(char *s, int fd);
// (Perso) Write the string 's' followed by a newline.
// Uses: write
void ft_putendl_fd(char *s, int fd);
// (Perso) Write the number 'n'.
// Uses: write
void ft_putnbr_fd(int n, int fd);
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;
///// BONUS /////
// Create an malloced list of size = 1: {content}
// Uses: malloc
// Error: return NULL
t_list *ft_lstnew(void *content);
// Add 'new' at the beginning of the list.
void ft_lstadd_front(t_list **lst, t_list *new);
// Get the length of the list.
int ft_lstsize(t_list *lst);
// Return the last node of the list.
t_list *ft_lstlast(t_list *lst);
// Add 'new' at the end of the list.
void ft_lstadd_back(t_list **lst, t_list *new);
// Apply 'del' on the element's content, then free lst.
// Uses: free
void ft_lstdelone(t_list *lst, void (*del)(void *));
// Free every element's content with del and free the elements.
// *lst will be set to NULL.
// Uses: free
void ft_lstclear(t_list **lst, void (*del)(void *));
// Apply f on the content of each node.
void ft_lstiter(t_list *lst, void (*f)(void *));
// Apply f on the content of each node
// and create a new list with the resulting contents.
// Uses: free, malloc
// Error: return NULL
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
#endif

91
Makefile Normal file
View file

@ -0,0 +1,91 @@
NAME = cub3d
CPP = gcc
LIBRARIES_DIR = Libft Minilibx
LIBRARIES_A = Libft/libft.a Minilibx/libmlx.a
SHARED = -lX11 -lXext -lm
CPP_1 = $(CPP) -Wall -Wextra -Werror -I Libft -I Minilibx -I include $(FLAGS) $(FLAGS_1)
CPP_2 = $(CPP) $(FLAGS) $(FLAGS_2)
C_FILES = $(wildcard src/*.c)
ifeq ($(BONUS), yes)
C_FILES_REAL = $(filter-out $(wildcard src/*_nobonus.c),$(C_FILES))
else
C_FILES_REAL = $(filter-out $(wildcard src/*_bonus.c),$(C_FILES))
endif
O_FILES = $(patsubst %.c,%.o,$(C_FILES))
O_FILES_REAL = $(patsubst %.c,%.o,$(C_FILES_REAL))
ECHO = echoo(){ \
if [ -t 1 ]; then \
echo "$$*"; \
else \
echo "$$*" | sed -E "s/\x1B[[][0-9;]+m//g"; \
fi; \
};echoo
all : $(NAME)
bonus :
$(MAKE) all BONUS=yes FLAGS_1="$(FLAGS_1) -DBONUS"
debug :
$(MAKE) all FLAGS_1="$(FLAGS_1) -g"
debugre :
$(MAKE) re FLAGS_1="$(FLAGS_1) -g"
$(LIBRARIES_DIR):
@$(ECHO)
@$(ECHO) "\e[30;47;1m $(NAME): making library $@... \e[0m"
$(MAKE) -C $@
clean :
@$(ECHO)
@$(ECHO) "\e[30;47;1m $(NAME): clean... \e[0m"
-rm -f $(O_FILES)
fclean : clean
@$(ECHO)
@$(ECHO) "\e[30;47;1m $(NAME): fclean... \e[0m"
-rm -f $(NAME)
-$(MAKE) -C Libft fclean
-$(MAKE) -C Minilibx clean
-rm $$(find Minilibx -name "Makefile.gen")
re : clean all
rebonus : clean bonus
$(NAME) : $(O_FILES_REAL) $(LIBRARIES_DIR)
@$(ECHO)
@$(ECHO) "\e[30;47;1m $(NAME): linking... \e[0m"
$(CPP_2) $(O_FILES_REAL) $(LIBRARIES_A) $(SHARED) -o $@
@$(ECHO)
@$(ECHO) "\t\t \e[0;92m\(^o^)/ \e[0;102;30;1m $(NAME) made! \e[0;92m \(^o^)/\e[0m"
@$(ECHO)
%.o : %.c
@$(ECHO)
@$(ECHO) "\e[30;47;1m $(NAME): making '$@'... \e[0m"
$(CPP_1) $(FLAGS_1) -c $< -o $@
check_headers :
@ERROR=0; \
for HEADER in $(wildcard *.h) $(wildcard **/*.h); \
do \
echo "check header $$HEADER..."; \
> __tmp_check_header.c echo "#include \"$$HEADER\""; \
>> __tmp_check_header.c echo "#include \"$$HEADER\""; \
>> __tmp_check_header.c echo "int main() {}"; \
$(CPP_1) -o __tmp_check_header.out __tmp_check_header.c; \
if [ $$? -ne 0 ]; \
then \
ERROR=1; \
echo " error \e[31m:(\e[0m"; \
fi; \
echo " good \e[32m:)\e[0m"; \
2> /dev/null rm -- "__tmp_check_header.out" "__tmp_check_header.c"; \
done; \
2> /dev/null rm __tmp_check_header.out __tmp_check_header.c; \
if [ $$ERROR -eq 0 ]; then true; else false; fi;
.PHONY : all clean fclean re check_headers $(LIBRARIES_DIR)

88
Minilibx/.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,88 @@
name: Build
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ${{ matrix.os }}
env:
DISPLAY: ":99"
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Install mlx dependencies
run: |
set -x
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get update -qq
sudo apt-get install -y -qq gcc make xorg libxext-dev libbsd-dev
elif [ "$RUNNER_OS" == "macOS" ]; then
brew install xquartz
echo "/usr/X11/bin" >> $GITHUB_PATH
else
echo "$RUNNER_OS not supported"
exit 1
fi
- name: Setup x11 headless testing environment
run: |
set -x
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get install xvfb xdotool valgrind
Xvfb $DISPLAY -screen 0 1280x1024x24 &
elif [ "$RUNNER_OS" == "macOS" ]; then
brew install xdotool
defaults write org.x.X11 enable_test_extensions -boolean true
sudo Xvfb $DISPLAY -screen 0 1280x1024x24 &
else
echo "$RUNNER_OS not supported"
exit 1
fi
- name: Run ./configure
run: ./configure
- name: make check Linux
if: matrix.os == 'ubuntu-latest'
run: make -f Makefile.gen check
- name: make check MacOS
continue-on-error: true
if: matrix.os == 'macos-latest'
run: make -f Makefile.gen check
# Didn't find a way to simulate inputs on Macos. libxdo seem to no longer work on macos.
# It can be partially fixed writing proper unit-tests, thus avoiding the need of libxdo.
- name: Check leaks from binary "test/mlx-test"
run: |
cd test
if [ "$RUNNER_OS" == "Linux" ]; then
echo "Info: Still reachable doesn't matter. Valgrind will return success on thoses reports.
It is fine, we searching for lost pointers. Valgrind will return exit status 42 if any block is lost."
valgrind --leak-check=full --show-leak-kinds=definite,indirect,possible --errors-for-leak-kinds=definite,indirect,possible --error-exitcode=42 ./mlx-test > /dev/null &
PID=$!
sleep 30
xdotool search --name Title3 windowfocus key Escape
xdotool search --name Title2 windowfocus key Escape
wait $PID
elif [ "$RUNNER_OS" == "macOS" ]; then
MallocStackLoggingNoCompact=1
./mlx-test &
sleep 30
leaks mlx-test
pkill mlx-test
fi
- name: Norminette, just for fun
continue-on-error: true
run: |
pip3 install Norminette
norminette *.c *.h
norminette --version

67
Minilibx/.gitignore vendored Normal file
View file

@ -0,0 +1,67 @@
## Mlx related
Makefile.gen
/test/mlx-test
## Editor
.vscode/*
*~
\#*\#
## Other
.DS_STORE
## Template from https://github.com/github/gitignore
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

25
Minilibx/LICENSE Normal file
View file

@ -0,0 +1,25 @@
BSD 2-Clause License
Copyright (c) 2021, Ecole 42
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

22
Minilibx/Makefile Normal file
View file

@ -0,0 +1,22 @@
##
## 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

66
Minilibx/Makefile.mk Normal file
View file

@ -0,0 +1,66 @@
##
## 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 =%%%%
UNAME = $(shell uname)
CC = gcc
ifeq ($(UNAME),FreeBSD)
CC = clang
endif
NAME = libmlx.a
NAME_UNAME = libmlx_$(UNAME).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_DIR = obj
OBJ = $(addprefix $(OBJ_DIR)/,$(SRC:%.c=%.o))
CFLAGS = -O3 -I$(INC)
all : $(NAME)
$(OBJ_DIR)/%.o: %.c
@mkdir -p $(OBJ_DIR)
$(CC) $(CFLAGS) $(IFLAGS) -c $< -o $@
$(NAME) : $(OBJ)
ar -r $(NAME) $(OBJ)
ranlib $(NAME)
cp $(NAME) $(NAME_UNAME)
check: all
@test/run_tests.sh
show:
@printf "NAME : $(NAME)\n"
@printf "NAME_UNAME : $(NAME_UNAME)\n"
@printf "CC : $(CC)\n"
@printf "CFLAGS : $(CFLAGS)\n"
@printf "SRC :\n $(SRC)\n"
@printf "OBJ :\n $(OBJ)\n"
clean :
rm -rf $(OBJ_DIR)/ $(NAME) $(NAME_UNAME) *~ core *.core
.PHONY: all check show clean

55
Minilibx/README.md Executable file
View file

@ -0,0 +1,55 @@
[![Build](https://github.com/42Paris/minilibx-linux/actions/workflows/ci.yml/badge.svg)](https://github.com/42Paris/minilibx-linux/actions/workflows/ci.yml)
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 for Linux
- 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)**
Requirements for MacOS
- [Xquartz](https://www.xquartz.org/)
```bash
➜ ~ Brew install Xquartz
➜ ~ reboot
➜ ~ xeyes # run an hello world X11 app
```
MlX Color Opacity / Transparency / Alpha (32 bits depth)
- 0xFF (fully transparent) or 0x00 (fully opaque)
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 -

126
Minilibx/configure vendored Executable file
View file

@ -0,0 +1,126 @@
#!/usr/bin/env sh
set -e
BOLD="\033[1m"
RESET="\033[0m"
LIGHT_RED="\033[91m"
LIGHT_GREEN="\033[92m"
LIGHT_CYAN="\033[96m"
logging(){
local type=$1; shift
printf "${LIGHT_CYAN}${BOLD}configure${RESET} [%b] : %b\n" "$type" "$*"
}
log_info(){
logging "${LIGHT_GREEN}info${RESET}" "$@"
}
log_error(){
logging "${LIGHT_RED}error${RESET}" "$@" >&2
}
# find and print x11 header path
get_xlib_include_path(){
local result=""
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/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
result=$inc
break
fi
done
echo $result
}
show_help(){
cat <<EOF
Usage :
$0 Auto-configure and make MinilibX
$0 clean Execute the clean rule of both Makefile.gen
EOF
}
clean(){
log_info 'Execute "make clean" from "makefile.gen"'
${MAKE} -f Makefile.gen clean
log_info 'Execute "make clean" from "test/makefile.gen"'
${MAKE} -f Makefile.gen -C test/ --no-print-directory clean
}
parse_args(){
case "$1" in
--help | -h)
show_help
exit 0;;
clean)
clean
exit 0;;
"") return;;
*)
log_error "unknown command \"$1\"\nRun \"./configure --help\" for usage."
exit 1;;
esac
}
main(){
local xlib_inc="$(get_xlib_include_path)"
case $(uname) in
FreeBSD) MAKE=gmake ;;
*) MAKE=make ;;
esac
parse_args "$@"
if [ -z "$xlib_inc" ]; then
log_error "Can't find a suitable X11 include directory."
exit 1
fi
log_info "Found X11 include path directory: $xlib_inc"
log_info 'Generate "makefile.gen" from template "makefile.mk"'
echo "INC=$xlib_inc" > Makefile.gen
cat Makefile.mk | grep -v %%%% >> Makefile.gen
log_info 'Generate "test/makefile.gen" from template "test/makefile.mk"'
echo "INC=$xlib_inc" > test/Makefile.gen
cat test/Makefile.mk | grep -v %%%% >> test/Makefile.gen
log_info 'Execute "make all" from file "makefile.gen"'
${MAKE} -f Makefile.gen all
log_info 'Execute "make all" from file "test/makefile.gen"'
(cd test ; ${MAKE} -f Makefile.gen all )
}
main "$@"

93
Minilibx/man/man1/mlx.1 Normal file
View file

@ -0,0 +1,93 @@
.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

View file

@ -0,0 +1,141 @@
.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

View file

@ -0,0 +1,192 @@
.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

View file

@ -0,0 +1,79 @@
.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

View file

@ -0,0 +1,84 @@
.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

93
Minilibx/man/man3/mlx.3 Normal file
View file

@ -0,0 +1,93 @@
.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

View file

@ -0,0 +1,141 @@
.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

View file

@ -0,0 +1,192 @@
.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

View file

@ -0,0 +1,79 @@
.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

View file

@ -0,0 +1,81 @@
.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:
.nf
| 0 | R | G | B | color integer
+---+---+---+---+
.fi
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

139
Minilibx/mlx.h Normal file
View file

@ -0,0 +1,139 @@
/*
** mlx.h for MinilibX in
**
** Made by Charlie Root
** Login <ol@epitech.net>
**
** Started on Mon Jul 31 16:37:50 2000 Charlie Root
** Last update Tue May 15 16:23:28 2007 Olivier Crouzet
*/
/*
** MinilibX - Please report bugs
*/
/*
** FR msg - FR msg - FR msg
**
** La MinilibX utilise 2 librairies supplementaires qu'il
** est necessaire de rajouter a la compilation :
** -lmlx -lXext -lX11
**
** La MinilibX permet le chargement des images de type Xpm.
** Notez que cette implementation est incomplete.
** Merci de communiquer tout probleme de chargement d'image
** de ce type.
*/
#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 0x00RRGGBB
*/
/*
** Image stuff
*/
void *mlx_new_image(void *mlx_ptr,int width,int height);
/*
** 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,
int *size_line, int *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
*/
int mlx_put_image_to_window(void *mlx_ptr, void *win_ptr, void *img_ptr,
int x, int y);
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);
int mlx_loop_end (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...
*/
int mlx_string_put(void *mlx_ptr, void *win_ptr, int x, int y, int color,
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,
int *width, int *height);
void *mlx_xpm_file_to_image(void *mlx_ptr, char *filename,
int *width, int *height);
int mlx_destroy_window(void *mlx_ptr, void *win_ptr);
int mlx_destroy_image(void *mlx_ptr, void *img_ptr);
int mlx_destroy_display(void *mlx_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_do_key_autorepeatoff(void *mlx_ptr);
int mlx_do_key_autorepeaton(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 */

View file

@ -0,0 +1,21 @@
/*
** 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);
}

View file

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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);
}

View file

@ -0,0 +1,31 @@
/*
** 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);
}

View file

@ -0,0 +1,38 @@
/*
** 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);
}

View file

@ -0,0 +1,22 @@
/*
** 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;
}

104
Minilibx/mlx_ext_randr.c Normal file
View file

@ -0,0 +1,104 @@
#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);
}

View file

@ -0,0 +1,25 @@
/*
** 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);
}
}

View file

@ -0,0 +1,33 @@
/*
** 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);
}

View file

@ -0,0 +1,23 @@
/*
** 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);
}

40
Minilibx/mlx_hook.c Normal file
View file

@ -0,0 +1,40 @@
/*
** 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);
}

99
Minilibx/mlx_init.c Normal file
View file

@ -0,0 +1,99 @@
/*
** 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);
xvar->wm_protocols = XInternAtom (xvar->display, "WM_PROTOCOLS", 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);
xvar->end_loop = 0;
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] ++; }
}

140
Minilibx/mlx_int.h Normal file
View file

@ -0,0 +1,140 @@
/*
** 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;
Atom wm_protocols;
int end_loop;
} 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

View file

@ -0,0 +1,28 @@
/*
** 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);
}

View file

@ -0,0 +1,16 @@
/*
** 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)
{
}

View file

@ -0,0 +1,39 @@
/*
** 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);
}

View file

@ -0,0 +1,100 @@
/*
** 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
};

View file

@ -0,0 +1,34 @@
/*
** 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;
}
}

View file

@ -0,0 +1,113 @@
/*
** mlx_int_str_to_wordtab.c for MinilibX in
**
** 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"
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);
}

View file

@ -0,0 +1,23 @@
/*
** 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);
}

22
Minilibx/mlx_key_hook.c Normal file
View file

@ -0,0 +1,22 @@
/*
** 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;
}

96
Minilibx/mlx_lib_xpm.c Normal file
View file

@ -0,0 +1,96 @@
/*
** 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));
}

63
Minilibx/mlx_loop.c Normal file
View file

@ -0,0 +1,63 @@
/*
** 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[]))();
static int win_count(t_xvar *xvar)
{
int i;
t_win_list *win;
i = 0;
win = xvar->win_list;
while (win)
{
win = win->next;
++i;
}
return (i);
}
int mlx_loop_end(t_xvar *xvar)
{
xvar->end_loop = 1;
return (1);
}
int mlx_loop(t_xvar *xvar)
{
XEvent ev;
t_win_list *win;
mlx_int_set_win_event_mask(xvar);
xvar->do_flush = 0;
while (win_count(xvar) && !xvar->end_loop)
{
while (!xvar->end_loop && (!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 == ClientMessage && ev.xclient.message_type == xvar->wm_protocols && ev.xclient.data.l[0] == xvar->wm_delete_window && win->hooks[DestroyNotify].hook)
win->hooks[DestroyNotify].hook(win->hooks[DestroyNotify].param);
if (win && ev.type < MLX_MAX_EVENT && win->hooks[ev.type].hook)
mlx_int_param_event[ev.type](xvar, &ev, win);
}
XSync(xvar->display, False);
if (xvar->loop_hook)
xvar->loop_hook(xvar->loop_param);
}
return (0);
}

21
Minilibx/mlx_loop_hook.c Normal file
View file

@ -0,0 +1,21 @@
/*
** 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;
}

48
Minilibx/mlx_mouse.c Normal file
View file

@ -0,0 +1,48 @@
#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));
}

22
Minilibx/mlx_mouse_hook.c Normal file
View file

@ -0,0 +1,22 @@
/*
** 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;
}

159
Minilibx/mlx_new_image.c Normal file
View file

@ -0,0 +1,159 @@
/*
** 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))))
return ((void *)0);
if (!(img->data = malloc((width+32)*height*4)))
{
free(img);
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));
}

62
Minilibx/mlx_new_window.c Normal file
View file

@ -0,0 +1,62 @@
/*
** 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);
}

26
Minilibx/mlx_pixel_put.c Normal file
View file

@ -0,0 +1,26 @@
/*
** 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);
}

View file

@ -0,0 +1,37 @@
/*
** 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);
}

764
Minilibx/mlx_rgb.c Normal file
View file

@ -0,0 +1,764 @@
/*
** This is a generated file with rgb2c.pl and rgb.txt from
** the XFree86 distribution.
*/
#include "mlx_int.h"
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 }
};

View file

@ -0,0 +1,13 @@
#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;
}

30
Minilibx/mlx_set_font.c Normal file
View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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);
}

26
Minilibx/mlx_string_put.c Normal file
View file

@ -0,0 +1,26 @@
/*
** 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);
}

345
Minilibx/mlx_xpm.c Normal file
View file

@ -0,0 +1,345 @@
/*
** 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); \
tab = (void *)0; 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;
dec = opp;
while (dec--)
{
if (img->image->byte_order)
*(data+x*opp+dec) = col&0xFF;
else
*(data+x*opp+opp-dec-1) = col&0xFF;
col >>= 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;
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 ..
!(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;
// 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; //rgb_col>=0?mlx_get_color_value(xvar,rgb_col):rgb_col;
}
free(tab);
tab = (void *)0;
}
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 ++;
*/
if (col==-1)
col = 0xFF000000;
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);
}

310
Minilibx/mlx_xpm.c.ok Normal file
View file

@ -0,0 +1,310 @@
/*
** 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:40:55 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);
}
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)
{
int i;
if (*name == '#')
return (strtol(name+1,0,16));
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;
dec = opp;
while (dec--)
{
if (img->image->byte_order)
*(data+x*opp+dec) = col&0xFF;
else
*(data+x*opp+opp-dec-1) = col&0xFF;
col >>= 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]))==-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);
}

Some files were not shown because too many files have changed in this diff Show more