Beispiel #1
0
void GFX_C2V_bitBlt(
		    struct Tracker_Windows *tvisual,
		    int from_x1,int from_x2,
		    int to_y
		    ){
  Window window=tvisual->os_visual->window;
  Pixmap cursorpixmap=tvisual->os_visual->cursorpixmap;

  GFX_P_bouncePoints(tvisual->os_visual);

  XCopyArea(
	    x11_display,
	    cursorpixmap,
	    window,
	    DefaultGC(x11_display,x11_screen),
	    from_x1,0,
	    from_x2-from_x1,tvisual->fontheight,
	    from_x1,to_y
	    );	     
F
}
Beispiel #2
0
void GFX_BitBlt(
	struct Tracker_Windows *tvisual,
	int dx,int dy,
	int x,int y,
	int x2,int y2
){
  Pixmap pixmap=tvisual->os_visual->pixmap;

  GFX_P_bouncePoints(tvisual->os_visual);

  XCopyArea(
	    x11_display,
	    pixmap,
	    pixmap,
	    DefaultGC(x11_display,x11_screen),
	    x,y,
	    x2-x+1,y2-y+1,
	    x+dx,y+dy
	    );

}
static gboolean
idle_refresh (gpointer data)
{
    GstV4l2Object *v4l2object = GST_V4L2_OBJECT (data);
    GstV4l2Xv *v4l2xv = v4l2object->xv;
    XWindowAttributes attr;

    if (v4l2xv) {
        g_mutex_lock (v4l2xv->mutex);

        XGetWindowAttributes (v4l2xv->dpy, v4l2object->xwindow_id, &attr);
        XvPutVideo (v4l2xv->dpy, v4l2xv->port, v4l2object->xwindow_id,
                    DefaultGC (v4l2xv->dpy, DefaultScreen (v4l2xv->dpy)),
                    0, 0, attr.width, attr.height, 0, 0, attr.width, attr.height);

        v4l2xv->idle_id = 0;
        g_mutex_unlock (v4l2xv->mutex);
    }

    /* once */
    return FALSE;
}
Beispiel #4
0
void GFX_P2V_bitBlt(
		    struct Tracker_Windows *tvisual,
		    int from_x,int from_y,
		    int to_x,int to_y,
		    int width,int height
		    ){
  Window window=tvisual->os_visual->window;
  Pixmap pixmap=tvisual->os_visual->pixmap;

  GFX_P_bouncePoints(tvisual->os_visual);

  XCopyArea(
	    x11_display,
	    pixmap,
	    window,
	    DefaultGC(x11_display,x11_screen),
	    from_x,from_y,
	    width,height,
	    to_x,to_y
	    );	     
F
}
Beispiel #5
0
void inicjujOkno(){
  mydisplay = XOpenDisplay("");
  myscreen = DefaultScreen(mydisplay);
  myvisual = DefaultVisual(mydisplay,myscreen);
  mydepth = DefaultDepth(mydisplay,myscreen);
  mywindowattributes.background_pixel = XWhitePixel(mydisplay,0);
  mywindowattributes.override_redirect = False;
  mywindow = XCreateWindow(mydisplay,XRootWindow(mydisplay,myscreen),
                      100,100,400,400,10,mydepth,InputOutput,
                      myvisual,CWBackPixel|CWOverrideRedirect,
                      &mywindowattributes);
  XSelectInput(mydisplay,mywindow,ExposureMask|ButtonPressMask|KeyPressMask);
  colorMap = DefaultColormap(mydisplay,myscreen);                 
  XAllocNamedColor(mydisplay,colorMap,"sienna4",&darkBrown,&dummy);
  XAllocNamedColor(mydisplay,colorMap,"WhiteSmoke",&white,&dummy);
  XAllocNamedColor(mydisplay,colorMap,"black",&black,&dummy);
  XAllocNamedColor(mydisplay,colorMap,"chocolate1",&lightBrown,&dummy);
  XStoreName(mydisplay,mywindow,"Wilk i owce");   
  XMapWindow(mydisplay,mywindow);
  mygc = DefaultGC(mydisplay,myscreen);
  
}
Beispiel #6
0
/*
 * Copy raw pixel data to the screen
 */
void
CopyDataToScreen(CARD8 *buf, int x, int y, int width, int height)
{
#if 0
    /* DEBUG */
    printf("CDTS ");
    fflush(stdout);
#endif
    if (rawDelay != 0) {
#if 0
        XFillRectangle(dpy, canvas, DefaultGC(dpy,DefaultScreen(dpy)),
                       x, y, width, height);
#endif
        XSync(dpy,False);
        usleep(rawDelay * 1000);
    }
    if (!useBGR233) {
        GrArea(canvas, gc, x, y, width, height, buf, MWPF_PALETTE);
    } else {
        CopyBGR233ToScreen(buf, x, y, width, height);
    }
}
Beispiel #7
0
//=========================================
// update root window contents
//-----------------------------------------
void RedrawWindow (void) {
	int i;
	int planes = 0;
	for (i=0;i<scr_count;i++) {
		Window root = RootWindow(dpy,i);
		GC mgc = DefaultGC(dpy,i);
		planes = DisplayPlanes (dpy,i);
		if (planes < 8) {
			continue;
		}
		XCopyArea (
			dpy,save[i].bg,root,mgc,0,0,
			save[i].width,save[i].height,save[i].x1,save[i].y1
		);
		if (i > 0) {
		XPutImage (
			dpy,root,mgc,img,0,0,
			imgx,imgy,img->width,img->height
		);
		}
	}
	XFlush(dpy);
}
Beispiel #8
0
void
initdisplay(void) {
	display = XOpenDisplay(nil);
	if(display == nil)
		fatal("Can't open display");
	scr.screen = DefaultScreen(display);
	scr.colormap = DefaultColormap(display, scr.screen);
	scr.visual = DefaultVisual(display, scr.screen);
	scr.gc = DefaultGC(display, scr.screen);
	scr.depth = DefaultDepth(display, scr.screen);

	scr.root.xid = RootWindow(display, scr.screen);
	scr.root.visual = scr.visual;
	scr.root.r = Rect(0, 0,
			  DisplayWidth(display, scr.screen),
			  DisplayHeight(display, scr.screen));
	scr.rect = scr.root.r;

	scr.root.parent = &scr.root;

	scr.xim = XOpenIM(display, nil, nil, nil);

	windowmap.bucket = wbucket;
	windowmap.nhash = nelem(wbucket);
	atommap.bucket = abucket;
	atommap.nhash = nelem(abucket);
	atomnamemap.bucket = anamebucket;
	atomnamemap.nhash = nelem(anamebucket);

	fmtinstall('A', Afmt);
	fmtinstall('L', Lfmt);
	fmtinstall('R', Rfmt);
	fmtinstall('P', Pfmt);
	fmtinstall('W', Wfmt);

	xlib_errorhandler = XSetErrorHandler(errorhandler);
}
Beispiel #9
0
/*
 * Pøipojit k serveru, zjistit o nìm informace
 */
