Beispiel #1
0
static void
DrawConnectingLine(Display *dpy,
                    Window win,
                    GC gc,
                    XRectangle *clipRect,
                    int oddFlag,
                    int x1,
                    int y1,
                    int x2,
                    int y2)
	{
	int i, x, y;
	XPoint points[100];

	i = 0;
	for (x = x1; x <= x2; x++)
		for (y = y1; y <= y2; y++)
			{
			if ((((x + oddFlag) & 1) == (y & 1)) ||
				x < clipRect->x ||
				x >= (clipRect->x + (int)clipRect->width) ||
				y < clipRect->y ||
				y >= (clipRect->y + (int)clipRect->height))
				continue;
			points[i].x = x;
			points[i].y = y;
			if (++i < 100)
				continue;
			XDrawPoints(dpy, win, gc, points, i, CoordModeOrigin);
			i = 0;
			}
	if (i)
		XDrawPoints(dpy, win, gc, points, i, CoordModeOrigin);
	}
Beispiel #2
0
ENTRYPOINT void
draw_fadeplot (ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	GC          gc = MI_GC(mi);
	int         i, j, temp;
	fadeplotstruct *fp;

	if (fadeplots == NULL)
		return;
	fp = &fadeplots[MI_SCREEN(mi)];
	if (fp->stab == NULL)
		return;

	MI_IS_DRAWN(mi) = True;
	XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
	XDrawPoints(display, window, gc, fp->pts, fp->maxpts, CoordModeOrigin);

	if (MI_NPIXELS(mi) > 2) {
		XSetForeground(display, gc, MI_PIXEL(mi, fp->pix));
		if (++fp->pix >= MI_NPIXELS(mi))
			fp->pix = 0;
	} else
		XSetForeground(display, gc, MI_WHITE_PIXEL(mi));

	temp = 0;
	for (j = 0; j < fp->nbstep; j++) {
		for (i = 0; i < fp->maxpts / fp->nbstep; i++) {
			fp->pts[temp].x =
				fp->stab[(fp->st.x + fp->speed.x * j + i * fp->step.x) % fp->angles] *
				fp->factor.x + fp->width / 2 - fp->min;
			fp->pts[temp].y =
				fp->stab[(fp->st.y + fp->speed.y * j + i * fp->step.y) % fp->angles] *
				fp->factor.y + fp->height / 2 - fp->min;
			temp++;
		}
	}
	XDrawPoints(display, window, gc, fp->pts, temp, CoordModeOrigin);
	fp->st.x = (fp->st.x + fp->speed.x) % fp->angles;
	fp->st.y = (fp->st.y + fp->speed.y) % fp->angles;
	fp->temps++;
	if ((fp->temps % (fp->angles / 2)) == 0) {
		fp->temps = fp->temps % fp->angles * 5;
		if ((fp->temps % (fp->angles)) == 0)
			fp->speed.y = (fp->speed.y + 1) % 30 + 1;
		if ((fp->temps % (fp->angles * 2)) == 0)
			fp->speed.x = (fp->speed.x) % 20;
		if ((fp->temps % (fp->angles * 3)) == 0)
			fp->step.y = (fp->step.y + 1) % 2 + 1;

		MI_CLEARWINDOW(mi);
	}
}
Beispiel #3
0
static void
fizzle (eraser_state *st)
{
  XPoint *points;
  int chunk = 20000;
  int npoints = st->width * st->height * 4;
  npoints *= (st->ratio - st->prev_ratio);

  points = (XPoint *) malloc (chunk * sizeof(*points));
  if (! points) return;

  while (npoints > 0)
    {
      int remain = (chunk > npoints ? npoints : chunk);
      int i;
      for (i = 0; i < remain; i++)
        {
          int r = random();
          points[i].x = r % st->width;
          points[i].y = (r >> 16) % st->height;
        }
      XDrawPoints (st->dpy, st->window, st->bg_gc, 
                   points, remain, CoordModeOrigin);
      npoints -= remain;
    }
  free (points);
}
Beispiel #4
0
static void dplot(int density, short x, short y, short w, short h)
{
   int n;
   int n_max, n_plot, flg[POINTS];
   int p;
   XPoint pos[POINTS];

   n_max = ++w * ++h;
   n_plot = (density * n_max) / LEVEL;

#if defined(HAVE_MEMSET)
   memset(flg, 0, sizeof(*flg) * POINTS);
#elif defined(HAVE_BZERO)
   bzero((char *) flg, sizeof(*flg) * POINTS);
#endif

   for (n = 0; n < n_plot; n++) {
      p = (int) (n_max * (double) rand() / (double) INT_MAX);
      if (flg[p] == 0) {
         flg[p] = 1;
         pos[n].x = x + (short) p % w;
         pos[n].y = y - (short) p / w;
      }
   }
   XDrawPoints(display, main_window, gc, pos, n_plot, CoordModeOrigin);
}
Beispiel #5
0
void
polypoint_test(void)
{
  XPoint *points;
  int num_points = 100000;
  long totaltime;
  char buf[80];
  int i;
  
  num_points *= X.percent;

  points = (XPoint *) malloc(sizeof(XPoint) * num_points);

  points[0].x = random()%400; points[0].y = random()%400;
  points[1].x = random()%400; points[1].y = random()%400;

  for (i=2;i<num_points;++i) {
    points[i].x = (points[i-1].x+points[i-2].y+i*3/200)%400;
    points[i].y = (points[i-1].y+points[i-2].x+i*5/200)%400;
  }

  XSync(X.dpy,0);
  start_timer();
  XDrawPoints(X.dpy,X.win,X.gc,points,num_points,CoordModeOrigin);
  XSync(X.dpy,0);
  totaltime = end_timer();

  snprintf(buf,sizeof buf,"%d points in %.3f seconds.",num_points,
	  (double)totaltime/1000000.);
  show_result(buf);

  free(points);
}
Beispiel #6
0
 void Graphics::DrawPoints(const vector<Point> & points)
 {
   this->PrepareGraphicsContext();
   XPoint* xPoints = this->GetTransformedXPoints(points);
   XDrawPoints(this->display, this->window, this->gc, xPoints, points.size(), CoordModeOrigin);
   delete[] xPoints;
   DebugDelay(string("DrawPoints"));
 }
