Esempio n. 1
0
/**
 * Similar to #UI_fontstyle_draw
 * but ignore alignment, shadow & no clipping rect.
 *
 * For drawing on-screen labels.
 */
void UI_fontstyle_draw_simple(const uiFontStyle *fs, float x, float y, const char *str)
{
	if (fs->kerning == 1)
		BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);

	UI_fontstyle_set(fs);
	BLF_position(fs->uifont_id, x, y, 0.0f);
	BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);

	if (fs->kerning == 1)
		BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT);
}
Esempio n. 2
0
/* drawn same as above, but at 90 degree angle */
void UI_fontstyle_draw_rotated(const uiFontStyle *fs, const rcti *rect, const char *str)
{
	float height;
	int xofs, yofs;
	float angle;
	rcti txtrect;

	UI_fontstyle_set(fs);

	height = BLF_ascender(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);

	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);
}
int UI_fontstyle_string_width(const uiFontStyle *fs, const char *str)
{
	int width;
	
	if (fs->kerning == 1) /* for BLF_width */
		BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);
	
	UI_fontstyle_set(fs);
	width = BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
	
	if (fs->kerning == 1)
		BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT);
	
	return width;
}
Esempio n. 4
0
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;
}
Esempio n. 5
0
float file_string_width(const char *str)
{
	uiStyle *style = UI_style_get();
	float width;

	UI_fontstyle_set(&style->widget);
	if (style->widget.kerning == 1) {  /* for BLF_width */
		BLF_enable(style->widget.uifont_id, BLF_KERNING_DEFAULT);
	}

	width = BLF_width(style->widget.uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);

	if (style->widget.kerning == 1) {
		BLF_disable(style->widget.uifont_id, BLF_KERNING_DEFAULT);
	}

	return width;
}
Esempio n. 6
0
/**
 * Same as #UI_fontstyle_draw but draw a colored backdrop.
 */
void UI_fontstyle_draw_simple_backdrop(const uiFontStyle *fs,
                                       float x,
                                       float y,
                                       const char *str,
                                       const float col_fg[4],
                                       const float col_bg[4])
{
  if (fs->kerning == 1) {
    BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);
  }

  UI_fontstyle_set(fs);

  {
    const float width = BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
    const float height = BLF_height_max(fs->uifont_id);
    const float decent = BLF_descender(fs->uifont_id);
    const float margin = height / 4.0f;

    /* backdrop */
    float color[4] = {col_bg[0], col_bg[1], col_bg[2], 0.5f};

    UI_draw_roundbox_corner_set(UI_CNR_ALL);
    UI_draw_roundbox_aa(true,
                        x - margin,
                        (y + decent) - margin,
                        x + width + margin,
                        (y + decent) + height + margin,
                        margin,
                        color);
  }

  BLF_position(fs->uifont_id, x, y, 0.0f);
  BLF_color4fv(fs->uifont_id, col_fg);
  BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);

  if (fs->kerning == 1) {
    BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT);
  }
}
/**
 * Same as #UI_fontstyle_draw but draw a colored backdrop.
 */
void UI_fontstyle_draw_simple_backdrop(
        const uiFontStyle *fs, float x, float y, const char *str,
        const unsigned char fg[4], const unsigned char bg[4])
{
	if (fs->kerning == 1)
		BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);

	UI_fontstyle_set(fs);

	{
		const float width = BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
		const float height = BLF_height_max(fs->uifont_id);
		const float decent = BLF_descender(fs->uifont_id);
		const float margin = height / 4.0f;

		/* backdrop */
		glColor4ubv(bg);

		UI_draw_roundbox_corner_set(UI_CNR_ALL | UI_RB_ALPHA);
		UI_draw_roundbox(
		        x - margin,
		        (y + decent) - margin,
		        x + width + margin,
		        (y + decent) + height + margin,
		        margin);

		glColor4ubv(fg);
	}


	BLF_position(fs->uifont_id, x, y, 0.0f);
	BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);

	if (fs->kerning == 1)
		BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT);
}
int UI_fontstyle_height_max(const uiFontStyle *fs)
{
	UI_fontstyle_set(fs);
	return BLF_height_max(fs->uifont_id);
}
Esempio n. 9
0
float file_string_width(const char *str)
{
	uiStyle *style = UI_style_get();
	UI_fontstyle_set(&style->widget);
	return BLF_width(style->widget.uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
}
Esempio n. 10
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;
}