diff options
Diffstat (limited to 'source/blender/editors/interface/interface_widgets.c')
-rw-r--r-- | source/blender/editors/interface/interface_widgets.c | 142 |
1 files changed, 56 insertions, 86 deletions
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index fb7b319b720..8190df678e2 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -65,9 +65,9 @@ #define ICON_SIZE_FROM_BUTRECT(rect) (0.8f * BLI_rcti_size_y(rect)) /* ************** widget base functions ************** */ -/* +/** * - in: roundbox codes for corner types and radius - * - return: array of [size][2][x,y] points, the edges of the roundbox, + UV coords + * - return: array of `[size][2][x, y]` points, the edges of the roundbox, + UV coords * * - draw black box with alpha 0 on exact button boundbox * - for every AA step: @@ -100,14 +100,14 @@ typedef struct uiWidgetBase { float inner_v[WIDGET_SIZE_MAX][2]; float inner_uv[WIDGET_SIZE_MAX][2]; - bool inner, outline, emboss, shadedir; + bool draw_inner, draw_outline, draw_emboss, draw_shadedir; uiWidgetTrias tria1; uiWidgetTrias tria2; } uiWidgetBase; -/* uiWidgetType: for time being only for visual appearance, +/** uiWidgetType: for time being only for visual appearance, * later, a handling callback can be added too */ typedef struct uiWidgetType { @@ -237,10 +237,10 @@ static void widget_init(uiWidgetBase *wtb) wtb->tria1.tot = 0; wtb->tria2.tot = 0; - wtb->inner = 1; - wtb->outline = 1; - wtb->emboss = 1; - wtb->shadedir = 1; + wtb->draw_inner = true; + wtb->draw_outline = true; + wtb->draw_emboss = true; + wtb->draw_shadedir = true; } /* helper call, makes shadow rect, with 'sun' above menu, so only shadow to left/right/bottom */ @@ -647,7 +647,7 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol) glEnable(GL_BLEND); /* backdrop non AA */ - if (wtb->inner) { + if (wtb->draw_inner) { if (wcol->shaded == 0) { if (wcol->alpha_check) { float inner_v_half[WIDGET_SIZE_MAX][2]; @@ -713,7 +713,7 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol) glShadeModel(GL_SMOOTH); for (a = 0; a < wtb->totvert; a++, col_pt += 4) { - round_box_shade_col4_r(col_pt, col1, col2, wtb->inner_uv[a][wtb->shadedir]); + round_box_shade_col4_r(col_pt, col1, col2, wtb->inner_uv[a][wtb->draw_shadedir ? 1 : 0]); } glEnableClientState(GL_VERTEX_ARRAY); @@ -729,7 +729,7 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol) } /* for each AA step */ - if (wtb->outline) { + if (wtb->draw_outline) { float triangle_strip[WIDGET_SIZE_MAX * 2 + 2][2]; /* + 2 because the last pair is wrapped */ float triangle_strip_emboss[WIDGET_SIZE_MAX * 2][2]; /* only for emboss */ @@ -740,7 +740,7 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol) widget_verts_to_triangle_strip(wtb, wtb->totvert, triangle_strip); - if (wtb->emboss) { + if (wtb->draw_emboss) { widget_verts_to_triangle_strip_open(wtb, wtb->halfwayvert, triangle_strip_emboss); } @@ -758,7 +758,7 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol) glDrawArrays(GL_TRIANGLE_STRIP, 0, wtb->totvert * 2 + 2); /* emboss bottom shadow */ - if (wtb->emboss) { + if (wtb->draw_emboss) { UI_GetThemeColor4ubv(TH_WIDGET_EMBOSS, emboss); if (emboss[3]) { @@ -929,7 +929,8 @@ static void ui_text_clip_give_next_off(uiBut *but, const char *str) but->ofs += bytes; } -/* Helper. +/** + * Helper. * This func assumes things like kerning handling have already been handled! * Return the length of modified (right-clipped + ellipsis) string. */ @@ -969,7 +970,7 @@ static void ui_text_clip_right_ex( */ float UI_text_clip_middle_ex( uiFontStyle *fstyle, char *str, float okwidth, const float minwidth, - const size_t max_len, const char *rpart_sep) + const size_t max_len, const char rpart_sep) { float strwidth; @@ -1002,7 +1003,7 @@ float UI_text_clip_middle_ex( size_t final_lpart_len; if (rpart_sep) { - rpart = strstr(str, rpart_sep); + rpart = strrchr(str, rpart_sep); if (rpart) { rpart_len = strlen(rpart); @@ -1084,14 +1085,14 @@ static void ui_text_clip_middle(uiFontStyle *fstyle, uiBut *but, const rcti *rec const float minwidth = (float)(UI_DPI_ICON_SIZE) / but->block->aspect * 2.0f; but->ofs = 0; - but->strwidth = UI_text_clip_middle_ex(fstyle, but->drawstr, okwidth, minwidth, max_len, NULL); + but->strwidth = UI_text_clip_middle_ex(fstyle, but->drawstr, okwidth, minwidth, max_len, '\0'); } /** * Like ui_text_clip_middle(), but protect/preserve at all cost the right part of the string after sep. * Useful for strings with shortcuts (like 'AVeryLongFooBarLabelForMenuEntry|Ctrl O' -> 'AVeryLong...MenuEntry|Ctrl O'). */ -static void ui_text_clip_middle_protect_right(uiFontStyle *fstyle, uiBut *but, const rcti *rect, const char *rsep) +static void ui_text_clip_middle_protect_right(uiFontStyle *fstyle, uiBut *but, const rcti *rect, const char rsep) { /* No margin for labels! */ const int border = ELEM(but->type, UI_BTYPE_LABEL, UI_BTYPE_MENU) ? 0 : (int)(UI_TEXT_CLIP_MARGIN + 0.5f); @@ -1525,17 +1526,14 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB /* Big previews with optional text label below */ if (but->flag & UI_BUT_ICON_PREVIEW && ui_block_is_menu(but->block)) { const BIFIconID icon = (but->flag & UI_HAS_ICON) ? but->icon + but->iconadd : ICON_NONE; - const int icon_size_i = BLI_rcti_size_y(rect); - float icon_size, text_size; + int icon_size = BLI_rcti_size_y(rect); + int text_size = 0; /* This is a bit britle, but avoids adding an 'UI_BUT_HAS_LABEL' flag to but... */ - if (icon_size_i > BLI_rcti_size_x(rect)) { - icon_size = 0.8f * (float)icon_size_i; - text_size = 0.2f * (float)icon_size_i; - } - else { - icon_size = (float)icon_size_i; - text_size = 0.0f; + if (icon_size > BLI_rcti_size_x(rect)) { + /* button is not square, it has extra height for label */ + text_size = UI_UNIT_Y; + icon_size -= text_size; } /* draw icon in rect above the space reserved for the label */ @@ -1544,9 +1542,12 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB widget_draw_preview(icon, alpha, rect); glDisable(GL_BLEND); - /* offset rect to draw label in*/ + /* offset rect to draw label in */ rect->ymin -= text_size; rect->ymax -= icon_size; + + /* vertically centering text */ + rect->ymin += UI_UNIT_Y / 2; } /* Icons on the left with optional text label on the right */ else if (but->flag & UI_HAS_ICON || show_menu_icon) { @@ -1607,9 +1608,9 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB else if (ELEM(but->type, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER)) { ui_text_clip_right_label(fstyle, but, rect); } - else if ((but->block->flag & UI_BLOCK_LOOP) && (but->type == UI_BTYPE_BUT)) { + else if (but->flag & UI_BUT_HAS_SEP_CHAR) { /* Clip middle, but protect in all case right part containing the shortcut, if any. */ - ui_text_clip_middle_protect_right(fstyle, but, rect, "|"); + ui_text_clip_middle_protect_right(fstyle, but, rect, UI_SEP_CHAR); } else { ui_text_clip_middle(fstyle, but, rect); @@ -1626,17 +1627,6 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB /* *********************** widget types ************************************* */ - -/* uiWidgetStateColors - * char inner_anim[4]; - * char inner_anim_sel[4]; - * char inner_key[4]; - * char inner_key_sel[4]; - * char inner_driven[4]; - * char inner_driven_sel[4]; - * float blend; - */ - static struct uiWidgetStateColors wcol_state_colors = { {115, 190, 76, 255}, {90, 166, 51, 255}, @@ -1647,18 +1637,6 @@ static struct uiWidgetStateColors wcol_state_colors = { 0.5f, 0.0f }; -/* uiWidgetColors - * char outline[3]; - * char inner[4]; - * char inner_sel[4]; - * char item[3]; - * char text[3]; - * char text_sel[3]; - * - * short shaded; - * float shadetop, shadedown; - */ - static struct uiWidgetColors wcol_num = { {25, 25, 25, 255}, {180, 180, 180, 255}, @@ -2224,7 +2202,7 @@ static void widget_menu_back(uiWidgetColors *wcol, rcti *rect, int flag, int dir widget_softshadow(rect, roundboxalign, 0.25f * U.widget_unit); round_box_edges(&wtb, roundboxalign, rect, 0.25f * U.widget_unit); - wtb.emboss = 0; + wtb.draw_emboss = false; widgetbase_draw(&wtb, wcol); glDisable(GL_BLEND); @@ -2762,7 +2740,7 @@ void UI_draw_widget_scroll(uiWidgetColors *wcol, const rcti *rect, const rcti *s else rad = 0.5f * BLI_rcti_size_x(rect); - wtb.shadedir = (horizontal) ? 1 : 0; + wtb.draw_shadedir = (horizontal) ? true : false; /* draw back part, colors swapped and shading inverted */ if (horizontal) @@ -2791,11 +2769,11 @@ void UI_draw_widget_scroll(uiWidgetColors *wcol, const rcti *rect, const rcti *s } /* draw */ - wtb.emboss = 0; /* only emboss once */ + wtb.draw_emboss = false; /* only emboss once */ /* exception for progress bar */ if (state & UI_SCROLL_NO_OUTLINE) { - SWAP(bool, outline, wtb.outline); + SWAP(bool, outline, wtb.draw_outline); } round_box_edges(&wtb, UI_CNR_ALL, slider, rad); @@ -2818,7 +2796,7 @@ void UI_draw_widget_scroll(uiWidgetColors *wcol, const rcti *rect, const rcti *s widgetbase_draw(&wtb, wcol); if (state & UI_SCROLL_NO_OUTLINE) { - SWAP(bool, outline, wtb.outline); + SWAP(bool, outline, wtb.draw_outline); } } } @@ -2945,7 +2923,7 @@ static void widget_numslider(uiBut *but, uiWidgetColors *wcol, rcti *rect, int s toffs = offs * 0.75f; round_box_edges(&wtb, roundboxalign, rect, offs); - wtb.outline = 0; + wtb.draw_outline = false; widgetbase_draw(&wtb, wcol); /* draw left/right parts only when not in text editing */ @@ -2970,7 +2948,7 @@ static void widget_numslider(uiBut *but, uiWidgetColors *wcol, rcti *rect, int s /* left part of slider, always rounded */ rect1.xmax = rect1.xmin + ceil(offs + U.pixelsize); round_box_edges(&wtb1, roundboxalign & ~(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT), &rect1, offs); - wtb1.outline = 0; + wtb1.draw_outline = false; widgetbase_draw(&wtb1, wcol); /* right part of slider, interpolate roundness */ @@ -2995,8 +2973,8 @@ static void widget_numslider(uiBut *but, uiWidgetColors *wcol, rcti *rect, int s } /* outline */ - wtb.outline = 1; - wtb.inner = 0; + wtb.draw_outline = true; + wtb.draw_inner = false; widgetbase_draw(&wtb, wcol); /* add space at either side of the button so text aligns with numbuttons (which have arrow icons) */ @@ -3088,7 +3066,7 @@ static void widget_icon_has_anim(uiBut *but, uiWidgetColors *wcol, rcti *rect, i float rad; widget_init(&wtb); - wtb.outline = 0; + wtb.draw_outline = false; /* rounded */ rad = 0.5f * BLI_rcti_size_y(rect); @@ -3203,7 +3181,7 @@ static void widget_menu_itembut(uiWidgetColors *wcol, rcti *rect, int UNUSED(sta widget_init(&wtb); /* not rounded, no outline */ - wtb.outline = 0; + wtb.draw_outline = false; round_box_edges(&wtb, 0, rect, 0.0f); widgetbase_draw(&wtb, wcol); @@ -3217,7 +3195,7 @@ static void widget_menu_radial_itembut(uiBut *but, uiWidgetColors *wcol, rcti *r widget_init(&wtb); - wtb.emboss = 0; + wtb.draw_emboss = false; rad = 0.5f * BLI_rcti_size_y(rect); round_box_edges(&wtb, UI_CNR_ALL, rect, rad); @@ -3240,7 +3218,7 @@ static void widget_list_itembut(uiWidgetColors *wcol, rcti *rect, int UNUSED(sta widget_init(&wtb); /* rounded, but no outline */ - wtb.outline = 0; + wtb.draw_outline = false; rad = 0.2f * U.widget_unit; round_box_edges(&wtb, UI_CNR_ALL, rect, rad); @@ -3393,8 +3371,8 @@ static void widget_draw_extra_mask(const bContext *C, uiBut *but, uiWidgetType * /* outline */ round_box_edges(&wtb, UI_CNR_ALL, rect, rad); - wtb.outline = 1; - wtb.inner = 0; + wtb.draw_outline = true; + wtb.draw_inner = false; widgetbase_draw(&wtb, &wt->wcol); } @@ -4099,7 +4077,7 @@ void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, const char *name, int ic const float minwidth = (float)(UI_DPI_ICON_SIZE); BLI_strncpy(drawstr, name, sizeof(drawstr)); - UI_text_clip_middle_ex(fstyle, drawstr, okwidth, minwidth, max_len, NULL); + UI_text_clip_middle_ex(fstyle, drawstr, okwidth, minwidth, max_len, '\0'); glColor4ubv((unsigned char *)wt->wcol.text); UI_fontstyle_draw(fstyle, rect, drawstr); @@ -4134,39 +4112,31 @@ void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, const char *name, int ic void ui_draw_preview_item(uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state) { - rcti trect = *rect, bg_rect; + rcti trect = *rect; + const float text_size = UI_UNIT_Y; float font_dims[2] = {0.0f, 0.0f}; uiWidgetType *wt = widget_type(UI_WTYPE_MENU_ITEM); + /* drawing button background */ wt->state(wt, state); wt->draw(&wt->wcol, rect, 0, 0); + /* draw icon in rect above the space reserved for the label */ + rect->ymin += text_size; glEnable(GL_BLEND); widget_draw_preview(iconid, 1.0f, rect); + glDisable(GL_BLEND); BLF_width_and_height(fstyle->uifont_id, name, BLF_DRAW_STR_DUMMY_MAX, &font_dims[0], &font_dims[1]); /* text rect */ trect.xmin += 0; - trect.xmax = trect.xmin + font_dims[0] + 10; - trect.ymin += 10; + trect.xmax = trect.xmin + font_dims[0] + U.widget_unit / 2; + trect.ymin += U.widget_unit / 2; trect.ymax = trect.ymin + font_dims[1]; if (trect.xmax > rect->xmax - PREVIEW_PAD) trect.xmax = rect->xmax - PREVIEW_PAD; - bg_rect = trect; - bg_rect.xmin = rect->xmin + PREVIEW_PAD; - bg_rect.ymin = rect->ymin + PREVIEW_PAD; - bg_rect.xmax = rect->xmax - PREVIEW_PAD; - bg_rect.ymax += PREVIEW_PAD / 2; - - if (bg_rect.xmax > rect->xmax - PREVIEW_PAD) - bg_rect.xmax = rect->xmax - PREVIEW_PAD; - - glColor4ubv((unsigned char *)wt->wcol_theme->inner_sel); - glRecti(bg_rect.xmin, bg_rect.ymin, bg_rect.xmax, bg_rect.ymax); - glDisable(GL_BLEND); - { char drawstr[UI_MAX_DRAW_STR]; const float okwidth = (float)BLI_rcti_size_x(&trect); @@ -4174,7 +4144,7 @@ void ui_draw_preview_item(uiFontStyle *fstyle, rcti *rect, const char *name, int const float minwidth = (float)(UI_DPI_ICON_SIZE); BLI_strncpy(drawstr, name, sizeof(drawstr)); - UI_text_clip_middle_ex(fstyle, drawstr, okwidth, minwidth, max_len, NULL); + UI_text_clip_middle_ex(fstyle, drawstr, okwidth, minwidth, max_len, '\0'); glColor4ubv((unsigned char *)wt->wcol.text); UI_fontstyle_draw(fstyle, &trect, drawstr); |