Exemplo n.º 1
0
/****************************************************************************
  Return the size of the given text in the given font.  This size should
  include the ascent and descent of the text.  Either of width or height
  may be NULL in which case those values simply shouldn't be filled out.
****************************************************************************/
void get_text_size(int *width, int *height,
		   enum client_font font, const char *text)
{
  SDL_String16 *pText = create_string16(NULL, 0, *fonts[font]);
  copy_chars_to_string16(pText, text);

  if (width) {
    *width = str16size(pText).w;
  }
  if (height) {
    *height = str16size(pText).h;
  }
  
  FREESTRING16(pText);
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
/**************************************************************************
  ...
**************************************************************************/
bool convert_string_to_const_surface_width(SDL_String16 *pString,
								int width)
{  
  int w;
  bool converted = FALSE;
  
  fc_assert_ret_val(pString != NULL, FALSE);
  fc_assert_ret_val(pString->text != NULL, FALSE);
  
  w = str16size(pString).w;
  if(w > width) {
    /* cut string length to w length by replacing space " " with new line "\n" */
    bool resize = FALSE;
    int len = 0, adv;
    Uint16 New_Line, Space;
    Uint16 *ptr_rev, *ptr = pString->text;
        
    {
      Uint16 pBuf[2];
      convertcopy_to_utf16(pBuf, sizeof(pBuf), "\n");
      New_Line = pBuf[0];
      convertcopy_to_utf16(pBuf, sizeof(pBuf), " ");
      Space = pBuf[0];
    }
    
    converted = TRUE;
    
    do {
      if (!resize) {
	
	if (*ptr == '\0') {
	  resize = TRUE;
	  continue;
	}
	
	if (*ptr == New_Line) {
	  len = 0;
	  ptr++;
	  continue;
	}
		
	if (!((pString->style & 0x0F) & TTF_STYLE_NORMAL)) {
    	  TTF_SetFontStyle(pString->font, (pString->style & 0x0F));
	}
	TTF_GlyphMetrics(pString->font, *ptr, NULL, NULL, NULL, NULL, &adv);
	if (!((pString->style & 0x0F) & TTF_STYLE_NORMAL)) {
    	  TTF_SetFontStyle(pString->font, TTF_STYLE_NORMAL);
	}
	
	len += adv;
	
	if (len > width) {
	  ptr_rev = ptr;
	  while(ptr_rev != pString->text) {
	    if(*ptr_rev == Space) {
              *ptr_rev = New_Line;/* "\n" */
              w = str16size(pString).w;
	      len = 0;
	      break;
	    }
	    if(*ptr_rev == New_Line) {
	      resize = TRUE;
	      break;
	    }
	    ptr_rev--;
	  }
	  if (ptr_rev == pString->text) {
	    resize = TRUE;
	  }
	}
	
	ptr++;
      } else {
        if (pString->ptsize > 8) {
	  change_ptsize16(pString, pString->ptsize - 1);
	  w = str16size(pString).w;
	} else {
          log_error("Can't convert string to const width");
          break;
	}
      }  
      
    } while (w > width);
  }
    
  return converted;
}