Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_widgets.c
| Show First 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | typedef enum { | ||||
| UI_WTYPE_PULLDOWN, | UI_WTYPE_PULLDOWN, | ||||
| UI_WTYPE_MENU_ITEM, | UI_WTYPE_MENU_ITEM, | ||||
| UI_WTYPE_MENU_ITEM_RADIAL, | UI_WTYPE_MENU_ITEM_RADIAL, | ||||
| UI_WTYPE_MENU_BACK, | UI_WTYPE_MENU_BACK, | ||||
| /* specials */ | /* specials */ | ||||
| UI_WTYPE_ICON, | UI_WTYPE_ICON, | ||||
| UI_WTYPE_ICON_LABEL, | UI_WTYPE_ICON_LABEL, | ||||
| UI_WTYPE_PREVIEW_TILE, | |||||
| UI_WTYPE_SWATCH, | UI_WTYPE_SWATCH, | ||||
| UI_WTYPE_RGB_PICKER, | UI_WTYPE_RGB_PICKER, | ||||
| UI_WTYPE_UNITVEC, | UI_WTYPE_UNITVEC, | ||||
| UI_WTYPE_BOX, | UI_WTYPE_BOX, | ||||
| UI_WTYPE_SCROLL, | UI_WTYPE_SCROLL, | ||||
| UI_WTYPE_LISTITEM, | UI_WTYPE_LISTITEM, | ||||
| UI_WTYPE_PROGRESSBAR, | UI_WTYPE_PROGRESSBAR, | ||||
| UI_WTYPE_NODESOCKET, | UI_WTYPE_NODESOCKET, | ||||
| ▲ Show 20 Lines • Show All 2,994 Lines • ▼ Show 20 Lines | case UI_GRAD_S: | ||||
| break; | break; | ||||
| case UI_GRAD_V: | case UI_GRAD_V: | ||||
| hsv_to_rgb(1.0, 1.0, 0.0, &col1[2][0], &col1[2][1], &col1[2][2]); | hsv_to_rgb(1.0, 1.0, 0.0, &col1[2][0], &col1[2][1], &col1[2][2]); | ||||
| copy_v3_v3(col1[0], col1[2]); | copy_v3_v3(col1[0], col1[2]); | ||||
| copy_v3_v3(col1[1], col1[2]); | copy_v3_v3(col1[1], col1[2]); | ||||
| copy_v3_v3(col1[3], col1[2]); | copy_v3_v3(col1[3], col1[2]); | ||||
| break; | break; | ||||
| default: | default: | ||||
| BLI_assert(!"invalid 'type' argument"); | BLI_assert_msg(0, "invalid 'type' argument"); | ||||
| hsv_to_rgb(1.0, 1.0, 1.0, &col1[2][0], &col1[2][1], &col1[2][2]); | hsv_to_rgb(1.0, 1.0, 1.0, &col1[2][0], &col1[2][1], &col1[2][2]); | ||||
| copy_v3_v3(col1[0], col1[2]); | copy_v3_v3(col1[0], col1[2]); | ||||
| copy_v3_v3(col1[1], col1[2]); | copy_v3_v3(col1[1], col1[2]); | ||||
| copy_v3_v3(col1[3], col1[2]); | copy_v3_v3(col1[3], col1[2]); | ||||
| break; | break; | ||||
| } | } | ||||
| /* old below */ | /* old below */ | ||||
| ▲ Show 20 Lines • Show All 886 Lines • ▼ Show 20 Lines | static void widget_textbut(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign) | ||||
| widget_init(&wtb); | widget_init(&wtb); | ||||
| const float rad = wcol->roundness * U.widget_unit; | const float rad = wcol->roundness * U.widget_unit; | ||||
| round_box_edges(&wtb, roundboxalign, rect, rad); | round_box_edges(&wtb, roundboxalign, rect, rad); | ||||
| widgetbase_draw(&wtb, wcol); | widgetbase_draw(&wtb, wcol); | ||||
| } | } | ||||
| static void widget_preview_tile( | |||||
| uiBut *but, uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int UNUSED(roundboxalign)) | |||||
| { | |||||
| const uiStyle *style = UI_style_get(); | |||||
| ui_draw_preview_item_stateless( | |||||
| &style->widget, rect, but->drawstr, but->icon, wcol->text, UI_STYLE_TEXT_CENTER); | |||||
| } | |||||
| static void widget_menuiconbut(uiWidgetColors *wcol, | static void widget_menuiconbut(uiWidgetColors *wcol, | ||||
| rcti *rect, | rcti *rect, | ||||
| int UNUSED(state), | int UNUSED(state), | ||||
| int roundboxalign) | int roundboxalign) | ||||
| { | { | ||||
| uiWidgetBase wtb; | uiWidgetBase wtb; | ||||
| widget_init(&wtb); | widget_init(&wtb); | ||||
| ▲ Show 20 Lines • Show All 449 Lines • ▼ Show 20 Lines | case UI_WTYPE_ICON: | ||||
| break; | break; | ||||
| case UI_WTYPE_ICON_LABEL: | case UI_WTYPE_ICON_LABEL: | ||||
| /* behave like regular labels (this is simply a label with an icon) */ | /* behave like regular labels (this is simply a label with an icon) */ | ||||
| wt.state = widget_state_label; | wt.state = widget_state_label; | ||||
| wt.custom = widget_icon_has_anim; | wt.custom = widget_icon_has_anim; | ||||
| break; | break; | ||||
| case UI_WTYPE_PREVIEW_TILE: | |||||
| wt.draw = NULL; | |||||
| /* Drawn via the `custom` callback. */ | |||||
| wt.text = NULL; | |||||
| wt.custom = widget_preview_tile; | |||||
| break; | |||||
| case UI_WTYPE_SWATCH: | case UI_WTYPE_SWATCH: | ||||
| wt.custom = widget_swatch; | wt.custom = widget_swatch; | ||||
| break; | break; | ||||
| case UI_WTYPE_BOX: | case UI_WTYPE_BOX: | ||||
| wt.custom = widget_box; | wt.custom = widget_box; | ||||
| wt.wcol_theme = &btheme->tui.wcol_box; | wt.wcol_theme = &btheme->tui.wcol_box; | ||||
| break; | break; | ||||
| ▲ Show 20 Lines • Show All 279 Lines • ▼ Show 20 Lines | #endif | ||||
| wt = widget_type(UI_WTYPE_SWATCH); | wt = widget_type(UI_WTYPE_SWATCH); | ||||
| break; | break; | ||||
| case UI_BTYPE_ROUNDBOX: | case UI_BTYPE_ROUNDBOX: | ||||
| case UI_BTYPE_LISTBOX: | case UI_BTYPE_LISTBOX: | ||||
| wt = widget_type(UI_WTYPE_BOX); | wt = widget_type(UI_WTYPE_BOX); | ||||
| break; | break; | ||||
| case UI_BTYPE_PREVIEW_TILE: | |||||
| wt = widget_type(UI_WTYPE_PREVIEW_TILE); | |||||
| break; | |||||
| case UI_BTYPE_EXTRA: | case UI_BTYPE_EXTRA: | ||||
| widget_draw_extra_mask(C, but, widget_type(UI_WTYPE_BOX), rect); | widget_draw_extra_mask(C, but, widget_type(UI_WTYPE_BOX), rect); | ||||
| break; | break; | ||||
| case UI_BTYPE_HSVCUBE: { | case UI_BTYPE_HSVCUBE: { | ||||
| const uiButHSVCube *hsv_but = (uiButHSVCube *)but; | const uiButHSVCube *hsv_but = (uiButHSVCube *)but; | ||||
| if (ELEM(hsv_but->gradient_type, UI_GRAD_V_ALT, UI_GRAD_L_ALT)) { | if (ELEM(hsv_but->gradient_type, UI_GRAD_V_ALT, UI_GRAD_L_ALT)) { | ||||
| ▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Lines | #endif | ||||
| wt->state(wt, state, drawflag, but->emboss); | wt->state(wt, state, drawflag, but->emboss); | ||||
| if (wt->custom) { | if (wt->custom) { | ||||
| wt->custom(but, &wt->wcol, rect, state, roundboxalign); | wt->custom(but, &wt->wcol, rect, state, roundboxalign); | ||||
| } | } | ||||
| else if (wt->draw) { | else if (wt->draw) { | ||||
| wt->draw(&wt->wcol, rect, state, roundboxalign); | wt->draw(&wt->wcol, rect, state, roundboxalign); | ||||
| } | } | ||||
| if (wt->text) { | |||||
| if (use_alpha_blend) { | if (use_alpha_blend) { | ||||
| GPU_blend(GPU_BLEND_ALPHA); | GPU_blend(GPU_BLEND_ALPHA); | ||||
| } | } | ||||
| wt->text(fstyle, &wt->wcol, but, rect); | wt->text(fstyle, &wt->wcol, but, rect); | ||||
| if (use_alpha_blend) { | if (use_alpha_blend) { | ||||
| GPU_blend(GPU_BLEND_NONE); | GPU_blend(GPU_BLEND_NONE); | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| static void ui_draw_clip_tri(uiBlock *block, rcti *rect, uiWidgetType *wt) | static void ui_draw_clip_tri(uiBlock *block, rcti *rect, uiWidgetType *wt) | ||||
| { | { | ||||
| if (block) { | if (block) { | ||||
| float draw_color[4]; | float draw_color[4]; | ||||
| const uchar *color = wt->wcol.text; | const uchar *color = wt->wcol.text; | ||||
| draw_color[0] = ((float)color[0]) / 255.0f; | draw_color[0] = ((float)color[0]) / 255.0f; | ||||
| ▲ Show 20 Lines • Show All 418 Lines • ▼ Show 20 Lines | if (cpoin) { | ||||
| max_hint_width = available_width * 0.40f; | max_hint_width = available_width * 0.40f; | ||||
| /* Clipping xmax for clipping of item name. */ | /* Clipping xmax for clipping of item name. */ | ||||
| rect->xmax = (hint_width < max_hint_width) ? | rect->xmax = (hint_width < max_hint_width) ? | ||||
| (rect->xmax - hint_width) : | (rect->xmax - hint_width) : | ||||
| (rect->xmin + (available_width - max_hint_width)); | (rect->xmin + (available_width - max_hint_width)); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_assert(!"Unknwon menu item separator type"); | BLI_assert_msg(0, "Unknwon menu item separator type"); | ||||
| } | } | ||||
| if (fstyle->kerning == 1) { | if (fstyle->kerning == 1) { | ||||
| BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | if (cpoin) { | ||||
| &(struct uiFontStyleDraw_Params){ | &(struct uiFontStyleDraw_Params){ | ||||
| .align = UI_STYLE_TEXT_RIGHT, | .align = UI_STYLE_TEXT_RIGHT, | ||||
| }); | }); | ||||
| *cpoin = UI_SEP_CHAR; | *cpoin = UI_SEP_CHAR; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void ui_draw_preview_item( | /** | ||||
| const uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state) | * Version of #ui_draw_preview_item() that does not draw the menu background and item text based on | ||||
| * state. It just draws the preview and text directly. | |||||
| */ | |||||
| void ui_draw_preview_item_stateless(const uiFontStyle *fstyle, | |||||
| rcti *rect, | |||||
| const char *name, | |||||
| int iconid, | |||||
| const uchar text_col[4], | |||||
| eFontStyle_Align text_align) | |||||
| { | { | ||||
| rcti trect = *rect; | rcti trect = *rect; | ||||
| const float text_size = UI_UNIT_Y; | const float text_size = UI_UNIT_Y; | ||||
| float font_dims[2] = {0.0f, 0.0f}; | float font_dims[2] = {0.0f, 0.0f}; | ||||
| uiWidgetType *wt = widget_type(UI_WTYPE_MENU_ITEM); | |||||
| /* drawing button background */ | |||||
| wt->state(wt, state, 0, UI_EMBOSS_UNDEFINED); | |||||
| wt->draw(&wt->wcol, rect, 0, 0); | |||||
| /* draw icon in rect above the space reserved for the label */ | /* draw icon in rect above the space reserved for the label */ | ||||
| rect->ymin += text_size; | rect->ymin += text_size; | ||||
| GPU_blend(GPU_BLEND_ALPHA); | GPU_blend(GPU_BLEND_ALPHA); | ||||
| widget_draw_preview(iconid, 1.0f, rect); | widget_draw_preview(iconid, 1.0f, rect); | ||||
| GPU_blend(GPU_BLEND_NONE); | GPU_blend(GPU_BLEND_NONE); | ||||
| BLF_width_and_height( | BLF_width_and_height( | ||||
| fstyle->uifont_id, name, BLF_DRAW_STR_DUMMY_MAX, &font_dims[0], &font_dims[1]); | fstyle->uifont_id, name, BLF_DRAW_STR_DUMMY_MAX, &font_dims[0], &font_dims[1]); | ||||
| /* text rect */ | /* text rect */ | ||||
| trect.xmin += 0; | |||||
| trect.xmax = trect.xmin + font_dims[0] + U.widget_unit / 2; | |||||
| trect.ymin += U.widget_unit / 2; | trect.ymin += U.widget_unit / 2; | ||||
| trect.ymax = trect.ymin + font_dims[1]; | trect.ymax = trect.ymin + font_dims[1]; | ||||
| if (trect.xmax > rect->xmax - PREVIEW_PAD) { | if (trect.xmax > rect->xmax - PREVIEW_PAD) { | ||||
| trect.xmax = rect->xmax - PREVIEW_PAD; | trect.xmax = rect->xmax - PREVIEW_PAD; | ||||
| } | } | ||||
| { | { | ||||
| char drawstr[UI_MAX_DRAW_STR]; | char drawstr[UI_MAX_DRAW_STR]; | ||||
| const float okwidth = (float)BLI_rcti_size_x(&trect); | const float okwidth = (float)BLI_rcti_size_x(&trect); | ||||
| const size_t max_len = sizeof(drawstr); | const size_t max_len = sizeof(drawstr); | ||||
| const float minwidth = (float)(UI_DPI_ICON_SIZE); | const float minwidth = (float)(UI_DPI_ICON_SIZE); | ||||
| BLI_strncpy(drawstr, name, sizeof(drawstr)); | BLI_strncpy(drawstr, name, sizeof(drawstr)); | ||||
| UI_text_clip_middle_ex(fstyle, drawstr, okwidth, minwidth, max_len, '\0'); | UI_text_clip_middle_ex(fstyle, drawstr, okwidth, minwidth, max_len, '\0'); | ||||
| UI_fontstyle_draw(fstyle, | UI_fontstyle_draw(fstyle, | ||||
| &trect, | &trect, | ||||
| drawstr, | drawstr, | ||||
| wt->wcol.text, | text_col, | ||||
| &(struct uiFontStyleDraw_Params){ | &(struct uiFontStyleDraw_Params){ | ||||
| .align = UI_STYLE_TEXT_CENTER, | .align = text_align, | ||||
| }); | }); | ||||
| } | } | ||||
| } | } | ||||
| void ui_draw_preview_item(const uiFontStyle *fstyle, | |||||
| rcti *rect, | |||||
| const char *name, | |||||
| int iconid, | |||||
| int state, | |||||
| eFontStyle_Align text_align) | |||||
| { | |||||
| uiWidgetType *wt = widget_type(UI_WTYPE_MENU_ITEM); | |||||
| /* drawing button background */ | |||||
| wt->state(wt, state, 0, UI_EMBOSS_UNDEFINED); | |||||
| wt->draw(&wt->wcol, rect, 0, 0); | |||||
| ui_draw_preview_item_stateless(fstyle, rect, name, iconid, wt->wcol.text, text_align); | |||||
| } | |||||
| /** \} */ | /** \} */ | ||||