示例#1
0
文件: messg.c 项目: Jheengut/gmerlin
static void
getpos (uih_context * c, int *x, int *y, int *w, int *h, void *data)
{
  int n = (int) data;
  if (c->messg.message[n] != NULL)
    {
      int he = xtextheight (c->font);
      *y = c->messg.messagestart + he * n;
      *h = he;
      *w = xtextwidth (c->font, c->messg.message[n]);
      *x = (c->image->width - *w) / 2;
    }
  else
    {
      *w = *h = *x = *y = 0;
    }
}
示例#2
0
文件: messg.c 项目: Jheengut/gmerlin
static void
draw (uih_context * c, void *data)
{
  int x, y, w;
  int n = (int) data;
  if (c->messg.message[n] != NULL)
    {
      int h = xtextheight (c->font);
      y = c->messg.messagestart + h * n;
      w = xtextwidth (c->font, c->messg.message[n]);
      x = (c->image->width - w) / 2;
      if (c->messg.messagetype[n])
	xprint (c->image, c->font, x, y, c->messg.message[n],
		(c->image->flags & AAIMAGE) ? BGCOLOR (c) : SELCOLOR (c),
		BGCOLOR (c), 0);
      else
	xprint (c->image, c->font, x, y, c->messg.message[n],
		(c->image->flags & AAIMAGE) ? BGCOLOR (c) : FGCOLOR (c),
		BGCOLOR (c), 0);
    }
}
示例#3
0
static void
getpos (uih_context * c, int *x, int *y, int *w, int *h, void *data)
{
  int num = (int) data;
  int xmax, nr;
  if (c->text[num] == NULL)
    {
      *x = *y = *h = *w;
      return;
    }
  prepare (c, c->text[num], &xmax, &nr);
  nr *= xtextheight (c->font);
  switch (num)
    {
    case 0:
      *y = 0;
      break;
    case 1:
      *y = (c->image->height - nr) / 2;
      break;
    case 2:
      *y = c->image->height - nr;
      break;
    }
  *h = nr;
  switch (c->textpos[num])
    {
    case 0:
      *x = 0;
      break;
    case 1:
      *x = (c->image->width - xmax) / 2;
      break;
    case 2:
      *x = c->image->width - xmax;
      break;
    }
  *w = xmax;
}
示例#4
0
文件: filesel.c 项目: Azizou/XaoS
int ui_mousefilesel(int x, int y, int buttons, int flags)
{
    static int grabbed = -1;
    if (!filevisible)
	return 0;
    if (grabbed >= 0 && (flags & MOUSE_DRAG)) {
	if (!grabbed) {
	    int pos;
	    pos =
		(y - LISTSTART) * nnames / (LISTEND - LISTSTART -
					    2 * BORDERHEIGHT);
	    if (pos >= nnames - NVISIBLE)
		pos = nnames - NVISIBLE;
	    if (pos < 0)
		pos = 0;
	    if (pos != namestart) {
		namestart = pos;
		uih->display = 1;
		if (selectedname < pos)
		    selectedname = pos;
		if (selectedname >= pos + NVISIBLE)
		    selectedname = pos + NVISIBLE - 1;
	    }
	} else {
	    int pos;
	    pos =
		(y - LISTSTART) * ndirs / (LISTEND - LISTSTART -
					   2 * BORDERHEIGHT);
	    if (pos >= ndirs - NVISIBLE)
		pos = ndirs - NVISIBLE;
	    if (pos < 0)
		pos = 0;
	    if (pos != dirstart) {
		dirstart = pos;
		uih->display = 1;
		if (selecteddir < pos)
		    selecteddir = pos;
		if (selecteddir >= pos + NVISIBLE)
		    selecteddir = pos + NVISIBLE - 1;
	    }
	}
    } else
	grabbed = -1;
    if (x < filex || y < filey || x > filex + filewidth
	|| y > filex + fileheight) {
	if (flags & MOUSE_PRESS)
	    ui_closefilesel(0);
	return 1;
    }
    if (y < LISTSTART) {
	if (pressedbutton != -1)
	    pressedbutton = -1, uih->display = 1;
	if ((flags & MOUSE_MOVE) && active != ADIR)
	    active = ADIR, uih->display = 1;
	if (flags & MOUSE_PRESS)
	    ui_textmouse(dir, x, y);
    } else if (y < LISTEND) {
	int mouseat = 0;
	if (pressedbutton != -1)
	    pressedbutton = -1, uih->display = 1;
	if (x > filex + filewidth / 2)
	    mouseat = 1, x -= filewidth / 2;
	x -= filex;
	if (flags & MOUSE_MOVE) {
	    if (!mouseat && active != AFILELIST)
		active = AFILELIST, uih->display = 1;
	    if (mouseat && active != ADIRLIST)
		active = ADIRLIST, uih->display = 1;
	}
	if (x > LISTWIDTH && (flags & MOUSE_PRESS))
	    grabbed = mouseat;
	else {
	    if (flags & MOUSE_PRESS) {
		int atitem =
		    (y - LISTSTART -
		     BORDERHEIGHT) / xtextheight(uih->image, uih->font);
		if (atitem < 0)
		    atitem = 0;
		if (!mouseat) {
		    atitem += namestart;
		    if (atitem < nnames) {
			if (atitem == selectedname
			    && !strcmp(names[selectedname],
				       filename->text)) {
			    ui_closefilesel(1);
			} else {
			    selectedname = atitem;
			    uih->display = 1;
			    setname(selectedname);
			}
		    }
		} else {
		    atitem += dirstart;
		    if (atitem < ndirs) {
			selecteddir = atitem;
			uih->display = 1;
			setdir(selecteddir);
		    }
		}
	    }
	}
    } else if (y < OKSTART) {
	if (pressedbutton != -1)
	    pressedbutton = -1, uih->display = 1;
	/*exit(1); */
	if ((flags & MOUSE_MOVE) && active != AFILE)
	    active = AFILE, uih->display = 1;
	if (flags & MOUSE_PRESS)
	    ui_textmouse(filename, x, y);
    } else {
	int mouseat = 0;
	if (x > filex + filewidth / 2)
	    mouseat = 1;
	if (flags & MOUSE_PRESS) {
	    if (active != AOK)
		active = AOK, uih->display = 1;
	    if (activebutton != mouseat || pressedbutton != mouseat)
		activebutton = pressedbutton = mouseat, uih->display = 1;
	}
	if ((flags & MOUSE_MOVE) && pressedbutton != mouseat)
	    uih->display = 1, pressedbutton = -1, active =
		AOK, activebutton = mouseat;
	if ((flags & MOUSE_RELEASE) && pressedbutton == mouseat)
	    ui_closefilesel(!mouseat);
    }
    return 1;
}
示例#5
0
文件: filesel.c 项目: Azizou/XaoS
static void drawfile(uih_context * c, void *data)
{
    int i;
    int ypos;
    int h = xtextheight(uih->image, uih->font);
    uih_drawborder(uih, filex + BORDERWIDTH, DIRSTART,
		   filewidth - 2 * BORDERWIDTH, BUTTONHEIGHT,
		   BORDER_PRESSED | BORDER_LIGHT);
    uih_drawborder(uih, filex + BORDERWIDTH, FILESTART,
		   filewidth - 2 * BORDERWIDTH, BUTTONHEIGHT,
		   BORDER_PRESSED | BORDER_LIGHT);

    ui_drawbutton("OK", (pressedbutton == 0), active == AOK
		  && activebutton == 0, filex + BORDERWIDTH,
		  filex + filewidth / 2 - BORDERWIDTH, OKSTART);
    ui_drawbutton(gettext("Cancel"), (pressedbutton == 1), active == AOK
		  && activebutton == 1,
		  filex + filewidth / 2 + BORDERWIDTH,
		  filex + filewidth - BORDERWIDTH, OKSTART);

    uih_drawborder(uih, filex + BORDERWIDTH, LISTSTART,
		   LISTWIDTH + 3 * BORDERWIDTH + SCROLLWIDTH,
		   LISTEND - LISTSTART, BORDER_PRESSED);
    uih_drawborder(uih, filex + filewidth / 2 + BORDERWIDTH, LISTSTART,
		   LISTWIDTH + 3 * BORDERWIDTH + SCROLLWIDTH,
		   LISTEND - LISTSTART, BORDER_PRESSED);
    ypos = LISTSTART + BORDERHEIGHT;
    for (i = 0; ypos + h < LISTEND && i + namestart < nnames; i++) {
	if (i + namestart == selectedname) {
	    xrectangle(uih->image, filex + 2 * BORDERWIDTH, ypos,
		       LISTWIDTH, h,
		       (uih->palette->
			type & BITMAPS) ? BGCOLOR(uih) :
		       LIGHTGRAYCOLOR(uih));
	}
	if (uih->palette->type & BITMAPS)
	    xprint(uih->image, uih->font, filex + 2 * BORDERWIDTH, ypos,
		   snames[i + namestart], 
		   i + namestart ==
		   selectedname ? FGCOLOR(uih) : BGCOLOR(uih),
		   BGCOLOR(uih), TEXT_PRESSED);
	else
	    xprint(uih->image, uih->font, filex + 2 * BORDERWIDTH, ypos,
		   snames[i + namestart], 
		   (i + namestart) == selectedname
		   && active == AFILELIST ? SELCOLOR(uih) : FGCOLOR(uih),
		   BGCOLOR(uih), 0);
	ypos += h;
    }
    if (nnames) {
	int xstart = (namestart) * (LISTEND - LISTSTART) / nnames;
	int xend = (namestart + NVISIBLE) * (LISTEND - LISTSTART) / nnames;
	if (xstart > (LISTEND - LISTSTART - 2 * BORDERHEIGHT))
	    xstart = LISTEND - LISTSTART - 2 * BORDERHEIGHT;
	if (xend > (LISTEND - LISTSTART - 2 * BORDERHEIGHT))
	    xend = LISTEND - LISTSTART - 2 * BORDERHEIGHT;
	uih_drawborder(uih, filex + LISTWIDTH + 3 * BORDERWIDTH, LISTSTART + xstart + BORDERHEIGHT, SCROLLWIDTH, xend - xstart,	/*1|BORDER_LIGHT */
		       0);
    }

    ypos = LISTSTART + BORDERHEIGHT;
    for (i = 0; ypos + h < LISTEND && i + dirstart < ndirs; i++) {
	if (i + dirstart == selecteddir) {
	    xrectangle(uih->image, filex + filewidth / 2 + 2 * BORDERWIDTH,
		       ypos, LISTWIDTH, h,
		       (uih->palette->type & BITMAPS) ? BGCOLOR(uih) :
		       LIGHTGRAYCOLOR(uih));
	}
	if (uih->palette->type & BITMAPS)
	    xprint(uih->image, uih->font,
		   filex + filewidth / 2 + 2 * BORDERWIDTH, ypos,
		   sdirs[i + dirstart], 
		   i + dirstart ==
		   selecteddir ? FGCOLOR(uih) : BGCOLOR(uih), BGCOLOR(uih),
		   TEXT_PRESSED);
	else
	    xprint(uih->image, uih->font,
		   filex + filewidth / 2 + 2 * BORDERWIDTH, ypos,
		   sdirs[i + dirstart], 
		   (i + dirstart) == selecteddir
		   && active == ADIRLIST ? SELCOLOR(uih) : FGCOLOR(uih),
		   BGCOLOR(uih), 0);
	ypos += h;
    }
    if (ndirs) {
	int xstart = (dirstart) * (LISTEND - LISTSTART) / ndirs;
	int xend = (dirstart + NVISIBLE) * (LISTEND - LISTSTART) / ndirs;
	if (xstart > (LISTEND - LISTSTART - 2 * BORDERHEIGHT))
	    xstart = LISTEND - LISTSTART - 2 * BORDERHEIGHT;
	if (xend > (LISTEND - LISTSTART - 2 * BORDERHEIGHT))
	    xend = LISTEND - LISTSTART - 2 * BORDERHEIGHT;
	uih_drawborder(uih, filex + filewidth / 2 + LISTWIDTH + 3 * BORDERWIDTH, LISTSTART + xstart + BORDERHEIGHT, SCROLLWIDTH, xend - xstart,	/*1|BORDER_LIGHT */
		       0);
    }
    ui_drawtext(filename, active == AFILE);
    ui_drawtext(dir, active == ADIR);
}
示例#6
0
static void
draw (uih_context * c, void *data)
{
  int num = (int) data;
  int flags = 0;
  int xmax, n, nr, i;
  int x = 0, y = 0;
  char *string;
  int fgcolor = 0, bgcolor = 0;
  if (c->text[num] == NULL)
    return;
  prepare (c, c->text[num], &xmax, &n);
  nr = n * xtextheight (c->font);
  switch (c->textcolor[num])
    {
    case 0:
      fgcolor = FGCOLOR (c);
      bgcolor = BGCOLOR (c);
      break;
    case 1:
      fgcolor = BGCOLOR (c);
      bgcolor = BGCOLOR (c);
      flags = TEXT_PRESSED;
      break;
    case 2:
      fgcolor = SELCOLOR (c);
      bgcolor = BGCOLOR (c);
      break;
    default:
      x_fatalerror ("playtext:unknown color\n");
    }
  if (c->image->flags & AAIMAGE)
    fgcolor = BGCOLOR (c);
  switch (num)
    {
    case 0:
      y = 0;
      break;
    case 1:
      y = (c->image->height - nr) / 2;
      break;
    case 2:
      y = c->image->height - nr;
      break;
    }
  string = c->text[num];
  for (i = 0; i < n; i++)
    {
      xmax = xtextwidth (c->font, string);
      switch (c->textpos[num])
	{
	case 0:
	  x = 0;
	  break;
	case 1:
	  x = (c->image->width - xmax) / 2;
	  break;
	case 2:
	  x = c->image->width - xmax;
	  break;
	}
      string +=
	xprint (c->image, c->font, x, y, string, fgcolor, bgcolor, flags) + 1;
      y += xtextheight (c->font);
    }
}