~ubuntu-branches/ubuntu/vivid/xmountains/vivid

« back to all changes in this revision

Viewing changes to X_graphics.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2008-06-11 19:35:06 UTC
  • mfrom: (3.1.5 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080611193506-f9w3mgbd3zejd4oq
Tags: 2.7-8
Change Build-Depends: xutils-dev. (Closes: #485719)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include <stdio.h>
2
 
#include <string.h>
3
2
#include<X11/Xlib.h>
4
3
#include<X11/Xutil.h>
5
4
#include<X11/Xatom.h>
31
30
  int do_clear=FALSE;
32
31
  int pixmap_installed=FALSE;
33
32
 
34
 
  int swosh=FALSE;
35
 
 
36
33
  /* plot history */
37
34
  int plot_x, plot_y1, plot_y2;
38
35
  unsigned long plot_col;
44
41
  unsigned int depth=0;
45
42
  GC gc;
46
43
  Pixmap pix;
47
 
  Pixmap bg_pix;
48
44
  Colormap map, defaultmap;
49
45
  XColor *table=NULL;
50
46
void zap_events();
54
50
1024,
55
51
768,
56
52
0,
57
 
0,
58
53
0.3,
59
54
1.0,
60
55
0.3,
77
72
0
78
73
};
79
74
 
80
 
void finish_artist();
 
75
 
81
76
 
82
77
/*{{{void zap_events(int snooze)*/
83
78
void zap_events(snooze)
85
80
{
86
81
  XEvent event;
87
82
  XExposeEvent *expose = (XExposeEvent *)&event;
88
 
  int exw, exh;
 
83
  int exw, exh, i;
89
84
 
90
85
  while( XPending(dpy) ){
91
86
    XNextEvent(dpy, &event);
116
111
            }else{
117
112
              exh = expose->height;
118
113
            }
119
 
            if(g.repeat < 0)
120
 
            {
121
 
              XCopyArea(dpy, pix, win, gc, expose->x - g.repeat, expose->y,
122
 
                            exw, exh,
123
 
                            expose->x,expose->y);
124
 
            }
125
 
            else
126
 
            {
127
 
              XCopyArea(dpy,pix,win,gc,expose->x,expose->y,
128
 
                            exw,exh,
129
 
                            expose->x,expose->y);
130
 
            }
131
 
          }
132
 
          break;
 
114
            XCopyArea(dpy,pix,win,gc,expose->x,expose->y,
 
115
                          exw,exh,
 
116
                          expose->x,expose->y);
 
117
          }
 
118
          break;
133
119
        default:
134
120
            fprintf(stderr,"xmountains: unrecognized event %d\n",event.type);
135
121
            /* XCloseDisplay(dpy);
184
170
  {
185
171
    XFreeColormap(dpy, map );
186
172
  }
187
 
  if((count = XPending(dpy)))
 
173
  if( count = XPending(dpy) )
188
174
  {
189
175
    fprintf(stderr,"WARNING: %d events still pending\n",count);
190
176
  }
221
207
/*}}}*/
222
208
 
223
209
/*{{{void init_graphics( ... )*/
224
 
void init_graphics( want_use_root, use_window, use_background, want_clear,gptr,red,green,blue )
225
 
 
 
210
void init_graphics( want_use_root, use_window, use_background, want_clear, s_graph_width,s_graph_height,ncol,red,green,blue )
226
211
int want_use_root;    /* display on the root window */
227
212
Window use_window;    /* display on external window */
228
213
int  use_background;  /* install the pixmap as the background-pixmap */
229
214
int want_clear;
230
 
Graph *gptr;
231
 
 
 
215
int *s_graph_width;
 
216
int *s_graph_height;
 
