Exemplo n.º 1
0
void g2_attach(int vd_dev, int dev)
{
    g2_device *vd_devp, *devp;

    if((vd_devp=g2_get_device_pointer(vd_dev))==NULL) {
	fprintf(stderr, "g2_attach: No such device: %d\n", vd_dev);
	return;
    }

    if((devp=g2_get_device_pointer(dev))==NULL) {
	fprintf(stderr, "g2_attach: No such device: %d\n", dev);
	return;
    }

    if(vd_devp->t!=g2_VD) {
	fprintf(stderr, "g2_attach: Device %d is not virtual.\n", vd_dev);
	return;
    }

    if(devp->t==g2_VD)				  /* if virtual device */
	if(g2_is_attached(dev, vd_dev)) {	  /* check recurency */
	    fprintf(stderr,
		    "g2_attach: Device %d is already attached to %d.\n",
		    dev, vd_dev);
	    return;
	}

    vd_devp->d.vd->N++;
    vd_devp->d.vd->dix=g2_realloc(vd_devp->d.vd->dix,
				  vd_devp->d.vd->N*sizeof(int));

    vd_devp->d.vd->dix[vd_devp->d.vd->N-1]=dev;

    __g2_last_device=vd_dev;
}
Exemplo n.º 2
0
/**
 *
 * Save output
 *
 * \param dev device id
 *
 * \ingroup control
 */
void g2_save(int dev)
{
    g2_device *devp;
    int i;
    
    if((devp=g2_get_device_pointer(dev))==NULL) {
	fprintf(stderr, "g2_save: No such device: %d\n", dev);
	return;
    }
    
    switch(devp->t) {
      case g2_PD:
	g2_save_pd(devp->d.pd);
	break;
      case g2_VD:
	for(i=0;i<devp->d.vd->N;i++)
	    g2_save(devp->d.vd->dix[i]);
	break;
      case g2_ILLEGAL:
	break;
      case g2_NDEV:
	break;
    }
    __g2_last_device=dev;
}
Exemplo n.º 3
0
/**
 *
 * Get pointers to physical device specific handles. This function
 * should be used only if you are familiar with the g2 source code.
 * For details see physical device source code (e.g. in src/X11/).
 * Example usage can be found in demo/handles.c.
 *
 * \param pd physical device
 * \param handles returns pointers to physical device low level handles
 *
 * \ingroup control
 */
void g2_get_pd_handles(int pd, void *handles[G2_PD_HANDLES_SIZE])
{
    g2_device *devp;
    int i;

    for(i=0;i<G2_PD_HANDLES_SIZE;i++) {
	handles[i]=NULL;
    }
    if((devp=g2_get_device_pointer(pd))==NULL) {
	g2_log(Error, "g2: Error! g2_get_pd_handles: No such device: %d\n", pd);
	return;
    }
    
    switch(devp->t) {
      case g2_PD:
	g2_get_pd_handles_pd(devp->d.pd, handles);
	break;
      case g2_VD:
	break;
      case g2_ILLEGAL:
	break;
      case g2_NDEV:
	break;
    }
}
Exemplo n.º 4
0
/**
 *
 * Clear collor palette (remove all inks) and reallocate basic colors.
 *
 * \param dev device
 *
 * \ingroup color
 */
void g2_reset_palette(int dev)
{
    g2_device *devp;
    int i;
    
    if((devp=g2_get_device_pointer(dev))==NULL) {
	fprintf(stderr, "g2_reset_palette: No such device: %d\n", dev);
	return;
    }
    
    switch(devp->t) {
      case g2_PD:
	g2_clear_palette(dev);
	g2_allocate_basic_colors(dev);
	break;
      case g2_VD:
	for(i=0;i<devp->d.vd->N;i++)
	    g2_reset_palette(devp->d.vd->dix[i]);
	break;
      case g2_ILLEGAL:
	break;
      case g2_NDEV:
	break;
    }
    __g2_last_device=dev;
}
Exemplo n.º 5
0
/**
 *
 * Create an ink. To put ink into the pen use g2_pen().
 *
 * \param pd_dev physical device
 * \param red red component (0-1) according to the RGB color model
 * \param green green component (0-1) according to the RGB color model
 * \param blue blue component (0-1) according to the RGB color model
 * \return new pen, see g2_pen()
 *
 * \ingroup color
 */
