Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_widgets.c
| Show First 20 Lines • Show All 551 Lines • ▼ Show 20 Lines | static void draw_anti_tria( | ||||
| immEnd(); | immEnd(); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| GPU_blend(GPU_BLEND_NONE); | GPU_blend(GPU_BLEND_NONE); | ||||
| } | } | ||||
| /* Triangle 'icon' for panel header and other cases. */ | |||||
| void UI_draw_icon_tri(float x, float y, char dir, const float color[4]) | void UI_draw_icon_tri(float x, float y, char dir, const float color[4]) | ||||
| { | { | ||||
| const float f3 = 0.05 * U.widget_unit; | const float f3 = 0.05 * U.widget_unit; | ||||
| const float f5 = 0.15 * U.widget_unit; | const float f5 = 0.15 * U.widget_unit; | ||||
| const float f7 = 0.25 * U.widget_unit; | const float f7 = 0.25 * U.widget_unit; | ||||
| if (dir == 'h') { | if (dir == 'h') { | ||||
| draw_anti_tria(x - f3, y - f5, x - f3, y + f5, x + f7, y, color); | draw_anti_tria(x - f3, y - f5, x - f3, y + f5, x + f7, y, color); | ||||
| ▲ Show 20 Lines • Show All 946 Lines • ▼ Show 20 Lines | else { | ||||
| l_end = BLF_width_to_strlen(fstyle->uifont_id, str, max_len, okwidth, NULL); | l_end = BLF_width_to_strlen(fstyle->uifont_id, str, max_len, okwidth, NULL); | ||||
| str[l_end] = '\0'; | str[l_end] = '\0'; | ||||
| if (r_final_len) { | if (r_final_len) { | ||||
| *r_final_len = (size_t)l_end; | *r_final_len = (size_t)l_end; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * Cut off the middle of the text to fit into the given width. | |||||
| * | |||||
| * \note in case this middle clipping would just remove a few chars, | |||||
| * it rather clips right, which is more readable. | |||||
| * | |||||
| * If rpart_sep is not Null, the part of str starting to first occurrence of rpart_sep | |||||
| * is preserved at all cost. | |||||
| * Useful for strings with shortcuts | |||||
| * (like 'AVeryLongFooBarLabelForMenuEntry|Ctrl O' -> 'AVeryLong...MenuEntry|Ctrl O'). | |||||
| */ | |||||
| float UI_text_clip_middle_ex(const uiFontStyle *fstyle, | float UI_text_clip_middle_ex(const uiFontStyle *fstyle, | ||||
| char *str, | char *str, | ||||
| float okwidth, | float okwidth, | ||||
| const float minwidth, | const float minwidth, | ||||
| const size_t max_len, | const size_t max_len, | ||||
| const char rpart_sep) | const char rpart_sep) | ||||
| { | { | ||||
| /* Add some epsilon to OK width, avoids 'ellipsing' text that nearly fits! | /* Add some epsilon to OK width, avoids 'ellipsing' text that nearly fits! | ||||
| ▲ Show 20 Lines • Show All 1,334 Lines • ▼ Show 20 Lines | void ui_hsvcircle_vals_from_pos( | ||||
| const float radius = (float)min_ii(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)) / 2.0f; | const float radius = (float)min_ii(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)) / 2.0f; | ||||
| const float m_delta[2] = {mx - centx, my - centy}; | const float m_delta[2] = {mx - centx, my - centy}; | ||||
| const float dist_sq = len_squared_v2(m_delta); | const float dist_sq = len_squared_v2(m_delta); | ||||
| *r_val_dist = (dist_sq < (radius * radius)) ? sqrtf(dist_sq) / radius : 1.0f; | *r_val_dist = (dist_sq < (radius * radius)) ? sqrtf(dist_sq) / radius : 1.0f; | ||||
| *r_val_rad = atan2f(m_delta[0], m_delta[1]) / (2.0f * (float)M_PI) + 0.5f; | *r_val_rad = atan2f(m_delta[0], m_delta[1]) / (2.0f * (float)M_PI) + 0.5f; | ||||
| } | } | ||||
| /* cursor in hsv circle, in float units -1 to 1, to map on radius */ | |||||
| void ui_hsvcircle_pos_from_vals( | void ui_hsvcircle_pos_from_vals( | ||||
| const ColorPicker *cpicker, const rcti *rect, const float *hsv, float *r_xpos, float *r_ypos) | const ColorPicker *cpicker, const rcti *rect, const float *hsv, float *r_xpos, float *r_ypos) | ||||
| { | { | ||||
| /* duplication of code... well, simple is better now */ | /* duplication of code... well, simple is better now */ | ||||
| const float centx = BLI_rcti_cent_x_fl(rect); | const float centx = BLI_rcti_cent_x_fl(rect); | ||||
| const float centy = BLI_rcti_cent_y_fl(rect); | const float centy = BLI_rcti_cent_y_fl(rect); | ||||
| const float radius = (float)min_ii(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)) / 2.0f; | const float radius = (float)min_ii(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)) / 2.0f; | ||||
| ▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Draw Custom Buttons | /** \name Draw Custom Buttons | ||||
| * \{ */ | * \{ */ | ||||
| /* draws in resolution of 48x4 colors */ | |||||
| void ui_draw_gradient(const rcti *rect, | void ui_draw_gradient(const rcti *rect, | ||||
| const float hsv[3], | const float hsv[3], | ||||
| const eButGradientType type, | const eButGradientType type, | ||||
| const float alpha) | const float alpha) | ||||
| { | { | ||||
| /* allows for 4 steps (red->yellow) */ | /* allows for 4 steps (red->yellow) */ | ||||
| const int steps = 48; | const int steps = 48; | ||||
| const float color_step = 1.0f / steps; | const float color_step = 1.0f / steps; | ||||
| ▲ Show 20 Lines • Show All 476 Lines • ▼ Show 20 Lines | static void widget_numbut_embossn(const uiBut *UNUSED(but), | ||||
| rcti *rect, | rcti *rect, | ||||
| int state, | int state, | ||||
| int roundboxalign, | int roundboxalign, | ||||
| const float zoom) | const float zoom) | ||||
| { | { | ||||
| widget_numbut_draw(wcol, rect, zoom, state, roundboxalign, true); | widget_numbut_draw(wcol, rect, zoom, state, roundboxalign, true); | ||||
| } | } | ||||
| /* function in use for buttons and for view2d sliders */ | |||||
| void UI_draw_widget_scroll(uiWidgetColors *wcol, const rcti *rect, const rcti *slider, int state) | void UI_draw_widget_scroll(uiWidgetColors *wcol, const rcti *rect, const rcti *slider, int state) | ||||
| { | { | ||||
| uiWidgetBase wtb; | uiWidgetBase wtb; | ||||
| bool outline = false; | bool outline = false; | ||||
| widget_init(&wtb); | widget_init(&wtb); | ||||
| /* determine horizontal/vertical */ | /* determine horizontal/vertical */ | ||||
| ▲ Show 20 Lines • Show All 1,138 Lines • ▼ Show 20 Lines | static int widget_roundbox_set(uiBut *but, rcti *rect) | ||||
| return roundbox; | return roundbox; | ||||
| } | } | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Public API | /** \name Public API | ||||
| * \{ */ | * \{ */ | ||||
| /* conversion from old to new buttons, so still messy */ | |||||
| void ui_draw_but(const bContext *C, struct ARegion *region, uiStyle *style, uiBut *but, rcti *rect) | void ui_draw_but(const bContext *C, struct ARegion *region, uiStyle *style, uiBut *but, rcti *rect) | ||||
| { | { | ||||
| bTheme *btheme = UI_GetTheme(); | bTheme *btheme = UI_GetTheme(); | ||||
| const ThemeUI *tui = &btheme->tui; | const ThemeUI *tui = &btheme->tui; | ||||
| const uiFontStyle *fstyle = &style->widget; | const uiFontStyle *fstyle = &style->widget; | ||||
| uiWidgetType *wt = NULL; | uiWidgetType *wt = NULL; | ||||
| /* handle menus separately */ | /* handle menus separately */ | ||||
| ▲ Show 20 Lines • Show All 670 Lines • ▼ Show 20 Lines | |||||
| void ui_draw_tooltip_background(const uiStyle *UNUSED(style), uiBlock *UNUSED(block), rcti *rect) | void ui_draw_tooltip_background(const uiStyle *UNUSED(style), uiBlock *UNUSED(block), rcti *rect) | ||||
| { | { | ||||
| uiWidgetType *wt = widget_type(UI_WTYPE_TOOLTIP); | uiWidgetType *wt = widget_type(UI_WTYPE_TOOLTIP); | ||||
| wt->state(wt, 0, 0, UI_EMBOSS_UNDEFINED); | wt->state(wt, 0, 0, UI_EMBOSS_UNDEFINED); | ||||
| /* wt->draw ends up using same function to draw the tooltip as menu_back */ | /* wt->draw ends up using same function to draw the tooltip as menu_back */ | ||||
| wt->draw(&wt->wcol, rect, 0, 0, 1.0f); | wt->draw(&wt->wcol, rect, 0, 0, 1.0f); | ||||
| } | } | ||||
| /** | |||||
| * Helper call to draw a menu item without a button. | |||||
| * | |||||
| * \param state: The state of the button, | |||||
| * typically #UI_ACTIVE, #UI_BUT_DISABLED, #UI_BUT_INACTIVE. | |||||
| * \param separator_type: The kind of separator which controls if and how the string is clipped. | |||||
| * \param r_xmax: The right hand position of the text, this takes into the icon, | |||||
| * padding and text clipping when there is not enough room to display the full text. | |||||
| */ | |||||
| void ui_draw_menu_item(const uiFontStyle *fstyle, | void ui_draw_menu_item(const uiFontStyle *fstyle, | ||||
| rcti *rect, | rcti *rect, | ||||
| const char *name, | const char *name, | ||||
| int iconid, | int iconid, | ||||
| int state, | int state, | ||||
| uiMenuItemSeparatorType separator_type, | uiMenuItemSeparatorType separator_type, | ||||
| int *r_xmax) | int *r_xmax) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 122 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; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * 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, | void ui_draw_preview_item_stateless(const uiFontStyle *fstyle, | ||||
| rcti *rect, | rcti *rect, | ||||
| const char *name, | const char *name, | ||||
| int iconid, | int iconid, | ||||
| const uchar text_col[4], | const uchar text_col[4], | ||||
| eFontStyle_Align text_align) | eFontStyle_Align text_align) | ||||
| { | { | ||||
| rcti trect = *rect; | rcti trect = *rect; | ||||
| ▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines | |||||