예제 #1
0
파일: graphics.c 프로젝트: WndSks/msys
/* INTPROTO */
void
rxvt_Gr_NewWindow(rxvt_t *r, int nargs, int args[])
{
    int             x, y;
    unsigned int    w, h;
    Window          win;
    grwin_t        *grwin;
    Cursor          cursor;

    if (nargs != 4) {
	rxvt_print_error("NewWindow: 4 args needed, got %d\n", nargs);
	return;
    }
    x = args[0] * TermWin_TotalWidth() / GRX_SCALE;
    y = args[1] * TermWin_TotalHeight() / GRX_SCALE;
    w = args[2] * TermWin_TotalWidth() / GRX_SCALE;
    h = args[3] * TermWin_TotalHeight() / GRX_SCALE;

    win = XCreateSimpleWindow(r->Xdisplay, r->TermWin.vt,
			      x, y, w, h,
			      0,
			      r->PixColors[Color_fg],
			      r->PixColors[Color_bg]);

    cursor = XCreateFontCursor(r->Xdisplay, XC_crosshair);
    XDefineCursor(r->Xdisplay, win, cursor);
    XMapWindow(r->Xdisplay, win);
    XSelectInput(r->Xdisplay, win, ExposureMask);

    grwin = (grwin_t *) rxvt_malloc(sizeof(grwin_t));
    grwin->win = win;
    grwin->x = x;
    grwin->y = y;
    grwin->w = w;
    grwin->h = h;
    grwin->screen = 0;
    grwin->prev = NULL;
    grwin->next = r->h->gr_root;
    if (grwin->next)
	grwin->next->prev = grwin;
    r->h->gr_root = grwin;
    grwin->graphics = NULL;
    r->h->graphics_up++;

    rxvt_tt_printf(r, "\033W%ld\n", (long)grwin->win);
}
예제 #2
0
파일: main.c 프로젝트: tlwg/xiterm-thai
static void
resize_pixmap (void)
{
  XGCValues gcvalue;
  GC gc;
  unsigned int width = TermWin_TotalWidth ();
  unsigned int height = TermWin_TotalHeight ();

  if (TermWin.pixmap)
    XFreePixmap (Xdisplay, TermWin.pixmap);
  TermWin.pixmap = XCreatePixmap (Xdisplay, TermWin.vt,
				  width, height, Xdepth);

  gcvalue.foreground = PixColors[bgColor];
  gc = XCreateGC (Xdisplay, TermWin.vt, GCForeground, &gcvalue);

  if (bgPixmap.pixmap)
    {
      int w = bgPixmap.w;
      int h = bgPixmap.h;
      int x = bgPixmap.x;
      int y = bgPixmap.y;

      /*
       * don't zoom pixmap too much nor expand really small pixmaps
       */
      if (w > 1000 || h > 1000)
	w = 1;
      else if (width > (10 * xpmAttr.width) ||
	       height > (10 * xpmAttr.height))
	w = 0;			/* tile */

      if (w)
	{
	  float p, incr;
	  Pixmap tmp;
	  tmp = XCreatePixmap (Xdisplay, TermWin.vt,
			       width, xpmAttr.height,
			       Xdepth);

	  XFillRectangle (Xdisplay, tmp, gc, 0, 0, width, xpmAttr.height);
	  /*
	   * horizontal scaling
	   */
	  incr = (float) xpmAttr.width;
	  p = 0;

	  if (w == 1)
	    {
	      /* display image directly - no scaling at all */
	      incr = width;
	      if (xpmAttr.width <= width)
		{
		  w = xpmAttr.width;
		  x = (width - w) / 2;
		  w += x;
		}
	      else
		{
		  x = 0;
		  w = width;
		}
	    }
	  else if (w < 10)
	    {
	      incr *= w;	/* fit W images across screen */
	      x = 0;
	      w = width;
	    }
	  else
	    {
	      incr *= 100.0 / w;
	      if (w < 100)	/* contract */
		{
		  w = (w * width) / 100;
		  if (x >= 0)	/* position */
		    {
		      float pos;
		      pos = (float) x / 100 * width - (w / 2);

		      x = (width - w);
		      if (pos <= 0)
			x = 0;
		      else if (pos < x)
			x = pos;
		    }
		  else
		    {
		      x = (width - w) / 2;
		    }
		  w += x;
		}
	      else if (w >= 100)	/* expand */
		{
		  if (x > 0)	/* position */
		    {
		      float pos;
		      pos = (float) x / 100 * xpmAttr.width - (incr / 2);
		      p = xpmAttr.width - (incr);
		      if (pos <= 0)
			p = 0;
		      else if (pos < p)
			p = pos;
		    }
		  x = 0;
		  w = width;
		}
	    }
	  incr /= width;

	  for ( /*nil */ ; x < w; x++, p += incr)
	    {
	      if (p >= xpmAttr.width)
		p = 0;
	      XCopyArea (Xdisplay, bgPixmap.pixmap, tmp, gc,
			 (int) p, 0, 1, xpmAttr.height, x, 0);
	    }

	  /*
	   * vertical scaling
	   */
	  incr = (float) xpmAttr.height;
	  p = 0;

	  if (h == 1)
	    {
	      /* display image directly - no scaling at all */
	      incr = height;
	      if (xpmAttr.height <= height)
		{
		  h = xpmAttr.height;
		  y = (height - h) / 2;
		  h += y;
		}
	      else
		{
		  y = 0;
		  h = height;
		}
	    }
	  else if (h < 10)
	    {
	      incr *= h;	/* fit H images across screen */
	      y = 0;
	      h = height;
	    }
	  else
	    {
	      incr *= 100.0 / h;
	      if (h < 100)	/* contract */
		{
		  h = (h * height) / 100;
		  if (y >= 0)	/* position */
		    {
		      float pos;
		      pos = (float) y / 100 * height - (h / 2);

		      y = (height - h);
		      if (pos < 0.0f)
			y = 0;
		      else if (pos < y)
			y = pos;
		    }
		  else
		    {
		      y = (height - h) / 2;
		    }
		  h += y;
		}
	      else if (h >= 100)	/* expand */
		{
		  if (y > 0)	/* position */
		    {
		      float pos;
		      pos = (float) y / 100 * xpmAttr.height - (incr / 2);
		      p = xpmAttr.height - (incr);
		      if (pos < 0)
			p = 0;
		      else if (pos < p)
			p = pos;
		    }
		  y = 0;
		  h = height;
		}
	    }
	  incr /= height;

	  for ( /*nil */ ; y < h; y++, p += incr)
	    {
	      if (p >= xpmAttr.height)
		p = 0;
	      XCopyArea (Xdisplay, tmp, TermWin.pixmap, gc,
			 0, (int) p, width, 1, 0, y);
	    }
	  XFreePixmap (Xdisplay, tmp);
	}
      else
	{
	  /* tiled */
	  for (y = 0; y < height; y += xpmAttr.height)
	    {
	      unsigned int h = (height - y);
	      if (h > xpmAttr.height)
		h = xpmAttr.height;
	      for (x = 0; x < width; x += xpmAttr.width)
		{
		  unsigned int w = (width - x);
		  if (w > xpmAttr.width)
		    w = xpmAttr.width;
		  XCopyArea (Xdisplay,
			     bgPixmap.pixmap,
			     TermWin.pixmap,
			     gc,
			     0, 0, w, h, x, y);
		}
	    }
	}
    }
  else
    XFillRectangle (Xdisplay, TermWin.pixmap, gc,
		    0, 0, width, height);

#ifdef XPM_BUFFERING
  if (TermWin.buf_pixmap)
    XFreePixmap (Xdisplay, TermWin.buf_pixmap);
  TermWin.buf_pixmap = XCreatePixmap (Xdisplay, TermWin.vt,
				      width, height, Xdepth);
  XCopyArea (Xdisplay,
	     TermWin.pixmap,
	     TermWin.buf_pixmap,
	     gc,
	     0, 0,
	     width, height,
	     0, 0);
  XSetWindowBackgroundPixmap (Xdisplay, TermWin.vt, TermWin.buf_pixmap);
#else /* XPM_BUFFERING */
  XSetWindowBackgroundPixmap (Xdisplay, TermWin.vt, TermWin.pixmap);
#endif /* XPM_BUFFERING */
  XFreeGC (Xdisplay, gc);

  XClearWindow (Xdisplay, TermWin.vt);
  XFlush (Xdisplay);

  XSync (Xdisplay, 0);
}