コード例 #1
0
ファイル: input.c プロジェクト: AvanWolf/naev
/**
 * @brief Sets the input for an input widget.
 *
 *    @param wid Window to which the widget belongs.
 *    @param name Name of the widget to modify.
 *    @param msg Message to set for the input box or NULL to clear.
 * @return The message actually set (can be truncated).
 */
char* window_setInput( const unsigned int wid, char* name, const char *msg )
{
   Widget *wgt;

   /* Get the widget. */
   wgt = window_getwgt(wid,name);
   if (wgt == NULL)
      return NULL;

   /* Check the type. */
   if (wgt->type != WIDGET_INPUT) {
      WARN("Trying to set input on non-input widget '%s'.", name);
      return NULL;
   }

   /* Set the message. */
   if (msg == NULL) {
      memset( wgt->dat.inp.input, 0, wgt->dat.inp.max*sizeof(char) );
      wgt->dat.inp.pos     = 0;
      wgt->dat.inp.view    = 0;
   }
   else {
      strncpy( wgt->dat.inp.input, msg, wgt->dat.inp.max );
      wgt->dat.inp.pos = strlen( wgt->dat.inp.input );
   }

   /* Get the value. */
   return wgt->dat.inp.input;
}
コード例 #2
0
ファイル: tabwin.c プロジェクト: Delll/naev
/**
 * @brief Sets the active tab.
 *
 *    @param wid Window to which tabbed window belongs.
 *    @param tab Name of the tabbed window.
 *    @param active tab to set active.
 */
int window_tabWinSetActive( const unsigned int wid, const char *tab, int active )
{
   Widget *wgt = window_getwgt( wid, tab );

   /* Must be found in stack. */
   if (wgt == NULL) {
      WARN("Widget '%s' not found", tab);
      return -1;
   }

   /* Must be an image array. */
   if (wgt->type != WIDGET_TABBEDWINDOW) {
      WARN("Widget '%s' is not an image array.", tab);
      return -1;
   }

   /* Set active window. */
   wgt->dat.tab.active = active;

   /* Create event. */
   if (wgt->dat.tab.onChange != NULL)
      wgt->dat.tab.onChange( wid, wgt->name, wgt->dat.tab.active );

   return 0;
}
コード例 #3
0
ファイル: image.c プロジェクト: Anatolis/naev
/**
 * Modifies an existing image's image.
 *
 *    @param wid ID of the window to get widget from.
 *    @param name Name of the widget to modify image of.
 *    @param w New width to set, 0 uses image, -1 doesn't change and >0 sets directly.
 *    @param w New height to set, 0 uses image, -1 doesn't change and >0 sets directly.
 *    @param image New image to set.
 */
void window_modifyImage( const unsigned int wid,
      char* name, glTexture* image, int w, int h )
{
   Widget *wgt;

   /* Get the widget. */
   wgt = window_getwgt(wid,name);
   if (wgt == NULL)
      return;

   /* Check the type. */
   if (wgt->type != WIDGET_IMAGE) {
      WARN("Not modifying image on non-image widget '%s'.", name);
      return;
   }

   /* Set the image. */
   wgt->dat.img.image = image;

   /* Adjust size. */
   if (w >= 0)
      wgt->w = (w > 0) ? w : ((image==NULL) ? 0 : wgt->dat.img.image->sw);
   if (h >= 0)
      wgt->h = (h > 0) ? h : ((image==NULL) ? 0 : wgt->dat.img.image->sh);
}
コード例 #4
0
ファイル: toolkit.c プロジェクト: Delll/naev
/**
 * @brief Gets a widget's position.
 *
 *    @param wid ID of the window to get widget from.
 *    @param name Name of the widget to get position of.
 *    @param[out] x X position of the widget.
 *    @param[out] y Y position of the widget.
 */
void window_posWidget( const unsigned int wid,
      char* name, int *x, int *y )
{
   Widget *wgt;
  
   /* Get widget. */
   wgt = window_getwgt(wid,name);
   if (wgt == NULL)
      return;

   /* Return position. */
   if (x != NULL)
      (*x) = wgt->x;
   if (y != NULL)
      (*y) = wgt->y;
}
コード例 #5
0
ファイル: cust.c プロジェクト: AvanWolf/naev
/**
 * @brief Gets a custom widget.
 */
static Widget *cst_getWidget( const unsigned int wid, const char *name )
{
   Widget *wgt;

   /* Get widget. */
   wgt = window_getwgt(wid,name);
   if (wgt == NULL)
      return NULL;

   /* Make sure it is a custom widget. */
   if (wgt->type != WIDGET_CUST) {
      DEBUG("Widget is not a custom widget: '%s'", name);
      return NULL;
   }

   return wgt;
}
コード例 #6
0
ファイル: button.c プロジェクト: Elderman/naev
/**
 * @brief Gets a button widget.
 */