static void open_display(void)
{
    display_name = XDisplayName(NULL);
    if(!(display = XOpenDisplay(display_name))) {
	fprintf(stderr, "Cannot connect to X server \"%s\"\n", display_name);
	exit(1);
    }
    debug("Connected to X server \"%s\"\n", display_name);
    
    screen_num = DefaultScreen(display);
    screen = DefaultScreenOfDisplay(display);
    debug("Default screen number is %d\n", screen_num);
    
    screen_width = DisplayWidth(display, screen_num);
    screen_height = DisplayHeight(display, screen_num);
    screen_width_mm = DisplayWidthMM(display, screen_num);
    screen_height_mm = DisplayHeightMM(display, screen_num);
    debug("Screen size is %ux%u pixels, %ux%u mm\n", screen_width,
	  screen_height, screen_width_mm, screen_height_mm);
    
    root = RootWindow(display, screen_num);
    black = BlackPixel(display, screen_num);
    white = WhitePixel(display, screen_num);
    cmap = DefaultColormap(display, screen_num);
    debug("Root window ID is %#lx, black is %#lx, white is %#lx\n", root,
	  black, white);

    def_gc = DefaultGC(display, screen_num);
    /* Toto volání XQueryFont() do def_font->fid neulo¾í ID fontu, ale
     * grafického kontextu! Nevím, jak získat ID nebo jméno standardního
     * fontu. */
    if(!(def_font = XQueryFont(display, XGContextFromGC(def_gc)))) {
	fprintf(stderr, "XQueryFont() failed\n");
	exit(1);
    }
}
Beispiel #10
0
int main(void)
{
  	Display *d;
  	Window w;
  	char *msg = "Hello, World! AlanTom";
  	int s;
 
 
  	// open connection with the X server
  	d = XOpenDisplay(NULL);
 
 	//get screen_number
  	s = DefaultScreen(d);
 
  	// create a window 
  	w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 640, 480, 0,
                          BlackPixel(d, s), WhitePixel(d, s));
 
  
 	// set title words 
	XStoreName(d, w, "MY WINDOW!!");
 
  	// show the window
  	XMapWindow(d, w);
 
  	while (1) {
		// show string
      	XDrawString(d, w, DefaultGC(d, s), 120, 50, msg, strlen(msg));
    }
 
 
  	// close connection to X server
  	XCloseDisplay(d);
 
  	return 0;
}
Beispiel #11
0
/** Init the graphic context
*/
static void
init_gc(void)
{
     XGCValues gcv;

     /* Bits sequences */
     const char pix_bits[] =
          {
               0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55,
               0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55,
               0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55,
               0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55
          };

     gc = DefaultGC(dpy, SCREEN);

     /* Stipple GC */
     gcv.function   = GXcopy;
     gcv.fill_style = FillStippled;
     gcv.stipple    = XCreateBitmapFromData(dpy, ROOT, pix_bits, 10, 4);
     gc_stipple     = XCreateGC(dpy, ROOT, GCFunction | GCFillStyle | GCStipple, &gcv);

     return;
}
Beispiel #12
0
//=========================================
// XInitDisplay
//-----------------------------------------
XInit XInitDisplay (char *displayname) {
	// ...
	// Open the display and save geometry data and
	// display information about colors, screen, etc.
	// ---
	XInit xi;
	xi.dpy = XOpenDisplay (displayname);
	if (!xi.dpy) {
		fprintf (stderr,
			"xlook: unable to open display %s\n",
			XDisplayName(displayname)
		);
		exit (1);
	}
	xi.DScreen = XDefaultScreen(xi.dpy);
	xi.DMap    = DefaultColormap(xi.dpy,xi.DScreen);
	xi.DWin    = RootWindow (xi.dpy,XDefaultScreen(xi.dpy));
	xi.DGc     = DefaultGC  (xi.dpy,XDefaultScreen(xi.dpy));
	xi.DWidth  = DisplayWidth (xi.dpy,XDefaultScreen(xi.dpy));
	xi.DHeight = DisplayHeight (xi.dpy,XDefaultScreen(xi.dpy));
	xi.DDepth  = DefaultDepth(xi.dpy,xi.DScreen);
	xi.DVisual = DefaultVisual(xi.dpy,xi.DScreen);
	return(xi);
}
Beispiel #13
0
void xskin_start_interface( int pipe_in ) {

  int xskin_sc;
  XEvent xskin_e;
  XSetWindowAttributes xskin_attr;

  XSizeHints xskin_hint;
  XClassHint xskin_chint;
  XTextProperty ct;
  char *namlist[2];


  /* setup window */

  xskin_d     = XOpenDisplay( NULL );
  xskin_sc    = DefaultScreen( xskin_d );
  xskin_r     = RootWindow( xskin_d, xskin_sc );
  xskin_gc    = DefaultGC( xskin_d, xskin_sc );
  xskin_vis   = DefaultVisual( xskin_d, xskin_sc );
  xskin_depth = DefaultDepth( xskin_d, xskin_sc );

  xskin_w = XCreateSimpleWindow( xskin_d, xskin_r, 0, 0,
				 skin_width, skin_height, 0,
				 WhitePixel( xskin_d, xskin_sc ),
				 BlackPixel( xskin_d, xskin_sc ) );

  xskin_attr.backing_store = True;
  xskin_attr.override_redirect = False;
  XChangeWindowAttributes( xskin_d, xskin_w,
			   CWBackingStore|CWOverrideRedirect, &xskin_attr );

  XSelectInput( xskin_d, xskin_w,
		KeyPressMask|ExposureMask|
		EnterWindowMask|LeaveWindowMask|
		ButtonPressMask|ButtonReleaseMask|
		Button1MotionMask );

  xskin_hint.flags = USSize | PMinSize | PMaxSize | USPosition;
  xskin_hint.width = xskin_hint.min_width = xskin_hint.max_width
    = skin_width;
  xskin_hint.height = xskin_hint.min_height = xskin_hint.max_height
    = skin_height;
  XSetNormalHints( xskin_d, xskin_w, &xskin_hint );

  xskin_chint.res_name  = XSKIN_RES_NAME;
  xskin_chint.res_class = XSKIN_RES_CLASS;
  XSetClassHint( xskin_d, xskin_w, &xskin_chint );

  namlist[0]=(char *)safe_malloc(strlen(XSKIN_WINDOW_NAME)+1);
  strcpy( namlist[0], XSKIN_WINDOW_NAME );
  XmbTextListToTextProperty( xskin_d, namlist, 1, XCompoundTextStyle, &ct );
  XSetWMName( xskin_d, xskin_w, &ct );
  XSetWMIconName( xskin_d, xskin_w, &ct );
  free(namlist[0]);


  /* setup pixmaps */

  if ( load_skins()!=0 ) goto finish;

  XSetWindowBackgroundPixmap( xskin_d, xskin_w, xskin_back );
  XClearWindow( xskin_d, xskin_w );

  XMapWindow( xskin_d, xskin_w );
  while( 1 ) {
    XNextEvent( xskin_d, &xskin_e );
    if ( xskin_e.type == Expose ) break; 
  }

  fshuf=0;
  frep=0;
  fequ=1;
  fpll=1;
  fplay=0;
  fpause=0;
  fremain=0;
  play_val=1;
  vol_val=50;
  last_current_time=0;
  total_time=0;
  speana_buf = NULL;
  strcpy( last_text, "welcome to timidity" );

  install_sighandler();

  repaint();
  ts_spectrum( -1, speana_buf );

  XFlush(xskin_d);

  xskin_jobs( pipe_in );   /* tskin main jobs */

finish:
  signal_vector(0);  /* finish */
}
Beispiel #14
0
int main(int argc, char* argv[])
{
    struct timeval begin, now;
    long counter;

    printf("\n -- EYEBOT Viewer -- \n\n");

    // Allocate buffers
    img_buffer = malloc(SIZE * CHANNELS);
    read_buffer = malloc(SIZE + PADDING);

    scaled_up_img = malloc(UP_S * CHANNELS);
    scaled_up_img_dbl = malloc(UP_S * CHANNELS);

    unsigned char b[4096];

    display = XOpenDisplay(NULL);
    visual = DefaultVisual(display, 0);
    
    window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, 320, 300, 1, 0, 0);
    XMapWindow(display, window);
    XFlush(display);

    if(visual->class!=TrueColor)
    {
        fprintf(stderr, "Cannot handle non true color visual ...\n");
        exit(1);
    }

    //XMapWindow(display, window);
    //XFlush(display);

    image = NULL;

    struct addrinfo hints, *res;
    int socket_fd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
    if(socket_fd == -1)
    {
        printf("Could not make a socket\n");
        return 1;
    }

    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_STREAM;
    getaddrinfo(SERVER_HOSTNAME, SERVER_PORT, &hints, &res);

    sleep(1);
    memset(b, 0, sizeof(b));
    sprintf(b, "Eyebot Line Follower - LiveEye");
    XSetForeground(display, DefaultGC(display, 0), 0x00ff0000); // red
    XDrawString(display, window, DefaultGC(display, 0), 10, 20, b, strlen(b));
    
    memset(b, 0, sizeof(b));
    sprintf(b, "Copyright (C) 2013 Andre Christensen and Jacob Pedersen");
    XSetForeground(display, DefaultGC(display, 0), 0x000000EF); // red
    XDrawString(display, window, DefaultGC(display, 0), 10, 35, b, strlen(b));

    XFlush(display);

    while (1)
    {
        printf("Connecting to EYEBOT! (%s:%s)\n", SERVER_HOSTNAME, SERVER_PORT);

        // Connect loop
        while (1)
        {
            if (connect(socket_fd, res->ai_addr, res->ai_addrlen) == -1)
            {
                sleep(1);
            } 
            else
            {
                printf("Connected!\n");
                break;
            }
        }

        // Two seconds of timeout. Useful so that recv doesn't wait 
        // forever to receive all its bytes.
        struct timeval tv;
        tv.tv_sec = 2;  
        tv.tv_usec = 0; 
        setsockopt(socket_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval));

        // Measure time at beginning
        counter = 0;
        gettimeofday(&begin, NULL);

        // Frame update loop
        while (1)
        {
            int bytes_read;
            int total = 0;
            unsigned int x = 0, y = 0, error, error_upper, mass;
            int l_x, l_y, u_x, u_y;

            fd_set fds;
            FD_ZERO(&fds);
            FD_SET(socket_fd, &fds);

            struct timeval timeout;
            timeout.tv_sec = 6 * 60;
            timeout.tv_usec = 0;

            if (select(sizeof(fds) * 8, &fds, NULL, NULL, &timeout) < 0)
            {
                exitp("select()");
            }

            if (read(socket_fd, &l_x, sizeof(l_x)) < 0)
            {
                exitp("read() (error x)");
            }

            if (read(socket_fd, &l_y, sizeof(l_y)) < 0)
            {
                exitp("read() (error y)");
            }

            if (read(socket_fd, &u_x, sizeof(u_x)) < 0)
            {
                exitp("read() (error x)");
            }

            if (read(socket_fd, &u_y, sizeof(u_y)) < 0)
            {
                exitp("read() (error y)");
            }

            if (read(socket_fd, &error, sizeof(error)) < 0)
            {
                exitp("read() (error)");
            }

            if (read(socket_fd, &error_upper, sizeof(error_upper)) < 0)
            {
                exitp("read() (error)");
            }


            if (read(socket_fd, &mass, sizeof(mass)) < 0)
            {
                exitp("read() (error mass)");
            }

            // Clear the read buffer
            memset(read_buffer, 0, SIZE);

            //
            // Read the 76800 bytes a frame consist of
            //
            
            bytes_read = recv(socket_fd, read_buffer, SIZE, MSG_WAITALL);
            if (bytes_read < 0)
            {
                perror("recv");
                break;
            }
            else if (bytes_read == SIZE)
            {
                copy_to_x_buffer(read_buffer, bytes_read);
                draw_center_point(l_x, l_y, 0, 0, 255);
                draw_center_point(u_x, u_y, 0, 255, 0);
                draw_center_lines();

                //upscale_image();

                if (image != NULL)
                {
                    XDestroyImage(image);
                }

                //upscale_image();
                //draw_center_point2(l_x, l_y, 0, 0, 255);
                //draw_center_point2(u_x, u_y, 0, 255, 0);
                //draw_center_lines2();

                //scaled_up_img_dbl = malloc(UP_S * CHANNELS);
                //memcpy(scaled_up_img_dbl, scaled_up_img, UP_S * CHANNELS);


                // Allocate a new buffer for next frame. 
                // The old one is freed by XDestroyImage
                img_disp_buffer = (unsigned char *) malloc(SIZE * CHANNELS);
                memcpy(img_disp_buffer, img_buffer, SIZE * CHANNELS);
                
                image = XCreateImage(display, visual, 24, ZPixmap, 0, img_disp_buffer, 320, 240, 32, 0);
                XPutImage(display, window, DefaultGC(display, 0), image, 0, 0, 0, 0, 320, 240);

                //image = XCreateImage(display, visual, 24, ZPixmap, 0, scaled_up_img_dbl, 640, 480, 32, 0);
                //XPutImage(display, window, DefaultGC(display, 0), image, 0, 0, 0, 0, 640, 480);

                // Clear text area
                XSetForeground(display, DefaultGC(display, 0), 0x00ffffff); 
                XFillRectangle(display, window, DefaultGC(display, 0), 0, 240, 320, 60);

                // memset(b, 0, sizeof(b));
                // sprintf(b, "Center: (%d, %d)", x,y);
                XSetForeground(display, DefaultGC(display, 0), 0x00ff0000); // red
                // XDrawString(display, window, DefaultGC(display, 0), 5, 260, b, strlen(b));

                memset(b, 0, sizeof(b));
                sprintf(b, "Error (upper): %d", error_upper);
                XDrawString(display, window, DefaultGC(display, 0), 5, 250, b, strlen(b));

                memset(b, 0, sizeof(b));
                sprintf(b, "Error (lower): %d", error);
                XDrawString(display, window, DefaultGC(display, 0), 5, 280, b, strlen(b));

                memset(b, 0, sizeof(b));
                sprintf(b, "Mass: %d", mass);
                XDrawString(display, window, DefaultGC(display, 0), 150, 250, b, strlen(b));


                // Calculate and display fps
                gettimeofday(&now, NULL);
                double  elapsed = (now.tv_sec - begin.tv_sec) * 1000.0;
                elapsed += (now.tv_usec - begin.tv_usec) / 1000.0;
                elapsed /= 1000.0;
                memset(b, 0, sizeof(b));
                sprintf(b, "FPS: %.2f", ((counter / elapsed) * 3));
                XDrawString(display, window, DefaultGC(display, 0), 150, 280, b, strlen(b));

                counter++;
            }
            else
            {   
                printf("Connection lost - retrying!\n");
                close(socket_fd);
                break;
            }
        }
    }

	printf("Closing the socket\n");
    if(close(socket_fd) == -1)
    {
    	printf("Could not close socket\n");
     	return 0;
    }
}
Beispiel #15
0
int wyswietl(circle *circles, int id) {
   mydisplay = XOpenDisplay("");
   myscreen = DefaultScreen(mydisplay);
   myvisual = DefaultVisual(mydisplay,myscreen);
   mydepth = DefaultDepth(mydisplay,myscreen);
   mywindowattributes.background_pixel = XWhitePixel(mydisplay,myscreen);
   mywindowattributes.override_redirect = False;
   mywindowattributes.backing_store = Always;
   mywindowattributes.bit_gravity = NorthWestGravity;
   mywindow = XCreateWindow(mydisplay,XRootWindow(mydisplay,myscreen),
                            100,100,600,600,10,mydepth,InputOutput,
                            myvisual,CWBackingStore|CWBackingPlanes|CWBitGravity|
                            CWBackPixel|CWOverrideRedirect,&mywindowattributes);
   XSelectInput(mydisplay,mywindow,ExposureMask|KeyPressMask|KeyReleaseMask|ButtonPressMask|ButtonMotionMask);
   mycolormap = DefaultColormap(mydisplay,myscreen);
         XAllocNamedColor(mydisplay,mycolormap,"blue",&mycolor,&dummy);
         XAllocNamedColor(mydisplay,mycolormap,"white",&mycolor1,&dummy);
         XAllocNamedColor(mydisplay,mycolormap,"black",&mycolor2,&dummy);
	 XAllocNamedColor(mydisplay,mycolormap,"red",&mycolor3,&dummy);
         myname="Berek";
   XStoreName(mydisplay,mywindow,myname);
   XMapWindow(mydisplay,mywindow);
   mygc = DefaultGC(mydisplay,myscreen);
   while (1)
   {
	   if(XPending(mydisplay) > 0) {
		  XNextEvent(mydisplay,&myevent);
		  switch (myevent.type)
		  {
			 case Expose:
				  XSetFunction(mydisplay,mygc,GXcopy);
pokaz_wszystkich(circles, id);
if(circles[id].czy_berek == true) { XSetForeground(mydisplay,mygc,mycolor3.pixel); }
				  else { XSetForeground(mydisplay,mygc,mycolor.pixel); }
				  circles[id].x = 100;
				  circles[id].y = 100;
				  circles[id].size = 60;
//				  pokaz_wszystkich(circles, id);
				  XFillArc(mydisplay, mywindow, mygc, circles[id].x, circles[id].y, circles[id].size, circles[id].size, 0, 360*64);
				  //pokaz_wszystkich(circles, id);
//int i; for(i=0; i<6; i++) {printf("%d %d %d\n", circles[i].ID, circles[i].x, circles[i].y); }
				  XFlush(mydisplay);
				  break;

			  case KeyPress:
//				  printf("%x\n", myevent.xkey.keycode);
				  //EXIT
XSetForeground(mydisplay, mygc, mycolor1.pixel);
XFillRectangle(mydisplay, mywindow, mygc, 0, 0, 600, 600);
sprawdz(circles, id);
				  pokaz_wszystkich(circles, id);
				  if(myevent.xkey.keycode == 0x09) {
					  XCloseDisplay(mydisplay);
					  shmdt(adres);
					  shmctl(pamiec, IPC_RMID, NULL);
					  exit(0);
				  }
				  //UP
				  if(myevent.xkey.keycode == 0x62) {//0x62) {
					  sprawdz(circles, id);
					  XSetForeground(mydisplay,mygc,mycolor1.pixel);
					  XFillArc(mydisplay, mywindow, mygc, circles[id].x, circles[id].y, circles[id].size, circles[id].size, 0, 360*64);
					  if(circles[id].czy_berek == true) { XSetForeground(mydisplay,mygc,mycolor3.pixel); }
					  else {XSetForeground(mydisplay,mygc,mycolor.pixel); }
					  circles[id].y -= 5;
					  XFillArc(mydisplay, mywindow, mygc, circles[id].x, circles[id].y, circles[id].size, circles[id].size, 0, 360*64);
					  XFlush(mydisplay);
				  }
				  //RIGHT
				  if(myevent.xkey.keycode == 0x66) {//0x66) {
					  sprawdz(circles, id);
					  XSetForeground(mydisplay,mygc,mycolor1.pixel);
					  XFillArc(mydisplay, mywindow, mygc, circles[id].x, circles[id].y, circles[id].size, circles[id].size, 0, 360*64);
					  if(circles[id].czy_berek == true) { XSetForeground(mydisplay,mygc,mycolor3.pixel); }
					  else {XSetForeground(mydisplay,mygc,mycolor.pixel); }
					  circles[id].x += 5;
					  XFillArc(mydisplay, mywindow, mygc, circles[id].x, circles[id].y, circles[id].size, circles[id].size, 0, 360*64);
					  XFlush(mydisplay);
				  }
				  //LEFT
				  if(myevent.xkey.keycode == 0x64) {//0x64) {
					  sprawdz(circles, id);
					  XSetForeground(mydisplay,mygc,mycolor1.pixel);
					  XFillArc(mydisplay, mywindow, mygc, circles[id].x, circles[id].y, circles[id].size, circles[id].size, 0, 360*64);
					  if(circles[id].czy_berek == true) { XSetForeground(mydisplay,mygc,mycolor3.pixel); }
					  else {XSetForeground(mydisplay,mygc,mycolor.pixel); }
					  circles[id].x -= 5;
					  XFillArc(mydisplay, mywindow, mygc, circles[id].x, circles[id].y, circles[id].size, circles[id].size, 0, 360*64);
					  XFlush(mydisplay);
				  }
				  //DOWN
				  if(myevent.xkey.keycode == 0x68) {//0x68) {
					  sprawdz(circles, id);
					  XSetForeground(mydisplay,mygc,mycolor1.pixel);
					  XFillArc(mydisplay, mywindow, mygc, circles[id].x, circles[id].y, circles[id].size, circles[id].size, 0, 360*64);
					  if(circles[id].czy_berek == true) { XSetForeground(mydisplay,mygc,mycolor3.pixel); }
					  else {XSetForeground(mydisplay,mygc,mycolor.pixel); }
					  circles[id].y += 5;
					  XFillArc(mydisplay, mywindow, mygc, circles[id].x, circles[id].y, circles[id].size, circles[id].size, 0, 360*64);
					  XFlush(mydisplay);
				  }
			  break;
		}
	}
  }
}
Beispiel #16
0
int main(void)
{
	Display *d;
	Window w;
	XEvent e;
	XWindowAttributes attr;

	int s;


	float x_max, y_max;

	int w_, h_,  delt;

	int i;
	int id1, id2, id3;
//	float kx, ky, kx_0, ky_0, kxa, kya, x, y;
	float kx, ky, kxa, kya, x, y;
	int fl =0;
	int fl1=0;
	int fl2=0;

	int flagg=0;
	FILE *file;
    file=fopen("data.txt","r");


	srand(time(NULL));

	

	if(flagg==1)
	{


	}

	if ( (file=fopen("data.txt", "r")) == NULL)
	{

		return -1;
	}

	/*N=0;
	while (fscanf(file, "%d %d", &i, &j) == 2)
		N++;
	fseek(file, 0L, SEEK_SET);
	* */

	 printf("[PIXEL DATA]\n");
	 /*
	point=(Point*)malloc(N*sizeof(Point));
	for (i=0; i<N; i++)
	{
		fscanf(file, "%f %f", &point[i].x, &point[i].y);
		printf("x, y = %f %f\n", point[i].x, point[i].y);
	}*/
	
	while (fscanf(file, "%f %f", &x, &y) ==2)
		AddPoint(x, y);
	
	printf("N=%d\n", N);
	if (N==0)
	{
		printf("N=0\n");
		exit(0);
	}	
	


	fclose(file);
	
	
/*
	x_min=point[0].x;
	y_min=point[0].y;

	x_max=point[0].x;
	y_max=point[0].y;

	for (i=0; i<N; i++)
	{
		if (point[i].x - x_min < eps)
			x_min=point[i].x;

		if (point[i].y - y_min < eps)
			y_min=point[i].y;

		if (point[i].x - x_max > eps)
			x_max=point[i].x;

		if (point[i].y - y_max > eps)
			y_max=point[i].y;
	}


	printf("\nxmin, ymin = %f %f\n", x_min, y_min);
	printf("xmax, ymax = %f %f\n", x_max, y_max);

	kx_0=float(x_max/x_min);
	ky_0=float(y_max/y_min);

	printf("kx_0, ky_0 = %f %f\n\n", kx_0, ky_0);

    int a,b,c;
    int t=0,q=1,g=2;
    float minn;
	id1=id2=id3=0;
	max=cos(point[0], point[1], point[2]);
	for (i=t; i<N; i++)
	{
		for(j=q;j<N; j++)
		{
			for (k=g;k<N; k++)
			{
			    minn=dist(point[i],point[j]);
			    a=i;b=k;c=j;
			    id1=a; id2=b; id3=c;
			    if((minn-dist(point[i],point[k]))>0)
			    {
                    a=i;b=j;c=k;
			    }
			    if((minn-dist(point[k],point[j]))>0)
			    {
                    a=j;b=i;c=k;
			    }

                if (((cos(point[a], point[b], point[c])-max)  > eps) && (cos(point[a], point[b], point[c])-1>eps))
                {
                    max=cos(point[a], point[b], point[c]);
                    id1=a; id2=b; id3=c;
                    printf("cos=%f\n",cos(point[a], point[b], point[c]));
                    printf("i=%d,j=%d,k=%d\n",id1,id2,id3);
                }
                g++;
			}
			printf("i=%d,j=%d,k=%d\n",id1,id2,id3);
			q++;
		}
		i++;
		}*/

	w_=w0;
	h_=h0;
	
	
	
	refresh(&x_max, &y_max, &id1, &id2, &id3);

	kx=float(w_ / x_max);
	ky=float(h_ / y_max);

	printf("kx, ky = %f, %f\n", kx, ky);

	if ((d = XOpenDisplay(getenv("DISPLAY"))) == NULL) {
			exit(1);
	}

	s = DefaultScreen(d);


	w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, w0, h0, 1,
							   BlackPixel(d, s), WhitePixel(d, s));


	XSelectInput(d, w, ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask );


	XMapWindow(d, w);

	kxa=kya=1;
	while (1)
	{
			XGetWindowAttributes(d, w, &attr);
			w_=attr.width;
			h_=attr.height;
			kx=float(w_ / x_max);
			ky=float(h_ / y_max);

		XNextEvent(d, &e);



		if (e.type==ButtonPress)
		{
			printf("Button Press\n");

			ButPress(10,10,e.xbutton.x,e.xbutton.y,&fl);
			ButPress(10,50,e.xbutton.x,e.xbutton.y,&fl1);
			ButPress(10,90,e.xbutton.x,e.xbutton.y,&fl2);
			if(fl==1||fl1==1||fl2==1)
			{
				printf("fl=%d, fl1=%d, fl2=%d\n", fl, fl1, fl2);
				if(fl==1)
				{
					kxa=kxa-0.02;
					printf("KX ----- %f\n", kxa);
					printf("BUTTON 1\n");
				}
				if(fl1==1)
				{
					kxa=kxa+0.02;
					printf("KX +++++ %f\n", kxa);
					printf("BUTTON 2\n");
				}
				if(fl2==1)
				{
					AddPoint(10, 50);
					refresh(&x_max, &y_max, &id1, &id2, &id3);
				}
			}

		}

		if (e.type==ButtonRelease)
		{
			printf("Button Release\n\n");
			fl=fl2=fl1=0;
			XClearArea(d,w,0,0,attr.width,attr.height,1);
			XEvent ev;
			ev.type=Expose;
			XSendEvent(d,w,1,0,&ev);
		}


		if (e.type == Expose)
		{


			if (kx>ky)
				kx=ky;
			else
				ky=kx;

			kx*=kxa;
			ky*=kya;
			
			printf("kx = %f ky = %f\n", kx, ky);

			if (w_ > h_)
				delt=h_;
			else
				delt=w_;


			DrawButton( d,w,DefaultGC(d, s),10,10,s,fl);
    	    DrawButton( d,w,DefaultGC(d, s),10,50,s,fl1);
    	    DrawButton( d,w,DefaultGC(d, s),10,90,s,fl2);


			for (i=0; i<N; i++)
			XFillRectangle(d, w, DefaultGC(d, s), kx*point[i].x - delt/coef, ky*point[i].y - delt/coef, delt/(coef/2), delt/(coef/2));

			XDrawLine(d, w, DefaultGC(d, s), kx*point[id1].x, ky*point[id1].y, kx*point[id2].x, ky*point[id2].y);
			XDrawLine(d, w, DefaultGC(d, s), kx*point[id2].x, ky*point[id2].y, kx*point[id3].x, ky*point[id3].y);
			XDrawLine(d, w, DefaultGC(d, s), kx*point[id3].x, ky*point[id3].y, kx*point[id1].x, ky*point[id1].y);

		}
		if (e.type == KeyPress)
			break;
  }


	XCloseDisplay(d);

	if (point)
		free(point);

	return 0;
}
Beispiel #17
0
void wsCreateWindow(wsTWindow *win, int X, int Y, int wX, int hY, int bW, int cV, unsigned char D, char *label)
{
    int depth;

    win->Property = D;

    if (D & wsShowFrame)
        win->Decorations = 1;

    wsHGC = DefaultGC(wsDisplay, wsScreen);

// The window position and size.
    switch (X) {
    case -1:
        win->X = (wsMaxX / 2) - (wX / 2) + wsOrgX;
        break;

    case -2:
        win->X = wsMaxX - wX - 1 + wsOrgX;
        break;

    default:
        win->X = X;
        break;
    }

    switch (Y) {
    case -1:
        win->Y = (wsMaxY / 2) - (hY / 2) + wsOrgY;
        break;

    case -2:
        win->Y = wsMaxY - hY - 1 + wsOrgY;
        break;

    default:
        win->Y = Y;
        break;
    }

    win->Width     = wX;
    win->Height    = hY;
    win->OldX      = win->X;
    win->OldY      = win->Y;
    win->OldWidth  = win->Width;
    win->OldHeight = win->Height;

// Border size for window.
    win->BorderWidth = bW;
// Hide Mouse Cursor
    win->wsCursor = None;
    win->wsMouseEventType = cV;
    win->wsCursorData[0]  = 0;
    win->wsCursorPixmap   = XCreateBitmapFromData(wsDisplay, wsRootWin, win->wsCursorData, 1, 1);

    if (!(cV & wsShowMouseCursor))
        win->wsCursor = XCreatePixmapCursor(wsDisplay, win->wsCursorPixmap, win->wsCursorPixmap, &win->wsColor, &win->wsColor, 0, 0);

    depth = vo_find_depth_from_visuals(wsDisplay, wsScreen, NULL);

    if (depth < 15) {
        mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ColorDepthTooLow);
        guiExit(EXIT_ERROR);
    }

    XMatchVisualInfo(wsDisplay, wsScreen, depth, TrueColor, &win->VisualInfo);

