Пример #1
0
void KotORWidget::load(const Aurora::GFFStruct &gff) {
	gff.getVector("COLOR", _r, _g, _b);
	_a = gff.getDouble("ALPHA", 1.0);

	Extend extend = getExtend(gff);

	_width  = extend.w;
	_height = extend.h;

	Widget::setPosition(extend.x, extend.y, 0.0);

	Border border = getBorder(gff);

	_quad = new Graphics::Aurora::GUIQuad(border.fill, 0.0, 0.0, extend.w, extend.h);
	_quad->setPosition(extend.x, extend.y, 0.0);
	_quad->setTag(getTag());
	_quad->setClickable(true);

	if (border.fill.empty())
		_quad->setColor(0.0, 0.0, 0.0, 0.0);

	Text text = getText(gff);

	if (!text.text.empty() && !text.font.empty()) {
		_text = new Graphics::Aurora::Text(FontMan.get(text.font), text.text,
		                                   text.r, text.g, text.b, 1.0);

		const float hspan = extend.w - _text->getWidth();
		const float vspan = extend.h - _text->getHeight();

		const float x = extend.x + text.halign * hspan;
		const float y = extend.y + text.valign * vspan;

		_text->setPosition(x, y, -1.0);
		_text->setTag(getTag());
		_text->setClickable(true);
	}
}
Пример #2
0
/* ****************************************************************************
	FUNCTION :	loadImages
	PURPOSE :	Load the images from the given directory.
	INPUT :		dirpath	= directory where the images are located.
	OUTPUT :	None.
	RETURN :	-1 if error, 0 else.
	DESCRIPTION :
 *****************************************************************************/
int loadImages (
	char	*dirpath)
{
  DIR		*dirp = NULL;	/* Directory data */
  struct dirent	*direntp;	/* Directory entry */
  char		*fileName;	/* As read from the system */
  char		 name [1024];	/* To build the full path */
  struct stat	 stat_buf;	/* To read the image size */
  int		 fd = -1;		/* To open the image */
  int		 ret;		/* Return value */
  int		 rc = 0;

  /*
   * Initialization
   */
  mctx.images     = NULL;
  mctx.imagesNb   = 0;
  mctx.imagesLast = -1;

  if ((ret = ldclt_mutex_init(&(mctx.imagesLast_mutex))) != 0)
  {
    fprintf (stderr, "ldclt: %s\n", strerror (ret));
    fprintf (stderr, "Error: cannot initiate imagesLast_mutex\n");
    fflush (stderr);
    rc = -1;
    goto exit;
  }

  /*
   * Open the directory
   */
  dirp = opendir (dirpath);
  if (dirp == NULL)
  {
    perror (dirpath);
    fprintf (stderr, "ldlct: cannot load images from %s\n", dirpath);
    fprintf (stderr, "ldclt: try using -e imagesdir=path\n");	/*JLS 06-03-01*/
    fflush (stderr);
    rc = -1;
    goto exit;
  }

  /*
   * Process the directory.
   * We will only accept the .jpg files, as stated by the RFC.
   */
  while ((direntp = readdir (dirp)) != NULL)
  {
    fileName = direntp->d_name;
    if (!strcmp (getExtend (fileName), "jpg"))
    {
      /*
       * Allocate a new image, and initiates with its name.
       */
      mctx.imagesNb++;
      mctx.images = 
		(image *) realloc (mctx.images, mctx.imagesNb * sizeof (image));
      if (mctx.images == NULL)					/*JLS 06-03-00*/
      {								/*JLS 06-03-00*/
	printf ("Error: cannot realloc(mctx.images), error=%d (%s)\n",
		errno, strerror (errno));			/*JLS 06-03-00*/
	rc = -1;
	goto exit;
      }								/*JLS 06-03-00*/
      mctx.images[mctx.imagesNb-1].name = 
		(char *) malloc (strlen(fileName) + 1);
      if (mctx.images[mctx.imagesNb-1].name == NULL)		/*JLS 06-03-00*/
      {								/*JLS 06-03-00*/
	printf ("Error: cannot malloc(mctx.images[%d]).name, error=%d (%s)\n",
		mctx.imagesNb-1, errno, strerror (errno));	/*JLS 06-03-00*/
	rc = -1;
	goto exit;
      }								/*JLS 06-03-00*/
      strcpy (mctx.images[mctx.imagesNb-1].name, fileName);

      /*
       * Read the image size
       */
      snprintf (name, sizeof(name), "%s/%s", dirpath, fileName);
      name[sizeof(name)-1] = '\0';

      /*
       * Open the image
       */
      fd = open (name, O_RDONLY);
      if (fd < 0)
      {
	perror (name);
	fprintf (stderr, "Cannot open(%s)\n", name);
	fflush (stderr);
	rc = -1;
	goto exit;
      }

      if (fstat (fd, &stat_buf) < 0)
      {
	perror (name);
	fprintf (stderr, "Cannot stat(%s)\n", name);
	fflush (stderr);
	rc = -1;
	goto exit;
      }
      mctx.images[mctx.imagesNb-1].length = stat_buf.st_size;

      /*
       * mmap() the image
       */
      mctx.images[mctx.imagesNb-1].data = mmap (0, stat_buf.st_size,
			PROT_READ, MAP_SHARED, fd, 0);
      if (mctx.images[mctx.imagesNb-1].data == (char *)MAP_FAILED)
      {
	perror (name);
	fprintf (stderr, "Cannot mmap(%s)\n", name);
	fflush (stderr);
	rc = -1;
	goto exit;
      }

      /*
       * Close the image. The mmap() will remain available, and this
       * close() will save file descriptors.
       */
      if (close (fd) < 0)
      {
          perror (name);
          fprintf (stderr, "Cannot close(%s)\n", name);
          fflush (stderr);
          rc = -1;
          goto exit;
      } else {
          fd = -1;
      }
    }
  } /* while ((direntp = readdir (dirp)) != NULL) */
exit:
  /*
   * Close the directory
   */
  if (dirp && closedir (dirp) < 0)
  {
    perror (dirpath);
    fprintf (stderr, "Cannot closedir(%s)\n", dirpath);
    fflush (stderr);
    rc = -1;
  }


  /*
   * Normal end
   */
  if(fd != -1)
      close(fd);

  return rc;
}