/** * @brief Adds a button widget to a window. * * Position origin is 0,0 at bottom left. If you use negative X or Y * positions. They actually count from the opposite side in. * * @param wid ID of the window to add the widget to. * @param x X position within the window to use. * @param y Y position within the window to use. * @param w Width of the widget. * @param h Height of the widget. * @param name Name of the widget to use internally. * @param display Text displayed on the button (centered). * @param call Function to call when checkbox is toggled Parameter passed * is the name of the checkbox. */ void window_addCheckbox( const unsigned int wid, const int x, const int y, /* position */ const int w, const int h, /* size */ char* name, char* display, /* label name, display name */ void (*call) (unsigned int,char*), /* toggle function */ int default_state ) /* default state. */ { Window *wdw = window_wget(wid); Widget *wgt = window_newWidget(wdw, name); if (wgt == NULL) return; /* generic */ wgt->type = WIDGET_CHECKBOX; /* specific */ wgt->keyevent = chk_key; wgt->mclickevent = chk_mclick; wgt->render = chk_render; wgt->cleanup = chk_cleanup; wgt->dat.chk.display = (display == NULL) ? NULL : strdup(display); wgt->dat.chk.fptr = call; wgt->dat.chk.state = default_state; /* position/size */ wgt->w = (double) w; wgt->h = (double) h; toolkit_setPos( wdw, wgt, x, y ); }
/** * @brief Adds a custom widget to a window. * * Position origin is 0,0 at bottom left. If you use negative X or Y * positions. They actually count from the opposite side in. * * You are in charge of the rendering and handling mouse input for this widget. * Mouse events outside the widget position won't be passed on. * * @param wid ID of the window to add the widget to. * @param x X position within the window to use. * @param y Y position within the window to use. * @param w Width of the widget. * @param h Height of the widget. * @param name Name of the widget to use internally. * @param border Whether or not it should have a border. * @param render Render function, passes the position and dimensions of the * widget as parameters. * @param mouse Mouse function, passes the window id, event and position as * parameters. */ void window_addCust( const unsigned int wid, const int x, const int y, /* position */ const int w, const int h, /* size */ char* name, const int border, void (*render) (double x, double y, double w, double h, void *data), void (*mouse) (unsigned int wid, SDL_Event* event, double x, double y, double w, double h, void *data), void *data ) { Window *wdw = window_wget(wid); Widget *wgt = window_newWidget(wdw, name); if (wgt == NULL) return; /* generic */ wgt->type = WIDGET_CUST; /* specific */ wgt->render = cst_render; wgt->renderOverlay = cst_renderOverlay; wgt->dat.cst.border = border; wgt->dat.cst.render = render; wgt->dat.cst.mouse = mouse; wgt->dat.cst.clip = 1; wgt->dat.cst.userdata = data; /* position/size */ wgt->w = (double) w; wgt->h = (double) h; toolkit_setPos( wdw, wgt, x, y ); }
/** * @brief Adds a text widget to the window. * * Position origin is 0,0 at bottom left. If you use negative X or Y * positions. They actually count from the opposite side in. * * @param wid ID of the window to add the widget to. * @param x X position within the window to use. * @param y Y position within the window to use. * @param w Maximum width of the text. * @param h Maximum height of the text. * @param centered Whether text should be centered. * @param name Name of the widget to use internally. * @param font Font to use (NULL is default). * @param colour Colour to use (NULL is default). * @param string Text to display. */ void window_addText( const unsigned int wid, const int x, const int y, const int w, const int h, const int centered, char* name, glFont* font, glColour* colour, const char* string ) { Window *wdw = window_wget(wid); Widget *wgt = window_newWidget(wdw, name); /* generic */ wgt->type = WIDGET_TEXT; /* specific */ wgt->render = txt_render; wgt->cleanup = txt_cleanup; wgt->dat.txt.font = (font==NULL) ? &gl_defFont : font; wgt->dat.txt.colour = (colour==NULL) ? &cBlack : colour; wgt->dat.txt.centered = centered; wgt->dat.txt.text = (string==NULL) ? NULL : strdup(string); /* position/size */ wgt->w = (double) w; wgt->h = (double) h; toolkit_setPos( wdw, wgt, x, y ); }
/** * @brief Adds an input widget to a window. * * Position origin is 0,0 at bottom left. If you use negative X or Y * positions. They actually count from the opposite side in. * * @param wid ID of the window to add the widget to. * @param x X position within the window to use. * @param y Y position within the window to use. * @param w Width of the widget. * @param h Height of the widget. * @param name Name of the widget to use internally. * @param max Max amount of characters that can be written. * @param oneline Whether widget should only be one line long. * @param font Font to use. */ void window_addInput( const unsigned int wid, const int x, const int y, /* position */ const int w, const int h, /* size */ char* name, const int max, const int oneline, glFont *font ) { Window *wdw = window_wget(wid); Widget *wgt = window_newWidget(wdw, name); if (wgt == NULL) return; /* generic */ wgt->type = WIDGET_INPUT; /* specific */ wgt->render = inp_render; wgt->cleanup = inp_cleanup; wgt_setFlag(wgt, WGT_FLAG_CANFOCUS); wgt->keyevent = inp_key; wgt->textevent = inp_text; /*wgt->keyevent = inp_key;*/ wgt->dat.inp.font = (font != NULL) ? font : &gl_smallFont; wgt->dat.inp.max = max+1; wgt->dat.inp.oneline = oneline; wgt->dat.inp.pos = 0; wgt->dat.inp.view = 0; wgt->dat.inp.input = malloc(sizeof(char)*wgt->dat.inp.max); memset(wgt->dat.inp.input, 0, wgt->dat.inp.max*sizeof(char)); /* position/size */ wgt->w = (double) w; wgt->h = (double) h; toolkit_setPos( wdw, wgt, x, y ); }
/** * @brief Adds a rectangle widget to a window. * * Position origin is 0,0 at bottom left. If you use negative X or Y * positions. They actually count from the opposite side in. * * @param wid ID of the window to add the widget to. * @param x X position within the window to use. * @param y Y position within the window to use. * @param w Width of the widget. * @param h Height of the widget. * @param name Name of the widget to use internally. * @param colour Colour of the rectangle. * @param border Whether or not it should have a border. */ void window_addRect( const unsigned int wid, const int x, const int y, /* position */ const int w, const int h, /* size */ char* name, const glColour* colour, int border ) { Window *wdw = window_wget(wid); Widget *wgt = window_newWidget(wdw, name); if (wgt == NULL) return; /* generic */ wgt->type = WIDGET_RECT; /* specific */ wgt->render = rct_render; if (colour != NULL) { wgt->dat.rct.colour = *colour; wgt->dat.rct.fill = 1; } else wgt->dat.rct.fill = 0; wgt->dat.rct.border = border; /* position/size */ wgt->w = (double) w; wgt->h = (double) h; toolkit_setPos( wdw, wgt, x, y ); }
/** * @brief Adds a button widget to a window. * * Position origin is 0,0 at bottom left. If you use negative X or Y * positions. They actually count from the opposite side in. * * @param wid ID of the window to add the widget to. * @param x X position within the window to use. * @param y Y position within the window to use. * @param w Width of the widget. * @param h Height of the widget. * @param name Name of the widget to use internally. * @param ntabs Number of tabs in the widget. * @param tabnames Name of the tabs in the widget. * @return List of created windows. */ unsigned int* window_addTabbedWindow( const unsigned int wid, const int x, const int y, /* position */ const int w, const int h, /* size */ const char* name, int ntabs, const char **tabnames ) { int i; Window *wdw, *wtmp; Widget *wgt; /* Create the Widget. */ wdw = window_wget(wid); wgt = window_newWidget(wdw, name); if (wgt == NULL) return NULL; /* generic */ wgt->type = WIDGET_TABBEDWINDOW; /* specific */ wgt_setFlag( wgt, WGT_FLAG_RAWINPUT ); wgt->rawevent = tab_raw; wgt->render = tab_render; wgt->renderOverlay = tab_renderOverlay; wgt->cleanup = tab_cleanup; wgt->dat.tab.ntabs = ntabs; /* position/size */ wgt->w = (double) w; wgt->h = (double) h; toolkit_setPos( wdw, wgt, x, y ); /* Copy tab information. */ wgt->dat.tab.tabnames = malloc( sizeof(char*) * ntabs ); wgt->dat.tab.windows = malloc( sizeof(unsigned int) * ntabs ); wgt->dat.tab.namelen = malloc( sizeof(int) * ntabs ); for (i=0; i<ntabs; i++) { /* Hack to get around possible reallocs. */ wdw = window_wget(wid); /* Get name and length. */ wgt->dat.tab.tabnames[i] = strdup( tabnames[i] ); wgt->dat.tab.namelen[i] = gl_printWidthRaw( &gl_defFont, wgt->dat.tab.tabnames[i] ); /* Create windows. */ wgt->dat.tab.windows[i] = window_create( tabnames[i], wdw->x + x, wdw->y + y + TAB_HEIGHT, wdw->w, wdw->h - TAB_HEIGHT ); wtmp = window_wget( wgt->dat.tab.windows[i] ); /* Set flags. */ window_setFlag( wtmp, WINDOW_NOFOCUS ); window_setFlag( wtmp, WINDOW_NORENDER ); window_setFlag( wtmp, WINDOW_NOINPUT ); window_setFlag( wtmp, WINDOW_NOBORDER ); } /* Return list of windows. */ return wgt->dat.tab.windows; }
/** * @brief Adds an Image Array widget. * * Position origin is 0,0 at bottom left. If you use negative X or Y * positions. They actually count from the opposite side in. * * @param wid Window to add to. * @param x X position. * @param y Y position. * @param w Width. * @param h Height. * @param name Internal widget name. * @param iw Image width to use. * @param ih Image height to use. * @param tex Texture array to use (not freed). * @param caption Caption array to use (freed). * @param nelem Elements in tex and caption. * @param call Callback when modified. */ void window_addImageArray( const unsigned int wid, const int x, const int y, /* position */ const int w, const int h, /* size */ char* name, const int iw, const int ih, glTexture** tex, char** caption, int nelem, void (*call) (unsigned int wdw, char* wgtname), void (*rmcall) (unsigned int wdw, char* wgtname) ) { Window *wdw = window_wget(wid); Widget *wgt = window_newWidget(wdw, name); if (wgt == NULL) return; /* generic */ wgt->type = WIDGET_IMAGEARRAY; /* position/size */ wgt->w = (double) w; wgt->h = (double) h; toolkit_setPos( wdw, wgt, x, y ); /* specific */ wgt->render = iar_render; wgt->renderOverlay = iar_renderOverlay; wgt->cleanup = iar_cleanup; wgt_setFlag(wgt, WGT_FLAG_CANFOCUS); wgt->keyevent = iar_key; wgt->mclickevent = iar_mclick; wgt->mmoveevent = iar_mmove; wgt_setFlag(wgt, WGT_FLAG_ALWAYSMMOVE); wgt->dat.iar.images = tex; wgt->dat.iar.captions = caption; wgt->dat.iar.nelements = nelem; wgt->dat.iar.selected = 0; wgt->dat.iar.pos = 0; wgt->dat.iar.alt = -1; wgt->dat.iar.iw = iw; wgt->dat.iar.ih = ih; wgt->dat.iar.fptr = call; wgt->dat.iar.rmptr = rmcall; wgt->dat.iar.xelem = floor((w - 10.) / (double)(wgt->dat.iar.iw+10)); wgt->dat.iar.yelem = (wgt->dat.iar.xelem == 0) ? 0 : (int)wgt->dat.iar.nelements / wgt->dat.iar.xelem + 1; if (wdw->focus == -1) /* initialize the focus */ toolkit_nextFocus( wdw ); }
/** * @brief Adds a button widget to a window, with a hotkey that enables the button to be activated with that key. * * Position origin is 0,0 at bottom left. If you use negative X or Y * positions. They actually count from the opposite side in. * * @param wid ID of the window to add the widget to. * @param x X position within the window to use. * @param y Y position within the window to use. * @param w Width of the widget. * @param h Height of the widget. * @param name Name of the widget to use internally. * @param display Text displayed on the button (centered). * @param call Function to call when button is pressed. Parameter passed * is the name of the button. * @param key Hotkey for using the button without it being focused. */ void window_addButtonKey( const unsigned int wid, const int x, const int y, const int w, const int h, char* name, char* display, void (*call) (unsigned int wgt, char* wdwname), SDLKey key ) { Window *wdw = window_wget(wid); Widget *wgt = window_newWidget(wdw, name); if (wgt == NULL) return; /* generic */ wgt->type = WIDGET_BUTTON; /* specific */ wgt->keyevent = btn_key; wgt->render = btn_render; wgt->cleanup = btn_cleanup; wgt_setFlag(wgt, WGT_FLAG_CANFOCUS); wgt->dat.btn.display = strdup(display); wgt->dat.btn.disabled = 0; /* initially enabled */ wgt->dat.btn.fptr = call; if (key != 0) { wgt->dat.btn.key = key; btn_updateHotkey(wgt); } /* position/size */ wgt->w = (double) w; wgt->h = (double) h; toolkit_setPos( wdw, wgt, x, y ); if (wgt->dat.btn.fptr == NULL) { /* Disable if function is NULL. */ wgt->dat.btn.disabled = 1; wgt_rmFlag(wgt, WGT_FLAG_CANFOCUS); } if (wdw->focus == -1) /* initialize the focus */ toolkit_nextFocus( wdw ); }
/** * @brief Adds a list widget to a window. * * Position origin is 0,0 at bottom left. If you use negative X or Y * positions. They actually count from the opposite side in. * * @param wid ID of the window to add the widget to. * @param x X position within the window to use. * @param y Y position within the window to use. * @param w Width of the widget. * @param h Height of the widget. * @param name Name of the widget to use internally. * @param items Items in the list (will be freed automatically). * @param nitems Number of items in items parameter. * @param defitem Default item to select. * @param call Function to call when new item is selected. Parameter passed * is the name of the list. */ void window_addList( const unsigned int wid, const int x, const int y, const int w, const int h, char* name, char **items, int nitems, int defitem, void (*call) (unsigned int wdw, char* wgtname) ) { Window *wdw = window_wget(wid); Widget *wgt = window_newWidget(wdw, name); if (wgt == NULL) return; /* generic */ wgt->type = WIDGET_LIST; /* specific */ wgt->render = lst_render; wgt->cleanup = lst_cleanup; wgt_setFlag(wgt, WGT_FLAG_CANFOCUS); wgt->keyevent = lst_key; wgt->mclickevent = lst_mclick; wgt->mmoveevent = lst_mmove; wgt->dat.lst.options = items; wgt->dat.lst.noptions = nitems; wgt->dat.lst.selected = defitem; /* -1 would be none */ wgt->dat.lst.pos = 0; wgt->dat.lst.fptr = call; /* position/size */ wgt->w = (double) w; wgt->h = (double) h - ((h % (gl_defFont.h+2)) - 2); toolkit_setPos( wdw, wgt, x, y ); /* check if needs scrollbar. */ if (2 + (nitems * (gl_defFont.h + 2)) > (int)wgt->h) wgt->dat.lst.height = (2 + gl_defFont.h) * nitems + 2; else wgt->dat.lst.height = 0; if (wdw->focus == -1) /* initialize the focus */ toolkit_nextFocus(); }
/** * @brief Adds an image widget to the window. * * Position origin is 0,0 at bottom left. If you use negative X or Y * positions. They actually count from the opposite side in. * * @param wid ID of the window to add the widget to. * @param x X position within the window to use. * @param y Y position within the window to use. * @param name Name of the widget to use internally. * @param image Image to use. * @param border Whether to use a border. */ void window_addImage( const unsigned int wid, const int x, const int y, char* name, glTexture* image, int border ) { Window *wdw = window_wget(wid); Widget *wgt = window_newWidget(wdw, name); /* generic */ wgt->type = WIDGET_IMAGE; /* specific */ wgt->render = img_render; wgt->dat.img.image = image; wgt->dat.img.border = border; wgt->dat.img.colour = NULL; /* normal colour */ /* position/size */ wgt->w = (image==NULL) ? 0 : wgt->dat.img.image->sw; wgt->h = (image==NULL) ? 0 : wgt->dat.img.image->sh; toolkit_setPos( wdw, wgt, x, y ); }