home *** CD-ROM | disk | FTP | other *** search
- #define _BSD
-
- /*#include <stdio.h>*/
-
- /*#include <stdlib.h>*/
-
- #define XK_LATIN1
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
- #include <X11/Xos.h>
- /*#include <X11/keysymde.h>*/
- #include <X11/bitmaps/icon>
-
- #include "mp_eubang.h"
-
- #define WNAME "XLights"
- #define INAME "XLights"
-
- int border;
- int panel_width;
- int panel_height;
-
- int light_width;
- int light_height;
- int loadlight_x;
- int loadlight_y;
-
- int width, height;
- int x,y;
-
- int panel_x( x )
- int x;
- { return ((x)*(panel_width+2*border)+(2*border)); }
-
- int panel_y( y )
- int y;
- { return ((y)*(panel_height+2*border)+(2*border)); }
-
- #define XKillPendingRequests( dpy ) ((dpy)->bufptr = (dpy)->buffer)
-
- Display * display;
- Visual * visual;
- int screen;
- Window win;
- GC gc;
- XEvent xevent;
- Pixmap icon_pixmap;
- Font font;
- XFontStruct * fontinfo;
- int black;
- int white;
- int grey = 22;
-
- char ** colnames;
- int ncolors;
-
- char * huenames[] =
- {
- "black",
- "red",
- "skyblue",
- "green"
- };
-
- char * greynames[] =
- {
- "black",
- "black",
- "white",
- "white"
- };
-
- int colors[ 20 ];
-
- /* ------------------------- */
- #define IOdebug printf
- #define Delay(x) sleep(x)
- #define OneSec 1
-
- typedef int word;
- typedef int bool;
-
- #ifndef TRUE
- #define TRUE 1
- #endif
- #ifndef FALSE
- #define FALSE 0
- #endif
-
- #define WIDTH MASPAR_XLEN
- #define HEIGHT MASPAR_YLEN
-
- /* ------------------------- */
-
- int running = FALSE;
-
-
-
- void Xlights();
-
- void visualise( info )
-
- char info[WIDTH][HEIGHT];
-
- {
- Xlights( info );
- }
-
- void draw_lights();
- void setup();
- void redisplay();
-
- char old_info[WIDTH][HEIGHT];
-
- void init_info( info )
-
- char info[WIDTH][HEIGHT];
-
- {
- int x;
- int y;
- XSetForeground(display, gc, white );
- for( y = 0; y < HEIGHT; y++ )
- for( x = 0; x < HEIGHT; x++ ) {
- XFillRectangle( display, win, gc, panel_x(x)
- ,panel_y(y),panel_width,panel_height);
- info[x][y] = (char)5;
- }
- XFlush(display);
- }
-
- void rand_info( info )
-
- char info[WIDTH][HEIGHT];
-
- {
- }
-
- void print_info( info )
-
- char info[WIDTH][HEIGHT];
-
- {
- int x;
- int y;
- for( y = 0; y < HEIGHT; y++ )
- {
- for( x = 0; x < WIDTH; x++ )
- printf(" %d",(int)info[x][y]);
- printf("\n");
- }
- }
-
- void Xlights( info)
- char info[WIDTH][HEIGHT];
- {
- if (!(running)) {
- setup(NULL);
- init_info( old_info);
- }
- redisplay(info);
- }
-
- void
- setup( display_name )
- char * display_name;
- {
- XSizeHints hints;
- int i;
- int maxw = 0;
- char * maxname;
- XColor c;
- Colormap cmap;
- int selfpos = 0;
- int args_start;
-
- if ((display = XOpenDisplay( display_name )) == NULL )
- {
- IOdebug("failed to open display %s", XDisplayName( display_name ));
-
- exit(1);
- }
-
- font = XLoadFont(display, "6x13");
- fontinfo = XQueryFont(display, font);
-
- border = 1;
-
- light_height = 4;
- light_width = light_height;
- panel_width = (light_width+2*border);
- panel_height = (light_height+2*border);
-
- loadlight_x = border;
- loadlight_y = border;
-
- screen = DefaultScreen(display);
- visual = DefaultVisual(display,screen);
- cmap = DefaultColormap(display, screen);
-
- width = (panel_width+2*border)*WIDTH+(2*border);
- height = (panel_height+2*border)*HEIGHT+(2*border);
- x = DisplayWidth(display,screen)-width-2*border;
- y = DisplayHeight(display,screen)-height-2*border;
- black = BlackPixel(display,screen);
- white = WhitePixel(display,screen);
-
- if( visual->class == GrayScale )
- {
- colnames = greynames;
- ncolors = sizeof(greynames)/4;
- }
- else
- {
- colnames = huenames;
- ncolors = sizeof(huenames)/4;
- }
-
- XParseColor(display, cmap, "darkslategrey", &c );
- XAllocColor(display, cmap, &c );
- grey = c.pixel;
-
- for( i = 0; i < ncolors; i++ )
- {
- XParseColor(display, cmap, colnames[i], &c );
- XAllocColor(display, cmap, &c );
- colors[i] = c.pixel;
- }
-
- win = XCreateSimpleWindow(display, RootWindow(display,screen),
- x,y,width,height,border,white,grey);
-
-
- icon_pixmap = XCreateBitmapFromData(display, win, icon_bits,
- icon_width, icon_height);
-
- hints.flags = 0; /* selfpos?(USPosition|USSize):(PPosition|PSize); */
- hints.x = x;
- hints.y = y;
- hints.width = width;
- hints.height = height;
-
- XSetStandardProperties(display, win, WNAME, INAME, icon_pixmap,
- NULL, 0, &hints );
-
- gc = XCreateGC(display, win, NULL, 0 );
-
- XSetLineAttributes(display, gc, 0, LineSolid, CapButt, JoinMiter );
-
- XSelectInput( display, win,
- StructureNotifyMask | ExposureMask | KeyPressMask );
-
- XMapWindow(display, win);
-
- /* running = TRUE;*/
- }
-
- void redisplay( info)
- char info[WIDTH][HEIGHT];
- {
- if( !running || XPending(display) )
- {
- XNextEvent( display, &xevent);
- switch( xevent.type )
- {
- case Expose:
- expose:
- while(XCheckTypedEvent(display,Expose,&xevent));
- XClearArea(display, win, 0, 0, width, height, FALSE);
- XSetForeground(display, gc, black);
- for(x = 0; x < WIDTH; x++ ) {
-
- for(y = 0; y < HEIGHT; y++ )
- XFillRectangle(display, win, gc,
- panel_x(x), panel_y(y),
- panel_width,panel_height);
- }
- break;
-
- case ConfigureNotify:
- width = xevent.xconfigure.width;
- height = xevent.xconfigure.height;
- XKillPendingRequests(display);
- break;
-
- default:
- break;
- }
- }
-
- if (!running) {
-
- running = TRUE;
- XClearArea(display, win, 0, 0, width, height, FALSE);
- XSetForeground(display, gc, black);
- for(x = 0; x < WIDTH; x++ ) {
-
- for(y = 0; y < HEIGHT; y++ ) {
-
- XFillRectangle(display, win, gc,
- panel_x(x), panel_y(y),
- panel_width,panel_height);
- old_info[x][y] = (char) 5;
- }
- }
- }
-
- if( running ) {
-
- for( y = 0; y < HEIGHT; y++ ) {
-
- for( x = 0; x < WIDTH; x++ )
-
- if (info[x][y] != old_info[x][y]) {
-
- draw_lights((int)info[x][y],y,x);
- old_info[x][y]=info[x][y];
- }
- }
- XFlush(display);
- }
- }
-
-
- void light( value, x, y )
-
- int value;
- int x;
- int y;
-
- {
- int color = colors[ value ];
- if (value == 0) color = black;
-
- XSetForeground( display, gc, color );
- #if 1
- XFillRectangle(display, win, gc, x, y, light_width, light_height);
- #else
- XFillArc( display, win, gc, x, y, light_width, light_height, 0, 360*64);
- #endif
- }
-
- int
- new_light( value)
- int value;
- {
- if (value >= ncolors)
- value = ncolors - 1;
- return value;
- }
-
- void draw_lights( value, x , y )
-
- int value;
- int x;
- int y;
-
- {
- int new = new_light(value);
- light(new, panel_x(x)+loadlight_x, panel_y(y)+loadlight_y);
- }
-
-
-
-
-
-
-
-