/* 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); }
/* drawn same as above, but at 90 degree angle */ void uiStyleFontDrawRotated(uiFontStyle *fs, rcti *rect, const char *str) { float height; int xofs, yofs; float angle; rcti txtrect; uiStyleFontSet(fs); height= BLF_ascender(fs->uifont_id); /* becomes x-offset when rotated */ xofs= ceil( 0.5f*(rect->ymax - rect->ymin - 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) + 5; angle= 90.0f; /* translate rect to vertical */ txtrect.xmin= rect->xmin - (rect->ymax - rect->ymin); txtrect.ymin= rect->ymin - (rect->xmax - rect->xmin); 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); 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_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); }
void GPC_RenderTools::RenderText3D( int fontid, const char* text, int size, int dpi, float* color, double* mat, float aspect) { /* the actual drawing */ glColor3fv(color); /* multiply the text matrix by the object matrix */ BLF_enable(fontid, BLF_MATRIX|BLF_ASPECT); BLF_matrix(fontid, mat); /* aspect is the inverse scale that allows you to increase */ /* your resolution without sizing the final text size */ /* the bigger the size, the smaller the aspect */ BLF_aspect(fontid, aspect, aspect, aspect); BLF_size(fontid, size, dpi); BLF_position(fontid, 0, 0, 0); BLF_draw(fontid, (char *)text, strlen(text)); BLF_disable(fontid, BLF_MATRIX|BLF_ASPECT); glEnable(GL_DEPTH_TEST); }
void RAS_OpenGLRasterizer::RenderText3D( int fontid, const char *text, int size, int dpi, const float color[4], const double mat[16], float aspect) { /* gl prepping */ DisableForText(); /* the actual drawing */ glColor4fv(color); /* multiply the text matrix by the object matrix */ BLF_enable(fontid, BLF_MATRIX|BLF_ASPECT); BLF_matrix(fontid, mat); /* aspect is the inverse scale that allows you to increase */ /* your resolution without sizing the final text size */ /* the bigger the size, the smaller the aspect */ BLF_aspect(fontid, aspect, aspect, aspect); BLF_size(fontid, size, dpi); BLF_position(fontid, 0, 0, 0); BLF_draw(fontid, text, 65535); BLF_disable(fontid, BLF_MATRIX|BLF_ASPECT); }
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; }
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; }
void UI_fontstyle_draw_ex( const uiFontStyle *fs, const rcti *rect, const char *str, 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->word_wrap == 1) { font_flag |= BLF_WORD_WRAP; } BLF_enable(fs->uifont_id, font_flag); if (fs->word_wrap == 1) { /* draw from boundbox top */ yofs = BLI_rcti_size_y(rect) - BLF_height_max(fs->uifont_id); } else { /* draw from boundbox center */ yofs = ceil(0.5f * (BLI_rcti_size_y(rect) - BLF_ascender(fs->uifont_id))); } 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_position(fs->uifont_id, rect->xmin + xofs, rect->ymin + yofs, 0.0f); BLF_draw(fs->uifont_id, str, len); BLF_disable(fs->uifont_id, font_flag); *r_xofs = xofs; *r_yofs = yofs; }
static PyObject *py_blf_enable(PyObject *UNUSED(self), PyObject *args) { int option, fontid; if (!PyArg_ParseTuple(args, "ii:blf.enable", &fontid, &option)) return NULL; BLF_enable(fontid, option); Py_RETURN_NONE; }
/** * 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); }
/* temporarily, does widget font */ void UI_DrawString(float x, float y, const char *str) { uiStyle *style= U.uistyles.first; if (style->widget.kerning == 1) BLF_enable(style->widget.uifont_id, BLF_KERNING_DEFAULT); uiStyleFontSet(&style->widget); BLF_position(style->widget.uifont_id, x, y, 0.0f); BLF_draw(style->widget.uifont_id, str, 65535); /* XXX, use real length */ if (style->widget.kerning == 1) BLF_disable(style->widget.uifont_id, BLF_KERNING_DEFAULT); }
void GPC_RenderTools::RenderText3D( int fontid, const char* text, int size, int dpi, float* color, double* mat, float aspect) { if(GLEW_ARB_multitexture) { for(int i=0; i<MAXTEX; i++) { glActiveTextureARB(GL_TEXTURE0_ARB+i); if(GLEW_ARB_texture_cube_map) if(glIsEnabled(GL_TEXTURE_CUBE_MAP_ARB)) glDisable(GL_TEXTURE_CUBE_MAP_ARB); if(glIsEnabled(GL_TEXTURE_2D)) glDisable(GL_TEXTURE_2D); } glActiveTextureARB(GL_TEXTURE0_ARB); } else { if(GLEW_ARB_texture_cube_map) if(glIsEnabled(GL_TEXTURE_CUBE_MAP_ARB)) glDisable(GL_TEXTURE_CUBE_MAP_ARB); if(glIsEnabled(GL_TEXTURE_2D)) glDisable(GL_TEXTURE_2D); } /* the actual drawing */ glColor4fv(color); /* multiply the text matrix by the object matrix */ BLF_enable(fontid, BLF_MATRIX|BLF_ASPECT); BLF_matrix(fontid, mat); /* aspect is the inverse scale that allows you to increase */ /* your resolution without sizing the final text size */ /* the bigger the size, the smaller the aspect */ BLF_aspect(fontid, aspect, aspect, aspect); BLF_size(fontid, size, dpi); BLF_position(fontid, 0, 0, 0); BLF_draw(fontid, text, 65535); BLF_disable(fontid, BLF_MATRIX|BLF_ASPECT); glEnable(GL_DEPTH_TEST); }
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; }
/* temporarily, does widget font */ int UI_GetStringWidth(const char *str) { uiStyle *style= U.uistyles.first; uiFontStyle *fstyle= &style->widget; int width; if (fstyle->kerning==1) /* for BLF_width */ BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); uiStyleFontSet(fstyle); width= BLF_width(fstyle->uifont_id, str); if (fstyle->kerning==1) BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); return width; }
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; }
/** * 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); } }
/* Print 3D text */ void BL_print_game_line(int fontid, const char *text, int size, int dpi, float *color, double *mat, float aspect) { /* gl prepping */ DisableForText(); /* the actual drawing */ glColor4fv(color); /* multiply the text matrix by the object matrix */ BLF_enable(fontid, BLF_MATRIX|BLF_ASPECT); BLF_matrix(fontid, mat); /* aspect is the inverse scale that allows you to increase */ /* your resolution without sizing the final text size */ /* the bigger the size, the smaller the aspect */ BLF_aspect(fontid, aspect, aspect, aspect); BLF_size(fontid, size, dpi); BLF_position(fontid, 0, 0, 0); BLF_draw(fontid, (char *)text, 65535); BLF_disable(fontid, BLF_MATRIX|BLF_ASPECT); }
/** * 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); }
static void ruler_info_draw_pixel(const struct bContext *C, ARegion *ar, void *arg) { Scene *scene = CTX_data_scene(C); UnitSettings *unit = &scene->unit; RulerItem *ruler_item; RulerInfo *ruler_info = arg; RegionView3D *rv3d = ruler_info->ar->regiondata; // ARegion *ar = ruler_info->ar; const float cap_size = 4.0f; const float bg_margin = 4.0f * U.pixelsize; const float bg_radius = 4.0f * U.pixelsize; const float arc_size = 64.0f * U.pixelsize; #define ARC_STEPS 24 const int arc_steps = ARC_STEPS; int i; //unsigned int color_act = 0x666600; unsigned int color_act = 0xffffff; unsigned int color_base = 0x0; unsigned char color_back[4] = {0xff, 0xff, 0xff, 0x80}; unsigned char color_text[3]; unsigned char color_wire[3]; /* anti-aliased lines for more consistent appearance */ glEnable(GL_LINE_SMOOTH); BLF_enable(blf_mono_font, BLF_ROTATION); BLF_size(blf_mono_font, 14 * U.pixelsize, U.dpi); BLF_rotation(blf_mono_font, 0.0f); UI_GetThemeColor3ubv(TH_TEXT, color_text); UI_GetThemeColor3ubv(TH_WIRE, color_wire); for (ruler_item = ruler_info->items.first, i = 0; ruler_item; ruler_item = ruler_item->next, i++) { const bool is_act = (i == ruler_info->item_active); float dir_ruler[2]; float co_ss[3][2]; int j; /* should these be checked? - ok for now not to */ for (j = 0; j < 3; j++) { ED_view3d_project_float_global(ar, ruler_item->co[j], co_ss[j], V3D_PROJ_TEST_NOP); } glEnable(GL_BLEND); cpack(is_act ? color_act : color_base); if (ruler_item->flag & RULERITEM_USE_ANGLE) { glBegin(GL_LINE_STRIP); for (j = 0; j < 3; j++) { glVertex2fv(co_ss[j]); } glEnd(); cpack(0xaaaaaa); setlinestyle(3); glBegin(GL_LINE_STRIP); for (j = 0; j < 3; j++) { glVertex2fv(co_ss[j]); } glEnd(); setlinestyle(0); /* arc */ { float dir_tmp[3]; float co_tmp[3]; float arc_ss_coords[ARC_STEPS + 1][2]; float dir_a[3]; float dir_b[3]; float quat[4]; float axis[3]; float angle; const float px_scale = (ED_view3d_pixel_size(rv3d, ruler_item->co[1]) * min_fff(arc_size, len_v2v2(co_ss[0], co_ss[1]) / 2.0f, len_v2v2(co_ss[2], co_ss[1]) / 2.0f)); sub_v3_v3v3(dir_a, ruler_item->co[0], ruler_item->co[1]); sub_v3_v3v3(dir_b, ruler_item->co[2], ruler_item->co[1]); normalize_v3(dir_a); normalize_v3(dir_b); cross_v3_v3v3(axis, dir_a, dir_b); angle = angle_normalized_v3v3(dir_a, dir_b); axis_angle_to_quat(quat, axis, angle / arc_steps); copy_v3_v3(dir_tmp, dir_a); glColor3ubv(color_wire); for (j = 0; j <= arc_steps; j++) { madd_v3_v3v3fl(co_tmp, ruler_item->co[1], dir_tmp, px_scale); ED_view3d_project_float_global(ar, co_tmp, arc_ss_coords[j], V3D_PROJ_TEST_NOP); mul_qt_v3(quat, dir_tmp); } glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_FLOAT, 0, arc_ss_coords); glDrawArrays(GL_LINE_STRIP, 0, arc_steps + 1); glDisableClientState(GL_VERTEX_ARRAY); } /* text */ { char numstr[256]; float numstr_size[2]; float pos[2]; const int prec = 2; /* XXX, todo, make optional */ ruler_item_as_string(ruler_item, unit, numstr, sizeof(numstr), prec); BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]); pos[0] = co_ss[1][0] + (cap_size * 2.0f); pos[1] = co_ss[1][1] - (numstr_size[1] / 2.0f); /* draw text (bg) */ glColor4ubv(color_back); uiSetRoundBox(UI_CNR_ALL); uiRoundBox(pos[0] - bg_margin, pos[1] - bg_margin, pos[0] + bg_margin + numstr_size[0], pos[1] + bg_margin + numstr_size[1], bg_radius); /* draw text */ glColor3ubv(color_text); BLF_position(blf_mono_font, pos[0], pos[1], 0.0f); BLF_rotation(blf_mono_font, 0.0f); BLF_draw(blf_mono_font, numstr, sizeof(numstr)); } /* capping */ { float rot_90_vec_a[2]; float rot_90_vec_b[2]; float cap[2]; sub_v2_v2v2(dir_ruler, co_ss[0], co_ss[1]); rot_90_vec_a[0] = -dir_ruler[1]; rot_90_vec_a[1] = dir_ruler[0]; normalize_v2(rot_90_vec_a); sub_v2_v2v2(dir_ruler, co_ss[1], co_ss[2]); rot_90_vec_b[0] = -dir_ruler[1]; rot_90_vec_b[1] = dir_ruler[0]; normalize_v2(rot_90_vec_b); glEnable(GL_BLEND); glColor3ubv(color_wire); glBegin(GL_LINES); madd_v2_v2v2fl(cap, co_ss[0], rot_90_vec_a, cap_size); glVertex2fv(cap); madd_v2_v2v2fl(cap, co_ss[0], rot_90_vec_a, -cap_size); glVertex2fv(cap); madd_v2_v2v2fl(cap, co_ss[2], rot_90_vec_b, cap_size); glVertex2fv(cap); madd_v2_v2v2fl(cap, co_ss[2], rot_90_vec_b, -cap_size); glVertex2fv(cap); /* angle vertex */ glVertex2f(co_ss[1][0] - cap_size, co_ss[1][1] - cap_size); glVertex2f(co_ss[1][0] + cap_size, co_ss[1][1] + cap_size); glVertex2f(co_ss[1][0] - cap_size, co_ss[1][1] + cap_size); glVertex2f(co_ss[1][0] + cap_size, co_ss[1][1] - cap_size); glEnd(); glDisable(GL_BLEND); } } else { glBegin(GL_LINE_STRIP); for (j = 0; j < 3; j += 2) { glVertex2fv(co_ss[j]); } glEnd(); cpack(0xaaaaaa); setlinestyle(3); glBegin(GL_LINE_STRIP); for (j = 0; j < 3; j += 2) { glVertex2fv(co_ss[j]); } glEnd(); setlinestyle(0); sub_v2_v2v2(dir_ruler, co_ss[0], co_ss[2]); /* text */ { char numstr[256]; float numstr_size[2]; const int prec = 6; /* XXX, todo, make optional */ float pos[2]; ruler_item_as_string(ruler_item, unit, numstr, sizeof(numstr), prec); BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]); mid_v2_v2v2(pos, co_ss[0], co_ss[2]); /* center text */ pos[0] -= numstr_size[0] / 2.0f; pos[1] -= numstr_size[1] / 2.0f; /* draw text (bg) */ glColor4ubv(color_back); uiSetRoundBox(UI_CNR_ALL); uiRoundBox(pos[0] - bg_margin, pos[1] - bg_margin, pos[0] + bg_margin + numstr_size[0], pos[1] + bg_margin + numstr_size[1], bg_radius); /* draw text */ glColor3ubv(color_text); BLF_position(blf_mono_font, pos[0], pos[1], 0.0f); BLF_draw(blf_mono_font, numstr, sizeof(numstr)); } /* capping */ { float rot_90_vec[2] = {-dir_ruler[1], dir_ruler[0]}; float cap[2]; normalize_v2(rot_90_vec); glEnable(GL_BLEND); glColor3ubv(color_wire); glBegin(GL_LINES); madd_v2_v2v2fl(cap, co_ss[0], rot_90_vec, cap_size); glVertex2fv(cap); madd_v2_v2v2fl(cap, co_ss[0], rot_90_vec, -cap_size); glVertex2fv(cap); madd_v2_v2v2fl(cap, co_ss[2], rot_90_vec, cap_size); glVertex2fv(cap); madd_v2_v2v2fl(cap, co_ss[2], rot_90_vec, -cap_size); glVertex2fv(cap); glEnd(); glDisable(GL_BLEND); } } } glDisable(GL_LINE_SMOOTH); BLF_disable(blf_mono_font, BLF_ROTATION); #undef ARC_STEPS /* draw snap */ if ((ruler_info->snap_flag & RULER_SNAP_OK) && (ruler_info->state == RULER_STATE_DRAG)) { ruler_item = ruler_item_active_get(ruler_info); if (ruler_item) { /* size from drawSnapping */ const float size = 2.5f * UI_GetThemeValuef(TH_VERTEX_SIZE); float co_ss[3]; ED_view3d_project_float_global(ar, ruler_item->co[ruler_item->co_index], co_ss, V3D_PROJ_TEST_NOP); cpack(color_act); circ(co_ss[0], co_ss[1], size * U.pixelsize); } } }
static void playanim_toscreen(PlayState *ps, PlayAnimPict *picture, struct ImBuf *ibuf, int fontid, int fstep) { float offsx, offsy; if (ibuf == NULL) { printf("%s: no ibuf for picture '%s'\n", __func__, picture ? picture->name : "<NIL>"); return; } if (ibuf->rect == NULL && ibuf->rect_float) { IMB_rect_from_float(ibuf); imb_freerectfloatImBuf(ibuf); } if (ibuf->rect == NULL) return; GHOST_ActivateWindowDrawingContext(g_WS.ghost_window); /* offset within window */ offsx = 0.5f * (((float)ps->win_x - ps->zoom * ibuf->x) / (float)ps->win_x); offsy = 0.5f * (((float)ps->win_y - ps->zoom * ibuf->y) / (float)ps->win_y); CLAMP(offsx, 0.0f, 1.0f); CLAMP(offsy, 0.0f, 1.0f); glRasterPos2f(offsx, offsy); glClearColor(0.1, 0.1, 0.1, 0.0); glClear(GL_COLOR_BUFFER_BIT); /* checkerboard for case alpha */ if (ibuf->planes == 32) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); fdrawcheckerboard(offsx, offsy, offsx + (ps->zoom * ibuf->x) / (float)ps->win_x, offsy + (ps->zoom * ibuf->y) / (float)ps->win_y); } glDrawPixels(ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); glDisable(GL_BLEND); pupdate_time(); if (picture && (g_WS.qual & (WS_QUAL_SHIFT | WS_QUAL_LMOUSE)) && (fontid != -1)) { int sizex, sizey; float fsizex_inv, fsizey_inv; char str[32 + FILE_MAX]; cpack(-1); BLI_snprintf(str, sizeof(str), "%s | %.2f frames/s", picture->name, fstep / swaptime); playanim_window_get_size(&sizex, &sizey); fsizex_inv = 1.0f / sizex; fsizey_inv = 1.0f / sizey; BLF_enable(fontid, BLF_ASPECT); BLF_aspect(fontid, fsizex_inv, fsizey_inv, 1.0f); BLF_position(fontid, 10.0f * fsizex_inv, 10.0f * fsizey_inv, 0.0f); BLF_draw(fontid, str, sizeof(str)); } GHOST_SwapWindowBuffers(g_WS.ghost_window); }
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; }
/* reading without uifont will create one */ void uiStyleInit(void) { uiFont *font; uiStyle *style = U.uistyles.first; int monofont_size = datatoc_bmonofont_ttf_size; unsigned char *monofont_ttf = (unsigned char *)datatoc_bmonofont_ttf; /* recover from uninitialized dpi */ if (U.dpi == 0) U.dpi = 72; CLAMP(U.dpi, 48, 144); for (font = U.uifonts.first; font; font = font->next) { BLF_unload_id(font->blf_id); } if (blf_mono_font != -1) { BLF_unload_id(blf_mono_font); blf_mono_font = -1; } if (blf_mono_font_render != -1) { BLF_unload_id(blf_mono_font_render); blf_mono_font_render = -1; } font = U.uifonts.first; /* default builtin */ if (font == NULL) { font = MEM_callocN(sizeof(uiFont), "ui font"); BLI_addtail(&U.uifonts, font); } if (U.font_path_ui[0]) { BLI_strncpy(font->filename, U.font_path_ui, sizeof(font->filename)); font->uifont_id = UIFONT_CUSTOM1; } else { BLI_strncpy(font->filename, "default", sizeof(font->filename)); font->uifont_id = UIFONT_DEFAULT; } for (font = U.uifonts.first; font; font = font->next) { if (font->uifont_id == UIFONT_DEFAULT) { #ifdef WITH_INTERNATIONAL int font_size = datatoc_bfont_ttf_size; unsigned char *font_ttf = (unsigned char *)datatoc_bfont_ttf; static int last_font_size = 0; /* use unicode font for translation */ if (U.transopts & USER_DOTRANSLATE) { font_ttf = BLF_get_unifont(&font_size); if (!font_ttf) { /* fall back if not found */ font_size = datatoc_bfont_ttf_size; font_ttf = (unsigned char *)datatoc_bfont_ttf; } } /* relload only if needed */ if (last_font_size != font_size) { BLF_unload("default"); last_font_size = font_size; } font->blf_id = BLF_load_mem("default", font_ttf, font_size); #else font->blf_id = BLF_load_mem("default", (unsigned char *)datatoc_bfont_ttf, datatoc_bfont_ttf_size); #endif } else { font->blf_id = BLF_load(font->filename); if (font->blf_id == -1) { font->blf_id = BLF_load_mem("default", (unsigned char *)datatoc_bfont_ttf, datatoc_bfont_ttf_size); } } BLF_default_set(font->blf_id); if (font->blf_id == -1) { if (G.debug & G_DEBUG) printf("%s: error, no fonts available\n", __func__); } else { /* ? just for speed to initialize? * Yes, this build the glyph cache and create * the texture. */ BLF_size(font->blf_id, 11 * U.pixelsize, U.dpi); BLF_size(font->blf_id, 12 * U.pixelsize, U.dpi); BLF_size(font->blf_id, 14 * U.pixelsize, U.dpi); } } if (style == NULL) { ui_style_new(&U.uistyles, "Default Style", UIFONT_DEFAULT); } #ifdef WITH_INTERNATIONAL /* use unicode font for text editor and interactive console */ if (U.transopts & USER_DOTRANSLATE) { monofont_ttf = BLF_get_unifont_mono(&monofont_size); if (!monofont_ttf) { /* fall back if not found */ monofont_size = datatoc_bmonofont_ttf_size; monofont_ttf = (unsigned char *)datatoc_bmonofont_ttf; } } #endif /* XXX, this should be moved into a style, but for now best only load the monospaced font once. */ BLI_assert(blf_mono_font == -1); if (U.font_path_ui_mono[0]) { blf_mono_font = BLF_load_unique(U.font_path_ui_mono); } if (blf_mono_font == -1) { blf_mono_font = BLF_load_mem_unique("monospace", monofont_ttf, monofont_size); } BLF_size(blf_mono_font, 12 * U.pixelsize, 72); /* Set default flags based on UI preferences (not render fonts) */ { int flag_disable = BLF_MONOCHROME | BLF_HINTING_NONE | BLF_HINTING_SLIGHT | BLF_HINTING_FULL; int flag_enable = 0; if (U.text_render & USER_TEXT_HINTING_NONE) { flag_enable |= BLF_HINTING_NONE; } else if (U.text_render & USER_TEXT_HINTING_SLIGHT) { flag_enable |= BLF_HINTING_SLIGHT; } else if (U.text_render & USER_TEXT_HINTING_FULL) { flag_enable |= BLF_HINTING_FULL; } if (U.text_render & USER_TEXT_DISABLE_AA) { flag_enable |= BLF_MONOCHROME; } for (font = U.uifonts.first; font; font = font->next) { if (font->blf_id != -1) { BLF_disable(font->blf_id, flag_disable); BLF_enable(font->blf_id, flag_enable); } } if (blf_mono_font != -1) { BLF_disable(blf_mono_font, flag_disable); BLF_enable(blf_mono_font, flag_enable); } } /** * Second for rendering else we get threading problems, * * \note This isn't good that the render font depends on the preferences, * keep for now though, since without this there is no way to display many unicode chars. */ if (blf_mono_font_render == -1) blf_mono_font_render = BLF_load_mem_unique("monospace", monofont_ttf, monofont_size); BLF_size(blf_mono_font_render, 12 * U.pixelsize, 72); }