void UI_fontstyle_draw_ex(
        const uiFontStyle *fs, const rcti *rect, const char *str,
        size_t len, float *r_xofs, float *r_yofs)
{
	float height;
	int xofs = 0, yofs;
	
	UI_fontstyle_set(fs);

	height = BLF_ascender(fs->uifont_id);
	yofs = ceil(0.5f * (BLI_rcti_size_y(rect) - height));

	if (fs->align == UI_STYLE_TEXT_CENTER) {
		xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len)));
		/* don't center text if it chops off the start of the text, 2 gives some margin */
		if (xofs < 2) {
			xofs = 2;
		}
	}
	else if (fs->align == UI_STYLE_TEXT_RIGHT) {
		xofs = BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len) - 0.1f * U.widget_unit;
	}
	
	/* clip is very strict, so we give it some space */
	BLF_clipping(fs->uifont_id, rect->xmin - 2, rect->ymin - 4, rect->xmax + 1, rect->ymax + 4);
	BLF_enable(fs->uifont_id, BLF_CLIPPING);
	BLF_position(fs->uifont_id, rect->xmin + xofs, rect->ymin + yofs, 0.0f);

	if (fs->shadow) {
		BLF_enable(fs->uifont_id, BLF_SHADOW);
		BLF_shadow(fs->uifont_id, fs->shadow, fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha);
		BLF_shadow_offset(fs->uifont_id, fs->shadx, fs->shady);
	}

	if (fs->kerning == 1)
		BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);

	BLF_draw(fs->uifont_id, str, len);
	BLF_disable(fs->uifont_id, BLF_CLIPPING);
	if (fs->shadow)
		BLF_disable(fs->uifont_id, BLF_SHADOW);
	if (fs->kerning == 1)
		BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT);

	*r_xofs = xofs;
	*r_yofs = yofs;
}
Exemple #2
0
void uiStyleFontDrawExt(uiFontStyle *fs, rcti *rect, const char *str,
	float *r_xofs, float *r_yofs)
{
	float height;
	int xofs=0, yofs;
	
	uiStyleFontSet(fs);

	height= BLF_ascender(fs->uifont_id);
	yofs= ceil( 0.5f*(rect->ymax - rect->ymin - height));

	if(fs->align==UI_STYLE_TEXT_CENTER) {
		xofs= floor( 0.5f*(rect->xmax - rect->xmin - BLF_width(fs->uifont_id, str)));
		/* don't center text if it chops off the start of the text, 2 gives some margin */
		if(xofs < 2) {
			xofs= 2;
		}
	}
	else if(fs->align==UI_STYLE_TEXT_RIGHT) {
		xofs= rect->xmax - rect->xmin - BLF_width(fs->uifont_id, str) - 1;
	}
	
	/* clip is very strict, so we give it some space */
	BLF_clipping(fs->uifont_id, rect->xmin-1, rect->ymin-4, rect->xmax+1, rect->ymax+4);
	BLF_enable(fs->uifont_id, BLF_CLIPPING);
	BLF_position(fs->uifont_id, rect->xmin+xofs, rect->ymin+yofs, 0.0f);

	if (fs->shadow) {
		BLF_enable(fs->uifont_id, BLF_SHADOW);
		BLF_shadow(fs->uifont_id, fs->shadow, fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha);
		BLF_shadow_offset(fs->uifont_id, fs->shadx, fs->shady);
	}

	if (fs->kerning == 1)
		BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);

	BLF_draw(fs->uifont_id, str, 65535); /* XXX, use real length */
	BLF_disable(fs->uifont_id, BLF_CLIPPING);
	if (fs->shadow)
		BLF_disable(fs->uifont_id, BLF_SHADOW);
	if (fs->kerning == 1)
		BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT);

	*r_xofs= xofs;
	*r_yofs= yofs;
}
Exemple #3
0
/* drawn same as above, but at 90 degree angle */
void UI_fontstyle_draw_rotated(const uiFontStyle *fs,
                               const rcti *rect,
                               const char *str,
                               const uchar col[4])
{
  float height;
  int xofs, yofs;
  float angle;
  rcti txtrect;

  UI_fontstyle_set(fs);

  height = BLF_ascender(fs->uifont_id) + BLF_descender(fs->uifont_id);
  /* becomes x-offset when rotated */
  xofs = ceil(0.5f * (BLI_rcti_size_y(rect) - height));

  /* ignore UI_STYLE, always aligned to top */

  /* rotate counter-clockwise for now (assumes left-to-right language)*/
  xofs += height;
  yofs = BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX) + 5;
  angle = M_PI_2;

  /* translate rect to vertical */
  txtrect.xmin = rect->xmin - BLI_rcti_size_y(rect);
  txtrect.ymin = rect->ymin - BLI_rcti_size_x(rect);
  txtrect.xmax = rect->xmin;
  txtrect.ymax = rect->ymin;

  /* clip is very strict, so we give it some space */
  /* clipping is done without rotation, so make rect big enough to contain both positions */
  BLF_clipping(fs->uifont_id,
               txtrect.xmin - 1,
               txtrect.ymin - yofs - xofs - 4,
               rect->xmax + 1,
               rect->ymax + 4);
  BLF_enable(fs->uifont_id, BLF_CLIPPING);
  BLF_position(fs->uifont_id, txtrect.xmin + xofs, txtrect.ymax - yofs, 0.0f);

  BLF_enable(fs->uifont_id, BLF_ROTATION);
  BLF_rotation(fs->uifont_id, angle);
  BLF_color4ubv(fs->uifont_id, col);

  if (fs->shadow) {
    BLF_enable(fs->uifont_id, BLF_SHADOW);
    const float shadow_color[4] = {
        fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha};
    BLF_shadow(fs->uifont_id, fs->shadow, shadow_color);
    BLF_shadow_offset(fs->uifont_id, fs->shadx, fs->shady);
  }

  if (fs->kerning == 1) {
    BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);
  }

  BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
  BLF_disable(fs->uifont_id, BLF_ROTATION);
  BLF_disable(fs->uifont_id, BLF_CLIPPING);
  if (fs->shadow) {
    BLF_disable(fs->uifont_id, BLF_SHADOW);
  }
  if (fs->kerning == 1) {
    BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT);
  }
}
Exemple #4
0
void UI_fontstyle_draw_ex(const uiFontStyle *fs,
                          const rcti *rect,
                          const char *str,
                          const uchar col[4],
                          const struct uiFontStyleDraw_Params *fs_params,
                          size_t len,
                          float *r_xofs,
                          float *r_yofs)
{
  int xofs = 0, yofs;
  int font_flag = BLF_CLIPPING;

  UI_fontstyle_set(fs);

  /* set the flag */
  if (fs->shadow) {
    font_flag |= BLF_SHADOW;
    const float shadow_color[4] = {
        fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha};
    BLF_shadow(fs->uifont_id, fs->shadow, shadow_color);
    BLF_shadow_offset(fs->uifont_id, fs->shadx, fs->shady);
  }
  if (fs->kerning == 1) {
    font_flag |= BLF_KERNING_DEFAULT;
  }
  if (fs_params->word_wrap == 1) {
    font_flag |= BLF_WORD_WRAP;
  }

  BLF_enable(fs->uifont_id, font_flag);

  if (fs_params->word_wrap == 1) {
    /* draw from boundbox top */
    yofs = BLI_rcti_size_y(rect) - BLF_height_max(fs->uifont_id);
  }
  else {
    /* draw from boundbox center */
    float height = BLF_ascender(fs->uifont_id) + BLF_descender(fs->uifont_id);
    yofs = ceil(0.5f * (BLI_rcti_size_y(rect) - height));
  }

  if (fs_params->align == UI_STYLE_TEXT_CENTER) {
    xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len)));
  }
  else if (fs_params->align == UI_STYLE_TEXT_RIGHT) {
    xofs = BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len);
  }

  yofs = MAX2(0, yofs);
  xofs = MAX2(0, xofs);

  BLF_clipping(fs->uifont_id, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
  BLF_position(fs->uifont_id, rect->xmin + xofs, rect->ymin + yofs, 0.0f);
  BLF_color4ubv(fs->uifont_id, col);

  BLF_draw(fs->uifont_id, str, len);

  BLF_disable(fs->uifont_id, font_flag);

  *r_xofs = xofs;
  *r_yofs = yofs;
}