diff options
Diffstat (limited to 'source/blender/editors/interface/interface_widgets.c')
-rw-r--r-- | source/blender/editors/interface/interface_widgets.c | 187 |
1 files changed, 96 insertions, 91 deletions
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 97dd4f59ff6..9826f07e464 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -118,7 +118,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)(uiFontStyle *, uiWidgetColors *, uiBut *, rcti *); + void (*text)(uiFontStyle *, uiWidgetColors *, uiBut *, rcti *); } uiWidgetType; @@ -606,7 +606,7 @@ static void widget_check_trias(uiWidgetTrias *tria, const rcti *rect) /* prepares shade colors */ -static void shadecolors4(char coltop[4], char *coldown, const char *color, short shadetop, short shadedown) +static void shadecolors4(char coltop[4], char coldown[4], const char *color, short shadetop, short shadedown) { coltop[0] = CLAMPIS(color[0] + shadetop, 0, 255); @@ -682,17 +682,14 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol) glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v); glDrawArrays(GL_POLYGON, 0, wtb->totvert); - glDisableClientState(GL_VERTEX_ARRAY); /* light checkers */ glEnable(GL_POLYGON_STIPPLE); glColor4ub(UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, 255); glPolygonStipple(checker_stipple_sml); - glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v); glDrawArrays(GL_POLYGON, 0, wtb->totvert); - glDisableClientState(GL_VERTEX_ARRAY); glDisable(GL_POLYGON_STIPPLE); @@ -700,7 +697,6 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4ubv((unsigned char *)wcol->inner); - glEnableClientState(GL_VERTEX_ARRAY); for (a = 0; a < wtb->totvert; a++) { x_mid += wtb->inner_v[a][0]; @@ -709,7 +705,6 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol) glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v); glDrawArrays(GL_POLYGON, 0, wtb->totvert); - glDisableClientState(GL_VERTEX_ARRAY); /* 1/2 solid color */ glColor4ub(wcol->inner[0], wcol->inner[1], wcol->inner[2], 255); @@ -719,7 +714,6 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol) inner_v_half[a][1] = wtb->inner_v[a][1]; } - glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_FLOAT, 0, inner_v_half); glDrawArrays(GL_POLYGON, 0, wtb->totvert); glDisableClientState(GL_VERTEX_ARRAY); @@ -882,7 +876,7 @@ static void widget_draw_icon(uiBut *but, BIFIconID icon, float alpha, const rcti } /* extra feature allows more alpha blending */ - if (ELEM(but->type, LABEL, LISTLABEL) && but->a1 == 1.0f) + if ((but->type == LABEL) && but->a1 == 1.0f) alpha *= but->a2; glEnable(GL_BLEND); @@ -890,7 +884,7 @@ static void widget_draw_icon(uiBut *but, BIFIconID icon, float alpha, const rcti if (icon && icon != ICON_BLANK1) { float ofs = 1.0f / aspect; - if (but->flag & UI_ICON_LEFT) { + if (but->drawflag & UI_BUT_ICON_LEFT) { if (but->block->flag & UI_BLOCK_LOOP) { if (ELEM(but->type, SEARCH_MENU, SEARCH_MENU_UNLINK)) xs = rect->xmin + 4.0f * ofs; @@ -956,7 +950,7 @@ static void ui_text_clip_give_next_off(uiBut *but) */ static void ui_text_clip_left(uiFontStyle *fstyle, uiBut *but, const rcti *rect) { - int border = (but->flag & UI_BUT_ALIGN_RIGHT) ? 8 : 10; + int border = (but->drawflag & UI_BUT_ALIGN_RIGHT) ? 8 : 10; int okwidth = BLI_rcti_size_x(rect) - border; if (but->flag & UI_HAS_ICON) @@ -973,11 +967,11 @@ static void ui_text_clip_left(uiFontStyle *fstyle, uiBut *but, const rcti *rect) BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); but->ofs = 0; - but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr); + but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr, sizeof(but->drawstr)); while (but->strwidth > okwidth) { ui_text_clip_give_next_off(but); - but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs); + but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs); if (but->strwidth < 10) break; } @@ -991,7 +985,7 @@ static void ui_text_clip_left(uiFontStyle *fstyle, uiBut *but, const rcti *rect) */ static void ui_text_clip_cursor(uiFontStyle *fstyle, uiBut *but, const rcti *rect) { - int border = (but->flag & UI_BUT_ALIGN_RIGHT) ? 8 : 10; + int border = (but->drawflag & UI_BUT_ALIGN_RIGHT) ? 8 : 10; int okwidth = max_ii(BLI_rcti_size_x(rect) - border, 0); if (but->flag & UI_HAS_ICON) okwidth -= UI_DPI_ICON_SIZE; @@ -1007,20 +1001,16 @@ static void ui_text_clip_cursor(uiFontStyle *fstyle, uiBut *but, const rcti *rec if (but->ofs > but->pos) but->ofs = but->pos; - if (BLF_width(fstyle->uifont_id, but->drawstr) <= okwidth) + if (BLF_width(fstyle->uifont_id, but->drawstr, sizeof(but->drawstr)) <= okwidth) but->ofs = 0; - but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs); + but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs); while (but->strwidth > okwidth) { float width; - char buf[UI_MAX_DRAW_STR]; - /* copy draw string */ - BLI_strncpy_utf8(buf, but->drawstr, sizeof(buf)); /* string position of cursor */ - buf[but->pos] = 0; - width = BLF_width(fstyle->uifont_id, buf + but->ofs); + width = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, but->pos - but->ofs); /* if cursor is at 20 pixels of right side button we clip left */ if (width > okwidth - 20) { @@ -1038,7 +1028,7 @@ static void ui_text_clip_cursor(uiFontStyle *fstyle, uiBut *but, const rcti *rec but->drawstr[len - bytes] = 0; } - but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs); + but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs); if (but->strwidth < 10) break; } @@ -1055,7 +1045,7 @@ static void ui_text_clip_cursor(uiFontStyle *fstyle, uiBut *but, const rcti *rec */ static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti *rect) { - int border = (but->flag & UI_BUT_ALIGN_RIGHT) ? 8 : 10; + int border = (but->drawflag & UI_BUT_ALIGN_RIGHT) ? 8 : 10; int okwidth = max_ii(BLI_rcti_size_x(rect) - border, 0); char *cpoin = NULL; int drawstr_len = strlen(but->drawstr); @@ -1067,7 +1057,7 @@ static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti if (fstyle->kerning == 1) /* for BLF_width */ BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); - but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr); + but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr, sizeof(but->drawstr)); but->ofs = 0; @@ -1095,7 +1085,7 @@ static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti drawstr_len -= bytes; // BLI_assert(strlen(but->drawstr) == drawstr_len); - but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs); + but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs); if (but->strwidth < 10) break; } @@ -1103,7 +1093,7 @@ static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti /* after the leading text is gone, chop off the : and following space, with ofs */ while ((but->strwidth > okwidth) && (but->ofs < 2)) { ui_text_clip_give_next_off(but); - but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs); + but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs); if (but->strwidth < 10) break; } @@ -1121,7 +1111,7 @@ static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti but->drawstr[drawstr_len] = 0; // BLI_assert(strlen(but->drawstr) == drawstr_len); - but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs); + but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs); if (but->strwidth < 10) break; } @@ -1132,17 +1122,18 @@ static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect) { - //int transopts; // UNUSED - char *cpoin = NULL; + int drawstr_left_len = UI_MAX_DRAW_STR; + char *drawstr_right = NULL; + bool use_right_only = false; /* for underline drawing */ float font_xofs, font_yofs; uiStyleFontSet(fstyle); - if (but->editstr || (but->flag & UI_TEXT_LEFT)) + if (but->editstr || (but->drawflag & UI_BUT_TEXT_LEFT)) fstyle->align = UI_STYLE_TEXT_LEFT; - else if (but->flag & UI_TEXT_RIGHT) + else if (but->drawflag & UI_BUT_TEXT_RIGHT) fstyle->align = UI_STYLE_TEXT_RIGHT; else fstyle->align = UI_STYLE_TEXT_CENTER; @@ -1152,7 +1143,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b /* text button selection and cursor */ if (but->editstr && but->pos != -1) { - short t = 0, pos = 0, ch; + short t = 0, pos = 0; short selsta_tmp, selend_tmp, selsta_draw, selwidth_draw; if ((but->selend - but->selsta) > 0) { @@ -1163,23 +1154,13 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b if (but->drawstr[0] != 0) { if (but->selsta >= but->ofs) { - ch = but->drawstr[selsta_tmp]; - but->drawstr[selsta_tmp] = 0; - - selsta_draw = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs); - - but->drawstr[selsta_tmp] = ch; + selsta_draw = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, selsta_tmp - but->ofs); } else { selsta_draw = 0; } - - ch = but->drawstr[selend_tmp]; - but->drawstr[selend_tmp] = 0; - - selwidth_draw = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs); - - but->drawstr[selend_tmp] = ch; + + selwidth_draw = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, selend_tmp - but->ofs); glColor4ubv((unsigned char *)wcol->item); glRects(rect->xmin + selsta_draw, rect->ymin + 2, rect->xmin + selwidth_draw, rect->ymax - 2); @@ -1190,12 +1171,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b pos = but->pos; if (pos >= but->ofs) { if (but->drawstr[0] != 0) { - ch = but->drawstr[pos]; - but->drawstr[pos] = 0; - - t = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs) / but->aspect; - - but->drawstr[pos] = ch; + t = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, pos - but->ofs) / but->aspect; } glColor3f(0.20, 0.6, 0.9); @@ -1215,20 +1191,45 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b /* cut string in 2 parts - only for menu entries */ if ((but->block->flag & UI_BLOCK_LOOP)) { if (ELEM3(but->type, NUM, TEX, NUMSLI) == 0) { - cpoin = strchr(but->drawstr, UI_SEP_CHAR); - if (cpoin) *cpoin = 0; + drawstr_right = strchr(but->drawstr, UI_SEP_CHAR); + if (drawstr_right) { + drawstr_left_len = (drawstr_right - but->drawstr); + drawstr_right++; + } } } +#ifdef USE_NUMBUTS_LR_ALIGN + if (!drawstr_right && ELEM(but->type, NUM, NUMSLI) && (but->editstr == NULL)) { + drawstr_right = strchr(but->drawstr + but->ofs, ':'); + if (drawstr_right) { + drawstr_right++; + drawstr_left_len = (drawstr_right - but->drawstr); + + while (*drawstr_right == ' ') { + drawstr_right++; + } + } + else { + /* no prefix, even so use only cpoin */ + drawstr_right = but->drawstr + but->ofs; + use_right_only = true; + } + } +#endif + glColor4ubv((unsigned char *)wcol->text); - uiStyleFontDrawExt(fstyle, rect, but->drawstr + but->ofs, &font_xofs, &font_yofs); + if (!use_right_only) { + uiStyleFontDrawExt(fstyle, rect, but->drawstr + but->ofs, + drawstr_left_len - but->ofs, &font_xofs, &font_yofs); + } if (but->menu_key != '\0') { char fixedbuf[128]; char *str; - BLI_strncpy(fixedbuf, but->drawstr + but->ofs, sizeof(fixedbuf)); + BLI_strncpy(fixedbuf, but->drawstr + but->ofs, min_ii(sizeof(fixedbuf), drawstr_left_len)); str = strchr(fixedbuf, but->menu_key - 32); /* upper case */ if (str == NULL) @@ -1245,7 +1246,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b } fixedbuf[ul_index] = '\0'; - ul_advance = BLF_width(fstyle->uifont_id, fixedbuf); + ul_advance = BLF_width(fstyle->uifont_id, fixedbuf, ul_index); BLF_position(fstyle->uifont_id, rect->xmin + font_xofs + ul_advance, rect->ymin + font_yofs, 0.0f); BLF_draw(fstyle->uifont_id, "_", 2); @@ -1257,11 +1258,10 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b } /* part text right aligned */ - if (cpoin) { + if (drawstr_right) { fstyle->align = UI_STYLE_TEXT_RIGHT; rect->xmax -= ui_but_draw_menu_icon(but) ? UI_DPI_ICON_SIZE : 0.25f * U.widget_unit; - uiStyleFontDraw(fstyle, rect, cpoin + 1); - *cpoin = UI_SEP_CHAR; + uiStyleFontDraw(fstyle, rect, drawstr_right); } } @@ -1310,17 +1310,17 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB /* icons default draw 0.8f x height */ rect->xmin += (int)(0.8f * BLI_rcti_size_y(rect)); - if (but->editstr || (but->flag & UI_TEXT_LEFT)) { + if (but->editstr || (but->drawflag & UI_BUT_TEXT_LEFT)) { rect->xmin += (UI_TEXT_MARGIN_X * U.widget_unit) / but->block->aspect; } - else if ((but->flag & UI_TEXT_RIGHT)) { + else if ((but->drawflag & UI_BUT_TEXT_RIGHT)) { rect->xmax -= (UI_TEXT_MARGIN_X * U.widget_unit) / but->block->aspect; } } - else if ((but->flag & UI_TEXT_LEFT)) { + else if ((but->drawflag & UI_BUT_TEXT_LEFT)) { rect->xmin += (UI_TEXT_MARGIN_X * U.widget_unit) / but->block->aspect; } - else if ((but->flag & UI_TEXT_RIGHT)) { + else if ((but->drawflag & UI_BUT_TEXT_RIGHT)) { rect->xmax -= (UI_TEXT_MARGIN_X * U.widget_unit) / but->block->aspect; } @@ -1656,8 +1656,14 @@ static void widget_state(uiWidgetType *wt, int state) { uiWidgetStateColors *wcol_state = wt->wcol_state; + if ((state & UI_BUT_LIST_ITEM) && !(state & UI_TEXTINPUT)) { + /* Override default widget's colors. */ + bTheme *btheme = UI_GetTheme(); + wt->wcol_theme = &btheme->tui.wcol_list_item; + } + wt->wcol = *(wt->wcol_theme); - + if (state & UI_SELECT) { copy_v4_v4_char(wt->wcol.inner, wt->wcol.inner_sel); @@ -2289,7 +2295,7 @@ static void widget_numbut_draw(uiWidgetColors *wcol, rcti *rect, int state, int { uiWidgetBase wtb; const float rad = 0.5f * BLI_rcti_size_y(rect); - float textofs = rad * 0.75f; + float textofs = rad * 0.85f; if (state & UI_SELECT) SWAP(short, wcol->shadetop, wcol->shadedown); @@ -2318,9 +2324,9 @@ static void widget_numbut(uiWidgetColors *wcol, rcti *rect, int state, int round widget_numbut_draw(wcol, rect, state, roundboxalign, false); } -/* +/** * Draw number buttons still with triangles when field is not embossed -*/ + */ static void widget_numbut_embossn(uiBut *UNUSED(but), uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign) { widget_numbut_draw(wcol, rect, state, roundboxalign, true); @@ -2335,7 +2341,7 @@ int ui_link_bezier_points(const rcti *rect, float coord_array[][2], int resol) vec[3][0] = rect->xmax; vec[3][1] = rect->ymax; - dist = 0.5f * ABS(vec[0][0] - vec[3][0]); + dist = 0.5f * fabsf(vec[0][0] - vec[3][0]); vec[1][0] = vec[0][0] + dist; vec[1][1] = vec[0][1]; @@ -2866,12 +2872,21 @@ static void widget_optionbut(uiWidgetColors *wcol, rcti *rect, int state, int UN /* labels use Editor theme colors for text */ static void widget_state_label(uiWidgetType *wt, int state) { - /* call this for option button */ - widget_state(wt, state); - if (state & UI_SELECT) - UI_GetThemeColor3ubv(TH_TEXT_HI, (unsigned char *)wt->wcol.text); - else - UI_GetThemeColor3ubv(TH_TEXT, (unsigned char *)wt->wcol.text); + if (state & UI_BUT_LIST_ITEM) { + /* Override default label theme's colors. */ + bTheme *btheme = UI_GetTheme(); + wt->wcol_theme = &btheme->tui.wcol_list_item; + /* call this for option button */ + widget_state(wt, state); + } + else { + /* call this for option button */ + widget_state(wt, state); + if (state & UI_SELECT) + UI_GetThemeColor3ubv(TH_TEXT_HI, (unsigned char *)wt->wcol.text); + else + UI_GetThemeColor3ubv(TH_TEXT, (unsigned char *)wt->wcol.text); + } } static void widget_radiobut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign) @@ -2991,11 +3006,6 @@ static uiWidgetType *widget_type(uiWidgetTypeEnum type) case UI_WTYPE_REGULAR: break; - case UI_WTYPE_LISTLABEL: - wt.wcol_theme = &btheme->tui.wcol_list_item; - wt.draw = NULL; - /* Can't use usual label code. */ - break; case UI_WTYPE_LABEL: wt.draw = NULL; wt.state = widget_state_label; @@ -3139,15 +3149,15 @@ static int widget_roundbox_set(uiBut *but, rcti *rect) int roundbox = UI_CNR_ALL; /* alignment */ - if ((but->flag & UI_BUT_ALIGN) && but->type != PULLDOWN) { + if ((but->drawflag & UI_BUT_ALIGN) && but->type != PULLDOWN) { /* ui_block_position has this correction too, keep in sync */ - if (but->flag & UI_BUT_ALIGN_TOP) + if (but->drawflag & UI_BUT_ALIGN_TOP) rect->ymax += U.pixelsize; - if (but->flag & UI_BUT_ALIGN_LEFT) + if (but->drawflag & UI_BUT_ALIGN_LEFT) rect->xmin -= U.pixelsize; - switch (but->flag & UI_BUT_ALIGN) { + switch (but->drawflag & UI_BUT_ALIGN) { case UI_BUT_ALIGN_TOP: roundbox = UI_CNR_BOTTOM_LEFT | UI_CNR_BOTTOM_RIGHT; break; @@ -3245,11 +3255,6 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct fstyle = &style->widgetlabel; } break; - - case LISTLABEL: - wt = widget_type(UI_WTYPE_LISTLABEL); - fstyle = &style->widgetlabel; - break; case SEPR: break; @@ -3295,7 +3300,7 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct case OPTIONN: if (!(but->flag & UI_HAS_ICON)) { wt = widget_type(UI_WTYPE_OPTION); - but->flag |= UI_TEXT_LEFT; + but->drawflag |= UI_BUT_TEXT_LEFT; } else wt = widget_type(UI_WTYPE_TOGGLE); @@ -3529,7 +3534,7 @@ void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, const char *name, int ic cpoin = strchr(name, UI_SEP_CHAR); if (cpoin) { *cpoin = 0; - rect->xmax -= BLF_width(fstyle->uifont_id, cpoin + 1) + 10; + rect->xmax -= BLF_width(fstyle->uifont_id, cpoin + 1, INT_MAX) + 10; } } @@ -3575,7 +3580,7 @@ void ui_draw_preview_item(uiFontStyle *fstyle, rcti *rect, const char *name, int widget_draw_preview(iconid, 1.0f, rect); - BLF_width_and_height(fstyle->uifont_id, name, &font_dims[0], &font_dims[1]); + BLF_width_and_height(fstyle->uifont_id, name, BLF_DRAW_STR_DUMMY_MAX, &font_dims[0], &font_dims[1]); /* text rect */ trect.xmin += 0; |