root/trunk/X11/example.d

Revision 364, 1.8 kB (checked in by Gor, 1 year ago)

added module names to examples to resolve conflict

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