217
int ncol;
232
218
Gun *red;
233
219
Gun *green;
234
220
Gun *blue;
235
221
{
236
222
/*{{{defs*/
237
223
  Visual *vis;
238
 
 
239
 
  
 
224
  int mask;
 
225
  int count;
240
226
  int x=0;
241
227
  int y=0;
242
228
  int gbits=0;
260
246
  do_clear = want_clear;
261
247
  use_root = want_use_root;
262
248
  pixmap_installed = use_background;
263
 
  graph_width = gptr->graph_width;
264
 
  graph_height = gptr->graph_height;
 
249
  graph_width = *s_graph_width;
 
250
  graph_height = *s_graph_height;
265
251
/*{{{open display*/
266
252
 
267
253
  dpy = XOpenDisplay(display);
282
268
  depth = DefaultDepth(dpy,screen);
283
269
/*}}}*/
284
270
/*{{{set colormap*/
285
 
  table = (XColor *)malloc(gptr->n_col * sizeof(XColor));
 
271
  table=(XColor *)malloc(ncol * sizeof(XColor));
286
272
  if( NULL == table )
287
273
  {
288
274
    fprintf(stderr,"malloc failed for colour table\n");
289
275
    exit(1);
290
276
  }
291
 
  for(i = 0; i < gptr->n_col; i++)
 
277
  for(i=0; i<ncol ; i++)
292
278
  {
293
279
    table[i].red   = red[i];
294
280
    table[i].green = green[i];
392
378
/*    graph_width = DisplayWidth(dpy,screen); */
393
379
/*    graph_height = DisplayHeight(dpy,screen); */
394
380
  }
395
 
 
396
 
  if(swosh)
397
 
  {
398
 
    if(gptr->repeat < 0)
399
 
    {
400
 
      gptr->pixmap_width = graph_width - gptr->repeat;
401
 
      bg_pix = XCreatePixmap(dpy, win, graph_width, graph_height, depth);
402
 
    }
403
 
    else
404
 
    {
405
 
      if(gptr->repeat == 0)
406
 
      {
407
 
        gptr->repeat = graph_width;
408
 
      }
409
 
      gptr->pixmap_width = graph_width + gptr->repeat;
410
 
    }
411
 
  }
412
 
  else
413
 
  {
414
 
    gptr->pixmap_width = graph_width;
415
 
  }
416
 
  pix = XCreatePixmap(dpy, win, gptr->pixmap_width, graph_height, depth);
 
381
  pix = XCreatePixmap(dpy,win,graph_width,graph_height,depth);
417
382
 
418
383
/*}}}*/
419
 
  blank_region(0, 0, gptr->pixmap_width, graph_height); 
 
384
  blank_region(0,0,graph_width,graph_height); 
420
385
 
421
386
  if( use_background )
422
387
  {
429
394
  XClearWindow(dpy,win);
430
395
  zap_events(0);
431
396
  
432
 
  gptr->graph_width = graph_width;
433
 
  gptr->graph_height = graph_height;
 
397
  *s_graph_width = graph_width;
 
398
  *s_graph_height = graph_height;
434
399
}
435
400
/*}}}*/
436
401
 
446
411
    reverse=TRUE;
447
412
  }
448
413
  /* scroll the pixmap */
449
 
  if( dist > g.pixmap_width )
 
414
  if( dist > graph_width )
450
415
  {
451
 
    dist = g.pixmap_width;
 
416
    dist = graph_width;
452
417
  }
453
418
  if( reverse )
454
419
  {
455
420
    /* copy the data */
456
 
    XCopyArea(dpy, pix, pix, gc, 0, 0, g.pixmap_width - dist, graph_height, dist, 0);
 
421
    XCopyArea(dpy,pix,pix,gc,0,0,graph_width-dist,graph_height,dist,0);
457
422
    /* blank new region */
458
423
    blank_region(0,0,dist,graph_height);
459
424
  }else{
460
425
    /* copy the data */
461
 
    XCopyArea(dpy, pix, pix, gc, dist, 0, g.pixmap_width - dist, graph_height, 0, 0);
 
426
    XCopyArea(dpy,pix,pix,gc,dist,0,graph_width-dist,graph_height,0,0);
462
427
    /* blank new region */
463
 
    blank_region(g.pixmap_width - dist, 0, dist, graph_height);
 
428
    blank_region(graph_width-dist,0,dist,graph_height);
464
429
  }
465
430
  /* update the window to match */
466
431
  if( pixmap_installed )
471
436
     * so in principle we should re-install.
472
437
     */
473
438
    XSetWindowBackgroundPixmap(dpy,win,None);
474
 
 
475
 
    if(swosh && reverse)
476
 
    {
477
 
      XCopyArea(dpy, pix, bg_pix, gc, dist, 0, graph_width, graph_height, 0, 0);
478
 
      XSetWindowBackgroundPixmap(dpy, win, bg_pix);
479
 
    }
480
 
    else
481
 
    {
482
 
      XSetWindowBackgroundPixmap(dpy,win,pix);
483
 
    }
 
439
    XSetWindowBackgroundPixmap(dpy,win,pix);
484
440
    XClearWindow(dpy,win);
485
441
  }else{
486
 
    if(reverse)
487
 
    {
488
 
      XCopyArea(dpy, pix, win, gc, dist, 0, graph_width, graph_height, 0, 0);
489
 
    }
490
 
    else
491
 
    {
492
 
      XCopyArea(dpy, pix, win, gc, 0, 0, graph_width, graph_height, 0, 0);
493
 
    }
 
442
    XCopyArea(dpy,pix,win,gc,0,0,graph_width,graph_height,0,0);
494
443
  }
495
444
 
496
445
}
562
511
{
563
512
  /* flush outstanding plots */
564
513
  plot_pixel(-1,0,0);
565
 
  if(!swosh)
566
 
  {
567
 
    XCopyArea(dpy,pix,win,gc,x,y,w,h,x,y);
568
 
  }
 
514
  XCopyArea(dpy,pix,win,gc,x,y,w,h,x,y);
569
515
}
570
516
/*}}}*/
571
517