Beispiel #7
0
/*ARGSUSED*/
static void 
draw_it(XtPointer client_data, XtIntervalId *id)
{
    StripChartWidget w = (StripChartWidget)client_data;
    double value;
   
    if (w->strip_chart.update > 0)
	w->strip_chart.interval_id =
	    XtAppAddTimeOut(XtWidgetToApplicationContext((Widget)w),
			    w->strip_chart.update * MS_PER_SEC,draw_it,
			    client_data);

    if (w->strip_chart.interval >= XtWidth(w))
	MoveChart((StripChartWidget)w, True);

    /* Get the value, stash the point and draw corresponding line */
    if (w->strip_chart.get_value == NULL)
	return;

    XtCallCallbacks((Widget)w, XtNgetValue, (XtPointer)&value);

    /* 
     * Keep w->strip_chart.max_value up to date, and if this data 
     * point is off the graph, change the scale to make it fit
     */
    if (value > w->strip_chart.max_value) {
	w->strip_chart.max_value = value;
	if (XtIsRealized((Widget)w) &&
	    w->strip_chart.max_value > w->strip_chart.scale) {
	    XClearWindow(XtDisplay(w), XtWindow(w));
	    w->strip_chart.interval = repaint_window(w, 0, XtWidth(w));
	}
    }

    w->strip_chart.valuedata[w->strip_chart.interval] = value;
    if (XtIsRealized((Widget)w)) {
	int y = (int)(XtHeight(w) - XtHeight(w) * value
		     / w->strip_chart.scale);

	XFillRectangle(XtDisplay(w), XtWindow(w), w->strip_chart.fgGC,
		       w->strip_chart.interval, y, 
		       1, XtHeight(w) - y);

	/*
	 * Fill in the graph lines we just painted over
	 */
	if (w->strip_chart.points != NULL) {
	    w->strip_chart.points[0].x = w->strip_chart.interval;
	    XDrawPoints(XtDisplay(w), XtWindow(w), w->strip_chart.hiGC,
			w->strip_chart.points, w->strip_chart.scale - 1,
			CoordModePrevious);
	}

	XFlush(XtDisplay(w));		    /* Flush output buffers */
    }
    w->strip_chart.interval++;		    /* Next point */
}
Beispiel #8
0
static void
fizzle (eraser_state *st)
{
#if 1	// hacked by katahiromz
  // NOTE: XDrawPoints is too slow in Win32
  XArc *arcs;
  int chunk = 1000;
  int n = 4;
  int narcs = st->width * st->height / 8;
  narcs *= (st->ratio - st->prev_ratio);

  arcs = (XArc *) calloc (chunk, sizeof(*arcs));
  if (! arcs) return;

  while (narcs > 0)
    {
      int remain = (chunk > narcs ? narcs : chunk);
      int i;
      for (i = 0; i < remain; i++)
        {
          int r = random();
          arcs[i].x = r % st->width - 4;
          arcs[i].y = (r >> 16) % st->height - 4;
          arcs[i].width = arcs[i].height = n;
        }
      XFillArcs(st->dpy, st->window, st->bg_gc, arcs, remain);
      narcs -= remain;
      n++;
    }
  free (arcs);
#else
  XPoint *points;
  int chunk = 20000;
  int npoints = st->width * st->height * 4;
  npoints *= (st->ratio - st->prev_ratio);

  points = (XPoint *) malloc (chunk * sizeof(*points));
  if (! points) return;

  while (npoints > 0)
    {
      int remain = (chunk > npoints ? npoints : chunk);
      int i;
      for (i = 0; i < remain; i++)
        {
          int r = random();
          points[i].x = r % st->width;
          points[i].y = (r >> 16) % st->height;
        }
      XDrawPoints (st->dpy, st->window, st->bg_gc, 
                   points, remain, CoordModeOrigin);
      npoints -= remain;
    }
  free (points);
#endif
}
Beispiel #9
0
void
draw_blot(ModeInfo * mi)
{
	blotstruct *bp;
	XPoint     *xp;
	int         x, y, k;

	if (blots == NULL)
		return;
	bp = &blots[MI_SCREEN(mi)];
	xp = bp->pointBuffer;
	if (xp == NULL)
		init_blot(mi);

	MI_IS_DRAWN(mi) = True;
	if (MI_NPIXELS(mi) > 2) {
		XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_PIXEL(mi, bp->pix));
		if (++bp->pix >= MI_NPIXELS(mi))
			bp->pix = 0;
	}
	x = bp->xmid;
	y = bp->ymid;
	k = bp->size;
	while (k >= 4) {
		x += (NRAND(1 + (bp->offset << 1)) - bp->offset);
		y += (NRAND(1 + (bp->offset << 1)) - bp->offset);
		k--;
		xp->x = x;
		xp->y = y;
		xp++;
		if (bp->xsym) {
			k--;
			xp->x = bp->width - x;
			xp->y = y;
			xp++;
		}
		if (bp->ysym) {
			k--;
			xp->x = x;
			xp->y = bp->height - y;
			xp++;
		}
		if (bp->xsym && bp->ysym) {
			k--;
			xp->x = bp->width - x;
			xp->y = bp->height - y;
			xp++;
		}
	}
	XDrawPoints(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi),
		    bp->pointBuffer, (bp->size - k), CoordModeOrigin);
	if (++bp->count > MI_CYCLES(mi))
		init_blot(mi);
}
Beispiel #10
0
void GFX_P_bouncePoint(struct OS_visual *os_visual,int color){
  if(os_visual->num_points[color]>0){
    GC gc=os_visual->gcs[color];
    XDrawPoints(
		x11_display,
		os_visual->pixmap,
		gc,
		os_visual->xpoints[color],
		os_visual->num_points[color],
		CoordModeOrigin
		);
    os_visual->num_points[color]=0;
  }
}
Beispiel #11
0
void
drawhop(Window win)
{
	double      oldj, oldi;
	XPoint     *xp = pointBuffer;
	hopstruct  *hp = &hops[screen];
	int         k = hp->bufsize;

	hp->inc++;
	if (!mono && Scr[screen].npixels > 2) {
		XSetForeground(dsp, Scr[screen].gc, Scr[screen].pixels[hp->pix]);
		if (++hp->pix >= Scr[screen].npixels)
			hp->pix = 0;
	}
	while (k--) {
		oldj = hp->j;
		switch (hp->op) {
			case SQRT:
				oldi = hp->i + hp->inc;
				hp->j = hp->a - hp->i;
				hp->i = oldj + ((hp->i < 0)
					   ? sqrt(fabs(hp->b * oldi - hp->c))
					: -sqrt(fabs(hp->b * oldi - hp->c)));
				xp->x = hp->centerx + (int) (hp->i + hp->j);
				xp->y = hp->centery - (int) (hp->i - hp->j);
				break;
			case SIN:
				oldi = hp->i + hp->inc;
				hp->j = hp->a - hp->i;
				hp->i = oldj - sin(oldi);
				xp->x = hp->centerx + (int) (hp->i + hp->j);
				xp->y = hp->centery - (int) (hp->i - hp->j);
				break;
			case JONG:
				oldi = hp->i + 4 * hp->inc / hp->centerx;
				hp->j = sin(hp->c * hp->i) - cos(hp->d * hp->j);
				hp->i = sin(hp->a * oldj) - cos(hp->b * oldi);
				// included parenthesis after (int) to get rid of warnings
				// epirker, 10-Jul-97
				xp->x = hp->centerx + (int) (hp->centerx * (hp->i + hp->j)) / 4;
				xp->y = hp->centery - (int) (hp->centery * (hp->i - hp->j)) / 4;
				break;
		}
		xp++;
	}
	XDrawPoints(dsp, win, Scr[screen].gc,
		    pointBuffer, hp->bufsize, CoordModeOrigin);
	if (++hp->count > cycles )
		inithop(win);
}
Beispiel #12
0
void 
DoDots(XParms xp, Parms p, int reps)
{
    int     i;

    for (i = 0; i != reps; i++) {
        XDrawPoints(xp->d, xp->w, pgc, points, p->objects, CoordModeOrigin);
        if (pgc == xp->bggc)
            pgc = xp->fggc;
        else
            pgc = xp->bggc;
	CheckAbort ();
    }
}
Beispiel #13
0
static void
draw_field(struct state *st, struct field * f)
{
    unsigned int x, y;
    unsigned int rx, ry = 0;	/* random amount to offset the dot */
    unsigned int size = 1 << f->cell_size;
    unsigned int mask = size - 1;
    unsigned int fg_count, bg_count;

    /* columns 0 and width-1 are off screen and not drawn. */
    for (y = 1; y < f->height - 1; y++) {
	fg_count = 0;
	bg_count = 0;

	/* rows 0 and height-1 are off screen and not drawn. */
	for (x = 1; x < f->width - 1; x++) {
	    rx = random();
	    ry = rx >> f->cell_size;
	    rx &= mask;
	    ry &= mask;

	    if (*cell_at(f, x, y)) {
		st->fg_points[fg_count].x = (short) x *size - rx - 1;
		st->fg_points[fg_count].y = (short) y *size - ry - 1;
		fg_count++;
	    } else {
		st->bg_points[bg_count].x = (short) x *size - rx - 1;
		st->bg_points[bg_count].y = (short) y *size - ry - 1;
		bg_count++;
	    }
	}
	XDrawPoints(st->dpy, st->window, st->fgc, st->fg_points, fg_count,
		    CoordModeOrigin);
	XDrawPoints(st->dpy, st->window, st->bgc, st->bg_points, bg_count,
		    CoordModeOrigin);
    }
}
Beispiel #14
0
static int
X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
                     int count)
{
    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
    SDL_Window *window = renderer->window;
    unsigned long foreground;
    XPoint *xpoints, *xpoint;
    int i, xcount;

    if (data->makedirty) {
        SDL_Rect rect;

        /* Get the smallest rectangle that contains everything */
        rect.x = 0;
        rect.y = 0;
        rect.w = window->w;
        rect.h = window->h;
        if (!SDL_EnclosePoints(points, count, &rect, &rect)) {
            /* Nothing to draw */
            return 0;
        }
        SDL_AddDirtyRect(&data->dirty, &rect);
    }

    foreground = renderdrawcolor(renderer, 1);
    XSetForeground(data->display, data->gc, foreground);

    xpoint = xpoints = SDL_stack_alloc(XPoint, count);
    xcount = 0;
    for (i = 0; i < count; ++i) {
        int x = points[i].x;
        int y = points[i].y;
        if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
            continue;
        }
        xpoint->x = (short)x;
        xpoint->y = (short)y;
        ++xpoint;
        ++xcount;
    }
    if (xcount > 0) {
        XDrawPoints(data->display, data->drawable, data->gc, xpoints, xcount,
                    CoordModeOrigin);
    }
    SDL_stack_free(xpoints);

    return 0;
}
Beispiel #15
0
/* draw float points (with clipping) */
void FXDrawPoints(Display *display, Drawable d, FGC fgc, 
	FXPoint fpoints[], int npoints, int mode)
{
	int i,nbuf;
	FXPoint *fbuf;
	XPoint *points,pbuf[NPBUF];
	if (npoints>NPBUF)
		points = (XPoint *)malloc(npoints*sizeof(*points));
	else
		points = pbuf;
	if (fgc->clip) {
		fbuf = malloc(npoints*sizeof(*fbuf));
		for (i=nbuf=0; i<npoints; ++i)
			if (FClipPoint(fgc,fpoints[i].fx,fpoints[i].fy))
				fbuf[nbuf++] = fpoints[i];
		FMapFPoints(fgc,fbuf,nbuf,points);
		XDrawPoints(display,d,fgc->gc,points,nbuf,mode);
		free(fbuf);
	} else {
		FMapFPoints(fgc,fpoints,npoints,points);
		XDrawPoints(display,d,fgc->gc,points,npoints,mode);
	}
	if (npoints>NPBUF) free(points);
}
Beispiel #16
0
/** Render list of points, \a pptInit in \a pDrawable on the back-end
 *  server associated with \a pDrawable's screen.  If the offscreen
 *  optimization is enabled, only draw when \a pDrawable is at least
 *  partially visible. */
