From d2cc19dcc65e2684894ba5b1e413b4b69cb09742 Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Fri, 10 Apr 2009 14:06:24 +0000 Subject: 2.5 More font style work; - hooked up almost all ui buttons code to new font system, including text clipping - panel headers scale now too to smaller fonts - added further style hints, for shadow/emboss. Is all going to be in UI designer control! - for fun; changed layout engine to spread vertical buttons in window width Next: removal of all usage of old font system, using 'styles'. Will also move font blurring to blenfont module. --- source/blender/blenfont/intern/blf_font.c | 5 +- source/blender/editors/include/UI_interface.h | 3 +- source/blender/editors/interface/interface.c | 110 ++++++++----------- .../blender/editors/interface/interface_intern.h | 8 +- .../blender/editors/interface/interface_layout.c | 5 +- source/blender/editors/interface/interface_panel.c | 7 +- .../blender/editors/interface/interface_regions.c | 12 +-- source/blender/editors/interface/interface_style.c | 95 +++++++++++++++-- .../blender/editors/interface/interface_widgets.c | 117 ++++++++++++--------- source/blender/makesdna/DNA_userdef_types.h | 2 +- 10 files changed, 214 insertions(+), 150 deletions(-) (limited to 'source') diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index b510832cbdd..9a4c0fdfa30 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -154,9 +154,8 @@ void blf_font_draw(FontBLF *font, char *str) pen_x += delta.x >> 6; } - /* This only return zero if the clipping is enable and the glyph is out of the clip rctf. */ - if (blf_glyph_render(font, g, (float)pen_x, (float)pen_y) == 0) - break; + /* do not return this loop if clipped, we want every character tested */ + blf_glyph_render(font, g, (float)pen_x, (float)pen_y); pen_x += g->advance; g_prev= g; diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 9c8cba94fae..44fee85b085 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -635,7 +635,8 @@ void uiRegionHeaderLayout(const struct bContext *C, struct ARegion *ar); void uiAnimContextProperty(const struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index); /* Styled text draw */ -void uiFontStyleDraw(struct uiFontStyle *fs, struct rcti *rect, char *str); +void uiStyleFontSet(struct uiFontStyle *fs); +void uiStyleFontDraw(struct uiFontStyle *fs, struct rcti *rect, char *str); diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 5a1b8fb6118..ea3b1ca3bce 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -52,6 +52,8 @@ #include "BIF_gl.h" #include "BIF_glutil.h" +#include "BLF_api.h" + #include "UI_interface.h" #include "UI_text.h" @@ -228,19 +230,21 @@ static void ui_block_translate(uiBlock *block, int x, int y) static void ui_text_bounds_block(uiBlock *block, float offset) { + uiStyle *style= U.uistyles.first; // XXX pass on as arg uiBut *bt; int i = 0, j, x1addval= offset, nextcol; - bt= block->buttons.first; - while(bt) { + uiStyleFontSet(&style->widget); + + for(bt= block->buttons.first; bt; bt= bt->next) { if(bt->type!=SEPR) { - int transopts= ui_translate_buttons(); - if(bt->type==TEX || bt->type==IDPOIN) transopts= 0; - j= UI_GetStringWidth(bt->font, bt->drawstr, transopts); + //int transopts= ui_translate_buttons(); + //if(bt->type==TEX || bt->type==IDPOIN) transopts= 0; + + j= BLF_width(bt->drawstr); if(j > i) i = j; } - bt= bt->next; } /* cope with multi collumns */ @@ -643,6 +647,22 @@ void uiEndBlock(const bContext *C, uiBlock *block) /* ************** BLOCK DRAWING FUNCTION ************* */ +static void ui_fontscale(short *points, float aspect) +{ + if(aspect < 0.9f || aspect > 1.1f) { + float pointsf= *points; + + /* for some reason scaling fonts goes too fast compared to widget size */ + aspect= sqrt(aspect); + pointsf /= aspect; + + if(aspect > 1.0) + *points= ceil(pointsf); + else + *points= floor(pointsf); + } +} + /* project button or block (but==NULL) to pixels in regionspace */ static void ui_but_to_pixelrect(rcti *rect, const ARegion *ar, uiBlock *block, uiBut *but) { @@ -665,8 +685,10 @@ static void ui_but_to_pixelrect(rcti *rect, const ARegion *ar, uiBlock *block, u rect->ymax= floor(getsizey*(0.5+ 0.5*(gx*block->winmat[0][1]+ gy*block->winmat[1][1]+ block->winmat[3][1]))); } +/* uses local copy of style, to scale things down, and allow widgets to change stuff */ void uiDrawBlock(const bContext *C, uiBlock *block) { + uiStyle style= *((uiStyle *)U.uistyles.first); // XXX pass on as arg ARegion *ar; uiBut *but; rcti rect; @@ -682,6 +704,15 @@ void uiDrawBlock(const bContext *C, uiBlock *block) /* we set this only once */ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + /* scale fonts */ + ui_fontscale(&style.paneltitle.points, block->aspect); + ui_fontscale(&style.grouplabel.points, block->aspect); + ui_fontscale(&style.widgetlabel.points, block->aspect); + ui_fontscale(&style.widget.points, block->aspect); + + /* scale block min/max to rect */ + ui_but_to_pixelrect(&rect, ar, block, NULL); + /* pixel space for AA widgets */ glMatrixMode(GL_PROJECTION); glPushMatrix(); @@ -692,18 +723,17 @@ void uiDrawBlock(const bContext *C, uiBlock *block) wmOrtho2(0.0f, ar->winx, 0.0f, ar->winy); /* back */ - ui_but_to_pixelrect(&rect, ar, block, NULL); if(block->flag & UI_BLOCK_LOOP) - ui_draw_menu_back(block, &rect); + ui_draw_menu_back(&style, block, &rect); else if(block->panel) - ui_draw_panel(ar, block, &rect); + ui_draw_panel(ar, &style, block, &rect); if(block->drawextra) block->drawextra(C, block); /* widgets */ for(but= block->buttons.first; but; but= but->next) { ui_but_to_pixelrect(&rect, ar, block, but); - ui_draw_but(ar, but, &rect); + ui_draw_but(ar, &style, but, &rect); } /* restore matrix */ @@ -1876,14 +1906,6 @@ uiBlock *uiBeginBlock(const bContext *C, ARegion *region, char *name, short dt, BLI_strncpy(block->name, name, sizeof(block->name)); -#if 0 - /* draw win */ - block->win= win; - /* window where queue event should be added, pretty weak this way! - this is because the 'mainwin' pup menu's */ - block->winq= mywinget(); -#endif - block->dt= dt; block->themecol= TH_AUTO; @@ -1908,8 +1930,6 @@ uiBlock *uiBeginBlock(const bContext *C, ARegion *region, char *name, short dt, block->flag |= UI_BLOCK_LOOP; /* tag as menu */ } - uiSetCurFont(block, font); - return block; } @@ -1931,7 +1951,6 @@ void ui_check_but(uiBut *but) double value; float okwidth; int transopts= ui_translate_buttons(); - short pos; ui_is_but_sel(but); @@ -2076,55 +2095,8 @@ void ui_check_but(uiBut *but) strcpy(but->drawstr, but->str); strcat(but->drawstr, but->editstr); } - - if(but->drawstr[0]) { - but->strwidth= but->aspect*UI_GetStringWidth(but->font, but->drawstr, transopts); - // here should be check for less space for icon offsets... - if(but->type==MENU) okwidth -= 15; - } - else - but->strwidth= 0; - - /* automatic width */ - if(but->x2==0.0f && but->x1 > 0.0f) { - but->x2= (but->x1+but->strwidth+6); - } - - if(but->strwidth==0) but->drawstr[0]= 0; - else if(but->block->flag & UI_BLOCK_LOOP); // no clip string, uiTextBoundsBlock is used (hack!) - else { - - /* calc but->ofs, to draw the string shorter if too long */ - but->ofs= 0; - - while(but->strwidth > (int)okwidth ) { - if ELEM3(but->type, NUM, NUMABS, TEX) { // only these cut off left - but->ofs++; - but->strwidth= but->aspect*UI_GetStringWidth(but->font, but->drawstr+but->ofs, transopts); - - /* textbut exception */ - if(but->editstr && but->pos != -1) { - pos= but->pos+strlen(but->str); - if(pos-1 < but->ofs) { - pos= but->ofs-pos+1; - but->ofs -= pos; - if(but->ofs<0) { - but->ofs= 0; - pos--; - } - but->drawstr[ strlen(but->drawstr)-pos ]= 0; - } - } - } - else { - but->drawstr[ strlen(but->drawstr)-1 ]= 0; - but->strwidth= but->aspect*UI_GetStringWidth(but->font, but->drawstr, transopts); - } - - if(but->strwidth < 10) break; - } - } + /* text clipping moved to widget drawing code itself */ } static int ui_auto_themecol(uiBut *but) diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 8061d075e22..84ce8ed5ec0 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -40,6 +40,7 @@ struct uiHandleButtonData; struct wmEvent; struct wmWindow; struct uiFontStyle; +struct uiStyle; /* ****************** general defines ************** */ @@ -362,7 +363,7 @@ void autocomplete_end(struct AutoComplete *autocpl, char *autoname); /* interface_panel.c */ extern int ui_handler_panel_region(struct bContext *C, struct wmEvent *event); -extern void ui_draw_panel(struct ARegion *ar, uiBlock *block, rcti *rect); +extern void ui_draw_panel(struct ARegion *ar, struct uiStyle *style, uiBlock *block, rcti *rect); /* interface_draw.c */ extern void ui_rasterpos_safe(float x, float y, float aspect); @@ -382,13 +383,14 @@ extern void ui_button_active_cancel(const struct bContext *C, uiBut *but); /* interface_widgets.c */ void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3); -void ui_draw_menu_back(uiBlock *block, rcti *rect); -extern void ui_draw_but(ARegion *ar, uiBut *but, rcti *rect); +void ui_draw_menu_back(struct uiStyle *style, uiBlock *block, rcti *rect); +extern void ui_draw_but(ARegion *ar, struct uiStyle *style, uiBut *but, rcti *rect); /* interface_style.c */ void uiStyleInit(void); void uiStyleExit(void); + /* interface_anim.c */ void ui_but_anim_flag(uiBut *but, float cfra); void ui_but_anim_insert_keyframe(struct bContext *C); diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 61ae8c6b139..f2bab0284a2 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -940,7 +940,10 @@ void uiRegionPanelLayout(const bContext *C, ARegion *ar, int vertical, char *con if(pt->draw && (!pt->poll || pt->poll(C))) { block= uiBeginBlock(C, ar, pt->idname, UI_EMBOSS, UI_HELV); - w= (ar->type->minsizex)? ar->type->minsizex-22: UI_PANEL_WIDTH-22; + if(vertical) + w= (ar->type->minsizex)? ar->type->minsizex-12: ar->winx-12; + else + w= (ar->type->minsizex)? ar->type->minsizex-12: UI_PANEL_WIDTH-12; if(uiNewPanel(C, ar, block, pt->name, pt->name, x, y, w, 0)) { panel= uiPanelFromBlock(block); diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index be14c963136..6d7a0eae6af 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -570,7 +570,7 @@ static void ui_draw_panel_header_style(ARegion *ar, uiStyle *style, Panel *panel hrect.ymin= rect->ymax; hrect.xmax= rect->xmax; hrect.ymax= rect->ymax + PNL_HEADER; - uiFontStyleDraw(&style->paneltitle, &hrect, activename); + uiStyleFontDraw(&style->paneltitle, &hrect, activename); return; } @@ -591,16 +591,15 @@ static void ui_draw_panel_header_style(ARegion *ar, uiStyle *style, Panel *panel hrect.ymin= rect->ymax; hrect.xmax= hrect.xmin + width; hrect.ymax= hrect.ymin + PNL_HEADER; - uiFontStyleDraw(&style->paneltitle, &hrect, panelname); + uiStyleFontDraw(&style->paneltitle, &hrect, panelname); a++; } } } -void ui_draw_panel(ARegion *ar, uiBlock *block, rcti *rect) +void ui_draw_panel(ARegion *ar, uiStyle *style, uiBlock *block, rcti *rect) { - uiStyle *style= U.uistyles.first; // XXX pass on Panel *panel= block->panel, *prev; int ofsx; diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 8da44ccd7fb..475f19b0cbd 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -789,14 +789,13 @@ uiBlock *ui_block_func_MENU(bContext *C, uiPopupBlockHandle *handle, void *arg_b if(md->title) { uiBut *bt; - uiSetCurFont(block, block->font+1); + if (md->titleicon) { bt= uiDefIconTextBut(block, LABEL, 0, md->titleicon, md->title, startx, (short)(starty+rows*boxh), (short)width, (short)boxh, NULL, 0.0, 0.0, 0, 0, ""); } else { bt= uiDefBut(block, LABEL, 0, md->title, startx, (short)(starty+rows*boxh), (short)width, (short)boxh, NULL, 0.0, 0.0, 0, 0, ""); bt->flag= UI_TEXT_LEFT; } - uiSetCurFont(block, block->font); } for(a=0; anitems; a++) { @@ -902,9 +901,8 @@ uiBlock *ui_block_func_ICONTEXTROW(bContext *C, uiPopupBlockHandle *handle, void if(md->title) { uiBut *bt; - uiSetCurFont(block, block->font+1); + bt= uiDefBut(block, LABEL, 0, md->title, 0, ypos, (short)width, 19, NULL, 0.0, 0.0, 0, 0, ""); - uiSetCurFont(block, block->font); bt->flag= UI_TEXT_LEFT; } @@ -1421,7 +1419,6 @@ uiBlock *ui_block_func_PUPMENU(bContext *C, uiPopupBlockHandle *handle, void *ar if(md->title) { uiBut *bt; char titlestr[256]; - uiSetCurFont(block, UI_HELVB); if(md->titleicon) { width+= 20; @@ -1432,7 +1429,6 @@ uiBlock *ui_block_func_PUPMENU(bContext *C, uiPopupBlockHandle *handle, void *ar bt= uiDefBut(block, LABEL, 0, md->title, startx, (short)(starty+height), columns*width, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, ""); bt->flag= UI_TEXT_LEFT; } - uiSetCurFont(block, UI_HELV); //uiDefBut(block, SEPR, 0, "", startx, (short)(starty+height)-MENU_SEPR_HEIGHT, width, MENU_SEPR_HEIGHT, NULL, 0.0, 0.0, 0, 0, ""); } @@ -1595,7 +1591,6 @@ uiBlock *ui_block_func_PUPMENUCOL(bContext *C, uiPopupBlockHandle *handle, void /* here we go! */ if(md->title) { uiBut *bt; - uiSetCurFont(block, UI_HELVB); if(md->titleicon) { } @@ -1603,7 +1598,6 @@ uiBlock *ui_block_func_PUPMENUCOL(bContext *C, uiPopupBlockHandle *handle, void bt= uiDefBut(block, LABEL, 0, md->title, startx, (short)(starty+rows*MENU_BUTTON_HEIGHT), columns*width, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, ""); bt->flag= UI_TEXT_LEFT; } - uiSetCurFont(block, UI_HELV); } for(a=0; anitems; a++) { @@ -1782,7 +1776,6 @@ static uiBlock *ui_block_func_MENU_ITEM(bContext *C, uiPopupBlockHandle *handle, /* here we go! */ if(head->name[0]) { char titlestr[256]; - uiSetCurFont(block, UI_HELVB); if(head->icon) { width+= 20; @@ -1793,7 +1786,6 @@ static uiBlock *ui_block_func_MENU_ITEM(bContext *C, uiPopupBlockHandle *handle, but= uiDefBut(block, LABEL, 0, head->name, startx, (short)(starty+height), width, MENU_BUTTON_HEIGHT, NULL, 0.0, 0.0, 0, 0, ""); but->flag= UI_TEXT_LEFT; } - uiSetCurFont(block, UI_HELV); //uiDefBut(block, SEPR, 0, "", startx, (short)(starty+height)-MENU_SEPR_HEIGHT, width, MENU_SEPR_HEIGHT, NULL, 0.0, 0.0, 0, 0, ""); } diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index 4d9ebcf05c2..e66fef2ee59 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -92,17 +92,26 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name) style->paneltitle.uifont_id= UIFONT_DEFAULT; style->paneltitle.points= 14; - style->paneltitle.shadow= 3; + style->paneltitle.shadow= 5; + style->paneltitle.shadx= 2; + style->paneltitle.shady= -2; style->paneltitle.shadowalpha= 0.25f; + style->paneltitle.shadowcolor= 0.0f; style->grouplabel.uifont_id= UIFONT_DEFAULT; style->grouplabel.points= 12; - style->paneltitle.shadow= 3; + style->grouplabel.shadow= 3; + style->grouplabel.shadx= 1; + style->grouplabel.shady= -1; style->grouplabel.shadowalpha= 0.25f; style->widgetlabel.uifont_id= UIFONT_DEFAULT; style->widgetlabel.points= 11; - style->widgetlabel.shadowalpha= 0.25f; + style->widgetlabel.shadow= 3; + style->widgetlabel.shadx= 1; + style->widgetlabel.shady= -1; + style->widgetlabel.shadowalpha= 0.3f; + style->widgetlabel.shadowcolor= 1.0f; style->widget.uifont_id= UIFONT_DEFAULT; style->widget.points= 11; @@ -125,24 +134,85 @@ static uiFont *uifont_to_blfont(int id) /* *************** draw ************************ */ -void uiFontStyleDraw(uiFontStyle *fs, rcti *rect, char *str) + +static void ui_font_shadow5_draw(uiFontStyle *fs, int x, int y, char *str) +{ + float soft[25]= { + 1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f, + 1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f, + 2/60.0f, 5/60.0f, 8/60.0f, 5/60.0f, 2/60.0f, + 1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f, + 1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f}; + + float color[4], *fp= soft; + int dx, dy; + + glGetFloatv(GL_CURRENT_COLOR, color); + + x+= fs->shadx; + y+= fs->shady; + + for(dx=-2; dx<3; dx++) { + for(dy=-2; dy<3; dy++, fp++) { + glColor4f(fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fp[0]*fs->shadowalpha); + BLF_position(x+dx, y+dy, 0.0f); + BLF_draw(str); + } + } + + glColor4fv(color); +} + +static void ui_font_shadow3_draw(uiFontStyle *fs, int x, int y, char *str) +{ + float soft[9]= {1/16.0f, 2/16.0f, 1/16.0f, 2/16.0f, 4/16.0f, 2/16.0f, 1/16.0f, 2/16.0f, 1/16.0f}; + float color[4], *fp= soft; + int dx, dy; + + glGetFloatv(GL_CURRENT_COLOR, color); + + x+= fs->shadx; + y+= fs->shady; + + for(dx=-1; dx<2; dx++) { + for(dy=-1; dy<2; dy++, fp++) { + glColor4f(fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fp[0]*fs->shadowalpha); + BLF_position(x+dx, y+dy, 0.0f); + BLF_draw(str); + } + } + + glColor4fv(color); +} + +void uiStyleFontDraw(uiFontStyle *fs, rcti *rect, char *str) { - uiFont *font= uifont_to_blfont(fs->uifont_id); float height; int xofs=0, yofs; - BLF_set(font->blf_id); - BLF_size(fs->points, U.dpi); + uiStyleFontSet(fs); height= BLF_height("A"); yofs= floor( 0.5f*(rect->ymax - rect->ymin - height)); if(fs->align==UI_STYLE_TEXT_CENTER) xofs= floor( 0.5f*(rect->xmax - rect->xmin - BLF_width(str))); + else if(fs->align==UI_STYLE_TEXT_RIGHT) + xofs= rect->xmax - rect->xmin - BLF_width(str); - BLF_position(rect->xmin+xofs, rect->ymin+yofs, 0.0f); + /* clip is very strict, so we give it some space */ + BLF_clipping(rect->xmin-4, rect->ymin-4, rect->xmax+4, rect->ymax+4); + BLF_enable(BLF_CLIPPING); + + if(fs->shadow==3) + ui_font_shadow3_draw(fs, rect->xmin+xofs, rect->ymin+yofs, str); + else if(fs->shadow==5) + ui_font_shadow5_draw(fs, rect->xmin+xofs, rect->ymin+yofs, str); + BLF_position(rect->xmin+xofs, rect->ymin+yofs, 0.0f); BLF_draw(str); + + BLF_disable(BLF_CLIPPING); } @@ -200,3 +270,12 @@ void uiStyleExit(void) BLI_freelistN(&U.uistyles); } + +void uiStyleFontSet(uiFontStyle *fs) +{ + uiFont *font= uifont_to_blfont(fs->uifont_id); + + BLF_set(font->blf_id); + BLF_size(fs->points, U.dpi); +} + diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 6a206617907..d3512a67eed 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -46,20 +46,16 @@ #include "BIF_gl.h" #include "BIF_glutil.h" +#include "BLF_api.h" + #include "UI_interface.h" #include "UI_interface_icons.h" #include "UI_resources.h" -#include "UI_text.h" #include "UI_view2d.h" #include "ED_util.h" #include "ED_types.h" -#include "BMF_Api.h" -#ifdef INTERNATIONAL -#include "FTF_Api.h" -#endif - #include "interface_intern.h" /* ************** widget base functions ************** */ @@ -134,7 +130,7 @@ typedef struct uiWidgetType { void (*state)(struct uiWidgetType *, int state); void (*draw)(uiWidgetColors *, rcti *, int state, int roundboxalign); void (*custom)(uiBut *, uiWidgetColors *, rcti *, int state, int roundboxalign); - void (*text)(uiStyle *style, uiBut *, rcti *, float *col); + void (*text)(uiFontStyle *, uiBut *, rcti *, float *col); } uiWidgetType; @@ -700,9 +696,42 @@ static void widget_draw_icon(uiBut *but, BIFIconID icon, int blend, rcti *rect) glDisable(GL_BLEND); } +/* sets but->ofs to make sure text is correctly visible */ +static void ui_text_leftclip(uiFontStyle *fstyle, uiBut *but, rcti *rect) +{ + int okwidth= rect->xmax-rect->xmin; + + /* need to set this first */ + uiStyleFontSet(fstyle); + but->strwidth= BLF_width(but->drawstr); + but->ofs= 0; + + while(but->strwidth > okwidth ) { + + but->ofs++; + but->strwidth= BLF_width(but->drawstr+but->ofs); + + /* textbut exception */ + if(but->editstr && but->pos != -1) { + int pos= but->pos+strlen(but->str); + + if(pos-1 < but->ofs) { + pos= but->ofs-pos+1; + but->ofs -= pos; + if(but->ofs<0) { + but->ofs= 0; + pos--; + } + but->drawstr[ strlen(but->drawstr)-pos ]= 0; + } + } + + if(but->strwidth < 10) break; + } +} -static void widget_draw_text(uiStyle *style, uiBut *but, rcti *rect) +static void widget_draw_text(uiFontStyle *fstyle, uiBut *but, rcti *rect) { // int transopts; char *cpoin; @@ -715,31 +744,36 @@ static void widget_draw_text(uiStyle *style, uiBut *but, rcti *rect) cpoin= strchr(but->drawstr, '|'); if(cpoin) *cpoin= 0; - if(but->flag & UI_TEXT_LEFT) - style->widget.align= UI_STYLE_TEXT_LEFT; + if(but->editstr || (but->flag & UI_TEXT_LEFT)) + fstyle->align= UI_STYLE_TEXT_LEFT; else - style->widget.align= UI_STYLE_TEXT_CENTER; + fstyle->align= UI_STYLE_TEXT_CENTER; - // XXX finish cutting - uiFontStyleDraw(&style->widget, rect, but->drawstr+but->ofs); + uiStyleFontDraw(fstyle, rect, but->drawstr+but->ofs); - /* part text right aligned */ + /* part text right aligned */ if(cpoin) { -// int len= UI_GetStringWidth(but->font, cpoin+1, ui_translate_buttons()); -// ui_rasterpos_safe( but->x2 - len*but->aspect-3, y, but->aspect); -// UI_DrawString(but->font, cpoin+1, ui_translate_buttons()); + fstyle->align= UI_STYLE_TEXT_RIGHT; + rect->xmax-=5; + uiStyleFontDraw(fstyle, rect, cpoin+1); *cpoin= '|'; } } /* draws text and icons for buttons */ -static void widget_draw_text_icon(uiStyle *style, uiBut *but, rcti *rect, float *col) +static void widget_draw_text_icon(uiFontStyle *fstyle, uiBut *but, rcti *rect, float *col) { short t, pos, ch; short selsta_tmp, selend_tmp, selsta_draw, selwidth_draw; if(but==NULL) return; + /* cutting off from left part */ + if ELEM3(but->type, NUM, NUMABS, TEX) { + ui_text_leftclip(fstyle, but, rect); + } + else but->ofs= 0; + /* check for button text label */ if (but->type == ICONTEXTROW) { widget_draw_icon(but, (BIFIconID) (but->icon+but->iconadd), 0, rect); @@ -758,7 +792,9 @@ static void widget_draw_text_icon(uiStyle *style, uiBut *but, rcti *rect, float ch= but->drawstr[selsta_tmp]; but->drawstr[selsta_tmp]= 0; - selsta_draw = but->aspect*UI_GetStringWidth(but->font, but->drawstr+but->ofs, ui_translate_buttons()) + 3; + uiStyleFontSet(fstyle); + + selsta_draw = BLF_width(but->drawstr+but->ofs) + 3; but->drawstr[selsta_tmp]= ch; @@ -766,7 +802,7 @@ static void widget_draw_text_icon(uiStyle *style, uiBut *but, rcti *rect, float ch= but->drawstr[selend_tmp]; but->drawstr[selend_tmp]= 0; - selwidth_draw = but->aspect*UI_GetStringWidth(but->font, but->drawstr+but->ofs, ui_translate_buttons()) + 3; + selwidth_draw = BLF_width(but->drawstr+but->ofs) + 3; but->drawstr[selend_tmp]= ch; @@ -781,7 +817,9 @@ static void widget_draw_text_icon(uiStyle *style, uiBut *but, rcti *rect, float ch= but->drawstr[pos]; but->drawstr[pos]= 0; - t= but->aspect*UI_GetStringWidth(but->font, but->drawstr+but->ofs, ui_translate_buttons()) + 3; + uiStyleFontSet(fstyle); + + t= BLF_width(but->drawstr+but->ofs) + 3; but->drawstr[pos]= ch; } @@ -820,7 +858,7 @@ static void widget_draw_text_icon(uiStyle *style, uiBut *but, rcti *rect, float rect->xmin += 5; glColor3fv(col); - widget_draw_text(style, but, rect); + widget_draw_text(fstyle, but, rect); } /* if there's no text label, then check to see if there's an icon only and draw it */ @@ -1487,7 +1525,7 @@ static void widget_optionbut(uiWidgetColors *wcol, rcti *rect, int state, int ro widgetbase_draw(&wtb, wcol); /* text space */ - rect->xmin += (rect->ymax-rect->ymin) + 8; + rect->xmin += (rect->ymax-rect->ymin) + delta; } @@ -1694,37 +1732,16 @@ static int widget_roundbox_set(uiBut *but, rcti *rect) return 15; } -static void ui_fontscale(short *points, float aspect) -{ - if(aspect < 0.9f || aspect > 1.1f) { - float pointsf= *points; - - /* for some reason scaling fonts goes too fast compared to widget size */ - aspect= sqrt(aspect); - pointsf /= aspect; - - if(aspect > 1.0) - *points= ceil(pointsf); - else - *points= floor(pointsf); - } -} - /* conversion from old to new buttons, so still messy */ -void ui_draw_but(ARegion *ar, uiBut *but, rcti *rect) +void ui_draw_but(ARegion *ar, uiStyle *style, uiBut *but, rcti *rect) { - uiStyle style= *((uiStyle *)U.uistyles.first); // XXX pass on as arg uiWidgetType *wt= NULL; - /* scale fonts */ - ui_fontscale(&style.widgetlabel.points, but->block->aspect); - ui_fontscale(&style.widget.points, but->block->aspect); - /* handle menus seperately */ if(but->dt==UI_EMBOSSP) { switch (but->type) { case LABEL: - widget_draw_text_icon(&style, but, rect, wcol_menu_back.text); + widget_draw_text_icon(&style->widgetlabel, but, rect, wcol_menu_back.text); break; case SEPR: break; @@ -1748,9 +1765,9 @@ void ui_draw_but(ARegion *ar, uiBut *but, rcti *rect) switch (but->type) { case LABEL: if(but->block->flag & UI_BLOCK_LOOP) - widget_draw_text_icon(&style, but, rect, wcol_menu_back.text); + widget_draw_text_icon(&style->widgetlabel, but, rect, wcol_menu_back.text); else - widget_draw_text_icon(&style, but, rect, wcol_regular.text); + widget_draw_text_icon(&style->widgetlabel, but, rect, wcol_regular.text); break; case SEPR: break; @@ -1830,14 +1847,14 @@ void ui_draw_but(ARegion *ar, uiBut *but, rcti *rect) wt->custom(but, &wt->wcol, rect, state, roundboxalign); else if(wt->draw) wt->draw(&wt->wcol, rect, state, roundboxalign); - wt->text(&style, but, rect, wt->wcol.text); + wt->text(&style->widget, but, rect, wt->wcol.text); if(state & UI_BUT_DISABLED) widget_disabled(rect); } } -void ui_draw_menu_back(uiBlock *block, rcti *rect) +void ui_draw_menu_back(uiStyle *style, uiBlock *block, rcti *rect) { uiWidgetType *wt= widget_type(UI_WTYPE_MENU_BACK); diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index e2acfe550f9..e85f347f6fc 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -71,7 +71,7 @@ typedef struct uiFontStyle { short shadx, shady; /* shadow offset in pixels */ short align; /* text align hint */ float shadowalpha; /* total alpha */ - float padf; + float shadowcolor; /* 1 value, typically white or black anyway */ } uiFontStyle; -- cgit v1.2.3