Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mlx_new_fullscreen_window. #45

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile.mk
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
##
## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
##
##
## Made by Olivier Crouzet
## Login <[email protected]>
##
##
## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet
## Last update Tue May 15 15:41:20 2007 Olivier Crouzet
##
Expand Down
9 changes: 6 additions & 3 deletions mlx.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
** mlx.h for MinilibX in
**
** mlx.h for MinilibX in
**
** Made by Charlie Root
** Login <[email protected]>
**
**
** Started on Mon Jul 31 16:37:50 2000 Charlie Root
** Last update Tue May 15 16:23:28 2007 Olivier Crouzet
*/
Expand Down Expand Up @@ -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
*/
Expand Down
6 changes: 4 additions & 2 deletions mlx_ext_randr.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@


/*
** Requires: sudo apt install libxrandr-dev libxrandr2
** Compile with flag: -lXrandr
*/

#include "mlx_int.h"

Expand Down
77 changes: 54 additions & 23 deletions mlx_new_window.c
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
/*
** mlx_new_window.c for MiniLibX in
**
** mlx_new_window.c for MiniLibX in
**
** Made by Charlie Root
** Login <[email protected]>
**
**
** 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"

#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;
Expand All @@ -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;
/*
Expand All @@ -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));
}
94 changes: 88 additions & 6 deletions test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -100,15 +105,21 @@ 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()))
{
printf(" !! KO !!\n");
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")))
{
Expand All @@ -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)))
{
Expand All @@ -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)))
{
Expand All @@ -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)))
{
Expand All @@ -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)))
Expand All @@ -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)
{
Expand Down