示例#1
0
/**
 * @brief Sets the active element in the Image Array.
 *
 *    @param wid Window where image array is.
 *    @param name Name of the image array.
 *    @param pos Position to set to.
 *    @return 0 on success.
 */
int toolkit_setImageArrayPos( const unsigned int wid, const char* name, int pos )
{
   Widget *wgt = iar_getWidget( wid, name );
   if (wgt == NULL)
      return -1;

   /* Set position. */
   wgt->dat.iar.selected = CLAMP( 0, wgt->dat.iar.nelements-1, pos );

   /* Call callback - dangerous if called from within callback. */
   if (wgt->dat.iar.fptr != NULL)
      wgt->dat.iar.fptr( wgt->wdw, wgt->name );

   iar_centerSelected( wgt );

   return 0;
}
示例#2
0
文件: imagearray.c 项目: s0be/naev
/**
 * @brief Sets the alt text for the images in the image array.
 *
 *    @param wid Window where image array is.
 *    @param name Name of the image array.
 *    @param alt Array of alt text the size of the images in the array.
 *    @return 0 on success.
 */
int toolkit_setImageArrayAlt( const unsigned int wid, const char* name, char **alt )
{
   int i;
   Widget *wgt = iar_getWidget( wid, name );
   if (wgt == NULL)
      return -1;

   /* Clean up. */
   if (wgt->dat.iar.alts != NULL) {
      for (i=0; i<wgt->dat.iar.nelements; i++)
         if (wgt->dat.iar.alts[i] != NULL)
            free(wgt->dat.iar.alts[i]);
      free(wgt->dat.iar.alts);
   }

   /* Set. */
   wgt->dat.iar.alts = alt;
   return 0;
}
示例#3
0
文件: imagearray.c 项目: s0be/naev
/**
 * @brief Sets the slot type text for the images in the image array.
 *
 *    @param wid Window where image array is.
 *    @param name Name of the image array.
 *    @param slottype Array of slot sizes for the images in the array.
 *    @return 0 on success.
 */
int toolkit_setImageArraySlotType( const unsigned int wid, const char* name,
      char **slottype )
{
   int i;
   Widget *wgt = iar_getWidget( wid, name );
   if (wgt == NULL)
      return -1;

   /* Clean up. */
   if (wgt->dat.iar.slottype != NULL) {
      for (i=0; i<wgt->dat.iar.nelements; i++)
         if (wgt->dat.iar.slottype[i] != NULL)
            free(wgt->dat.iar.slottype[i]);
      free(wgt->dat.iar.slottype);
   }

   /* Set. */
   wgt->dat.iar.slottype = slottype;
   return 0;
}
示例#4
0
文件: imagearray.c 项目: s0be/naev
/**
 * @brief Sets the quantity text for the images in the image array.
 *
 *    @param wid Window where image array is.
 *    @param name Name of the image array.
 *    @param quantity Array of quantities for the images in the array.
 *    @return 0 on success.
 */
int toolkit_setImageArrayQuantity( const unsigned int wid, const char* name,
      char **quantity )
{
   int i;
   Widget *wgt = iar_getWidget( wid, name );
   if (wgt == NULL)
      return -1;

   /* Clean up. */
   if (wgt->dat.iar.quantity != NULL) {
      for (i=0; i<wgt->dat.iar.nelements; i++)
         if (wgt->dat.iar.quantity[i] != NULL)
            free(wgt->dat.iar.quantity[i]);
      free(wgt->dat.iar.quantity);
   }

   /* Set. */
   wgt->dat.iar.quantity = quantity;
   return 0;
}
示例#5
0
文件: imagearray.c 项目: s0be/naev
/**
 * @brief Sets the Image Array offset.
 */
int toolkit_setImageArrayOffset( const unsigned int wid, const char* name, double off )
{
   double h;
   double hmax;

   Widget *wgt = iar_getWidget( wid, name );
   if (wgt == NULL)
      return -1;

   /* Get dimensions. */
   iar_getDim( wgt, NULL, &h );

   /* Ignore fancy stuff if smaller than height. */
   if (h * wgt->dat.iar.yelem < wgt->h) {
      wgt->dat.iar.pos = 0.;
      return 0;
   }

   /* Move if needed. */
   hmax = h * (wgt->dat.iar.yelem - (int)(wgt->h / h));
   wgt->dat.iar.pos = CLAMP( 0., hmax, off );

   return 0;
}
示例#6
0
文件: imagearray.c 项目: s0be/naev
/**
 * @brief Sets an image array based on value.
 */
int toolkit_setImageArray( const unsigned int wid, const char* name, char* elem )
{
   int i;
   Widget *wgt = iar_getWidget( wid, name );
   if (wgt == NULL)
      return -1;

   /* Case NULL. */
   if (elem == NULL) {
      wgt->dat.iar.selected = -1;
      return 0;
   }

   /* Try to find the element. */
   for (i=0; i<wgt->dat.iar.nelements; i++) {
      if (strcmp(elem,wgt->dat.iar.captions[i])==0) {
         wgt->dat.iar.selected = i;
         return 0;
      }
   }

   /* Element not found. */
   return -1;
}