// ---
    win->AtomLeaderClient = XInternAtom(wsDisplay, "WM_CLIENT_LEADER", False);
    win->AtomDeleteWindow = XInternAtom(wsDisplay, "WM_DELETE_WINDOW", False);
    win->AtomTakeFocus    = XInternAtom(wsDisplay, "WM_TAKE_FOCUS", False);
    win->AtomRolle         = XInternAtom(wsDisplay, "WM_WINDOW_ROLE", False);
    win->AtomWMSizeHint    = XInternAtom(wsDisplay, "WM_SIZE_HINT", False);
    win->AtomWMNormalHint  = XInternAtom(wsDisplay, "WM_NORMAL_HINT", False);
    win->AtomProtocols     = XInternAtom(wsDisplay, "WM_PROTOCOLS", False);
    win->AtomsProtocols[0] = win->AtomDeleteWindow;
    win->AtomsProtocols[1] = win->AtomTakeFocus;
    win->AtomsProtocols[2] = win->AtomRolle;
// ---

    win->WindowAttrib.background_pixel = BlackPixel(wsDisplay, wsScreen);
    win->WindowAttrib.border_pixel     = WhitePixel(wsDisplay, wsScreen);
    win->WindowAttrib.colormap   = XCreateColormap(wsDisplay, wsRootWin, win->VisualInfo.visual, AllocNone);
    win->WindowAttrib.event_mask = StructureNotifyMask | FocusChangeMask |
                                   ExposureMask | PropertyChangeMask |
                                   EnterWindowMask | LeaveWindowMask |
                                   VisibilityChangeMask |
                                   KeyPressMask | KeyReleaseMask;

    if ((cV & wsHandleMouseButton))
        win->WindowAttrib.event_mask |= ButtonPressMask | ButtonReleaseMask;

    if ((cV & wsHandleMouseMove))
        win->WindowAttrib.event_mask |= PointerMotionMask;

    win->WindowAttrib.cursor = win->wsCursor;
    win->WindowAttrib.override_redirect = False;

    if (D & wsOverredirect)
        win->WindowAttrib.override_redirect = True;

    win->WindowMask = CWBackPixel | CWBorderPixel |
                      CWColormap | CWEventMask | CWCursor |
                      CWOverrideRedirect;

    win->WindowID = XCreateWindow(wsDisplay,
                                  (win->Parent != 0 ? win->Parent : wsRootWin),
                                  win->X, win->Y, win->Width, win->Height, win->BorderWidth,
                                  win->VisualInfo.depth,
                                  InputOutput,
                                  win->VisualInfo.visual,
                                  win->WindowMask, &win->WindowAttrib);

    wsClassHint.res_name = "MPlayer";

    wsClassHint.res_class = "MPlayer";
    XSetClassHint(wsDisplay, win->WindowID, &wsClassHint);

    win->SizeHint.flags  = PPosition | PSize | PResizeInc | PWinGravity; // | PBaseSize;
    win->SizeHint.x      = win->X;
    win->SizeHint.y      = win->Y;
    win->SizeHint.width  = win->Width;
    win->SizeHint.height = win->Height;

    if (D & wsMinSize) {
        win->SizeHint.flags     |= PMinSize;
        win->SizeHint.min_width  = win->Width;
        win->SizeHint.min_height = win->Height;
    }

    if (D & wsMaxSize) {
        win->SizeHint.flags     |= PMaxSize;
        win->SizeHint.max_width  = win->Width;
        win->SizeHint.max_height = win->Height;
    }

    win->SizeHint.height_inc  = 1;
    win->SizeHint.width_inc   = 1;
    win->SizeHint.base_width  = win->Width;
    win->SizeHint.base_height = win->Height;
    win->SizeHint.win_gravity = StaticGravity;
    XSetWMNormalHints(wsDisplay, win->WindowID, &win->SizeHint);

    win->WMHints.flags = InputHint | StateHint;
    win->WMHints.input = True;
    win->WMHints.initial_state = NormalState;
    XSetWMHints(wsDisplay, win->WindowID, &win->WMHints);

    wsWindowDecoration(win, win->Decorations);
    XStoreName(wsDisplay, win->WindowID, label);
    XmbSetWMProperties(wsDisplay, win->WindowID, label, label, NULL, 0, NULL, NULL, NULL);

    XSetWMProtocols(wsDisplay, win->WindowID, win->AtomsProtocols, 3);
    XChangeProperty(wsDisplay, win->WindowID,
                    win->AtomLeaderClient,
                    XA_WINDOW, 32, PropModeReplace,
                    (unsigned char *)&LeaderWindow, 1);

    wsTextProperty.value    = label;
    wsTextProperty.encoding = XA_STRING;
    wsTextProperty.format   = 8;
    wsTextProperty.nitems   = strlen(label);
    XSetWMIconName(wsDisplay, win->WindowID, &wsTextProperty);

    win->wGC = XCreateGC(wsDisplay, win->WindowID,
                         GCForeground | GCBackground,
                         &win->wGCV);

    win->Visible = 0;
    win->Focused = 0;
    win->Mapped  = 0;
    win->Rolled  = 0;

    if (D & wsShowWindow)
        XMapWindow(wsDisplay, win->WindowID);

    wsCreateImage(win, win->Width, win->Height);
