Beispiel #1
0
bool GuiCalibratorX11::on_timer_signal()
{
    // Update clock
    if(calibrator->get_use_timeout()) {

        time_elapsed += time_step;
        if (time_elapsed > calibrator->get_timeout()) {
            exit(0);
        }

        XSetForeground(display, gc, pixel[BLACK]);
        XSetLineAttributes(display, gc, clock_line_width,
                    LineSolid, CapButt, JoinMiter);
        XDrawArc(display, win, gc, (display_width-clock_radius+clock_line_width)/2,
                    (display_height-clock_radius+clock_line_width)/2,
                    clock_radius-clock_line_width, clock_radius-clock_line_width,
                    90*64, ((double)time_elapsed/(double)calibrator->get_timeout()) * -360 * 64);
    }

    return true;
}
Beispiel #2
0
void drawWhiteRectangle(UpdateTask *pt) {
  Display *display  = XtDisplay(pt->displayInfo->drawingArea);
  GC      gc        = pt->displayInfo->pixmapGC;
  Drawable drawable = XtWindow(pt->displayInfo->drawingArea);

  XSetForeground(display,gc,WhitePixel(display,DefaultScreen(display)));
  XFillRectangle(display,drawable,gc,pt->rectangle.x+1,pt->rectangle.y+1,
	         pt->rectangle.width-2,pt->rectangle.height-2);
  XSetForeground(display,gc,BlackPixel(display,DefaultScreen(display)));
  XSetLineAttributes(display,gc,0,LineSolid,CapRound,JoinRound);
  XDrawRectangle(display,drawable,gc,pt->rectangle.x,pt->rectangle.y,
	         pt->rectangle.width-1,pt->rectangle.height-1);

#if 0
  XSetForeground(display,gc,BlackPixel(display,DefaultScreen(display)));
  XFillRectangle(display,drawable,gc,pt->rectangle.x,pt->rectangle.y,
	         pt->rectangle.width,pt->rectangle.height);
  XSetForeground(display,gc,WhitePixel(display,DefaultScreen(display)));
  XFillRectangle(display,drawable,gc,pt->rectangle.x+1,pt->rectangle.y+1,
		 pt->rectangle.width-2,pt->rectangle.height-2);
#endif
}
Beispiel #3
0
/**
 * Draw fast, XOR line with XDrawLine in front color buffer.
 * WARNING: this isn't fully OpenGL conformant because different pixels
 * will be hit versus using the other line functions.
 * Don't use the code in X server GLcore module since we need a wrapper
 * for the XSetLineAttributes() function call.
 */
static void
xor_line(struct gl_context *ctx, const SWvertex *vert0, const SWvertex *vert1)
{
   XMesaContext xmesa = XMESA_CONTEXT(ctx);
   XMesaDisplay *dpy = xmesa->xm_visual->display;
   XMesaGC gc = xmesa->xm_buffer->gc;
   GET_XRB(xrb);
   unsigned long pixel = xmesa_color_to_pixel(ctx,
                                              vert1->color[0], vert1->color[1],
                                              vert1->color[2], vert1->color[3],
                                              xmesa->pixelformat);
   int x0 =            (GLint) vert0->attrib[VARYING_SLOT_POS][0];
   int y0 = YFLIP(xrb, (GLint) vert0->attrib[VARYING_SLOT_POS][1]);
   int x1 =            (GLint) vert1->attrib[VARYING_SLOT_POS][0];
   int y1 = YFLIP(xrb, (GLint) vert1->attrib[VARYING_SLOT_POS][1]);
   XMesaSetForeground(dpy, gc, pixel);
   XMesaSetFunction(dpy, gc, GXxor);
   XSetLineAttributes(dpy, gc, (int) ctx->Line.Width,
                      LineSolid, CapButt, JoinMiter);
   XDrawLine(dpy, xrb->pixmap, gc, x0, y0, x1, y1);
   XMesaSetFunction(dpy, gc, GXcopy);  /* this gc is used elsewhere */
}
Beispiel #4
0
struct wm_window* create_parent_window(struct wm_window *child) {
	GC gc;
	XGCValues values;
	struct wm_window *parent_win = (struct wm_window *)malloc(sizeof(struct wm_window));
	XColor bg_color;
	bg_color.red = 0 * 256;
	bg_color.green = 100 * 256;
	bg_color.blue = 150 * 256;
	XAllocColor(wm.display, DefaultColormap(wm.display, wm.screen), &bg_color);
	parent_win->win = XCreateSimpleWindow(wm.display, DefaultRootWindow(wm.display), 0, 0, 600, 600, 0, bg_color.pixel, bg_color.pixel);
	wm_window_resize(&wm, child, 590, 570);

	int w, h;
	w = 100 + rand()%screen_width - (child->width + 20);
	h = 100 + rand()%screen_height - (child->height + 20);
	w = w >= 0 ? w : 0;
	h = h >= 0 ? h : 0;
	printf("::: %d %d\n", w, h);
	wm_window_move(&wm, parent_win, w, h);
	wm_window_show(&wm, parent_win);

   	gc = XCreateGC(wm.display, parent_win->win, None, &values);
	XSetLineAttributes(wm.display, gc,  2, LineSolid, CapButt, JoinRound);
	XDrawString(wm.display, parent_win->win, gc, 20, 20, child->title, strlen(child->title));

	Pixmap exit_icon, mask;
	XpmAttributes xpm_attr;
	XpmCreatePixmapFromData(wm.display, parent_win->win, exit_icon_xpm, &exit_icon, &mask, &xpm_attr);
	GC gc2;
	XGCValues values2;
       	gc2 = XCreateGC(wm.display, parent_win->win, None, &values2);
	XSetClipMask(wm.display, gc2, mask);
	// XcopyArea() server-side should be faster than XPutImage() client-side 
	XSetClipOrigin(wm.display, gc2, 600-xpm_attr.width, 0);
	XCopyArea(wm.display, exit_icon, parent_win->win, gc2, 0, 0, xpm_attr.width, xpm_attr.height, 600-xpm_attr.width, 0);

	return parent_win;
}
void init_X(){
    /* open connection with the server */ 
    X.display = XOpenDisplay(NULL);
    if(X.display == NULL) {
        printf("cannot open display\n");
        exit(EXIT_FAILURE);
    }

    X.screen = DefaultScreen(X.display);

    /* set window size */
    int width = point_num_x;
    int height = point_num_y;

    /* set window position */
    int x = 0;
    int y = 0;

    /* border width in pixels */
    int border_width = 0;

    /* create window */
    X.window = XCreateSimpleWindow(X.display, RootWindow(X.display, X.screen), x, y, width, height, border_width,
                                    BlackPixel(X.display, X.screen), WhitePixel(X.display, X.screen));
    
    /* create graph */
    XGCValues values;
    long valuemask = 0;
    
    X.gc = XCreateGC(X.display, X.window, valuemask, &values);
    XSetForeground(X.display, X.gc, BlackPixel (X.display, X.screen));
    XSetBackground(X.display, X.gc, 0X0000FF00);
    XSetLineAttributes(X.display, X.gc, 1, LineSolid, CapRound, JoinRound);
    
    /* map(show) the window */
    XMapWindow(X.display, X.window);
    XSync(X.display, 0);
}
Beispiel #6
0
void PlotArea::plot_linetype(const char *buf)
{
    int assignments = sscanf(buf, "L%4d", &line_type);
    if (assignments != 1)
    {
	plot_unknown(buf);
	return;
    }

    line_type = (line_type % 8) + 2;
    width = widths[line_type];
    if (dashes[line_type][0])
    {
	type = LineOnOffDash;
	XSetDashes(dpy, gc, 0, dashes[line_type], strlen(dashes[line_type]));
    }
    else
    {
	type = LineSolid;
    }
    XSetForeground(dpy, gc, colors[line_type + 3]);
    XSetLineAttributes(dpy, gc, width, type, CapButt, JoinBevel);
}
Beispiel #7
0
/************************************************************************
 *                                                                       *
 *  Draw a multi connected lines to form a polygon.			*
 *  It is called when a polygon is completed.				*
 *									*/
void
Polygon::draw(void)
{
    int i;
    if ((pnt == NULL) || (pnt[0].x == G_INIT_POS))
    return;

    set_clip_region(FRAME_CLIP_TO_IMAGE);

    if (visibility != VISIBLE_NEVER && visible != FALSE){
	XPoint *point = new XPoint[npnts+1];
	for (i=0; i<npnts; i++){
	    point[i].x = pnt[i].x;
	    point[i].y = pnt[i].y;
	}
	int npoints;
	if (closed){
	    npoints = npnts + 1;
	    point[npnts].x = pnt[0].x;
	    point[npnts].y = pnt[0].y;
	}else{
	    npoints = npnts;
	}
	G_Set_Color(gdev, color);
	XSetLineAttributes(gdev->xdpy, gdev->xgc,
			   0, LineSolid, CapButt, JoinBevel);
	XDrawLines(gdev->xdpy, gdev->xid, gdev->xgc, point, npoints,
		   CoordModeOrigin);
	delete[] point;
    }
    roi_set_state(ROI_STATE_EXIST);

    if (roi_state(ROI_STATE_MARK)){
	mark();
    }
    set_clip_region(FRAME_NO_CLIP);
}
Beispiel #8
0
void
p_pen(p_win *w, int width, int type)
{
  p_scr *s = w->s;
  GC gc = s->gc;
  int disjoint = (type & P_SQUARE);
  int same_type = (s->gc_type == type);

  if (width<2) width = 0;
  else if (width>100) width = 100;

  if (s->gc_width==width && same_type) return;

  type ^= disjoint;
  if (type>4 || type<0) type = 0;
  XSetLineAttributes(s->xdpy->dpy, gc, width,
                     type? LineOnOffDash : LineSolid,
                     disjoint? CapProjecting : CapRound,
                     disjoint? JoinMiter : JoinRound);
  if (!same_type) s->gc_type = (type | disjoint);
  s->gc_width = width;

  if (type) {
    /* dash pattern depends on linestyle */
    int n = x_ndash[type];
    if (width<2) {
      XSetDashes(s->xdpy->dpy, gc, 0, x_dash[type], n);
    } else {
      /* dash pattern must scale with line thickness */
      int i;
      char dash[6];
      for (i=0 ; i<n ; i++)
        dash[i] = x_dash[type][i]>1? width*x_dash[type][i] : 1;
      XSetDashes(s->xdpy->dpy, gc, 0, dash, n);
    }
  }
}
Beispiel #9
0
GC
create_gc(Display* display, Window win, int reverse_video)
{
  GC gc;				/* handle of newly created GC.  */
  unsigned long valuemask = 0;		/* which values in 'values' to  */
					/* check when creating the GC.  */
  XGCValues values;			/* initial values for the GC.   */
  unsigned int line_width = 2;		/* line width for the GC.       */
  int line_style = LineSolid;		/* style for lines drawing and  */
  int cap_style = CapButt;		/* style of the line's edje and */
  int join_style = JoinBevel;		/*  joined lines.		*/
  int screen_num = DefaultScreen(display);

  gc = XCreateGC(display, win, valuemask, &values);
  if (gc < 0) {
	fprintf(stderr, "XCreateGC: \n");
  }

  /* allocate foreground and background colors for this GC. */
  if (reverse_video) {
    XSetForeground(display, gc, WhitePixel(display, screen_num));
    XSetBackground(display, gc, BlackPixel(display, screen_num));
  }
  else {
    XSetForeground(display, gc, BlackPixel(display, screen_num));
    XSetBackground(display, gc, WhitePixel(display, screen_num));
  }

  /* define the style of lines that will be drawn using this GC. */
  XSetLineAttributes(display, gc,
                     line_width, line_style, cap_style, join_style);

  /* define the fill style for the GC. to be 'solid filling'. */
  XSetFillStyle(display, gc, FillSolid);

  return gc;
}
Beispiel #10
0
/*
 * Vytvoøení grafického kontextu
 */