void dmxPolyPoint(DrawablePtr pDrawable, GCPtr pGC,
		  int mode, int npt, DDXPointPtr pptInit)
{
    DMXScreenInfo *dmxScreen = &dmxScreens[pDrawable->pScreen->myNum];
    dmxGCPrivPtr   pGCPriv = DMX_GET_GC_PRIV(pGC);
    Drawable       draw;

    if (DMX_GCOPS_OFFSCREEN(pDrawable)) return;

    DMX_GCOPS_SET_DRAWABLE(pDrawable, draw);

    XDrawPoints(dmxScreen->beDisplay, draw, pGCPriv->gc,
		(XPoint *)pptInit, npt, mode);
    dmxSync(dmxScreen, FALSE);
}
Beispiel #17
0
void
p_dots(p_win *w)
{
  p_scr *s = w->s;
  Display *dpy = s->xdpy->dpy;
  GC gc = x_getgc(s, w, FillSolid);
  int nmx = XMaxRequestSize(dpy)-3;
  int n = x_pt_count;
  x_pt_count = 0;
  while (n>0) {
    if (n<nmx) nmx = n;
    XDrawPoints(dpy, w->d, gc, x_pt_list, nmx, CoordModeOrigin);
    n -= nmx;
  }
  if (p_signalling) p_abort();
}
Beispiel #18
0
static void
rorschach_draw_step (Display *dpy, Window window, struct state *st)
{
# define ITER_CHUNK 300
  XPoint points [4 * ITER_CHUNK];
  int x = st->current_x;
  int y = st->current_y;
  int i, j = 0;

  int this_iterations = ITER_CHUNK;
  if (this_iterations > st->remaining_iterations)
    this_iterations = st->remaining_iterations;

  for (i = 0; i < this_iterations; i++)
    {
      x += ((random () % (1 + (st->offset << 1))) - st->offset);
      y += ((random () % (1 + (st->offset << 1))) - st->offset);
      points [j].x = x;
      points [j].y = y;
      j++;
      if (st->xsym)
	{
	  points [j].x = st->xlim - x;
	  points [j].y = y;
	  j++;
	}
      if (st->ysym)
	{
	  points [j].x = x;
	  points [j].y = st->ylim - y;
	  j++;
	}
      if (st->xsym && st->ysym)
	{
	  points [j].x = st->xlim - x;
	  points [j].y = st->ylim - y;
	  j++;
	}
    }
  XDrawPoints (dpy, window, st->draw_gc, points, j, CoordModeOrigin);
  st->remaining_iterations -= this_iterations;
  if (st->remaining_iterations < 0) st->remaining_iterations = 0;
  st->current_x = x;
  st->current_y = y;
}
void
DisplayX11::draw_points( DisplayObject * d_obj,
                         const RGBcolor & col,
                         const int num,
                         const Point2d * vec )
{
    D_XPoints * myobj;

    if ( ! d_obj )
    {
        if ( d_xpoints.pp.max_size < num )
        {
            d_xpoints.pp.set_max_size( num );
        }

        d_xpoints.pp.set_cur_size( num );

        myobj = &d_xpoints;
        myobj->mark_col_change();
        myobj->mark_pos_change();
    }
    else
    {
        myobj = static_cast< D_XPoints * >( d_obj ); //dynamic_cast should also work, but it doesn't <- why?
    }


    //here we have the assumption num= myobj->pp.max_size; i.e. the it is not allowed to change the number of points

    if ( myobj->col_change )
    {
        myobj->col_change = false;
        myobj->XColor_pixel = AGetColor( col );
    }

    if ( myobj->area_number != area_number )
    {
        myobj->area_number = area_number;
        copy_2_XPoints( myobj->pp.tab, num, vec );
    }

    ASetForeground( myobj->XColor_pixel );

    XDrawPoints( disp, pixmap, gc, myobj->pp.tab, num, CoordModeOrigin );
}
Beispiel #20
0
static PyObject *
PaxGC_DrawPoints(PaxGCObject * self, PyObject *args)
{
	PyObject *arg1; XPoint *pts_arg1; int npts_arg1;
	int arg2;
	if (!PyArg_ParseTuple(args, "Oi",
			&arg1,
			&arg2))
		return NULL;
	if (!checkshortlist(2, arg1, (short**)&pts_arg1, &npts_arg1)) {
		if (!PyErr_Occurred())
			PyErr_SetString(PyExc_TypeError, "arg1 should be XPoint[]");
		return NULL;
	}
XDrawPoints(self->display, self->drawable, self->gc,
			pts_arg1, npts_arg1,
			arg2);
	PyMem_Free(pts_arg1);
	Py_INCREF(Py_None);
	return Py_None;
}
Beispiel #21
0
ENTRYPOINT void
draw_sierpinski(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	GC          gc = MI_GC(mi);
	XPoint     *xp[MAXCORNERS];
	int         i, v;
	sierpinskistruct *sp;

	if (tris == NULL)
		return;
	sp = &tris[MI_SCREEN(mi)];
	if (sp->pointBuffer[0] == NULL)
		return;

	MI_IS_DRAWN(mi) = True;
	if (MI_NPIXELS(mi) <= 2)
		XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
	for (i = 0; i < sp->corners; i++)
		xp[i] = sp->pointBuffer[i];
	for (i = 0; i < sp->total_npoints; i++) {
		v = NRAND(sp->corners);
		sp->px = (sp->px + sp->vertex[v].x) / 2;
		sp->py = (sp->py + sp->vertex[v].y) / 2;
		xp[v]->x = sp->px;
		xp[v]->y = sp->py;
		xp[v]++;
		sp->npoints[v]++;
	}
	for (i = 0; i < sp->corners; i++) {
		if (MI_NPIXELS(mi) > 2)
			XSetForeground(display, gc, MI_PIXEL(mi, sp->colors[i]));
		XDrawPoints(display, MI_WINDOW(mi), gc, sp->pointBuffer[i], sp->npoints[i],
			    CoordModeOrigin);
		sp->npoints[i] = 0;
	}
	if (++sp->time >= MI_CYCLES(mi))
		startover(mi);
}
void
JXGC::DrawLine
	(
	const Drawable		drawable,
	const JCoordinate	x1,
	const JCoordinate	y1,
	const JCoordinate	x2,
	const JCoordinate	y2
	)
	const
{
	XDrawLine(*itsDisplay, drawable, itsXGC, x1,y1, x2,y2);

	if (itsLastLineWidth == 1)		// X sometimes doesn't draw either end point
		{
		XPoint pt[2];	// initialization with { ... } causes core dump
		pt[0].x = x1;
		pt[0].y = y1;
		pt[1].x = x2;
		pt[1].y = y2;
		XDrawPoints(*itsDisplay, drawable, itsXGC, pt, 2, CoordModeOrigin);
		}
}
Beispiel #23
0
void display_iteration() 
     /* Siempre hay una estructura grafica con todo lo que debe estar en pantalla. Permite el pintado incremental para los buffers de puntos, borran el incremento viejo y pintan solo el nuevo */
{
  int i;
  Tvoxel kaka;
 
 
  fl_winset(canvas_win); 
  
 if ((track_robot==TRUE)&&
     ((fabs(robot[0]+odometrico[0])>(rango/4.))||
      (fabs(robot[1]+odometrico[1])>(rango/4.))))
   {odometrico[0]=-robot[0];
   odometrico[1]=-robot[1];
   visual_refresh = TRUE;
   if (debug[SCH_GUIXFORMS]) printf("gui: robot tracking, display movement\n"); 
     }

 if (iteracion_display*guixforms_cycle>FORCED_REFRESH) 
   {iteracion_display=0;
   visual_refresh=TRUE;
   }
 else iteracion_display++;


 if (visual_refresh==TRUE)
   {
     if (debug[SCH_GUIXFORMS]) printf(" TOTAL ");
     fl_rectbound(0,0,width,height,FL_WHITE);   
     XFlush(display);
     /*XSync(display,True);*/
   }
 
 
 /* VISUALIZACION de una instantanea ultrasonica */
   if ((((display_state&DISPLAY_SONARS)!=0)&&(visual_refresh==FALSE))
      || (visual_delete_us==TRUE))
     {  
    fl_set_foreground(canvas_gc,FL_WHITE); 
    /* clean last sonars, but only if there wasn't a total refresh. In case of total refresh the white rectangle already cleaned all */
  for(i=0;i<NUM_SONARS*2;i+=2) XDrawLine(display,canvas_win,canvas_gc,us_dpy[i].x,us_dpy[i].y,us_dpy[i+1].x,us_dpy[i+1].y);

     }

  if ((display_state&DISPLAY_SONARS)!=0){
   if (debug[SCH_GUIXFORMS]) printf(" sonars ");
  for(i=0;i<NUM_SONARS;i++)
      {us2xy(i,0.,0.,&kaka); /* Da en el Tvoxel kaka las coordenadas del sensor, pues es distancia 0 */
      xy2canvas(kaka,&us_dpy[2*i]);
      us2xy(i,us[i],0.,&kaka);
      /*us2xy(i,200,0.,&kaka);
	if (i==6) us2xy(i,400,0.,&kaka);*/
      xy2canvas(kaka,&us_dpy[2*i+1]);
      }
  fl_set_foreground(canvas_gc,FL_PALEGREEN);
  for(i=0;i<NUM_SONARS*2;i+=2) XDrawLine(display,canvas_win,canvas_gc,us_dpy[i].x,us_dpy[i].y,us_dpy[i+1].x,us_dpy[i+1].y);
  }

 /* VISUALIZACION de una instantanea laser*/
   if ((((display_state&DISPLAY_LASER)!=0)&&(visual_refresh==FALSE))
      || (visual_delete_laser==TRUE))
     {  
    fl_set_foreground(canvas_gc,FL_WHITE); 
    /* clean last laser, but only if there wasn't a total refresh. In case of total refresh the white rectangle already cleaned all */
    /*for(i=0;i<NUM_LASER;i++) XDrawPoint(display,canvas_win,canvas_gc,laser_dpy[i].x,laser_dpy[i].y);*/
    XDrawPoints(display,canvas_win,canvas_gc,laser_dpy,NUM_LASER,CoordModeOrigin);
     }

  if ((display_state&DISPLAY_LASER)!=0){
   if (debug[SCH_GUIXFORMS]) printf(" laser ");
   for(i=0;i<NUM_LASER;i++)
     {
       laser2xy(i,laser[i],&kaka);
       xy2canvas(kaka,&laser_dpy[i]);
     }
   fl_set_foreground(canvas_gc,FL_BLUE);
   /*for(i=0;i<NUM_LASER;i++) XDrawPoint(display,canvas_win,canvas_gc,laser_dpy[i].x,laser_dpy[i].y);*/
   XDrawPoints(display,canvas_win,canvas_gc,laser_dpy,NUM_LASER,CoordModeOrigin);
  }




  /* VISUALIZACION: pintar o borrar de el PROPIO ROBOT.
     Siempre hay un repintado total. Esta es la ultima estructura que se se pinta, para que ninguna otra se solape encima */

   if ((((display_state&DISPLAY_ROBOT)!=0) &&(visual_refresh==FALSE))
       || (visual_delete_ego==TRUE))
     {  
      fl_set_foreground(canvas_gc,FL_WHITE); 
    /* clean last robot, but only if there wasn't a total refresh. In case of total refresh the white rectangle already cleaned all */
    for(i=0;i<numego;i++) XDrawLine(display,canvas_win,canvas_gc,ego[i].x,ego[i].y,ego[i+1].x,ego[i+1].y);

     }

  if ((display_state&DISPLAY_ROBOT)!=0){
    if (debug[SCH_GUIXFORMS]) printf(" ego ");
    fl_set_foreground(canvas_gc,FL_MAGENTA);
 /* relleno los nuevos */
    us2xy(15,0.,0.,&kaka);
    xy2canvas(kaka,&ego[0]);
    us2xy(3,0.,0.,&kaka);
    xy2canvas(kaka,&ego[1]);
    us2xy(4,0.,0.,&kaka);
    xy2canvas(kaka,&ego[2]);
    us2xy(8,0.,0.,&kaka);
    xy2canvas(kaka,&ego[3]);
    us2xy(15,0.,0.,&kaka);
    xy2canvas(kaka,&ego[EGOMAX-1]);
    for(i=0;i<NUM_SONARS;i++)
      {
      us2xy((15+i)%NUM_SONARS,0.,0.,&kaka); /* Da en el Tvoxel kaka las coordenadas del sensor, pues es distancia 0 */
      xy2canvas(kaka,&ego[i+4]);       
      }
 
    /* pinto los nuevos */
    numego=EGOMAX-1;
    for(i=0;i<numego;i++) XDrawLine(display,canvas_win,canvas_gc,ego[i].x,ego[i].y,ego[i+1].x,ego[i+1].y);
  }

  if (debug[SCH_GUIXFORMS]) printf("\n");



  /* grey imageA display */
  if (((display_state&DISPLAY_GREYIMAGEA)!=0)&&((display_state&DISPLAY_COLORIMAGEA)==0))
     {
       /* Pasa de la imagen capturada (greyA) a la imagen para visualizar (imagenA_buf), "cambiando" de formato adecuadamente */
       if ((vmode==PseudoColor)&&(fl_state[vmode].depth==8))
	 {for(i=0; i<SIFNTSC_ROWS*SIFNTSC_COLUMNS; i++) 
	   {/*shmimage->data[i]= (unsigned char)tabla[(unsigned char)(greyA[i])];*/
	     imagenA_buf[i]= (unsigned char)tabla[(unsigned char)(greyA[i])];}}
       else if ((vmode==TrueColor)&&(fl_state[vmode].depth==16)) 
	 {
	   for(i=0; i<SIFNTSC_ROWS*SIFNTSC_COLUMNS; i++)
	     { imagenA_buf[i*2+1]=(0xf8&(greyA[i]))+((0xe0&(greyA[i]))>>5);
	     imagenA_buf[i*2]=((0xf8&(greyA[i]))>>3)+((0x1c&(greyA[i]))<<3);
	     }
	 }
       else if ((vmode==TrueColor)&&(fl_state[vmode].depth==24)) 
	 {for(i=0; i<SIFNTSC_ROWS*SIFNTSC_COLUMNS; i++) 
	   { imagenA_buf[i*4]=greyA[i]; /* Blue Byte */
	   imagenA_buf[i*4+1]=greyA[i]; /* Green Byte */
	   imagenA_buf[i*4+2]=greyA[i]; /* Red Byte */
	   imagenA_buf[i*4+3]=0; /* dummy byte */  }
	 }
     }
Beispiel #24
0
ENTRYPOINT void
draw_thornbird(ModeInfo * mi)
{
	Display    *dsp = MI_DISPLAY(mi);
	Window      win = MI_WINDOW(mi);
	double      oldj, oldi;
	int         batchcount = MI_COUNT(mi);
	int         k;
	XPoint     *xp;
	GC          gc = MI_GC(mi);
	int         erase;
	int         current;

	double      sint, cost, sinp, cosp;
	thornbirdstruct *hp;

	if (thornbirds == NULL)
		return;
	hp = &thornbirds[MI_SCREEN(mi)];
	if (hp->pointBuffer == NULL)
		return;

	erase = (hp->inc + 1) % MI_CYCLES(mi);
	current = hp->inc % MI_CYCLES(mi);
	k = batchcount;


	xp = hp->pointBuffer[current];

	/* vary papameters */
	hp->a = 1.99 + (0.4 * sin(hp->inc / hp->liss.f1) +
					0.05 * cos(hp->inc / hp->liss.f2));
	hp->c = 0.80 + (0.15 * cos(hp->inc / hp->liss.f1) +
					0.05 * sin(hp->inc / hp->liss.f2));

	/* vary view */
	hp->tumble.theta += hp->tumble.dtheta;
	hp->tumble.phi += hp->tumble.dphi;
	sint = sin(hp->tumble.theta);
	cost = cos(hp->tumble.theta);
	sinp = sin(hp->tumble.phi);
	cosp = cos(hp->tumble.phi);

	while (k--) {
		oldj = hp->j;
		oldi = hp->i;

		hp->j = oldi;
		hp->i = (1 - hp->c) * cos(M_PI * hp->a * oldj) + hp->c * hp->b;
		hp->b = oldj;

		xp->x = (short)
		  (hp->maxx / 2 * (1
						   + sint*hp->j + cost*cosp*hp->i - cost*sinp*hp->b));
		xp->y = (short)
		  (hp->maxy / 2 * (1
						   - cost*hp->j + sint*cosp*hp->i - sint*sinp*hp->b));
		xp++;
	}

	MI_IS_DRAWN(mi) = True;

	if (hp->pointBuffer[erase] == NULL) {
		if ((hp->pointBuffer[erase] = (XPoint *) malloc(MI_COUNT(mi) *
				sizeof (XPoint))) == NULL) {
			free_thornbird(hp);
			return;
		}
	} else {
		XSetForeground(dsp, gc, MI_BLACK_PIXEL(mi));
		XDrawPoints(dsp, win, gc, hp->pointBuffer[erase],
			    batchcount, CoordModeOrigin);
	}
	if (MI_NPIXELS(mi) > 2) {
		XSetForeground(dsp, gc, MI_PIXEL(mi, hp->pix));
#if 0
		if (erase == 0) /* change colours after "cycles" cycles */
#else
        if (!((hp->inc + 1) % (1 + (MI_CYCLES(mi) / 3)))) /* jwz: sooner */
#endif
			if (++hp->pix >= MI_NPIXELS(mi))
				hp->pix = 0;
	} else
		XSetForeground(dsp, gc, MI_WHITE_PIXEL(mi));

	XDrawPoints(dsp, win, gc, hp->pointBuffer[current],
		    batchcount, CoordModeOrigin);
	hp->inc++;

}
Beispiel #25
0
int main(int argc, char* argv[]) {
  
  struct body a = {2, 2, 0, 0, 0, 0, 0};
  struct body b = {1, 1, 0, 0, 0, 0, 0};

  int N = 200;
  int iter = 1000;
  if(argc == 1) {
    float dist = distance (a, b);
    printf("Test distance: %f\n", dist);
  }
  
  if(argc == 3)
    {
      N = atoi(argv[1]);
      iter = atoi(argv[2]);
    }

#ifdef ANIMATE
  XPoint* points = malloc(sizeof(XPoint)*N);
  Display* disp;
  Window window, rootwin;
  int screen;

  disp = XOpenDisplay(NULL);
  screen = DefaultScreen(disp);
  rootwin = RootWindow(disp,screen);
  window = XCreateSimpleWindow(disp,rootwin,
                               0,0,X_SIZE,Y_SIZE,1,0,0);
  GC gc = XCreateGC(disp, window, 0, 0);
  XSetForeground(disp, gc, WhitePixel(disp, screen));
  XSetBackground(disp, gc, BlackPixel(disp, screen));
  XMapWindow(disp,window);

  XClearWindow(disp,window);	
	
  copyToXBuffer(star, points, N);
  XDrawPoints(disp, window, gc, points, N, 0);

  XFlush(disp);

#endif

  clock_t start = clock();
  for(int i = 0; i < iter; i++)
    {

#ifdef ANIMATE
      copyToXBuffer(star, points, N);
      XDrawPoints(disp, window, gc, points, N, CoordModeOrigin);
      XClearWindow(disp,window);	
#endif
    }
  clock_t stop = clock();
  float diff = (float)(stop - start)/CLOCKS_PER_SEC;
  printf("Total: %lf seconds\n",diff);
  printf("Bodies: %d\n",N);
  printf("Iterations: %d\n", iter);

#ifdef ANIMATE
  XCloseDisplay(disp);
#endif

  return 0;
}
Beispiel #26
0
ENTRYPOINT void
draw_strange(ModeInfo * mi)
{
	int         i, j, n, Cur_Pt;
	PRM         x, y, xo, yo;
	DBL         u;
	XPoint     *Buf;
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	GC          gc = MI_GC(mi);
	DBL         Lx, Ly;
	void        (*Iterate) (ATTRACTOR *, PRM, PRM, PRM *, PRM *);
	PRM         xmin, xmax, ymin, ymax;
	ATTRACTOR  *A;

	if (Root == NULL)
		return;
	A = &Root[MI_SCREEN(mi)];
	if (A->Fold == NULL)
		return;

	Cur_Pt = A->Cur_Pt;
	Iterate = A->Iterate;

	u = (DBL) (A->Count) / 1000.0;
	for (j = MAX_PRM - 1; j >= 0; --j)
		A->Prm[j] = DBL_To_PRM((1.0 - u) * A->Prm1[j] + u * A->Prm2[j]);

	x = y = DBL_To_PRM(.0);
	for (n = SKIP_FIRST; n; --n) {
		(*Iterate) (A, x, y, &xo, &yo);
		x = xo + NRAND(8) - 4;
		y = yo + NRAND(8) - 4;
	}

	xmax = 0;
	xmin = UNIT * 4;
	ymax = 0;
	ymin = UNIT * 4;
	A->Cur_Pt = 0;
	Buf = A->Buffer2;
	Lx = (DBL) A->Width / UNIT / 2.2;
	Ly = (DBL) A->Height / UNIT / 2.2;
	for (n = A->Max_Pt; n; --n) {
		(*Iterate) (A, x, y, &xo, &yo);
		Buf->x = (int) (Lx * (x + DBL_To_PRM(1.1)));
		Buf->y = (int) (Ly * (DBL_To_PRM(1.1) - y));
		/* (void) fprintf( stderr, "X,Y: %d %d    ", Buf->x, Buf->y ); */
		Buf++;
		A->Cur_Pt++;
		if (xo > xmax)
			xmax = xo;
		else if (xo < xmin)
			xmin = xo;
		if (yo > ymax)
			ymax = yo;
		else if (yo < ymin)
			ymin = yo;
		x = xo + NRAND(8) - 4;
		y = yo + NRAND(8) - 4;
	}

	MI_IS_DRAWN(mi) = True;

	XSetForeground(display, gc, MI_BLACK_PIXEL(mi));

	if (A->dbuf != None) {		/* jwz */
		XSetForeground(display, A->dbuf_gc, 0);
/* XDrawPoints(display, A->dbuf, A->dbuf_gc, A->Buffer1,
   Cur_Pt,CoordModeOrigin); */
		XFillRectangle(display, A->dbuf, A->dbuf_gc, 0, 0, A->Width, A->Height);
	} else
		XDrawPoints(display, window, gc, A->Buffer1, Cur_Pt, CoordModeOrigin);

	if (MI_NPIXELS(mi) < 2)
		XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
	else
		XSetForeground(display, gc, MI_PIXEL(mi, A->Col % MI_NPIXELS(mi)));

	if (A->dbuf != None) {
		XSetForeground(display, A->dbuf_gc, 1);
		XDrawPoints(display, A->dbuf, A->dbuf_gc, A->Buffer2, A->Cur_Pt,
			    CoordModeOrigin);
		XCopyPlane(display, A->dbuf, window, gc, 0, 0, A->Width, A->Height, 0, 0, 1);
	} else
		XDrawPoints(display, window, gc, A->Buffer2, A->Cur_Pt, CoordModeOrigin);

	Buf = A->Buffer1;
	A->Buffer1 = A->Buffer2;
	A->Buffer2 = Buf;

	if ((xmax - xmin < DBL_To_PRM(.2)) && (ymax - ymin < DBL_To_PRM(.2)))
		A->Count += 4 * A->Speed;
	else
		A->Count += A->Speed;
	if (A->Count >= 1000) {
		for (i = MAX_PRM - 1; i >= 0; --i)
			A->Prm1[i] = A->Prm2[i];
		Random_Prm(A->Prm2);
		A->Count = 0;
	}
	A->Col++;
}
Beispiel #27
0
static void Paint_world_radar_old(void)
{
    int			i, xi, yi, xm, ym, xp, yp = 0;
    int			xmoff, xioff;
    int			type, vis;
    double		damage;
    double		xs, ys;
    int			npoint = 0, nsegment = 0;
    int			start, end;
    int			currColor, visibleColorChange;
    const int		max = 256;
    u_byte		visible[256];
    u_byte		visibleColor[256];
    XSegment		segments[256];
    XPoint		points[256];

    radar_exposures = 2;

    if (radarPixmap2 == radarPixmap)
	XSetPlaneMask(dpy, radarGC,
		      AllPlanes & ~(dpl_1[0] | dpl_1[1]));

    if (radarPixmap2 != radarWindow) {
	/* Clear radar */
	XSetForeground(dpy, radarGC, colors[BLACK].pixel);
	XFillRectangle(dpy, radarPixmap2, radarGC, 0, 0, 256, RadarHeight);
    } else
	XClearWindow(dpy, radarWindow);

    /*
     * Calculate an array which is later going to be indexed
     * by map block type.  The indexing should return a true
     * value when the map block should be visible on the radar
     * and a false value otherwise.
     */
    memset(visible, 0, sizeof visible);
    visible[SETUP_FILLED] = 1;
    visible[SETUP_FILLED_NO_DRAW] = 1;
    visible[SETUP_REC_LU] = 1;
    visible[SETUP_REC_RU] = 1;
    visible[SETUP_REC_LD] = 1;
    visible[SETUP_REC_RD] = 1;
    visible[SETUP_FUEL] = 1;
    for (i = 0; i < 10; i++)
	visible[SETUP_TARGET+i] = 1;

    for (i = BLUE_BIT; i < (int)sizeof visible; i++)
	visible[i] = 1;

    if (instruments.showDecor) {
	visible[SETUP_DECOR_FILLED] = 1;
	visible[SETUP_DECOR_LU] = 1;
	visible[SETUP_DECOR_RU] = 1;
	visible[SETUP_DECOR_LD] = 1;
	visible[SETUP_DECOR_RD] = 1;
    }

    /*
     * Calculate an array which returns the color to use
     * for drawing when indexed with a map block type.
     */
    memset(visibleColor, 0, sizeof visibleColor);
    visibleColor[SETUP_FILLED] =
	visibleColor[SETUP_FILLED_NO_DRAW] =
	visibleColor[SETUP_REC_LU] =
	visibleColor[SETUP_REC_RU] =
	visibleColor[SETUP_REC_LD] =
	visibleColor[SETUP_REC_RD] =
	visibleColor[SETUP_FUEL] = wallRadarColor;
    for (i = 0; i < 10; i++)
	visibleColor[SETUP_TARGET+i] = targetRadarColor;

    for (i = BLUE_BIT; i < (int)sizeof visible; i++)
	visibleColor[i] = wallRadarColor;

    if (instruments.showDecor)
	visibleColor[SETUP_DECOR_FILLED] =
	    visibleColor[SETUP_DECOR_LU] =
	    visibleColor[SETUP_DECOR_RU] =
	    visibleColor[SETUP_DECOR_LD] =
	    visibleColor[SETUP_DECOR_RD] = decorRadarColor;

    /* The following code draws the map on the radar.  Segments and
     * points arrays are use to build lists of things to be drawn.
     * Normally the segments and points are drawn when the arrays are
     * full, but now they are also drawn when the color changes.  The
     * visibleColor array is used to determine the color to be used
     * for the given visible block type.
     *
     * Another (and probably better) way to do this would be use
     * different segments and points arrays for each visible color.
     */
    if (Setup->x >= 256) {
	xs = (double)(256 - 1) / (Setup->x - 1);
	ys = (double)(RadarHeight - 1) / (Setup->y - 1);
	currColor = -1;
	for (xi = 0; xi < Setup->x; xi++) {
	    start = end = -1;
	    xp = (int)(xi * xs + 0.5);
	    xioff = xi * Setup->y;
	    for (yi = 0; yi < Setup->y; yi++) {
		visibleColorChange = 0;
		type = Setup->map_data[xioff + yi];
		if (type >= SETUP_TARGET && type < SETUP_TARGET + 10)
		    vis = (Target_alive(xi, yi, &damage) == 0);
		else
		    vis = visible[type];

		if (vis) {
		    yp = (int)(yi * ys + 0.5);
		    if (start == -1) {
			if ((nsegment > 0 || npoint > 0)
			    && currColor != visibleColor[type]) {
			    if (nsegment > 0) {
				XDrawSegments(dpy, radarPixmap2, radarGC,
					      segments, nsegment);
				nsegment = 0;
			    }
			    if (npoint > 0) {
				XDrawPoints(dpy, radarPixmap2, radarGC,
					    points, npoint, CoordModeOrigin);
				npoint = 0;
			    }
			}
			start = end = yp;
			currColor = visibleColor[type];
			XSetForeground(dpy, radarGC, colors[currColor].pixel);
		    } else {
			end = yp;
			visibleColorChange = (visibleColor[type] != currColor);
		    }
		}

		if (start != -1
		    && (!vis || yi == Setup->y - 1 || visibleColorChange)) {
		    if (end > start) {
			segments[nsegment].x1 = xp;
			segments[nsegment].y1 = RadarHeight - 1 - start;
			segments[nsegment].x2 = xp;
			segments[nsegment].y2 = RadarHeight - 1 - end;
			nsegment++;
			if (nsegment >= max || yi == Setup->y - 1) {
			    XDrawSegments(dpy, radarPixmap2, radarGC,
					  segments, nsegment);
			    nsegment = 0;
			}
		    } else {
			points[npoint].x = xp;
			points[npoint].y = RadarHeight - 1 - start;
			npoint++;
			if (npoint >= max || yi == Setup->y - 1) {
			    XDrawPoints(dpy, radarPixmap2, radarGC,
					points, npoint, CoordModeOrigin);
			    npoint = 0;
			}
		    }
		    start = end = -1;
		}

		if (visibleColorChange) {
		    if (nsegment > 0) {
			XDrawSegments(dpy, radarPixmap2, radarGC,
				      segments, nsegment);
			nsegment = 0;
		    }
		    if (npoint > 0) {
			XDrawPoints(dpy, radarPixmap2, radarGC,
				    points, npoint, CoordModeOrigin);
			npoint = 0;
		    }
		    start = end = yp;
		    currColor = visibleColor[type];
		    XSetForeground(dpy, radarGC, colors[currColor].pixel);
		}
	    }
	}
    } else {
	xs = (double)(Setup->x - 1) / (256 - 1);
	ys = (double)(Setup->y - 1) / (RadarHeight - 1);
	currColor = -1;
	for (xi = 0; xi < 256; xi++) {
	    xm = (int)(xi * xs + 0.5);
	    xmoff = xm * Setup->y;
	    start = end = -1;
	    xp = xi;
	    for (yi = 0; yi < (int)RadarHeight; yi++) {
		visibleColorChange = 0;
		ym = (int)(yi * ys + 0.5);
		type = Setup->map_data[xmoff + ym];
		vis = visible[type];
		if (type >= SETUP_TARGET && type < SETUP_TARGET + 10)
		    vis = (Target_alive(xm, ym, &damage) == 0);
		if (vis) {
		    yp = yi;
		    if (start == -1) {
			if ((nsegment > 0 || npoint > 0)
			    && currColor != visibleColor[type]) {
			    if (nsegment > 0) {
				XDrawSegments(dpy, radarPixmap2, radarGC,
					      segments, nsegment);
				nsegment = 0;
			    }
			    if (npoint > 0) {
				XDrawPoints(dpy, radarPixmap2, radarGC,
					    points, npoint, CoordModeOrigin);
				npoint = 0;
			    }
			}
			start = end = yp;
			currColor = visibleColor[type];
			XSetForeground(dpy, radarGC, colors[currColor].pixel);
		    } else {
			end = yp;
			visibleColorChange = visibleColor[type] != currColor;
		    }
		}

		if (start != -1
		    && (!vis || yi == (int)RadarHeight - 1
			|| visibleColorChange)) {
		    if (end > start) {
			segments[nsegment].x1 = xp;
			segments[nsegment].y1 = RadarHeight - 1 - start;
			segments[nsegment].x2 = xp;
			segments[nsegment].y2 = RadarHeight - 1 - end;
			nsegment++;
			if (nsegment >= max || yi == (int)RadarHeight - 1) {
			    XDrawSegments(dpy, radarPixmap2, radarGC,
					  segments, nsegment);
			    nsegment = 0;
			}
		    } else {
			points[npoint].x = xp;
			points[npoint].y = RadarHeight - 1 - start;
			npoint++;
			if (npoint >= max || yi == (int)RadarHeight - 1) {
			    XDrawPoints(dpy, radarPixmap2, radarGC,
					points, npoint, CoordModeOrigin);
			    npoint = 0;
			}
		    }
		    start = end = -1;
		}

		if (visibleColorChange) {
		    if (nsegment > 0) {
			XDrawSegments(dpy, radarPixmap2, radarGC,
				      segments, nsegment);
			nsegment = 0;
		    }
		    if (npoint > 0) {
			XDrawPoints(dpy, radarPixmap2, radarGC,
				    points, npoint, CoordModeOrigin);
			npoint = 0;
		    }
		    start = end = yp;
		    currColor = visibleColor[type];
		    XSetForeground(dpy, radarGC, colors[currColor].pixel);
		}
	    }
	}
    }
    if (nsegment > 0)
	XDrawSegments(dpy, radarPixmap2, radarGC, segments, nsegment);

    if (npoint > 0)
	XDrawPoints(dpy, radarPixmap2, radarGC,
		    points, npoint, CoordModeOrigin);

    if (radarPixmap2 == radarPixmap)
	XSetPlaneMask(dpy, radarGC,
		      AllPlanes & ~(dpl_2[0] | dpl_2[1]));

    for (i = 0;; i++) {
	int dead_time;
	double targ_damage;

	if (Target_by_index(i, &xi, &yi, &dead_time, &targ_damage) == -1)
	    break;
	if (dead_time)
	    continue;
	Paint_radar_block(xi, yi, targetRadarColor);
    }
}
Beispiel #28
0
main()
{
      Window w2;

      Display *dpy = XOpenDisplay(NIL);
      assert(dpy);
      Screen *scr = DefaultScreenOfDisplay(dpy);

      // CreateWindow

      Window w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent,
			       CopyFromParent, CopyFromParent,
			       0, NIL);

      XDestroyWindow(dpy, w);

      // CreateWindow with arguments

      XSetWindowAttributes swa;
      swa.background_pixel = WhitePixelOfScreen(scr);
      swa.bit_gravity = NorthWestGravity;
      swa.border_pixel = BlackPixelOfScreen(scr);
      swa.colormap = DefaultColormapOfScreen(scr);
      swa.cursor = None;
      swa.win_gravity = NorthGravity;

      w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent,
			CopyFromParent, CopyFromParent,
			CWBackPixel | CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWWinGravity, 
			&swa);
      
      // CreateWindow with other arguments

      XDestroyWindow(dpy, w);

      Pixmap pixmap = XCreatePixmap(dpy, RootWindowOfScreen(scr), 45, 25, DefaultDepthOfScreen(scr));
      assert(pixmap);

      swa.background_pixmap = pixmap;
      swa.border_pixmap = pixmap;

      w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent,
			CopyFromParent, CopyFromParent,
			CWBackPixmap | CWBorderPixmap,
			&swa);
      
      // ChangeWindowAttributes

      swa.backing_planes = 0x1;
      swa.backing_pixel = WhitePixelOfScreen(scr);
      swa.save_under = True;
      swa.event_mask = KeyPressMask | KeyReleaseMask;
      swa.do_not_propagate_mask = ButtonPressMask | Button4MotionMask;
      swa.override_redirect = False;
      XChangeWindowAttributes(dpy, w, CWBackingPlanes | CWBackingPixel | CWSaveUnder | CWEventMask
			      | CWDontPropagate | CWOverrideRedirect, &swa);

      // GetWindowAttributes

      XWindowAttributes wa;
      Status success = XGetWindowAttributes(dpy, w, &wa);

      // DestroyWindow (done)

      // DestroySubwindows

      w2 = XCreateWindow(dpy, w, 20, 30, 40, 50, 3, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL);
      XDestroySubwindows(dpy, w);

      // ChangeSaveSet

