Ejemplo n.º 1
0
/**************************************************************************
  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;
}
Ejemplo n.º 2
0
/**************************************************************************
  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;
}