int g2_ink(int pd_dev, double red, double green, double blue)
{
    g2_device *devp;
    int rv=-1;

    if((devp=g2_get_device_pointer(pd_dev))==NULL) {
	fprintf(stderr, "g2_ink: No such device: %d\n", pd_dev);
	return -1;
    }

    if(red   < 0.0) red=0.0;
    if(green < 0.0) green=0.0;
    if(blue  < 0.0) blue=0.0;
    if(red   > 1.0) red=1.0;
    if(green > 1.0) green=1.0;
    if(blue  > 1.0) blue=1.0;
    
    switch(devp->t) {
      case g2_PD:
	rv=g2_ink_pd(devp->d.pd, red, green, blue);
	break;
      case g2_VD:
	fprintf(stderr, "g2_ink: g2_ink is enabled only for phys. devices\n");
	break;
      case g2_ILLEGAL:
	break;
      case g2_NDEV:
	break;
    }
    __g2_last_device=pd_dev;
    return rv;
}
Exemplo n.º 6
0
/**
 *
 * Set the background color
 *
 * \param dev device
 * \param color pen (either one of default pens 0-26, or a pen returned by g2_ink() )
 *
 * \ingroup color
 */
void g2_set_background(int dev, int color)
{
    g2_device *devp;
    int i;
    
    if((devp=g2_get_device_pointer(dev))==NULL) {
	fprintf(stderr, "g2_set_background: No such device: %d\n", dev);
	return;
    }
    
    switch(devp->t) {
      case g2_PD:
	g2_set_background_pd(devp->d.pd, color);
	break;
      case g2_VD:
	for(i=0;i<devp->d.vd->N;i++)
	    g2_set_background(devp->d.vd->dix[i], color);
	break;
      case g2_ILLEGAL:
	break;
      case g2_NDEV:
	break;
    }
    
    if(devp->auto_flush)
	g2_flush(dev);
    
    __g2_last_device=dev;
}
Exemplo n.º 7
0
void g2_detach(int vd_dev, int dev)
{
    g2_device *vd_devp;
    int i;

    if((vd_devp=g2_get_device_pointer(vd_dev))==NULL) {
	fprintf(stderr, "g2_detach: No such device: %d\n", vd_dev);
	return;
    }

    if(vd_devp->t!=g2_VD) {
	fprintf(stderr, "g2_detach: Device %d is not virtual.\n", vd_dev);
	return;
    }

    for(i=0;i<vd_devp->d.vd->N;i++)
	if(vd_devp->d.vd->dix[i]==dev) {
	    if(vd_devp->d.vd->N>1)
		vd_devp->d.vd->dix[i]=vd_devp->d.vd->dix[vd_devp->d.vd->N-1];
	    vd_devp->d.vd->N--;
	    if(vd_devp->d.vd->N!=0)
		vd_devp->d.vd->dix=g2_realloc(vd_devp->d.vd->dix,
					      vd_devp->d.vd->N*sizeof(int));
	    return;
	}

    __g2_last_device=vd_dev;
}
Exemplo n.º 8
0
/**
 *
 * Set QuasiPixel size and shape.
 *
 * \param dev device
 * \param d size
 * \param shape shape (rectangle or circle, see ::QPshape )
 *
 * \ingroup control
 */
void g2_set_QP(int dev, double d, enum QPshape shape)
{
    g2_device *devp;
    
    if((devp=g2_get_device_pointer(dev))==NULL) {
	fprintf(stderr, "g2_set_QP: No such device: %d\n", dev);
	return;
    }
    
    devp->QPd=d;
    devp->QPshape=shape;
    
    __g2_last_device=dev;
}
Exemplo n.º 9
0
/**
 *
 * Query pointer (e.g. mouse for X11) position and button state. See
 * the demo program pointer.c for an example.
 *
 * \param dev device
 * \param x returns pointer x coordinate
 * \param y returns pointer y coordinate
 * \param button returns button state
 *
 * \ingroup control
 */
void g2_query_pointer(int dev, double *x, double *y, unsigned int *button)
{
    g2_device *devp;
    
    if((devp=g2_get_device_pointer(dev))==NULL) {
	fprintf(stderr, "g2_query_pointer: No such device: %d\n", dev);
	return;
    }
    
    switch(devp->t) {
      case g2_PD:
	g2_query_pointer_pd(devp->d.pd, x, y, button);
	break;
      case g2_VD:
	break;
      case g2_ILLEGAL:
	break;
      case g2_NDEV:
	break;
    }   
    __g2_last_device=dev;
}