/************************************************************************** ... **************************************************************************/ struct widget *create_checkbox(struct gui_layer *pDest, bool state, Uint32 flags) { struct widget *pCBox = widget_new(); struct CHECKBOX *pTmp = fc_calloc(1, sizeof(struct CHECKBOX)); if (state) { pCBox->theme = pTheme->CBOX_Sell_Icon; } else { pCBox->theme = pTheme->CBOX_Unsell_Icon; } set_wflag(pCBox, (WF_FREE_STRING | WF_FREE_GFX | WF_FREE_PRIVATE_DATA | flags)); set_wstate(pCBox, FC_WS_DISABLED); set_wtype(pCBox, WT_CHECKBOX); pCBox->mod = KMOD_NONE; pCBox->dst = pDest; pTmp->state = state; pTmp->pTRUE_Theme = pTheme->CBOX_Sell_Icon; pTmp->pFALSE_Theme = pTheme->CBOX_Unsell_Icon; pCBox->private_data.cbox = pTmp; checkbox_baseclass_redraw = pCBox->redraw; pCBox->redraw = redraw_icon; pCBox->size.w = pCBox->theme->w / 4; pCBox->size.h = pCBox->theme->h; return pCBox; }
/************************************************************************** Create ( malloc ) Theme Icon (theme)Button Widget structure. Icon Theme graphic is taken from 'pIcon_theme' surface ( change with button changes ); Button Theme graphic is taken from pTheme->Button surface; Text is taken from 'pString16'. This function determinate future size of Button ( width, high ) and save this in: pWidget->size rectangle ( SDL_Rect ) function return pointer to allocated Button Widget. **************************************************************************/ struct widget * create_themeicon_button(SDL_Surface *pIcon_theme, struct gui_layer *pDest, SDL_String16 *pString16, Uint32 flags) { /* extract a single icon */ SDL_Surface *pIcon = create_icon_from_theme(pIcon_theme, 1); struct widget *pButton = create_icon_button(pIcon, pDest, pString16, flags); FREESURFACE(pButton->theme2); pButton->theme2 = pIcon_theme; set_wtype(pButton, WT_TI_BUTTON); pButton->redraw = redraw_tibutton; return pButton; }
/************************************************************************** ... **************************************************************************/ struct widget * create_textcheckbox(struct gui_layer *pDest, bool state, SDL_String16 *pStr, Uint32 flags) { struct widget *pCBox; struct CHECKBOX *pTmp; SDL_Surface *pSurf, *pIcon; struct widget *pTmpWidget; if (!pStr) { return create_checkbox(pDest, state, flags); } pTmp = fc_calloc(1, sizeof(struct CHECKBOX)); if (state) { pSurf = pTheme->CBOX_Sell_Icon; } else { pSurf = pTheme->CBOX_Unsell_Icon; } pIcon = create_icon_from_theme(pSurf, 0); pCBox = create_iconlabel(pIcon, pDest, pStr, (flags | WF_FREE_PRIVATE_DATA)); pStr->style &= ~SF_CENTER; pCBox->theme = pSurf; FREESURFACE(pIcon); set_wtype(pCBox, WT_TCHECKBOX); pTmp->state = state; pTmp->pTRUE_Theme = pTheme->CBOX_Sell_Icon; pTmp->pFALSE_Theme = pTheme->CBOX_Unsell_Icon; pCBox->private_data.cbox = pTmp; pTmpWidget = widget_new(); /* we can't use pCBox->redraw here, because it is of type iconlabel */ textcheckbox_baseclass_redraw = pTmpWidget->redraw; FREEWIDGET(pTmpWidget); pCBox->redraw = redraw_textcheckbox; return pCBox; }
/************************************************************************** Create ( malloc ) Edit Widget structure. Edit Theme graphic is taken from pTheme->Edit surface; Text is taken from 'pString16'. 'length' parametr determinate width of Edit rect. This function determinate future size of Edit ( width, high ) and save this in: pWidget->size rectangle ( SDL_Rect ) function return pointer to allocated Edit Widget. **************************************************************************/ struct widget * create_edit(SDL_Surface *pBackground, struct gui_layer *pDest, SDL_String16 *pString16, Uint16 length, Uint32 flags) { SDL_Rect buf = {0, 0, 0, 0}; struct widget *pEdit = widget_new(); pEdit->theme = pTheme->Edit; pEdit->theme2 = pBackground; /* FIXME: make somewhere use of it */ pEdit->string16 = pString16; set_wflag(pEdit, (WF_FREE_STRING | WF_FREE_GFX | flags)); set_wstate(pEdit, FC_WS_DISABLED); set_wtype(pEdit, WT_EDIT); pEdit->mod = KMOD_NONE; baseclass_redraw = pEdit->redraw; pEdit->redraw = redraw_edit; if (pString16) { pEdit->string16->style |= SF_CENTER; buf = str16size(pString16); buf.h += adj_size(4); } length = MAX(length, buf.w + adj_size(10)); correct_size_bcgnd_surf(pTheme->Edit, &length, &buf.h); pEdit->size.w = length; pEdit->size.h = buf.h; if(pDest) { pEdit->dst = pDest; } else { pEdit->dst = add_gui_layer(pEdit->size.w, pEdit->size.h); } return pEdit; }
/************************************************************************** Create ( malloc ) Icon2 Widget ( flat Button ) **************************************************************************/ struct widget * create_icon2(SDL_Surface *pIcon, struct gui_layer *pDest, Uint32 flags) { struct widget *pIcon_Widget = widget_new(); pIcon_Widget->theme = pIcon; set_wflag(pIcon_Widget, (WF_FREE_STRING | WF_FREE_GFX | flags)); set_wstate(pIcon_Widget, FC_WS_DISABLED); set_wtype(pIcon_Widget, WT_ICON2); pIcon_Widget->mod = KMOD_NONE; pIcon_Widget->dst = pDest; baseclass_redraw = pIcon_Widget->redraw; pIcon_Widget->redraw = redraw_icon2; if (pIcon) { pIcon_Widget->size.w = pIcon->w + adj_size(4); pIcon_Widget->size.h = pIcon->h + adj_size(4); } return pIcon_Widget; }
/************************************************************************** Create ( malloc ) Icon (theme)Button Widget structure. Icon graphic is taken from 'pIcon' surface (don't change with button changes ); Button Theme graphic is taken from pTheme->Button surface; Text is taken from 'pString16'. This function determinate future size of Button ( width, high ) and save this in: pWidget->size rectangle ( SDL_Rect ) function return pointer to allocated Button Widget. **************************************************************************/ struct widget * create_icon_button(SDL_Surface *pIcon, struct gui_layer *pDest, SDL_String16 *pStr, Uint32 flags) { SDL_Rect buf = {0, 0, 0, 0}; int w = 0, h = 0; struct widget *pButton; if (!pIcon && !pStr) { return NULL; } pButton = widget_new(); pButton->theme = pTheme->Button; pButton->theme2 = pIcon; pButton->string16 = pStr; set_wflag(pButton, (WF_FREE_STRING | flags)); set_wstate(pButton, FC_WS_DISABLED); set_wtype(pButton, WT_I_BUTTON); pButton->mod = KMOD_NONE; pButton->dst = pDest; baseclass_redraw = pButton->redraw; pButton->redraw = redraw_ibutton; if (pStr) { pButton->string16->style |= SF_CENTER; /* if BOLD == true then longest wight */ if (!(pStr->style & TTF_STYLE_BOLD)) { pStr->style |= TTF_STYLE_BOLD; buf = str16size(pStr); pStr->style &= ~TTF_STYLE_BOLD; } else { buf = str16size(pStr); } w = MAX(w, buf.w); h = MAX(h, buf.h); } if (pIcon) { if (pStr) { if ((flags & WF_ICON_UNDER_TEXT) || (flags & WF_ICON_ABOVE_TEXT)) { w = MAX(w, pIcon->w + adj_size(2)); h = MAX(h, buf.h + pIcon->h + adj_size(4)); } else { w = MAX(w, buf.w + pIcon->w + adj_size(20)); h = MAX(h, pIcon->h + adj_size(2)); } } else { w = MAX(w, pIcon->w + adj_size(2)); h = MAX(h, pIcon->h + adj_size(2)); } } else { w += adj_size(10); h += adj_size(2); } correct_size_bcgnd_surf(pTheme->Button, &w, &h); pButton->size.w = w; pButton->size.h = h; return pButton; }