// --- End of creating --------------------------------------------------------------------------

    {
        int i;

        for (i = 0; i < wsWLCount; i++)
            if (wsWindowList[i] == NULL)
                break;

        if (i == wsWLCount) {
            mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_TooManyOpenWindows);
            guiExit(EXIT_ERROR);
        }

        wsWindowList[i] = win;
    }

    XFlush(wsDisplay);
    XSync(wsDisplay, False);

    win->ReDraw       = NULL;
    win->ReSize       = NULL;
    win->Idle         = NULL;
    win->MouseHandler = NULL;
    win->KeyHandler   = NULL;
    mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[ws] window is created. ( %s ).\n", label);
}
Beispiel #18
0
Pixmap xskin_loadBMP( Display *d, Window w, char *filename,
		int *width, int *height ) {

  Pixmap ret=0;
  BMPHeader *bmp;
  struct timidity_file *fp;

  GC gc;

  if ( width!=NULL )
    *width=-1;
  if ( height!=NULL )
    *height=-1;

  sc   = DefaultScreen( d );
  gc   = DefaultGC( d, sc );
  cmap = DefaultColormap( d, sc );

  rshift = 15-highbit(xskin_vis->red_mask);
  gshift = 15-highbit(xskin_vis->green_mask);
  bshift = 15-highbit(xskin_vis->blue_mask);

  fp = open_file( filename, 1, OF_SILENT );
  if ( fp == NULL ) return ret;
  if ( fp->url->url_tell == NULL ) {
    fp->url = url_buff_open( fp->url, 1 );
  }

  bmp = loadBMPHeader( fp );
  if ( bmp==NULL ) goto finish1;

  if ( !loadBMPColors( d, bmp, fp ) ) goto finish1;

  ret = XCreatePixmap( d, w, bmp->w, bmp->h, xskin_depth );
  XSetForeground( d, gc, 0 );
  XFillRectangle( d, ret, gc, 0, 0, bmp->w, bmp->h );
  XSetForeground( d, gc, WhitePixel( d, sc ));

  switch( bmp->bitcounts ) {
  case 4:
    if ( bmp->compress == 0 )
      Draw4bit( d, ret, gc, bmp, fp );
    else if ( bmp->compress == 2 )
      DrawCompressed4bit( d, ret, gc, bmp, fp );
    break;
  case 8:
    if ( bmp->compress == 0 )
      Draw8bit( d, ret, gc, bmp, fp );
    else if ( bmp->compress == 1 )
      DrawCompressed8bit( d, ret, gc, bmp, fp );
    break;
  case 24:
    Draw24bit( d, ret, gc, bmp, fp );
    break;
  default:
    break;
  }

  if ( width!=NULL )
    *width = bmp->w;
  if ( height!=NULL )
    *height = bmp->h;

finish1:
  close_file( fp );
  return ret;
}
Beispiel #19
0
gboolean
myDisplayTestXrender (DisplayInfo *display, gdouble min_time)
{
#ifdef HAVE_RENDER
    GTimeVal t1, t2;
    gdouble dt;
    Display *dpy;
    Picture picture1, picture2, picture3;
    XRenderPictFormat *format_src, *format_dst;
    Pixmap fillPixmap, rootPixmap;
    XRenderPictureAttributes pa;
    XSetWindowAttributes attrs;
    XImage *ximage;
    Window output;
    XRenderColor c;
    Visual *visual;
    Screen *screen;
    int x, y, w, h;
    int screen_number;
    int depth;
    int iterations;

    g_return_val_if_fail (display != NULL, FALSE);
    TRACE ("entering myDisplayTesxrender");

    c.alpha = 0x7FFF;
    c.red   = 0xFFFF;
    c.green = 0xFFFF;
    c.blue  = 0xFFFF;

    dpy = display->dpy;
    screen_number = DefaultScreen (dpy);
    screen = DefaultScreenOfDisplay (dpy);
    visual = DefaultVisual (dpy, screen_number);
    depth = DefaultDepth (dpy, screen_number);

    w = WidthOfScreen(screen) / 16;
    h = HeightOfScreen(screen) / 16;
    x = (WidthOfScreen(screen) - w);
    y = (HeightOfScreen(screen) - h);

    format_dst = XRenderFindVisualFormat (dpy, visual);
    g_return_val_if_fail (format_dst != NULL , FALSE);

    format_src = XRenderFindStandardFormat (dpy, PictStandardA8);
    g_return_val_if_fail (format_src != NULL , FALSE);

    ximage = XGetImage (dpy,
                        DefaultRootWindow(dpy),
                        x, y, w, h,
                        AllPlanes, ZPixmap);
    g_return_val_if_fail (ximage != NULL , FALSE);

    rootPixmap = XCreatePixmap (dpy,
                                DefaultRootWindow(dpy),
                                w, h, depth);
    XPutImage (dpy, rootPixmap,
               DefaultGC (dpy, screen_number), ximage,
               0, 0, 0, 0, w, h);
    XDestroyImage (ximage);

    attrs.override_redirect = TRUE;
    output = XCreateWindow (dpy,
                            DefaultRootWindow(dpy),
                            x, y, w, h,
                            0, CopyFromParent, CopyFromParent,
                            (Visual *) CopyFromParent,
                            CWOverrideRedirect, &attrs);
    XMapRaised (dpy, output);

    fillPixmap = XCreatePixmap (dpy,
                                DefaultRootWindow(dpy),
                                1, 1, 8);

    g_get_current_time (&t1);

    pa.repeat = TRUE;
    picture1 = XRenderCreatePicture (dpy,
                                     rootPixmap,
                                     format_dst, 0, NULL);
    picture2 = XRenderCreatePicture (dpy,
                                     fillPixmap,
                                     format_src, CPRepeat, &pa);
    picture3 = XRenderCreatePicture (dpy,
                                     output,
                                     format_dst, 0, NULL);
    XRenderComposite (dpy, PictOpSrc,
                    picture1, None, picture3,
                    0, 0, 0, 0, 0, 0, w, h);
    XRenderFillRectangle (dpy, PictOpSrc,
                          picture2, &c, 0, 0,
                          1, 1);
    for (iterations = 0; iterations < 10; iterations++)
    {
        XRenderComposite (dpy, PictOpOver,
                        picture1, picture2, picture3,
                        0, 0, 0, 0, 0, 0, w, h);
        ximage = XGetImage (dpy, output,
                            0, 0, 1, 1,
                            AllPlanes, ZPixmap);
        if (ximage)
        {
                XDestroyImage (ximage);
        }
    }
    XRenderFreePicture (dpy, picture1);
    XRenderFreePicture (dpy, picture2);
    XRenderFreePicture (dpy, picture3);

    XFreePixmap (dpy, fillPixmap);
    XFreePixmap (dpy, rootPixmap);

    XDestroyWindow (dpy, output);

    g_get_current_time (&t2);

    dt = (gdouble) (t2.tv_sec - t1.tv_sec) * G_USEC_PER_SEC +
         (gdouble) (t2.tv_usec - t1.tv_usec) / 1000.0;

    if (dt < min_time)
    {
        TRACE ("XRender test passed (target %3.4f sec., measured %3.4f sec.).", min_time, dt);
        return TRUE;
    }
    g_print ("XRender test failed (target %3.4f sec., measured %3.4f sec.).\n", min_time, dt);
    return FALSE;
#else  /* HAVE_RENDER */
    return FALSE;
#endif /* HAVE_RENDER */
}
Beispiel #20
0
int main(int argc,char *argv[]) {
 XSetWindowAttributes xswa;
 XWindowAttributes wattr;
 char *displayname = NULL;
 unsigned long mask = 0;
 Display *dpy;
 Window root;
 Window win;
 GC mgc;
 Visual vis;
 int c;
 int x1     = 0;
 int y1     = 0;
 int depth;
 int width  = 0;
 int height = 0;
 Pixmap bg;

 // get options...
 // ---------------
 while (1) {
  int option_index = 0;
  static struct option long_options[] =
  {
   {"display"    , 1 , 0 , 'd'},
   {"x1"         , 1 , 0 , 'x'},
   {"y1"         , 1 , 0 , 'y'},
   {"width"      , 1 , 0 , 'w'},
   {"height"     , 1 , 0 , 'e'},
   {"help"       , 0 , 0 , 'h'},
   {0            , 0 , 0 , 0  }
  };

  c = getopt_long (argc, argv, "hd:x:y:w:e:",long_options, &option_index);
  if (c == -1)
   break;

  switch (c) {
    case 0:
     break;

    case 'h':
     usage();

    case 'd':
     displayname = (char*)malloc(80*sizeof(char));
     strcpy(displayname,optarg);
     break;

    case 'x':
     x1 = atoi(optarg);
     break;

    case 'y':
     y1 = atoi(optarg);
     break;

    case 'w':
     width = atoi(optarg);
     break;

    case 'e':
     height = atoi(optarg);
     break;

    default:
     /*fprintf (stderr,"?? getopt returned character code 0%o ??\n", c);*/
     usage();
     exit(1);
  }
 }

 // open display...
 // -----------------
 dpy = XOpenDisplay (displayname);
 if (!dpy) {
  fprintf (stderr, "unable to open display %s\n", XDisplayName(displayname));
  exit (1);
 }

 // get screen dimensions...
 // --------------------------
 if (width <= 0) {
  width = DisplayWidth(dpy,XDefaultScreen(dpy));
 }
 if (height <= 0) {
  height = DisplayHeight(dpy,XDefaultScreen(dpy));
 }

 // get root window and default context
 // ------------------------------------
 root  = RootWindow  (dpy,XDefaultScreen(dpy));
 mgc   = DefaultGC   (dpy,XDefaultScreen(dpy));
 depth = DefaultDepth(dpy,XDefaultScreen(dpy));

 xswa.event_mask        = EnterWindowMask | 
  LeaveWindowMask         | 
  ExposureMask            | 
  VisibilityChangeMask    | 
  StructureNotifyMask     | 
  SubstructureNotifyMask  | 
  SubstructureRedirectMask
 ; 
 xswa.background_pixmap = None;
 xswa.override_redirect = True;
 xswa.backing_store     = NotUseful;
 xswa.save_under        = False;
 vis.visualid           = CopyFromParent;
 mask  |= (
  CWBackPixmap   |
  CWOverrideRedirect |
  CWBackingStore |
  CWSaveUnder
 );

 // create windows (top,bottom,left,right)...
 // ---------------------------------------------
 win = XCreateWindow(
  dpy,root,x1,y1,width,height,0,depth,InputOutput,&vis,mask,&xswa
 );
 XMapWindow(dpy,win);
 bg = XCreatePixmap(dpy,win,width,height,depth);
 XCopyArea(dpy,win,bg,mgc,0,0,width,height,0,0);
 XFlush(dpy);

 XGetWindowAttributes(dpy, win, &wattr);
 if (wattr.all_event_masks & ButtonPressMask) {
  xswa.event_mask &= ~ButtonPressMask;
 }
 xswa.event_mask &= ~SubstructureRedirectMask;
 XSelectInput(dpy, win, xswa.event_mask);

 while(1) {
  XEvent event;
  XNextEvent (dpy, &event);
  switch (event.type) {
   case Expose:
    XCopyArea(dpy,bg,win,mgc,0,0,width,height,0,0);
    break;
  }
 }

 // flush and close...
 // -------------------
 XCloseDisplay(dpy);
}
Beispiel #21
0
void display_image() { 
   Display *d;
   int s;
   Window w;
   XEvent e;
 
                        /* open connection with the server */
   d=XOpenDisplay(NULL);
   if(d==NULL) {
     printf("Cannot open display\n");
     exit(1);
   }
   s=DefaultScreen(d);
 





   Visual * vis;
   vis = DefaultVisual(d,s);

   char * dImage = (char *)malloc(sizeof(png_byte) * height);
  
   XImage * image = XCreateImage(d,vis, bit_depth, ZPixmap, 0, dImage, width, height, 16, 0);

  

   //  XCreatePixmap(d, DefaultRootWindow(display),width, height, depth);
   //gc = XCreateGC(display, pixmap, 0, &gcv);

   //XPutImage(display, pixmap, gc, image, 0,0,0,0,width, height);
   
   /* create window */
   w=XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1,
                         BlackPixel(d, s), WhitePixel(d, s));



   // Process Window Close Event through event handler so XNextEvent does Not fail
        Atom delWindow = XInternAtom( d, "WM_DELETE_WINDOW", 0 );
        XSetWMProtocols(d , w, &delWindow, 1);
 
                        /* select kind of events we are interested in */
   XSelectInput(d, w, ExposureMask | KeyPressMask);
 
                        /* map (show) the window */
   XMapWindow(d, w);
 
                        /* event loop */
   while(1) {
     XNextEvent(d, &e);
                        /* draw or redraw the window */
     if(e.type==Expose) {
       XFillRectangle(d, w, DefaultGC(d, s), 20, 20, 10, 10);
     }
                        /* exit on key press */
     if(e.type==KeyPress)
       break;
 
     // Handle Windows Close Event
     if(e.type==ClientMessage)
        break;
   }
 
                        /* destroy our window */
   XDestroyWindow(d, w);
 
                        /* close connection to server */
   XCloseDisplay(d);
 

}
Beispiel #22
0
static int
win_open (const GEN_PAR * pg, char *title, int x, int y, int w, int h)
{
  char *DisplayName = NULL;
  char **argv;
  XSizeHints Hints;
  unsigned long ValueMask;
  XSetWindowAttributes WinAttr;
  XEvent Event;
  char colorname[13];
  int i;

	/**
	 ** Simulate command line arguments
	 **/

  argv = (char **) malloc (3 * sizeof (char *));
  argv[0] = PROG_NAME;
  argv[1] = title;
  argv[2] = NULL;

	/**
	 ** X11 server reachable ?
	 **/

  if ((XDisplay = (Display *) XOpenDisplay (DisplayName)) == NULL)
    {
      Eprintf ("No X11 server found !\n");
      return NO_SERVER;
    }



  XScreen = DefaultScreen (XDisplay);
  XRoot = RootWindow (XDisplay, XScreen);
  XVisual = DefaultVisual (XDisplay, XScreen);
  XGcWin = DefaultGC (XDisplay, XScreen);

  scr_width = WidthOfScreen (ScreenOfDisplay (XDisplay, XScreen));
  scr_height = HeightOfScreen (ScreenOfDisplay (XDisplay, XScreen));
  if (x + w > scr_width || y + h > scr_height)
    {
  if (!pg->quiet)
      Eprintf ("Window exceeds screen limits, use mouse button 1 to pan\n");
      w = MIN (w, scr_width);
      h = MIN (h, scr_height);
      oversized = 1;
/*		return SIZE;*/
    }

	/**
	 ** Set window attributes
	 **/

  WinAttr.background_pixel = WhitePixel (XDisplay, XScreen);
  WinAttr.border_pixel = WhitePixel (XDisplay, XScreen);
  WinAttr.backing_store = Always;
  ValueMask = CWBackPixel | CWBorderPixel | CWBackingStore;

	/**
	 ** Create Window
	 **/

  XWin = XCreateWindow (XDisplay, XRoot,
			x, y, w, h,
			1, 0,
			CopyFromParent, CopyFromParent, ValueMask, &WinAttr);

	/**
	 ** Define window properties
	 **/

  Hints.flags = PSize | PMinSize | PMaxSize | USPosition;
  Hints.x = x;
  Hints.y = y;
  Hints.width = Hints.min_width = Hints.max_width = w;
  Hints.height = Hints.min_height = Hints.max_height = h;

  XSetStandardProperties (XDisplay, XWin,
			  title, title, 0, argv, 2, &Hints);

/**
 ** Define color table (compatible to SunView and Turbo-C usage)
 **/

  def_clut = DefaultColormap (XDisplay, XScreen);
  if (DefaultDepth (XDisplay, XScreen) < 4)
    {
      col_table[BLACK] = WhitePixel (XDisplay, XScreen);
      col_table[WHITE] = BlackPixel (XDisplay, XScreen);
      col_table[GRAY] = col_table[WHITE];
      col_table[RED] = col_table[WHITE];
      col_table[GREEN] = col_table[WHITE];
      col_table[BLUE] = col_table[WHITE];
      col_table[CYAN] = col_table[WHITE];
      col_table[MAGENTA] = col_table[WHITE];
      col_table[YELLOW] = col_table[WHITE];
      col_table[LIGHTGRAY] = col_table[WHITE];
      col_table[LIGHTRED] = col_table[WHITE];
      col_table[LIGHTGREEN] = col_table[WHITE];
      col_table[LIGHTBLUE] = col_table[WHITE];
      col_table[LIGHTCYAN] = col_table[WHITE];
      col_table[LIGHTMAGENTA] = col_table[WHITE];
    }
  else
    {
      XParseColor (XDisplay, def_clut, "gray10", &Xcol);
      XAllocColor (XDisplay, def_clut, &Xcol);
      col_table[GRAY] = Xcol.pixel;

      for (i = 1; i <= pg->maxpens; i++)
	{
	  sprintf (colorname, "#%2.2X%2.2X%2.2X",
		   pt.clut[i][0], pt.clut[i][1], pt.clut[i][2]);
	  if (XParseColor (XDisplay, def_clut, colorname, &Xcol)==0) fprintf(stderr,"failed tp map color for pen %d\n",i);
	if (XAllocColor (XDisplay, def_clut, &Xcol)==0) {
	fprintf(stderr,"failed to alloc X color for pen %d\n",i);
	col_table[i] = col_table[GRAY];
	}else
	  col_table[i] = Xcol.pixel;
	}
    }


	/**
	 **  Set foreground and background colors
	 **/

  XSetState (XDisplay, XGcWin,
	     col_table[BLACK], col_table[WHITE], GXcopy, AllPlanes);

	/**
	 ** Define permitted events for this window
	 **/

  XSelectInput (XDisplay, XWin,
		ExposureMask  | KeyPressMask | VisibilityChangeMask |
		ButtonPressMask | ButtonReleaseMask);

	/**
	 ** Display window
	 **/
  XMapWindow (XDisplay, XWin);
  do
    {
      XNextEvent (XDisplay, &Event);
    }
  while (Event.type != Expose && Event.type != VisibilityNotify );

  width = w;
  height = h;
  bytes = (w + 7) / 8;


  free ((char *) argv);
  return (0);
}
Beispiel #23
0
int main(int argc, char* argv[]){
 
  char* action;
  Window window;
  int arg[5]={0};

  // Connexion à un serveur X
  display = XOpenDisplay(NULL);
  if(!display){
    printf("Can not open display.\n");
    exit(EXIT_FAILURE);
  }

  // Récupère la valeur par default des différentes variables.
  screen = DefaultScreen(display);
  gc = DefaultGC (display, screen);
  root = RootWindow (display, screen);
  // Détermine l'action à effectuer :
  // On vérifie que le 2er argument (autre que nom fichier) est un id de fenetre :

  if(argc>2 && ((!strncmp(argv[2],"0x",2) && strtoll(argv[2],NULL,16)) || strtoll(argv[2],NULL,10)) ){  

      action = argv[1];
      window = get_window(argv); 
      
      // Si 5 arguments, c'est soit un move, soit un resize:
      if (argc==3){ // 1 seul argument (ex: 0x32422 )
	if(!strcmp(action,"mapRaise"))
	  do_map_and_raise(window);
	else if(!strcmp(action,"map"))
	  do_map(window);
	else if(!strcmp(action,"raise"))
	  do_raise(window);
	else if(!strcmp(action,"destroy"))
	  do_destroy(window);
	else if(!strcmp(action,"focus"))
	  do_focus(window);
	else if(!strcmp(action,"minimize"))
	  do_minimize(window);
	else if(!strcmp(action,"set_desktop"))
	  set_desktop((int)strtoll(argv[2],NULL,10));
	else
	  fail();
      }
      else if(argc==4){ // 2 arguments (ex : 0x4242535 1 )
	if(!strcmp(action,"set_desktop_for_window")){
	  set_desktop(strtoll(argv[3],NULL,10));
	  set_desktop_for_window(window,strtoll(argv[3],NULL,10));
	}
	else if(!strcmp(action,"set_viewport"))
	  set_viewport((int)strtoll(argv[2],NULL,10),(int)strtoll(argv[3],NULL,10));
	else
	  fail();
      }
      else if(argc==5){ 

	arg[0]=(int)strtoll(argv[3],NULL,10);
	arg[1]=(int)strtoll(argv[4],NULL,10);
	if(!strcmp(action,"move"))
	  do_move(window, arg[0], arg[1]); 
	else if(!strcmp(action,"resize"))
	  do_resize(window,arg[0],arg[1]); 
	else
	  fail();
      }
      else if(argc==7){

	arg[0]=(int)strtoll(argv[3],NULL,10);
	arg[1]=(int)strtoll(argv[4],NULL,10);
	arg[2]=(int)strtoll(argv[5],NULL,10);
	arg[3]=(int)strtoll(argv[6],NULL,10);

	if(!strcmp(action,"moveResize"))
	  do_move_and_resize(window, arg[0], arg[1], arg[2], arg[3]); 
	else
	  fail();
      }
      else
	fail();
  }
  else
    fail();
  
  
  XCloseDisplay(display);
  return EXIT_SUCCESS;
  
}
Beispiel #24
0
// initialisation d'une fenetre mail, avec du message
void init_mail_win_graphique(int num_msg){
	tab_mails[num_msg].mail_fen = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0,
			    WIDTH_MAIL_WIN,
				HEIGHT_MAIL_WIN,
				BORDER, 
				BlackPixel(dpy,DefaultScreen(dpy)), 
				color_fond_de_fen.pixel);	

	tab_mails[num_msg].mail_contenu_fen= XCreateSimpleWindow(dpy, tab_mails[num_msg].mail_fen, MARGIN, MARGIN,
					       WIDTH_MAIL_CONTENU,
					       HEIGHT_MAIL_CONTENU,
					       BORDER/2, 
					       BlackPixel(dpy,DefaultScreen(dpy)),
					       WhitePixel(dpy,DefaultScreen(dpy)));

	// faire la requete 
	char * contenu_mail= (char*) malloc(sizeof(char) * 4096);
	retr_handler(num_msg, contenu_mail);
	if(strcmp(contenu_mail, "") == 0){
		XDrawString(dpy, main_fen, DefaultGC(dpy,DefaultScreen(dpy)), 10, 20, "Mail multipart non conforme", strlen("Mail multipart non conforme") );
		besoin_msg_erreur=true;
		return;
	}

	int font_direction, font_ascent, font_descent;
	XCharStruct text_structure;
	char string_etal[]= "lj";								// pour avoir la taille max d'une ligne 
	XTextExtents(font, string_etal, strlen(string_etal),
	             &font_direction, &font_ascent, &font_descent,
	             &text_structure);

	int width_max= WIDTH_MAIL_CONTENU;
	int width_tmp=0;
	int nb_ligne=0;

	tab_mails[num_msg].height_ligne=font_descent + font_ascent;

	// traiter le text
	tab_mails[num_msg].contenu_mail_traiter= (char*) malloc(sizeof(char) * 4096);
	tab_mails[num_msg].contenu_mail_traiter[0]='\0';
	char* line;
	int cmpt_total=0;

	for(line= strtok(contenu_mail, "\n") ; line != NULL; line= strtok(NULL, "\n")){		// on lit le texte ligne par ligne 
		nb_ligne++;
		width_tmp=0;

		char* debutmot=line;
		int cmpt=0;
		int debut=0;

		while(debutmot[cmpt] != '\n' && debutmot[cmpt] != '\0' ){
			if(debutmot[cmpt] == '\r' ){
				debutmot[cmpt] = ' ';
			}
			else{
				if(debutmot[cmpt] == ' ' ){
					XTextExtents(font, debutmot+debut, cmpt-debut+1, &font_direction, &font_ascent,  &font_descent, &text_structure);
					if(width_tmp + text_structure.width> width_max){
						strcat(tab_mails[num_msg].contenu_mail_traiter, "\n");
						width_tmp=0;
						nb_ligne++;
					}
					else{
						width_tmp+= text_structure.width;
					}	
			
					strncat(tab_mails[num_msg].contenu_mail_traiter, debutmot+debut, cmpt-debut+1);

					debut+=(cmpt-debut+1);
				}
			}
			cmpt++;
		}
		if(cmpt-debut > 1){
			XTextExtents(font, debutmot+debut, cmpt-debut+1, &font_direction, &font_ascent,  &font_descent, &text_structure);
			if(width_tmp + text_structure.width> width_max){
				strcat(tab_mails[num_msg].contenu_mail_traiter, "\n");
				width_tmp=0;
				nb_ligne++;
			}
			else{
				width_tmp+= text_structure.width;
			}	
			
			strncat(tab_mails[num_msg].contenu_mail_traiter, debutmot+debut, cmpt-debut);
			debut+=(cmpt-debut+1);
			cmpt++;
		}
		strcat(tab_mails[num_msg].contenu_mail_traiter, "\n");
		cmpt_total+= cmpt;
	}

	free(contenu_mail);
	tab_mails[num_msg].height_contenu_inter= nb_ligne * (tab_mails[num_msg].height_ligne + BORDER) + MARGIN;

	// faire une fenetre adapté 
	tab_mails[num_msg].mail_contenu_inter= XCreateSimpleWindow(dpy, tab_mails[num_msg].mail_contenu_fen, 0, 0,
					       WIDTH_MAIL_CONTENU,
					       tab_mails[num_msg].height_contenu_inter,
					       0, 
					       BlackPixel(dpy,DefaultScreen(dpy)),
					       WhitePixel(dpy,DefaultScreen(dpy)));


	tab_mails[num_msg].quit_button=  XCreateSimpleWindow(dpy, tab_mails[num_msg].mail_fen, MARGIN, HEIGHT_MAIL_WIN  -MARGIN - HEIGHT_BUTTON,
					       WIDTH_BUTTON,
					       HEIGHT_BUTTON,
					       BORDER, 
					       BlackPixel(dpy,DefaultScreen(dpy)),
					       color_fond.pixel);

	tab_mails[num_msg].slide_fond=  XCreateSimpleWindow(dpy, tab_mails[num_msg].mail_fen, WIDTH_MAIL_WIN - MARGIN - WIDTH_FOND_SLIDE, MARGIN,
					       WIDTH_FOND_SLIDE,
					       HEIGHT_MAIL_CONTENU,
					       BORDER/2, 
					       BlackPixel(dpy,DefaultScreen(dpy)),
					       WhitePixel(dpy,DefaultScreen(dpy)));
					       
	tab_mails[num_msg].slider=  XCreateSimpleWindow(dpy, tab_mails[num_msg].slide_fond,  0, 0,
					       WIDTH_SLIDER,
					       HEIGHT_SLIDER,
					       0, 
					       BlackPixel(dpy,DefaultScreen(dpy)),
					       color_focus.pixel);
	tab_mails[num_msg].posslider=0;			       

	tab_mails[num_msg].gc_glob=XCreateGC(dpy, tab_mails[num_msg].mail_fen, 0, NULL);
 	XSetForeground(dpy, tab_mails[num_msg].gc_glob, BlackPixel(dpy,DefaultScreen(dpy)));
 	XSetBackground(dpy, tab_mails[num_msg].gc_glob, color_fond.pixel); 


	XSelectInput(dpy, tab_mails[num_msg].quit_button,  ButtonPressMask | ExposureMask);
	XSelectInput(dpy, tab_mails[num_msg].mail_contenu_inter, ExposureMask);
	XSelectInput(dpy, tab_mails[num_msg].slider, PointerMotionMask |  ButtonReleaseMask | ButtonPressMask | ExposureMask);

	XDefineCursor(dpy, tab_mails[num_msg].quit_button, cursor);


	XMapWindow(dpy, tab_mails[num_msg].mail_fen);
	XMapSubwindows(dpy, tab_mails[num_msg].mail_fen);
	XMapWindow(dpy, tab_mails[num_msg].mail_contenu_fen);
	XMapSubwindows(dpy, tab_mails[num_msg].mail_contenu_fen);
	XMapWindow(dpy, tab_mails[num_msg].slide_fond);
	XMapSubwindows(dpy, tab_mails[num_msg].slide_fond);

	XFlush(dpy);

	tab_mails[num_msg].init_window=true;
}
Beispiel #25
0
void main(int argc, char **argv)
{
  int   i,j,k,
        x_return, y_return;
  float D;
  unsigned int width_return, height_return,
               border_width_return, depth_return;
  Window root_return;  
  char *display_name;
  int screen;
  XSetWindowAttributes winAttributes;
  char *window_name = "sbXcityfly";
  char *icon_name = "sbXcityfly";

  static ButtonRec buttonDefs[]={
    {&buttonDefs[1],  "1",     "Translation ON ",         0, 
     SPW_BwFlagRoundButton},
    {&buttonDefs[2],  "2",     "Rotation ON ",            0, 
     SPW_BwFlagRoundButton},
    {&buttonDefs[3],  "3",     "Single Axis Filter OFF",  0, 
     SPW_BwFlagRoundButton},
    {&buttonDefs[4],  "4",     "Roll ON ",                0, 
     SPW_BwFlagRoundButton},
    {&buttonDefs[5],  "5",     "Decrease sensitivity",    0, 
     SPW_BwFlagRoundButton},
    {&buttonDefs[6], "Sensi",  "Sensitivity:    1 ",      0, 
     SPW_BwFlagNoButton},
    {&buttonDefs[7],  "6",     "Increase sensitivity",    0, 
     SPW_BwFlagRoundButton},
    {&buttonDefs[8],  "7",     " ",                       0, 
     SPW_BwFlagRoundButton},
    {&buttonDefs[9],  "8",     "Rezero",                  0, 
     SPW_BwFlagRoundButton},
    {&buttonDefs[10],  "P",    "Reset View",              0, 
     SPW_BwFlagRoundButton},
    {&buttonDefs[11], NULL,    NULL,                      0, 
     SPW_BwFlagSeparator},
    {&buttonDefs[12], "ESC",   "Quit",            XK_Escape, 
     SPW_BwFlagKey},
    {NULL,                NULL,    NULL,                      0, 
             SPW_BwFlagSeparator},
  };


  /*
   *  Connect to the X Server
   */

  if ((display_name=getenv("DISPLAY")) == NULL)
    display_name=":0";
  
  if ((Spw_Dpy=XOpenDisplay(display_name)) == NULL)
    {
      fprintf(stderr,"%s: Could not open X Display\n",argv[0]);
      exit(1);
    }
  
  screen=DefaultScreen(Spw_Dpy);
  Spw_Gc=DefaultGC(Spw_Dpy,screen);
  XSetBackground(Spw_Dpy,Spw_Gc,BlackPixel(Spw_Dpy,screen));
  XSetForeground(Spw_Dpy,Spw_Gc,WhitePixel(Spw_Dpy,screen));
  winAttributes.background_pixel=BlackPixel(Spw_Dpy,screen);

  /*
   *  Create the main window proportional to the root window
   */
  XGetGeometry(Spw_Dpy, DefaultRootWindow(Spw_Dpy), &root_return,
               &x_return,&y_return,
               &width_return, &height_return,& border_width_return,
               &depth_return);

  Spw_WindowSize = .8 * MIN(height_return,width_return);
  Spw_WindowWidth = Spw_WindowSize;
  Spw_WindowHeight = Spw_WindowSize;

  Spw_mainWindow = XCreateWindow(Spw_Dpy,DefaultRootWindow(Spw_Dpy),
                                 250, 0, Spw_WindowWidth, Spw_WindowHeight,1,
                                 CopyFromParent,CopyFromParent,CopyFromParent,
                                 CWBackPixel,&winAttributes);
  Spw_mainBuffer= XCreatePixmap(Spw_Dpy, Spw_mainWindow, 
                                Spw_WindowWidth, Spw_WindowHeight,
                                XDefaultDepthOfScreen(XDefaultScreenOfDisplay(Spw_Dpy)));

  /*
   *  Select the colors to draw in
   */
  Spw_white   = AllocPublicColor(0xffff,0xffff,0xffff);
  Spw_black   = AllocPublicColor(0x0000,0x0000,0x0000);
  Spw_grey    = AllocPublicColor(0xffff,0xffff,0xffff);
  Spw_green   = AllocPublicColor(0x0000,0xffff,0x0000);
  
  /*
   * Set up and map the window
   */
  XStoreName(Spw_Dpy, Spw_mainWindow, argv[0]);
  setWindowHints(Spw_mainWindow, argv, argc, window_name, icon_name,
                 "sbXcityfly", "SBxcityfly");
  XMapWindow(Spw_Dpy, Spw_mainWindow);

  /*
   *  Initialize the Spaceball and Button Window
   */

  if (!(SPW_InputCheckForSpaceball(Spw_Dpy, Spw_mainWindow, "sbXcityfly")) )
    {
      fprintf (stderr, "Sorry, no Spaceball found!\n");
      exit(0);
    }
  
  Spw_ButtonWindow=SPW_BwInit(Spw_Dpy, DefaultScreenOfDisplay(Spw_Dpy), 
                   "sbXcityfly", buttonDefs);
  
  if(!Spw_ButtonWindow)
    {
      fprintf(stderr, "Error: BwInit returned NULL\n");
      exit(-1);
    }
  
   SpwUpdateButtons();

  /*
   *  Set up the geometry to be displayed
   */

   D = 1.0/tan( (double) ((M_PI/180.0)*(FOV/2.0)) );
   SPW_InitializeMatrix(Spw_Persp, 1.0, 0.0,  0.0,  0.0,
                               0.0, 1.0,  0.0,  0.0,
                                      0.0, 0.0, -1.0, -1.0/D,
                               0.0, 0.0,  0.0,  0.0);

   GetUniqPoints(bldg, buniq, Spw_SizeBldg );
   GetUniqPoints(land, luniq, Spw_SizeLand );

  /*
   *  Go into main loop, clean up if we ever exit cleanly
   */

   DispatchLoop();
   XDestroyWindow(Spw_Dpy, Spw_mainWindow);
   XCloseDisplay(Spw_Dpy);

} /* end of main */
Beispiel #26
0
void
initializeWindowSystem(void)
{
    char *display_name = NULL;
    XColor fg, bg;
#if 0
    XColor rgbdef;
#endif
    Colormap cmap;
    Pixmap  mousebits, mousemask;
/*    fprintf(stderr,"initx:initializeWindowSystem:entered\n");*/
    /* Try to open the display */
/*    fprintf(stderr,"initx:initializeWindowSystem:XOpenDisplay\n");*/
    if ((gXDisplay = XOpenDisplay(display_name)) == NULL) {
        fprintf(stderr, "(HyperDoc) Cannot connect to the X11 server!\n");
        exit(-1);
    }

    /* Get the screen */
/*    fprintf(stderr,"initx:initializeWindowSystem:DefaultScreen\n");*/
    gXScreenNumber = scrn = DefaultScreen(gXDisplay);
/*    fprintf(stderr,"initx:initializeWindowSystem:XGContextFromGC\n");*/
    server_font =XGContextFromGC(DefaultGC(gXDisplay, gXScreenNumber));

    /* Get the cursors we need. */

/*    fprintf(stderr,"initx:initializeWindowSystem:DefaultColormap\n");*/
    cmap = DefaultColormap(gXDisplay, gXScreenNumber);
/*    fprintf(stderr,"initx:initializeWindowSystem:WhitePixel\n");*/
    fg.pixel = WhitePixel(gXDisplay,gXScreenNumber);
/*    fprintf(stderr,"initx:initializeWindowSystem:XQueryColor\n");*/
    XQueryColor(gXDisplay, cmap, &fg );
/*    fprintf(stderr,"initx:initializeWindowSystem:BlackPixel\n");*/
    bg.pixel = BlackPixel(gXDisplay,gXScreenNumber);
/*    fprintf(stderr,"initx:initializeWindowSystem:XQueryColor2\n");*/
    XQueryColor(gXDisplay, cmap, &bg );
#if 0
    XAllocNamedColor(gXDisplay, cmap, "Black", &fg, &rgbdef);
    XAllocNamedColor(gXDisplay, cmap, "White", &bg, &rgbdef);
#endif

#ifdef USE_BORING_OLD_CURSORS
    gActiveCursor = XCreateFontCursor(gXDisplay, XC_circle);
    gNormalCursor = XCreateFontCursor(gXDisplay, XC_dot);
#else
/*  fprintf(stderr,"initx:initializeWindowSystem:XCreateBitmapFromData 1\n");*/
    mousebits = XCreateBitmapFromData(gXDisplay,
        RootWindow(gXDisplay, gXScreenNumber),
        ucharp_to_charp(mouseBitmap_bits),
        mouseBitmap_width,mouseBitmap_height);
/* fprintf(stderr,"initx:initializeWindowSystem:XCreateBitmapFromData 2\n");*/
    mousemask = XCreateBitmapFromData(gXDisplay,
        RootWindow(gXDisplay, gXScreenNumber),
        ucharp_to_charp(mouseMask_bits), mouseMask_width,mouseMask_height);
/* fprintf(stderr,"initx:initializeWindowSystem:XCreateBitmapFromData 2\n");*/
    gActiveCursor = XCreatePixmapCursor(gXDisplay,
        mousebits, mousemask, &fg, &bg,
        mouseBitmap_x_hot,mouseBitmap_y_hot);

/*    fprintf(stderr,"initx:initializeWindowSystem:XCreateFontCursor\n");*/
    gNormalCursor = XCreateFontCursor(gXDisplay, XC_left_ptr);
#endif

/*    fprintf(stderr,"initx:initializeWindowSystem:XCreateFontCursor 2\n");*/
    gBusyCursor = XCreateFontCursor(gXDisplay, XC_watch);

    /* Now initialize all the colors and fonts */

/*    fprintf(stderr,"initx:initializeWindowSystem:ingItColors_and_fonts\n");*/
    ingItColors_and_fonts();
/*    fprintf(stderr,"initx:initializeWindowSystem:init_text\n");*/
    init_text();
/*    fprintf(stderr,"initx:initializeWindowSystem:exited\n");*/

}
Beispiel #27
0
void SetDeskPageBackground(const Command *c)
{
	Display *dpy2 = NULL;
	Window root2 = None;
	int screen2;
	Pixmap pix = None;

	current_colorset = -1;

	/* FvwmBacker bg preperation */
	switch (c->type)
	{
	case 1: /* solid colors */
	case 2: /* colorset */
		dpy2 =  XOpenDisplay(displayName);
		if (!dpy2)
		{
			fvwm_msg(ERR, "FvwmBacker",
				 "Fail to create a forking dpy, Exit!");
			exit(2);
		}
		screen2 = DefaultScreen(dpy2);
		root2 = RootWindow(dpy2, screen2);
		if (RetainPixmap)
		{
			XSetCloseDownMode(dpy2, RetainPermanent);
		}
		XGrabServer(dpy2);
		DeleteRootAtoms(dpy2, root2);
		switch (c->type)
		{
		case 2:
			current_colorset = c->colorset;
			/* Process a colorset */
			if (CSET_IS_TRANSPARENT(c->colorset))
			{
				fvwm_msg(ERR,"FvwmBacker", "You cannot "
					 "use a transparent colorset as "
					 "background!");
				XUngrabServer(dpy2);
				XCloseDisplay(dpy2);
				return;
			}
			else if (Pdepth != DefaultDepth(dpy2, screen2))
			{
				fvwm_msg(ERR,"FvwmBacker", "You cannot "
					 "use a colorset background if\n"
					 "the fvwm depth is not equal "
					 "to the root depth!");
				XUngrabServer(dpy2);
				XCloseDisplay(dpy2);
				return;
			}
			else if (RetainPixmap)
			{
				pix = CreateBackgroundPixmap(
					dpy2, root2, MyDisplayWidth,
					MyDisplayHeight,
					&Colorset[c->colorset],
					DefaultDepth(dpy2, screen2),
					DefaultGC(dpy2, screen2), False);
				if (pix != None)
				{
					XSetWindowBackgroundPixmap(
						dpy2, root2, pix);
					XClearWindow(dpy2, root2);
				}
			}
			else
			{
				SetWindowBackground(
					dpy2, root2, MyDisplayWidth,
					MyDisplayHeight,
					&Colorset[c->colorset],
					DefaultDepth(dpy2, screen2),
					DefaultGC(dpy2, screen2), True);
			}
			break;
		case 1: /* Process a solid color request */
			if (RetainPixmap)
			{
				GC gc;
				XGCValues xgcv;

				xgcv.foreground = c->solidColor;
				gc = fvwmlib_XCreateGC(
					dpy2, root2, GCForeground,
					&xgcv);
				pix = XCreatePixmap(
					dpy2, root2, 1, 1,
					DefaultDepth(dpy2, screen2));
				XFillRectangle(
					dpy2, pix, gc, 0, 0, 1, 1);
				XFreeGC(dpy2, gc);
			}
			XSetWindowBackground(dpy2, root2, c->solidColor);
			XClearWindow(dpy2, root2);
			break;
		}
		SetRootAtoms(dpy2, root2, pix);
		XUngrabServer(dpy2);
		XCloseDisplay(dpy2); /* this XSync, Ungrab, ...etc */
		break;
	case -1:
	case 0:
	default:
		if(c->cmdStr != NULL)
		{
			SendFvwmPipe(fvwm_fd, c->cmdStr, (unsigned long)0);
		}
		break;
	}
}
Beispiel #28
0
gint
nsFreeTypeXImage::DrawString(nsRenderingContextGTK* aContext,
                            nsDrawingSurfaceGTK* aSurface, nscoord aX,
                            nscoord aY, const PRUnichar* aString,
                            PRUint32 aLength)
{

#if DEBUG_SHOW_GLYPH_BOX
  PRUint32 x, y;
  // grey shows image size
  // red shows character cells
  // green box shows text ink
#endif

  if (aLength < 1) {
    return 0;
  }

  // get the face/size from the FreeType cache
  FT_Face face = getFTFace();
  NS_ASSERTION(face, "failed to get face/size");
  if (!face)
    return 0;

  nsresult rslt;
  PRInt32 leftBearing, rightBearing, ascent, descent, width;
  rslt = doGetBoundingMetrics(aString, aLength, &leftBearing, &rightBearing,
                              &ascent, &descent, &width);
  if (NS_FAILED(rslt))
    return 0;

  // make sure we bring down enough background for blending
  rightBearing = PR_MAX(rightBearing, width+1);

  // offset in the ximage to the x origin
  PRInt32 x_origin = PR_MAX(0, -leftBearing);
  // offset in the ximage to the x origin
  PRInt32 y_origin = ascent;
  PRInt32 x_pos = x_origin;

  int image_width  = x_origin + rightBearing;
  int image_height = y_origin + PR_MAX(descent, 0);
  if ((image_width<=0) || (image_height<=0)) {
    // if we do not have any pixels then no point in trying to draw
    // eg: the space char has 0 height
    NS_ASSERTION(width>=0, "Negative width");
    return width;
  }
  Display *dpy = GDK_DISPLAY();
  Drawable win = GDK_WINDOW_XWINDOW(aSurface->GetDrawable());
  GC gc = GDK_GC_XGC(aContext->GetGC());
  XGCValues values;
  if (!XGetGCValues(dpy, gc, GCForeground, &values)) {
    NS_ERROR("failed to get foreground pixel");
    return 0;
  }
  nscolor color = nsX11AlphaBlend::PixelToNSColor(values.foreground);

#if DEBUG_SHOW_GLYPH_BOX
  // show X/Y origin
  XDrawLine(dpy, win, DefaultGC(dpy, 0), aX-2, aY, aX+2, aY);
  XDrawLine(dpy, win, DefaultGC(dpy, 0), aX, aY-2, aX, aY+2);
  // show width
  XDrawLine(dpy, win, DefaultGC(dpy, 0), aX-x_origin,  aY-y_origin-2,
                                         aX+rightBearing, aY-y_origin-2);
#endif

  //
  // Get the background
  //
  XImage *sub_image = nsX11AlphaBlend::GetBackground(dpy, DefaultScreen(dpy),
                                 win, aX-x_origin, aY-y_origin,
                                 image_width, image_height);
  if (sub_image==nsnull) {
#ifdef DEBUG
    int screen = DefaultScreen(dpy);
    // complain if the requested area is not completely off screen
    int win_width = DisplayWidth(dpy, screen);
    int win_height = DisplayHeight(dpy, screen);
    if (((int)(aX-leftBearing+image_width) > 0)  // not hidden to left
        && ((int)(aX-leftBearing) < win_width)   // not hidden to right
        && ((int)(aY-ascent+image_height) > 0)// not hidden to top
        && ((int)(aY-ascent) < win_height))   // not hidden to bottom
    {
      NS_ASSERTION(sub_image, "failed to get the image");
    }
#endif
    return 0;
  }

#if DEBUG_SHOW_GLYPH_BOX
  DEBUG_AADRAWBOX(sub_image,0,0,image_width,image_height,0,0,0,255/4);
  nscolor black NS_RGB(0,255,0);
  blendPixel blendPixelFunc = nsX11AlphaBlend::GetBlendPixel();
  // x origin
  for (x=0; x<(unsigned int)image_height; x++)
    if (x%4==0) (*blendPixelFunc)(sub_image, x_origin, x, black, 255/2);
  // y origin
  for (y=0; y<(unsigned int)image_width; y++)
    if (y%4==0) (*blendPixelFunc)(sub_image, y, ascent-1, black, 255/2);
#endif

  FTC_Image_Cache icache;
  mFt2->GetImageCache(&icache);
  if (!icache)
    return 0;

  //
  // Get aa glyphs and blend with background
  //
  blendGlyph blendGlyph = nsX11AlphaBlend::GetBlendGlyph();
  PRUint32 i, extraSurrogateLength;
  for (i=0; i<aLength; i+=1+extraSurrogateLength) {
    FT_UInt glyph_index;
    FT_Glyph glyph;
    nsresult rv;
    FT_BBox glyph_bbox;
    FT_ULong code_point = aString[i];
    extraSurrogateLength = 0;

    if(i<aLength-1 && IS_HIGH_SURROGATE(code_point) && IS_LOW_SURROGATE(aString[i+1])) {
      // if surrogate, make UCS4 code point from high aString[i] surrogate and
      // low surrogate aString[i+1]
      code_point = SURROGATE_TO_UCS4(code_point, aString[i+1]);

      // skip aString[i+1], it is already used as low surrogate
      extraSurrogateLength = 1;
    }

    mFt2->GetCharIndex(face, code_point, &glyph_index);
    if (glyph_index) {
      rv = mFt2->ImageCacheLookup(icache, &mImageDesc, glyph_index, &glyph);
    }
    if ((glyph_index) && (NS_SUCCEEDED(rv))) {
      mFt2->GlyphGetCBox(glyph, ft_glyph_bbox_pixels, &glyph_bbox);
    }
    else {
      // draw an empty box for the missing glyphs
      GetFallbackGlyphMetrics(&glyph_bbox, face);
      int x, y, w = glyph_bbox.xMax, h = glyph_bbox.yMax;
      for (x=1; x<w; x++) {
        XPutPixel(sub_image, x_pos+x, ascent-1,   values.foreground);
        XPutPixel(sub_image, x_pos+x, ascent-h, values.foreground);
      }
      for (y=1; y<h; y++) {
        XPutPixel(sub_image, x_pos+1, ascent-y, values.foreground);
        XPutPixel(sub_image, x_pos+w-1, ascent-y, values.foreground);
        x = (y*(w-2))/h;
        XPutPixel(sub_image, x_pos+x+1, ascent-y,   values.foreground);
      }
      x_pos += w + 1;
      continue;
    }

    FT_BitmapGlyph slot = (FT_BitmapGlyph)glyph;
    nsAntiAliasedGlyph aaglyph(glyph_bbox.xMax-glyph_bbox.xMin,
                               glyph_bbox.yMax-glyph_bbox.yMin, 0);
    PRUint8 buf[IMAGE_BUFFER_SIZE]; // try to use the stack for data
    if (!aaglyph.WrapFreeType(&glyph_bbox, slot, buf, IMAGE_BUFFER_SIZE)) {
      NS_ERROR("failed to wrap freetype image");
      XDestroyImage(sub_image);
      return 0;
    }

    //
    // blend the aa-glyph onto the background
    //
    NS_ASSERTION(ascent>=glyph_bbox.yMax,"glyph too tall");
    NS_ASSERTION(x_pos>=-aaglyph.GetLBearing(),"glyph extends too far to left");

#if DEBUG_SHOW_GLYPH_BOX
  // draw box around part of glyph that extends to the left
  // of the main area (negative LBearing)
  if (aaglyph.GetLBearing() < 0) {
    DEBUG_AADRAWBOX(sub_image, x_pos + aaglyph.GetLBearing(),
                    ascent-glyph_bbox.yMax,
                    -aaglyph.GetLBearing(), glyph_bbox.yMax, 255,0,0, 255/4);
  }
  // draw box around main glyph area
  DEBUG_AADRAWBOX(sub_image, x_pos, ascent-glyph_bbox.yMax,
                  aaglyph.GetAdvance(), glyph_bbox.yMax, 0,255,0, 255/4);
  // draw box around part of glyph that extends to the right
  // of the main area (negative LBearing)
  if (aaglyph.GetRBearing() > (int)aaglyph.GetAdvance()) {
    DEBUG_AADRAWBOX(sub_image, x_pos + aaglyph.GetAdvance(),
                    ascent-glyph_bbox.yMax,
                    aaglyph.GetRBearing()-aaglyph.GetAdvance(),
                    glyph_bbox.yMax, 0,0,255, 255/4);
  }
#endif
    (*blendGlyph)(sub_image, &aaglyph, sLinearWeightTable, color,
                  x_pos + aaglyph.GetLBearing(), ascent-glyph_bbox.yMax);

    x_pos += aaglyph.GetAdvance();
  }

  //
  // Send it to the display
  //
  XPutImage(dpy, win, gc, sub_image, 0, 0, aX-x_origin , aY-ascent,
            image_width, image_height);
  XDestroyImage(sub_image);

  return width;
}
Beispiel #29
0
void
TestWidget::DrawStuff
(
    JPainter& p
)
{
    JIndex i;

    JXColormap* colormap = GetColormap();

    p.SetPenColor(colormap->GetGreenColor());
    JRect ellipseRect(100,50,150,300);
    p.Ellipse(ellipseRect);

    p.SetPenColor(colormap->GetBlackColor());

    if (itsFillFlag)
    {
        p.SetFilling(kJTrue);
    }

    JRect ap = GetAperture();
    p.Line(ap.topLeft(), ap.bottomRight());
    p.Line(ap.topRight(), ap.bottomLeft());

    p.SetLineWidth(2);
    p.SetFontName(JXGetTimesFontName());
    p.SetFontSize(18);

    p.Image(*itsHomeImage, itsHomeImage->GetBounds(), itsHomeRect);

    its2Rect = JRect(150, 5, 200, 30);
    p.SetPenColor(colormap->GetRedColor());
    p.Rect(its2Rect);
    p.SetFontStyle(colormap->GetRedColor());
    p.String(its2Rect.topLeft(), "2",
             its2Rect.width(),  JPainter::kHAlignCenter,
             its2Rect.height(), JPainter::kVAlignCenter);

    its3Rect = JRect(10, 150, 40, 200);
    p.SetPenColor(colormap->GetBlueColor());
    p.Rect(its3Rect);
    p.SetFontStyle(colormap->GetBlueColor());
    p.String(its3Rect.topLeft(), "3",
             its3Rect.width(),  JPainter::kHAlignCenter,
             its3Rect.height(), JPainter::kVAlignCenter);

    p.SetLineWidth(1);
    p.SetFont(JGetDefaultFontName(), kJXDefaultFontSize, colormap->GetBlackColor());

    p.ShiftOrigin(10,10);

    p.Point(0,0);
    for (i=1; i<=itsRandPointCount; i++)
    {
        p.Point(itsRNG.UniformLong(0,200), itsRNG.UniformLong(0,200));
    }

    p.SetPenColor(colormap->GetRedColor());
    p.Line(10,0, 0,10);
    p.SetPenColor(colormap->GetGreenColor());
    p.LineTo(10,20);
    p.SetPenColor(colormap->GetBlueColor());
    p.LineTo(0,30);

    p.ShiftOrigin(2,0);

    JPoint textPt(40,30);
    p.String(  0.0, textPt, "Hello");
    p.String( 90.0, textPt, "Hello");
    p.String(180.0, textPt, "Hello");
    p.String(270.0, textPt, "Hello");

    p.Rect(310, 70, 80, 80);
    p.String(  0.0, 310, 70, "Hello", 80, JPainter::kHAlignCenter,
               80, JPainter::kVAlignCenter);
    p.String( 90.0, 310,150, "Hello", 80, JPainter::kHAlignCenter,
              80, JPainter::kVAlignCenter);
    p.String(180.0, 390,150, "Hello", 80, JPainter::kHAlignCenter,
             80, JPainter::kVAlignCenter);
    p.String(270.0, 390, 70, "Hello", 80, JPainter::kHAlignCenter,
             80, JPainter::kVAlignCenter);

    p.Rect(200, 10, 100, 50);
    p.String(200, 10, "Hello", 100, JPainter::kHAlignLeft);
    p.String(200, 10+p.GetLineHeight(), "Hello", 100, JPainter::kHAlignCenter);
    p.String(200, 10+2*p.GetLineHeight(), "Hello", 100, JPainter::kHAlignRight);

    p.SetPenColor(colormap->GetYellowColor());
    JRect r(0,11,80,91);
    p.Rect(r);
    r.Shrink(1,1);
    p.SetPenColor(colormap->GetBlueColor());
    p.Ellipse(r);
    r.Shrink(1,1);
    p.SetPenColor(colormap->GetRedColor());
    p.Arc(r, 270.0-45.0, -270.0);

    JPolygon poly;
    poly.AppendElement(JPoint(0,85));
    poly.AppendElement(JPoint(10,85));
    poly.AppendElement(JPoint(5,95));
    p.Polygon(poly);

    p.Line(0,100, 2,98);
    p.LineTo(4,100);
    p.LineTo(2,102);
    p.LineTo(0,100);

    poly.SetElement(1, JPoint(0,5));
    poly.SetElement(2, JPoint(2,0));
    poly.SetElement(3, JPoint(4,5));
    p.Polygon(2,105, poly);

    // test filling rule

    p.SetPenColor(colormap->GetRedColor());
    p.SetFilling(kJTrue);

    JPolygon fillRulePoly;
    fillRulePoly.AppendElement(JPoint(175,45));
    fillRulePoly.AppendElement(JPoint(165,65));
    fillRulePoly.AppendElement(JPoint(190,50));
    fillRulePoly.AppendElement(JPoint(160,50));
    fillRulePoly.AppendElement(JPoint(185,65));
    p.Polygon(fillRulePoly);

    p.SetFilling(kJFalse);

    // dashed lines

    p.DrawDashedLines(kJTrue);

    p.SetPenColor(colormap->GetBlackColor());

    JArray<JSize> dashList;			// pixel rulers
    dashList.AppendElement(1);
    dashList.AppendElement(1);
    p.SetDashList(dashList);
    p.Line(100,110, 200,110);
    p.Line(100,114, 200,114);
    p.Line(100,118, 200,118);

    dashList.SetElement(1, 2);		// simple pattern
    dashList.SetElement(2, 3);
    p.SetDashList(dashList);
    p.Line(100,112, 200,112);

    p.SetFontStyle(JFontStyle(kJFalse, kJFalse, 1, kJFalse));
    p.String(130,155, "underline without dashes");

    p.SetDashList(dashList, 3);		// test offset
    p.Line(100,116, 200,116);

    dashList.SetElement(1, 1);		// example with odd # of values from X manuals
    dashList.SetElement(2, 2);
    dashList.AppendElement(3);
    p.SetDashList(dashList);
    p.Line(100,120, 200,120);

    dashList.SetElement(1, 5);		// dash-dot pattern
    dashList.SetElement(2, 2);
    dashList.SetElement(3, 1);
    dashList.AppendElement(2);
    p.SetDashList(dashList);
    p.Line(100,122, 200,122);

    p.Ellipse(210,110, 20,20);
    p.DrawDashedLines(kJFalse);
    p.Ellipse(213,113, 14,14);
    p.Rect(207,107, 26,26);
    p.SetPenColor(colormap->GetYellowColor());
    p.DrawDashedLines(kJTrue);
    p.Ellipse(213,113, 14,14);

    // animated colors

    p.SetFilling(kJTrue);

    JCoordinate x = 25;
    const JSize animColorCount = itsAnimColorList->GetElementCount();
    for (i=1; i<=animColorCount; i++)
    {
        p.SetPenColor(itsAnimColorList->GetElement(i));
        p.Rect(x, 150, 10, 10);
        x += 10;
    }

    // icons

    p.Image(*itsXPMImage, itsXPMImage->GetBounds(), 33,110);
    p.Image(*itsPartialXPMImage, itsXPMImage->GetBounds(), 50,121);

    // *NEVER* do this in your code!  I do it here ONLY to test JXColormap.
    // (Besides, look at how messy it is!)

    unsigned long xPixel;
    if (colormap->CalcPreallocatedXPixel(62720, 56832, 45824, &xPixel))
    {
        JXDisplay* display = GetDisplay();
        Display* xdisplay  = display->GetXDisplay();
        GC gc = DefaultGC(xdisplay, display->GetScreen());
        XSetForeground(xdisplay, gc, xPixel);
        XFillRectangle(xdisplay, (GetWindow())->GetXWindow(), gc, 110,40, 20,20);
    }
}
Beispiel #30
0
	int main(int argc, char **argv)
	{
		static char *string = "Hello World!";
		Display *display;
		int screen_num;
		Window win;			//窗口ID
		unsigned int width, height;	//窗口尺寸
		unsigned int border_width = 4;	//边界空白
		unsigned int display_width, display_height;//屏幕尺寸
		int count;
		XEvent report;
		GC gc;
		unsigned long valuemask = 0;
		XGCValues values;
		char *display_name = NULL;
	
		// 和X 服务器连接
		if ( (display=XOpenDisplay(display_name)) == NULL )
		{
			printf("Cannot connect to X server %s\n", 
					XDisplayName(display_name));
			exit(-1);
		}

		//获得缺省的 screen_num
		screen_num = DefaultScreen(display);

		//获得屏幕的宽度和高度
		display_width = DisplayWidth(display, screen_num);
		display_height = DisplayHeight(display, screen_num);
	
		//指定所建立窗口的宽度和高度
		width = display_width/3;
		height = display_height/4;
	
		//建立窗口
		win = XCreateSimpleWindow(display, 	//display
			RootWindow(display,screen_num), //父窗口
			0, 0, width, height, 		//位置和大小
			border_width, 			//边界宽度
			BlackPixel(display,screen_num), //前景色
			WhitePixel(display,screen_num));//背景色
	
		//选择窗口感兴趣的事件掩码
		XSelectInput(display, win, 
			ExposureMask | KeyPressMask | 
			ButtonPressMask | StructureNotifyMask);

		//建立GC
		gc = DefaultGC(display, screen_num);

		//显示窗口
		XMapWindow(display, win);

		//进入事件循环
		while (1)  {

			//取得队列中的事件
			XNextEvent(display, &report);
			switch  (report.type) {

			//曝光事件, 窗口应重绘
			case Expose:
				//取得最后一个曝光事件
				if (report.xexpose.count != 0) break;
				break;

			//窗口尺寸改变, 重新取得窗口的宽度和高度
			case ConfigureNotify:
				break;

			//鼠标点击显示窗口的某些属性
			case ButtonPress:
				{
				XWindowAttributes xa;
				Window root;
				int x, y;
				unsigned int w, h, border, depth;
					
				XGetWindowAttributes(display,win,&xa);
				printf("geometry:%d %d %d %d\n",
					xa.x,xa.y, xa.width, xa.height);
				printf("override redirect:%d\n", 
					xa.override_redirect);
				XGetGeometry(display,win,&root, &x, &y,
					&w, &h, &border, &depth);
				printf("attrib: x:%d y:%d w:%d h:%d "
					"border:%d depth: %d\n",
					x, y, w, h, border, depth);
				}
				break;
			case KeyPress:
				XFreeGC(display, gc);
				exit(1);
			default:
				
				break;
			}
		}
	}