Commit a0ae785bf7f3cef46c375417f3b0bab89ecf4449

Authored by Jean Wasilewski
1 parent 155f7ac1

Non working version

Showing 1 changed file with 49 additions and 50 deletions   Show diff stats
1 -/*  
2 - Remember to compile try:  
3 - 1) gcc hi.c -o hi -lX11  
4 - 2) gcc hi.c -I /usr/include/X11 -L /usr/X11/lib -lX11  
5 - 3) gcc hi.c -I /where/ever -L /who/knows/where -l X11  
6 -  
7 - Brian Hammond 2/9/96. Feel free to do with this as you will!  
8 -*/  
9 -  
10 -  
11 -/* include the X library headers */  
12 #include <X11/Xlib.h> 1 #include <X11/Xlib.h>
13 #include <X11/Xutil.h> 2 #include <X11/Xutil.h>
14 #include <X11/Xos.h> 3 #include <X11/Xos.h>
15 -  
16 -/* include some silly stuff */  
17 #include <stdio.h> 4 #include <stdio.h>
18 #include <stdlib.h> 5 #include <stdlib.h>
19 6
20 -/* here are our X variables */ 7 +#define AWESOME 7
  8 +
21 Display *dis; 9 Display *dis;
22 int screen; 10 int screen;
23 Window win; 11 Window win;
24 GC gc; 12 GC gc;
25 int width=320; 13 int width=320;
26 int height=240; 14 int height=240;
  15 +int i=0;