static Widget* btn_get( const unsigned int wid, const char* name )
{
   Widget *wgt;

   /* Get widget. */
   wgt = window_getwgt(wid,name);
   if (wgt == NULL)
      return NULL;

   /* Check type. */
   if (wgt->type != WIDGET_BUTTON) {
      DEBUG("Widget '%s' isn't a button", name);
      return NULL;
   }

   return wgt;
}
コード例 #7
0
ファイル: checkbox.c プロジェクト: AvanWolf/naev
/**
 * @brief Gets a widget.
 */
static Widget *chk_getWgt( const unsigned int wid, const char *name )
{
   Widget *wgt;

   /* Get widget. */
   wgt = window_getwgt(wid,name);
   if (wgt == NULL)
      return NULL;

   /* Check type. */
   if (wgt->type != WIDGET_CHECKBOX) {
      DEBUG("Calling checkbox function on non-checkbox widget '%s'", name);
      return NULL;
   }

   return wgt;
}
コード例 #8
0
ファイル: input.c プロジェクト: AvanWolf/naev
/**
 * @brief Gets the input from an input widget.
 *
 *    @param wid ID of the window to get widget from.
 *    @param name Name of the widget.
 */
char* window_getInput( const unsigned int wid, char* name )
{
   Widget *wgt;

   /* Get the widget. */
   wgt = window_getwgt(wid,name);
   if (wgt == NULL)
      return NULL;

   /* Check the type. */
   if (wgt->type != WIDGET_INPUT) {
      WARN("Trying to get input from non-input widget '%s'.", name);
      return NULL;
   }

   /* Get the value. */
   return wgt->dat.inp.input;
}
コード例 #9
0
ファイル: image.c プロジェクト: zid/naev
/**
 * @brief Gets the image from an image widget
 *
 *    @param wid ID of the window to get widget from.
 *    @param name Name of the widget.
 */
glTexture* window_getImage( const unsigned int wid, char* name )
{  
   Widget *wgt;
   
   /* Get the widget. */
   wgt = window_getwgt(wid,name);
   if (wgt == NULL)
      return NULL;
   
   /* Check the type. */
   if (wgt->type != WIDGET_IMAGE) {
      WARN("Trying to get image from non-image widget '%s'.", name);
      return NULL;
   }
   
   /* Get the value. */
   return (wgt) ? wgt->dat.img.image : NULL;
}
コード例 #10
0
ファイル: imagearray.c プロジェクト: s0be/naev
/**
 * @brief Gets an image array.
 */
static Widget *iar_getWidget( const unsigned int wid, const char *name )
{
   Widget *wgt = window_getwgt(wid,name);

   /* Must be found in stack. */
   if (wgt == NULL) {
      WARN("Widget '%s' not found", name);
      return NULL;
   }

   /* Must be an image array. */
   if (wgt->type != WIDGET_IMAGEARRAY) {
      WARN("Widget '%s' is not an image array.", name);
      return NULL;
   }

   return wgt;
}
コード例 #11
0
ファイル: list.c プロジェクト: ekrumme/naev
/**
 * @brief Gets the list widget.
 */
static Widget *lst_getWgt( const unsigned int wid, char* name )
{
   Widget *wgt = window_getwgt(wid,name);

   /* Must be in stack. */
   if (wgt == NULL) {
      WARN("Widget '%s' not found", name);
      return NULL;
   }

   /* Must be a list. */
   if (wgt->type != WIDGET_LIST) {
      WARN("Widget '%s' is not a list", name);
      return NULL;
   }

   return wgt;
}
コード例 #12
0
ファイル: toolkit.c プロジェクト: Delll/naev
/**
 * @brief Moves a widget.
 *
 *    @param wid ID of the window to get widget from.
 *    @param name Name of the widget to set position to.
 *    @param x New X position to set widget to.
 *    @param y New Y position to set widget to.
 */
void window_moveWidget( const unsigned int wid,
      char* name, int x, int y )
{
   Window *wdw;
   Widget *wgt;
  
   /* Get window. */
   wdw = window_wget(wid);
   if (wdw == NULL)
      return;

   /* Get widget. */
   wgt = window_getwgt(wid,name);
   if (wgt == NULL)
      return;

   /* Set position. */
   toolkit_setPos( wdw, wgt, x, y );
}
コード例 #13
0
ファイル: image.c プロジェクト: zid/naev
/**
 * Modifies an existing image's colour.
 *
 *    @param wid ID of the window to get widget from.
 *    @param name Name of the widget to modify image colour of.
 *    @param colour New colour to use.
 */
void window_imgColour( const unsigned int wid,
      char* name, glColour* colour )
{  
   Widget *wgt;
   
   /* Get the widget. */
   wgt = window_getwgt(wid,name);
   if (wgt == NULL)
      return;
   
   /* Check the type. */
   if (wgt->type != WIDGET_IMAGE) {
      WARN("Not modifying image on non-image widget '%s'.", name);
      return;
   }
   
   /* Set the colour. */
   wgt->dat.img.colour = colour;
}
コード例 #14
0
ファイル: menu.c プロジェクト: naev/naev
/**
 * @brief Resizes the main menu and its background.
 *
 * This is a one-off function that ensures the main menu's appearance
 * is consistent regardless of window resizing.
 */