//        Display *dpy2 = XOpenDisplay(NIL);
//        assert(dpy2);
//        XAddToSaveSet(dpy2, w);
//        XCloseDisplay(dpy2);

      // ReparentWindow

      w2 = XCreateWindow(dpy, RootWindowOfScreen(scr), 20, 30, 40, 50, 3, 
			 CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL);
      XReparentWindow(dpy, w2, w, 10, 5);

      // MapWindow

      XMapWindow(dpy, w);

      // MapSubwindows
      
      XMapSubwindows(dpy, w);

      // UnmapWindow
      
      XUnmapWindow(dpy, w);

      // UnmapSubwindows

      XMapWindow(dpy, w);
      XUnmapSubwindows(dpy, w2);
      XMapSubwindows(dpy, w);

      // ConfigureWindow

      Window w3 = XCreateWindow(dpy, w, 10, 50, 100, 10, 2,
			 CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL);

      XMapWindow(dpy, w3);

      XWindowChanges wc;
      wc.x = -5;
      wc.y = -10;
      wc.width = 50;
      wc.height = 40;
      wc.border_width = 7;
      wc.sibling = w2;
      wc.stack_mode = Opposite;
      XConfigureWindow(dpy, w3, 
		       CWX | CWY | CWWidth | CWHeight | CWBorderWidth | CWSibling | CWStackMode, 
		       &wc);

      // CirculateWindow

      XCirculateSubwindows(dpy, w, RaiseLowest);

      // GetGeometry

      Window root;
      int x, y;
      unsigned width, height, border_width, depth;
      XGetGeometry(dpy, w, &root, &x, &y, &width, &height, &border_width, &depth);

      // QueryTree

      Window parent;
      Window *children;
      unsigned nchildren;
      success = XQueryTree(dpy, w, &root, &parent, &children, &nchildren);
      XFree(children);

      // InternAtom

      Atom a = XInternAtom(dpy, "WM_PROTOCOLS", True);

      // GetAtomName

      char *string = XGetAtomName(dpy, XA_PRIMARY);
      XFree(string);

      // ChangeProperty

      XStoreName(dpy, w, "test window");

      // DeleteProperty

      XDeleteProperty(dpy, w, XA_WM_NAME);

      // GetProperty
      // TODO

      // ListProperties

      int num_prop;
      Atom *list = XListProperties(dpy, w, &num_prop);
      XFree(list);

      // SetSelectionOwner

      XSetSelectionOwner(dpy, XA_PRIMARY, w, 12000);
      XSetSelectionOwner(dpy, XA_SECONDARY, w, CurrentTime);

      // GetSelectionOwner

      Window wx = XGetSelectionOwner(dpy, XA_PRIMARY);

      // ConvertSelection

      XConvertSelection(dpy, XA_SECONDARY, XA_CURSOR, XA_POINT, w, CurrentTime);

      // SendEvent

      // GrabPointer

      std::cerr << "Grabbing" << std::endl;
      int res = XGrabPointer(dpy, w, False, Button5MotionMask | PointerMotionHintMask,
			     GrabModeSync, GrabModeAsync, w, None, CurrentTime);
      XSync(dpy, False);
