/** * @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; }
/** * @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; }
/** * 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); }
/** * @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; }
/** * @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; }
/** * @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; }
/** * @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; }
/** * @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; }
/** * @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; }
/** * @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; }
/** * @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; }
/** * @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 ); }
/** * 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; }
/** * @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 ); }
/** * 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; }
/** * @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; }
/** * @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; }
/** * @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 ); }