void menu_main_resize (void)
{
   int w, h, bgw, bgh, tw, th;
   int offset_logo, offset_wdw, freespace;
   int menu_id, bg_id;
   Widget *wgt;

   if (!menu_isOpen(MENU_MAIN))
      return;

   menu_id = window_get("Main Menu");
   bg_id   = window_get("BG");

   window_dimWindow( menu_id, &w, &h );
   window_dimWindow( bg_id, &bgw, &bgh );

   freespace = SCREEN_H - main_naevLogo->sh - h;
   if (freespace < 0) {
      offset_logo = SCREEN_H - main_naevLogo->sh;
      offset_wdw  = 0;
   }
   else {
      offset_logo = -freespace/4;
      offset_wdw  = freespace/2;
   }

   window_moveWidget( bg_id, "imgLogo",
         (bgw - main_naevLogo->sw)/2., offset_logo );

   window_dimWidget( bg_id, "txtBG", &tw, &th );

   if (tw > SCREEN_W) {
      /* RIP abstractions. X must be set manually because window_moveWidget
       * transforms negative coordinates. */
      wgt = window_getwgt( bg_id, "txtBG" );
      if (wgt)
         wgt->x = (SCREEN_W - tw) / 2;
   }
   else
      window_moveWidget( bg_id, "txtBG", (SCREEN_W - tw)/2, 10. );

   window_move( menu_id, -1, offset_wdw );
}
コード例 #15
0
ファイル: image.c プロジェクト: zid/naev
/**
 * Modifies an existing image's image.
 *
 *    @param wid ID of the window to get widget from.
 *    @param name Name of the widget to modify image of.
 *    @param image New image to set.
 */
void window_modifyImage( const unsigned int wid,
      char* name, glTexture* image )
{  
   Widget *wgt;
   
   /* Get the widget. */
   wgt = window_getwgt(wid,name);
   if (wgt == NULL)
      return;
   
   /* Check the type. */
   if (wgt->type != WIDGET_IMAGE) {
      WARN("Not modifying image on non-image widget '%s'.", name);
      return;
   }
   
   /* Set the image. */
   wgt->dat.img.image = image;
}
コード例 #16
0
ファイル: text.c プロジェクト: zid/naev
/**
 * @brief Modifies an existing text widget.
 *
 *    @param wid Window to which the text widget belongs.
 *    @param name Name of the text widget.
 *    @param newstring String to set for the text widget.
 */
void window_modifyText( const unsigned int wid,
      char* name, char* newstring )
{  
   Widget *wgt;
   
   /* Get the widget. */
   wgt = window_getwgt(wid,name);
   if (wgt == NULL)
      return;
   
   /* Check type. */
   if (wgt->type != WIDGET_TEXT) {
      WARN("Not modifying text on non-text widget '%s'.", name);
      return;
   }
   
   /* Set text. */
   if (wgt->dat.txt.text)
      free(wgt->dat.txt.text);
   wgt->dat.txt.text = (newstring) ?  strdup(newstring) : NULL;
}
コード例 #17
0
ファイル: tabwin.c プロジェクト: Delll/naev
/**
 * @brief Sets the onChange function callback.
 *
 *    @param wid Window to which tabbed window belongs.
 *    @param tab Name of the tabbed window.
 *    @param onChange Callback to use (NULL disables).
 */
int window_tabWinOnChange( const unsigned int wid, const char *tab,
      void(*onChange)(unsigned int,char*,int) )
{
   Widget *wgt = window_getwgt( wid, tab );

   /* Must be found in stack. */
   if (wgt == NULL) {
      WARN("Widget '%s' not found", tab);
      return -1;
   }

   /* Must be an image array. */
   if (wgt->type != WIDGET_TABBEDWINDOW) {
      WARN("Widget '%s' is not an image array.", tab);
      return -1;
   }

   /* Set on change function. */
   wgt->dat.tab.onChange = onChange;

   return 0;
}
コード例 #18
0
ファイル: input.c プロジェクト: AvanWolf/naev
/**
 * @brief Sets the input filter.
 *
 * This is a list of characters which won't be accepted as input.
 *
 *    @param wid Window to which input widget belongs.
 *    @param name Input widget to set filter on.
 *    @param filter '\0' terminated list of characters to filter.
 */
void window_setInputFilter( const unsigned int wid, char* name, const char *filter )
{
   Widget *wgt;

   /* Get the widget. */
   wgt = window_getwgt(wid,name);
   if (wgt == NULL)
      return;

   /* Check the type. */
   if (wgt->type != WIDGET_INPUT) {
      WARN("Trying to set input filter on non-input widget '%s'.", name);
      return;
   }

   /* Free if already exists. */
   if (wgt->dat.inp.filter != NULL)
      free(wgt->dat.inp.filter);

   /* Copy filter over. */
   wgt->dat.inp.filter = strdup( filter );
}