//      sleep(5);

      // UngrabPointer

      std::cerr << "Ungrabbing" << std::endl;
      XUngrabPointer(dpy, CurrentTime);

      // GrabButton

      XGrabButton(dpy, 3, ShiftMask | ControlMask, w, False, PointerMotionHintMask | Button2MotionMask, 
		  GrabModeAsync, GrabModeSync, None, None);
		  
      XGrabButton(dpy, 2, AnyModifier, w, False, PointerMotionHintMask | Button2MotionMask, 
		  GrabModeAsync, GrabModeSync, None, None);
		  
      // UngrabButton

      XUngrabButton(dpy, 2, LockMask, w);

      // ChangeActivePointerGrab

      XChangeActivePointerGrab(dpy, ButtonPressMask, None, CurrentTime);

      // GrabKeyboard

      XGrabKeyboard(dpy, w, True, GrabModeSync, GrabModeSync, 12000);

      // UngrabKeyboard

      XUngrabKeyboard(dpy, 13000);

      // GrabKey

      XGrabKey(dpy, XKeysymToKeycode(dpy, XK_Tab), ShiftMask | Mod3Mask, w, True, GrabModeSync,
	       GrabModeSync);

      // UngrabKey

      XUngrabKey(dpy, AnyKey, AnyModifier, w);

      // AllowEvents

      XAllowEvents(dpy, AsyncPointer, 14000);

      // GrabServer

      XGrabServer(dpy);

      // UngrabServer

      XUngrabServer(dpy);

      // QueryPointer

      Window child;
      int root_x, root_y, win_x, win_y;
      unsigned mask;
      Bool bres = XQueryPointer(dpy, w, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask);

      // GetMotionEvents

      int nevents;
      XGetMotionEvents(dpy, w, 15000, 16000, &nevents);

      // TranslateCoordinates

      int dest_x, dest_y;

      XTranslateCoordinates(dpy, w, w2, 10, 20, &dest_x, &dest_y, &child);

      // WarpPointer

      XWarpPointer(dpy, w, w2, 0, 0, 100, 100, 20, 30);

      // SetInputFocus

      XSetInputFocus(dpy,w, RevertToPointerRoot, 17000);
      XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, 17000);

      // GetInputFocus

      Window focus;
      int revert_to;
      XGetInputFocus(dpy, &focus, &revert_to);

      // QueryKeymap

      char keys_return[32];
      XQueryKeymap(dpy, keys_return);

      // OpenFont

      Font fid = XLoadFont(dpy, "cursor");

      // CloseFont

      XUnloadFont(dpy, fid);

      // QueryFont

      XFontStruct *fs = XLoadQueryFont(dpy, "cursor");
      assert(fs);

      // QueryTextExtents

      int direction, font_ascent, font_descent;
      XCharStruct overall;
      XQueryTextExtents(dpy, fs -> fid, "toto", 4, &direction, &font_ascent, &font_descent, &overall);
      XQueryTextExtents(dpy, fs -> fid, "odd__length", 11, &direction, &font_ascent, &font_descent, &overall);

      XChar2b c2bs;
      c2bs.byte1 = '$';
      c2bs.byte2 = 'B';
      XQueryTextExtents16(dpy, fs -> fid, &c2bs, 1, &direction, &font_ascent, &font_descent, &overall);

      XQueryTextExtents(dpy, fs -> fid, longString, strlen(longString), &direction, &font_ascent, 
			&font_descent, &overall);

      // ListFonts

      int actual_count;
      char **fontList = XListFonts(dpy, "*", 100, &actual_count);
      XFree((char *)fontList);

      // ListFontsWithInfo

      int count;
      XFontStruct *info;
      char **names = XListFontsWithInfo(dpy, "*", 100, &count, &info);
      XFreeFontInfo(names, info, count);

      // SetFontPath
      // GetFontPath

      int npaths;
      char **charList = XGetFontPath(dpy, &npaths);

      char **charList2 = new char *[npaths + 1];
      memcpy(charList2, charList, npaths * sizeof(char *));
      charList2[npaths] = charList2[0];

      XSetFontPath(dpy, charList2, npaths + 1);
      XSetFontPath(dpy, charList, npaths); // Reset to some reasonnable value

      XFreeFontPath(charList);
      delete [] charList2;

      // CreatePixmap

      Pixmap pix2 = XCreatePixmap(dpy, w, 100, 200, DefaultDepthOfScreen(scr));

      // FreePixmap

      XFreePixmap(dpy, pix2);

      // CreateGC

      Pixmap bitmap = XCreateBitmapFromData(dpy, RootWindowOfScreen(scr), 
					    "\000\000\001\000\000\001\000\000\001\377\377\377", 3, 4);

      XGCValues gcv;
      gcv.function = GXand;
      gcv.plane_mask = 0x1;
      gcv.foreground = WhitePixelOfScreen(scr);
      gcv.background = BlackPixelOfScreen(scr);
      gcv.line_width = 2;
      gcv.line_style = LineDoubleDash;
      gcv.cap_style = CapProjecting;
      gcv.join_style = JoinRound;
      gcv.fill_style = FillStippled;
      gcv.fill_rule = EvenOddRule;
      gcv.arc_mode = ArcPieSlice;
      gcv.tile = pixmap;
      gcv.stipple = bitmap;
      gcv.ts_x_origin = 3;
      gcv.ts_y_origin = 4;
      gcv.font = fs -> fid;
      gcv.subwindow_mode = ClipByChildren;
      gcv.graphics_exposures = True;
      gcv.clip_x_origin = 5;
      gcv.clip_y_origin = 6;
      gcv.clip_mask = bitmap;
      gcv.dash_offset = 1;
      gcv.dashes = 0xc2;
      
      GC gc = XCreateGC(dpy, w, 
			  GCFunction | GCPlaneMask | GCForeground | GCBackground | GCLineWidth
			| GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle | GCFillRule | GCTile
			| GCStipple | GCTileStipXOrigin | GCTileStipYOrigin | GCFont | GCSubwindowMode
			| GCGraphicsExposures | GCClipXOrigin | GCClipYOrigin | GCClipMask | GCDashOffset
			| GCDashList | GCArcMode,
			&gcv);

      // ChangeGC

      gcv.function = GXandReverse;

      // Only a few of these should appear, since the values are cached on the client side by the Xlib.

      XChangeGC(dpy, gc, GCFunction | GCLineStyle | GCStipple | GCGraphicsExposures | GCDashList, &gcv);

      // CopyGC
      
      GC gc2 = XCreateGC(dpy, w, 0, NIL);
      XCopyGC(dpy, gc, GCFunction | GCLineStyle | GCStipple | GCGraphicsExposures | GCDashList, gc2);

      // SetDashes

      XSetDashes(dpy, gc, 3, "\001\377\001", 3);

      // SetClipRectangles

      XRectangle rectangles[] = { { 10, 20, 30, 40 }, { 100, 200, 5, 3 }, { -5, 1, 12, 24 } };
      XSetClipRectangles(dpy, gc, 12, 9, rectangles, SIZEOF(rectangles), Unsorted);

      // FreeGC

	    // done already

      // ClearArea

      XClearArea(dpy, w, 30, 10, 10, 100, False);

      // CopyArea

      XCopyArea(dpy, w, pixmap, gc, 0, 0, 100, 100, 10, 10);

      // CopyPlane

      // This won't work if the Screen doesn't have at least 3 planes
      XCopyPlane(dpy, pixmap, w, gc, 20, 10, 40, 30, 0, 0, 0x4);

      // PolyPoint

      XDrawPoint(dpy, w, gc, 1, 2);

      XPoint points[] = { { 3, 4 }, { 5, 6 } };
      XDrawPoints(dpy, w, gc, points, SIZEOF(points), CoordModeOrigin);

      // PolyLine

      XDrawLines(dpy, w, gc, points, SIZEOF(points), CoordModePrevious);

      // PolySegment

      XSegment segments[] = { { 7, 8, 9, 10 }, { 11, 12, 13, 14 }, { 15, 16, 17, 18 } };
      XDrawSegments(dpy, w, gc, segments, SIZEOF(segments));

      // PolyRectangle

      XDrawRectangles(dpy, w, gc, rectangles, SIZEOF(rectangles));

      // PolyArc

      XArc arcs[] = { { 10, 20, 30, 40, 50, 60 }, { -70, 80, 90, 100, 110, 120 }, 
		      { 10, 20, 30, 40, 50, -30 } };

      XDrawArcs(dpy, w, gc, arcs, SIZEOF(arcs));

      // FillPoly

      XFillPolygon(dpy, w, gc, points, SIZEOF(points), Convex, CoordModePrevious);

      // PolyFillRectangle
      
      XFillRectangles(dpy, w, gc, rectangles, SIZEOF(rectangles));

      // PolyFillArc
      
      XFillArcs(dpy, w, gc, arcs, SIZEOF(arcs));

      // PutImage
      // GetImage

      XImage *image = XGetImage(dpy, w, 10, 20, 40, 30, AllPlanes, ZPixmap);
      XPutImage(dpy, w, gc, image, 0, 0, 50, 60, 40, 30);
      XSync(dpy, False); // Make the next request starts at the beginning of a packet

      // PolyText8
      XTextItem textItems[3];
      textItems[0].chars = "toto";
      textItems[0].nchars = strlen(textItems[0].chars);
      textItems[0].delta = -3;
      textItems[0].font = fs->fid;
      textItems[1].chars = "titi";
      textItems[1].nchars = strlen(textItems[1].chars);
      textItems[1].delta = 3;
      textItems[1].font = None;
      textItems[2].chars = "tutu";
      textItems[2].nchars = strlen(textItems[2].chars);
      textItems[2].delta = 0;
      textItems[2].font = fs->fid;

      XDrawText(dpy, w, gc, 10, 10, textItems, 3);


      XTextItem textItems2[3];
      textItems2[0].chars = "totox";
      textItems2[0].nchars = strlen(textItems2[0].chars);
      textItems2[0].delta = -3;
      textItems2[0].font = fs->fid;
      textItems2[1].chars = "titi";
      textItems2[1].nchars = strlen(textItems2[1].chars);
      textItems2[1].delta = 3;
      textItems2[1].font = None;
      textItems2[2].chars = "tutu";
      textItems2[2].nchars = strlen(textItems2[2].chars);
      textItems2[2].delta = 0;
      textItems2[2].font = fs->fid;

      XDrawText(dpy, w, gc, 10, 10, textItems2, 3);

      // PolyText16

      XChar2b c2b2[] = { 0, 't', 0, 'x' };

      XTextItem16 items16[] = { { &c2bs, 1, -5, None }, { NULL, 0, 0, None }, { c2b2, 2, 0, fs -> fid } };
      XDrawText16(dpy, w, gc, 10, 0, items16, SIZEOF(items16));

      // ImageText8

      XDrawImageString(dpy, w, gc, 10, 10, "toto", 4);

      // ImageText16

      XDrawImageString16(dpy, w, gc, 10, 10, &c2bs, 1);
      XDrawImageString16(dpy, w, gc, 10, 20, c2b2, 2);

      // CreateColormap
      // Don't forget to tell the kids how it was when we had only 8 bits per pixel.

      Colormap colormap = XCreateColormap(dpy, w, DefaultVisualOfScreen(scr), None);

      // FreeColormap

      XFreeColormap(dpy, colormap);
      colormap = XCreateColormap(dpy, w, DefaultVisualOfScreen(scr), None);

      // CopyColormapAndFree

      Colormap colormap2 = XCopyColormapAndFree(dpy, colormap);

      // InstallColormap

      XInstallColormap(dpy, colormap2);

      // UninstallColormap

      XUninstallColormap(dpy, colormap2);

      // ListInstalledColormaps

      int num;
      Colormap *colormapList = XListInstalledColormaps(dpy, w, &num);

      // AllocColor

      XColor screen;
      screen.red = 0;
      screen.green = 32767;
      screen.blue = 65535;
      screen.flags = DoRed | DoGreen | DoBlue;
      success = XAllocColor(dpy, colormap, &screen);

      // AllocNamedColor

      XColor screen2, exact;
      success = XAllocNamedColor(dpy, colormap, "Wheat", &screen2, &exact);

      // AllocColorCells

      unsigned long plane_masks, pixels;
      success = XAllocColorCells(dpy, colormap, False, &plane_masks, 1, &pixels, 1);

      // AllocColorPlanes

      unsigned long rmask, gmask, bmask;
      success = XAllocColorPlanes(dpy, colormap, False, &pixels, 1, 0, 0, 0, &rmask, &gmask, &bmask);

      // FreeColors

      unsigned long pixels2[2] = { screen.pixel, screen2.pixel };
      XFreeColors(dpy, colormap, pixels2, 2, 0);

      // StoreColors

      success = XAllocColorCells(dpy, colormap, False, NIL, 0, pixels2, 2);

      // On many contemporary (that is, year 2000) video cards, you can't allocate read / write cells
      // I want my requests to be sent, however.
      if (!success) {
	    XSetErrorHandler(errorHandler);
      }

      XColor colors[2];
      colors[0] = screen;  colors[0].pixel = pixels2[0];
      colors[1] = screen2; colors[1].pixel = pixels2[1];
      XStoreColors(dpy, colormap, colors, 2);

      // StoreNamedColor

      XStoreNamedColor(dpy, colormap, "Wheat", colors[0].pixel, DoBlue);

      XSync(dpy, False);
      XSetErrorHandler(NIL); // Restore the default handler

      // QueryColors

      screen2.pixel = WhitePixelOfScreen(scr);
      XQueryColor(dpy, colormap, &screen2);

      // LookupColor

      success = XLookupColor(dpy, colormap, "DarkCyan", &exact, &screen);

      // CreateCursor

      Cursor cursor = XCreatePixmapCursor(dpy, pixmap, None, &exact, colors, 10, 10);

      // CreateGlyphCursor
      
      Cursor cursor2 = XCreateGlyphCursor(dpy, fs -> fid, fs -> fid, 'X', 0, &exact, colors);

      // FreeCursor
      
      XFreeCursor(dpy, cursor2);

      // RecolorCursor

      XRecolorCursor(dpy, cursor, colors, &exact);

      // QueryBestSize

      success = XQueryBestSize(dpy, CursorShape, RootWindowOfScreen(scr), 100, 20, &width, &height);

      // QueryExtension

      int major_opcode, first_event, first_error;
      XQueryExtension(dpy, "toto", &major_opcode, &first_event, &first_error);

      // ListExtensions

      int nextensions;
      char **extensionList = XListExtensions(dpy, &nextensions);
      for(char **p = extensionList; nextensions; nextensions--, p++) std::cout << *p << std::endl;
      XFree(extensionList);

      // ChangeKeyboardMapping
      // GetKeyboardMapping

      int min_keycodes, max_keycodes;
      XDisplayKeycodes(dpy, &min_keycodes, &max_keycodes);

      int keysyms_per_keycode;
      KeySym *keysyms = XGetKeyboardMapping(dpy, min_keycodes, max_keycodes - min_keycodes + 1,
					    &keysyms_per_keycode);
      XChangeKeyboardMapping(dpy, min_keycodes, keysyms_per_keycode, keysyms, 
			     max_keycodes - min_keycodes + 1);

      // ChangeKeyboardControl
      // GetKeyboardControl

      XKeyboardState keyboardState;
      XGetKeyboardControl(dpy, &keyboardState);

      XKeyboardControl keyboardValues;
      keyboardValues.key_click_percent = keyboardState.key_click_percent;
      keyboardValues.bell_percent = keyboardState.bell_percent;
      keyboardValues.bell_pitch = keyboardState.bell_pitch;
      keyboardValues.bell_duration = keyboardState.bell_duration;
      keyboardValues.led = 1;
      keyboardValues.led_mode = LedModeOn;
      keyboardValues.key = min_keycodes;
      keyboardValues.auto_repeat_mode = AutoRepeatModeDefault;
      XChangeKeyboardControl(dpy, 
			       KBKeyClickPercent | KBBellPercent | KBBellPitch | KBBellDuration
			     | KBLed | KBLedMode | KBKey | KBAutoRepeatMode,
			     &keyboardValues);

      // Bell

      XBell(dpy, 90);

      // ChangePointerControl
      // GetPointerControl

      int accel_numerator, accel_denominator, threshold;
      XGetPointerControl(dpy, &accel_numerator, &accel_denominator, &threshold);

      XChangePointerControl(dpy, True, True, accel_numerator, accel_denominator, threshold);

      // SetScreenSaver
      // GetScreenSaver

      int timeout, interval, prefer_blanking, allow_exposures;
      XGetScreenSaver(dpy, &timeout, &interval, &prefer_blanking, &allow_exposures);
      XSetScreenSaver(dpy, timeout, interval, prefer_blanking, allow_exposures);

      // ChangeHosts
      // ListHosts

      int nhosts;
      Bool state;
      XHostAddress *hostList = XListHosts(dpy, &nhosts, &state);

      XHostAddress host;
      host.family = FamilyInternet;
      host.length = 4;
      host.address = "\001\002\003\004";
      XAddHost(dpy, &host);

      // SetAccessControl

      XSetAccessControl(dpy, EnableAccess);

      // SetCloseDownMode

      XSetCloseDownMode(dpy, RetainTemporary);

      // KillClient

      XKillClient(dpy, AllTemporary);

      // RotateProperties

      Atom properties[] = { XInternAtom(dpy, "CUT_BUFFER0", False), 
			    XInternAtom(dpy, "CUT_BUFFER1", False),
			    XInternAtom(dpy, "CUT_BUFFER2", False) };
      XRotateWindowProperties(dpy, RootWindowOfScreen(scr), properties, SIZEOF(properties), -1);

      // ForceScreenSaver

      XForceScreenSaver(dpy, ScreenSaverReset);

      // SetPointerMapping
      // GetPointerMapping

      unsigned char map[64];
      int map_length = XGetPointerMapping(dpy, map, 64);
      XSetPointerMapping(dpy, map, map_length);

      // SetModifierMapping
      // GetModifierMapping

      XModifierKeymap *modmap = XGetModifierMapping(dpy);
      XSetModifierMapping(dpy, modmap);

      // NoOperation

      XNoOp(dpy);

      for(;;) {
	    XEvent e;
	    XNextEvent(dpy, &e);
	    std::cout << "Got an event of type " << e.type << std::endl;
      }
}
Beispiel #29
0
ENTRYPOINT void
draw_hop(ModeInfo * mi)
{
	double      oldj, oldi;
	XPoint     *xp;
	int         k;
	hopstruct  *hp;

	if (hops == NULL)
		return;
	hp = &hops[MI_SCREEN(mi)];

#ifdef STANDALONE
    if (hp->eraser) {
      hp->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), hp->eraser);
      return;
    }
