Ejemplo n.º 1
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);
  }
}
Ejemplo n.º 2
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 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);
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
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);
  }
}
Ejemplo n.º 5
0
int textview_draw(TextViewContext *tvc, const int draw, int mval[2], void **mouse_pick, int *pos_pick)
{
	ConsoleDrawContext cdc = {0};

	int x_orig = CONSOLE_DRAW_MARGIN, y_orig = CONSOLE_DRAW_MARGIN + tvc->lheight / 6;
	int xy[2], y_prev;
	int sel[2] = {-1, -1}; /* defaults disabled */
	unsigned char fg[3], bg[3];
	const int font_id = blf_mono_font;

	console_font_begin(font_id, tvc->lheight);

	xy[0] = x_orig; xy[1] = y_orig;

	if (mval[1] != INT_MAX)
		mval[1] += (tvc->ymin + CONSOLE_DRAW_MARGIN);

	if (pos_pick)
		*pos_pick = 0;

	/* constants for the sequencer context */
	cdc.font_id = font_id;
	cdc.cwidth = (int)BLF_fixed_width(font_id);
	assert(cdc.cwidth > 0);
	cdc.lheight = tvc->lheight;
	cdc.lofs = -BLF_descender(font_id);
	/* note, scroll bar must be already subtracted () */
	cdc.console_width = (tvc->winx - (CONSOLE_DRAW_MARGIN * 2)) / cdc.cwidth;
	/* avoid divide by zero on small windows */
	if (cdc.console_width < 1)
		cdc.console_width = 1;
	cdc.winx = tvc->winx - CONSOLE_DRAW_MARGIN;
	cdc.ymin = tvc->ymin;
	cdc.ymax = tvc->ymax;
	cdc.xy = xy;
	cdc.sel = sel;
	cdc.pos_pick = pos_pick;
	cdc.mval = mval;
	cdc.draw = draw;

	/* shouldnt be needed */
	tvc->cwidth = cdc.cwidth;
	tvc->console_width = cdc.console_width;
	tvc->iter_index = 0;

	if (tvc->sel_start != tvc->sel_end) {
		sel[0] = tvc->sel_start;
		sel[1] = tvc->sel_end;
	}

	if (tvc->begin(tvc)) {
		unsigned char bg_sel[4] = {0};

		if (draw && tvc->const_colors) {
			tvc->const_colors(tvc, bg_sel);
		}

		do {
			const char *ext_line;
			int ext_len;
			int color_flag = 0;

			y_prev = xy[1];

			if (draw)
				color_flag = tvc->line_color(tvc, fg, bg);

			tvc->line_get(tvc, &ext_line, &ext_len);

			if (!console_draw_string(&cdc, ext_line, ext_len,
			                         (color_flag & TVC_LINE_FG) ? fg : NULL,
			                         (color_flag & TVC_LINE_BG) ? bg : NULL,
			                         bg_sel))
			{
				/* when drawing, if we pass v2d->cur.ymax, then quit */
				if (draw) {
					break; /* past the y limits */
				}
			}

			if ((mval[1] != INT_MAX) && (mval[1] >= y_prev && mval[1] <= xy[1])) {
				*mouse_pick = (void *)tvc->iter;
				break;
			}

			tvc->iter_index++;

		} while (tvc->step(tvc));
	}

	tvc->end(tvc);

	xy[1] += tvc->lheight * 2;

	return xy[1] - y_orig;
}