diff --git a/Makefile.mk b/Makefile.mk
index 1bae8df..02af928 100644
--- a/Makefile.mk
+++ b/Makefile.mk
@@ -1,9 +1,9 @@
##
## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
-##
+##
## Made by Olivier Crouzet
## Login
-##
+##
## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet
## Last update Tue May 15 15:41:20 2007 Olivier Crouzet
##
diff --git a/mlx.h b/mlx.h
index b323412..e851221 100644
--- a/mlx.h
+++ b/mlx.h
@@ -1,9 +1,9 @@
/*
-** mlx.h for MinilibX in
-**
+** mlx.h for MinilibX in
+**
** Made by Charlie Root
** Login
-**
+**
** Started on Mon Jul 31 16:37:50 2000 Charlie Root
** Last update Tue May 15 16:23:28 2007 Olivier Crouzet
*/
@@ -44,6 +44,9 @@ void *mlx_init();
*/
void *mlx_new_window(void *mlx_ptr, int size_x, int size_y, char *title);
+void *mlx_new_fullscreen_window(void *mlx_ptr, int *size_x, int *size_y,
+ char *title);
+
/*
** return void *0 if failed
*/
diff --git a/mlx_ext_randr.c b/mlx_ext_randr.c
index 34ddb91..11543e9 100644
--- a/mlx_ext_randr.c
+++ b/mlx_ext_randr.c
@@ -1,5 +1,7 @@
-
-
+/*
+** Requires: sudo apt install libxrandr-dev libxrandr2
+** Compile with flag: -lXrandr
+*/
#include "mlx_int.h"
diff --git a/mlx_new_window.c b/mlx_new_window.c
index 3f05914..2162175 100644
--- a/mlx_new_window.c
+++ b/mlx_new_window.c
@@ -1,14 +1,13 @@
/*
-** mlx_new_window.c for MiniLibX in
-**
+** mlx_new_window.c for MiniLibX in
+**
** Made by Charlie Root
** Login
-**
+**
** 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
@@ -16,14 +15,11 @@
** With mlx_int_wait_first_expose, no flush is needed.
*/
-#include "mlx_int.h"
-
+#include "mlx_int.h"
-void *mlx_new_window(t_xvar *xvar,int size_x,int size_y,char *title)
+static XSetWindowAttributes get_default_attributes(t_xvar *xvar)
{
- t_win_list *new_win;
XSetWindowAttributes xswa;
- XGCValues xgcv;
xswa.background_pixel = 0;
xswa.border_pixel = -1;
@@ -33,21 +29,24 @@ void *mlx_new_window(t_xvar *xvar,int size_x,int size_y,char *title)
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);
+ xswa.event_mask = 0xFFFFFF; /* all events */
+ return (xswa);
+}
+
+static void *set_configs(t_xvar *xvar, t_win_list *new_win, int size_x,
+ int size_y, char *title)
+{
+ XGCValues xgcv;
+
+ 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->gc = XCreateGC(xvar->display, new_win->window,
+ GCFunction | GCPlaneMask | GCForeground, &xgcv);
new_win->next = xvar->win_list;
xvar->win_list = new_win;
/*
@@ -56,7 +55,39 @@ void *mlx_new_window(t_xvar *xvar,int size_x,int size_y,char *title)
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);
+ XMapRaised(xvar->display, new_win->window);
+ mlx_int_wait_first_expose(xvar, new_win->window);
return (new_win);
}
+
+void *mlx_new_window(t_xvar *xvar, int size_x, int size_y, char *title)
+{
+ t_win_list *new_win;
+ XSetWindowAttributes xswa;
+
+ if (!(new_win = malloc(sizeof(*new_win))))
+ return ((void *)0);
+ xswa = get_default_attributes(xvar);
+ new_win->window = XCreateWindow(xvar->display, xvar->root, 0, 0, size_x,
+ size_y, 0, CopyFromParent, InputOutput, xvar->visual,
+ CWEventMask | CWBackPixel | CWBorderPixel | CWColormap, &xswa);
+ return (set_configs(xvar, new_win, size_x, size_y, title));
+}
+
+void *mlx_new_fullscreen_window(t_xvar *xvar, int *size_x, int *size_y,
+ char *title)
+{
+ t_win_list *new_win;
+ XSetWindowAttributes xswa;
+
+ if (!(new_win = malloc(sizeof(*new_win))))
+ return ((void *)0);
+ xswa = get_default_attributes(xvar);
+ xswa.override_redirect = 1;
+ mlx_get_screen_size(xvar, size_x, size_y);
+ new_win->window = XCreateWindow(xvar->display, xvar->root, 0, 0, *size_x,
+ *size_y, 0, CopyFromParent, InputOutput, xvar->visual,
+ CWEventMask | CWBackPixel | CWBorderPixel | CWColormap | CWOverrideRedirect,
+ &xswa);
+ return (set_configs(xvar, new_win, *size_x, *size_y, title));
+}
diff --git a/test/main.c b/test/main.c
index 578eaae..07cd18d 100644
--- a/test/main.c
+++ b/test/main.c
@@ -11,28 +11,34 @@
void *mlx;
void *win1;
-void *win2;
-void *win3;
-void *im1;
+void *win2;
+void *win3;
+void *window_fullsreen;
+void *im1;
void *im2;
void *im3;
void *im4;
+void *im5;
int bpp1;
int bpp2;
int bpp3;
int bpp4;
+int bpp5;
int sl1;
int sl2;
int sl3;
int sl4;
+int sl5;
int endian1;
int endian2;
int endian3;
int endian4;
+int endian5;
char *data1;
char *data2;
char *data3;
char *data4;
+char *data5;
int xpm1_x;
int xpm1_y;
@@ -88,8 +94,7 @@ int mouse_win3(int x,int y, void *p)
printf("Mouse moving in Win3, at %dx%d.\n",x,y);
}
-
-int main()
+static void test_endianess(void)
{
int a;
@@ -100,7 +105,10 @@ int main()
else
local_endian = 0;
printf(" => Local Endian : %d\n",local_endian);
+}
+static void test_mlx_init(void)
+{
printf(" => Connection ...");
if (!(mlx = mlx_init()))
{
@@ -108,7 +116,10 @@ int main()
exit(1);
}
printf("OK (use_xshm %d pshm_format %d)\n",((t_xvar *)mlx)->use_xshm,((t_xvar *)mlx)->pshm_format);
+}
+static void test_window(void)
+{
printf(" => Window1 %dx%d \"Title 1\" ...",WIN1_SX,WIN1_SY);
if (!(win1 = mlx_new_window(mlx,WIN1_SX,WIN1_SY,"Title1")))
{
@@ -126,7 +137,10 @@ int main()
mlx_clear_window(mlx,win1);
printf("OK\n");
sleep(2);
+}
+static void test_image(void)
+{
printf(" => Image1 ZPixmap %dx%d ...",IM1_SX,IM1_SY);
if (!(im1 = mlx_new_image(mlx,IM1_SX,IM1_SY)))
{
@@ -150,7 +164,10 @@ int main()
mlx_destroy_image(mlx, im1);
printf("OK\n");
sleep(2);
+}
+static void test_string(void)
+{
printf(" => Image3 ZPixmap %dx%d ...",IM3_SX,IM3_SY);
if (!(im3 = mlx_new_image(mlx,IM3_SX,IM3_SY)))
{
@@ -175,7 +192,10 @@ int main()
mlx_string_put(mlx,win1,15,WIN1_SY/2+20,0x00FFFF,"MinilibX test");
printf("OK\n");
sleep(2);
+}
+static void test_xpm(void)
+{
printf(" => Xpm from file ...");
if (!(im2 = mlx_xpm_file_to_image(mlx,"open.xpm",&xpm1_x,&xpm1_y)))
{
@@ -190,9 +210,60 @@ int main()
printf(" => Put xpm ...");
mlx_put_image_to_window(mlx,win1,im2,0,0);
mlx_put_image_to_window(mlx,win1,im2,100,100);
+ printf("OK\n"); sleep(2);
+}
+
+static void test_fullscreen_window(void)
+{
+ int size_x;
+ int size_y;
+
+ printf(" => Fullscreen Window \"Fullscreen1\" ");
+ if (!(window_fullsreen = mlx_new_fullscreen_window(mlx,&size_x,&size_y,"Title1")))
+ {
+ printf(" !! KO !!\n");
+ exit(1);
+ }
+ printf("%dx%d ...", size_x, size_y);
+ printf("OK\n");
+
+ printf(" => Image5 ZPixmap %dx%d ...",size_x,size_y);
+ if (!(im5 = mlx_new_image(mlx,size_x,size_y)))
+ {
+ printf(" !! KO !!\n");
+ exit(1);
+ }
+ data5 = mlx_get_data_addr(im5,&bpp5,&sl5,&endian5);
+ printf("OK (bpp5: %d, sizeline5: %d endian: %d type: %d)\n",bpp5,sl5,endian5,
+ ((t_img *)im5)->type);
+
+ printf(" => Fill Image5 ...");
+ color_map_2(data5,bpp5,sl5,size_x,size_y,endian5, 5);
+ printf("OK (pixmap : %d)\n",(int)((t_img *)im5)->pix);
+
+ printf(" => Put Image5 ...");
+ mlx_put_image_to_window(mlx,window_fullsreen,im5,20,20);
printf("OK\n");
sleep(2);
+ printf(" => Destroy Image5 ... ");
+ mlx_destroy_image(mlx, im5);
+ printf("OK\n");
+ sleep(2);
+
+ printf(" => Clear Fullscreen Window ...");
+ mlx_clear_window(mlx,window_fullsreen);
+ printf("OK\n");
+ sleep(2);
+
+ printf(" => Destroy Fullscreen Window ...");
+ mlx_destroy_window(mlx,window_fullsreen);
+ printf("OK\n");
+ sleep(2);
+}
+
+static void test_hooks(void)
+{
printf(" => 2nd window,");
win2 = mlx_new_window(mlx,WIN1_SX,WIN1_SY,"Title2");
if (!(im4 = mlx_new_image(mlx,IM3_SX, IM3_SY)))
@@ -216,10 +287,21 @@ int main()
mlx_hook(win3, MotionNotify, PointerMotionMask, mouse_win3, 0);
printf("OK\nNow in Loop. Just play. Esc in 3 to destroy, 1&2 to quit.\n");
-
+
mlx_loop(mlx);
}
+int main()
+{
+ test_endianess();
+ test_mlx_init();
+ test_window();
+ test_image();
+ test_string();
+ test_xpm();
+ test_fullscreen_window();
+ test_hooks();
+}
int color_map_1(void *win,int w,int h)
{