#endif


	if (hp->pointBuffer == NULL)
		return;
	xp = hp->pointBuffer;
	k = hp->bufsize;

	MI_IS_DRAWN(mi) = True;
	hp->inc++;
	if (MI_NPIXELS(mi) > 2) {
		XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_PIXEL(mi, hp->pix));
		if (++hp->pix >= MI_NPIXELS(mi))
			hp->pix = 0;
	}
	while (k--) {
		oldj = hp->j;
		switch (hp->op) {
			case MARTIN:	/* SQRT, MARTIN1 */
				oldi = hp->i + hp->inc;
				hp->j = hp->a - hp->i;
				hp->i = oldj + ((hp->i < 0)
					   ? sqrt(fabs(hp->b * oldi - hp->c))
					: -sqrt(fabs(hp->b * oldi - hp->c)));
				xp->x = hp->centerx + (int) (hp->i + hp->j);
				xp->y = hp->centery - (int) (hp->i - hp->j);
				break;
			case EJK1:
				oldi = hp->i + hp->inc;
				hp->j = hp->a - hp->i;
				hp->i = oldj - ((hp->i > 0) ? (hp->b * oldi - hp->c) :
						-(hp->b * oldi - hp->c));
				xp->x = hp->centerx + (int) (hp->i + hp->j);
				xp->y = hp->centery - (int) (hp->i - hp->j);
				break;
			case EJK2:
				oldi = hp->i + hp->inc;
				hp->j = hp->a - hp->i;
				hp->i = oldj - ((hp->i < 0) ? log(fabs(hp->b * oldi - hp->c)) :
					   -log(fabs(hp->b * oldi - hp->c)));
				xp->x = hp->centerx + (int) (hp->i + hp->j);
				xp->y = hp->centery - (int) (hp->i - hp->j);
				break;
			case EJK3:
				oldi = hp->i + hp->inc;
				hp->j = hp->a - hp->i;
				hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c :
						-sin(hp->b * oldi) - hp->c);
				xp->x = hp->centerx + (int) (hp->i + hp->j);
				xp->y = hp->centery - (int) (hp->i - hp->j);
				break;
			case EJK4:
				oldi = hp->i + hp->inc;
				hp->j = hp->a - hp->i;
				hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c :
					  -sqrt(fabs(hp->b * oldi - hp->c)));
				xp->x = hp->centerx + (int) (hp->i + hp->j);
				xp->y = hp->centery - (int) (hp->i - hp->j);
				break;
			case EJK5:
				oldi = hp->i + hp->inc;
				hp->j = hp->a - hp->i;
				hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c :
						-(hp->b * oldi - hp->c));
				xp->x = hp->centerx + (int) (hp->i + hp->j);
				xp->y = hp->centery - (int) (hp->i - hp->j);
				break;
			case EJK6:
				oldi = hp->i + hp->inc;
				hp->j = hp->a - hp->i;
				hp->i = oldj - asin((hp->b * oldi) - (long) (hp->b * oldi));
				xp->x = hp->centerx + (int) (hp->i + hp->j);
				xp->y = hp->centery - (int) (hp->i - hp->j);
				break;
			case RR:	/* RR1 */
				oldi = hp->i + hp->inc;
				hp->j = hp->a - hp->i;
				hp->i = oldj - ((hp->i < 0) ? -pow(fabs(hp->b * oldi - hp->c), hp->d) :
				     pow(fabs(hp->b * oldi - hp->c), hp->d));
				xp->x = hp->centerx + (int) (hp->i + hp->j);
				xp->y = hp->centery - (int) (hp->i - hp->j);
				break;
			case POPCORN:
#define HVAL 0.05
#define INCVAL 50
				{
					double      tempi, tempj;

					if (hp->inc >= 100)
						hp->inc = 0;
					if (hp->inc == 0) {
						if (hp->a++ >= INCVAL) {
							hp->a = 0;
							if (hp->b++ >= INCVAL)
								hp->b = 0;
						}
						hp->i = (-hp->c * INCVAL / 2 + hp->c * hp->a) * M_PI / 180.0;
						hp->j = (-hp->c * INCVAL / 2 + hp->c * hp->b) * M_PI / 180.0;
					}
					tempi = hp->i - HVAL * sin(hp->j + tan(3.0 * hp->j));
					tempj = hp->j - HVAL * sin(hp->i + tan(3.0 * hp->i));
					xp->x = hp->centerx + (int) (MI_WIDTH(mi) / 40 * tempi);
					xp->y = hp->centery + (int) (MI_HEIGHT(mi) / 40 * tempj);
					hp->i = tempi;
					hp->j = tempj;
				}
				break;
			case JONG:
				if (hp->centerx > 0)
					oldi = hp->i + 4 * hp->inc / hp->centerx;
				else
					oldi = hp->i;
				hp->j = sin(hp->c * hp->i) - cos(hp->d * hp->j);
				hp->i = sin(hp->a * oldj) - cos(hp->b * oldi);
				xp->x = hp->centerx + (int) (hp->centerx * (hp->i + hp->j) / 4.0);
				xp->y = hp->centery - (int) (hp->centery * (hp->i - hp->j) / 4.0);
				break;
			case SINE:	/* MARTIN2 */
				oldi = hp->i + hp->inc;
				hp->j = hp->a - hp->i;
				hp->i = oldj - sin(oldi);
				xp->x = hp->centerx + (int) (hp->i + hp->j);
				xp->y = hp->centery - (int) (hp->i - hp->j);
				break;
		}
		xp++;
	}
	XDrawPoints(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi),
		    hp->pointBuffer, hp->bufsize, CoordModeOrigin);
	if (++hp->count > MI_CYCLES(mi)) {
#ifdef STANDALONE
      hp->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), hp->eraser);
#endif /* STANDALONE */
		init_hop(mi);
	}
}
Beispiel #30
0
void EZX_DrawPoints(EZXW_p w, int npoints, XPoint *points)
{
    XDrawPoints(theDisplay, w->w, theGC, points, npoints, EZX_CoordMode);
}