27 16
28 -/* here are our X routines declared! */  
29 void init_x(); 17 void init_x();
30 void close_x(); 18 void close_x();
31 void redraw(); 19 void redraw();
32 20
33 -main () { 21 +int main ()
  22 +{
34 XEvent event; /* the XEvent declaration !!! */ 23 XEvent event; /* the XEvent declaration !!! */
35 KeySym key; /* a dealie-bob to handle KeyPress Events */ 24 KeySym key; /* a dealie-bob to handle KeyPress Events */
36 char text[255]; /* a char buffer for KeyPress Events */ 25 char text[255]; /* a char buffer for KeyPress Events */
37 - Pixmap pmap;  
38 XColor col; 26 XColor col;
  27 + int initOffsetBMP;
39 28
40 init_x(); 29 init_x();
41 30
42 printf("Patte de canard\n"); 31 printf("Patte de canard\n");
43 Colormap cmap = DefaultColormap(dis, DefaultScreen(dis)); 32 Colormap cmap = DefaultColormap(dis, DefaultScreen(dis));
44 printf("?\n"); 33 printf("?\n");
45 - pmap = XCreatePixmap(dis, win, width, height, DefaultDepth(dis, DefaultScreen(dis)));  
46 -  
47 34
48 FILE* home = NULL; 35 FILE* home = NULL;
49 char buffer[4]; 36 char buffer[4];
@@ -57,6 +44,7 @@ main () { @@ -57,6 +44,7 @@ main () {
57 buffer[2] = getc(home); 44 buffer[2] = getc(home);
58 buffer[3] = getc(home); 45 buffer[3] = getc(home);
59 printf("Pixel array offset %02x %02x %02x %02x\n", buffer[0], buffer[1], buffer[2], buffer[3]); 46 printf("Pixel array offset %02x %02x %02x %02x\n", buffer[0], buffer[1], buffer[2], buffer[3]);
  47 + initOffsetBMP = buffer[0] + (buffer[1] >> 8) + (buffer[2] >> 16) + (buffer[3] >> 24);
60 48
61 fseek(home, 0x12, SEEK_SET); 49 fseek(home, 0x12, SEEK_SET);
62 buffer[0] = getc(home); 50 buffer[0] = getc(home);
@@ -84,61 +72,72 @@ main () { @@ -84,61 +72,72 @@ main () {
84 } 72 }
85 73
86 74
  75 + fseek(home, initOffsetBMP, SEEK_SET);
87 76
88 -  
89 - while(1);  
90 -  
91 -  
92 - /* look for events forever... */  
93 - while(1) {  
94 - /* get the next event and stuff it into our event variable.  
95 - Note: only events we set the mask for are detected!  
96 - */ 77 + while(1)
  78 + {
97 XNextEvent(dis, &event); 79 XNextEvent(dis, &event);
98 80
99 - if (event.type==Expose && event.xexpose.count==0) {  
100 - /* the window was exposed redraw it! */ 81 + if (event.type==Expose && event.xexpose.count==0)
101 redraw(); 82 redraw();
102 - }  
103 - if (event.type==KeyPress&&  
104 - XLookupString(&event.xkey,text,255,&key,0)==1) {  
105 - /* use the XLookupString routine to convert the invent  
106 - KeyPress data into regular text. Weird but necessary...  
107 - */  
108 - if (text[0]=='q') { 83 +
  84 + if (event.type==KeyPress&& XLookupString(&event.xkey,text,255,&key,0)==1)
  85 + {
  86 + if (text[0]=='q')
109 close_x(); 87 close_x();
110 - }  
111 printf("You pressed the %c key!\n",text[0]); 88 printf("You pressed the %c key!\n",text[0]);
112 } 89 }
113 - if (event.type==ButtonPress) {  
114 - /* tell where the mouse Button was Pressed */  
115 - int x=event.xbutton.x,  
116 - y=event.xbutton.y; 90 + if (event.type==ButtonPress)
  91 + {
  92 + //int x=event.xbutton.x,
  93 + //y=event.xbutton.y;
117 94
118 //strcpy(text,"X is FUN!"); 95 //strcpy(text,"X is FUN!");
119 //XSetForeground(dis,gc,rand()%event.xbutton.x%255); 96 //XSetForeground(dis,gc,rand()%event.xbutton.x%255);
120 //XDrawString(dis,win,gc,x,y, text, strlen(text)); 97 //XDrawString(dis,win,gc,x,y, text, strlen(text));
121 98
  99 + buffer[0] = getc(home);
  100 + buffer[1] = getc(home);
  101 + buffer[2] = getc(home);
  102 +
  103 + int j;
  104 +
  105 + for(j=0; j<AWESOME; j++)
  106 + {
  107 + col.red = buffer[2];
  108 + col.green = buffer[1];
  109 + col.blue = buffer[0];
122 110
123 - col.red = 128;  
124 - col.green = 128;  
125 - col.blue = 0;  
126 - XAllocColor(dis, cmap, &col);  
127 - XSetForeground(dis, gc, col.pixel);  
128 - XDrawPoint(dis,win,gc,x,y); 111 +
  112 +
  113 +
  114 +
  115 + if(XAllocColor(dis, cmap, &col) == 0)
  116 + printf("Failed to allocate color\n");
  117 + if(XSetForeground(dis, gc, col.pixel) == 0)
  118 + printf("Failed to set foreground\n");
  119 + if(XDrawPoint(dis,win,gc,i%width,i/height) == 0)
  120 + printf("Failed to draw point\n");
  121 + buffer[0] = getc(home);
  122 + buffer[1] = getc(home);
  123 + buffer[2] = getc(home);
  124 + printf("X %03d Y %03d R %02x G %02x B %02x\n", i%width, i/height, buffer[0], buffer[1], buffer[2]);
  125 + i++;
  126 + }
129 } 127 }
130 } 128 }
  129 + printf("End of display\n");
  130 + return 0;
131 } 131 }
132 132
133 void init_x() { 133 void init_x() {
134 -/* get the colors black and white (see section for details) */  
135 unsigned long black,white; 134 unsigned long black,white;
136 135
137 dis=XOpenDisplay((char *)0); 136 dis=XOpenDisplay((char *)0);
138 screen=DefaultScreen(dis); 137 screen=DefaultScreen(dis);
139 black=BlackPixel(dis,screen), 138 black=BlackPixel(dis,screen),
140 white=WhitePixel(dis, screen); 139 white=WhitePixel(dis, screen);
141 - win=XCreateSimpleWindow(dis,DefaultRootWindow(dis),0,0,height,width, 0,black, white); 140 + win=XCreateSimpleWindow(dis,DefaultRootWindow(dis),0,0,width,height, 0,black, white);
142 XSetStandardProperties(dis,win,"Howdy","Hi",None,NULL,0,NULL); 141 XSetStandardProperties(dis,win,"Howdy","Hi",None,NULL,0,NULL);
143 XSelectInput(dis, win, ExposureMask|ButtonPressMask|KeyPressMask); 142 XSelectInput(dis, win, ExposureMask|ButtonPressMask|KeyPressMask);
144 gc=XCreateGC(dis, win, 0,0); 143 gc=XCreateGC(dis, win, 0,0);