Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface.c
| Show First 20 Lines • Show All 196 Lines • ▼ Show 20 Lines | float ui_block_to_window_scale(const ARegion *region, uiBlock *block) | ||||
| float min_y = 0, max_y = 1; | float min_y = 0, max_y = 1; | ||||
| float dummy_x = 0.0f; | float dummy_x = 0.0f; | ||||
| ui_block_to_window_fl(region, block, &dummy_x, &min_y); | ui_block_to_window_fl(region, block, &dummy_x, &min_y); | ||||
| dummy_x = 0.0f; | dummy_x = 0.0f; | ||||
| ui_block_to_window_fl(region, block, &dummy_x, &max_y); | ui_block_to_window_fl(region, block, &dummy_x, &max_y); | ||||
| return max_y - min_y; | return max_y - min_y; | ||||
| } | } | ||||
| /* for mouse cursor */ | |||||
| void ui_window_to_block_fl(const ARegion *region, uiBlock *block, float *r_x, float *r_y) | void ui_window_to_block_fl(const ARegion *region, uiBlock *block, float *r_x, float *r_y) | ||||
| { | { | ||||
| const int getsizex = BLI_rcti_size_x(®ion->winrct) + 1; | const int getsizex = BLI_rcti_size_x(®ion->winrct) + 1; | ||||
| const int getsizey = BLI_rcti_size_y(®ion->winrct) + 1; | const int getsizey = BLI_rcti_size_y(®ion->winrct) + 1; | ||||
| const int sx = region->winrct.xmin; | const int sx = region->winrct.xmin; | ||||
| const int sy = region->winrct.ymin; | const int sy = region->winrct.ymin; | ||||
| const float a = 0.5f * ((float)getsizex) * block->winmat[0][0]; | const float a = 0.5f * ((float)getsizex) * block->winmat[0][0]; | ||||
| ▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Lines | else { | ||||
| const int height = WM_window_pixels_y(window); | const int height = WM_window_pixels_y(window); | ||||
| const rcti winrct = {0, width - 1, 0, height - 1}; | const rcti winrct = {0, width - 1, 0, height - 1}; | ||||
| wmGetProjectionMatrix(block->winmat, &winrct); | wmGetProjectionMatrix(block->winmat, &winrct); | ||||
| block->aspect = 2.0f / fabsf(width * block->winmat[0][0]); | block->aspect = 2.0f / fabsf(width * block->winmat[0][0]); | ||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * Popups will add a margin to #ARegion.winrct for shadow, | |||||
| * for interactivity (point-inside tests for eg), we want the winrct without the margin added. | |||||
| */ | |||||
| void ui_region_winrct_get_no_margin(const struct ARegion *region, struct rcti *r_rect) | void ui_region_winrct_get_no_margin(const struct ARegion *region, struct rcti *r_rect) | ||||
| { | { | ||||
| uiBlock *block = region->uiblocks.first; | uiBlock *block = region->uiblocks.first; | ||||
| if (block && (block->flag & UI_BLOCK_LOOP) && (block->flag & UI_BLOCK_RADIAL) == 0) { | if (block && (block->flag & UI_BLOCK_LOOP) && (block->flag & UI_BLOCK_RADIAL) == 0) { | ||||
| BLI_rcti_rctf_copy_floor(r_rect, &block->rect); | BLI_rcti_rctf_copy_floor(r_rect, &block->rect); | ||||
| BLI_rcti_translate(r_rect, region->winrct.xmin, region->winrct.ymin); | BLI_rcti_translate(r_rect, region->winrct.xmin, region->winrct.ymin); | ||||
| } | } | ||||
| else { | else { | ||||
| ▲ Show 20 Lines • Show All 224 Lines • ▼ Show 20 Lines | static void ui_block_bounds_calc_popup( | ||||
| * Needed to handle correctly floating panels once they have been dragged around, | * Needed to handle correctly floating panels once they have been dragged around, | ||||
| * see T52999. */ | * see T52999. */ | ||||
| if (r_xy) { | if (r_xy) { | ||||
| r_xy[0] = xy[0] + block->rect.xmin - raw_x; | r_xy[0] = xy[0] + block->rect.xmin - raw_x; | ||||
| r_xy[1] = xy[1] + block->rect.ymin - raw_y; | r_xy[1] = xy[1] + block->rect.ymin - raw_y; | ||||
| } | } | ||||
| } | } | ||||
| /* used for various cases */ | |||||
| void UI_block_bounds_set_normal(uiBlock *block, int addval) | void UI_block_bounds_set_normal(uiBlock *block, int addval) | ||||
| { | { | ||||
| if (block == NULL) { | if (block == NULL) { | ||||
| return; | return; | ||||
| } | } | ||||
| block->bounds = addval; | block->bounds = addval; | ||||
| block->bounds_type = UI_BLOCK_BOUNDS; | block->bounds_type = UI_BLOCK_BOUNDS; | ||||
| } | } | ||||
| /* Used for pull-downs. */ | |||||
| void UI_block_bounds_set_text(uiBlock *block, int addval) | void UI_block_bounds_set_text(uiBlock *block, int addval) | ||||
| { | { | ||||
| block->bounds = addval; | block->bounds = addval; | ||||
| block->bounds_type = UI_BLOCK_BOUNDS_TEXT; | block->bounds_type = UI_BLOCK_BOUNDS_TEXT; | ||||
| } | } | ||||
| /* used for block popups */ | |||||
| void UI_block_bounds_set_popup(uiBlock *block, int addval, const int bounds_offset[2]) | void UI_block_bounds_set_popup(uiBlock *block, int addval, const int bounds_offset[2]) | ||||
| { | { | ||||
| block->bounds = addval; | block->bounds = addval; | ||||
| block->bounds_type = UI_BLOCK_BOUNDS_POPUP_MOUSE; | block->bounds_type = UI_BLOCK_BOUNDS_POPUP_MOUSE; | ||||
| if (bounds_offset != NULL) { | if (bounds_offset != NULL) { | ||||
| block->bounds_offset[0] = bounds_offset[0]; | block->bounds_offset[0] = bounds_offset[0]; | ||||
| block->bounds_offset[1] = bounds_offset[1]; | block->bounds_offset[1] = bounds_offset[1]; | ||||
| } | } | ||||
| else { | else { | ||||
| block->bounds_offset[0] = 0; | block->bounds_offset[0] = 0; | ||||
| block->bounds_offset[1] = 0; | block->bounds_offset[1] = 0; | ||||
| } | } | ||||
| } | } | ||||
| /* used for menu popups */ | |||||
| void UI_block_bounds_set_menu(uiBlock *block, int addval, const int bounds_offset[2]) | void UI_block_bounds_set_menu(uiBlock *block, int addval, const int bounds_offset[2]) | ||||
| { | { | ||||
| block->bounds = addval; | block->bounds = addval; | ||||
| block->bounds_type = UI_BLOCK_BOUNDS_POPUP_MENU; | block->bounds_type = UI_BLOCK_BOUNDS_POPUP_MENU; | ||||
| if (bounds_offset != NULL) { | if (bounds_offset != NULL) { | ||||
| copy_v2_v2_int(block->bounds_offset, bounds_offset); | copy_v2_v2_int(block->bounds_offset, bounds_offset); | ||||
| } | } | ||||
| else { | else { | ||||
| zero_v2_int(block->bounds_offset); | zero_v2_int(block->bounds_offset); | ||||
| } | } | ||||
| } | } | ||||
| /* used for centered popups, i.e. splash */ | |||||
| void UI_block_bounds_set_centered(uiBlock *block, int addval) | void UI_block_bounds_set_centered(uiBlock *block, int addval) | ||||
| { | { | ||||
| block->bounds = addval; | block->bounds = addval; | ||||
| block->bounds_type = UI_BLOCK_BOUNDS_POPUP_CENTER; | block->bounds_type = UI_BLOCK_BOUNDS_POPUP_CENTER; | ||||
| } | } | ||||
| void UI_block_bounds_set_explicit(uiBlock *block, int minx, int miny, int maxx, int maxy) | void UI_block_bounds_set_explicit(uiBlock *block, int minx, int miny, int maxx, int maxy) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 325 Lines • ▼ Show 20 Lines | else { | ||||
| * draw are the same this gives O(1) lookup for each button */ | * draw are the same this gives O(1) lookup for each button */ | ||||
| BLI_remlink(&oldblock->buttons, oldbut); | BLI_remlink(&oldblock->buttons, oldbut); | ||||
| ui_but_free(C, oldbut); | ui_but_free(C, oldbut); | ||||
| } | } | ||||
| return found_active; | return found_active; | ||||
| } | } | ||||
| /** | |||||
| * Needed for temporarily rename buttons, such as in outliner or file-select, | |||||
| * they should keep calling #uiDefBut to keep them alive. | |||||
| * \return false when button removed. | |||||
| */ | |||||
| bool UI_but_active_only_ex( | bool UI_but_active_only_ex( | ||||
| const bContext *C, ARegion *region, uiBlock *block, uiBut *but, const bool remove_on_failure) | const bContext *C, ARegion *region, uiBlock *block, uiBut *but, const bool remove_on_failure) | ||||
| { | { | ||||
| bool activate = false, found = false, isactive = false; | bool activate = false, found = false, isactive = false; | ||||
| uiBlock *oldblock = block->oldblock; | uiBlock *oldblock = block->oldblock; | ||||
| if (!oldblock) { | if (!oldblock) { | ||||
| activate = true; | activate = true; | ||||
| Show All 31 Lines | bool UI_but_active_only_ex( | ||||
| return true; | return true; | ||||
| } | } | ||||
| bool UI_but_active_only(const bContext *C, ARegion *region, uiBlock *block, uiBut *but) | bool UI_but_active_only(const bContext *C, ARegion *region, uiBlock *block, uiBut *but) | ||||
| { | { | ||||
| return UI_but_active_only_ex(C, region, block, but, true); | return UI_but_active_only_ex(C, region, block, but, true); | ||||
| } | } | ||||
| /** | |||||
| * \warning This must run after other handlers have been added, | |||||
| * otherwise the handler won't be removed, see: T71112. | |||||
| */ | |||||
| bool UI_block_active_only_flagged_buttons(const bContext *C, ARegion *region, uiBlock *block) | bool UI_block_active_only_flagged_buttons(const bContext *C, ARegion *region, uiBlock *block) | ||||
| { | { | ||||
| /* Running this command before end-block has run, means buttons that open menus | /* Running this command before end-block has run, means buttons that open menus | ||||
| * won't have those menus correctly positioned, see T83539. */ | * won't have those menus correctly positioned, see T83539. */ | ||||
| BLI_assert(block->endblock); | BLI_assert(block->endblock); | ||||
| bool done = false; | bool done = false; | ||||
| LISTBASE_FOREACH (uiBut *, but, &block->buttons) { | LISTBASE_FOREACH (uiBut *, but, &block->buttons) { | ||||
| Show All 14 Lines | if (done) { | ||||
| LISTBASE_FOREACH (uiBut *, but, &block->buttons) { | LISTBASE_FOREACH (uiBut *, but, &block->buttons) { | ||||
| but->flag &= ~UI_BUT_ACTIVATE_ON_INIT; | but->flag &= ~UI_BUT_ACTIVATE_ON_INIT; | ||||
| } | } | ||||
| } | } | ||||
| return done; | return done; | ||||
| } | } | ||||
| /* simulate button click */ | |||||
| void UI_but_execute(const bContext *C, ARegion *region, uiBut *but) | void UI_but_execute(const bContext *C, ARegion *region, uiBut *but) | ||||
| { | { | ||||
| void *active_back; | void *active_back; | ||||
| ui_but_execute_begin((bContext *)C, region, but, &active_back); | ui_but_execute_begin((bContext *)C, region, but, &active_back); | ||||
| /* Value is applied in begin. No further action required. */ | /* Value is applied in begin. No further action required. */ | ||||
| ui_but_execute_end((bContext *)C, region, but, active_back); | ui_but_execute_end((bContext *)C, region, but, active_back); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | for (int pass = 0; pass < 2; pass++) { | ||||
| /* check if second pass is needed */ | /* check if second pass is needed */ | ||||
| if (!tot_missing) { | if (!tot_missing) { | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* XXX, this code will shorten any allocated string to 'UI_MAX_NAME_STR' | |||||
| * since this is really long its unlikely to be an issue, | |||||
| * but this could be supported */ | |||||
| void ui_but_add_shortcut(uiBut *but, const char *shortcut_str, const bool do_strip) | void ui_but_add_shortcut(uiBut *but, const char *shortcut_str, const bool do_strip) | ||||
| { | { | ||||
| if (do_strip && (but->flag & UI_BUT_HAS_SEP_CHAR)) { | if (do_strip && (but->flag & UI_BUT_HAS_SEP_CHAR)) { | ||||
| char *cpoin = strrchr(but->str, UI_SEP_CHAR); | char *cpoin = strrchr(but->str, UI_SEP_CHAR); | ||||
| if (cpoin) { | if (cpoin) { | ||||
| *cpoin = '\0'; | *cpoin = '\0'; | ||||
| } | } | ||||
| but->flag &= ~UI_BUT_HAS_SEP_CHAR; | but->flag &= ~UI_BUT_HAS_SEP_CHAR; | ||||
| ▲ Show 20 Lines • Show All 650 Lines • ▼ Show 20 Lines | if (but->type == UI_BTYPE_NUM) { | ||||
| if (ELEM(but->pointype, UI_BUT_POIN_CHAR, UI_BUT_POIN_SHORT, UI_BUT_POIN_INT)) { | if (ELEM(but->pointype, UI_BUT_POIN_CHAR, UI_BUT_POIN_SHORT, UI_BUT_POIN_INT)) { | ||||
| BLI_assert((int)number_but->step_size > 0); | BLI_assert((int)number_but->step_size > 0); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| #endif | #endif | ||||
| /** | |||||
| * Check if the operator \a ot poll is successful with the context given by \a but (optionally). | |||||
| * \param but: The button that might store context. Can be NULL for convenience (e.g. if there is | |||||
| * no button to take context from, but we still want to poll the operator). | |||||
| */ | |||||
| bool ui_but_context_poll_operator_ex(bContext *C, | bool ui_but_context_poll_operator_ex(bContext *C, | ||||
| const uiBut *but, | const uiBut *but, | ||||
| const wmOperatorCallParams *optype_params) | const wmOperatorCallParams *optype_params) | ||||
| { | { | ||||
| bool result; | bool result; | ||||
| if (but && but->context) { | if (but && but->context) { | ||||
| CTX_store_set(C, but->context); | CTX_store_set(C, but->context); | ||||
| ▲ Show 20 Lines • Show All 139 Lines • ▼ Show 20 Lines | |||||
| static bool ui_but_pixelrect_in_view(const ARegion *region, const rcti *rect) | static bool ui_but_pixelrect_in_view(const ARegion *region, const rcti *rect) | ||||
| { | { | ||||
| rcti rect_winspace = *rect; | rcti rect_winspace = *rect; | ||||
| BLI_rcti_translate(&rect_winspace, region->winrct.xmin, region->winrct.ymin); | BLI_rcti_translate(&rect_winspace, region->winrct.xmin, region->winrct.ymin); | ||||
| return BLI_rcti_isect(®ion->winrct, &rect_winspace, NULL); | return BLI_rcti_isect(®ion->winrct, &rect_winspace, NULL); | ||||
| } | } | ||||
| /* uses local copy of style, to scale things down, and allow widgets to change stuff */ | |||||
| void UI_block_draw(const bContext *C, uiBlock *block) | void UI_block_draw(const bContext *C, uiBlock *block) | ||||
| { | { | ||||
| uiStyle style = *UI_style_get_dpi(); /* XXX pass on as arg */ | uiStyle style = *UI_style_get_dpi(); /* XXX pass on as arg */ | ||||
| /* get menu region or area region */ | /* get menu region or area region */ | ||||
| ARegion *region = CTX_wm_menu(C); | ARegion *region = CTX_wm_menu(C); | ||||
| if (!region) { | if (!region) { | ||||
| region = CTX_wm_region(C); | region = CTX_wm_region(C); | ||||
| ▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| LISTBASE_FOREACH (uiBlock *, block, ®ion->uiblocks) { | LISTBASE_FOREACH (uiBlock *, block, ®ion->uiblocks) { | ||||
| ui_block_message_subscribe(region, mbus, block); | ui_block_message_subscribe(region, mbus, block); | ||||
| } | } | ||||
| } | } | ||||
| /* ************* EVENTS ************* */ | /* ************* EVENTS ************* */ | ||||
| /** | |||||
| * Check if the button is pushed, this is only meaningful for some button types. | |||||
| * | |||||
| * \return (0 == UNSELECT), (1 == SELECT), (-1 == DO-NOTHING) | |||||
| */ | |||||
| int ui_but_is_pushed_ex(uiBut *but, double *value) | int ui_but_is_pushed_ex(uiBut *but, double *value) | ||||
| { | { | ||||
| int is_push = 0; | int is_push = 0; | ||||
| if (but->pushed_state_func) { | if (but->pushed_state_func) { | ||||
| return but->pushed_state_func(but, but->pushed_state_arg); | return but->pushed_state_func(but, but->pushed_state_arg); | ||||
| } | } | ||||
| if (but->bit) { | if (but->bit) { | ||||
| ▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | void UI_block_lock_clear(uiBlock *block) | ||||
| block->lock = false; | block->lock = false; | ||||
| block->lockstr = NULL; | block->lockstr = NULL; | ||||
| } | } | ||||
| /* *********************** data get/set *********************** | /* *********************** data get/set *********************** | ||||
| * this either works with the pointed to data, or can work with | * this either works with the pointed to data, or can work with | ||||
| * an edit override pointer while dragging for example */ | * an edit override pointer while dragging for example */ | ||||
| /* for buttons pointing to color for example */ | |||||
| void ui_but_v3_get(uiBut *but, float vec[3]) | void ui_but_v3_get(uiBut *but, float vec[3]) | ||||
| { | { | ||||
| if (but->editvec) { | if (but->editvec) { | ||||
| copy_v3_v3(vec, but->editvec); | copy_v3_v3(vec, but->editvec); | ||||
| } | } | ||||
| if (but->rnaprop) { | if (but->rnaprop) { | ||||
| PropertyRNA *prop = but->rnaprop; | PropertyRNA *prop = but->rnaprop; | ||||
| Show All 31 Lines | else { | ||||
| } | } | ||||
| } | } | ||||
| if (but->type == UI_BTYPE_UNITVEC) { | if (but->type == UI_BTYPE_UNITVEC) { | ||||
| normalize_v3(vec); | normalize_v3(vec); | ||||
| } | } | ||||
| } | } | ||||
| /* for buttons pointing to color for example */ | |||||
| void ui_but_v3_set(uiBut *but, const float vec[3]) | void ui_but_v3_set(uiBut *but, const float vec[3]) | ||||
| { | { | ||||
| if (but->editvec) { | if (but->editvec) { | ||||
| copy_v3_v3(but->editvec, vec); | copy_v3_v3(but->editvec, vec); | ||||
| } | } | ||||
| if (but->rnaprop) { | if (but->rnaprop) { | ||||
| PropertyRNA *prop = but->rnaprop; | PropertyRNA *prop = but->rnaprop; | ||||
| ▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | if (unit->system == USER_UNIT_NONE) { | ||||
| if (unit_type != PROP_UNIT_ROTATION) { | if (unit_type != PROP_UNIT_ROTATION) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| /** | |||||
| * Check if this button is similar enough to be grouped with another. | |||||
| */ | |||||
| bool ui_but_is_compatible(const uiBut *but_a, const uiBut *but_b) | bool ui_but_is_compatible(const uiBut *but_a, const uiBut *but_b) | ||||
| { | { | ||||
| if (but_a->type != but_b->type) { | if (but_a->type != but_b->type) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (but_a->pointype != but_b->pointype) { | if (but_a->pointype != but_b->pointype) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| Show All 19 Lines | |||||
| { | { | ||||
| if (but->rnaprop == NULL || RNA_struct_contains_property(&but->rnapoin, but->rnaprop)) { | if (but->rnaprop == NULL || RNA_struct_contains_property(&but->rnapoin, but->rnaprop)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| printf("property removed %s: %p\n", but->drawstr, but->rnaprop); | printf("property removed %s: %p\n", but->drawstr, but->rnaprop); | ||||
| return false; | return false; | ||||
| } | } | ||||
| /** | |||||
| * Checks if the button supports cycling next/previous menu items (ctrl+mouse-wheel). | |||||
| */ | |||||
| bool ui_but_supports_cycling(const uiBut *but) | bool ui_but_supports_cycling(const uiBut *but) | ||||
| { | { | ||||
| return (ELEM(but->type, UI_BTYPE_ROW, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER, UI_BTYPE_LISTBOX) || | return (ELEM(but->type, UI_BTYPE_ROW, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER, UI_BTYPE_LISTBOX) || | ||||
| (but->type == UI_BTYPE_MENU && ui_but_menu_step_poll(but)) || | (but->type == UI_BTYPE_MENU && ui_but_menu_step_poll(but)) || | ||||
| (but->type == UI_BTYPE_COLOR && ((uiButColor *)but)->is_pallete_color) || | (but->type == UI_BTYPE_COLOR && ((uiButColor *)but)->is_pallete_color) || | ||||
| (but->menu_step_func != NULL)); | (but->menu_step_func != NULL)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 190 Lines • ▼ Show 20 Lines | static double ui_get_but_scale_unit(uiBut *but, double value) | ||||
| /* Time unit is a bit special, not handled by BKE_scene_unit_scale() for now. */ | /* Time unit is a bit special, not handled by BKE_scene_unit_scale() for now. */ | ||||
| if (unit_type == PROP_UNIT_TIME) { /* WARNING: using evil_C :| */ | if (unit_type == PROP_UNIT_TIME) { /* WARNING: using evil_C :| */ | ||||
| Scene *scene = CTX_data_scene(but->block->evil_C); | Scene *scene = CTX_data_scene(but->block->evil_C); | ||||
| return FRA2TIME(value); | return FRA2TIME(value); | ||||
| } | } | ||||
| return BKE_scene_unit_scale(unit, RNA_SUBTYPE_UNIT_VALUE(unit_type), value); | return BKE_scene_unit_scale(unit, RNA_SUBTYPE_UNIT_VALUE(unit_type), value); | ||||
| } | } | ||||
| /* str will be overwritten */ | |||||
| void ui_but_convert_to_unit_alt_name(uiBut *but, char *str, size_t maxlen) | void ui_but_convert_to_unit_alt_name(uiBut *but, char *str, size_t maxlen) | ||||
| { | { | ||||
| if (!ui_but_is_unit(but)) { | if (!ui_but_is_unit(but)) { | ||||
| return; | return; | ||||
| } | } | ||||
| UnitSettings *unit = but->block->unit; | UnitSettings *unit = but->block->unit; | ||||
| const int unit_type = UI_but_unit_type_get(but); | const int unit_type = UI_but_unit_type_get(but); | ||||
| ▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | if (step == step_unit) { | ||||
| * Without this we can't select between a single degree, or a 10th of a degree. | * Without this we can't select between a single degree, or a 10th of a degree. | ||||
| */ | */ | ||||
| step_final *= step_orig; | step_final *= step_orig; | ||||
| } | } | ||||
| return (float)step_final; | return (float)step_final; | ||||
| } | } | ||||
| /** | |||||
| * \param float_precision: For number buttons the precision | |||||
| * to use or -1 to fallback to the button default. | |||||
| * \param use_exp_float: Use exponent representation of floats | |||||
| * when out of reasonable range (outside of 1e3/1e-3). | |||||
| */ | |||||
| void ui_but_string_get_ex(uiBut *but, | void ui_but_string_get_ex(uiBut *but, | ||||
| char *str, | char *str, | ||||
| const size_t maxlen, | const size_t maxlen, | ||||
| const int float_precision, | const int float_precision, | ||||
| const bool use_exp_float, | const bool use_exp_float, | ||||
| bool *r_use_exp_float) | bool *r_use_exp_float) | ||||
| { | { | ||||
| if (r_use_exp_float) { | if (r_use_exp_float) { | ||||
| ▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | else { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void ui_but_string_get(uiBut *but, char *str, const size_t maxlen) | void ui_but_string_get(uiBut *but, char *str, const size_t maxlen) | ||||
| { | { | ||||
| ui_but_string_get_ex(but, str, maxlen, -1, false, NULL); | ui_but_string_get_ex(but, str, maxlen, -1, false, NULL); | ||||
| } | } | ||||
| /** | |||||
| * A version of #ui_but_string_get_ex for dynamic buffer sizes | |||||
| * (where #ui_but_string_get_max_length returns 0). | |||||
| * | |||||
| * \param r_str_size: size of the returned string (including terminator). | |||||
| */ | |||||
| char *ui_but_string_get_dynamic(uiBut *but, int *r_str_size) | char *ui_but_string_get_dynamic(uiBut *but, int *r_str_size) | ||||
| { | { | ||||
| char *str = NULL; | char *str = NULL; | ||||
| *r_str_size = 1; | *r_str_size = 1; | ||||
| if (but->rnaprop && ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) { | if (but->rnaprop && ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) { | ||||
| const PropertyType type = RNA_property_type(but->rnaprop); | const PropertyType type = RNA_property_type(but->rnaprop); | ||||
| ▲ Show 20 Lines • Show All 342 Lines • ▼ Show 20 Lines | void ui_but_range_set_hard(uiBut *but) | ||||
| else if (type == PROP_FLOAT) { | else if (type == PROP_FLOAT) { | ||||
| float fmin, fmax; | float fmin, fmax; | ||||
| RNA_property_float_range(&but->rnapoin, but->rnaprop, &fmin, &fmax); | RNA_property_float_range(&but->rnapoin, but->rnaprop, &fmin, &fmax); | ||||
| but->hardmin = fmin; | but->hardmin = fmin; | ||||
| but->hardmax = fmax; | but->hardmax = fmax; | ||||
| } | } | ||||
| } | } | ||||
| /* NOTE: this could be split up into functions which handle arrays and not. */ | |||||
| void ui_but_range_set_soft(uiBut *but) | void ui_but_range_set_soft(uiBut *but) | ||||
| { | { | ||||
| /* This could be split up into functions which handle arrays and not. */ | |||||
| /* Ideally we would not limit this, but practically it's more than | /* Ideally we would not limit this, but practically it's more than | ||||
| * enough. Worst case is very long vectors won't use a smart soft-range, | * enough. Worst case is very long vectors won't use a smart soft-range, | ||||
| * which isn't so bad. */ | * which isn't so bad. */ | ||||
| if (but->rnaprop) { | if (but->rnaprop) { | ||||
| const PropertyType type = RNA_property_type(but->rnaprop); | const PropertyType type = RNA_property_type(but->rnaprop); | ||||
| const PropertySubType subtype = RNA_property_subtype(but->rnaprop); | const PropertySubType subtype = RNA_property_subtype(but->rnaprop); | ||||
| double softmin, softmax /*, step, precision*/; | double softmin, softmax /*, step, precision*/; | ||||
| ▲ Show 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | static void ui_but_free(const bContext *C, uiBut *but) | ||||
| } | } | ||||
| ui_but_extra_operator_icons_free(but); | ui_but_extra_operator_icons_free(but); | ||||
| BLI_assert(UI_butstore_is_registered(but->block, but) == false); | BLI_assert(UI_butstore_is_registered(but->block, but) == false); | ||||
| MEM_freeN(but); | MEM_freeN(but); | ||||
| } | } | ||||
| /* can be called with C==NULL */ | |||||
| void UI_block_free(const bContext *C, uiBlock *block) | void UI_block_free(const bContext *C, uiBlock *block) | ||||
| { | { | ||||
| UI_butstore_clear(block); | UI_butstore_clear(block); | ||||
| uiBut *but; | uiBut *but; | ||||
| while ((but = BLI_pophead(&block->buttons))) { | while ((but = BLI_pophead(&block->buttons))) { | ||||
| ui_but_free(C, but); | ui_but_free(C, but); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| LISTBASE_FOREACH (uiBlock *, block, lb) { | LISTBASE_FOREACH (uiBlock *, block, lb) { | ||||
| if (block->active) { | if (block->active) { | ||||
| UI_block_draw(C, block); | UI_block_draw(C, block); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* can be called with C==NULL */ | |||||
| void UI_blocklist_free(const bContext *C, ARegion *region) | void UI_blocklist_free(const bContext *C, ARegion *region) | ||||
| { | { | ||||
| ListBase *lb = ®ion->uiblocks; | ListBase *lb = ®ion->uiblocks; | ||||
| uiBlock *block; | uiBlock *block; | ||||
| while ((block = BLI_pophead(lb))) { | while ((block = BLI_pophead(lb))) { | ||||
| UI_block_free(C, block); | UI_block_free(C, block); | ||||
| } | } | ||||
| if (region->runtime.block_name_map != NULL) { | if (region->runtime.block_name_map != NULL) { | ||||
| ▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | void UI_block_theme_style_set(uiBlock *block, char theme_style) | ||||
| block->theme_style = theme_style; | block->theme_style = theme_style; | ||||
| } | } | ||||
| bool UI_block_is_search_only(const uiBlock *block) | bool UI_block_is_search_only(const uiBlock *block) | ||||
| { | { | ||||
| return block->flag & UI_BLOCK_SEARCH_ONLY; | return block->flag & UI_BLOCK_SEARCH_ONLY; | ||||
| } | } | ||||
| /** | |||||
| * Use when a block must be searched to give accurate results | |||||
| * for the whole region but shouldn't be displayed. | |||||
| */ | |||||
| void UI_block_set_search_only(uiBlock *block, bool search_only) | void UI_block_set_search_only(uiBlock *block, bool search_only) | ||||
| { | { | ||||
| SET_FLAG_FROM_TEST(block->flag, search_only, UI_BLOCK_SEARCH_ONLY); | SET_FLAG_FROM_TEST(block->flag, search_only, UI_BLOCK_SEARCH_ONLY); | ||||
| } | } | ||||
| static void ui_but_build_drawstr_float(uiBut *but, double value) | static void ui_but_build_drawstr_float(uiBut *but, double value) | ||||
| { | { | ||||
| size_t slen = 0; | size_t slen = 0; | ||||
| ▲ Show 20 Lines • Show All 355 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| size_t alloc_size; | size_t alloc_size; | ||||
| const char *alloc_str; | const char *alloc_str; | ||||
| ui_but_alloc_info(type, &alloc_size, &alloc_str, NULL); | ui_but_alloc_info(type, &alloc_size, &alloc_str, NULL); | ||||
| return MEM_callocN(alloc_size, alloc_str); | return MEM_callocN(alloc_size, alloc_str); | ||||
| } | } | ||||
| /** | |||||
| * Reallocate the button (new address is returned) for a new button type. | |||||
| * This should generally be avoided and instead the correct type be created right away. | |||||
| * | |||||
| * \note Only the #uiBut data can be kept. If the old button used a derived type (e.g. #uiButTab), | |||||
| * the data that is not inside #uiBut will be lost. | |||||
| */ | |||||
| uiBut *ui_but_change_type(uiBut *but, eButType new_type) | uiBut *ui_but_change_type(uiBut *but, eButType new_type) | ||||
| { | { | ||||
| if (but->type == new_type) { | if (but->type == new_type) { | ||||
| /* Nothing to do. */ | /* Nothing to do. */ | ||||
| return but; | return but; | ||||
| } | } | ||||
| size_t alloc_size; | size_t alloc_size; | ||||
| ▲ Show 20 Lines • Show All 217 Lines • ▼ Show 20 Lines | void ui_def_but_icon(uiBut *but, const int icon, const int flag) | ||||
| but->icon = (BIFIconID)icon; | but->icon = (BIFIconID)icon; | ||||
| but->flag |= flag; | but->flag |= flag; | ||||
| if (but->str && but->str[0]) { | if (but->str && but->str[0]) { | ||||
| but->drawflag |= UI_BUT_ICON_LEFT; | but->drawflag |= UI_BUT_ICON_LEFT; | ||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * Avoid using this where possible since it's better not to ask for an icon in the first place. | |||||
| */ | |||||
| void ui_def_but_icon_clear(uiBut *but) | void ui_def_but_icon_clear(uiBut *but) | ||||
| { | { | ||||
| but->icon = ICON_NONE; | but->icon = ICON_NONE; | ||||
| but->flag &= ~UI_HAS_ICON; | but->flag &= ~UI_HAS_ICON; | ||||
| but->drawflag &= ~UI_BUT_ICON_LEFT; | but->drawflag &= ~UI_BUT_ICON_LEFT; | ||||
| } | } | ||||
| static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *but_p) | static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *but_p) | ||||
| ▲ Show 20 Lines • Show All 1,037 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| wmOperatorType *ot = WM_operatortype_find(opname, 0); | wmOperatorType *ot = WM_operatortype_find(opname, 0); | ||||
| if (str == NULL && ot == NULL) { | if (str == NULL && ot == NULL) { | ||||
| str = opname; | str = opname; | ||||
| } | } | ||||
| return uiDefButO_ptr(block, type, ot, opcontext, str, x, y, width, height, tip); | return uiDefButO_ptr(block, type, ot, opcontext, str, x, y, width, height, tip); | ||||
| } | } | ||||
| /* if a1==1.0 then a2 is an extra icon blending factor (alpha 0.0 - 1.0) */ | |||||
| uiBut *uiDefIconBut(uiBlock *block, | uiBut *uiDefIconBut(uiBlock *block, | ||||
| int type, | int type, | ||||
| int retval, | int retval, | ||||
| int icon, | int icon, | ||||
| int x, | int x, | ||||
| int y, | int y, | ||||
| short width, | short width, | ||||
| short height, | short height, | ||||
| ▲ Show 20 Lines • Show All 363 Lines • ▼ Show 20 Lines | uiBut *uiDefIconButO(uiBlock *block, | ||||
| short width, | short width, | ||||
| short height, | short height, | ||||
| const char *tip) | const char *tip) | ||||
| { | { | ||||
| wmOperatorType *ot = WM_operatortype_find(opname, 0); | wmOperatorType *ot = WM_operatortype_find(opname, 0); | ||||
| return uiDefIconButO_ptr(block, type, ot, opcontext, icon, x, y, width, height, tip); | return uiDefIconButO_ptr(block, type, ot, opcontext, icon, x, y, width, height, tip); | ||||
| } | } | ||||
| /* Button containing both string label and icon */ | |||||
| uiBut *uiDefIconTextBut(uiBlock *block, | uiBut *uiDefIconTextBut(uiBlock *block, | ||||
| int type, | int type, | ||||
| int retval, | int retval, | ||||
| int icon, | int icon, | ||||
| const char *str, | const char *str, | ||||
| int x, | int x, | ||||
| int y, | int y, | ||||
| short width, | short width, | ||||
| ▲ Show 20 Lines • Show All 414 Lines • ▼ Show 20 Lines | int UI_blocklist_min_y_get(ListBase *lb) | ||||
| return min; | return min; | ||||
| } | } | ||||
| void UI_block_direction_set(uiBlock *block, char direction) | void UI_block_direction_set(uiBlock *block, char direction) | ||||
| { | { | ||||
| block->direction = direction; | block->direction = direction; | ||||
| } | } | ||||
| /* this call escapes if there's alignment flags */ | |||||
| void UI_block_order_flip(uiBlock *block) | void UI_block_order_flip(uiBlock *block) | ||||
| { | { | ||||
| float centy, miny = 10000, maxy = -10000; | float centy, miny = 10000, maxy = -10000; | ||||
| if (U.uiflag & USER_MENUFIXEDORDER) { | if (U.uiflag & USER_MENUFIXEDORDER) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (block->flag & UI_BLOCK_NO_FLIP) { | if (block->flag & UI_BLOCK_NO_FLIP) { | ||||
| ▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | void UI_but_drag_set_id(uiBut *but, ID *id) | ||||
| but->dragtype = WM_DRAG_ID; | but->dragtype = WM_DRAG_ID; | ||||
| if (but->dragflag & UI_BUT_DRAGPOIN_FREE) { | if (but->dragflag & UI_BUT_DRAGPOIN_FREE) { | ||||
| WM_drag_data_free(but->dragtype, but->dragpoin); | WM_drag_data_free(but->dragtype, but->dragpoin); | ||||
| but->dragflag &= ~UI_BUT_DRAGPOIN_FREE; | but->dragflag &= ~UI_BUT_DRAGPOIN_FREE; | ||||
| } | } | ||||
| but->dragpoin = (void *)id; | but->dragpoin = (void *)id; | ||||
| } | } | ||||
| /** | |||||
| * Set an image to display while dragging. This works for any drag type (`WM_DRAG_XXX`). | |||||
| * Not to be confused with #UI_but_drag_set_image(), which sets up dragging of an image. | |||||
| */ | |||||
| void UI_but_drag_attach_image(uiBut *but, struct ImBuf *imb, const float scale) | void UI_but_drag_attach_image(uiBut *but, struct ImBuf *imb, const float scale) | ||||
| { | { | ||||
| but->imb = imb; | but->imb = imb; | ||||
| but->imb_scale = scale; | but->imb_scale = scale; | ||||
| } | } | ||||
| /** | |||||
| * \param asset: May be passed from a temporary variable, drag data only stores a copy of this. | |||||
| */ | |||||
| void UI_but_drag_set_asset(uiBut *but, | void UI_but_drag_set_asset(uiBut *but, | ||||
| const AssetHandle *asset, | const AssetHandle *asset, | ||||
| const char *path, | const char *path, | ||||
| struct AssetMetaData *metadata, | struct AssetMetaData *metadata, | ||||
| int import_type, | int import_type, | ||||
| int icon, | int icon, | ||||
| struct ImBuf *imb, | struct ImBuf *imb, | ||||
| float scale) | float scale) | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | void UI_but_drag_set_name(uiBut *but, const char *name) | ||||
| but->dragtype = WM_DRAG_NAME; | but->dragtype = WM_DRAG_NAME; | ||||
| if (but->dragflag & UI_BUT_DRAGPOIN_FREE) { | if (but->dragflag & UI_BUT_DRAGPOIN_FREE) { | ||||
| WM_drag_data_free(but->dragtype, but->dragpoin); | WM_drag_data_free(but->dragtype, but->dragpoin); | ||||
| but->dragflag &= ~UI_BUT_DRAGPOIN_FREE; | but->dragflag &= ~UI_BUT_DRAGPOIN_FREE; | ||||
| } | } | ||||
| but->dragpoin = (void *)name; | but->dragpoin = (void *)name; | ||||
| } | } | ||||
| /* value from button itself */ | |||||
| void UI_but_drag_set_value(uiBut *but) | void UI_but_drag_set_value(uiBut *but) | ||||
| { | { | ||||
| but->dragtype = WM_DRAG_VALUE; | but->dragtype = WM_DRAG_VALUE; | ||||
| } | } | ||||
| void UI_but_drag_set_image( | void UI_but_drag_set_image( | ||||
| uiBut *but, const char *path, int icon, struct ImBuf *imb, float scale, const bool use_free) | uiBut *but, const char *path, int icon, struct ImBuf *imb, float scale, const bool use_free) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 246 Lines • ▼ Show 20 Lines | uiBut *uiDefIconMenuBut(uiBlock *block, | ||||
| but->drawflag &= ~UI_BUT_ICON_LEFT; | but->drawflag &= ~UI_BUT_ICON_LEFT; | ||||
| but->menu_create_func = func; | but->menu_create_func = func; | ||||
| ui_but_update(but); | ui_but_update(but); | ||||
| return but; | return but; | ||||
| } | } | ||||
| /* Block button containing both string label and icon */ | |||||
| uiBut *uiDefIconTextBlockBut(uiBlock *block, | uiBut *uiDefIconTextBlockBut(uiBlock *block, | ||||
| uiBlockCreateFunc func, | uiBlockCreateFunc func, | ||||
| void *arg, | void *arg, | ||||
| int icon, | int icon, | ||||
| const char *str, | const char *str, | ||||
| int x, | int x, | ||||
| int y, | int y, | ||||
| short width, | short width, | ||||
| Show All 12 Lines | uiBut *uiDefIconTextBlockBut(uiBlock *block, | ||||
| ui_but_submenu_enable(block, but); | ui_but_submenu_enable(block, but); | ||||
| but->block_create_func = func; | but->block_create_func = func; | ||||
| ui_but_update(but); | ui_but_update(but); | ||||
| return but; | return but; | ||||
| } | } | ||||
| /* Block button containing icon */ | |||||
| uiBut *uiDefIconBlockBut(uiBlock *block, | uiBut *uiDefIconBlockBut(uiBlock *block, | ||||
| uiBlockCreateFunc func, | uiBlockCreateFunc func, | ||||
| void *arg, | void *arg, | ||||
| int retval, | int retval, | ||||
| int icon, | int icon, | ||||
| int x, | int x, | ||||
| int y, | int y, | ||||
| short width, | short width, | ||||
| Show All 36 Lines | uiBut *but = ui_def_but(block, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| tip); | tip); | ||||
| ui_but_update(but); | ui_but_update(but); | ||||
| return but; | return but; | ||||
| } | } | ||||
| /* short pointers hardcoded */ | |||||
| /* modkeypoin will be set to KM_SHIFT, KM_ALT, KM_CTRL, KM_OSKEY bits */ | |||||
| uiBut *uiDefHotKeyevtButS(uiBlock *block, | uiBut *uiDefHotKeyevtButS(uiBlock *block, | ||||
| int retval, | int retval, | ||||
| const char *str, | const char *str, | ||||
| int x, | int x, | ||||
| int y, | int y, | ||||
| short width, | short width, | ||||
| short height, | short height, | ||||
| short *keypoin, | short *keypoin, | ||||
| Show All 14 Lines | uiBut *but = ui_def_but(block, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| tip); | tip); | ||||
| but->modifier_key = *modkeypoin; | but->modifier_key = *modkeypoin; | ||||
| ui_but_update(but); | ui_but_update(but); | ||||
| return but; | return but; | ||||
| } | } | ||||
| /* arg is pointer to string/name, use UI_but_func_search_set() below to make this work */ | |||||
| /* here a1 and a2, if set, control thumbnail preview rows/cols */ | |||||
| uiBut *uiDefSearchBut(uiBlock *block, | uiBut *uiDefSearchBut(uiBlock *block, | ||||
| void *arg, | void *arg, | ||||
| int retval, | int retval, | ||||
| int icon, | int icon, | ||||
| int maxlen, | int maxlen, | ||||
| int x, | int x, | ||||
| int y, | int y, | ||||
| short width, | short width, | ||||
| Show All 9 Lines | uiBut *uiDefSearchBut(uiBlock *block, | ||||
| but->drawflag |= UI_BUT_ICON_LEFT | UI_BUT_TEXT_LEFT; | but->drawflag |= UI_BUT_ICON_LEFT | UI_BUT_TEXT_LEFT; | ||||
| ui_but_update(but); | ui_but_update(but); | ||||
| return but; | return but; | ||||
| } | } | ||||
| /** | |||||
| * \note The item-pointer (referred to below) is a per search item user pointer | |||||
| * passed to #UI_search_item_add (stored in #uiSearchItems.pointers). | |||||
| * | |||||
| * \param search_create_fn: Function to create the menu. | |||||
| * \param search_update_fn: Function to refresh search content after the search text has changed. | |||||
| * \param arg: user value. | |||||
| * \param free_arg: Set to true if the argument is newly allocated memory for every redraw and | |||||
| * should be freed when the button is destroyed. | |||||
| * \param search_arg_free_fn: When non-null, use this function to free \a arg. | |||||
| * \param search_exec_fn: Function that executes the action, gets \a arg as the first argument. | |||||
| * The second argument as the active item-pointer | |||||
| * \param active: When non-null, this item-pointer item will be visible and selected, | |||||
| * otherwise the first item will be selected. | |||||
| */ | |||||
| void UI_but_func_search_set(uiBut *but, | void UI_but_func_search_set(uiBut *but, | ||||
| uiButSearchCreateFn search_create_fn, | uiButSearchCreateFn search_create_fn, | ||||
| uiButSearchUpdateFn search_update_fn, | uiButSearchUpdateFn search_update_fn, | ||||
| void *arg, | void *arg, | ||||
| const bool free_arg, | const bool free_arg, | ||||
| uiFreeArgFunc search_arg_free_fn, | uiFreeArgFunc search_arg_free_fn, | ||||
| uiButHandleFunc search_exec_fn, | uiButHandleFunc search_exec_fn, | ||||
| void *active) | void *active) | ||||
| ▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
| void UI_but_func_search_set_context_menu(uiBut *but, uiButSearchContextMenuFn context_menu_fn) | void UI_but_func_search_set_context_menu(uiBut *but, uiButSearchContextMenuFn context_menu_fn) | ||||
| { | { | ||||
| uiButSearch *but_search = (uiButSearch *)but; | uiButSearch *but_search = (uiButSearch *)but; | ||||
| BLI_assert(but->type == UI_BTYPE_SEARCH_MENU); | BLI_assert(but->type == UI_BTYPE_SEARCH_MENU); | ||||
| but_search->item_context_menu_fn = context_menu_fn; | but_search->item_context_menu_fn = context_menu_fn; | ||||
| } | } | ||||
| /** | |||||
| * \param search_sep_string: when not NULL, this string is used as a separator, | |||||
| * showing the icon and highlighted text after the last instance of this string. | |||||
| */ | |||||
| void UI_but_func_search_set_sep_string(uiBut *but, const char *search_sep_string) | void UI_but_func_search_set_sep_string(uiBut *but, const char *search_sep_string) | ||||
| { | { | ||||
| uiButSearch *but_search = (uiButSearch *)but; | uiButSearch *but_search = (uiButSearch *)but; | ||||
| BLI_assert(but->type == UI_BTYPE_SEARCH_MENU); | BLI_assert(but->type == UI_BTYPE_SEARCH_MENU); | ||||
| but_search->item_sep_string = search_sep_string; | but_search->item_sep_string = search_sep_string; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | if (ot->prop) { | ||||
| * because one of its parameters is the button itself! */ | * because one of its parameters is the button itself! */ | ||||
| } | } | ||||
| else { | else { | ||||
| printf("%s: op->prop for '%s' is NULL\n", __func__, ot->idname); | printf("%s: op->prop for '%s' is NULL\n", __func__, ot->idname); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * Same parameters as for uiDefSearchBut, with additional operator type and properties, | |||||
| * used by callback to call again the right op with the right options (properties values). | |||||
| */ | |||||
| uiBut *uiDefSearchButO_ptr(uiBlock *block, | uiBut *uiDefSearchButO_ptr(uiBlock *block, | ||||
| wmOperatorType *ot, | wmOperatorType *ot, | ||||
| IDProperty *properties, | IDProperty *properties, | ||||
| void *arg, | void *arg, | ||||
| int retval, | int retval, | ||||
| int icon, | int icon, | ||||
| int maxlen, | int maxlen, | ||||
| int x, | int x, | ||||
| Show All 30 Lines | |||||
| { | { | ||||
| uiButTreeRow *but_row = (uiButTreeRow *)but; | uiButTreeRow *but_row = (uiButTreeRow *)but; | ||||
| BLI_assert(but->type == UI_BTYPE_TREEROW); | BLI_assert(but->type == UI_BTYPE_TREEROW); | ||||
| but_row->indentation = indentation; | but_row->indentation = indentation; | ||||
| BLI_assert(indentation >= 0); | BLI_assert(indentation >= 0); | ||||
| } | } | ||||
| /** | |||||
| * Adds a hint to the button which draws right aligned, grayed out and never clipped. | |||||
| */ | |||||
| void UI_but_hint_drawstr_set(uiBut *but, const char *string) | void UI_but_hint_drawstr_set(uiBut *but, const char *string) | ||||
| { | { | ||||
| ui_but_add_shortcut(but, string, false); | ui_but_add_shortcut(but, string, false); | ||||
| } | } | ||||
| void UI_but_node_link_set(uiBut *but, bNodeSocket *socket, const float draw_color[4]) | void UI_but_node_link_set(uiBut *but, bNodeSocket *socket, const float draw_color[4]) | ||||
| { | { | ||||
| but->flag |= UI_BUT_NODE_LINK; | but->flag |= UI_BUT_NODE_LINK; | ||||
| Show All 15 Lines | void UI_but_number_precision_set(uiBut *but, float precision) | ||||
| uiButNumber *but_number = (uiButNumber *)but; | uiButNumber *but_number = (uiButNumber *)but; | ||||
| BLI_assert(but->type == UI_BTYPE_NUM); | BLI_assert(but->type == UI_BTYPE_NUM); | ||||
| but_number->precision = precision; | but_number->precision = precision; | ||||
| /* -1 is a valid value, UI code figures out an appropriate precision then. */ | /* -1 is a valid value, UI code figures out an appropriate precision then. */ | ||||
| BLI_assert(precision > -2); | BLI_assert(precision > -2); | ||||
| } | } | ||||
| /** | |||||
| * push a new event onto event queue to activate the given button | |||||
| * (usually a text-field) upon entering a popup | |||||
| */ | |||||
| void UI_but_focus_on_enter_event(wmWindow *win, uiBut *but) | void UI_but_focus_on_enter_event(wmWindow *win, uiBut *but) | ||||
| { | { | ||||
| wmEvent event; | wmEvent event; | ||||
| wm_event_init_from_window(win, &event); | wm_event_init_from_window(win, &event); | ||||
| event.type = EVT_BUT_OPEN; | event.type = EVT_BUT_OPEN; | ||||
| event.val = KM_PRESS; | event.val = KM_PRESS; | ||||
| event.is_repeat = false; | event.is_repeat = false; | ||||
| ▲ Show 20 Lines • Show All 286 Lines • ▼ Show 20 Lines | |||||
| /* Program Init/Exit */ | /* Program Init/Exit */ | ||||
| void UI_init(void) | void UI_init(void) | ||||
| { | { | ||||
| ui_resources_init(); | ui_resources_init(); | ||||
| } | } | ||||
| /* after reading userdef file */ | |||||
| void UI_init_userdef(void) | void UI_init_userdef(void) | ||||
| { | { | ||||
| /* Initialize UI variables from values set in the preferences. */ | /* Initialize UI variables from values set in the preferences. */ | ||||
| uiStyleInit(); | uiStyleInit(); | ||||
| } | } | ||||
| void UI_reinit_font(void) | void UI_reinit_font(void) | ||||
| { | { | ||||
| Show All 13 Lines | |||||