static void getGC(Window win, GC *gc, XFontStruct *font_info)
{
    unsigned long valuemask = 0; /* Ignorovat XGCValues a pou¾ít default */
    XGCValues values; /* Nastavení grafického kontextu */
    /* Atributy pro kreslení èar (daly by se nastavit i pøi XCreateGC) */
    unsigned int line_width = 6;
    int line_style = LineOnOffDash;
    int cap_style = CapRound;
    int join_style = JoinRound;
    int dash_offset = 0;
    static char dash_list[] = {12, 24};
    int list_length = 2;
    
    /* Vytvoøit defaultní graphics context */
    *gc = XCreateGC(display, win, valuemask, &values);
    /* Nastavit font pro kreslení textu */
    XSetFont(display, *gc, font_info->fid);
    /* Nastavit foreground na èernou, proto¾e default background je bílý */
    XSetForeground(display, *gc, BlackPixel(display, screen_num));
    /* Nastavit parametry pro kreslení èar */
    XSetLineAttributes(display, *gc, line_width, line_style, cap_style,
                       join_style);
    XSetDashes(display, *gc, dash_offset, dash_list, list_length);
}
Beispiel #11
0
void creategui()
{
	int x, y, w = width, h = height;
	XSetWindowAttributes wa;

	if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
		fputs("no locale support\n", stderr);

	screen = DefaultScreen(dpy);
	root = RootWindow(dpy, screen);
	initfont(font);
	cursor = XCreateFontCursor(dpy, XC_left_ptr);

	dc.norm[ColBG] = getcolor(normbgcolor);
	dc.norm[ColFG] = getcolor(normfgcolor);
	dc.sel[ColBG] = getcolor(selbgcolor);
	dc.sel[ColFG] = getcolor(selfgcolor);
	dc.drawable = XCreatePixmap(dpy, root, w, 2 * h, DefaultDepth(dpy, screen));
	dc.gc = XCreateGC(dpy, root, 0, NULL);
	XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
	if (!dc.font.set)
		XSetFont(dpy, dc.gc, dc.font.xfont->fid);

	wa.cursor = cursor;
	wa.background_pixel = dc.norm[ColBG];
	XChangeWindowAttributes(dpy, root, CWBackPixel|CWCursor, &wa);

	x = (DisplayWidth(dpy, screen) - w) / 2;
	y = DisplayHeight(dpy, screen) / 2;
	createinput(userprompt, x, y - h, w, h, innerpx, False);
	createinput(passprompt, x, y, w, h, innerpx, True);

	im = XOpenIM(dpy, NULL, NULL, NULL);
	ic = XCreateIC(im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
			XNClientWindow, inputs->win, XNFocusWindow, inputs->win, NULL);
}
Beispiel #12
0
void MP_LineStyle (Scene& scene, short linestyle, short thickness)
{
     char pattern[8]; 
     unsigned thick;

     // use same formula as in image.cpp
     thick = 1 + (thickness-1)/2; 

     strcpy(pattern,
	    (linestyle == Dotted)       ? "\2\1" :
	    (linestyle == Dashed)       ? "\6\3" : 
	    (linestyle == LongDashed)   ? "\10\5"  : 
	    (linestyle == DotDashed)    ? "\6\2\1\2" : 
	    (linestyle == DotDotDashed) ? "\6\2\1\2\1\2" :
	                                  "\1\3");
     if (linestyle != Solid)
       XSetDashes(Mp.theDisplay,scene.mpwindow->DrawGC,0,pattern,strlen(pattern));

     XSetLineAttributes(Mp.theDisplay,scene.mpwindow->DrawGC,
			thick,
			(linestyle != Solid) ? LineOnOffDash : LineSolid,
			CapButt,
			JoinBevel);
}
Beispiel #13
0
void paint_border(GUI* g,Window win, WIDGET* w)
{
  struct border_data_t* data=w->widget_data;
  if((w->status&STATUS_VISIBLE)==0){
    XSetForeground(g->dsp,g->draw,g->bgColor);
    XSetLineAttributes(g->dsp,g->draw,data->thickness,LineSolid,CapButt,JoinMiter);
    XDrawRectangle(g->dsp,win,g->draw,w->x,w->y,w->width,w->height);
    XSetLineAttributes(g->dsp,g->draw,1,LineSolid,CapButt,JoinMiter);
  }
  else{
    if(data->color>-1){
      XSetForeground(g->dsp,g->draw,data->color);
      XSetLineAttributes(g->dsp,g->draw,data->thickness,LineSolid,CapButt,JoinMiter);
      XDrawRectangle(g->dsp,win,g->draw,w->x,w->y,w->width,w->height);
      XSetLineAttributes(g->dsp,g->draw,1,LineSolid,CapButt,JoinMiter);
    }
    else {
      XSetForeground(g->dsp,g->draw,g->blackColor);
      XSetLineAttributes(g->dsp,g->draw,data->thickness,LineSolid,CapButt,JoinMiter);
      XDrawRectangle(g->dsp,win,g->draw,w->x,w->y,w->width,w->height);
      XSetLineAttributes(g->dsp,g->draw,1,LineSolid,CapButt,JoinMiter);
    }
  }
}
Beispiel #14
0
static void LoopLasers(struct state *st, int xlim, int ylim)
{
  int i, j, miny = ylim * 0.8;
  int x, y;
  for (i = 0; i < kMaxLasers; i++) {
	 Laser *m = &st->laser[i];
	 if (!m->alive)
		continue;

	 if (m->oldx != -1) {
		 XSetLineAttributes(st->dpy, st->erase_gc, 2, 0,0,0);
		 XDrawLine(st->dpy, st->window, st->erase_gc,
				  m->oldx2, m->oldy2, m->oldx, m->oldy);
	 }

	 m->fposx += m->velx;
	 m->fposy += m->vely;
	 m->x = m->fposx;
	 m->y = m->fposy;
	 
	 x = m->fposx + (-m->velx * m->lenMul);
	 y = m->fposy + (-m->vely * m->lenMul);

	 m->oldx = x;
	 m->oldy = y;

	 XSetLineAttributes(st->dpy, st->draw_gc, 2, 0,0,0);
    XSetForeground (st->dpy, st->draw_gc, m->color.pixel);
	 XDrawLine(st->dpy, st->window, st->draw_gc,
				  m->x, m->y, x, y);

	 m->oldx2 = m->x;
	 m->oldy2 = m->y;
	 m->oldx = x;
	 m->oldy = y;
	 
	 if (m->y < m->endy) {
		m->alive = 0;
	 }

	 /* check hitting explosions */
	 if (m->y < miny)
		for (j=0;j<kMaxBooms;j++) {
		  Boom *b = &st->boom[j];
		  if (!b->alive)
			 continue;
		  else {
			 int dx = abs(m->x - b->x);
			 int dy = abs(m->y - b->y);
			 int r = b->rad + 2;
			 if (b->oflaser)
				continue;
			 if ((dx < r) && (dy < r))
				if (dx * dx + dy * dy < r * r) {
				  m->alive = 0;
				  /* one less enemy on this missile -- it probably didn't make it */
				  if (st->missile[m->target].alive)
					 st->missile[m->target].enemies--;
				}
		  }
		}
	 
	 if (m->alive == 0) {
		/* we just died */
		XDrawLine(st->dpy, st->window, st->erase_gc,
				  m->x, m->y, x, y);
		Explode(st, m->x, m->y, kBoomRad, m->color, 1);
	 }
  }
}
Beispiel #15
0
static void LoopMissiles(struct state *st, int xlim, int ylim)
{
  int i, j, max = 0;
  for (i = 0; i < kMaxMissiles; i++) {
	 int old_x, old_y;
	 Missile *m = &st->missile[i];
	 if (!m->alive)
		continue;
	 old_x = m->x;
	 old_y = m->y;
	 m->pos += kMissileSpeed;
	 m->x = m->startx + ((float) (m->endx - m->startx)) * m->pos;
	 m->y = m->starty + ((float) (m->endy - m->starty)) * m->pos;

      /* erase old one */

	 XSetLineAttributes(st->dpy, st->draw_gc, 4, 0,0,0);
    XSetForeground (st->dpy, st->draw_gc, m->color.pixel);
	 XDrawLine(st->dpy, st->window, st->draw_gc,
				  old_x, old_y, m->x, m->y);

	 /* maybe split off a new missile? */
	 if (m->splits && (m->y > m->splits)) {
		m->splits = 0;
		launch(st, xlim, ylim, i);
	 }
	 
	 if (m->y >= ylim) {
		m->alive = 0;
		if (st->city[m->dcity].alive) {
		  st->city[m->dcity].alive = 0;
		  Explode(st, m->x, m->y, kBoomRad * 2, m->color, 0);
		}
	 }

	 /* check hitting explosions */
	 for (j=0;j<kMaxBooms;j++) {
		Boom *b = &st->boom[j];
		if (!b->alive)
		  continue;
		else {
		  int dx = abs(m->x - b->x);
		  int dy = abs(m->y - b->y);
		  int r = b->rad + 2;
		  if ((dx < r) && (dy < r))
			 if (dx * dx + dy * dy < r * r) {
				m->alive = 0;
				max = b->max + st->bgrowth - kBoomRad;
				AddScore(st, xlim, ylim, SCORE_MISSILE);
		  }
		}
	 }

	 if (m->alive == 0) {
		float my_pos;
		/* we just died */
		Explode(st, m->x, m->y, kBoomRad + max, m->color, 0);
		XSetLineAttributes(st->dpy, st->erase_gc, 4, 0,0,0);
		/* In a perfect world, we could simply erase a line from
		   (m->startx, m->starty) to (m->x, m->y). This is not a
		   perfect world. */
		old_x = m->startx;
		old_y = m->starty;
		my_pos = kMissileSpeed;
		while (my_pos <= m->pos) {
			m->x = m->startx + ((float) (m->endx - m->startx)) * my_pos;
			m->y = m->starty + ((float) (m->endy - m->starty)) * my_pos;
			XDrawLine(st->dpy, st->window, st->erase_gc, old_x, old_y, m->x, m->y);
			old_x = m->x;
			old_y = m->y;
			my_pos += kMissileSpeed;
		}
	 }
  }
}
Beispiel #16
0
void InitItemDraw(struct XObj *xobj)
{
  unsigned long mask;
  XSetWindowAttributes Attr;
  int minHeight,minWidth;
  int asc,desc,dir;
  XCharStruct struc;
#ifdef I18N_MB
  char **ml;
  XFontStruct **fs_list;
#endif

  /* Enregistrement des couleurs et de la police */
  if (xobj->colorset >= 0) {
    xobj->TabColor[fore] = Colorset[xobj->colorset].fg;
    xobj->TabColor[back] = Colorset[xobj->colorset].bg;
    xobj->TabColor[hili] = Colorset[xobj->colorset].hilite;
    xobj->TabColor[shad] = Colorset[xobj->colorset].shadow;
  } else {
    xobj->TabColor[fore] = GetColor(xobj->forecolor);
    xobj->TabColor[back] = GetColor(xobj->backcolor);
    xobj->TabColor[hili] = GetColor(xobj->hilicolor);
    xobj->TabColor[shad] = GetColor(xobj->shadcolor);
  }

  Attr.background_pixel = xobj->TabColor[back];
  mask = CWBackPixel;

  xobj->win = XCreateWindow(dpy, *xobj->ParentWin,
		xobj->x, xobj->y, xobj->width, xobj->height, 0,
		CopyFromParent, InputOutput, CopyFromParent,
		mask, &Attr);
  xobj->gc = fvwmlib_XCreateGC(dpy, xobj->win, 0, NULL);
  XSetForeground(dpy, xobj->gc, xobj->TabColor[fore]);

#ifdef I18N_MB
  if ((xobj->xfontset = GetFontSetOrFixed(dpy,xobj->font)) == NULL) {
    fprintf(stderr, "FvwmScript: Couldn't load font. Exiting!\n");
    exit(1);
  }
  XFontsOfFontSet(xobj->xfontset, &fs_list, &ml);
  xobj->xfont = fs_list[0];
#else
  if ((xobj->xfont = GetFontOrFixed(dpy, xobj->font)) == NULL) {
    fprintf(stderr, "FvwmScript: Couldn't load font. Exiting!\n");
    exit(1);
  }
#endif
  XSetFont(dpy, xobj->gc, xobj->xfont->fid);

  XSetLineAttributes(dpy, xobj->gc, 1, LineSolid, CapRound, JoinMiter);

  /* Redimensionnement du widget */
  if (strlen(xobj->title) != 0)
    XTextExtents(xobj->xfont, "lp", strlen("lp"), &dir, &asc, &desc, &struc);
  else {
    asc = 0;
    desc = 0;
  }

  if (xobj->icon == NULL)
  {
    if (strlen(xobj->title) != 0)
    {
      /* title but no icon */
      minHeight = asc+desc+2;
      minWidth = XTextWidth(xobj->xfont, xobj->title, strlen(xobj->title))+2;
      if (xobj->height < minHeight)
	xobj->height = minHeight;
      if (xobj->width < minWidth)
	xobj->width = minWidth;
    }
  }
  else if (strlen(xobj->title)==0)
  {
    /* icon but no title */
    if (xobj->height<xobj->icon_h)
      xobj->height = xobj->icon_h;
    if (xobj->width<xobj->icon_w)
      xobj->width = xobj->icon_w;
  }
  else
  {
    /* title and icon */
    if (xobj->icon_w>XTextWidth(xobj->xfont, xobj->title, strlen(xobj->title))+2)
    {
      /* icon is wider than the title */
      if (xobj->width<xobj->icon_w)
	xobj->width = xobj->icon_w;
    }
    else
    {
      /* title is wider than icon */
      if (xobj->width < 
	  XTextWidth(xobj->xfont, xobj->title, strlen(xobj->title)) + 2)
	xobj->width =
	  XTextWidth(xobj->xfont, xobj->title, strlen(xobj->title))+2;
    }
    xobj->height = xobj->icon_h+asc+desc+2;
  }
  XResizeWindow(dpy, xobj->win, xobj->width, xobj->height);
  if (xobj->colorset >= 0)
    SetWindowBackground(dpy, xobj->win, xobj->width, xobj->height,
			&Colorset[xobj->colorset], Pdepth,
			xobj->gc, True);
  XSelectInput(dpy, xobj->win, ExposureMask);
  /* x and y value of a clic */
  xobj->value2 = -1;
  xobj->value3 = -1;
}
Beispiel #17
0
Display * x11setup(Window *win, GC *gc, int width, int height)
{

    /* --------------------------- X11 graphics setup ------------------------------ */
    Display 		*display;
    unsigned int 	win_x,win_y, /* window position */
                    border_width, /* border width in pixels */
                    display_width, display_height, /* size of screen */
                    screen; /* which screen */

    char 			window_name[] = "N-Body Simulation", *display_name = NULL;
    unsigned long 	valuemask = 0;
    XGCValues 		values;

    XSizeHints 		size_hints;

    //Pixmap 		bitmap;
    //XPoint 		points[800];
    FILE 			*fopen ();//, *fp;
    //char 			str[100];

    XSetWindowAttributes attr[1];

    if ( (display = XOpenDisplay (display_name)) == NULL ) { /* connect to Xserver */
        fprintf (stderr, "Cannot connect to X server %s\n",XDisplayName (display_name) );
        exit (-1);
    }

    screen = DefaultScreen (display); /* get screen size */
    display_width = DisplayWidth (display, screen);
    display_height = DisplayHeight (display, screen);

    win_x = 0; win_y = 0; /* set window position */

    border_width = 4; /* create opaque window */
    *win = XCreateSimpleWindow (display, RootWindow (display, screen),
            win_x, win_y, width, height, border_width,
            WhitePixel (display, screen), BlackPixel (display, screen));

    size_hints.flags = USPosition|USSize;
    size_hints.x = win_x;
    size_hints.y = win_y;
    size_hints.width = width;
    size_hints.height = height;
    size_hints.min_width = 300;
    size_hints.min_height = 300;

    XSetNormalHints (display, *win, &size_hints);
    XStoreName(display, *win, window_name);

    *gc = XCreateGC (display, *win, valuemask, &values); /* create graphics context */

    XSetBackground (display, *gc, BlackPixel (display, screen));
    XSetForeground (display, *gc, WhitePixel (display, screen));
    XSetLineAttributes (display, *gc, 1, LineSolid, CapRound, JoinRound);

    attr[0].backing_store = Always;
    attr[0].backing_planes = 1;
    attr[0].backing_pixel = BlackPixel(display, screen);

    XChangeWindowAttributes(display, *win, CWBackingStore | CWBackingPlanes | CWBackingPixel, attr);

    XSelectInput(display, *win, KeyPressMask);

    XMapWindow (display, *win);
    XSync(display, 0);

    /* --------------------------- End of X11 graphics setup ------------------------------ */
    return display;
}
Beispiel #18
0
ENTRYPOINT void
init_flow (ModeInfo * mi)
{
	flowstruct *sp;
	char       *name;
	
	if (flows == NULL) {
		if ((flows = (flowstruct *) calloc(MI_NUM_SCREENS(mi),
										   sizeof (flowstruct))) == NULL)
			return;
	}
	sp = &flows[MI_SCREEN(mi)];

	sp->count2 = 0;

	sp->taillen = MI_SIZE(mi);
	if (sp->taillen < -MINTRAIL) {
		/* Change by sqrt so it seems more variable */
		sp->taillen = NRAND((int)sqrt((double) (-sp->taillen - MINTRAIL + 1)));
		sp->taillen = sp->taillen * sp->taillen + MINTRAIL;
	} else if (sp->taillen < MINTRAIL) {
		sp->taillen = MINTRAIL;
	}

	if(!rotatep && !ridep) rotatep = True; /* We need at least one viewpoint */

	/* Start camera at Orbit or Bee */
	if(rotatep) {
		sp->chaseto = ORBIT;
	} else {
		sp->chaseto = BEE;
	}
	sp->chasetime = 1; /* Go directly to target */

	sp->lyap = 0;
	sp->yperiod = 0;
	sp->step2 = INITIALSTEP;

	/* Zero parameter set */
	memset(sp->par2, 0, N_PARS * sizeof(dvector));

	/* Set up standard examples */
	switch (NRAND((periodicp) ? 5 : 3)) {
	case 0:
		/*
		  x' = a(y - x)
		  y' = x(b - z) - y
		  z' = xy - cz
		 */
		name = "Lorentz";
		sp->par2[Y].x = 10 + balance_rand(5*0); /* a */
		sp->par2[X].x = - sp->par2[Y].x;        /* -a */
		sp->par2[X].y = 28 + balance_rand(5*0); /* b */
		sp->par2[XZ].y = -1;
		sp->par2[Y].y = -1;
		sp->par2[XY].z = 1;
		sp->par2[Z].z = - 2 + balance_rand(1*0); /* -c */		
		break;
	case 1:
		/*
		  x' = -(y + az)
		  y' = x + by
		  z' = c + z(x - 5.7)
		 */
		name = "Rossler";
		sp->par2[Y].x = -1;
		sp->par2[Z].x = -2 + balance_rand(1); /* a */
		sp->par2[X].y = 1;
		sp->par2[Y].y = 0.2 + balance_rand(0.1); /* b */
		sp->par2[C].z = 0.2 + balance_rand(0.1); /* c */
		sp->par2[XZ].z = 1;
		sp->par2[Z].z = -5.7;
		break;
	case 2: 
		/*
		  x' = -(y + az)
		  y' = x + by - cz^2
		  z' = 0.2 + z(x - 5.7)
		 */
		name = "RosslerCone";
		sp->par2[Y].x = -1;
		sp->par2[Z].x = -2; /* a */
		sp->par2[X].y = 1;
		sp->par2[Y].y = 0.2; /* b */
		sp->par2[ZZ].y = -0.331 + balance_rand(0.01); /* c */
		sp->par2[C].z = 0.2;
		sp->par2[XZ].z = 1;
		sp->par2[Z].z = -5.7;
		break;
	case 3:
		/*
		  x' = -z + b sin(y)
		  y' = c
		  z' = 0.7x + az(0.1 - x^2) 
		 */
		name = "Birkhoff";
		sp->par2[Z].x = -1;
		sp->par2[SINY].x = 0.35 + balance_rand(0.25); /* b */
		sp->par2[C].y = 1.57; /* c */
		sp->par2[X].z = 0.7;
		sp->par2[Z].z = 1 + balance_rand(0.5); /* a/10 */
		sp->par2[XXZ].z = -10 * sp->par2[Z].z; /* -a */
		sp->yperiod = 2 * M_PI;
		break;
	default:
		/*
		  x' = -ax - z/2 - z^3/8 + b sin(y)
		  y' = c
		  z' = 2x
		 */
		name = "Duffing";
		sp->par2[X].x = -0.2 + balance_rand(0.1); /* a */
		sp->par2[Z].x = -0.5;
		sp->par2[ZZZ].x = -0.125;
		sp->par2[SINY].x = 27.0 + balance_rand(3.0); /* b */
		sp->par2[C].y = 1.33; /* c */
		sp->par2[X].z = 2;
		sp->yperiod = 2 * M_PI;
		break;

	}

	sp->range.x = 5;
	sp->range.z = 5;

	if(sp->yperiod > 0) {
		sp->ODE = Periodic;
		/* periodic flows show either uniform distribution or a
           snapshot on the 'time' axis */
		sp->range.y = NRAND(2)? sp->yperiod : 0;
	} else {
		sp->range.y = 5;
		sp->ODE = Cubic;
	}

	/* Run discoverer to set up bounding box, etc.  Lyapunov will
	   probably be innaccurate, since we're only running it once, but
	   we're using known strange attractors so it should be ok. */
	discover(mi);
	if(MI_IS_VERBOSE(mi))
		fprintf(stdout,
				"flow: Lyapunov exponent: %g, step: %g, size: %g (%s)\n",
				sp->lyap2, sp->step2, sp->size2, name);
	/* Install new params */
	sp->lyap = sp->lyap2;
	sp->size = sp->size2;
	sp->mid = sp->mid2;
	sp->step = sp->step2;
	memcpy(sp->par, sp->par2, sizeof(sp->par2));

	sp->count2 = 0; /* Reset search */

	free_flow(sp);
	sp->beecount = MI_COUNT(mi);
	if (sp->beecount < 0) {	/* random variations */
		sp->beecount = NRAND(-sp->beecount) + 1; /* Minimum 1 */
	}

# ifdef HAVE_COCOA	/* Don't second-guess Quartz's double-buffering */
  dbufp = False;
# endif

	if(dbufp) { /* Set up double buffer */
		if (sp->buffer != None)
			XFreePixmap(MI_DISPLAY(mi), sp->buffer);
		sp->buffer = XCreatePixmap(MI_DISPLAY(mi), MI_WINDOW(mi),
								 MI_WIDTH(mi), MI_HEIGHT(mi), MI_DEPTH(mi));
	} else {
		sp->buffer = MI_WINDOW(mi);
	}
	/* no "NoExpose" events from XCopyArea wanted */
	XSetGraphicsExposures(MI_DISPLAY(mi), MI_GC(mi), False);

	/* Make sure we're using 'thin' lines */
	XSetLineAttributes(MI_DISPLAY(mi), MI_GC(mi), 0, LineSolid, CapNotLast,
					   JoinMiter);

	/* Clear the background (may be slow depending on user prefs). */
	MI_CLEARWINDOW(mi);

	/* Allocate memory. */
	if (sp->csegs == NULL) {
		allocate(sp->csegs, XSegment,
				 (sp->beecount + BOX_L) * MI_NPIXELS(mi) * sp->taillen);
		allocate(sp->cnsegs, int, MI_NPIXELS(mi));
		allocate(sp->old_segs, XSegment, sp->beecount * sp->taillen);
		allocate(sp->p, dvector, sp->beecount * sp->taillen);
	}
Beispiel #19
0
void InitPopupMenu(struct XObj *xobj)
{
  unsigned long mask;
  XSetWindowAttributes Attr;
  int i;
  char *str;

  /* Enregistrement des couleurs et de la police / set the colors and the font
   */
  if (xobj->colorset >= 0) {
    xobj->TabColor[fore] = Colorset[xobj->colorset].fg;
    xobj->TabColor[back] = Colorset[xobj->colorset].bg;
    xobj->TabColor[hili] = Colorset[xobj->colorset].hilite;
    xobj->TabColor[shad] = Colorset[xobj->colorset].shadow;
  } else {
    xobj->TabColor[fore] = GetColor(xobj->forecolor);
    xobj->TabColor[back] = GetColor(xobj->backcolor);
    xobj->TabColor[hili] = GetColor(xobj->hilicolor);
    xobj->TabColor[shad] = GetColor(xobj->shadcolor);
  }

  mask = 0;
  Attr.background_pixel = xobj->TabColor[back];
  mask |= CWBackPixel;
  Attr.cursor = XCreateFontCursor(dpy, XC_hand2);
  mask |= CWCursor;             /* Curseur pour la fenetre / window cursor */

  xobj->win = XCreateWindow(dpy, *xobj->ParentWin,
		xobj->x, xobj->y, xobj->width, xobj->height, 0,
		CopyFromParent, InputOutput, CopyFromParent,
		mask, &Attr);
  xobj->gc = fvwmlib_XCreateGC(dpy, xobj->win, 0, NULL);
  XSetForeground(dpy, xobj->gc, xobj->TabColor[fore]);

  if ((xobj->Ffont = FlocaleLoadFont(dpy, xobj->font, ScriptName)) == NULL)
  {
    fprintf(stderr, "%s: Couldn't load font. Exiting!\n", ScriptName);
    exit(1);
  }
  if (xobj->Ffont->font != NULL)
    XSetFont(dpy, xobj->gc, xobj->Ffont->font->fid);

  XSetLineAttributes(dpy, xobj->gc, 1, LineSolid, CapRound, JoinMiter);
  xobj->value3 = CountOption(xobj->title);
  if (xobj->value > xobj->value3)
    xobj->value = xobj->value3;
  if (xobj->value < 1)
    xobj->value = 1;

  /* Redimensionnement du widget / Widget resizing */
  xobj->height = xobj->Ffont->height  +12;
  xobj->width = 30;
  for (i = 1; i <= xobj->value3; i++)
  {
    str = (char*)GetMenuTitle(xobj->title, i);
    if (xobj->width < FlocaleTextWidth(xobj->Ffont, str, strlen(str))+34)
      xobj->width = FlocaleTextWidth(xobj->Ffont, str, strlen(str))+34;
    free(str);
  }
  XResizeWindow(dpy, xobj->win, xobj->width, xobj->height);
  if (xobj->colorset >= 0)
    SetWindowBackground(dpy, xobj->win, xobj->width, xobj->height,
			&Colorset[xobj->colorset], Pdepth,
			xobj->gc, True);
  XSelectInput(dpy, xobj->win, ExposureMask);
}
int main(void)
{
	Display *display;
	Window window;      //initialization for a window
	int screen;         //which screen

	/* open connection with the server */
	display = XOpenDisplay(NULL);
	if(display == NULL) {
		fprintf(stderr, "cannot open display\n");
		return 0;
	}

	screen = DefaultScreen(display);

	/* set window size */
	int width = 400;
	int height = 400;

	/* set window position */
	int x = 0;
	int y = 0;

	/* border width in pixels */
	int border_width = 0;

	/* create window */
	window = XCreateSimpleWindow(display, RootWindow(display, screen), x, y, width, height, border_width,
					BlackPixel(display, screen), WhitePixel(display, screen));

	/* create graph */
	GC gc;
	XGCValues values;
	long valuemask = 0;

	gc = XCreateGC(display, window, valuemask, &values);
	//XSetBackground (display, gc, WhitePixel (display, screen));
	XSetForeground (display, gc, BlackPixel (display, screen));
	XSetBackground(display, gc, 0X0000FF00);
	XSetLineAttributes (display, gc, 1, LineSolid, CapRound, JoinRound);

	/* map(show) the window */
	XMapWindow(display, window);
	XSync(display, 0);

	int* repeatsBuffer;
	repeatsBuffer  = (int*)malloc(sizeof(int) * width * height);
	const int threadNum = 50;
	pthread_t threads[threadNum];
	WorkPara* paras[threadNum];
	WorkPara* para;
	int numPerThread;
	int i;
	struct timespec timeStart, timeEnd;

	clock_gettime(CLOCK_REALTIME, &timeStart);
	numPerThread = width % threadNum == 0 ? width / threadNum : width / threadNum + 1;
	for(i=0;i<threadNum;i++){
		para = paras[i] = (WorkPara*)malloc(sizeof(WorkPara));
		para -> repeatsBuffer = repeatsBuffer;
		para -> width = width;
		para -> height = height;
		para -> start = numPerThread * i;
		para -> end = para -> start + numPerThread;
		if(para -> end > width){
			para -> end = width;
		}
		para -> tid = i;
		pthread_create(&threads[i], NULL, doWork, (void*)para);
	}

	for(i = 0; i < threadNum ; i++){
		pthread_join(threads[i],NULL);
	}
	clock_gettime(CLOCK_REALTIME, &timeEnd);
	
	printf("Time Usage: %lf s\n", (double)(timeEnd.tv_sec - timeStart.tv_sec) + (double)(timeEnd.tv_nsec - timeStart.tv_nsec)/1e9);
	fflush(stdout);
	for(i = 0; i < width * height; i++){
		XSetForeground (display, gc,  1024 * 1024 * (repeatsBuffer[i] % 256));
		//printf("%d\n",repeatsBuffer[i]);
		XDrawPoint (display, window, gc, i/width, i%width);
	}
	XFlush(display);

	for(i = 0; i < threadNum ; i++){
		free(paras[i]);
	}
	free(repeatsBuffer);

	sleep(5);
	return 0;
}
int main(int argc, char **argv)
{
    threads = atoi(argv[1]);
    
    atof(minX, 2);
    atof(maxX, 3);
    atof(minY, 4);
    atof(maxY, 5);
    width = atoi(argv[6]);
    height = atoi(argv[7]);
    
    std::string in = argv[8];
    if (in == "enable")
        isEnable = true;
    else
        isEnable = false;

/********* MPI MISSION START *********/
    
    int rank, size;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank (MPI_COMM_WORLD, &rank);
    MPI_Comm_size (MPI_COMM_WORLD, &size);
    
    MPI_Status status;
    Display *display;
	Window window;      //initialization for a window
	int screen;         //which screen 

	/* set window position */
	int x = 0;
	int y = 0;
	
    /* create graph */
	GC gc;
	XGCValues values;
	long valuemask = 0;

	/* border width in pixels */
	int border_width = 0;
	/* open connection with the server */
    
	/* draw points */
    int numPerTask = width / (size);
    if (rank == size - 1)
       numPerTask += width % (size);
    
    if (isEnable && rank == 0) {
        display = XOpenDisplay(NULL);
        if(display == NULL) {
            fprintf(stderr, "cannot open display\n");
            return 0;
        }

        screen = DefaultScreen(display);

        /* set window size */
        
        /* create window */
        window = XCreateSimpleWindow(display, 
            RootWindow(display, screen), x, y, 
                width, height, border_width, 
                    BlackPixel(display, screen), 
                        WhitePixel(display, screen));
        
        gc = XCreateGC(display, window, valuemask, &values);
        //XSetBackground (display, gc, WhitePixel (display, screen));
        XSetForeground (display, gc, BlackPixel (display, screen));
        XSetBackground(display, gc, 0X0000FF00);
        XSetLineAttributes (display, gc, 1, LineSolid, CapRound, JoinRound);
        
        /* map(show) the window */
        XMapWindow(display, window);
        XSync(display, 0);
        if (isEnable)  
             XFlush(display);
        
    }

    Pixel *pixel = new Pixel[numPerTask * height];
    int curIndex = 0;
    int beginPos = rank != size - 1 ?  
        numPerTask * (rank) : (rank) * (numPerTask - (width % (size)));
    
     
    printf("rank %d -> begin = %d, numTasks = %d\n", rank, beginPos, numPerTask);
    int ansK = -1;
    for(int i = beginPos, k = 0; k < numPerTask; i++, k++) {
        ansK = ansK > i ? ansK : i;
        for(int j=0; j<height; j++) {
            // printf("rank %d : (%d, %d)\n", rank, i, j);
            Compl z, c;
            double temp, lengthsq;
            int repeats;
            z.real = 0.0;
            z.imag = 0.0;
            
            double scaleX = width / (maxX - minX);
            double scaleY = height / (maxY - minY);
            
            c.real = ((double)i + scaleX * minX) / scaleX; 
            /* Theorem : If c belongs to M(Mandelbrot set), then |c| <= 2 */
            
            c.imag = ((double)j + scaleY * minY) / scaleY; 
            /* So needs to scale the window */

            repeats = 0;
            lengthsq = 0.0;

            while(repeats < 10000 && lengthsq < 4.0) { 
                /* Theorem : If c belongs to M, then |Zn| <= 2. So Zn^2 <= 4 */
                temp = z.real*z.real - z.imag*z.imag + c.real;
                z.imag = 2*z.real*z.imag + c.imag;
                z.real = temp;
                lengthsq = z.real*z.real + z.imag*z.imag;
                 
                repeats++;
            }
            
            if (!isEnable) continue; 
            pixel[curIndex++] = Pixel(i, j, repeats);
        }
    }

    printf("Rank[%d] ansK = %d\n", rank, ansK);
    
    if (rank != 0) {
        send(&curIndex, 1, MPI_INT, ROOT);
       // printf("rank %d send curIndex %d ...\n", rank, curIndex);
       // sleep(5);
        send(pixel, curIndex * sizeof(Pixel), MPI_CHAR, ROOT);
       // printf("rank %d send pixel...\n", rank);
    }
    else if (isEnable) {
        for (int index = 0; index < curIndex; ++index) {
            XSetForeground (display, gc,  
                        1024 * 1024 * (pixel[index].repeats % 256));	
            XDrawPoint (display, window, gc, pixel[index].i, pixel[index].j);
        }
            
        std::vector <Pixel> drawGraph; 
        for (int threads = 1; threads < size; ++threads) {
            int pixelNum;
            recv(&pixelNum, sizeof(int), MPI_INT, threads);
            // printf("recv pixelNum =  %d\n", pixelNum);   
            Pixel *pixel = new Pixel[pixelNum];
            recv(pixel, pixelNum * sizeof(Pixel), MPI_CHAR, threads);
            for (int i = 0; i < pixelNum; ++i)
                drawGraph.push_back(pixel[i]);
            delete [] pixel;
        }
        int drawTimes = 2;
        while (drawTimes--) {
          for (int k = 0; k < drawGraph.size(); ++k) {
              int i = drawGraph[k].i;
              int j = drawGraph[k].j;
              int repeats = drawGraph[k].repeats;

              XSetForeground (display, gc,  
                          1024 * 1024 * (repeats % 256));	
              XDrawPoint (display, window, gc, i, j);
          }
        }
    }
    delete [] pixel;

    MPI_Finalize();
    if (isEnable) sleep(5);
	return 0;
}
Beispiel #22
0
void
draw_stress(void) {
  int i, j, npoints, start, end;
  /*float width = (float) (str_width) - 2. * (float) STR_HMARGIN;*/
  /*float maxwidth = (float) MAXSTRVALUES;*/
  float height = (float) (str_height) - 2. * (float) STR_VMARGIN;
  float x, y;
  static Boolean initd = False;
  XPoint axes[3];
  char str[32];
  static int strwidth;
  XPoint strPts[MAXSTRVALUES];

  if (!initd) {
    str_window = XtWindow(str_wksp);
    make_str_pixmap();

    sprintf(str, ".9999");
    strwidth = XTextWidth(appdata.plotFont, str, strlen(str));

    initd = True;
  }

  /*
   * The starting point should be zero until npoints has
   * been surpassed; after that, it should be nstrValues
   * minus npoints.  Define the indices for strPts.
  */
  /* plotting one point per pixel ... */
  npoints = MIN(str_width - 2*STR_HMARGIN, nstrValues);
  start = MAX(0, nstrValues - npoints);
  end = nstrValues;

  for (i=start, j=0; i<end; i++, j++) {
    x = (float) j ;
    strPts[j].x = (int) (x + STR_HMARGIN);
    y = (float) (1 - strValues[i]) * height;
    strPts[j].y = (int) (y + STR_VMARGIN);
  }

  /* axes */
  axes[0].x = STR_HMARGIN;
  axes[0].y = STR_VMARGIN;
  axes[1].x = STR_HMARGIN;
  axes[1].y = str_height - STR_VMARGIN;
  axes[2].x = str_width - STR_HMARGIN;
  axes[2].y = str_height - STR_VMARGIN;

  /* stress as a fraction */
  sprintf(str, "%2.4f", strValues[nstrValues-1]);

  XSetForeground(display, copy_GC, plotcolors.fg);
  clear_str_pixmap();
  XDrawLines(display, str_pixmap, copy_GC,
    axes, 3, CoordModeOrigin);
  if (nstrValues) {
    XDrawString(display, str_pixmap, copy_GC,
      str_width - 2*STR_HMARGIN - strwidth,
      FONTHEIGHT(appdata.plotFont),
      str,
      strlen(str));
    XSetLineAttributes(display, copy_GC, 2, LineSolid,
      CapRound, JoinBevel);
    XDrawLines(display, str_pixmap, copy_GC,
      strPts, npoints, CoordModeOrigin);
    XSetLineAttributes(display, copy_GC, 1, LineSolid,
      CapRound, JoinBevel);
  }
  copy_str_pixmap();
}
int main (int argc, char **argv){
int i,j;
WMColor *color;
WMWindow * win;
RImage *image;
struct _pict pict;
Drawable de;

RColor one, two={0xaf, 0x0f,0xff,0x33};
one.red=247;
one.green=251;
one.blue=107;
one.alpha=0xff;


WMInitializeApplication("DrawWin", &argc, argv);
display = XOpenDisplay("");
screen = WMCreateScreen(display, DefaultScreen(display));
win = WMCreateWindow(screen, "");
WMResizeWidget(win, WINWIDTH, WINHEIGHT);
WMSetWindowCloseAction(win, closeAction, NULL);
WMSetWindowTitle(win,"Graphics");
color = WMCreateRGBColor(screen,124<<9,206<<8,162<<8, False);
WMSetWidgetBackgroundColor((WMWidget *)win, color);
       /* end setup main window */

image=RCreateImage( 100,100,0.5);
RFillImage(image, &two);
RDrawLine(image, 50,10,90,90,&one);
RDrawLine(image, 10,90,50,10,&one);
RDrawLine(image, 10,90,90,90,&one);

g3=WMColorGC(screen->gray);
XSetLineAttributes(display,g3,3,LineSolid,CapButt,JoinMiter);

pict.segments[1].x1= pict.segments[0].x1=HOFF;
pict.segments[0].x2=HOFF;
pict.segments[0].y1=VOFF;
pict.segments[1].y2=  pict.segments[0].y2=VOFF;
pict.segments[1].x2= HOFF+10;
pict.segments[1].y1=VOFF+10;
pict.seglen=2;
for (i=9;i>0;i--){
 j=2*(10-i);
 pict.segments[j+1].x1= pict.segments[j].x1=HOFF;
 pict.segments[j+1].y2= pict.segments[j].y2=VOFF;
 pict.segments[j].x2= i+pict.segments[j-1].x2;
 pict.segments[j].y1=i+pict.segments[j-1].y1;
 pict.segments[j+1].x2= i+pict.segments[j].x2;
 pict.segments[j+1].y1=i+pict.segments[j].y1;
 pict.seglen+=2;
};


WMRealizeWidget(win);

pict.dwin=W_VIEW_DRAWABLE(WMWidgetView(win));
pixmap=WMCreatePixmapFromRImage(screen, image,1);

WMCreateEventHandler(WMWidgetView(win), ExposureMask,drawProcedure,&pict);

WMMapWidget(win);
WMScreenMainLoop(screen);
}
Beispiel #24
0
int setEpaisseurCrayon(TC *p,int e)
{
  XSetLineAttributes(p->display,p->gc,e,LineSolid,CapRound,JoinRound);
  return 0;
}
Beispiel #25
0
static bool LogoCallBack(t_x11 *x11, XEvent *event, Window /*w*/, void *data)
{
    /* Assume window is 100x110 */
    static bool bFirst = true;
#define CSIZE 9
#define NSIZE 8
#define OSIZE 9
#define HSIZE 7
#define YOFFS 30
    static t_circle c[] = {
        { 10, YOFFS+12, CSIZE, &LIGHTGREEN },
        { 20, YOFFS+22, CSIZE, &LIGHTGREEN },
        { 20, YOFFS+34, OSIZE, &LIGHTRED   },
        { 30, YOFFS+12, NSIZE, &LIGHTCYAN  },
        { 30, YOFFS+ 2, HSIZE, &WHITE     },
        { 40, YOFFS+22, CSIZE, &LIGHTGREEN },
        { 40, YOFFS+34, CSIZE, &LIGHTGREEN },
        { 50, YOFFS+12, CSIZE, &LIGHTGREEN },
        { 50, YOFFS,    OSIZE, &LIGHTRED   },
        { 60, YOFFS+22, NSIZE, &LIGHTCYAN  },
        { 60, YOFFS+32, HSIZE, &WHITE     },
        { 70, YOFFS+12, CSIZE, &LIGHTGREEN },
        { 80, YOFFS+22, CSIZE, &LIGHTGREEN },
        { 80, YOFFS+34, OSIZE, &LIGHTRED   },
        { 90, YOFFS+12, NSIZE, &LIGHTCYAN  },
        { 90, YOFFS+ 2, HSIZE, &WHITE      },
        {100, YOFFS+22, CSIZE, &LIGHTGREEN }
    };
    static int      lines[] = {
        0, 1, 1, 2, 1, 3, 3, 4, 3, 5, 5, 6, 5, 7, 7, 8, 7, 9,
        9, 10, 9, 11, 11, 12, 12, 13, 12, 14, 14, 15, 14, 16
    };
#define COFFS 70
    static t_mess   Mess[] = {
        { "GROMACS",                         0,       20, NULL },
        { NULL,                             16,        9, NULL },
        { "Copyright (c) 1991-2013",        COFFS+ 2,  9, NULL },
        { "D.v.d.Spoel, E.Lindahl, B.Hess", COFFS+11,  9, NULL },
        { "& Groningen University ",        COFFS+20,  9, NULL },
        { "click to dismiss",               COFFS+31,  8, NULL }
    };
#define NMESS asize(Mess)
    int             i;
    real            wfac, hfac;
    t_logo         *logo;
    t_windata      *wd;

    logo = (t_logo *)data;
    wd   = &(logo->wd);
    if (bFirst)
    {
        wfac = wd->width/110.0;
        hfac = wd->height/110.0;
        for (i = 0; (i < asize(c)); i++)
        {
            c[i].x *= wfac;
            c[i].y *= hfac;
        }
        Mess[1].text = GromacsVersion();
        for (i = 0; (i < NMESS); i++)
        {
            Mess[i].y  *= hfac;
            Mess[i].h  *= hfac;
            Mess[i].fnt = (i == 0) ? logo->bigfont : (i == NMESS-1) ? x11->font :
                logo->smallfont;
        }
        bFirst = false;
    }
    switch (event->type)
    {
        case Expose:
            XSetForeground(x11->disp, x11->gc, WHITE);
            XSetLineAttributes(x11->disp, x11->gc, 3, LineSolid, CapNotLast, JoinRound);
            for (i = 0; (i < asize(lines)); i += 2)
            {
                XDrawLine(x11->disp, wd->self, x11->gc,
                          c[lines[i]].x, c[lines[i]].y, c[lines[i+1]].x, c[lines[i+1]].y);
            }
            XSetLineAttributes(x11->disp, x11->gc, 1, LineSolid, CapNotLast, JoinRound);
            for (i = 0; (i < asize(c)); i++)
            {
                XSetForeground(x11->disp, x11->gc, *(c[i].col));
                XFillCircle(x11->disp, wd->self, x11->gc, c[i].x, c[i].y, c[i].rad);
            }
            XSetForeground(x11->disp, x11->gc, BLACK);
            XDrawRectangle(x11->disp, wd->self, x11->gc, 2, 2, wd->width-5, wd->height-5);
            for (i = 0; (i < NMESS); i++)
            {
                SpecialTextInRect(x11, Mess[i].fnt, wd->self, Mess[i].text,
                                  0, Mess[i].y, wd->width, Mess[i].h,
                                  eXCenter, eYCenter);
            }
            XSetForeground(x11->disp, x11->gc, x11->fg);
            break;
        case ButtonPress:
            hide_logo(x11, logo);
            return logo->bQuitOnClick;
            break;
        default:
            break;
    }

    return false;
}
Beispiel #26
0
void InitCheckBox(struct XObj *xobj)
{
  unsigned long mask;
  XSetWindowAttributes Attr;
  int asc,desc,dir;
  XCharStruct struc;
#ifdef I18N_MB
  char **ml;
  XFontStruct **fs_list;
#endif
  
  /* Enregistrement des couleurs et de la police / fonts and colors */
  if (xobj->colorset >= 0) {
    xobj->TabColor[fore] = Colorset[xobj->colorset].fg;
    xobj->TabColor[back] = Colorset[xobj->colorset].bg;
    xobj->TabColor[hili] = Colorset[xobj->colorset].hilite;
    xobj->TabColor[shad] = Colorset[xobj->colorset].shadow;
  } else {
    xobj->TabColor[fore] = GetColor(xobj->forecolor);
    xobj->TabColor[back] = GetColor(xobj->backcolor);
    xobj->TabColor[hili] = GetColor(xobj->hilicolor);
    xobj->TabColor[shad] = GetColor(xobj->shadcolor);
  }

  mask = 0;
  Attr.background_pixel = xobj->TabColor[back];
  mask |= CWBackPixel;
  Attr.cursor = XCreateFontCursor(dpy,XC_hand2);
  mask |= CWCursor;  /* Curseur pour la fenetre / Cursor for the window */

  xobj->win = XCreateWindow(dpy, *xobj->ParentWin,
		xobj->x, xobj->y, xobj->width, xobj->height,0,
		CopyFromParent, InputOutput, CopyFromParent,
		mask, &Attr);
  xobj->gc = fvwmlib_XCreateGC(dpy,xobj->win,0,NULL);
  XSetForeground(dpy, xobj->gc, xobj->TabColor[fore]);

#ifdef I18N_MB
  if ((xobj->xfontset = GetFontSetOrFixed(dpy,xobj->font)) == NULL) {
    fprintf(stderr, "FvwmScript: Couldn't load font. Exiting!\n");
    exit(1);
  }
  XFontsOfFontSet(xobj->xfontset,&fs_list,&ml);
  xobj->xfont = fs_list[0];
#else
  if ((xobj->xfont = GetFontOrFixed(dpy,xobj->font)) == NULL) {
    fprintf(stderr, "FvwmScript: Couldn't load font. Exiting!\n");
    exit(1);
  }
#endif
  XSetFont(dpy, xobj->gc, xobj->xfont->fid);

  XSetLineAttributes(dpy, xobj->gc, 1, LineSolid, CapRound, JoinMiter);

  /* Redimensionnement du widget / resize the widget */
  XTextExtents(xobj->xfont, "lp", strlen("lp"), &dir, &asc, &desc, &struc);
  xobj->height = asc+desc+5;
  xobj->width = XTextWidth(xobj->xfont, xobj->title, strlen(xobj->title)) + 30;
  XResizeWindow(dpy, xobj->win, xobj->width, xobj->height);
  if (xobj->colorset >= 0)
    SetWindowBackground(dpy, xobj->win, xobj->width, xobj->height,
			&Colorset[xobj->colorset], Pdepth,
			xobj->gc, True);
  XSelectInput(dpy, xobj->win, ExposureMask);
}
Beispiel #27
0
ENTRYPOINT void
draw_braid(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	int         num_points = 500;
	float       t_inc;
	float       theta, psi;
	float       t, r_diff;
	int         i, s;
	float       x_1, y_1, x_2, y_2, r1, r2;
	float       color, color_use = 0.0, color_inc;
	braidtype  *braid;

	if (braids == NULL)
		return;
	braid = &braids[MI_SCREEN(mi)];

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

	MI_IS_DRAWN(mi) = True;
	XSetLineAttributes(display, MI_GC(mi), braid->linewidth,
			   LineSolid,
			   (braid->linewidth <= 3 ? CapButt : CapRound),
			   JoinMiter);

	theta = (2.0 * M_PI) / (float) (braid->braidlength);
	t_inc = (2.0 * M_PI) / (float) num_points;
	color_inc = (float) MI_NPIXELS(mi) * braid->color_direction /
		(float) num_points;
	braid->startcolor += SPINRATE * color_inc;
	if (((int) braid->startcolor) >= MI_NPIXELS(mi))
		braid->startcolor = 0.0;

	r_diff = (braid->max_radius - braid->min_radius) / (float) (braid->nstrands);

	color = braid->startcolor;
	psi = 0.0;
	for (i = 0; i < braid->braidlength; i++) {
		psi += theta;
		for (t = 0.0; t < theta; t += t_inc) {
#ifdef COLORROUND
			color += color_inc;
			if (((int) color) >= MI_NPIXELS(mi))
				color = 0.0;
			color_use = color;
#endif
			for (s = 0; s < braid->nstrands; s++) {
				if (ABS(braid->braidword[i]) == s)
					continue;
				if (ABS(braid->braidword[i]) - 1 == s) {
					/* crosSINFg */
#ifdef COLORCOMP
					if (MI_NPIXELS(mi) > 2) {
						color_use = color + SPINRATE *
							braid->components[applywordbackto(braid, s, i)] +
							(psi + t) / 2.0 / M_PI * (float) MI_NPIXELS(mi);
						while (((int) color_use) >= MI_NPIXELS(mi))
							color_use -= (float) MI_NPIXELS(mi);
						while (((int) color_use) < 0)
							color_use += (float) MI_NPIXELS(mi);
					}
#endif
#ifdef COLORROUND
					if (MI_NPIXELS(mi) > 2) {
						color_use += SPINRATE * color_inc;
						while (((int) color_use) >= MI_NPIXELS(mi))
							color_use -= (float) MI_NPIXELS(mi);
					}
#endif
					r1 = braid->min_radius + r_diff * (float) (s);
					r2 = braid->min_radius + r_diff * (float) (s + 1);
					if (braid->braidword[i] > 0 ||
					    (FABSF(t - theta / 2.0) > theta / 7.0)) {
						x_1 = ((0.5 * (1.0 + SINF(t / theta * M_PI - M_PI_2)) * r2 +
							0.5 * (1.0 + SINF((theta - t) / theta * M_PI - M_PI_2)) * r1)) *
							COSF(t + psi) + braid->center_x;
						y_1 = ((0.5 * (1.0 + SINF(t / theta * M_PI - M_PI_2)) * r2 +
							0.5 * (1.0 + SINF((theta - t) / theta * M_PI - M_PI_2)) * r1)) *
							SINF(t + psi) + braid->center_y;
						x_2 = ((0.5 * (1.0 + SINF((t + t_inc) / theta * M_PI - M_PI_2)) * r2 +
							0.5 * (1.0 + SINF((theta - t - t_inc) / theta * M_PI - M_PI_2)) * r1)) *
							COSF(t + t_inc + psi) + braid->center_x;
						y_2 = ((0.5 * (1.0 + SINF((t + t_inc) / theta * M_PI - M_PI_2)) * r2 +
							0.5 * (1.0 + SINF((theta - t - t_inc) / theta * M_PI - M_PI_2)) * r1)) *
							SINF(t + t_inc + psi) + braid->center_y;
						if (MI_NPIXELS(mi) > 2)
							XSetForeground(display, MI_GC(mi), MI_PIXEL(mi, (int) color_use));
						else
							XSetForeground(display, MI_GC(mi), MI_WHITE_PIXEL(mi));

						XDrawLine(display, window, MI_GC(mi),
							  (int) (x_1), (int) (y_1), (int) (x_2), (int) (y_2));
					}
#ifdef COLORCOMP
					if (MI_NPIXELS(mi) > 2) {
						color_use = color + SPINRATE *
							braid->components[applywordbackto(braid, s + 1, i)] +
							(psi + t) / 2.0 / M_PI * (float) MI_NPIXELS(mi);
						while (((int) color_use) >= MI_NPIXELS(mi))
							color_use -= (float) MI_NPIXELS(mi);
						while (((int) color_use) < 0)
							color_use += (float) MI_NPIXELS(mi);
					}
#endif
					if (braid->braidword[i] < 0 ||
					    (FABSF(t - theta / 2.0) > theta / 7.0)) {
						x_1 = ((0.5 * (1.0 + SINF(t / theta * M_PI - M_PI_2)) * r1 +
							0.5 * (1.0 + SINF((theta - t) / theta * M_PI - M_PI_2)) * r2)) *
							COSF(t + psi) + braid->center_x;
						y_1 = ((0.5 * (1.0 + SINF(t / theta * M_PI - M_PI_2)) * r1 +
							0.5 * (1.0 + SINF((theta - t) / theta * M_PI - M_PI_2)) * r2)) *
							SINF(t + psi) + braid->center_y;
						x_2 = ((0.5 * (1.0 + SINF((t + t_inc) / theta * M_PI - M_PI_2)) * r1 +
							0.5 * (1.0 + SINF((theta - t - t_inc) / theta * M_PI - M_PI_2)) * r2)) *
							COSF(t + t_inc + psi) + braid->center_x;
						y_2 = ((0.5 * (1.0 + SINF((t + t_inc) / theta * M_PI - M_PI_2)) * r1 +
							0.5 * (1.0 + SINF((theta - t - t_inc) / theta * M_PI - M_PI_2)) * r2)) *
							SINF(t + t_inc + psi) + braid->center_y;
						if (MI_NPIXELS(mi) > 2)
							XSetForeground(display, MI_GC(mi), MI_PIXEL(mi, (int) color_use));
						else
							XSetForeground(display, MI_GC(mi), MI_WHITE_PIXEL(mi));

						XDrawLine(display, window, MI_GC(mi),
							  (int) (x_1), (int) (y_1), (int) (x_2), (int) (y_2));
					}
				} else {
					/* no crosSINFg */
#ifdef COLORCOMP
					if (MI_NPIXELS(mi) > 2) {
						color_use = color + SPINRATE *
							braid->components[applywordbackto(braid, s, i)] +
							(psi + t) / 2.0 / M_PI * (float) MI_NPIXELS(mi);
						while (((int) color_use) >= MI_NPIXELS(mi))
							color_use -= (float) MI_NPIXELS(mi);
						while (((int) color_use) < 0)
							color_use += (float) MI_NPIXELS(mi);
					}
#endif
#ifdef COLORROUND
					if (MI_NPIXELS(mi) > 2) {
						color_use += SPINRATE * color_inc;
						while (((int) color_use) >= MI_NPIXELS(mi))
							color_use -= (float) MI_NPIXELS(mi);
					}
#endif
					r1 = braid->min_radius + r_diff * (float) (s);
					x_1 = r1 * COSF(t + psi) + braid->center_x;
					y_1 = r1 * SINF(t + psi) + braid->center_y;
					x_2 = r1 * COSF(t + t_inc + psi) + braid->center_x;
					y_2 = r1 * SINF(t + t_inc + psi) + braid->center_y;
					if (MI_NPIXELS(mi) > 2)
						XSetForeground(display, MI_GC(mi), MI_PIXEL(mi, (int) color_use));
					else
						XSetForeground(display, MI_GC(mi), MI_WHITE_PIXEL(mi));

					XDrawLine(display, window, MI_GC(mi),
						  (int) (x_1), (int) (y_1), (int) (x_2), (int) (y_2));
				}
			}
		}
	}
	XSetLineAttributes(display, MI_GC(mi), 1, LineSolid, CapNotLast, JoinRound);

	if (++braid->age > MI_CYCLES(mi)) {
#ifdef STANDALONE
      braid->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), braid->eraser);
#endif
		init_braid(mi);
	}
}
Beispiel #28
0
void INTERNAL_init_cursor(GC gc_pixmap)
{
    unsigned long valuemask = 0;
    XGCValues values;
    Cursor cursor;
    Pixmap hand, handmask;
    Pixmap updown, updownmask;
    unsigned long fg, bg;
    unsigned int width, height; 
    unsigned int hot_x, hot_y, hot2_x, hot2_y;
    int i;
    Colormap cmap;
    XColor black, white;

    init_store_cursor();

    for (i=0;i<G_MAXWINDOW;i++) 
        INTERNAL_reset_cursor(i);
    gc_pix = gc_pixmap;
    gc_crosshair= XCreateGC(INTERNAL_display,INTERNAL_rootwin,valuemask,&values);
    valuemask = GCLineStyle | GCLineWidth | GCCapStyle  | GCJoinStyle;
    XGetGCValues(INTERNAL_display,gc_pix,valuemask,&values);
    XSetLineAttributes(INTERNAL_display,
                       gc_pix,
                       0,
                       values.line_style,
                       values.cap_style,
                       values.join_style);
    XSetLineAttributes(INTERNAL_display,
                       gc_crosshair,
                       0,
                       values.line_style,
                       values.cap_style,
                       values.join_style);
    XSetFunction(INTERNAL_display, gc_crosshair, GXxor);
    XSetForeground(INTERNAL_display, gc_crosshair, 
              WhitePixel(INTERNAL_display, INTERNAL_screen) ^ 
              BlackPixel(INTERNAL_display, INTERNAL_screen));

    cur_cross = XCreateFontCursor(INTERNAL_display, XC_crosshair);
    cur_wait  = XCreateFontCursor(INTERNAL_display, XC_watch);
    XQueryBestCursor(INTERNAL_display, INTERNAL_rootwin, 32, 32, &width, &height);

    fg = 1;
    bg = 0;
    if (width >= 32 && height >= 32) {
        hand = XCreatePixmapFromBitmapData(INTERNAL_display, INTERNAL_rootwin,
               (char*)hand32_bits, hand32_width, hand32_height, fg, bg, 1); 
        handmask = XCreatePixmapFromBitmapData(INTERNAL_display, INTERNAL_rootwin,
               (char*)handm32_bits, handm32_width, handm32_height, fg, bg, 1);
        hot_x = 8;
        hot_y = 12;
        updown = XCreatePixmapFromBitmapData(INTERNAL_display, INTERNAL_rootwin,
               (char*)updown32_bits, updown32_width, updown32_height, fg, bg, 1); 
        updownmask = XCreatePixmapFromBitmapData(INTERNAL_display, INTERNAL_rootwin,
               (char*)updownmask32_bits, updownmask32_width, updownmask32_height, fg, bg, 1);
        hot2_x = 16;
        hot2_y = 16;
    }
    else { 
        hand = XCreatePixmapFromBitmapData(INTERNAL_display, INTERNAL_rootwin,
               (char*)hand_bits, hand_width, hand_height, fg, bg, 1); 
        handmask = XCreatePixmapFromBitmapData(INTERNAL_display, INTERNAL_rootwin,
               (char*)handmask_bits, handmask_width, handmask_height, fg, bg, 1);
        hot_x = 4;
        hot_y = 6;
        updown = XCreatePixmapFromBitmapData(INTERNAL_display, INTERNAL_rootwin,
               (char*)updown_bits, updown_width, updown_height, fg, bg, 1); 
        updownmask = XCreatePixmapFromBitmapData(INTERNAL_display, INTERNAL_rootwin,
               (char*)updownmask_bits, updownmask_width, updownmask_height, fg, bg, 1);
        hot2_x = 8;
        hot2_y = 8;
    }
    cmap    = DefaultColormap(INTERNAL_display,INTERNAL_screen);
    XParseColor(INTERNAL_display, cmap, "black", &black);
    XAllocColor(INTERNAL_display, cmap, &black);
    XParseColor(INTERNAL_display, cmap, "white", &white);
    XAllocColor(INTERNAL_display, cmap, &white);
 
    cur_hand = XCreatePixmapCursor(INTERNAL_display, hand, handmask, 
           &black, &white, hot_x, hot_y);
    cur_updown = XCreatePixmapCursor(INTERNAL_display, updown, updownmask, 
           &black, &white, hot2_x, hot2_y);

    XFreePixmap(INTERNAL_display, hand);
    XFreePixmap(INTERNAL_display, handmask);
}
Beispiel #29
0
G_MODULE_EXPORT int
test_pixmap_main (int argc, char **argv)
{
  GOptionContext      *context;
  Display	      *xdpy;
  int		       screen;
  ClutterActor        *group = NULL, *label, *stage, *tex;
  Pixmap               pixmap;
  const ClutterColor   gry = { 0x99, 0x99, 0x99, 0xFF };
  Window               win_remote;
  guint		       w, h, d;
  GC		       gc;
  ClutterTimeline     *timeline;
  ClutterAlpha	      *alpha;
  ClutterBehaviour    *depth_behavior;
  int		       i;
  int                  row_height;

#ifdef CLUTTER_WINDOWING_X11
  clutter_set_windowing_backend (CLUTTER_WINDOWING_X11);
#endif

  if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    return 1;

#ifdef CLUTTER_WINDOWING_X11
  if (!clutter_check_windowing_backend (CLUTTER_WINDOWING_X11))
    g_error ("test-pixmap requires the X11 Clutter backend.");
#endif

  xdpy = clutter_x11_get_default_display ();
  XSynchronize (xdpy, True);

  context = g_option_context_new (" - test-pixmap options");
  g_option_context_add_main_entries (context, g_options, NULL);
  g_option_context_parse (context, &argc, &argv, NULL);

  pixmap = create_pixmap (&w, &h, &d);

  screen = DefaultScreen(xdpy);
  win_remote = XCreateSimpleWindow (xdpy, DefaultRootWindow(xdpy),
				    0, 0, 200, 200,
				    0,
				    WhitePixel(xdpy, screen),
				    WhitePixel(xdpy, screen));

  XMapWindow (xdpy, win_remote);

  stage = clutter_stage_new ();
  clutter_actor_set_position (stage, 0, 150);
  clutter_actor_set_background_color (stage, &gry);
  clutter_stage_set_title (CLUTTER_STAGE (stage), "X11 Texture from Pixmap");
  g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);

  timeline = clutter_timeline_new (5000);
  g_signal_connect (timeline,
                    "completed", G_CALLBACK (timeline_completed),
                    NULL);

  alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR);
  depth_behavior = clutter_behaviour_depth_new (alpha, -2500, 400);

  if (!disable_x11)
    {
      group = clutter_group_new ();
      clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
      label = clutter_text_new_with_text ("fixed",
                                          "ClutterX11Texture (Window)");
      clutter_container_add_actor (CLUTTER_CONTAINER (group), label);
      tex = clutter_x11_texture_pixmap_new_with_window (win_remote);
      clutter_container_add_actor (CLUTTER_CONTAINER (group), tex);
      clutter_actor_set_position (tex, 0, 20);
      clutter_x11_texture_pixmap_set_automatic (CLUTTER_X11_TEXTURE_PIXMAP (tex),
                                                TRUE);
      clutter_texture_set_filter_quality (CLUTTER_TEXTURE (tex),
                                          CLUTTER_TEXTURE_QUALITY_HIGH);
      clutter_actor_set_position (group, 0, 0);
      if (!disable_animation)
        clutter_behaviour_apply (depth_behavior, group);
    }

  if (group)
    row_height = clutter_actor_get_height (group);
  else
    row_height = 0;

  /* NB: We only draw on the window after being redirected, so we dont
   * have to worry about handling expose events... */
  gc = XCreateGC (xdpy, win_remote, 0, NULL);
  XSetForeground (xdpy, gc, BlackPixel (xdpy, screen));
  XSetLineAttributes(xdpy, gc, 5, LineSolid, CapButt, JoinMiter);

  for (i = 0; i < 10; i++)
    XDrawLine (xdpy, win_remote, gc, 0+i*20, 0, 10+i*20+i, 200);


  group = clutter_group_new ();
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
  label = clutter_text_new_with_text ("fixed", "ClutterX11Texture (Pixmap)");
  clutter_container_add_actor (CLUTTER_CONTAINER (group), label);
  tex = clutter_x11_texture_pixmap_new_with_pixmap (pixmap);
  clutter_x11_texture_pixmap_set_automatic (CLUTTER_X11_TEXTURE_PIXMAP (tex),
                                            TRUE);
  clutter_container_add_actor (CLUTTER_CONTAINER (group), tex);
  clutter_actor_set_position (tex, 0, 20);
  clutter_texture_set_filter_quality (CLUTTER_TEXTURE (tex),
				      CLUTTER_TEXTURE_QUALITY_HIGH);
  /* oddly, the actor's size is 0 until it is realized, even though
     pixmap-height is set */
  clutter_actor_set_position (group, 0, row_height);
  if (!disable_animation)
    clutter_behaviour_apply (depth_behavior, group);


  g_signal_connect (stage, "key-release-event",
                    G_CALLBACK (stage_key_release_cb), (gpointer)pixmap);
  g_signal_connect (stage, "button-press-event",
                    G_CALLBACK (stage_button_press_cb), (gpointer)pixmap);

  clutter_actor_show (stage);

  if (!disable_animation)
    clutter_timeline_start (timeline);

  clutter_threads_add_timeout (1000, draw_arc, GUINT_TO_POINTER (pixmap));

  clutter_main ();

  return EXIT_SUCCESS;
}
Beispiel #30
0
/* width, height      give the size of the thing being drawn
 *                    on in pixels
 *
 * x, y           draw at x, y on this cairo surface.
 *                translate the plots, in pixels, which
 *                is where the origin is on the
 *                width by height surface
 *
 * the graph (gr) keep a shift and scale that map the plot
 * data from qp_plot_begin_x() and qp_plot_nextx() and etc
 * from an square area of in doubles x,y [0,0 to 1,1] to an
 * area that is the size of the drawing_area in pixels like
 * x,y [0,0 to 800,600]
 *
 * width, height   is not necessarily the same size as the
 *                 drawing_area widget, likely it is larger
 *                 like 2000 by 3000
 */
