root/trunk/X11/example.d

Revision 202, 1.7 kB (checked in by sligor, 1 year ago)

X11 binding for D version 0.1
->Complete binding for X11/Xlib.h & X11/X.h

Line 
1 /* this an example for this binding*/
2 /* please read README file before */
3
4 /* compile with: dmd example.d Xlib.d X.d  -L-lX11*/
5
6 import std.c.linux.X11.Xlib;
7 import std.c.stdio;
8
9 int main(char[][] args)
10 {
11     Display* display = XOpenDisplay(null);  //Open default display
12     Window window = XCreateSimpleWindow(    //create a simple windows
13         display,                                // display
14         DefaultRootWindow(display),             // parent window
15         0, 0, 200, 100,                         // x, y, w, h
16         0,0x0,0x000000FF                        // border_width,boder_color,back_color
17         );                                       
18     XMapWindow(display, window); //map the window
19     XRaiseWindow(display, window); //show the window
20     XStoreName(display,window,"Hello Window\0"); //set window name , don't forget /0 term char !
21     XFlush(display); // flush X server
22    
23     //wait for a enter pressed (in fact you need to wait for MapNotify event before drawing...)
24     printf("press enter to show window content\0");
25     getchar();
26    
27     XGCValues values;
28     values.foreground=0xFFFFFF;
29     values.background=0x00FF00;
30     GC gc=XCreateGC(display,window,GCMask.GCForeground | GCMask.GCBackground,&values); //create zone for drawing
31     char* chaine="hello world";
32     XDrawString(display, window,gc, 30,50,chaine, 11); //draw string
33     XDrawRectangle(display,window,gc,20,20,150,50); //draw rectangle
34     XFlush(display); //flush X server
35     printf("press enter to close program\0");
36     getchar(); //wait for a enter pressed to close program
37     XUnmapWindow(display, window); // unmap the window
38     XDestroyWindow(display, window); //destroy the window
39     XCloseDisplay(display); //close the display
40     return 0;
41 };
Note: See TracBrowser for help on using the browser.