enum Edit_Return_Codes edit_field(struct widget *pEdit_Widget) { struct EDIT pEdt; struct UniChar ___last; struct UniChar *pInputChain_TMP = NULL; enum Edit_Return_Codes ret; void *backup = pEdit_Widget->data.ptr; pEdt.pWidget = pEdit_Widget; pEdt.ChainLen = 0; pEdt.Truelength = 0; pEdt.Start_X = adj_size(5); pEdt.InputChain_X = 0; pEdit_Widget->data.ptr = (void *)&pEdt; SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); pEdt.pBg = create_bcgnd_surf(pEdit_Widget->theme, 2, pEdit_Widget->size.w, pEdit_Widget->size.h); /* Creating Chain */ pEdt.pBeginTextChain = text2chain(pEdit_Widget->string16->text); /* Creating Empty (Last) pice of Chain */ pEdt.pInputChain = &___last; pEdt.pEndTextChain = pEdt.pInputChain; pEdt.pEndTextChain->chr[0] = 32; /*spacebar */ pEdt.pEndTextChain->chr[1] = 0; /*spacebar */ pEdt.pEndTextChain->next = NULL; pEdt.pEndTextChain->prev = NULL; /* set font style (if any ) */ if (!((pEdit_Widget->string16->style & 0x0F) & TTF_STYLE_NORMAL)) { TTF_SetFontStyle(pEdit_Widget->string16->font, (pEdit_Widget->string16->style & 0x0F)); } pEdt.pEndTextChain->pTsurf = TTF_RenderUNICODE_Blended(pEdit_Widget->string16->font, pEdt.pEndTextChain->chr, pEdit_Widget->string16->fgcol); /* create surface for each font in chain and find chain length */ if (pEdt.pBeginTextChain) { pInputChain_TMP = pEdt.pBeginTextChain; while (TRUE) { pEdt.ChainLen++; pInputChain_TMP->pTsurf = TTF_RenderUNICODE_Blended(pEdit_Widget->string16->font, pInputChain_TMP->chr, pEdit_Widget->string16->fgcol); pEdt.Truelength += pInputChain_TMP->pTsurf->w; if (pInputChain_TMP->next == NULL) { break; } pInputChain_TMP = pInputChain_TMP->next; } /* set terminator of list */ pInputChain_TMP->next = pEdt.pInputChain; pEdt.pInputChain->prev = pInputChain_TMP; pInputChain_TMP = NULL; } else { pEdt.pBeginTextChain = pEdt.pInputChain; } redraw_edit_chain(&pEdt); set_wstate(pEdit_Widget, FC_WS_PRESSED); { /* local loop */ Uint16 rety = gui_event_loop((void *)&pEdt, NULL, edit_key_down, NULL, edit_mouse_button_down, NULL, NULL); if (pEdt.pBeginTextChain == pEdt.pEndTextChain) { pEdt.pBeginTextChain = NULL; } if (rety == MAX_ID) { ret = ED_FORCE_EXIT; } else { ret = (enum Edit_Return_Codes) rety; /* this is here becouse we have no knowladge that pEdit_Widget exist or nor in force exit mode from gui loop */ /* reset font settings */ if (!((pEdit_Widget->string16->style & 0x0F) & TTF_STYLE_NORMAL)) { TTF_SetFontStyle(pEdit_Widget->string16->font, TTF_STYLE_NORMAL); } if(ret != ED_ESC) { FC_FREE(pEdit_Widget->string16->text); pEdit_Widget->string16->text = chain2text(pEdt.pBeginTextChain, pEdt.ChainLen); pEdit_Widget->string16->n_alloc = (pEdt.ChainLen + 1) * sizeof(Uint16); } pEdit_Widget->data.ptr = backup; set_wstate(pEdit_Widget, FC_WS_NORMAL); } } FREESURFACE(pEdt.pEndTextChain->pTsurf); del_chain(pEdt.pBeginTextChain); FREESURFACE(pEdt.pBg); /* disable repeate key */ SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); /* disable Unicode */ SDL_EnableUNICODE(0); return ret; }
/************************************************************************** Create Icon Button image with text and Icon then blit to Dest(ination) on positon pIButton->size.x , pIButton->size.y. WARRING: pDest must exist. Text with atributes is taken from pIButton->string16 parameter. Graphic for button is taken from pIButton->theme surface and blit to new created image. Graphic for Icon is taken from pIButton->theme2 surface and blit to new created image. function return (-1) if there are no Icon and Text. Else return 0. **************************************************************************/ static int redraw_ibutton(struct widget *pIButton) { SDL_Rect dest = { 0, 0, 0, 0 }; SDL_String16 TMPString; SDL_Surface *pButton = NULL, *pText = NULL, *pIcon = pIButton->theme2; Uint16 Ix, Iy, x; Uint16 y = 0; /* FIXME: possibly uninitialized */ int ret; ret = (*baseclass_redraw)(pIButton); if (ret != 0) { return ret; } if (pIButton->string16) { /* make copy of string16 */ TMPString = *pIButton->string16; if (get_wstate(pIButton) == FC_WS_NORMAL) { TMPString.fgcol = *get_theme_color(COLOR_THEME_WIDGET_NORMAL_TEXT); } else if (get_wstate(pIButton) == FC_WS_SELLECTED) { TMPString.fgcol = *get_theme_color(COLOR_THEME_WIDGET_SELECTED_TEXT); TMPString.style |= TTF_STYLE_BOLD; } else if (get_wstate(pIButton) == FC_WS_PRESSED) { TMPString.fgcol = *get_theme_color(COLOR_THEME_WIDGET_PRESSED_TEXT); } else if (get_wstate(pIButton) == FC_WS_DISABLED) { TMPString.fgcol = *get_theme_color(COLOR_THEME_WIDGET_DISABLED_TEXT); } pText = create_text_surf_from_str16(&TMPString); } if (!pText && !pIcon) { return -1; } /* create Button graphic */ pButton = create_bcgnd_surf(pIButton->theme, get_wstate(pIButton), pIButton->size.w, pIButton->size.h); clear_surface(pIButton->dst->surface, &pIButton->size); alphablit(pButton, NULL, pIButton->dst->surface, &pIButton->size); FREESURFACE(pButton); if (pIcon) { /* Icon */ if (pText) { if (get_wflags(pIButton) & WF_ICON_CENTER_RIGHT) { Ix = pIButton->size.w - pIcon->w - 5; } else { if (get_wflags(pIButton) & WF_ICON_CENTER) { Ix = (pIButton->size.w - pIcon->w) / 2; } else { Ix = 5; } } if (get_wflags(pIButton) & WF_ICON_ABOVE_TEXT) { Iy = 3; y = 3 + pIcon->h + 3 + (pIButton->size.h - (pIcon->h + 6) - pText->h) / 2; } else { if (get_wflags(pIButton) & WF_ICON_UNDER_TEXT) { y = 3 + (pIButton->size.h - (pIcon->h + 3) - pText->h) / 2; Iy = y + pText->h + 3; } else { /* center */ Iy = (pIButton->size.h - pIcon->h) / 2; y = (pIButton->size.h - pText->h) / 2; } } } else { /* no text */ Iy = (pIButton->size.h - pIcon->h) / 2; Ix = (pIButton->size.w - pIcon->w) / 2; } if (get_wstate(pIButton) == FC_WS_PRESSED) { Ix += 1; Iy += 1; } dest.x = pIButton->size.x + Ix; dest.y = pIButton->size.y + Iy; ret = alphablit(pIcon, NULL, pIButton->dst->surface, &dest); if (ret) { FREESURFACE(pText); return ret - 10; } } if (pText) { if (pIcon) { if (!(get_wflags(pIButton) & WF_ICON_ABOVE_TEXT) && !(get_wflags(pIButton) & WF_ICON_UNDER_TEXT)) { if (get_wflags(pIButton) & WF_ICON_CENTER_RIGHT) { if (pIButton->string16->style & SF_CENTER) { x = (pIButton->size.w - (pIcon->w + 5) - pText->w) / 2; } else { if (pIButton->string16->style & SF_CENTER_RIGHT) { x = pIButton->size.w - (pIcon->w + 7) - pText->w; } else { x = 5; } } } /* end WF_ICON_CENTER_RIGHT */ else { if (get_wflags(pIButton) & WF_ICON_CENTER) { /* text is blit on icon */ goto Alone; } /* end WF_ICON_CENTER */ else { /* icon center left - default */ if (pIButton->string16->style & SF_CENTER) { x = 5 + pIcon->w + ((pIButton->size.w - (pIcon->w + 5) - pText->w) / 2); } else { if (pIButton->string16->style & SF_CENTER_RIGHT) { x = pIButton->size.w - pText->w - 5; } else { /* text center left */ x = 5 + pIcon->w + 3; } } } /* end icon center left - default */ } /* 888888888888888888 */ } else { goto Alone; } } else { /* !pIcon */ y = (pIButton->size.h - pText->h) / 2; Alone: if (pIButton->string16->style & SF_CENTER) { x = (pIButton->size.w - pText->w) / 2; } else { if (pIButton->string16->style & SF_CENTER_RIGHT) { x = pIButton->size.w - pText->w - 5; } else { x = 5; } } } if (get_wstate(pIButton) == FC_WS_PRESSED) { x += 1; } else { y -= 1; } dest.x = pIButton->size.x + x; dest.y = pIButton->size.y + y; ret = alphablit(pText, NULL, pIButton->dst->surface, &dest); } FREESURFACE(pText); return 0; }
/************************************************************************** Create Edit Field surface ( with Text) and blit them to Main.screen, on position 'pEdit_Widget->size.x , pEdit_Widget->size.y' Graphic is taken from 'pEdit_Widget->theme' Text is taken from 'pEdit_Widget->sting16' if flag 'FW_DRAW_THEME_TRANSPARENT' is set theme will be blit transparent ( Alpha = 128 ) function return Hight of created surfaces or (-1) if theme surface can't be created. **************************************************************************/ static int redraw_edit(struct widget *pEdit_Widget) { int ret; if (get_wstate(pEdit_Widget) == FC_WS_PRESSED) { return redraw_edit_chain((struct EDIT *)pEdit_Widget->data.ptr); } else { int iRet = 0; SDL_Rect rDest = {pEdit_Widget->size.x, pEdit_Widget->size.y, 0, 0}; SDL_Surface *pEdit = NULL; SDL_Surface *pText; ret = (*baseclass_redraw)(pEdit_Widget); if (ret != 0) { return ret; } if (pEdit_Widget->string16->text && get_wflags(pEdit_Widget) & WF_PASSWD_EDIT) { Uint16 *backup = pEdit_Widget->string16->text; size_t len = unistrlen(backup) + 1; char *cBuf = fc_calloc(1, len); memset(cBuf, '*', len - 1); cBuf[len - 1] = '\0'; pEdit_Widget->string16->text = convert_to_utf16(cBuf); pText = create_text_surf_from_str16(pEdit_Widget->string16); FC_FREE(pEdit_Widget->string16->text); FC_FREE(cBuf); pEdit_Widget->string16->text = backup; } else { pText = create_text_surf_from_str16(pEdit_Widget->string16); } pEdit = create_bcgnd_surf(pEdit_Widget->theme, get_wstate(pEdit_Widget), pEdit_Widget->size.w, pEdit_Widget->size.h); if (!pEdit) { return -1; } /* blit theme */ alphablit(pEdit, NULL, pEdit_Widget->dst->surface, &rDest); /* set position and blit text */ if (pText) { rDest.y += (pEdit->h - pText->h) / 2; /* blit centred text to botton */ if (pEdit_Widget->string16->style & SF_CENTER) { rDest.x += (pEdit->w - pText->w) / 2; } else { if (pEdit_Widget->string16->style & SF_CENTER_RIGHT) { rDest.x += pEdit->w - pText->w - adj_size(5); } else { rDest.x += adj_size(5); /* cennter left */ } } alphablit(pText, NULL, pEdit_Widget->dst->surface, &rDest); } /* pText */ iRet = pEdit->h; /* Free memory */ FREESURFACE(pText); FREESURFACE(pEdit); return iRet; } return 0; }