static inline
void graph_draw(struct qp_graph *gr, cairo_t *cr,
    int x, int y, int width, int height)
{
  struct qp_plot *p;
  /* These doubles will hold the net result of zoom and pixel scaling 
   * the zoom, gr->z, changes as the user zooms in and out and the
   * pixel scaling changes with the drawing area widget size allocation */
  double xscale, xshift, yscale, yshift;
  xscale = gr->xscale*gr->z->xscale;
  yscale = gr->yscale*gr->z->yscale;
  xshift = gr->xscale*gr->z->xshift + gr->xshift + x;
  yshift = gr->yscale*gr->z->yshift + gr->yshift + y;

  if(gr->x11 && gr->background_color.a < 0.05)
  {
    /* For some reason when drawing with X11
     * and having mostly-transparent background the
     * drawing seems to fail to cover the old
     * drawing.  Painting the whole area to
     * start with seems to fix it. */
    cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
    cairo_set_source_rgba(cr, 1,1,1,1.0);
    cairo_paint(cr);
  }

  cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
  cairo_paint(cr);
  cairo_set_operator(cr, CAIRO_OPERATOR_OVER);

  cairo_set_source_rgba(cr, gr->background_color.r,
      gr->background_color.g, gr->background_color.b,
      gr->background_color.a);

  cairo_paint(cr);

  cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
  cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);


  if(gr->qp->shape)
    cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
  else
    cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT);


  draw_grid(gr, cr, xscale, xshift, yscale, yshift, width, height);

  if(gr->show_grid && (gr->same_x_scale || gr->same_y_scale) &&
      qp_sllist_length(gr->plots) > 0)
  {
    struct qp_plot *p;
    p = (struct qp_plot *)qp_sllist_first(gr->plots);
    /* We need to initialize the plot scaling for this
     * graph grid drawing */
    qp_plot_scale(p, xscale, xshift, yscale, yshift);
    qp_graph_grid_draw(gr, p, cr, width, height);
  }

  if(gr->x11)
  {
    /* Get ready to draw with X11 API calls now */
    cairo_surface_flush(cairo_get_target(cr));
    gr->DrawLine = x11_DrawLine;
  }
  else
  {
    gr->DrawLine = cairo_DrawLine;
    gr->cr = cr;
  }

  p = (struct qp_plot *) qp_sllist_begin(gr->plots);

  while(p)
  {
    double x_val, y_val;

    if(p->lines)
    {
      /* draw lines */

      double minusLineWidthPlus1, widthPlus, heightPlus;
      double prev_x, prev_y;
      int new_line = 1;

      minusLineWidthPlus1 = - p->line_width - 1;
      widthPlus = width + p->line_width;
      heightPlus = height + p->line_width;

      if(gr->x11)
      {
        XSetLineAttributes(gr->x11->dsp, gr->x11->gc, INT(p->line_width),
            LineSolid, CapRound, JoinRound);
        XSetForeground(gr->x11->dsp, gr->x11->gc, p->l.x);
      }
      else
      {
        cairo_set_source_rgba(cr, p->l.c.r, p->l.c.g, p->l.c.b, p->l.c.a);
        cairo_set_line_width(cr, p->line_width);
      }

      if(qp_plot_begin(p, xscale, xshift, yscale, yshift,
            INT(minusLineWidthPlus1), INT(minusLineWidthPlus1),
            INT(widthPlus), INT(heightPlus),
            &prev_x, &prev_y))
      {
        /* We start with a good point in  prev_x, prev_y */
        while((!is_good_double(prev_x) || !is_good_double(prev_y)) &&
            qp_plot_next(p, &prev_x, &prev_y));

        while(qp_plot_next(p, &x_val, &y_val))
        {
          CullDrawLine(gr, &new_line,
              minusLineWidthPlus1, widthPlus, heightPlus,
              prev_x, prev_y, x_val, y_val);
          if(p->gaps)
          {
            prev_x = x_val;
            prev_y = y_val;
          }
          else /* no gaps */
          {
            /* do not lift up the pen if no gaps */
            if(is_good_double(x_val) && is_good_double(y_val))
            {
              /* This may be any number of points from before
               * if there where an NAN or something. */
              prev_x = x_val;
              prev_y = y_val;
            }
            if(new_line)
              new_line = 0;
          }
        }

        if(!gr->x11)
          cairo_stroke(cr);
      }
    }

    if(p->points)
    {
      double point_w, point_w2;
      int ipoint_w;
      double point_min, point_xmax, point_ymax;
      point_w2 = (point_w = p->point_size)/2;
      point_min = - point_w2 - 2;
      point_xmax = width + point_w2 + 1;
      point_ymax = height + point_w2 + 1;
      ipoint_w = INT(point_w);

      if(gr->x11)
        XSetForeground(gr->x11->dsp, gr->x11->gc, p->p.x);
      else
        cairo_set_source_rgba(cr, p->p.c.r, p->p.c.g, p->p.c.b, p->p.c.a);


      /* Putting the point width offset (point_w2) into
       * the plot data reader object is faster than adding
       * the point width offset in the tight loop in the
       * cairo_rectangle() call where we would add it
       * every loop interation. */
      
      if(qp_plot_begin(p, xscale, xshift - point_w2,
                       yscale, yshift - point_w2,
                       INT(point_min), INT(point_min),
                       INT(point_xmax), INT(point_ymax),
                       &x_val, &y_val))
      {
        int prev_x = INT_MAX, prev_y = INT_MAX;
        do
        {
          //DEBUG("%g %g\n", x_val, y_val);
          if(is_good_double(x_val) && is_good_double(y_val) &&
              /* point culling is easy */
              point_min < x_val && point_min < y_val &&
              x_val < point_xmax && y_val < point_ymax)
          {
            int x, y;
            x = INT(x_val);
            y = INT(y_val);
            /* speed up point drawing by not drawing points
             * that are on top of adjacent points more than once.
             * This can be the biggest time saver when there are
             * over 100,000 points.  Note this assumes that
             * points that as close in x,y space are adjacent
             * in the series (channel). This will slow down
             * plotting of small files, but not enough that
             * we can measure.  Tests show that cairo rectangle
             * drawing is much slower than line drawing.  Cairo
             * does not appear to be optimised for small rectangle
             * drawing.  Single pixel drawing in cairo uses
             * 1x1 rectangles, which are no faster to draw.
             * We convert the doubles to ints in the call to
             * cairo_rectangle() just because it speeds up
             * drawing. */
            if(prev_x != x || prev_y != y)
            {
              if(gr->x11)
                XFillRectangle(gr->x11->dsp, gr->x11->pixmap,
                    gr->x11->gc, x, y, ipoint_w, ipoint_w);
              else
                cairo_rectangle(cr, x, y, point_w, point_w);
            }
            prev_x = x;
            prev_y = y;
          }
        } while(qp_plot_next(p, &x_val, &y_val));

        if(!gr->x11)
          cairo_fill(cr);
      }
    }
    /* The mouse pointer value picker needs this to be reset from the
     * - point_w2 offset above.  Needed for all plots when
     * using the value picker GUI */
    qp_plot_scale(p, xscale, xshift, yscale, yshift);
 
    p = (struct qp_plot *) qp_sllist_next(gr->plots);
  }
}