Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_handlers.c
| Show First 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | |||||
| #define USE_KEYNAV_LIMIT | #define USE_KEYNAV_LIMIT | ||||
| /* drag popups by their header */ | /* drag popups by their header */ | ||||
| #define USE_DRAG_POPUP | #define USE_DRAG_POPUP | ||||
| #define UI_MAX_PASSWORD_STR 128 | #define UI_MAX_PASSWORD_STR 128 | ||||
| /* proto */ | /* proto */ | ||||
| static void ui_add_smart_controller(bContext *C, uiBut *from, uiBut *to); | static void ui_but_smart_controller_add(bContext *C, uiBut *from, uiBut *to); | ||||
| static void ui_add_link(bContext *C, uiBut *from, uiBut *to); | static void ui_but_link_add(bContext *C, uiBut *from, uiBut *to); | ||||
| static int ui_do_but_EXIT(bContext *C, uiBut *but, struct uiHandleButtonData *data, const wmEvent *event); | static int ui_do_but_EXIT(bContext *C, uiBut *but, struct uiHandleButtonData *data, const wmEvent *event); | ||||
| #ifdef USE_KEYNAV_LIMIT | #ifdef USE_KEYNAV_LIMIT | ||||
| static void ui_mouse_motion_keynav_init(struct uiKeyNavLock *keynav, const wmEvent *event); | static void ui_mouse_motion_keynav_init(struct uiKeyNavLock *keynav, const wmEvent *event); | ||||
| static bool ui_mouse_motion_keynav_test(struct uiKeyNavLock *keynav, const wmEvent *event); | static bool ui_mouse_motion_keynav_test(struct uiKeyNavLock *keynav, const wmEvent *event); | ||||
| #endif | #endif | ||||
| /***************** structs and defines ****************/ | /***************** structs and defines ****************/ | ||||
| ▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | #endif | ||||
| int draglastvalue; | int draglastvalue; | ||||
| int dragstartvalue; | int dragstartvalue; | ||||
| bool dragchange, draglock; | bool dragchange, draglock; | ||||
| int dragsel; | int dragsel; | ||||
| float dragf, dragfstart; | float dragf, dragfstart; | ||||
| CBData *dragcbd; | CBData *dragcbd; | ||||
| #ifdef USE_CONT_MOUSE_CORRECT | #ifdef USE_CONT_MOUSE_CORRECT | ||||
| /* when ungrabbing buttons which are #ui_is_a_warp_but(), we may want to position them | /* when ungrabbing buttons which are #ui_but_is_cursor_warp(), we may want to position them | ||||
| * FLT_MAX signifies do-nothing, use #ui_block_to_window_fl() to get this into a usable space */ | * FLT_MAX signifies do-nothing, use #ui_block_to_window_fl() to get this into a usable space */ | ||||
| float ungrab_mval[2]; | float ungrab_mval[2]; | ||||
| #endif | #endif | ||||
| /* menu open (watch uiFreeActiveButtons) */ | /* menu open (watch UI_screen_free_active_but) */ | ||||
| uiPopupBlockHandle *menu; | uiPopupBlockHandle *menu; | ||||
| int menuretval; | int menuretval; | ||||
| /* search box (watch uiFreeActiveButtons) */ | /* search box (watch UI_screen_free_active_but) */ | ||||
| ARegion *searchbox; | ARegion *searchbox; | ||||
| #ifdef USE_KEYNAV_LIMIT | #ifdef USE_KEYNAV_LIMIT | ||||
| struct uiKeyNavLock searchbox_keynav_state; | struct uiKeyNavLock searchbox_keynav_state; | ||||
| #endif | #endif | ||||
| #ifdef USE_DRAG_MULTINUM | #ifdef USE_DRAG_MULTINUM | ||||
| /* Multi-buttons will be updated in unison with the active button. */ | /* Multi-buttons will be updated in unison with the active button. */ | ||||
| uiHandleButtonMulti multi_data; | uiHandleButtonMulti multi_data; | ||||
| Show All 35 Lines | typedef struct uiAfterFunc { | ||||
| bContextStore *context; | bContextStore *context; | ||||
| char undostr[BKE_UNDO_STR_MAX]; | char undostr[BKE_UNDO_STR_MAX]; | ||||
| } uiAfterFunc; | } uiAfterFunc; | ||||
| static bool ui_is_but_interactive(const uiBut *but, const bool labeledit); | static bool ui_but_is_interactive(const uiBut *but, const bool labeledit); | ||||
| static bool ui_but_contains_pt(uiBut *but, float mx, float my); | static bool ui_but_contains_pt(uiBut *but, float mx, float my); | ||||
| static bool ui_mouse_inside_button(ARegion *ar, uiBut *but, int x, int y); | static bool ui_but_contains_point_px(ARegion *ar, uiBut *but, int x, int y); | ||||
| static uiBut *ui_but_find_mouse_over_ex(ARegion *ar, const int x, const int y, const bool labeledit); | static uiBut *ui_but_find_mouse_over_ex(ARegion *ar, const int x, const int y, const bool labeledit); | ||||
| static uiBut *ui_but_find_mouse_over(ARegion *ar, const wmEvent *event); | static uiBut *ui_but_find_mouse_over(ARegion *ar, const wmEvent *event); | ||||
| static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonActivateType type); | static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonActivateType type); | ||||
| static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState state); | static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState state); | ||||
| static void button_activate_exit(bContext *C, uiBut *but, uiHandleButtonData *data, | static void button_activate_exit(bContext *C, uiBut *but, uiHandleButtonData *data, | ||||
| const bool mousemove, const bool onfree); | const bool mousemove, const bool onfree); | ||||
| static int ui_handler_region_menu(bContext *C, const wmEvent *event, void *userdata); | static int ui_handler_region_menu(bContext *C, const wmEvent *event, void *userdata); | ||||
| static void ui_handle_button_activate(bContext *C, ARegion *ar, uiBut *but, uiButtonActivateType type); | static void ui_handle_button_activate(bContext *C, ARegion *ar, uiBut *but, uiButtonActivateType type); | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | if (ABS(lastdy) > (int)UI_UNIT_Y) { | ||||
| lastdy = 0; | lastdy = 0; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| bool ui_but_is_editable(const uiBut *but) | bool ui_but_is_editable(const uiBut *but) | ||||
| { | { | ||||
| return !ELEM(but->type, LABEL, SEPR, SEPRLINE, ROUNDBOX, LISTBOX, PROGRESSBAR); | return !ELEM(but->type, UI_BTYPE_LABEL, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE, UI_BTYPE_ROUNDBOX, UI_BTYPE_LISTBOX, UI_BTYPE_PROGRESS_BAR); | ||||
| } | } | ||||
| static uiBut *ui_but_prev(uiBut *but) | static uiBut *ui_but_prev(uiBut *but) | ||||
| { | { | ||||
| while (but->prev) { | while (but->prev) { | ||||
| but = but->prev; | but = but->prev; | ||||
| if (ui_but_is_editable(but)) return but; | if (ui_but_is_editable(but)) return but; | ||||
| } | } | ||||
| Show All 28 Lines | static uiBut *ui_but_last(uiBlock *block) | ||||
| but = block->buttons.last; | but = block->buttons.last; | ||||
| while (but) { | while (but) { | ||||
| if (ui_but_is_editable(but)) return but; | if (ui_but_is_editable(but)) return but; | ||||
| but = but->prev; | but = but->prev; | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| static bool ui_is_a_warp_but(uiBut *but) | static bool ui_but_is_cursor_warp(uiBut *but) | ||||
| { | { | ||||
| if (U.uiflag & USER_CONTINUOUS_MOUSE) { | if (U.uiflag & USER_CONTINUOUS_MOUSE) { | ||||
| if (ELEM(but->type, NUM, NUMSLI, HSVCIRCLE, TRACKPREVIEW, HSVCUBE, BUT_CURVE)) { | if (ELEM(but->type, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER, UI_BTYPE_HSVCIRCLE, UI_BTYPE_TRACK_PREVIEW, UI_BTYPE_HSVCUBE, UI_BTYPE_CURVE)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| static float ui_mouse_scale_warp_factor(const bool shift) | static float ui_mouse_scale_warp_factor(const bool shift) | ||||
| Show All 9 Lines | static void ui_mouse_scale_warp(uiHandleButtonData *data, | ||||
| const float fac = ui_mouse_scale_warp_factor(shift); | const float fac = ui_mouse_scale_warp_factor(shift); | ||||
| /* slow down the mouse, this is fairly picky */ | /* slow down the mouse, this is fairly picky */ | ||||
| *r_mx = (data->dragstartx * (1.0f - fac) + mx * fac); | *r_mx = (data->dragstartx * (1.0f - fac) + mx * fac); | ||||
| *r_my = (data->dragstarty * (1.0f - fac) + my * fac); | *r_my = (data->dragstarty * (1.0f - fac) + my * fac); | ||||
| } | } | ||||
| /* file selectors are exempt from utf-8 checks */ | /* file selectors are exempt from utf-8 checks */ | ||||
| bool ui_is_but_utf8(const uiBut *but) | bool ui_but_is_utf8(const uiBut *but) | ||||
| { | { | ||||
| if (but->rnaprop) { | if (but->rnaprop) { | ||||
| const int subtype = RNA_property_subtype(but->rnaprop); | const int subtype = RNA_property_subtype(but->rnaprop); | ||||
| return !(ELEM(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME, PROP_BYTESTRING)); | return !(ELEM(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME, PROP_BYTESTRING)); | ||||
| } | } | ||||
| else { | else { | ||||
| return !(but->flag & UI_BUT_NO_UTF8); | return !(but->flag & UI_BUT_NO_UTF8); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | static void ui_apply_but_func(bContext *C, uiBut *but) | ||||
| uiAfterFunc *after; | uiAfterFunc *after; | ||||
| uiBlock *block = but->block; | uiBlock *block = but->block; | ||||
| /* these functions are postponed and only executed after all other | /* these functions are postponed and only executed after all other | ||||
| * handling is done, i.e. menus are closed, in order to avoid conflicts | * handling is done, i.e. menus are closed, in order to avoid conflicts | ||||
| * with these functions removing the buttons we are working with */ | * with these functions removing the buttons we are working with */ | ||||
| if (but->func || but->funcN || block->handle_func || but->rename_func || | if (but->func || but->funcN || block->handle_func || but->rename_func || | ||||
| (but->type == BUTM && block->butm_func) || but->optype || but->rnaprop) | (but->type == UI_BTYPE_BUT_MENU && block->butm_func) || but->optype || but->rnaprop) | ||||
| { | { | ||||
| after = ui_afterfunc_new(); | after = ui_afterfunc_new(); | ||||
| if (but->func && ELEM(but, but->func_arg1, but->func_arg2)) { | if (but->func && ELEM(but, but->func_arg1, but->func_arg2)) { | ||||
| /* exception, this will crash due to removed button otherwise */ | /* exception, this will crash due to removed button otherwise */ | ||||
| but->func(C, but->func_arg1, but->func_arg2); | but->func(C, but->func_arg1, but->func_arg2); | ||||
| } | } | ||||
| else | else | ||||
| after->func = but->func; | after->func = but->func; | ||||
| after->func_arg1 = but->func_arg1; | after->func_arg1 = but->func_arg1; | ||||
| after->func_arg2 = but->func_arg2; | after->func_arg2 = but->func_arg2; | ||||
| after->funcN = but->funcN; | after->funcN = but->funcN; | ||||
| after->func_argN = (but->func_argN) ? MEM_dupallocN(but->func_argN) : NULL; | after->func_argN = (but->func_argN) ? MEM_dupallocN(but->func_argN) : NULL; | ||||
| after->rename_func = but->rename_func; | after->rename_func = but->rename_func; | ||||
| after->rename_arg1 = but->rename_arg1; | after->rename_arg1 = but->rename_arg1; | ||||
| after->rename_orig = but->rename_orig; /* needs free! */ | after->rename_orig = but->rename_orig; /* needs free! */ | ||||
| after->handle_func = block->handle_func; | after->handle_func = block->handle_func; | ||||
| after->handle_func_arg = block->handle_func_arg; | after->handle_func_arg = block->handle_func_arg; | ||||
| after->retval = but->retval; | after->retval = but->retval; | ||||
| if (but->type == BUTM) { | if (but->type == UI_BTYPE_BUT_MENU) { | ||||
| after->butm_func = block->butm_func; | after->butm_func = block->butm_func; | ||||
| after->butm_func_arg = block->butm_func_arg; | after->butm_func_arg = block->butm_func_arg; | ||||
| after->a2 = but->a2; | after->a2 = but->a2; | ||||
| } | } | ||||
| after->optype = but->optype; | after->optype = but->optype; | ||||
| after->opcontext = but->opcontext; | after->opcontext = but->opcontext; | ||||
| after->opptr = but->opptr; | after->opptr = but->opptr; | ||||
| after->rnapoin = but->rnapoin; | after->rnapoin = but->rnapoin; | ||||
| after->rnaprop = but->rnaprop; | after->rnaprop = but->rnaprop; | ||||
| if (but->context) | if (but->context) | ||||
| after->context = CTX_store_copy(but->context); | after->context = CTX_store_copy(but->context); | ||||
| but->optype = NULL; | but->optype = NULL; | ||||
| but->opcontext = 0; | but->opcontext = 0; | ||||
| but->opptr = NULL; | but->opptr = NULL; | ||||
| } | } | ||||
| } | } | ||||
| /* typically call ui_apply_undo(), ui_apply_autokey() */ | /* typically call ui_apply_but_undo(), ui_apply_but_autokey() */ | ||||
| static void ui_apply_undo(uiBut *but) | static void ui_apply_but_undo(uiBut *but) | ||||
| { | { | ||||
| uiAfterFunc *after; | uiAfterFunc *after; | ||||
| if (but->flag & UI_BUT_UNDO) { | if (but->flag & UI_BUT_UNDO) { | ||||
| const char *str = NULL; | const char *str = NULL; | ||||
| /* define which string to use for undo */ | /* define which string to use for undo */ | ||||
| if (ELEM(but->type, LINK, INLINK)) str = "Add button link"; | if (ELEM(but->type, UI_BTYPE_LINK, UI_BTYPE_INLINK)) str = "Add button link"; | ||||
| else if (but->type == MENU) str = but->drawstr; | else if (but->type == UI_BTYPE_MENU) str = but->drawstr; | ||||
| else if (but->drawstr[0]) str = but->drawstr; | else if (but->drawstr[0]) str = but->drawstr; | ||||
| else str = but->tip; | else str = but->tip; | ||||
| /* fallback, else we don't get an undo! */ | /* fallback, else we don't get an undo! */ | ||||
| if (str == NULL || str[0] == '\0') { | if (str == NULL || str[0] == '\0') { | ||||
| str = "Unknown Action"; | str = "Unknown Action"; | ||||
| } | } | ||||
| /* delayed, after all other funcs run, popups are closed, etc */ | /* delayed, after all other funcs run, popups are closed, etc */ | ||||
| after = ui_afterfunc_new(); | after = ui_afterfunc_new(); | ||||
| BLI_strncpy(after->undostr, str, sizeof(after->undostr)); | BLI_strncpy(after->undostr, str, sizeof(after->undostr)); | ||||
| } | } | ||||
| } | } | ||||
| static void ui_apply_autokey(bContext *C, uiBut *but) | static void ui_apply_but_autokey(bContext *C, uiBut *but) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| /* try autokey */ | /* try autokey */ | ||||
| ui_but_anim_autokey(C, but, scene, scene->r.cfra); | ui_but_anim_autokey(C, but, scene, scene->r.cfra); | ||||
| /* make a little report about what we've done! */ | /* make a little report about what we've done! */ | ||||
| if (but->rnaprop) { | if (but->rnaprop) { | ||||
| ▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | static void ui_apply_but_BUT(bContext *C, uiBut *but, uiHandleButtonData *data) | ||||
| ui_apply_but_func(C, but); | ui_apply_but_func(C, but); | ||||
| data->retval = but->retval; | data->retval = but->retval; | ||||
| data->applied = true; | data->applied = true; | ||||
| } | } | ||||
| static void ui_apply_but_BUTM(bContext *C, uiBut *but, uiHandleButtonData *data) | static void ui_apply_but_BUTM(bContext *C, uiBut *but, uiHandleButtonData *data) | ||||
| { | { | ||||
| ui_set_but_val(but, but->hardmin); | ui_but_value_set(but, but->hardmin); | ||||
| ui_apply_but_func(C, but); | ui_apply_but_func(C, but); | ||||
| data->retval = but->retval; | data->retval = but->retval; | ||||
| data->applied = true; | data->applied = true; | ||||
| } | } | ||||
| static void ui_apply_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data) | static void ui_apply_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data) | ||||
| { | { | ||||
| if (but->type == MENU) | if (but->type == UI_BTYPE_MENU) | ||||
| ui_set_but_val(but, data->value); | ui_but_value_set(but, data->value); | ||||
| ui_check_but(but); | ui_but_update(but); | ||||
| ui_apply_but_func(C, but); | ui_apply_but_func(C, but); | ||||
| data->retval = but->retval; | data->retval = but->retval; | ||||
| data->applied = true; | data->applied = true; | ||||
| } | } | ||||
| static void ui_apply_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data) | static void ui_apply_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data) | ||||
| { | { | ||||
| double value; | double value; | ||||
| int w, lvalue, push; | int w, lvalue, push; | ||||
| value = ui_get_but_val(but); | value = ui_but_value_get(but); | ||||
| lvalue = (int)value; | lvalue = (int)value; | ||||
| if (but->bit) { | if (but->bit) { | ||||
| w = UI_BITBUT_TEST(lvalue, but->bitnr); | w = UI_BITBUT_TEST(lvalue, but->bitnr); | ||||
| if (w) lvalue = UI_BITBUT_CLR(lvalue, but->bitnr); | if (w) lvalue = UI_BITBUT_CLR(lvalue, but->bitnr); | ||||
| else lvalue = UI_BITBUT_SET(lvalue, but->bitnr); | else lvalue = UI_BITBUT_SET(lvalue, but->bitnr); | ||||
| ui_set_but_val(but, (double)lvalue); | ui_but_value_set(but, (double)lvalue); | ||||
| if (but->type == ICONTOG || but->type == ICONTOGN) ui_check_but(but); | if (but->type == UI_BTYPE_ICON_TOGGLE || but->type == UI_BTYPE_ICON_TOGGLE_N) ui_but_update(but); | ||||
| } | } | ||||
| else { | else { | ||||
| if (value == 0.0) push = 1; | if (value == 0.0) push = 1; | ||||
| else push = 0; | else push = 0; | ||||
| if (ELEM(but->type, TOGN, ICONTOGN, OPTIONN)) push = !push; | if (ELEM(but->type, UI_BTYPE_TOGGLE_N, UI_BTYPE_ICON_TOGGLE_N, UI_BTYPE_CHECKBOX_N)) push = !push; | ||||
| ui_set_but_val(but, (double)push); | ui_but_value_set(but, (double)push); | ||||
| if (but->type == ICONTOG || but->type == ICONTOGN) ui_check_but(but); | if (but->type == UI_BTYPE_ICON_TOGGLE || but->type == UI_BTYPE_ICON_TOGGLE_N) ui_but_update(but); | ||||
| } | } | ||||
| ui_apply_but_func(C, but); | ui_apply_but_func(C, but); | ||||
| data->retval = but->retval; | data->retval = but->retval; | ||||
| data->applied = true; | data->applied = true; | ||||
| } | } | ||||
| static void ui_apply_but_ROW(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data) | static void ui_apply_but_ROW(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data) | ||||
| { | { | ||||
| uiBut *bt; | uiBut *bt; | ||||
| ui_set_but_val(but, but->hardmax); | ui_but_value_set(but, but->hardmax); | ||||
| ui_apply_but_func(C, but); | ui_apply_but_func(C, but); | ||||
| /* states of other row buttons */ | /* states of other row buttons */ | ||||
| for (bt = block->buttons.first; bt; bt = bt->next) | for (bt = block->buttons.first; bt; bt = bt->next) | ||||
| if (bt != but && bt->poin == but->poin && ELEM(bt->type, ROW, LISTROW)) | if (bt != but && bt->poin == but->poin && ELEM(bt->type, UI_BTYPE_ROW, UI_BTYPE_LISTROW)) | ||||
| ui_check_but(bt); | ui_but_update(bt); | ||||
| data->retval = but->retval; | data->retval = but->retval; | ||||
| data->applied = true; | data->applied = true; | ||||
| } | } | ||||
| static void ui_apply_but_TEX(bContext *C, uiBut *but, uiHandleButtonData *data) | static void ui_apply_but_TEX(bContext *C, uiBut *but, uiHandleButtonData *data) | ||||
| { | { | ||||
| if (!data->str) | if (!data->str) | ||||
| return; | return; | ||||
| ui_set_but_string(C, but, data->str); | ui_but_string_set(C, but, data->str); | ||||
| ui_check_but(but); | ui_but_update(but); | ||||
| /* give butfunc the original text too */ | /* give butfunc the original text too */ | ||||
| /* feature used for bone renaming, channels, etc */ | /* feature used for bone renaming, channels, etc */ | ||||
| /* afterfunc frees origstr */ | /* afterfunc frees origstr */ | ||||
| but->rename_orig = data->origstr; | but->rename_orig = data->origstr; | ||||
| data->origstr = NULL; | data->origstr = NULL; | ||||
| ui_apply_but_func(C, but); | ui_apply_but_func(C, but); | ||||
| data->retval = but->retval; | data->retval = but->retval; | ||||
| data->applied = true; | data->applied = true; | ||||
| } | } | ||||
| static void ui_apply_but_NUM(bContext *C, uiBut *but, uiHandleButtonData *data) | static void ui_apply_but_NUM(bContext *C, uiBut *but, uiHandleButtonData *data) | ||||
| { | { | ||||
| if (data->str) { | if (data->str) { | ||||
| if (ui_set_but_string(C, but, data->str)) { | if (ui_but_string_set(C, but, data->str)) { | ||||
| data->value = ui_get_but_val(but); | data->value = ui_but_value_get(but); | ||||
| } | } | ||||
| else { | else { | ||||
| data->cancel = true; | data->cancel = true; | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| else | else | ||||
| ui_set_but_val(but, data->value); | ui_but_value_set(but, data->value); | ||||
| ui_check_but(but); | ui_but_update(but); | ||||
| ui_apply_but_func(C, but); | ui_apply_but_func(C, but); | ||||
| data->retval = but->retval; | data->retval = but->retval; | ||||
| data->applied = true; | data->applied = true; | ||||
| } | } | ||||
| static void ui_apply_but_VEC(bContext *C, uiBut *but, uiHandleButtonData *data) | static void ui_apply_but_VEC(bContext *C, uiBut *but, uiHandleButtonData *data) | ||||
| { | { | ||||
| ui_set_but_vectorf(but, data->vec); | ui_but_v3_set(but, data->vec); | ||||
| ui_check_but(but); | ui_but_update(but); | ||||
| ui_apply_but_func(C, but); | ui_apply_but_func(C, but); | ||||
| data->retval = but->retval; | data->retval = but->retval; | ||||
| data->applied = true; | data->applied = true; | ||||
| } | } | ||||
| static void ui_apply_but_COLORBAND(bContext *C, uiBut *but, uiHandleButtonData *data) | static void ui_apply_but_COLORBAND(bContext *C, uiBut *but, uiHandleButtonData *data) | ||||
| { | { | ||||
| Show All 20 Lines | static void ui_multibut_add(uiHandleButtonData *data, uiBut *but) | ||||
| uiButMultiState *mbut_state; | uiButMultiState *mbut_state; | ||||
| BLI_assert(but->flag & UI_BUT_DRAG_MULTI); | BLI_assert(but->flag & UI_BUT_DRAG_MULTI); | ||||
| BLI_assert(data->multi_data.has_mbuts); | BLI_assert(data->multi_data.has_mbuts); | ||||
| mbut_state = MEM_callocN(sizeof(*mbut_state), __func__); | mbut_state = MEM_callocN(sizeof(*mbut_state), __func__); | ||||
| mbut_state->but = but; | mbut_state->but = but; | ||||
| mbut_state->origvalue = ui_get_but_val(but); | mbut_state->origvalue = ui_but_value_get(but); | ||||
| BLI_linklist_prepend(&data->multi_data.mbuts, mbut_state); | BLI_linklist_prepend(&data->multi_data.mbuts, mbut_state); | ||||
| UI_butstore_register(data->multi_data.bs_mbuts, &mbut_state->but); | UI_butstore_register(data->multi_data.bs_mbuts, &mbut_state->but); | ||||
| } | } | ||||
| static uiButMultiState *ui_multibut_lookup(uiHandleButtonData *data, const uiBut *but) | static uiButMultiState *ui_multibut_lookup(uiHandleButtonData *data, const uiBut *but) | ||||
| { | { | ||||
| Show All 15 Lines | |||||
| static void ui_multibut_restore(uiHandleButtonData *data, uiBlock *block) | static void ui_multibut_restore(uiHandleButtonData *data, uiBlock *block) | ||||
| { | { | ||||
| uiBut *but; | uiBut *but; | ||||
| for (but = block->buttons.first; but; but = but->next) { | for (but = block->buttons.first; but; but = but->next) { | ||||
| if (but->flag & UI_BUT_DRAG_MULTI) { | if (but->flag & UI_BUT_DRAG_MULTI) { | ||||
| uiButMultiState *mbut_state = ui_multibut_lookup(data, but); | uiButMultiState *mbut_state = ui_multibut_lookup(data, but); | ||||
| if (mbut_state) { | if (mbut_state) { | ||||
| ui_set_but_val(but, mbut_state->origvalue); | ui_but_value_set(but, mbut_state->origvalue); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void ui_multibut_free(uiHandleButtonData *data, uiBlock *block) | static void ui_multibut_free(uiHandleButtonData *data, uiBlock *block) | ||||
| { | { | ||||
| BLI_linklist_freeN(data->multi_data.mbuts); | BLI_linklist_freeN(data->multi_data.mbuts); | ||||
| Show All 30 Lines | for (but = but_active->block->buttons.first; but; but = but->next) { | ||||
| bool drag_curr = false; | bool drag_curr = false; | ||||
| /* re-set each time */ | /* re-set each time */ | ||||
| if (but->flag & UI_BUT_DRAG_MULTI) { | if (but->flag & UI_BUT_DRAG_MULTI) { | ||||
| but->flag &= ~UI_BUT_DRAG_MULTI; | but->flag &= ~UI_BUT_DRAG_MULTI; | ||||
| drag_prev = true; | drag_prev = true; | ||||
| } | } | ||||
| if (ui_is_but_interactive(but, false)) { | if (ui_but_is_interactive(but, false)) { | ||||
| /* drag checks */ | /* drag checks */ | ||||
| if (but_active != but) { | if (but_active != but) { | ||||
| if (ui_is_but_compatible(but_active, but)) { | if (ui_but_is_compatible(but_active, but)) { | ||||
| BLI_assert(but->active == NULL); | BLI_assert(but->active == NULL); | ||||
| /* finally check for overlap */ | /* finally check for overlap */ | ||||
| if (BLI_rctf_isect_segment(&but->rect, seg[0], seg[1])) { | if (BLI_rctf_isect_segment(&but->rect, seg[0], seg[1])) { | ||||
| but->flag |= UI_BUT_DRAG_MULTI; | but->flag |= UI_BUT_DRAG_MULTI; | ||||
| data->multi_data.has_mbuts = true; | data->multi_data.has_mbuts = true; | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | static void ui_multibut_states_apply(bContext *C, uiHandleButtonData *data, uiBlock *block) | ||||
| for (but = block->buttons.first; but; but = but->next) { | for (but = block->buttons.first; but; but = but->next) { | ||||
| if (but->flag & UI_BUT_DRAG_MULTI) { | if (but->flag & UI_BUT_DRAG_MULTI) { | ||||
| /* mbut_states for delta */ | /* mbut_states for delta */ | ||||
| uiButMultiState *mbut_state = ui_multibut_lookup(data, but); | uiButMultiState *mbut_state = ui_multibut_lookup(data, but); | ||||
| if (mbut_state) { | if (mbut_state) { | ||||
| void *active_back; | void *active_back; | ||||
| ui_button_execute_begin(C, ar, but, &active_back); | ui_but_execute_begin(C, ar, but, &active_back); | ||||
| BLI_assert(active_back == NULL); | BLI_assert(active_back == NULL); | ||||
| /* no need to check 'data->state' here */ | /* no need to check 'data->state' here */ | ||||
| if (data->str) { | if (data->str) { | ||||
| /* entering text (set all) */ | /* entering text (set all) */ | ||||
| but->active->value = data->value; | but->active->value = data->value; | ||||
| ui_set_but_string(C, but, data->str); | ui_but_string_set(C, but, data->str); | ||||
| } | } | ||||
| else { | else { | ||||
| /* dragging (use delta) */ | /* dragging (use delta) */ | ||||
| if (data->multi_data.is_proportional) { | if (data->multi_data.is_proportional) { | ||||
| but->active->value = mbut_state->origvalue * value_scale; | but->active->value = mbut_state->origvalue * value_scale; | ||||
| } | } | ||||
| else { | else { | ||||
| but->active->value = mbut_state->origvalue + value_delta; | but->active->value = mbut_state->origvalue + value_delta; | ||||
| } | } | ||||
| /* clamp based on soft limits, see: T40154 */ | /* clamp based on soft limits, see: T40154 */ | ||||
| CLAMP(but->active->value, (double)but->softmin, (double)but->softmax); | CLAMP(but->active->value, (double)but->softmin, (double)but->softmax); | ||||
| } | } | ||||
| ui_button_execute_end(C, ar, but, active_back); | ui_but_execute_end(C, ar, but, active_back); | ||||
| } | } | ||||
| else { | else { | ||||
| /* highly unlikely */ | /* highly unlikely */ | ||||
| printf("%s: cant find button\n", __func__); | printf("%s: cant find button\n", __func__); | ||||
| } | } | ||||
| /* end */ | /* end */ | ||||
| } | } | ||||
| Show All 32 Lines | for (block = ar->uiblocks.first; block; block = block->next) { | ||||
| float xy_b_block[2] = {UNPACK2(xy_dst)}; | float xy_b_block[2] = {UNPACK2(xy_dst)}; | ||||
| ui_window_to_block_fl(ar, block, &xy_a_block[0], &xy_a_block[1]); | ui_window_to_block_fl(ar, block, &xy_a_block[0], &xy_a_block[1]); | ||||
| ui_window_to_block_fl(ar, block, &xy_b_block[0], &xy_b_block[1]); | ui_window_to_block_fl(ar, block, &xy_b_block[0], &xy_b_block[1]); | ||||
| for (but = block->buttons.first; but; but = but->next) { | for (but = block->buttons.first; but; but = but->next) { | ||||
| /* Note: ctrl is always true here because (at least for now) we always want to consider text control | /* Note: ctrl is always true here because (at least for now) we always want to consider text control | ||||
| * in this case, even when not embossed. */ | * in this case, even when not embossed. */ | ||||
| if (ui_is_but_interactive(but, true)) { | if (ui_but_is_interactive(but, true)) { | ||||
| if (BLI_rctf_isect_segment(&but->rect, xy_a_block, xy_b_block)) { | if (BLI_rctf_isect_segment(&but->rect, xy_a_block, xy_b_block)) { | ||||
| /* execute the button */ | /* execute the button */ | ||||
| if (ui_is_but_bool(but) && but->type == but_type_start) { | if (ui_but_is_bool(but) && but->type == but_type_start) { | ||||
| /* is it pressed? */ | /* is it pressed? */ | ||||
| bool is_set_but = ui_is_but_push(but); | bool is_set_but = ui_but_is_pushed(but); | ||||
| BLI_assert(ui_is_but_bool(but) == true); | BLI_assert(ui_but_is_bool(but) == true); | ||||
| if (is_set_but != is_set) { | if (is_set_but != is_set) { | ||||
| uiButExecute(C, but); | UI_but_execute(C, but); | ||||
| if (do_check) { | if (do_check) { | ||||
| ui_check_but(but); | ui_but_update(but); | ||||
| } | } | ||||
| changed = true; | changed = true; | ||||
| } | } | ||||
| } | } | ||||
| /* done */ | /* done */ | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | static int ui_handler_region_drag_toggle(bContext *C, const wmEvent *event, void *userdata) | ||||
| } | } | ||||
| if (done) { | if (done) { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| uiBut *but = ui_but_find_mouse_over_ex(ar, drag_info->xy_init[0], drag_info->xy_init[1], true); | uiBut *but = ui_but_find_mouse_over_ex(ar, drag_info->xy_init[0], drag_info->xy_init[1], true); | ||||
| if (but) { | if (but) { | ||||
| ui_apply_undo(but); | ui_apply_but_undo(but); | ||||
| } | } | ||||
| WM_event_remove_ui_handler(&win->modalhandlers, | WM_event_remove_ui_handler(&win->modalhandlers, | ||||
| ui_handler_region_drag_toggle, | ui_handler_region_drag_toggle, | ||||
| ui_handler_region_drag_toggle_remove, | ui_handler_region_drag_toggle_remove, | ||||
| drag_info, false); | drag_info, false); | ||||
| ui_handler_region_drag_toggle_remove(C, drag_info); | ui_handler_region_drag_toggle_remove(C, drag_info); | ||||
| WM_event_add_mousemove(C); | WM_event_add_mousemove(C); | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| else { | else { | ||||
| return WM_UI_HANDLER_CONTINUE; | return WM_UI_HANDLER_CONTINUE; | ||||
| } | } | ||||
| } | } | ||||
| static bool ui_is_but_drag_toggle(const uiBut *but) | static bool ui_but_is_drag_toggle(const uiBut *but) | ||||
| { | { | ||||
| return ((ui_is_but_bool(but) == true) && | return ((ui_but_is_bool(but) == true) && | ||||
| /* menu check is importnt so the button dragged over isn't removed instantly */ | /* menu check is importnt so the button dragged over isn't removed instantly */ | ||||
| (ui_block_is_menu(but->block) == false)); | (ui_block_is_menu(but->block) == false)); | ||||
| } | } | ||||
| #endif /* USE_DRAG_TOGGLE */ | #endif /* USE_DRAG_TOGGLE */ | ||||
| static bool ui_but_mouse_inside_icon(uiBut *but, ARegion *ar, const wmEvent *event) | static bool ui_but_contains_point_px_icon(uiBut *but, ARegion *ar, const wmEvent *event) | ||||
| { | { | ||||
| rcti rect; | rcti rect; | ||||
| int x = event->x, y = event->y; | int x = event->x, y = event->y; | ||||
| ui_window_to_block(ar, but->block, &x, &y); | ui_window_to_block(ar, but->block, &x, &y); | ||||
| BLI_rcti_rctf_copy(&rect, &but->rect); | BLI_rcti_rctf_copy(&rect, &but->rect); | ||||
| if (but->imb || but->type == COLOR) { | if (but->imb || but->type == UI_BTYPE_COLOR) { | ||||
| /* use button size itself */ | /* use button size itself */ | ||||
| } | } | ||||
| else if (but->drawflag & UI_BUT_ICON_LEFT) { | else if (but->drawflag & UI_BUT_ICON_LEFT) { | ||||
| rect.xmax = rect.xmin + (BLI_rcti_size_y(&rect)); | rect.xmax = rect.xmin + (BLI_rcti_size_y(&rect)); | ||||
| } | } | ||||
| else { | else { | ||||
| int delta = BLI_rcti_size_x(&rect) - BLI_rcti_size_y(&rect); | int delta = BLI_rcti_size_x(&rect) - BLI_rcti_size_y(&rect); | ||||
| rect.xmin += delta / 2; | rect.xmin += delta / 2; | ||||
| rect.xmax -= delta / 2; | rect.xmax -= delta / 2; | ||||
| } | } | ||||
| return BLI_rcti_isect_pt(&rect, x, y); | return BLI_rcti_isect_pt(&rect, x, y); | ||||
| } | } | ||||
| static bool ui_but_start_drag(bContext *C, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | static bool ui_but_drag_init(bContext *C, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | ||||
| { | { | ||||
| /* prevent other WM gestures to start while we try to drag */ | /* prevent other WM gestures to start while we try to drag */ | ||||
| WM_gestures_remove(C); | WM_gestures_remove(C); | ||||
| if (ABS(data->dragstartx - event->x) + ABS(data->dragstarty - event->y) > U.dragthreshold) { | if (ABS(data->dragstartx - event->x) + ABS(data->dragstarty - event->y) > U.dragthreshold) { | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| data->cancel = true; | data->cancel = true; | ||||
| #ifdef USE_DRAG_TOGGLE | #ifdef USE_DRAG_TOGGLE | ||||
| if (ui_is_but_bool(but)) { | if (ui_but_is_bool(but)) { | ||||
| uiDragToggleHandle *drag_info = MEM_callocN(sizeof(*drag_info), __func__); | uiDragToggleHandle *drag_info = MEM_callocN(sizeof(*drag_info), __func__); | ||||
| ARegion *ar_prev; | ARegion *ar_prev; | ||||
| /* call here because regular mouse-up event wont run, | /* call here because regular mouse-up event wont run, | ||||
| * typically 'button_activate_exit()' handles this */ | * typically 'button_activate_exit()' handles this */ | ||||
| ui_apply_autokey(C, but); | ui_apply_but_autokey(C, but); | ||||
| drag_info->is_set = ui_is_but_push(but); | drag_info->is_set = ui_but_is_pushed(but); | ||||
| drag_info->but_cent_start[0] = BLI_rctf_cent_x(&but->rect); | drag_info->but_cent_start[0] = BLI_rctf_cent_x(&but->rect); | ||||
| drag_info->but_cent_start[1] = BLI_rctf_cent_y(&but->rect); | drag_info->but_cent_start[1] = BLI_rctf_cent_y(&but->rect); | ||||
| drag_info->but_type_start = but->type; | drag_info->but_type_start = but->type; | ||||
| copy_v2_v2_int(drag_info->xy_init, &event->x); | copy_v2_v2_int(drag_info->xy_init, &event->x); | ||||
| copy_v2_v2_int(drag_info->xy_last, &event->x); | copy_v2_v2_int(drag_info->xy_last, &event->x); | ||||
| /* needed for toggle drag on popups */ | /* needed for toggle drag on popups */ | ||||
| ar_prev = CTX_wm_region(C); | ar_prev = CTX_wm_region(C); | ||||
| CTX_wm_region_set(C, data->region); | CTX_wm_region_set(C, data->region); | ||||
| WM_event_add_ui_handler(C, &data->window->modalhandlers, | WM_event_add_ui_handler(C, &data->window->modalhandlers, | ||||
| ui_handler_region_drag_toggle, | ui_handler_region_drag_toggle, | ||||
| ui_handler_region_drag_toggle_remove, | ui_handler_region_drag_toggle_remove, | ||||
| drag_info, false); | drag_info, false); | ||||
| CTX_wm_region_set(C, ar_prev); | CTX_wm_region_set(C, ar_prev); | ||||
| } | } | ||||
| else | else | ||||
| #endif | #endif | ||||
| if (but->type == COLOR) { | if (but->type == UI_BTYPE_COLOR) { | ||||
| bool valid = false; | bool valid = false; | ||||
| uiDragColorHandle *drag_info = MEM_callocN(sizeof(*drag_info), __func__); | uiDragColorHandle *drag_info = MEM_callocN(sizeof(*drag_info), __func__); | ||||
| /* TODO support more button pointer types */ | /* TODO support more button pointer types */ | ||||
| if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) { | if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) { | ||||
| RNA_property_float_get_array(&but->rnapoin, but->rnaprop, drag_info->color); | RNA_property_float_get_array(&but->rnapoin, but->rnaprop, drag_info->color); | ||||
| drag_info->gamma_corrected = true; | drag_info->gamma_corrected = true; | ||||
| valid = true; | valid = true; | ||||
| Show All 18 Lines | if (but->type == UI_BTYPE_COLOR) { | ||||
| else { | else { | ||||
| MEM_freeN(drag_info); | MEM_freeN(drag_info); | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| wmDrag *drag; | wmDrag *drag; | ||||
| drag = WM_event_start_drag(C, but->icon, but->dragtype, but->dragpoin, ui_get_but_val(but), WM_DRAG_NOP); | drag = WM_event_start_drag(C, but->icon, but->dragtype, but->dragpoin, ui_but_value_get(but), WM_DRAG_NOP); | ||||
| if (but->imb) | if (but->imb) | ||||
| WM_event_drag_image(drag, but->imb, but->imb_scale, BLI_rctf_size_x(&but->rect), BLI_rctf_size_y(&but->rect)); | WM_event_drag_image(drag, but->imb, but->imb_scale, BLI_rctf_size_x(&but->rect), BLI_rctf_size_y(&but->rect)); | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* ********************** linklines *********************** */ | /* ********************** linklines *********************** */ | ||||
| static void ui_delete_active_linkline(uiBlock *block) | static void ui_linkline_remove_active(uiBlock *block) | ||||
| { | { | ||||
| uiBut *but; | uiBut *but; | ||||
| uiLink *link; | uiLink *link; | ||||
| uiLinkLine *line, *nline; | uiLinkLine *line, *nline; | ||||
| int a, b; | int a, b; | ||||
| for (but = block->buttons.first; but; but = but->next) { | for (but = block->buttons.first; but; but = but->next) { | ||||
| if (but->type == LINK && but->link) { | if (but->type == UI_BTYPE_LINK && but->link) { | ||||
| for (line = but->link->lines.first; line; line = nline) { | for (line = but->link->lines.first; line; line = nline) { | ||||
| nline = line->next; | nline = line->next; | ||||
| if (line->flag & UI_SELECT) { | if (line->flag & UI_SELECT) { | ||||
| BLI_remlink(&but->link->lines, line); | BLI_remlink(&but->link->lines, line); | ||||
| link = line->from->link; | link = line->from->link; | ||||
| Show All 24 Lines | if (but->type == UI_BTYPE_LINK && but->link) { | ||||
| MEM_freeN(line); | MEM_freeN(line); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static uiLinkLine *ui_is_a_link(uiBut *from, uiBut *to) | static uiLinkLine *ui_but_find_link(uiBut *from, uiBut *to) | ||||
| { | { | ||||
| uiLinkLine *line; | uiLinkLine *line; | ||||
| uiLink *link; | uiLink *link; | ||||
| link = from->link; | link = from->link; | ||||
| if (link) { | if (link) { | ||||
| for (line = link->lines.first; line; line = line->next) { | for (line = link->lines.first; line; line = line->next) { | ||||
| if (line->from == from && line->to == to) { | if (line->from == from && line->to == to) { | ||||
| return line; | return line; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* XXX BAD BAD HACK, fixme later **************** */ | /* XXX BAD BAD HACK, fixme later **************** */ | ||||
| /* Try to add an AND Controller between the sensor and the actuator logic bricks and to connect them all */ | /* Try to add an AND Controller between the sensor and the actuator logic bricks and to connect them all */ | ||||
| static void ui_add_smart_controller(bContext *C, uiBut *from, uiBut *to) | static void ui_but_smart_controller_add(bContext *C, uiBut *from, uiBut *to) | ||||
| { | { | ||||
| Object *ob = NULL; | Object *ob = NULL; | ||||
| bSensor *sens_iter; | bSensor *sens_iter; | ||||
| bActuator *act_to, *act_iter; | bActuator *act_to, *act_iter; | ||||
| bController *cont; | bController *cont; | ||||
| bController ***sens_from_links; | bController ***sens_from_links; | ||||
| uiBut *tmp_but; | uiBut *tmp_but; | ||||
| Show All 38 Lines | static void ui_but_smart_controller_add(bContext *C, uiBut *from, uiBut *to) | ||||
| /* (3) add a new controller */ | /* (3) add a new controller */ | ||||
| if (WM_operator_name_call(C, "LOGIC_OT_controller_add", WM_OP_EXEC_DEFAULT, &props_ptr) & OPERATOR_FINISHED) { | if (WM_operator_name_call(C, "LOGIC_OT_controller_add", WM_OP_EXEC_DEFAULT, &props_ptr) & OPERATOR_FINISHED) { | ||||
| cont = (bController *)ob->controllers.last; | cont = (bController *)ob->controllers.last; | ||||
| cont->type = CONT_LOGIC_AND; /* Quick fix to make sure we always have an AND controller. It might be nicer to make sure the operator gives us the right one though... */ | cont->type = CONT_LOGIC_AND; /* Quick fix to make sure we always have an AND controller. It might be nicer to make sure the operator gives us the right one though... */ | ||||
| /* (4) link the sensor->controller->actuator */ | /* (4) link the sensor->controller->actuator */ | ||||
| tmp_but = MEM_callocN(sizeof(uiBut), "uiBut"); | tmp_but = MEM_callocN(sizeof(uiBut), "uiBut"); | ||||
| uiSetButLink(tmp_but, (void **)&cont, (void ***)&(cont->links), &(cont->totlinks), from->link->tocode, (int)to->hardmin); | UI_but_link_set(tmp_but, (void **)&cont, (void ***)&(cont->links), &(cont->totlinks), from->link->tocode, (int)to->hardmin); | ||||
| tmp_but->hardmin = from->link->tocode; | tmp_but->hardmin = from->link->tocode; | ||||
| tmp_but->poin = (char *)cont; | tmp_but->poin = (char *)cont; | ||||
| tmp_but->type = INLINK; | tmp_but->type = UI_BTYPE_INLINK; | ||||
| ui_add_link(C, from, tmp_but); | ui_but_link_add(C, from, tmp_but); | ||||
| tmp_but->type = LINK; | tmp_but->type = UI_BTYPE_LINK; | ||||
| ui_add_link(C, tmp_but, to); | ui_but_link_add(C, tmp_but, to); | ||||
| /* (5) garbage collection */ | /* (5) garbage collection */ | ||||
| MEM_freeN(tmp_but->link); | MEM_freeN(tmp_but->link); | ||||
| MEM_freeN(tmp_but); | MEM_freeN(tmp_but); | ||||
| } | } | ||||
| WM_operator_properties_free(&props_ptr); | WM_operator_properties_free(&props_ptr); | ||||
| } | } | ||||
| static void ui_add_link(bContext *C, uiBut *from, uiBut *to) | static void ui_but_link_add(bContext *C, uiBut *from, uiBut *to) | ||||
| { | { | ||||
| /* in 'from' we have to add a link to 'to' */ | /* in 'from' we have to add a link to 'to' */ | ||||
| uiLink *link; | uiLink *link; | ||||
| uiLinkLine *line; | uiLinkLine *line; | ||||
| void **oldppoin; | void **oldppoin; | ||||
| int a; | int a; | ||||
| if ((line = ui_is_a_link(from, to))) { | if ((line = ui_but_find_link(from, to))) { | ||||
| line->flag |= UI_SELECT; | line->flag |= UI_SELECT; | ||||
| ui_delete_active_linkline(from->block); | ui_linkline_remove_active(from->block); | ||||
| return; | return; | ||||
| } | } | ||||
| if (from->type == INLINK && to->type == INLINK) { | if (from->type == UI_BTYPE_INLINK && to->type == UI_BTYPE_INLINK) { | ||||
| return; | return; | ||||
| } | } | ||||
| else if (from->type == LINK && to->type == INLINK) { | else if (from->type == UI_BTYPE_LINK && to->type == UI_BTYPE_INLINK) { | ||||
| if (from->link->tocode != (int)to->hardmin) { | if (from->link->tocode != (int)to->hardmin) { | ||||
| ui_add_smart_controller(C, from, to); | ui_but_smart_controller_add(C, from, to); | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| else if (from->type == INLINK && to->type == LINK) { | else if (from->type == UI_BTYPE_INLINK && to->type == UI_BTYPE_LINK) { | ||||
| if (to->link->tocode == (int)from->hardmin) { | if (to->link->tocode == (int)from->hardmin) { | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| link = from->link; | link = from->link; | ||||
| /* are there more pointers allowed? */ | /* are there more pointers allowed? */ | ||||
| Show All 18 Lines | |||||
| static void ui_apply_but_LINK(bContext *C, uiBut *but, uiHandleButtonData *data) | static void ui_apply_but_LINK(bContext *C, uiBut *but, uiHandleButtonData *data) | ||||
| { | { | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| uiBut *bt; | uiBut *bt; | ||||
| for (bt = but->block->buttons.first; bt; bt = bt->next) { | for (bt = but->block->buttons.first; bt; bt = bt->next) { | ||||
| if (ui_mouse_inside_button(ar, bt, but->linkto[0] + ar->winrct.xmin, but->linkto[1] + ar->winrct.ymin) ) | if (ui_but_contains_point_px(ar, bt, but->linkto[0] + ar->winrct.xmin, but->linkto[1] + ar->winrct.ymin) ) | ||||
| break; | break; | ||||
| } | } | ||||
| if (bt && bt != but) { | if (bt && bt != but) { | ||||
| if (!ELEM(bt->type, LINK, INLINK) || !ELEM(but->type, LINK, INLINK)) | if (!ELEM(bt->type, UI_BTYPE_LINK, UI_BTYPE_INLINK) || !ELEM(but->type, UI_BTYPE_LINK, UI_BTYPE_INLINK)) | ||||
| return; | return; | ||||
| if (but->type == LINK) ui_add_link(C, but, bt); | if (but->type == UI_BTYPE_LINK) ui_but_link_add(C, but, bt); | ||||
| else ui_add_link(C, bt, but); | else ui_but_link_add(C, bt, but); | ||||
| ui_apply_but_func(C, but); | ui_apply_but_func(C, but); | ||||
| data->retval = but->retval; | data->retval = but->retval; | ||||
| } | } | ||||
| data->applied = true; | data->applied = true; | ||||
| } | } | ||||
| static void ui_apply_but_IMAGE(bContext *C, uiBut *but, uiHandleButtonData *data) | static void ui_apply_but_IMAGE(bContext *C, uiBut *but, uiHandleButtonData *data) | ||||
| Show All 20 Lines | |||||
| static void ui_apply_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonData *data) | static void ui_apply_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonData *data) | ||||
| { | { | ||||
| ui_apply_but_func(C, but); | ui_apply_but_func(C, but); | ||||
| data->retval = but->retval; | data->retval = but->retval; | ||||
| data->applied = true; | data->applied = true; | ||||
| } | } | ||||
| static void ui_apply_button(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const bool interactive) | static void ui_apply_but(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const bool interactive) | ||||
| { | { | ||||
| char *editstr; | char *editstr; | ||||
| double *editval; | double *editval; | ||||
| float *editvec; | float *editvec; | ||||
| ColorBand *editcoba; | ColorBand *editcoba; | ||||
| CurveMapping *editcumap; | CurveMapping *editcumap; | ||||
| data->retval = 0; | data->retval = 0; | ||||
| Show All 32 Lines | static void ui_apply_but(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const bool interactive) | ||||
| but->editstr = NULL; | but->editstr = NULL; | ||||
| but->editval = NULL; | but->editval = NULL; | ||||
| but->editvec = NULL; | but->editvec = NULL; | ||||
| but->editcoba = NULL; | but->editcoba = NULL; | ||||
| but->editcumap = NULL; | but->editcumap = NULL; | ||||
| /* handle different types */ | /* handle different types */ | ||||
| switch (but->type) { | switch (but->type) { | ||||
| case BUT: | case UI_BTYPE_BUT: | ||||
| ui_apply_but_BUT(C, but, data); | ui_apply_but_BUT(C, but, data); | ||||
| break; | break; | ||||
| case TEX: | case UI_BTYPE_TEXT: | ||||
| case SEARCH_MENU_UNLINK: | case UI_BTYPE_SEARCH_MENU_UNLINK: | ||||
| case SEARCH_MENU: | case UI_BTYPE_SEARCH_MENU: | ||||
| ui_apply_but_TEX(C, but, data); | ui_apply_but_TEX(C, but, data); | ||||
| break; | break; | ||||
| case TOGBUT: | case UI_BTYPE_BUT_TOGGLE: | ||||
| case TOG: | case UI_BTYPE_TOGGLE: | ||||
| case ICONTOG: | case UI_BTYPE_ICON_TOGGLE: | ||||
| case ICONTOGN: | case UI_BTYPE_ICON_TOGGLE_N: | ||||
| case TOGN: | case UI_BTYPE_TOGGLE_N: | ||||
| case OPTION: | case UI_BTYPE_CHECKBOX: | ||||
| case OPTIONN: | case UI_BTYPE_CHECKBOX_N: | ||||
| ui_apply_but_TOG(C, but, data); | ui_apply_but_TOG(C, but, data); | ||||
| break; | break; | ||||
| case ROW: | case UI_BTYPE_ROW: | ||||
| case LISTROW: | case UI_BTYPE_LISTROW: | ||||
| ui_apply_but_ROW(C, block, but, data); | ui_apply_but_ROW(C, block, but, data); | ||||
| break; | break; | ||||
| case SCROLL: | case UI_BTYPE_SCROLL: | ||||
| case GRIP: | case UI_BTYPE_GRIP: | ||||
| case NUM: | case UI_BTYPE_NUM: | ||||
| case NUMSLI: | case UI_BTYPE_NUM_SLIDER: | ||||
| ui_apply_but_NUM(C, but, data); | ui_apply_but_NUM(C, but, data); | ||||
| break; | break; | ||||
| case MENU: | case UI_BTYPE_MENU: | ||||
| case BLOCK: | case UI_BTYPE_BLOCK: | ||||
| case PULLDOWN: | case UI_BTYPE_PULLDOWN: | ||||
| ui_apply_but_BLOCK(C, but, data); | ui_apply_but_BLOCK(C, but, data); | ||||
| break; | break; | ||||
| case COLOR: | case UI_BTYPE_COLOR: | ||||
| if (data->cancel) | if (data->cancel) | ||||
| ui_apply_but_VEC(C, but, data); | ui_apply_but_VEC(C, but, data); | ||||
| else | else | ||||
| ui_apply_but_BLOCK(C, but, data); | ui_apply_but_BLOCK(C, but, data); | ||||
| break; | break; | ||||
| case BUTM: | case UI_BTYPE_BUT_MENU: | ||||
| ui_apply_but_BUTM(C, but, data); | ui_apply_but_BUTM(C, but, data); | ||||
| break; | break; | ||||
| case BUT_NORMAL: | case UI_BTYPE_UNITVEC: | ||||
| case HSVCUBE: | case UI_BTYPE_HSVCUBE: | ||||
| case HSVCIRCLE: | case UI_BTYPE_HSVCIRCLE: | ||||
| ui_apply_but_VEC(C, but, data); | ui_apply_but_VEC(C, but, data); | ||||
| break; | break; | ||||
| case BUT_COLORBAND: | case UI_BTYPE_COLORBAND: | ||||
| ui_apply_but_COLORBAND(C, but, data); | ui_apply_but_COLORBAND(C, but, data); | ||||
| break; | break; | ||||
| case BUT_CURVE: | case UI_BTYPE_CURVE: | ||||
| ui_apply_but_CURVE(C, but, data); | ui_apply_but_CURVE(C, but, data); | ||||
| break; | break; | ||||
| case KEYEVT: | case UI_BTYPE_KEY_EVENT: | ||||
| case HOTKEYEVT: | case UI_BTYPE_HOTKEY_EVENT: | ||||
| ui_apply_but_BUT(C, but, data); | ui_apply_but_BUT(C, but, data); | ||||
| break; | break; | ||||
| case LINK: | case UI_BTYPE_LINK: | ||||
| case INLINK: | case UI_BTYPE_INLINK: | ||||
| ui_apply_but_LINK(C, but, data); | ui_apply_but_LINK(C, but, data); | ||||
| break; | break; | ||||
| case BUT_IMAGE: | case UI_BTYPE_IMAGE: | ||||
| ui_apply_but_IMAGE(C, but, data); | ui_apply_but_IMAGE(C, but, data); | ||||
| break; | break; | ||||
| case HISTOGRAM: | case UI_BTYPE_HISTOGRAM: | ||||
| ui_apply_but_HISTOGRAM(C, but, data); | ui_apply_but_HISTOGRAM(C, but, data); | ||||
| break; | break; | ||||
| case WAVEFORM: | case UI_BTYPE_WAVEFORM: | ||||
| ui_apply_but_WAVEFORM(C, but, data); | ui_apply_but_WAVEFORM(C, but, data); | ||||
| break; | break; | ||||
| case TRACKPREVIEW: | case UI_BTYPE_TRACK_PREVIEW: | ||||
| ui_apply_but_TRACKPREVIEW(C, but, data); | ui_apply_but_TRACKPREVIEW(C, but, data); | ||||
| break; | break; | ||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| #ifdef USE_DRAG_MULTINUM | #ifdef USE_DRAG_MULTINUM | ||||
| if (data->multi_data.has_mbuts) { | if (data->multi_data.has_mbuts) { | ||||
| Show All 21 Lines | |||||
| static void ui_but_drop(bContext *C, const wmEvent *event, uiBut *but, uiHandleButtonData *data) | static void ui_but_drop(bContext *C, const wmEvent *event, uiBut *but, uiHandleButtonData *data) | ||||
| { | { | ||||
| wmDrag *wmd; | wmDrag *wmd; | ||||
| ListBase *drags = event->customdata; /* drop event type has listbase customdata by default */ | ListBase *drags = event->customdata; /* drop event type has listbase customdata by default */ | ||||
| for (wmd = drags->first; wmd; wmd = wmd->next) { | for (wmd = drags->first; wmd; wmd = wmd->next) { | ||||
| if (wmd->type == WM_DRAG_ID) { | if (wmd->type == WM_DRAG_ID) { | ||||
| /* align these types with UI_but_active_drop_name */ | /* align these types with UI_but_active_drop_name */ | ||||
| if (ELEM(but->type, TEX, SEARCH_MENU, SEARCH_MENU_UNLINK)) { | if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { | ||||
| ID *id = (ID *)wmd->poin; | ID *id = (ID *)wmd->poin; | ||||
| button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); | button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); | ||||
| BLI_strncpy(data->str, id->name + 2, data->maxlen); | BLI_strncpy(data->str, id->name + 2, data->maxlen); | ||||
| if (ELEM(but->type, SEARCH_MENU, SEARCH_MENU_UNLINK)) { | if (ELEM(but->type, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { | ||||
| but->changed = true; | but->changed = true; | ||||
| ui_searchbox_update(C, data->searchbox, but, true); | ui_searchbox_update(C, data->searchbox, but, true); | ||||
| } | } | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 30 Lines | if (buf_paste_test) { | ||||
| buf_paste_alloc = true; | buf_paste_alloc = true; | ||||
| } | } | ||||
| } | } | ||||
| /* No return from here down */ | /* No return from here down */ | ||||
| /* numeric value */ | /* numeric value */ | ||||
| if (ELEM(but->type, NUM, NUMSLI)) { | if (ELEM(but->type, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER)) { | ||||
| if (but->poin == NULL && but->rnapoin.data == NULL) { | if (but->poin == NULL && but->rnapoin.data == NULL) { | ||||
| /* pass */ | /* pass */ | ||||
| } | } | ||||
| else if (mode == 'c') { | else if (mode == 'c') { | ||||
| /* Get many decimal places, then strip trailing zeros. | /* Get many decimal places, then strip trailing zeros. | ||||
| * note: too high values start to give strange results (6 or so is ok) */ | * note: too high values start to give strange results (6 or so is ok) */ | ||||
| char buf_copy[UI_MAX_DRAW_STR]; | char buf_copy[UI_MAX_DRAW_STR]; | ||||
| ui_get_but_string_ex(but, buf_copy, sizeof(buf_copy), 6); | ui_but_string_get_ex(but, buf_copy, sizeof(buf_copy), 6); | ||||
| BLI_str_rstrip_float_zero(buf_copy, '\0'); | BLI_str_rstrip_float_zero(buf_copy, '\0'); | ||||
| WM_clipboard_text_set(buf_copy, 0); | WM_clipboard_text_set(buf_copy, 0); | ||||
| } | } | ||||
| else { | else { | ||||
| double val; | double val; | ||||
| if (ui_set_but_string_eval_num(C, but, buf_paste, &val)) { | if (ui_but_string_set_eval_num(C, but, buf_paste, &val)) { | ||||
| button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); | button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); | ||||
| data->value = val; | data->value = val; | ||||
| ui_set_but_string(C, but, buf_paste); | ui_but_string_set(C, but, buf_paste); | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* NORMAL button */ | /* NORMAL button */ | ||||
| else if (but->type == BUT_NORMAL) { | else if (but->type == UI_BTYPE_UNITVEC) { | ||||
| float xyz[3]; | float xyz[3]; | ||||
| if (but->poin == NULL && but->rnapoin.data == NULL) { | if (but->poin == NULL && but->rnapoin.data == NULL) { | ||||
| /* pass */ | /* pass */ | ||||
| } | } | ||||
| else if (mode == 'c') { | else if (mode == 'c') { | ||||
| char buf_copy[UI_MAX_DRAW_STR]; | char buf_copy[UI_MAX_DRAW_STR]; | ||||
| ui_get_but_vectorf(but, xyz); | ui_but_v3_get(but, xyz); | ||||
| BLI_snprintf(buf_copy, sizeof(buf_copy), "[%f, %f, %f]", xyz[0], xyz[1], xyz[2]); | BLI_snprintf(buf_copy, sizeof(buf_copy), "[%f, %f, %f]", xyz[0], xyz[1], xyz[2]); | ||||
| WM_clipboard_text_set(buf_copy, 0); | WM_clipboard_text_set(buf_copy, 0); | ||||
| } | } | ||||
| else { | else { | ||||
| if (sscanf(buf_paste, "[%f, %f, %f]", &xyz[0], &xyz[1], &xyz[2]) == 3) { | if (sscanf(buf_paste, "[%f, %f, %f]", &xyz[0], &xyz[1], &xyz[2]) == 3) { | ||||
| if (normalize_v3(xyz) == 0.0f) { | if (normalize_v3(xyz) == 0.0f) { | ||||
| /* better set Z up then have a zero vector */ | /* better set Z up then have a zero vector */ | ||||
| xyz[2] = 1.0; | xyz[2] = 1.0; | ||||
| } | } | ||||
| button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); | button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); | ||||
| ui_set_but_vectorf(but, xyz); | ui_but_v3_set(but, xyz); | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* RGB triple */ | /* RGB triple */ | ||||
| else if (but->type == COLOR) { | else if (but->type == UI_BTYPE_COLOR) { | ||||
| float rgba[4]; | float rgba[4]; | ||||
| if (but->poin == NULL && but->rnapoin.data == NULL) { | if (but->poin == NULL && but->rnapoin.data == NULL) { | ||||
| /* pass */ | /* pass */ | ||||
| } | } | ||||
| else if (mode == 'c') { | else if (mode == 'c') { | ||||
| char buf_copy[UI_MAX_DRAW_STR]; | char buf_copy[UI_MAX_DRAW_STR]; | ||||
| if (but->rnaprop && RNA_property_array_length(&but->rnapoin, but->rnaprop) == 4) | if (but->rnaprop && RNA_property_array_length(&but->rnapoin, but->rnaprop) == 4) | ||||
| rgba[3] = RNA_property_float_get_index(&but->rnapoin, but->rnaprop, 3); | rgba[3] = RNA_property_float_get_index(&but->rnapoin, but->rnaprop, 3); | ||||
| else | else | ||||
| rgba[3] = 1.0f; | rgba[3] = 1.0f; | ||||
| ui_get_but_vectorf(but, rgba); | ui_but_v3_get(but, rgba); | ||||
| /* convert to linear color to do compatible copy between gamma and non-gamma */ | /* convert to linear color to do compatible copy between gamma and non-gamma */ | ||||
| if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) | if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) | ||||
| srgb_to_linearrgb_v3_v3(rgba, rgba); | srgb_to_linearrgb_v3_v3(rgba, rgba); | ||||
| BLI_snprintf(buf_copy, sizeof(buf_copy), "[%f, %f, %f, %f]", rgba[0], rgba[1], rgba[2], rgba[3]); | BLI_snprintf(buf_copy, sizeof(buf_copy), "[%f, %f, %f, %f]", rgba[0], rgba[1], rgba[2], rgba[3]); | ||||
| WM_clipboard_text_set(buf_copy, 0); | WM_clipboard_text_set(buf_copy, 0); | ||||
| } | } | ||||
| else { | else { | ||||
| if (sscanf(buf_paste, "[%f, %f, %f, %f]", &rgba[0], &rgba[1], &rgba[2], &rgba[3]) == 4) { | if (sscanf(buf_paste, "[%f, %f, %f, %f]", &rgba[0], &rgba[1], &rgba[2], &rgba[3]) == 4) { | ||||
| /* assume linear colors in buffer */ | /* assume linear colors in buffer */ | ||||
| if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) | if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) | ||||
| linearrgb_to_srgb_v3_v3(rgba, rgba); | linearrgb_to_srgb_v3_v3(rgba, rgba); | ||||
| button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); | button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); | ||||
| ui_set_but_vectorf(but, rgba); | ui_but_v3_set(but, rgba); | ||||
| if (but->rnaprop && RNA_property_array_length(&but->rnapoin, but->rnaprop) == 4) | if (but->rnaprop && RNA_property_array_length(&but->rnapoin, but->rnaprop) == 4) | ||||
| RNA_property_float_set_index(&but->rnapoin, but->rnaprop, 3, rgba[3]); | RNA_property_float_set_index(&but->rnapoin, but->rnaprop, 3, rgba[3]); | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* text/string and ID data */ | /* text/string and ID data */ | ||||
| else if (ELEM(but->type, TEX, SEARCH_MENU, SEARCH_MENU_UNLINK)) { | else if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { | ||||
| uiHandleButtonData *active_data = but->active; | uiHandleButtonData *active_data = but->active; | ||||
| if (but->poin == NULL && but->rnapoin.data == NULL) { | if (but->poin == NULL && but->rnapoin.data == NULL) { | ||||
| /* pass */ | /* pass */ | ||||
| } | } | ||||
| else if (mode == 'c') { | else if (mode == 'c') { | ||||
| button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); | button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); | ||||
| WM_clipboard_text_set(active_data->str, 0); | WM_clipboard_text_set(active_data->str, 0); | ||||
| active_data->cancel = true; | active_data->cancel = true; | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| } | } | ||||
| else { | else { | ||||
| button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); | button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); | ||||
| if (ui_is_but_utf8(but)) | if (ui_but_is_utf8(but)) | ||||
| BLI_strncpy_utf8(active_data->str, buf_paste, active_data->maxlen); | BLI_strncpy_utf8(active_data->str, buf_paste, active_data->maxlen); | ||||
| else | else | ||||
| BLI_strncpy(active_data->str, buf_paste, active_data->maxlen); | BLI_strncpy(active_data->str, buf_paste, active_data->maxlen); | ||||
| if (ELEM(but->type, SEARCH_MENU, SEARCH_MENU_UNLINK)) { | if (ELEM(but->type, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { | ||||
| /* else uiSearchboxData.active member is not updated [#26856] */ | /* else uiSearchboxData.active member is not updated [#26856] */ | ||||
| but->changed = true; | but->changed = true; | ||||
| ui_searchbox_update(C, data->searchbox, but, true); | ui_searchbox_update(C, data->searchbox, but, true); | ||||
| } | } | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| } | } | ||||
| } | } | ||||
| /* colorband (not supported by system clipboard) */ | /* colorband (not supported by system clipboard) */ | ||||
| else if (but->type == BUT_COLORBAND) { | else if (but->type == UI_BTYPE_COLORBAND) { | ||||
| if (mode == 'c') { | if (mode == 'c') { | ||||
| if (but->poin != NULL) { | if (but->poin != NULL) { | ||||
| memcpy(&but_copypaste_coba, but->poin, sizeof(ColorBand)); | memcpy(&but_copypaste_coba, but->poin, sizeof(ColorBand)); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| if (but_copypaste_coba.tot != 0) { | if (but_copypaste_coba.tot != 0) { | ||||
| if (!but->poin) | if (!but->poin) | ||||
| but->poin = MEM_callocN(sizeof(ColorBand), "colorband"); | but->poin = MEM_callocN(sizeof(ColorBand), "colorband"); | ||||
| button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); | button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); | ||||
| memcpy(data->coba, &but_copypaste_coba, sizeof(ColorBand)); | memcpy(data->coba, &but_copypaste_coba, sizeof(ColorBand)); | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else if (but->type == BUT_CURVE) { | else if (but->type == UI_BTYPE_CURVE) { | ||||
| if (mode == 'c') { | if (mode == 'c') { | ||||
| if (but->poin != NULL) { | if (but->poin != NULL) { | ||||
| but_copypaste_curve_alive = true; | but_copypaste_curve_alive = true; | ||||
| curvemapping_free_data(&but_copypaste_curve); | curvemapping_free_data(&but_copypaste_curve); | ||||
| curvemapping_copy_data(&but_copypaste_curve, (CurveMapping *) but->poin); | curvemapping_copy_data(&but_copypaste_curve, (CurveMapping *) but->poin); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| if (but_copypaste_curve_alive) { | if (but_copypaste_curve_alive) { | ||||
| if (!but->poin) | if (!but->poin) | ||||
| but->poin = MEM_callocN(sizeof(CurveMapping), "curvemapping"); | but->poin = MEM_callocN(sizeof(CurveMapping), "curvemapping"); | ||||
| button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); | button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); | ||||
| curvemapping_free_data((CurveMapping *) but->poin); | curvemapping_free_data((CurveMapping *) but->poin); | ||||
| curvemapping_copy_data((CurveMapping *) but->poin, &but_copypaste_curve); | curvemapping_copy_data((CurveMapping *) but->poin, &but_copypaste_curve); | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* operator button (any type) */ | /* operator button (any type) */ | ||||
| else if (but->optype) { | else if (but->optype) { | ||||
| if (mode == 'c') { | if (mode == 'c') { | ||||
| PointerRNA *opptr; | PointerRNA *opptr; | ||||
| char *str; | char *str; | ||||
| opptr = uiButGetOperatorPtrRNA(but); /* allocated when needed, the button owns it */ | opptr = UI_but_operator_ptr_get(but); /* allocated when needed, the button owns it */ | ||||
| str = WM_operator_pystring_ex(C, NULL, false, true, but->optype, opptr); | str = WM_operator_pystring_ex(C, NULL, false, true, but->optype, opptr); | ||||
| WM_clipboard_text_set(str, 0); | WM_clipboard_text_set(str, 0); | ||||
| MEM_freeN(str); | MEM_freeN(str); | ||||
| } | } | ||||
| } | } | ||||
| /* menu (any type) */ | /* menu (any type) */ | ||||
| else if (ELEM(but->type, MENU, PULLDOWN)) { | else if (ELEM(but->type, UI_BTYPE_MENU, UI_BTYPE_PULLDOWN)) { | ||||
| MenuType *mt = uiButGetMenuType(but); | MenuType *mt = UI_but_menutype_get(but); | ||||
| if (mt) { | if (mt) { | ||||
| char str[32 + sizeof(mt->idname)]; | char str[32 + sizeof(mt->idname)]; | ||||
| BLI_snprintf(str, sizeof(str), "bpy.ops.wm.call_menu(name=\"%s\")", mt->idname); | BLI_snprintf(str, sizeof(str), "bpy.ops.wm.call_menu(name=\"%s\")", mt->idname); | ||||
| WM_clipboard_text_set(str, 0); | WM_clipboard_text_set(str, 0); | ||||
| } | } | ||||
| } | } | ||||
| if (buf_paste_alloc) { | if (buf_paste_alloc) { | ||||
| Show All 27 Lines | |||||
| } | } | ||||
| static int ui_text_position_to_hidden(uiBut *but, int pos) | static int ui_text_position_to_hidden(uiBut *but, int pos) | ||||
| { | { | ||||
| const char *butstr = (but->editstr) ? but->editstr : but->drawstr; | const char *butstr = (but->editstr) ? but->editstr : but->drawstr; | ||||
| return BLI_strnlen_utf8(butstr, pos); | return BLI_strnlen_utf8(butstr, pos); | ||||
| } | } | ||||
| void ui_button_text_password_hide(char password_str[UI_MAX_PASSWORD_STR], uiBut *but, const bool restore) | void ui_but_text_password_hide(char password_str[UI_MAX_PASSWORD_STR], uiBut *but, const bool restore) | ||||
| { | { | ||||
| char *butstr; | char *butstr; | ||||
| if (!(but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_PASSWORD)) | if (!(but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_PASSWORD)) | ||||
| return; | return; | ||||
| butstr = (but->editstr) ? but->editstr : but->drawstr; | butstr = (but->editstr) ? but->editstr : but->drawstr; | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
| /** | /** | ||||
| * \param x Screen space cursor location - #wmEvent.x | * \param x Screen space cursor location - #wmEvent.x | ||||
| * | * | ||||
| * \note ``but->block->aspect`` is used here, so drawing button style is getting scaled too. | * \note ``but->block->aspect`` is used here, so drawing button style is getting scaled too. | ||||
| */ | */ | ||||
| static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, const float x) | static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, const float x) | ||||
| { | { | ||||
| uiStyle *style = UI_GetStyle(); // XXX pass on as arg | uiStyle *style = UI_style_get(); // XXX pass on as arg | ||||
| uiFontStyle *fstyle = &style->widget; | uiFontStyle *fstyle = &style->widget; | ||||
| const float aspect = but->block->aspect; | const float aspect = but->block->aspect; | ||||
| const short fstyle_points_prev = fstyle->points; | const short fstyle_points_prev = fstyle->points; | ||||
| float startx = but->rect.xmin; | float startx = but->rect.xmin; | ||||
| float starty_dummy = 0.0f; | float starty_dummy = 0.0f; | ||||
| char *origstr, password_str[UI_MAX_PASSWORD_STR]; | char *origstr, password_str[UI_MAX_PASSWORD_STR]; | ||||
| ui_block_to_window_fl(data->region, but->block, &startx, &starty_dummy); | ui_block_to_window_fl(data->region, but->block, &startx, &starty_dummy); | ||||
| ui_fontscale(&fstyle->points, aspect); | ui_fontscale(&fstyle->points, aspect); | ||||
| uiStyleFontSet(fstyle); | UI_fontstyle_set(fstyle); | ||||
| if (fstyle->kerning == 1) /* for BLF_width */ | if (fstyle->kerning == 1) /* for BLF_width */ | ||||
| BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | ||||
| ui_button_text_password_hide(password_str, but, false); | ui_but_text_password_hide(password_str, but, false); | ||||
| origstr = MEM_mallocN(sizeof(char) * data->maxlen, "ui_textedit origstr"); | origstr = MEM_mallocN(sizeof(char) * data->maxlen, "ui_textedit origstr"); | ||||
| BLI_strncpy(origstr, but->editstr, data->maxlen); | BLI_strncpy(origstr, but->editstr, data->maxlen); | ||||
| if (ELEM(but->type, TEX, SEARCH_MENU, SEARCH_MENU_UNLINK)) { | if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { | ||||
| if (but->flag & UI_HAS_ICON) { | if (but->flag & UI_HAS_ICON) { | ||||
| startx += UI_DPI_ICON_SIZE / aspect; | startx += UI_DPI_ICON_SIZE / aspect; | ||||
| } | } | ||||
| } | } | ||||
| /* but this extra .05 makes clicks inbetween characters feel nicer */ | /* but this extra .05 makes clicks inbetween characters feel nicer */ | ||||
| startx += ((UI_TEXT_MARGIN_X + 0.05f) * U.widget_unit) / aspect; | startx += ((UI_TEXT_MARGIN_X + 0.05f) * U.widget_unit) / aspect; | ||||
| /* mouse dragged outside the widget to the left */ | /* mouse dragged outside the widget to the left */ | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | else { /* (x >= startx) */ | ||||
| } | } | ||||
| but->pos += but->ofs; | but->pos += but->ofs; | ||||
| if (but->pos < 0) but->pos = 0; | if (but->pos < 0) but->pos = 0; | ||||
| } | } | ||||
| if (fstyle->kerning == 1) | if (fstyle->kerning == 1) | ||||
| BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | ||||
| ui_button_text_password_hide(password_str, but, true); | ui_but_text_password_hide(password_str, but, true); | ||||
| MEM_freeN(origstr); | MEM_freeN(origstr); | ||||
| fstyle->points = fstyle_points_prev; | fstyle->points = fstyle_points_prev; | ||||
| } | } | ||||
| static void ui_textedit_set_cursor_select(uiBut *but, uiHandleButtonData *data, const float x) | static void ui_textedit_set_cursor_select(uiBut *but, uiHandleButtonData *data, const float x) | ||||
| { | { | ||||
| if (x > data->selstartx) data->selextend = EXTEND_RIGHT; | if (x > data->selstartx) data->selextend = EXTEND_RIGHT; | ||||
| else if (x < data->selstartx) data->selextend = EXTEND_LEFT; | else if (x < data->selstartx) data->selextend = EXTEND_LEFT; | ||||
| ui_textedit_set_cursor_pos(but, data, x); | ui_textedit_set_cursor_pos(but, data, x); | ||||
| if (data->selextend == EXTEND_RIGHT) but->selend = but->pos; | if (data->selextend == EXTEND_RIGHT) but->selend = but->pos; | ||||
| else if (data->selextend == EXTEND_LEFT) but->selsta = but->pos; | else if (data->selextend == EXTEND_LEFT) but->selsta = but->pos; | ||||
| ui_check_but(but); | ui_but_update(but); | ||||
| } | } | ||||
| /* this is used for both utf8 and ascii, its meant to be used for single keys, | /* this is used for both utf8 and ascii, its meant to be used for single keys, | ||||
| * notice the buffer is either copied or not, so its not suitable for pasting in | * notice the buffer is either copied or not, so its not suitable for pasting in | ||||
| * - campbell */ | * - campbell */ | ||||
| static bool ui_textedit_type_buf(uiBut *but, uiHandleButtonData *data, | static bool ui_textedit_type_buf(uiBut *but, uiHandleButtonData *data, | ||||
| const char *utf8_buf, int utf8_buf_len) | const char *utf8_buf, int utf8_buf_len) | ||||
| { | { | ||||
| Show All 23 Lines | static bool ui_textedit_type_buf(uiBut *but, uiHandleButtonData *data, | ||||
| return changed; | return changed; | ||||
| } | } | ||||
| static bool ui_textedit_type_ascii(uiBut *but, uiHandleButtonData *data, char ascii) | static bool ui_textedit_type_ascii(uiBut *but, uiHandleButtonData *data, char ascii) | ||||
| { | { | ||||
| char buf[2] = {ascii, '\0'}; | char buf[2] = {ascii, '\0'}; | ||||
| if (ui_is_but_utf8(but) && (BLI_str_utf8_size(buf) == -1)) { | if (ui_but_is_utf8(but) && (BLI_str_utf8_size(buf) == -1)) { | ||||
| printf("%s: entering invalid ascii char into an ascii key (%d)\n", | printf("%s: entering invalid ascii char into an ascii key (%d)\n", | ||||
| __func__, (int)(unsigned char)ascii); | __func__, (int)(unsigned char)ascii); | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* in some cases we want to allow invalid utf8 chars */ | /* in some cases we want to allow invalid utf8 chars */ | ||||
| return ui_textedit_type_buf(but, data, buf, 1); | return ui_textedit_type_buf(but, data, buf, 1); | ||||
| } | } | ||||
| static void ui_textedit_move(uiBut *but, uiHandleButtonData *data, strCursorJumpDirection direction, | static void ui_textedit_move(uiBut *but, uiHandleButtonData *data, strCursorJumpDirection direction, | ||||
| const bool select, strCursorJumpType jump) | const bool select, strCursorJumpType jump) | ||||
| { | { | ||||
| const char *str = data->str; | const char *str = data->str; | ||||
| const int len = strlen(str); | const int len = strlen(str); | ||||
| const int pos_prev = but->pos; | const int pos_prev = but->pos; | ||||
| const bool has_sel = (but->selend - but->selsta) > 0; | const bool has_sel = (but->selend - but->selsta) > 0; | ||||
| ui_check_but(but); | ui_but_update(but); | ||||
| /* special case, quit selection and set cursor */ | /* special case, quit selection and set cursor */ | ||||
| if (has_sel && !select) { | if (has_sel && !select) { | ||||
| if (jump == STRCUR_JUMP_ALL) { | if (jump == STRCUR_JUMP_ALL) { | ||||
| but->selsta = but->selend = but->pos = direction ? len : 0; | but->selsta = but->selend = but->pos = direction ? len : 0; | ||||
| } | } | ||||
| else { | else { | ||||
| if (direction) { | if (direction) { | ||||
| ▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | static bool ui_textedit_copypaste(uiBut *but, uiHandleButtonData *data, const int mode) | ||||
| bool changed = false; | bool changed = false; | ||||
| int str_len, buf_len; | int str_len, buf_len; | ||||
| str = data->str; | str = data->str; | ||||
| str_len = strlen(str); | str_len = strlen(str); | ||||
| /* paste */ | /* paste */ | ||||
| if (mode == UI_TEXTEDIT_PASTE) { | if (mode == UI_TEXTEDIT_PASTE) { | ||||
| /* TODO, ensure UTF8 ui_is_but_utf8() - campbell */ | /* TODO, ensure UTF8 ui_but_is_utf8() - campbell */ | ||||
| /* extract the first line from the clipboard */ | /* extract the first line from the clipboard */ | ||||
| pbuf = WM_clipboard_text_get_firstline(false, &buf_len); | pbuf = WM_clipboard_text_get_firstline(false, &buf_len); | ||||
| if (pbuf) { | if (pbuf) { | ||||
| char buf[UI_MAX_DRAW_STR] = {0}; | char buf[UI_MAX_DRAW_STR] = {0}; | ||||
| unsigned int y; | unsigned int y; | ||||
| buf_len = BLI_strncpy_rlen(buf, pbuf, sizeof(buf)); | buf_len = BLI_strncpy_rlen(buf, pbuf, sizeof(buf)); | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | if (data->str) { | ||||
| data->str = NULL; | data->str = NULL; | ||||
| } | } | ||||
| #ifdef USE_DRAG_MULTINUM | #ifdef USE_DRAG_MULTINUM | ||||
| /* this can happen from multi-drag */ | /* this can happen from multi-drag */ | ||||
| if (data->applied_interactive) { | if (data->applied_interactive) { | ||||
| /* remove any small changes so canceling edit doesn't restore invalid value: T40538 */ | /* remove any small changes so canceling edit doesn't restore invalid value: T40538 */ | ||||
| data->cancel = true; | data->cancel = true; | ||||
| ui_apply_button(C, but->block, but, data, true); | ui_apply_but(C, but->block, but, data, true); | ||||
| data->cancel = false; | data->cancel = false; | ||||
| data->applied_interactive = false; | data->applied_interactive = false; | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* retrieve string */ | /* retrieve string */ | ||||
| data->maxlen = ui_get_but_string_max_length(but); | data->maxlen = ui_but_string_get_max_length(but); | ||||
| data->str = MEM_callocN(sizeof(char) * data->maxlen + 1, "textedit str"); | data->str = MEM_callocN(sizeof(char) * data->maxlen + 1, "textedit str"); | ||||
| ui_get_but_string(but, data->str, data->maxlen); | ui_but_string_get(but, data->str, data->maxlen); | ||||
| if (ui_is_but_float(but) && !ui_is_but_unit(but)) { | if (ui_but_is_float(but) && !ui_but_is_unit(but)) { | ||||
| BLI_str_rstrip_float_zero(data->str, '\0'); | BLI_str_rstrip_float_zero(data->str, '\0'); | ||||
| } | } | ||||
| if (ELEM(but->type, NUM, NUMSLI)) { | if (ELEM(but->type, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER)) { | ||||
| ui_convert_to_unit_alt_name(but, data->str, data->maxlen); | ui_but_convert_to_unit_alt_name(but, data->str, data->maxlen); | ||||
| } | } | ||||
| /* won't change from now on */ | /* won't change from now on */ | ||||
| len = strlen(data->str); | len = strlen(data->str); | ||||
| data->origstr = BLI_strdupn(data->str, len); | data->origstr = BLI_strdupn(data->str, len); | ||||
| data->selextend = 0; | data->selextend = 0; | ||||
| data->selstartx = 0.0f; | data->selstartx = 0.0f; | ||||
| /* set cursor pos to the end of the text */ | /* set cursor pos to the end of the text */ | ||||
| but->editstr = data->str; | but->editstr = data->str; | ||||
| but->pos = len; | but->pos = len; | ||||
| but->selsta = 0; | but->selsta = 0; | ||||
| but->selend = len; | but->selend = len; | ||||
| /* optional searchbox */ | /* optional searchbox */ | ||||
| if (ELEM(but->type, SEARCH_MENU, SEARCH_MENU_UNLINK)) { | if (ELEM(but->type, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { | ||||
| data->searchbox = ui_searchbox_create(C, data->region, but); | data->searchbox = ui_searchbox_create(C, data->region, but); | ||||
| ui_searchbox_update(C, data->searchbox, but, true); /* true = reset */ | ui_searchbox_update(C, data->searchbox, but, true); /* true = reset */ | ||||
| } | } | ||||
| /* reset alert flag (avoid confusion, will refresh on exit) */ | /* reset alert flag (avoid confusion, will refresh on exit) */ | ||||
| but->flag &= ~UI_BUT_REDALERT; | but->flag &= ~UI_BUT_REDALERT; | ||||
| ui_check_but(but); | ui_but_update(but); | ||||
| WM_cursor_modal_set(CTX_wm_window(C), BC_TEXTEDITCURSOR); | WM_cursor_modal_set(CTX_wm_window(C), BC_TEXTEDITCURSOR); | ||||
| } | } | ||||
| static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data) | static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data) | ||||
| { | { | ||||
| if (but) { | if (but) { | ||||
| if (ui_is_but_utf8(but)) { | if (ui_but_is_utf8(but)) { | ||||
| int strip = BLI_utf8_invalid_strip(but->editstr, strlen(but->editstr)); | int strip = BLI_utf8_invalid_strip(but->editstr, strlen(but->editstr)); | ||||
| /* not a file?, strip non utf-8 chars */ | /* not a file?, strip non utf-8 chars */ | ||||
| if (strip) { | if (strip) { | ||||
| /* wont happen often so isn't that annoying to keep it here for a while */ | /* wont happen often so isn't that annoying to keep it here for a while */ | ||||
| printf("%s: invalid utf8 - stripped chars %d\n", __func__, strip); | printf("%s: invalid utf8 - stripped chars %d\n", __func__, strip); | ||||
| } | } | ||||
| } | } | ||||
| Show All 20 Lines | static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data) | ||||
| WM_cursor_modal_restore(CTX_wm_window(C)); | WM_cursor_modal_restore(CTX_wm_window(C)); | ||||
| } | } | ||||
| static void ui_textedit_next_but(uiBlock *block, uiBut *actbut, uiHandleButtonData *data) | static void ui_textedit_next_but(uiBlock *block, uiBut *actbut, uiHandleButtonData *data) | ||||
| { | { | ||||
| uiBut *but; | uiBut *but; | ||||
| /* label and roundbox can overlap real buttons (backdrops...) */ | /* label and roundbox can overlap real buttons (backdrops...) */ | ||||
| if (ELEM(actbut->type, LABEL, SEPR, SEPRLINE, ROUNDBOX, LISTBOX)) | if (ELEM(actbut->type, UI_BTYPE_LABEL, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE, UI_BTYPE_ROUNDBOX, UI_BTYPE_LISTBOX)) | ||||
| return; | return; | ||||
| for (but = actbut->next; but; but = but->next) { | for (but = actbut->next; but; but = but->next) { | ||||
| if (ELEM(but->type, TEX, NUM, NUMSLI, SEARCH_MENU, SEARCH_MENU_UNLINK)) { | if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { | ||||
| if (!(but->flag & UI_BUT_DISABLED)) { | if (!(but->flag & UI_BUT_DISABLED)) { | ||||
| data->postbut = but; | data->postbut = but; | ||||
| data->posttype = BUTTON_ACTIVATE_TEXT_EDITING; | data->posttype = BUTTON_ACTIVATE_TEXT_EDITING; | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| for (but = block->buttons.first; but != actbut; but = but->next) { | for (but = block->buttons.first; but != actbut; but = but->next) { | ||||
| if (ELEM(but->type, TEX, NUM, NUMSLI, SEARCH_MENU, SEARCH_MENU_UNLINK)) { | if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { | ||||
| if (!(but->flag & UI_BUT_DISABLED)) { | if (!(but->flag & UI_BUT_DISABLED)) { | ||||
| data->postbut = but; | data->postbut = but; | ||||
| data->posttype = BUTTON_ACTIVATE_TEXT_EDITING; | data->posttype = BUTTON_ACTIVATE_TEXT_EDITING; | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void ui_textedit_prev_but(uiBlock *block, uiBut *actbut, uiHandleButtonData *data) | static void ui_textedit_prev_but(uiBlock *block, uiBut *actbut, uiHandleButtonData *data) | ||||
| { | { | ||||
| uiBut *but; | uiBut *but; | ||||
| /* label and roundbox can overlap real buttons (backdrops...) */ | /* label and roundbox can overlap real buttons (backdrops...) */ | ||||
| if (ELEM(actbut->type, LABEL, SEPR, SEPRLINE, ROUNDBOX, LISTBOX)) | if (ELEM(actbut->type, UI_BTYPE_LABEL, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE, UI_BTYPE_ROUNDBOX, UI_BTYPE_LISTBOX)) | ||||
| return; | return; | ||||
| for (but = actbut->prev; but; but = but->prev) { | for (but = actbut->prev; but; but = but->prev) { | ||||
| if (ELEM(but->type, TEX, NUM, NUMSLI, SEARCH_MENU, SEARCH_MENU_UNLINK)) { | if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { | ||||
| if (!(but->flag & UI_BUT_DISABLED)) { | if (!(but->flag & UI_BUT_DISABLED)) { | ||||
| data->postbut = but; | data->postbut = but; | ||||
| data->posttype = BUTTON_ACTIVATE_TEXT_EDITING; | data->posttype = BUTTON_ACTIVATE_TEXT_EDITING; | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| for (but = block->buttons.last; but != actbut; but = but->prev) { | for (but = block->buttons.last; but != actbut; but = but->prev) { | ||||
| if (ELEM(but->type, TEX, NUM, NUMSLI, SEARCH_MENU, SEARCH_MENU_UNLINK)) { | if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { | ||||
| if (!(but->flag & UI_BUT_DISABLED)) { | if (!(but->flag & UI_BUT_DISABLED)) { | ||||
| data->postbut = but; | data->postbut = but; | ||||
| data->posttype = BUTTON_ACTIVATE_TEXT_EDITING; | data->posttype = BUTTON_ACTIVATE_TEXT_EDITING; | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | #endif | ||||
| } | } | ||||
| if ((event->ascii || event->utf8_buf[0]) && (retval == WM_UI_HANDLER_CONTINUE)) { | if ((event->ascii || event->utf8_buf[0]) && (retval == WM_UI_HANDLER_CONTINUE)) { | ||||
| char ascii = event->ascii; | char ascii = event->ascii; | ||||
| const char *utf8_buf = event->utf8_buf; | const char *utf8_buf = event->utf8_buf; | ||||
| /* exception that's useful for number buttons, some keyboard | /* exception that's useful for number buttons, some keyboard | ||||
| * numpads have a comma instead of a period */ | * numpads have a comma instead of a period */ | ||||
| if (ELEM(but->type, NUM, NUMSLI)) { /* could use data->min*/ | if (ELEM(but->type, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER)) { /* could use data->min*/ | ||||
| if (event->type == PADPERIOD && ascii == ',') { | if (event->type == PADPERIOD && ascii == ',') { | ||||
| ascii = '.'; | ascii = '.'; | ||||
| utf8_buf = NULL; /* force ascii fallback */ | utf8_buf = NULL; /* force ascii fallback */ | ||||
| } | } | ||||
| } | } | ||||
| if (utf8_buf && utf8_buf[0]) { | if (utf8_buf && utf8_buf[0]) { | ||||
| int utf8_buf_len = BLI_str_utf8_size(utf8_buf); | int utf8_buf_len = BLI_str_utf8_size(utf8_buf); | ||||
| Show All 15 Lines | #endif | ||||
| /* textbutton with magnifier icon: do live update for search button */ | /* textbutton with magnifier icon: do live update for search button */ | ||||
| if (but->icon == ICON_VIEWZOOM) | if (but->icon == ICON_VIEWZOOM) | ||||
| update = true; | update = true; | ||||
| } | } | ||||
| if (changed) { | if (changed) { | ||||
| /* only update when typing for TAB key */ | /* only update when typing for TAB key */ | ||||
| if (update && data->interactive) { | if (update && data->interactive) { | ||||
| ui_apply_button(C, block, but, data, true); | ui_apply_but(C, block, but, data, true); | ||||
| } | } | ||||
| else { | else { | ||||
| ui_check_but(but); | ui_but_update(but); | ||||
| } | } | ||||
| but->changed = true; | but->changed = true; | ||||
| if (data->searchbox) | if (data->searchbox) | ||||
| ui_searchbox_update(C, data->searchbox, but, true); /* true = reset */ | ui_searchbox_update(C, data->searchbox, but, true); /* true = reset */ | ||||
| } | } | ||||
| if (changed || (retval == WM_UI_HANDLER_BREAK)) | if (changed || (retval == WM_UI_HANDLER_BREAK)) | ||||
| Show All 18 Lines | switch (event->type) { | ||||
| case LEFTMOUSE: | case LEFTMOUSE: | ||||
| if (event->val == KM_RELEASE) | if (event->val == KM_RELEASE) | ||||
| button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); | button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); | ||||
| retval = WM_UI_HANDLER_BREAK; | retval = WM_UI_HANDLER_BREAK; | ||||
| break; | break; | ||||
| } | } | ||||
| if (retval == WM_UI_HANDLER_BREAK) { | if (retval == WM_UI_HANDLER_BREAK) { | ||||
| ui_check_but(but); | ui_but_update(but); | ||||
| ED_region_tag_redraw(data->region); | ED_region_tag_redraw(data->region); | ||||
| } | } | ||||
| } | } | ||||
| /* ************* number editing for various types ************* */ | /* ************* number editing for various types ************* */ | ||||
| static void ui_numedit_begin(uiBut *but, uiHandleButtonData *data) | static void ui_numedit_begin(uiBut *but, uiHandleButtonData *data) | ||||
| { | { | ||||
| if (but->type == BUT_CURVE) { | if (but->type == UI_BTYPE_CURVE) { | ||||
| but->editcumap = (CurveMapping *)but->poin; | but->editcumap = (CurveMapping *)but->poin; | ||||
| } | } | ||||
| else if (but->type == BUT_COLORBAND) { | else if (but->type == UI_BTYPE_COLORBAND) { | ||||
| data->coba = (ColorBand *)but->poin; | data->coba = (ColorBand *)but->poin; | ||||
| but->editcoba = data->coba; | but->editcoba = data->coba; | ||||
| } | } | ||||
| else if (ELEM(but->type, BUT_NORMAL, HSVCUBE, HSVCIRCLE, COLOR)) { | else if (ELEM(but->type, UI_BTYPE_UNITVEC, UI_BTYPE_HSVCUBE, UI_BTYPE_HSVCIRCLE, UI_BTYPE_COLOR)) { | ||||
| ui_get_but_vectorf(but, data->origvec); | ui_but_v3_get(but, data->origvec); | ||||
| copy_v3_v3(data->vec, data->origvec); | copy_v3_v3(data->vec, data->origvec); | ||||
| but->editvec = data->vec; | but->editvec = data->vec; | ||||
| } | } | ||||
| else { | else { | ||||
| float softrange, softmin, softmax; | float softrange, softmin, softmax; | ||||
| data->startvalue = ui_get_but_val(but); | data->startvalue = ui_but_value_get(but); | ||||
| data->origvalue = data->startvalue; | data->origvalue = data->startvalue; | ||||
| data->value = data->origvalue; | data->value = data->origvalue; | ||||
| but->editval = &data->value; | but->editval = &data->value; | ||||
| softmin = but->softmin; | softmin = but->softmin; | ||||
| softmax = but->softmax; | softmax = but->softmax; | ||||
| softrange = softmax - softmin; | softrange = softmax - softmin; | ||||
| Show All 17 Lines | static void ui_numedit_end(uiBut *but, uiHandleButtonData *data) | ||||
| data->dragchange = false; | data->dragchange = false; | ||||
| data->dragcbd = NULL; | data->dragcbd = NULL; | ||||
| data->dragsel = 0; | data->dragsel = 0; | ||||
| } | } | ||||
| static void ui_numedit_apply(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data) | static void ui_numedit_apply(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data) | ||||
| { | { | ||||
| if (data->interactive) { | if (data->interactive) { | ||||
| ui_apply_button(C, block, but, data, true); | ui_apply_but(C, block, but, data, true); | ||||
| } | } | ||||
| else { | else { | ||||
| ui_check_but(but); | ui_but_update(but); | ||||
| } | } | ||||
| ED_region_tag_redraw(data->region); | ED_region_tag_redraw(data->region); | ||||
| } | } | ||||
| /* ****************** menu opening for various types **************** */ | /* ****************** menu opening for various types **************** */ | ||||
| static void ui_blockopen_begin(bContext *C, uiBut *but, uiHandleButtonData *data) | static void ui_block_open_begin(bContext *C, uiBut *but, uiHandleButtonData *data) | ||||
| { | { | ||||
| uiBlockCreateFunc func = NULL; | uiBlockCreateFunc func = NULL; | ||||
| uiBlockHandleCreateFunc handlefunc = NULL; | uiBlockHandleCreateFunc handlefunc = NULL; | ||||
| uiMenuCreateFunc menufunc = NULL; | uiMenuCreateFunc menufunc = NULL; | ||||
| void *arg = NULL; | void *arg = NULL; | ||||
| switch (but->type) { | switch (but->type) { | ||||
| case BLOCK: | case UI_BTYPE_BLOCK: | ||||
| case PULLDOWN: | case UI_BTYPE_PULLDOWN: | ||||
| if (but->menu_create_func) { | if (but->menu_create_func) { | ||||
| menufunc = but->menu_create_func; | menufunc = but->menu_create_func; | ||||
| arg = but->poin; | arg = but->poin; | ||||
| } | } | ||||
| else { | else { | ||||
| func = but->block_create_func; | func = but->block_create_func; | ||||
| arg = but->poin ? but->poin : but->func_argN; | arg = but->poin ? but->poin : but->func_argN; | ||||
| } | } | ||||
| break; | break; | ||||
| case MENU: | case UI_BTYPE_MENU: | ||||
| BLI_assert(but->menu_create_func); | BLI_assert(but->menu_create_func); | ||||
| menufunc = but->menu_create_func; | menufunc = but->menu_create_func; | ||||
| arg = but->poin; | arg = but->poin; | ||||
| break; | break; | ||||
| case COLOR: | case UI_BTYPE_COLOR: | ||||
| ui_get_but_vectorf(but, data->origvec); | ui_but_v3_get(but, data->origvec); | ||||
| copy_v3_v3(data->vec, data->origvec); | copy_v3_v3(data->vec, data->origvec); | ||||
| but->editvec = data->vec; | but->editvec = data->vec; | ||||
| handlefunc = ui_block_func_COLOR; | handlefunc = ui_block_func_COLOR; | ||||
| arg = but; | arg = but; | ||||
| break; | break; | ||||
| /* quiet warnings for unhandled types */ | /* quiet warnings for unhandled types */ | ||||
| Show All 11 Lines | else if (menufunc) { | ||||
| if (but->block->handle) | if (but->block->handle) | ||||
| data->menu->popup = but->block->handle->popup; | data->menu->popup = but->block->handle->popup; | ||||
| } | } | ||||
| /* this makes adjacent blocks auto open from now on */ | /* this makes adjacent blocks auto open from now on */ | ||||
| //if (but->block->auto_open == 0) but->block->auto_open = 1; | //if (but->block->auto_open == 0) but->block->auto_open = 1; | ||||
| } | } | ||||
| static void ui_blockopen_end(bContext *C, uiBut *but, uiHandleButtonData *data) | static void ui_block_open_end(bContext *C, uiBut *but, uiHandleButtonData *data) | ||||
| { | { | ||||
| if (but) { | if (but) { | ||||
| but->editval = NULL; | but->editval = NULL; | ||||
| but->editvec = NULL; | but->editvec = NULL; | ||||
| but->block->auto_open_last = PIL_check_seconds_timer(); | but->block->auto_open_last = PIL_check_seconds_timer(); | ||||
| } | } | ||||
| if (data->menu) { | if (data->menu) { | ||||
| ui_popup_block_free(C, data->menu); | ui_popup_block_free(C, data->menu); | ||||
| data->menu = NULL; | data->menu = NULL; | ||||
| } | } | ||||
| } | } | ||||
| int ui_button_open_menu_direction(uiBut *but) | int ui_but_menu_direction(uiBut *but) | ||||
| { | { | ||||
| uiHandleButtonData *data = but->active; | uiHandleButtonData *data = but->active; | ||||
| if (data && data->menu) | if (data && data->menu) | ||||
| return data->menu->direction; | return data->menu->direction; | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| /* Hack for uiList LISTROW buttons to "give" events to overlaying TEX buttons (cltr-clic rename feature & co). */ | /* Hack for uiList UI_BTYPE_LISTROW buttons to "give" events to overlaying UI_BTYPE_TEXT buttons (cltr-clic rename feature & co). */ | ||||
| static uiBut *ui_but_list_row_text_activate(bContext *C, uiBut *but, uiHandleButtonData *data, const wmEvent *event, | static uiBut *ui_but_list_row_text_activate(bContext *C, uiBut *but, uiHandleButtonData *data, const wmEvent *event, | ||||
| uiButtonActivateType activate_type) | uiButtonActivateType activate_type) | ||||
| { | { | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| uiBut *labelbut = ui_but_find_mouse_over_ex(ar, event->x, event->y, true); | uiBut *labelbut = ui_but_find_mouse_over_ex(ar, event->x, event->y, true); | ||||
| if (labelbut && labelbut->type == TEX && !(labelbut->flag & UI_BUT_DISABLED)) { | if (labelbut && labelbut->type == UI_BTYPE_TEXT && !(labelbut->flag & UI_BUT_DISABLED)) { | ||||
| /* exit listrow */ | /* exit listrow */ | ||||
| data->cancel = true; | data->cancel = true; | ||||
| button_activate_exit(C, but, data, false, false); | button_activate_exit(C, but, data, false, false); | ||||
| /* Activate the text button. */ | /* Activate the text button. */ | ||||
| button_activate_init(C, ar, labelbut, activate_type); | button_activate_init(C, ar, labelbut, activate_type); | ||||
| return labelbut; | return labelbut; | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | static int ui_do_but_HOTKEYEVT(bContext *C, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | ||||
| } | } | ||||
| else if (data->state == BUTTON_STATE_WAIT_KEY_EVENT) { | else if (data->state == BUTTON_STATE_WAIT_KEY_EVENT) { | ||||
| if (event->type == MOUSEMOVE) | if (event->type == MOUSEMOVE) | ||||
| return WM_UI_HANDLER_CONTINUE; | return WM_UI_HANDLER_CONTINUE; | ||||
| if (event->type == LEFTMOUSE && event->val == KM_PRESS) { | if (event->type == LEFTMOUSE && event->val == KM_PRESS) { | ||||
| /* only cancel if click outside the button */ | /* only cancel if click outside the button */ | ||||
| if (ui_mouse_inside_button(but->active->region, but, event->x, event->y) == 0) { | if (ui_but_contains_point_px(but->active->region, but, event->x, event->y) == 0) { | ||||
| /* data->cancel doesnt work, this button opens immediate */ | /* data->cancel doesnt work, this button opens immediate */ | ||||
| if (but->flag & UI_BUT_IMMEDIATE) | if (but->flag & UI_BUT_IMMEDIATE) | ||||
| ui_set_but_val(but, 0); | ui_but_value_set(but, 0); | ||||
| else | else | ||||
| data->cancel = true; | data->cancel = true; | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| } | } | ||||
| /* always set */ | /* always set */ | ||||
| but->modifier_key = 0; | but->modifier_key = 0; | ||||
| if (event->shift) but->modifier_key |= KM_SHIFT; | if (event->shift) but->modifier_key |= KM_SHIFT; | ||||
| if (event->alt) but->modifier_key |= KM_ALT; | if (event->alt) but->modifier_key |= KM_ALT; | ||||
| if (event->ctrl) but->modifier_key |= KM_CTRL; | if (event->ctrl) but->modifier_key |= KM_CTRL; | ||||
| if (event->oskey) but->modifier_key |= KM_OSKEY; | if (event->oskey) but->modifier_key |= KM_OSKEY; | ||||
| ui_check_but(but); | ui_but_update(but); | ||||
| ED_region_tag_redraw(data->region); | ED_region_tag_redraw(data->region); | ||||
| if (event->val == KM_PRESS) { | if (event->val == KM_PRESS) { | ||||
| if (ISHOTKEY(event->type)) { | if (ISHOTKEY(event->type)) { | ||||
| if (WM_key_event_string(event->type)[0]) | if (WM_key_event_string(event->type)[0]) | ||||
| ui_set_but_val(but, event->type); | ui_but_value_set(but, event->type); | ||||
| else | else | ||||
| data->cancel = true; | data->cancel = true; | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| else if (event->type == ESCKEY) { | else if (event->type == ESCKEY) { | ||||
| if (event->val == KM_PRESS) { | if (event->val == KM_PRESS) { | ||||
| Show All 19 Lines | static int ui_do_but_KEYEVT(bContext *C, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | ||||
| } | } | ||||
| else if (data->state == BUTTON_STATE_WAIT_KEY_EVENT) { | else if (data->state == BUTTON_STATE_WAIT_KEY_EVENT) { | ||||
| if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { | if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { | ||||
| return WM_UI_HANDLER_CONTINUE; | return WM_UI_HANDLER_CONTINUE; | ||||
| } | } | ||||
| if (event->val == KM_PRESS) { | if (event->val == KM_PRESS) { | ||||
| if (WM_key_event_string(event->type)[0]) | if (WM_key_event_string(event->type)[0]) | ||||
| ui_set_but_val(but, event->type); | ui_but_value_set(but, event->type); | ||||
| else | else | ||||
| data->cancel = true; | data->cancel = true; | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| } | } | ||||
| } | } | ||||
| return WM_UI_HANDLER_CONTINUE; | return WM_UI_HANDLER_CONTINUE; | ||||
| } | } | ||||
| static int ui_do_but_TEX(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | static int ui_do_but_TEX(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | ||||
| { | { | ||||
| if (data->state == BUTTON_STATE_HIGHLIGHT) { | if (data->state == BUTTON_STATE_HIGHLIGHT) { | ||||
| if (ELEM(event->type, LEFTMOUSE, EVT_BUT_OPEN, PADENTER, RETKEY) && event->val == KM_PRESS) { | if (ELEM(event->type, LEFTMOUSE, EVT_BUT_OPEN, PADENTER, RETKEY) && event->val == KM_PRESS) { | ||||
| if (ELEM(event->type, PADENTER, RETKEY) && (!ui_is_but_utf8(but))) { | if (ELEM(event->type, PADENTER, RETKEY) && (!ui_but_is_utf8(but))) { | ||||
| /* pass - allow filesel, enter to execute */ | /* pass - allow filesel, enter to execute */ | ||||
| } | } | ||||
| else if (but->dt == UI_EMBOSSN && !event->ctrl) { | else if (but->dt == UI_EMBOSS_NONE && !event->ctrl) { | ||||
| /* pass */ | /* pass */ | ||||
| } | } | ||||
| else { | else { | ||||
| button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); | button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else if (data->state == BUTTON_STATE_TEXT_EDITING) { | else if (data->state == BUTTON_STATE_TEXT_EDITING) { | ||||
| ui_do_but_textedit(C, block, but, data, event); | ui_do_but_textedit(C, block, but, data, event); | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| else if (data->state == BUTTON_STATE_TEXT_SELECTING) { | else if (data->state == BUTTON_STATE_TEXT_SELECTING) { | ||||
| ui_do_but_textedit_select(C, block, but, data, event); | ui_do_but_textedit_select(C, block, but, data, event); | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| return WM_UI_HANDLER_CONTINUE; | return WM_UI_HANDLER_CONTINUE; | ||||
| } | } | ||||
| static int ui_do_but_SEARCH_UNLINK(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | static int ui_do_but_SEARCH_UNLINK(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | ||||
| { | { | ||||
| /* unlink icon is on right */ | /* unlink icon is on right */ | ||||
| if (ELEM(event->type, LEFTMOUSE, EVT_BUT_OPEN, PADENTER, RETKEY) && event->val == KM_PRESS && | if (ELEM(event->type, LEFTMOUSE, EVT_BUT_OPEN, PADENTER, RETKEY) && event->val == KM_PRESS && | ||||
| ui_is_but_search_unlink_visible(but)) | ui_but_is_search_unlink_visible(but)) | ||||
| { | { | ||||
| ARegion *ar = data->region; | ARegion *ar = data->region; | ||||
| rcti rect; | rcti rect; | ||||
| int x = event->x, y = event->y; | int x = event->x, y = event->y; | ||||
| ui_window_to_block(ar, but->block, &x, &y); | ui_window_to_block(ar, but->block, &x, &y); | ||||
| BLI_rcti_rctf_copy(&rect, &but->rect); | BLI_rcti_rctf_copy(&rect, &but->rect); | ||||
| Show All 13 Lines | static int ui_do_but_SEARCH_UNLINK(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | ||||
| } | } | ||||
| return ui_do_but_TEX(C, block, but, data, event); | return ui_do_but_TEX(C, block, but, data, event); | ||||
| } | } | ||||
| static int ui_do_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | static int ui_do_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | ||||
| { | { | ||||
| #ifdef USE_DRAG_TOGGLE | #ifdef USE_DRAG_TOGGLE | ||||
| if (data->state == BUTTON_STATE_HIGHLIGHT) { | if (data->state == BUTTON_STATE_HIGHLIGHT) { | ||||
| if (event->type == LEFTMOUSE && event->val == KM_PRESS && ui_is_but_drag_toggle(but)) { | if (event->type == LEFTMOUSE && event->val == KM_PRESS && ui_but_is_drag_toggle(but)) { | ||||
| #if 0 /* UNUSED */ | #if 0 /* UNUSED */ | ||||
| data->togdual = event->ctrl; | data->togdual = event->ctrl; | ||||
| data->togonly = !event->shift; | data->togonly = !event->shift; | ||||
| #endif | #endif | ||||
| ui_apply_button(C, but->block, but, data, true); | ui_apply_but(C, but->block, but, data, true); | ||||
| button_activate_state(C, but, BUTTON_STATE_WAIT_DRAG); | button_activate_state(C, but, BUTTON_STATE_WAIT_DRAG); | ||||
| data->dragstartx = event->x; | data->dragstartx = event->x; | ||||
| data->dragstarty = event->y; | data->dragstarty = event->y; | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| } | } | ||||
| else if (data->state == BUTTON_STATE_WAIT_DRAG) { | else if (data->state == BUTTON_STATE_WAIT_DRAG) { | ||||
| /* note: the 'BUTTON_STATE_WAIT_DRAG' part of 'ui_do_but_EXIT' could be refactored into its own function */ | /* note: the 'BUTTON_STATE_WAIT_DRAG' part of 'ui_do_but_EXIT' could be refactored into its own function */ | ||||
| Show All 16 Lines | |||||
| static int ui_do_but_EXIT(bContext *C, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | static int ui_do_but_EXIT(bContext *C, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | ||||
| { | { | ||||
| if (data->state == BUTTON_STATE_HIGHLIGHT) { | if (data->state == BUTTON_STATE_HIGHLIGHT) { | ||||
| /* first handle click on icondrag type button */ | /* first handle click on icondrag type button */ | ||||
| if (event->type == LEFTMOUSE && but->dragpoin) { | if (event->type == LEFTMOUSE && but->dragpoin) { | ||||
| if (ui_but_mouse_inside_icon(but, data->region, event)) { | if (ui_but_contains_point_px_icon(but, data->region, event)) { | ||||
| /* tell the button to wait and keep checking further events to | /* tell the button to wait and keep checking further events to | ||||
| * see if it should start dragging */ | * see if it should start dragging */ | ||||
| button_activate_state(C, but, BUTTON_STATE_WAIT_DRAG); | button_activate_state(C, but, BUTTON_STATE_WAIT_DRAG); | ||||
| data->dragstartx = event->x; | data->dragstartx = event->x; | ||||
| data->dragstarty = event->y; | data->dragstarty = event->y; | ||||
| return WM_UI_HANDLER_CONTINUE; | return WM_UI_HANDLER_CONTINUE; | ||||
| } | } | ||||
| } | } | ||||
| #ifdef USE_DRAG_TOGGLE | #ifdef USE_DRAG_TOGGLE | ||||
| if (event->type == LEFTMOUSE && ui_is_but_drag_toggle(but)) { | if (event->type == LEFTMOUSE && ui_but_is_drag_toggle(but)) { | ||||
| button_activate_state(C, but, BUTTON_STATE_WAIT_DRAG); | button_activate_state(C, but, BUTTON_STATE_WAIT_DRAG); | ||||
| data->dragstartx = event->x; | data->dragstartx = event->x; | ||||
| data->dragstarty = event->y; | data->dragstarty = event->y; | ||||
| return WM_UI_HANDLER_CONTINUE; | return WM_UI_HANDLER_CONTINUE; | ||||
| } | } | ||||
| #endif | #endif | ||||
| if (ELEM(event->type, LEFTMOUSE, PADENTER, RETKEY) && event->val == KM_PRESS) { | if (ELEM(event->type, LEFTMOUSE, PADENTER, RETKEY) && event->val == KM_PRESS) { | ||||
| int ret = WM_UI_HANDLER_BREAK; | int ret = WM_UI_HANDLER_BREAK; | ||||
| /* XXX (a bit ugly) Special case handling for filebrowser drag button */ | /* XXX (a bit ugly) Special case handling for filebrowser drag button */ | ||||
| if (but->dragpoin && but->imb && ui_but_mouse_inside_icon(but, data->region, event)) { | if (but->dragpoin && but->imb && ui_but_contains_point_px_icon(but, data->region, event)) { | ||||
| ret = WM_UI_HANDLER_CONTINUE; | ret = WM_UI_HANDLER_CONTINUE; | ||||
| } | } | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| } | } | ||||
| else if (data->state == BUTTON_STATE_WAIT_DRAG) { | else if (data->state == BUTTON_STATE_WAIT_DRAG) { | ||||
| /* this function also ends state */ | /* this function also ends state */ | ||||
| if (ui_but_start_drag(C, but, data, event)) { | if (ui_but_drag_init(C, but, data, event)) { | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| /* If the mouse has been pressed and released, getting to | /* If the mouse has been pressed and released, getting to | ||||
| * this point without triggering a drag, then clear the | * this point without triggering a drag, then clear the | ||||
| * drag state for this button and continue to pass on the event */ | * drag state for this button and continue to pass on the event */ | ||||
| if (event->type == LEFTMOUSE && event->val == KM_RELEASE) { | if (event->type == LEFTMOUSE && event->val == KM_RELEASE) { | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| Show All 13 Lines | static float ui_numedit_apply_snapf(uiBut *but, float tempf, float softmin, float softmax, float softrange, | ||||
| const enum eSnapType snap) | const enum eSnapType snap) | ||||
| { | { | ||||
| if (tempf == softmin || tempf == softmax || snap == SNAP_OFF) { | if (tempf == softmin || tempf == softmax || snap == SNAP_OFF) { | ||||
| /* pass */ | /* pass */ | ||||
| } | } | ||||
| else { | else { | ||||
| float fac = 1.0f; | float fac = 1.0f; | ||||
| if (ui_is_but_unit(but)) { | if (ui_but_is_unit(but)) { | ||||
| UnitSettings *unit = but->block->unit; | UnitSettings *unit = but->block->unit; | ||||
| int unit_type = RNA_SUBTYPE_UNIT_VALUE(uiButGetUnitType(but)); | int unit_type = RNA_SUBTYPE_UNIT_VALUE(UI_but_unit_type_get(but)); | ||||
| if (bUnit_IsValid(unit->system, unit_type)) { | if (bUnit_IsValid(unit->system, unit_type)) { | ||||
| fac = (float)bUnit_BaseScalar(unit->system, unit_type); | fac = (float)bUnit_BaseScalar(unit->system, unit_type); | ||||
| if (ELEM(unit_type, B_UNIT_LENGTH, B_UNIT_AREA, B_UNIT_VOLUME)) { | if (ELEM(unit_type, B_UNIT_LENGTH, B_UNIT_AREA, B_UNIT_VOLUME)) { | ||||
| fac /= unit->scale_length; | fac /= unit->scale_length; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
| static bool ui_numedit_but_NUM(uiBut *but, uiHandleButtonData *data, | static bool ui_numedit_but_NUM(uiBut *but, uiHandleButtonData *data, | ||||
| int mx, | int mx, | ||||
| const enum eSnapType snap, float fac) | const enum eSnapType snap, float fac) | ||||
| { | { | ||||
| float deler, tempf, softmin, softmax, softrange; | float deler, tempf, softmin, softmax, softrange; | ||||
| int lvalue, temp; | int lvalue, temp; | ||||
| bool changed = false; | bool changed = false; | ||||
| const bool is_float = ui_is_but_float(but); | const bool is_float = ui_but_is_float(but); | ||||
| if (mx == data->draglastx) | if (mx == data->draglastx) | ||||
| return changed; | return changed; | ||||
| /* drag-lock - prevent unwanted scroll adjustments */ | /* drag-lock - prevent unwanted scroll adjustments */ | ||||
| /* change value (now 3) to adjust threshold in pixels */ | /* change value (now 3) to adjust threshold in pixels */ | ||||
| if (data->draglock) { | if (data->draglock) { | ||||
| if (abs(mx - data->dragstartx) <= 3) | if (abs(mx - data->dragstartx) <= 3) | ||||
| return changed; | return changed; | ||||
| #ifdef USE_DRAG_MULTINUM | #ifdef USE_DRAG_MULTINUM | ||||
| if (ELEM(data->multi_data.init, BUTTON_MULTI_INIT_UNSET, BUTTON_MULTI_INIT_SETUP)) { | if (ELEM(data->multi_data.init, BUTTON_MULTI_INIT_UNSET, BUTTON_MULTI_INIT_SETUP)) { | ||||
| return changed; | return changed; | ||||
| } | } | ||||
| #endif | #endif | ||||
| data->draglock = false; | data->draglock = false; | ||||
| data->dragstartx = mx; /* ignore mouse movement within drag-lock */ | data->dragstartx = mx; /* ignore mouse movement within drag-lock */ | ||||
| } | } | ||||
| softmin = but->softmin; | softmin = but->softmin; | ||||
| softmax = but->softmax; | softmax = but->softmax; | ||||
| softrange = softmax - softmin; | softrange = softmax - softmin; | ||||
| if (ui_is_a_warp_but(but)) { | if (ui_but_is_cursor_warp(but)) { | ||||
| /* Mouse location isn't screen clamped to the screen so use a linear mapping | /* Mouse location isn't screen clamped to the screen so use a linear mapping | ||||
| * 2px == 1-int, or 1px == 1-ClickStep */ | * 2px == 1-int, or 1px == 1-ClickStep */ | ||||
| if (is_float) { | if (is_float) { | ||||
| fac *= 0.01f * but->a1; | fac *= 0.01f * but->a1; | ||||
| tempf = (float)data->startvalue + ((float)(mx - data->dragstartx) * fac); | tempf = (float)data->startvalue + ((float)(mx - data->dragstartx) * fac); | ||||
| tempf = ui_numedit_apply_snapf(but, tempf, softmin, softmax, softrange, snap); | tempf = ui_numedit_apply_snapf(but, tempf, softmin, softmax, softrange, snap); | ||||
| #if 1 /* fake moving the click start, nicer for dragging back after passing the limit */ | #if 1 /* fake moving the click start, nicer for dragging back after passing the limit */ | ||||
| ▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Lines | else if (type == WHEELUPMOUSE && event->alt) { | ||||
| click = 1; | click = 1; | ||||
| } | } | ||||
| else if (event->val == KM_PRESS) { | else if (event->val == KM_PRESS) { | ||||
| if (ELEM(event->type, LEFTMOUSE, PADENTER, RETKEY) && event->ctrl) { | if (ELEM(event->type, LEFTMOUSE, PADENTER, RETKEY) && event->ctrl) { | ||||
| button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); | button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); | ||||
| retval = WM_UI_HANDLER_BREAK; | retval = WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| else if (event->type == LEFTMOUSE) { | else if (event->type == LEFTMOUSE) { | ||||
| data->dragstartx = data->draglastx = ui_is_a_warp_but(but) ? screen_mx : mx; | data->dragstartx = data->draglastx = ui_but_is_cursor_warp(but) ? screen_mx : mx; | ||||
| button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); | button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); | ||||
| retval = WM_UI_HANDLER_BREAK; | retval = WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| else if (ELEM(event->type, PADENTER, RETKEY) && event->val == KM_PRESS) { | else if (ELEM(event->type, PADENTER, RETKEY) && event->val == KM_PRESS) { | ||||
| click = 1; | click = 1; | ||||
| } | } | ||||
| else if (event->type == MINUSKEY && event->val == KM_PRESS) { | else if (event->type == MINUSKEY && event->val == KM_PRESS) { | ||||
| button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); | button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | #ifdef USE_DRAG_MULTINUM | ||||
| data->multi_data.drag_dir[0] += abs(data->draglastx - mx); | data->multi_data.drag_dir[0] += abs(data->draglastx - mx); | ||||
| data->multi_data.drag_dir[1] += abs(data->draglasty - my); | data->multi_data.drag_dir[1] += abs(data->draglasty - my); | ||||
| #endif | #endif | ||||
| fac = 1.0f; | fac = 1.0f; | ||||
| if (event->shift) fac /= 10.0f; | if (event->shift) fac /= 10.0f; | ||||
| if (event->alt) fac /= 20.0f; | if (event->alt) fac /= 20.0f; | ||||
| if (ui_numedit_but_NUM(but, data, (ui_is_a_warp_but(but) ? screen_mx : mx), snap, fac)) | if (ui_numedit_but_NUM(but, data, (ui_but_is_cursor_warp(but) ? screen_mx : mx), snap, fac)) | ||||
| ui_numedit_apply(C, block, but, data); | ui_numedit_apply(C, block, but, data); | ||||
| #ifdef USE_DRAG_MULTINUM | #ifdef USE_DRAG_MULTINUM | ||||
| else if (data->multi_data.has_mbuts) { | else if (data->multi_data.has_mbuts) { | ||||
| if (data->multi_data.init == BUTTON_MULTI_INIT_ENABLE) { | if (data->multi_data.init == BUTTON_MULTI_INIT_ENABLE) { | ||||
| ui_multibut_states_apply(C, data, block); | ui_multibut_states_apply(C, data, block); | ||||
| } | } | ||||
| } | } | ||||
| #endif | #endif | ||||
| Show All 16 Lines | if (click) { | ||||
| float handlewidth; | float handlewidth; | ||||
| int temp; | int temp; | ||||
| softmin = but->softmin; | softmin = but->softmin; | ||||
| softmax = but->softmax; | softmax = but->softmax; | ||||
| handlewidth = min_ff(BLI_rctf_size_x(&but->rect) / 3, BLI_rctf_size_y(&but->rect)); | handlewidth = min_ff(BLI_rctf_size_x(&but->rect) / 3, BLI_rctf_size_y(&but->rect)); | ||||
| if (!ui_is_but_float(but)) { | if (!ui_but_is_float(but)) { | ||||
| if (mx < (but->rect.xmin + handlewidth)) { | if (mx < (but->rect.xmin + handlewidth)) { | ||||
| button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); | button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); | ||||
| temp = (int)data->value - 1; | temp = (int)data->value - 1; | ||||
| if (temp >= softmin && temp <= softmax) | if (temp >= softmin && temp <= softmax) | ||||
| data->value = (double)temp; | data->value = (double)temp; | ||||
| else | else | ||||
| data->cancel = true; | data->cancel = true; | ||||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | static bool ui_numedit_but_SLI(uiBut *but, uiHandleButtonData *data, | ||||
| softmin = but->softmin; | softmin = but->softmin; | ||||
| softmax = but->softmax; | softmax = but->softmax; | ||||
| softrange = softmax - softmin; | softrange = softmax - softmin; | ||||
| /* yes, 'mx' as both x/y is intentional */ | /* yes, 'mx' as both x/y is intentional */ | ||||
| ui_mouse_scale_warp(data, mx, mx, &mx_fl, &my_fl, shift); | ui_mouse_scale_warp(data, mx, mx, &mx_fl, &my_fl, shift); | ||||
| if (but->type == NUMSLI) { | if (but->type == UI_BTYPE_NUM_SLIDER) { | ||||
| offs = (BLI_rctf_size_y(&but->rect) / 2.0f); | offs = (BLI_rctf_size_y(&but->rect) / 2.0f); | ||||
| deler = BLI_rctf_size_x(&but->rect) - offs; | deler = BLI_rctf_size_x(&but->rect) - offs; | ||||
| } | } | ||||
| else if (but->type == SCROLL) { | else if (but->type == UI_BTYPE_SCROLL) { | ||||
| const float size = (is_horizontal) ? BLI_rctf_size_x(&but->rect) : -BLI_rctf_size_y(&but->rect); | const float size = (is_horizontal) ? BLI_rctf_size_x(&but->rect) : -BLI_rctf_size_y(&but->rect); | ||||
| deler = size * (but->softmax - but->softmin) / (but->softmax - but->softmin + but->a1); | deler = size * (but->softmax - but->softmin) / (but->softmax - but->softmin + but->a1); | ||||
| offs = 0.0; | offs = 0.0; | ||||
| } | } | ||||
| else { | else { | ||||
| offs = (BLI_rctf_size_y(&but->rect) / 2.0f); | offs = (BLI_rctf_size_y(&but->rect) / 2.0f); | ||||
| deler = (BLI_rctf_size_x(&but->rect) - offs); | deler = (BLI_rctf_size_x(&but->rect) - offs); | ||||
| } | } | ||||
| f = (mx_fl - data->dragstartx) / deler + data->dragfstart; | f = (mx_fl - data->dragstartx) / deler + data->dragfstart; | ||||
| CLAMP(f, 0.0f, 1.0f); | CLAMP(f, 0.0f, 1.0f); | ||||
| /* deal with mouse correction */ | /* deal with mouse correction */ | ||||
| #ifdef USE_CONT_MOUSE_CORRECT | #ifdef USE_CONT_MOUSE_CORRECT | ||||
| if (ui_is_a_warp_but(but)) { | if (ui_but_is_cursor_warp(but)) { | ||||
| /* OK but can go outside bounds */ | /* OK but can go outside bounds */ | ||||
| if (is_horizontal) { | if (is_horizontal) { | ||||
| data->ungrab_mval[0] = (but->rect.xmin + offs) + (f * deler); | data->ungrab_mval[0] = (but->rect.xmin + offs) + (f * deler); | ||||
| data->ungrab_mval[1] = BLI_rctf_cent_y(&but->rect); | data->ungrab_mval[1] = BLI_rctf_cent_y(&but->rect); | ||||
| } | } | ||||
| else { | else { | ||||
| data->ungrab_mval[1] = (but->rect.ymin + offs) + (f * deler); | data->ungrab_mval[1] = (but->rect.ymin + offs) + (f * deler); | ||||
| data->ungrab_mval[0] = BLI_rctf_cent_x(&but->rect); | data->ungrab_mval[0] = BLI_rctf_cent_x(&but->rect); | ||||
| } | } | ||||
| BLI_rctf_clamp_pt_v(&but->rect, data->ungrab_mval); | BLI_rctf_clamp_pt_v(&but->rect, data->ungrab_mval); | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* done correcting mouse */ | /* done correcting mouse */ | ||||
| tempf = softmin + f * softrange; | tempf = softmin + f * softrange; | ||||
| temp = floorf(tempf + 0.5f); | temp = floorf(tempf + 0.5f); | ||||
| if (snap) { | if (snap) { | ||||
| if (tempf == softmin || tempf == softmax) { | if (tempf == softmin || tempf == softmax) { | ||||
| /* pass */ | /* pass */ | ||||
| } | } | ||||
| else if (ui_is_but_float(but)) { | else if (ui_but_is_float(but)) { | ||||
| if (shift) { | if (shift) { | ||||
| if (tempf == softmin || tempf == softmax) {} | if (tempf == softmin || tempf == softmax) {} | ||||
| else if (softmax - softmin < 2.10f) tempf = 0.01f * floorf(100.0f * tempf); | else if (softmax - softmin < 2.10f) tempf = 0.01f * floorf(100.0f * tempf); | ||||
| else if (softmax - softmin < 21.0f) tempf = 0.1f * floorf(10.0f * tempf); | else if (softmax - softmin < 21.0f) tempf = 0.1f * floorf(10.0f * tempf); | ||||
| else tempf = floorf(tempf); | else tempf = floorf(tempf); | ||||
| } | } | ||||
| else { | else { | ||||
| if (softmax - softmin < 2.10f) tempf = 0.1f * floorf(10.0f * tempf); | if (softmax - softmin < 2.10f) tempf = 0.1f * floorf(10.0f * tempf); | ||||
| else if (softmax - softmin < 21.0f) tempf = floorf(tempf); | else if (softmax - softmin < 21.0f) tempf = floorf(tempf); | ||||
| else tempf = 10.0f * floorf(tempf / 10.0f); | else tempf = 10.0f * floorf(tempf / 10.0f); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| temp = 10 * (temp / 10); | temp = 10 * (temp / 10); | ||||
| tempf = temp; | tempf = temp; | ||||
| } | } | ||||
| } | } | ||||
| if (!ui_is_but_float(but)) { | if (!ui_but_is_float(but)) { | ||||
| lvalue = floor(data->value + 0.5); | lvalue = floor(data->value + 0.5); | ||||
| CLAMP(temp, softmin, softmax); | CLAMP(temp, softmin, softmax); | ||||
| if (temp != lvalue) { | if (temp != lvalue) { | ||||
| data->value = temp; | data->value = temp; | ||||
| data->dragchange = true; | data->dragchange = true; | ||||
| changed = true; | changed = true; | ||||
| Show All 39 Lines | else if (type == WHEELUPMOUSE && event->alt) { | ||||
| mx = but->rect.xmax; | mx = but->rect.xmax; | ||||
| click = 2; | click = 2; | ||||
| } | } | ||||
| else if (event->val == KM_PRESS) { | else if (event->val == KM_PRESS) { | ||||
| if (ELEM(event->type, LEFTMOUSE, PADENTER, RETKEY) && event->ctrl) { | if (ELEM(event->type, LEFTMOUSE, PADENTER, RETKEY) && event->ctrl) { | ||||
| button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); | button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); | ||||
| retval = WM_UI_HANDLER_BREAK; | retval = WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| /* alt-click on sides to get "arrows" like in NUM buttons, and match wheel usage above */ | /* alt-click on sides to get "arrows" like in UI_BTYPE_NUM buttons, and match wheel usage above */ | ||||
| else if (event->type == LEFTMOUSE && event->alt) { | else if (event->type == LEFTMOUSE && event->alt) { | ||||
| int halfpos = BLI_rctf_cent_x(&but->rect); | int halfpos = BLI_rctf_cent_x(&but->rect); | ||||
| click = 2; | click = 2; | ||||
| if (mx < halfpos) | if (mx < halfpos) | ||||
| mx = but->rect.xmin; | mx = but->rect.xmin; | ||||
| else | else | ||||
| mx = but->rect.xmax; | mx = but->rect.xmax; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | #if 0 | ||||
| else | else | ||||
| #endif | #endif | ||||
| { | { | ||||
| f = (float)(mx - but->rect.xmin) / (BLI_rctf_size_x(&but->rect)); | f = (float)(mx - but->rect.xmin) / (BLI_rctf_size_x(&but->rect)); | ||||
| } | } | ||||
| f = softmin + f * softrange; | f = softmin + f * softrange; | ||||
| if (!ui_is_but_float(but)) { | if (!ui_but_is_float(but)) { | ||||
| if (f < temp) temp--; | if (f < temp) temp--; | ||||
| else temp++; | else temp++; | ||||
| if (temp >= softmin && temp <= softmax) | if (temp >= softmin && temp <= softmax) | ||||
| data->value = temp; | data->value = temp; | ||||
| else | else | ||||
| data->cancel = true; | data->cancel = true; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | |||||
| static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | ||||
| { | { | ||||
| if (data->state == BUTTON_STATE_HIGHLIGHT) { | if (data->state == BUTTON_STATE_HIGHLIGHT) { | ||||
| /* first handle click on icondrag type button */ | /* first handle click on icondrag type button */ | ||||
| if (event->type == LEFTMOUSE && but->dragpoin && event->val == KM_PRESS) { | if (event->type == LEFTMOUSE && but->dragpoin && event->val == KM_PRESS) { | ||||
| if (ui_but_mouse_inside_icon(but, data->region, event)) { | if (ui_but_contains_point_px_icon(but, data->region, event)) { | ||||
| button_activate_state(C, but, BUTTON_STATE_WAIT_DRAG); | button_activate_state(C, but, BUTTON_STATE_WAIT_DRAG); | ||||
| data->dragstartx = event->x; | data->dragstartx = event->x; | ||||
| data->dragstarty = event->y; | data->dragstarty = event->y; | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| } | } | ||||
| #ifdef USE_DRAG_TOGGLE | #ifdef USE_DRAG_TOGGLE | ||||
| if (event->type == LEFTMOUSE && event->val == KM_PRESS && (ui_is_but_drag_toggle(but))) { | if (event->type == LEFTMOUSE && event->val == KM_PRESS && (ui_but_is_drag_toggle(but))) { | ||||
| button_activate_state(C, but, BUTTON_STATE_WAIT_DRAG); | button_activate_state(C, but, BUTTON_STATE_WAIT_DRAG); | ||||
| data->dragstartx = event->x; | data->dragstartx = event->x; | ||||
| data->dragstarty = event->y; | data->dragstarty = event->y; | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* regular open menu */ | /* regular open menu */ | ||||
| if (ELEM(event->type, LEFTMOUSE, PADENTER, RETKEY) && event->val == KM_PRESS) { | if (ELEM(event->type, LEFTMOUSE, PADENTER, RETKEY) && event->val == KM_PRESS) { | ||||
| button_activate_state(C, but, BUTTON_STATE_MENU_OPEN); | button_activate_state(C, but, BUTTON_STATE_MENU_OPEN); | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| else if (but->type == MENU) { | else if (but->type == UI_BTYPE_MENU) { | ||||
| if (ELEM(event->type, WHEELDOWNMOUSE, WHEELUPMOUSE) && event->alt) { | if (ELEM(event->type, WHEELDOWNMOUSE, WHEELUPMOUSE) && event->alt) { | ||||
| const int direction = (event->type == WHEELDOWNMOUSE) ? -1 : 1; | const int direction = (event->type == WHEELDOWNMOUSE) ? -1 : 1; | ||||
| data->value = ui_step_name_menu(but, direction); | data->value = ui_but_menu_step(but, direction); | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| ui_apply_button(C, but->block, but, data, true); | ui_apply_but(C, but->block, but, data, true); | ||||
| /* button's state need to be changed to EXIT so moving mouse away from this mouse wouldn't lead | /* button's state need to be changed to EXIT so moving mouse away from this mouse wouldn't lead | ||||
| * to cancel changes made to this button, but changing state to EXIT also makes no button active for | * to cancel changes made to this button, but changing state to EXIT also makes no button active for | ||||
| * a while which leads to triggering operator when doing fast scrolling mouse wheel. | * a while which leads to triggering operator when doing fast scrolling mouse wheel. | ||||
| * using post activate stuff from button allows to make button be active again after checking for all | * using post activate stuff from button allows to make button be active again after checking for all | ||||
| * all that mouse leave and cancel stuff, so quick scroll wouldn't be an issue anymore. | * all that mouse leave and cancel stuff, so quick scroll wouldn't be an issue anymore. | ||||
| * same goes for scrolling wheel in another direction below (sergey) | * same goes for scrolling wheel in another direction below (sergey) | ||||
| */ | */ | ||||
| Show All 12 Lines | else if (but->type == UI_BTYPE_MENU) { | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else if (data->state == BUTTON_STATE_WAIT_DRAG) { | else if (data->state == BUTTON_STATE_WAIT_DRAG) { | ||||
| /* this function also ends state */ | /* this function also ends state */ | ||||
| if (ui_but_start_drag(C, but, data, event)) { | if (ui_but_drag_init(C, but, data, event)) { | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| /* outside icon quit, not needed if drag activated */ | /* outside icon quit, not needed if drag activated */ | ||||
| if (0 == ui_but_mouse_inside_icon(but, data->region, event)) { | if (0 == ui_but_contains_point_px_icon(but, data->region, event)) { | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| data->cancel = true; | data->cancel = true; | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| if (event->type == LEFTMOUSE && event->val == KM_RELEASE) { | if (event->type == LEFTMOUSE && event->val == KM_RELEASE) { | ||||
| button_activate_state(C, but, BUTTON_STATE_MENU_OPEN); | button_activate_state(C, but, BUTTON_STATE_MENU_OPEN); | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| } | } | ||||
| return WM_UI_HANDLER_CONTINUE; | return WM_UI_HANDLER_CONTINUE; | ||||
| } | } | ||||
| static bool ui_numedit_but_NORMAL(uiBut *but, uiHandleButtonData *data, | static bool ui_numedit_but_UNITVEC(uiBut *but, uiHandleButtonData *data, | ||||
| int mx, int my, | int mx, int my, | ||||
| const enum eSnapType snap) | const enum eSnapType snap) | ||||
| { | { | ||||
| float dx, dy, rad, radsq, mrad, *fp; | float dx, dy, rad, radsq, mrad, *fp; | ||||
| int mdx, mdy; | int mdx, mdy; | ||||
| bool changed = true; | bool changed = true; | ||||
| /* button is presumed square */ | /* button is presumed square */ | ||||
| ▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static int ui_do_but_COLOR(bContext *C, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | static int ui_do_but_COLOR(bContext *C, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | ||||
| { | { | ||||
| if (data->state == BUTTON_STATE_HIGHLIGHT) { | if (data->state == BUTTON_STATE_HIGHLIGHT) { | ||||
| /* first handle click on icondrag type button */ | /* first handle click on icondrag type button */ | ||||
| if (event->type == LEFTMOUSE && but->dragpoin && event->val == KM_PRESS) { | if (event->type == LEFTMOUSE && but->dragpoin && event->val == KM_PRESS) { | ||||
| ui_palette_set_active(but); | ui_palette_set_active(but); | ||||
| if (ui_but_mouse_inside_icon(but, data->region, event)) { | if (ui_but_contains_point_px_icon(but, data->region, event)) { | ||||
| button_activate_state(C, but, BUTTON_STATE_WAIT_DRAG); | button_activate_state(C, but, BUTTON_STATE_WAIT_DRAG); | ||||
| data->dragstartx = event->x; | data->dragstartx = event->x; | ||||
| data->dragstarty = event->y; | data->dragstarty = event->y; | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| } | } | ||||
| #ifdef USE_DRAG_TOGGLE | #ifdef USE_DRAG_TOGGLE | ||||
| if (event->type == LEFTMOUSE && event->val == KM_PRESS) { | if (event->type == LEFTMOUSE && event->val == KM_PRESS) { | ||||
| Show All 11 Lines | if (ELEM(event->type, LEFTMOUSE, PADENTER, RETKEY) && event->val == KM_PRESS) { | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| else if (ELEM(event->type, MOUSEPAN, WHEELDOWNMOUSE, WHEELUPMOUSE) && event->alt) { | else if (ELEM(event->type, MOUSEPAN, WHEELDOWNMOUSE, WHEELUPMOUSE) && event->alt) { | ||||
| ColorPicker *cpicker = but->custom_data; | ColorPicker *cpicker = but->custom_data; | ||||
| float hsv_static[3] = {0.0f}; | float hsv_static[3] = {0.0f}; | ||||
| float *hsv = cpicker ? cpicker->color_data : hsv_static; | float *hsv = cpicker ? cpicker->color_data : hsv_static; | ||||
| float col[3]; | float col[3]; | ||||
| ui_get_but_vectorf(but, col); | ui_but_v3_get(but, col); | ||||
| rgb_to_hsv_compat_v(col, hsv); | rgb_to_hsv_compat_v(col, hsv); | ||||
| if (event->type == WHEELDOWNMOUSE) | if (event->type == WHEELDOWNMOUSE) | ||||
| hsv[2] = CLAMPIS(hsv[2] - 0.05f, 0.0f, 1.0f); | hsv[2] = CLAMPIS(hsv[2] - 0.05f, 0.0f, 1.0f); | ||||
| else if (event->type == WHEELUPMOUSE) | else if (event->type == WHEELUPMOUSE) | ||||
| hsv[2] = CLAMPIS(hsv[2] + 0.05f, 0.0f, 1.0f); | hsv[2] = CLAMPIS(hsv[2] + 0.05f, 0.0f, 1.0f); | ||||
| else { | else { | ||||
| float fac = 0.005 * (event->y - event->prevy); | float fac = 0.005 * (event->y - event->prevy); | ||||
| hsv[2] = CLAMPIS(hsv[2] + fac, 0.0f, 1.0f); | hsv[2] = CLAMPIS(hsv[2] + fac, 0.0f, 1.0f); | ||||
| } | } | ||||
| hsv_to_rgb_v(hsv, data->vec); | hsv_to_rgb_v(hsv, data->vec); | ||||
| ui_set_but_vectorf(but, data->vec); | ui_but_v3_set(but, data->vec); | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| ui_apply_button(C, but->block, but, data, true); | ui_apply_but(C, but->block, but, data, true); | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| else if ((int)(but->a1) == UI_PALETTE_COLOR && | else if ((int)(but->a1) == UI_PALETTE_COLOR && | ||||
| event->type == DELKEY && event->val == KM_PRESS) | event->type == DELKEY && event->val == KM_PRESS) | ||||
| { | { | ||||
| Palette *palette = but->rnapoin.id.data; | Palette *palette = but->rnapoin.id.data; | ||||
| PaletteColor *color = but->rnapoin.data; | PaletteColor *color = but->rnapoin.data; | ||||
| BKE_palette_color_remove(palette, color); | BKE_palette_color_remove(palette, color); | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| } | } | ||||
| else if (data->state == BUTTON_STATE_WAIT_DRAG) { | else if (data->state == BUTTON_STATE_WAIT_DRAG) { | ||||
| /* this function also ends state */ | /* this function also ends state */ | ||||
| if (ui_but_start_drag(C, but, data, event)) { | if (ui_but_drag_init(C, but, data, event)) { | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| /* outside icon quit, not needed if drag activated */ | /* outside icon quit, not needed if drag activated */ | ||||
| if (0 == ui_but_mouse_inside_icon(but, data->region, event)) { | if (0 == ui_but_contains_point_px_icon(but, data->region, event)) { | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| data->cancel = true; | data->cancel = true; | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| if (event->type == LEFTMOUSE && event->val == KM_RELEASE) { | if (event->type == LEFTMOUSE && event->val == KM_RELEASE) { | ||||
| if ((int)(but->a1) == UI_PALETTE_COLOR) { | if ((int)(but->a1) == UI_PALETTE_COLOR) { | ||||
| if (!event->ctrl) { | if (!event->ctrl) { | ||||
| float color[3]; | float color[3]; | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Paint *paint = BKE_paint_get_active(scene); | Paint *paint = BKE_paint_get_active(scene); | ||||
| Brush *brush = BKE_paint_brush(paint); | Brush *brush = BKE_paint_brush(paint); | ||||
| if (brush->flag & BRUSH_USE_GRADIENT) { | if (brush->flag & BRUSH_USE_GRADIENT) { | ||||
| float *target = &brush->gradient->data[brush->gradient->cur].r; | float *target = &brush->gradient->data[brush->gradient->cur].r; | ||||
| if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) { | if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) { | ||||
| RNA_property_float_get_array(&but->rnapoin, but->rnaprop, target); | RNA_property_float_get_array(&but->rnapoin, but->rnaprop, target); | ||||
| ui_block_to_scene_linear_v3(but->block, target); | ui_block_cm_to_scene_linear_v3(but->block, target); | ||||
| } | } | ||||
| else if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR) { | else if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR) { | ||||
| RNA_property_float_get_array(&but->rnapoin, but->rnaprop, target); | RNA_property_float_get_array(&but->rnapoin, but->rnaprop, target); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) { | if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) { | ||||
| RNA_property_float_get_array(&but->rnapoin, but->rnaprop, color); | RNA_property_float_get_array(&but->rnapoin, but->rnaprop, color); | ||||
| BKE_brush_color_set(scene, brush, color); | BKE_brush_color_set(scene, brush, color); | ||||
| } | } | ||||
| else if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR) { | else if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR) { | ||||
| RNA_property_float_get_array(&but->rnapoin, but->rnaprop, color); | RNA_property_float_get_array(&but->rnapoin, but->rnaprop, color); | ||||
| ui_block_to_display_space_v3(but->block, color); | ui_block_cm_to_display_space_v3(but->block, color); | ||||
| BKE_brush_color_set(scene, brush, color); | BKE_brush_color_set(scene, brush, color); | ||||
| } | } | ||||
| } | } | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| } | } | ||||
| else { | else { | ||||
| button_activate_state(C, but, BUTTON_STATE_MENU_OPEN); | button_activate_state(C, but, BUTTON_STATE_MENU_OPEN); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| button_activate_state(C, but, BUTTON_STATE_MENU_OPEN); | button_activate_state(C, but, BUTTON_STATE_MENU_OPEN); | ||||
| } | } | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| } | } | ||||
| return WM_UI_HANDLER_CONTINUE; | return WM_UI_HANDLER_CONTINUE; | ||||
| } | } | ||||
| static int ui_do_but_NORMAL(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | static int ui_do_but_UNITVEC(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | ||||
| { | { | ||||
| int mx, my; | int mx, my; | ||||
| mx = event->x; | mx = event->x; | ||||
| my = event->y; | my = event->y; | ||||
| ui_window_to_block(data->region, block, &mx, &my); | ui_window_to_block(data->region, block, &mx, &my); | ||||
| if (data->state == BUTTON_STATE_HIGHLIGHT) { | if (data->state == BUTTON_STATE_HIGHLIGHT) { | ||||
| if (event->type == LEFTMOUSE && event->val == KM_PRESS) { | if (event->type == LEFTMOUSE && event->val == KM_PRESS) { | ||||
| const enum eSnapType snap = ui_event_to_snap(event); | const enum eSnapType snap = ui_event_to_snap(event); | ||||
| data->dragstartx = mx; | data->dragstartx = mx; | ||||
| data->dragstarty = my; | data->dragstarty = my; | ||||
| data->draglastx = mx; | data->draglastx = mx; | ||||
| data->draglasty = my; | data->draglasty = my; | ||||
| button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); | button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); | ||||
| /* also do drag the first time */ | /* also do drag the first time */ | ||||
| if (ui_numedit_but_NORMAL(but, data, mx, my, snap)) | if (ui_numedit_but_UNITVEC(but, data, mx, my, snap)) | ||||
| ui_numedit_apply(C, block, but, data); | ui_numedit_apply(C, block, but, data); | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| } | } | ||||
| else if (data->state == BUTTON_STATE_NUM_EDITING) { | else if (data->state == BUTTON_STATE_NUM_EDITING) { | ||||
| if (event->type == MOUSEMOVE) { | if (event->type == MOUSEMOVE) { | ||||
| if (mx != data->draglastx || my != data->draglasty) { | if (mx != data->draglastx || my != data->draglasty) { | ||||
| const enum eSnapType snap = ui_event_to_snap(event); | const enum eSnapType snap = ui_event_to_snap(event); | ||||
| if (ui_numedit_but_NORMAL(but, data, mx, my, snap)) | if (ui_numedit_but_UNITVEC(but, data, mx, my, snap)) | ||||
| ui_numedit_apply(C, block, but, data); | ui_numedit_apply(C, block, but, data); | ||||
| } | } | ||||
| } | } | ||||
| else if (event->type == LEFTMOUSE && event->val != KM_PRESS) { | else if (event->type == LEFTMOUSE && event->val != KM_PRESS) { | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| } | } | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | static bool ui_numedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, | ||||
| const enum eSnapType snap, const bool shift) | const enum eSnapType snap, const bool shift) | ||||
| { | { | ||||
| ColorPicker *cpicker = but->custom_data; | ColorPicker *cpicker = but->custom_data; | ||||
| float *hsv = cpicker->color_data; | float *hsv = cpicker->color_data; | ||||
| float rgb[3]; | float rgb[3]; | ||||
| float x, y; | float x, y; | ||||
| float mx_fl, my_fl; | float mx_fl, my_fl; | ||||
| bool changed = true; | bool changed = true; | ||||
| bool use_display_colorspace = ui_color_picker_use_display_colorspace(but); | bool use_display_colorspace = ui_but_is_colorpicker_display_space(but); | ||||
| ui_mouse_scale_warp(data, mx, my, &mx_fl, &my_fl, shift); | ui_mouse_scale_warp(data, mx, my, &mx_fl, &my_fl, shift); | ||||
| #ifdef USE_CONT_MOUSE_CORRECT | #ifdef USE_CONT_MOUSE_CORRECT | ||||
| if (ui_is_a_warp_but(but)) { | if (ui_but_is_cursor_warp(but)) { | ||||
| /* OK but can go outside bounds */ | /* OK but can go outside bounds */ | ||||
| data->ungrab_mval[0] = mx_fl; | data->ungrab_mval[0] = mx_fl; | ||||
| data->ungrab_mval[1] = my_fl; | data->ungrab_mval[1] = my_fl; | ||||
| BLI_rctf_clamp_pt_v(&but->rect, data->ungrab_mval); | BLI_rctf_clamp_pt_v(&but->rect, data->ungrab_mval); | ||||
| } | } | ||||
| #endif | #endif | ||||
| ui_get_but_vectorf(but, rgb); | ui_but_v3_get(but, rgb); | ||||
| if (use_display_colorspace) | if (use_display_colorspace) | ||||
| ui_block_to_display_space_v3(but->block, rgb); | ui_block_cm_to_display_space_v3(but->block, rgb); | ||||
| ui_rgb_to_color_picker_HSVCUBE_compat_v(but, rgb, hsv); | ui_rgb_to_color_picker_HSVCUBE_compat_v(but, rgb, hsv); | ||||
| /* only apply the delta motion, not absolute */ | /* only apply the delta motion, not absolute */ | ||||
| if (shift) { | if (shift) { | ||||
| rcti rect_i; | rcti rect_i; | ||||
| float xpos, ypos, hsvo[3]; | float xpos, ypos, hsvo[3]; | ||||
| BLI_rcti_rctf_copy(&rect_i, &but->rect); | BLI_rcti_rctf_copy(&rect_i, &but->rect); | ||||
| /* calculate original hsv again */ | /* calculate original hsv again */ | ||||
| copy_v3_v3(rgb, data->origvec); | copy_v3_v3(rgb, data->origvec); | ||||
| if (use_display_colorspace) | if (use_display_colorspace) | ||||
| ui_block_to_display_space_v3(but->block, rgb); | ui_block_cm_to_display_space_v3(but->block, rgb); | ||||
| copy_v3_v3(hsvo, hsv); | copy_v3_v3(hsvo, hsv); | ||||
| ui_rgb_to_color_picker_HSVCUBE_compat_v(but, rgb, hsvo); | ui_rgb_to_color_picker_HSVCUBE_compat_v(but, rgb, hsvo); | ||||
| /* and original position */ | /* and original position */ | ||||
| ui_hsvcube_pos_from_vals(but, &rect_i, hsvo, &xpos, &ypos); | ui_hsvcube_pos_from_vals(but, &rect_i, hsvo, &xpos, &ypos); | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | if (snap != SNAP_OFF) { | ||||
| if (ELEM((int)but->a1, UI_GRAD_HV, UI_GRAD_HS, UI_GRAD_H)) { | if (ELEM((int)but->a1, UI_GRAD_HV, UI_GRAD_HS, UI_GRAD_H)) { | ||||
| ui_color_snap_hue(snap, &hsv[0]); | ui_color_snap_hue(snap, &hsv[0]); | ||||
| } | } | ||||
| } | } | ||||
| ui_color_picker_to_rgb_HSVCUBE_v(but, hsv, rgb); | ui_color_picker_to_rgb_HSVCUBE_v(but, hsv, rgb); | ||||
| if (use_display_colorspace) | if (use_display_colorspace) | ||||
| ui_block_to_scene_linear_v3(but->block, rgb); | ui_block_cm_to_scene_linear_v3(but->block, rgb); | ||||
| /* clamp because with color conversion we can exceed range [#34295] */ | /* clamp because with color conversion we can exceed range [#34295] */ | ||||
| if (but->a1 == UI_GRAD_V_ALT) { | if (but->a1 == UI_GRAD_V_ALT) { | ||||
| clamp_axis_max_v3(rgb, but->softmax); | clamp_axis_max_v3(rgb, but->softmax); | ||||
| } | } | ||||
| copy_v3_v3(data->vec, rgb); | copy_v3_v3(data->vec, rgb); | ||||
| data->draglastx = mx; | data->draglastx = mx; | ||||
| data->draglasty = my; | data->draglasty = my; | ||||
| return changed; | return changed; | ||||
| } | } | ||||
| static void ui_ndofedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, | static void ui_ndofedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, | ||||
| const wmNDOFMotionData *ndof, | const wmNDOFMotionData *ndof, | ||||
| const enum eSnapType snap, const bool shift) | const enum eSnapType snap, const bool shift) | ||||
| { | { | ||||
| ColorPicker *cpicker = but->custom_data; | ColorPicker *cpicker = but->custom_data; | ||||
| float *hsv = cpicker->color_data; | float *hsv = cpicker->color_data; | ||||
| const float hsv_v_max = max_ff(hsv[2], but->softmax); | const float hsv_v_max = max_ff(hsv[2], but->softmax); | ||||
| float rgb[3]; | float rgb[3]; | ||||
| float sensitivity = (shift ? 0.15f : 0.3f) * ndof->dt; | float sensitivity = (shift ? 0.15f : 0.3f) * ndof->dt; | ||||
| bool use_display_colorspace = ui_color_picker_use_display_colorspace(but); | bool use_display_colorspace = ui_but_is_colorpicker_display_space(but); | ||||
| ui_get_but_vectorf(but, rgb); | ui_but_v3_get(but, rgb); | ||||
| if (use_display_colorspace) | if (use_display_colorspace) | ||||
| ui_block_to_display_space_v3(but->block, rgb); | ui_block_cm_to_display_space_v3(but->block, rgb); | ||||
| ui_rgb_to_color_picker_HSVCUBE_compat_v(but, rgb, hsv); | ui_rgb_to_color_picker_HSVCUBE_compat_v(but, rgb, hsv); | ||||
| switch ((int)but->a1) { | switch ((int)but->a1) { | ||||
| case UI_GRAD_SV: | case UI_GRAD_SV: | ||||
| hsv[2] += ndof->rvec[2] * sensitivity; | hsv[2] += ndof->rvec[2] * sensitivity; | ||||
| hsv[1] += ndof->rvec[0] * sensitivity; | hsv[1] += ndof->rvec[0] * sensitivity; | ||||
| break; | break; | ||||
| Show All 35 Lines | static void ui_ndofedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, | ||||
| } | } | ||||
| /* ndof specific: the changes above aren't clamping */ | /* ndof specific: the changes above aren't clamping */ | ||||
| hsv_clamp_v(hsv, hsv_v_max); | hsv_clamp_v(hsv, hsv_v_max); | ||||
| ui_color_picker_to_rgb_HSVCUBE_v(but, hsv, rgb); | ui_color_picker_to_rgb_HSVCUBE_v(but, hsv, rgb); | ||||
| if (use_display_colorspace) | if (use_display_colorspace) | ||||
| ui_block_to_scene_linear_v3(but->block, rgb); | ui_block_cm_to_scene_linear_v3(but->block, rgb); | ||||
| copy_v3_v3(data->vec, rgb); | copy_v3_v3(data->vec, rgb); | ||||
| ui_set_but_vectorf(but, data->vec); | ui_but_v3_set(but, data->vec); | ||||
| } | } | ||||
| static int ui_do_but_HSVCUBE(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | static int ui_do_but_HSVCUBE(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | ||||
| { | { | ||||
| int mx, my; | int mx, my; | ||||
| mx = event->x; | mx = event->x; | ||||
| my = event->y; | my = event->y; | ||||
| Show All 17 Lines | if (data->state == BUTTON_STATE_HIGHLIGHT) { | ||||
| } | } | ||||
| else if (event->type == NDOF_MOTION) { | else if (event->type == NDOF_MOTION) { | ||||
| const wmNDOFMotionData *ndof = event->customdata; | const wmNDOFMotionData *ndof = event->customdata; | ||||
| const enum eSnapType snap = ui_event_to_snap(event); | const enum eSnapType snap = ui_event_to_snap(event); | ||||
| ui_ndofedit_but_HSVCUBE(but, data, ndof, snap, event->shift != 0); | ui_ndofedit_but_HSVCUBE(but, data, ndof, snap, event->shift != 0); | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| ui_apply_button(C, but->block, but, data, true); | ui_apply_but(C, but->block, but, data, true); | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| /* XXX hardcoded keymap check.... */ | /* XXX hardcoded keymap check.... */ | ||||
| else if (event->type == BACKSPACEKEY && event->val == KM_PRESS) { | else if (event->type == BACKSPACEKEY && event->val == KM_PRESS) { | ||||
| if (ELEM(but->a1, UI_GRAD_V_ALT, UI_GRAD_L_ALT)) { | if (ELEM(but->a1, UI_GRAD_V_ALT, UI_GRAD_L_ALT)) { | ||||
| int len; | int len; | ||||
| /* reset only value */ | /* reset only value */ | ||||
| len = RNA_property_array_length(&but->rnapoin, but->rnaprop); | len = RNA_property_array_length(&but->rnapoin, but->rnaprop); | ||||
| if (ELEM(len, 3, 4)) { | if (ELEM(len, 3, 4)) { | ||||
| float rgb[3], def_hsv[3]; | float rgb[3], def_hsv[3]; | ||||
| float def[4]; | float def[4]; | ||||
| ColorPicker *cpicker = but->custom_data; | ColorPicker *cpicker = but->custom_data; | ||||
| float *hsv = cpicker->color_data; | float *hsv = cpicker->color_data; | ||||
| RNA_property_float_get_default_array(&but->rnapoin, but->rnaprop, def); | RNA_property_float_get_default_array(&but->rnapoin, but->rnaprop, def); | ||||
| ui_rgb_to_color_picker_HSVCUBE_v(but, def, def_hsv); | ui_rgb_to_color_picker_HSVCUBE_v(but, def, def_hsv); | ||||
| ui_get_but_vectorf(but, rgb); | ui_but_v3_get(but, rgb); | ||||
| ui_rgb_to_color_picker_HSVCUBE_compat_v(but, rgb, hsv); | ui_rgb_to_color_picker_HSVCUBE_compat_v(but, rgb, hsv); | ||||
| def_hsv[0] = hsv[0]; | def_hsv[0] = hsv[0]; | ||||
| def_hsv[1] = hsv[1]; | def_hsv[1] = hsv[1]; | ||||
| ui_color_picker_to_rgb_HSVCUBE_v(but, def_hsv, rgb); | ui_color_picker_to_rgb_HSVCUBE_v(but, def_hsv, rgb); | ||||
| ui_set_but_vectorf(but, rgb); | ui_but_v3_set(but, rgb); | ||||
| RNA_property_update(C, &but->rnapoin, but->rnaprop); | RNA_property_update(C, &but->rnapoin, but->rnaprop); | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else if (data->state == BUTTON_STATE_NUM_EDITING) { | else if (data->state == BUTTON_STATE_NUM_EDITING) { | ||||
| Show All 27 Lines | static bool ui_numedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, | ||||
| const enum eSnapType snap, const bool shift) | const enum eSnapType snap, const bool shift) | ||||
| { | { | ||||
| rcti rect; | rcti rect; | ||||
| bool changed = true; | bool changed = true; | ||||
| float mx_fl, my_fl; | float mx_fl, my_fl; | ||||
| float rgb[3]; | float rgb[3]; | ||||
| ColorPicker *cpicker = but->custom_data; | ColorPicker *cpicker = but->custom_data; | ||||
| float *hsv = cpicker->color_data; | float *hsv = cpicker->color_data; | ||||
| bool use_display_colorspace = ui_color_picker_use_display_colorspace(but); | bool use_display_colorspace = ui_but_is_colorpicker_display_space(but); | ||||
| ui_mouse_scale_warp(data, mx, my, &mx_fl, &my_fl, shift); | ui_mouse_scale_warp(data, mx, my, &mx_fl, &my_fl, shift); | ||||
| #ifdef USE_CONT_MOUSE_CORRECT | #ifdef USE_CONT_MOUSE_CORRECT | ||||
| if (ui_is_a_warp_but(but)) { | if (ui_but_is_cursor_warp(but)) { | ||||
| /* OK but can go outside bounds */ | /* OK but can go outside bounds */ | ||||
| data->ungrab_mval[0] = mx_fl; | data->ungrab_mval[0] = mx_fl; | ||||
| data->ungrab_mval[1] = my_fl; | data->ungrab_mval[1] = my_fl; | ||||
| { /* clamp */ | { /* clamp */ | ||||
| const float radius = min_ff(BLI_rctf_size_x(&but->rect), BLI_rctf_size_y(&but->rect)) / 2.0f; | const float radius = min_ff(BLI_rctf_size_x(&but->rect), BLI_rctf_size_y(&but->rect)) / 2.0f; | ||||
| const float cent[2] = {BLI_rctf_cent_x(&but->rect), BLI_rctf_cent_y(&but->rect)}; | const float cent[2] = {BLI_rctf_cent_x(&but->rect), BLI_rctf_cent_y(&but->rect)}; | ||||
| const float len = len_v2v2(cent, data->ungrab_mval); | const float len = len_v2v2(cent, data->ungrab_mval); | ||||
| if (len > radius) { | if (len > radius) { | ||||
| dist_ensure_v2_v2fl(data->ungrab_mval, cent, radius); | dist_ensure_v2_v2fl(data->ungrab_mval, cent, radius); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| #endif | #endif | ||||
| BLI_rcti_rctf_copy(&rect, &but->rect); | BLI_rcti_rctf_copy(&rect, &but->rect); | ||||
| ui_get_but_vectorf(but, rgb); | ui_but_v3_get(but, rgb); | ||||
| if (use_display_colorspace) | if (use_display_colorspace) | ||||
| ui_block_to_display_space_v3(but->block, rgb); | ui_block_cm_to_display_space_v3(but->block, rgb); | ||||
| ui_rgb_to_color_picker_compat_v(rgb, hsv); | ui_rgb_to_color_picker_compat_v(rgb, hsv); | ||||
| /* exception, when using color wheel in 'locked' value state: | /* exception, when using color wheel in 'locked' value state: | ||||
| * allow choosing a hue for black values, by giving a tiny increment */ | * allow choosing a hue for black values, by giving a tiny increment */ | ||||
| if (but->flag & UI_BUT_COLOR_LOCK) { | if (but->flag & UI_BUT_COLOR_LOCK) { | ||||
| if (U.color_picker_type == USER_CP_CIRCLE_HSV) { // lock | if (U.color_picker_type == USER_CP_CIRCLE_HSV) { // lock | ||||
| if (hsv[2] == 0.f) hsv[2] = 0.0001f; | if (hsv[2] == 0.f) hsv[2] = 0.0001f; | ||||
| } | } | ||||
| else { | else { | ||||
| if (hsv[2] == 0.0f) hsv[2] = 0.0001f; | if (hsv[2] == 0.0f) hsv[2] = 0.0001f; | ||||
| if (hsv[2] >= 0.9999f) hsv[2] = 0.9999f; | if (hsv[2] >= 0.9999f) hsv[2] = 0.9999f; | ||||
| } | } | ||||
| } | } | ||||
| /* only apply the delta motion, not absolute */ | /* only apply the delta motion, not absolute */ | ||||
| if (shift) { | if (shift) { | ||||
| float xpos, ypos, hsvo[3], rgbo[3]; | float xpos, ypos, hsvo[3], rgbo[3]; | ||||
| /* calculate original hsv again */ | /* calculate original hsv again */ | ||||
| copy_v3_v3(hsvo, hsv); | copy_v3_v3(hsvo, hsv); | ||||
| copy_v3_v3(rgbo, data->origvec); | copy_v3_v3(rgbo, data->origvec); | ||||
| if (use_display_colorspace) | if (use_display_colorspace) | ||||
| ui_block_to_display_space_v3(but->block, rgbo); | ui_block_cm_to_display_space_v3(but->block, rgbo); | ||||
| ui_rgb_to_color_picker_compat_v(rgbo, hsvo); | ui_rgb_to_color_picker_compat_v(rgbo, hsvo); | ||||
| /* and original position */ | /* and original position */ | ||||
| ui_hsvcircle_pos_from_vals(but, &rect, hsvo, &xpos, &ypos); | ui_hsvcircle_pos_from_vals(but, &rect, hsvo, &xpos, &ypos); | ||||
| mx_fl = xpos - (data->dragstartx - mx_fl); | mx_fl = xpos - (data->dragstartx - mx_fl); | ||||
| my_fl = ypos - (data->dragstarty - my_fl); | my_fl = ypos - (data->dragstarty - my_fl); | ||||
| Show All 12 Lines | #endif | ||||
| ui_color_picker_to_rgb_v(hsv, rgb); | ui_color_picker_to_rgb_v(hsv, rgb); | ||||
| if ((but->flag & UI_BUT_VEC_SIZE_LOCK) && (rgb[0] || rgb[1] || rgb[2])) { | if ((but->flag & UI_BUT_VEC_SIZE_LOCK) && (rgb[0] || rgb[1] || rgb[2])) { | ||||
| normalize_v3(rgb); | normalize_v3(rgb); | ||||
| mul_v3_fl(rgb, but->a2); | mul_v3_fl(rgb, but->a2); | ||||
| } | } | ||||
| if (use_display_colorspace) | if (use_display_colorspace) | ||||
| ui_block_to_scene_linear_v3(but->block, rgb); | ui_block_cm_to_scene_linear_v3(but->block, rgb); | ||||
| ui_set_but_vectorf(but, rgb); | ui_but_v3_set(but, rgb); | ||||
| data->draglastx = mx; | data->draglastx = mx; | ||||
| data->draglasty = my; | data->draglasty = my; | ||||
| return changed; | return changed; | ||||
| } | } | ||||
| static void ui_ndofedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, | static void ui_ndofedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, | ||||
| const wmNDOFMotionData *ndof, | const wmNDOFMotionData *ndof, | ||||
| const enum eSnapType snap, const bool shift) | const enum eSnapType snap, const bool shift) | ||||
| { | { | ||||
| ColorPicker *cpicker = but->custom_data; | ColorPicker *cpicker = but->custom_data; | ||||
| float *hsv = cpicker->color_data; | float *hsv = cpicker->color_data; | ||||
| bool use_display_colorspace = ui_color_picker_use_display_colorspace(but); | bool use_display_colorspace = ui_but_is_colorpicker_display_space(but); | ||||
| float rgb[3]; | float rgb[3]; | ||||
| float phi, r /*, sqr */ /* UNUSED */, v[2]; | float phi, r /*, sqr */ /* UNUSED */, v[2]; | ||||
| float sensitivity = (shift ? 0.06f : 0.3f) * ndof->dt; | float sensitivity = (shift ? 0.06f : 0.3f) * ndof->dt; | ||||
| ui_get_but_vectorf(but, rgb); | ui_but_v3_get(but, rgb); | ||||
| if (use_display_colorspace) | if (use_display_colorspace) | ||||
| ui_block_to_display_space_v3(but->block, rgb); | ui_block_cm_to_display_space_v3(but->block, rgb); | ||||
| ui_rgb_to_color_picker_compat_v(rgb, hsv); | ui_rgb_to_color_picker_compat_v(rgb, hsv); | ||||
| /* Convert current color on hue/sat disc to circular coordinates phi, r */ | /* Convert current color on hue/sat disc to circular coordinates phi, r */ | ||||
| phi = fmodf(hsv[0] + 0.25f, 1.0f) * -2.0f * (float)M_PI; | phi = fmodf(hsv[0] + 0.25f, 1.0f) * -2.0f * (float)M_PI; | ||||
| r = hsv[1]; | r = hsv[1]; | ||||
| /* sqr = r > 0.0f ? sqrtf(r) : 1; */ /* UNUSED */ | /* sqr = r > 0.0f ? sqrtf(r) : 1; */ /* UNUSED */ | ||||
| /* Convert to 2d vectors */ | /* Convert to 2d vectors */ | ||||
| Show All 36 Lines | static void ui_ndofedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, | ||||
| ui_color_picker_to_rgb_v(hsv, data->vec); | ui_color_picker_to_rgb_v(hsv, data->vec); | ||||
| if ((but->flag & UI_BUT_VEC_SIZE_LOCK) && (data->vec[0] || data->vec[1] || data->vec[2])) { | if ((but->flag & UI_BUT_VEC_SIZE_LOCK) && (data->vec[0] || data->vec[1] || data->vec[2])) { | ||||
| normalize_v3(data->vec); | normalize_v3(data->vec); | ||||
| mul_v3_fl(data->vec, but->a2); | mul_v3_fl(data->vec, but->a2); | ||||
| } | } | ||||
| if (use_display_colorspace) | if (use_display_colorspace) | ||||
| ui_block_to_scene_linear_v3(but->block, data->vec); | ui_block_cm_to_scene_linear_v3(but->block, data->vec); | ||||
| ui_set_but_vectorf(but, data->vec); | ui_but_v3_set(but, data->vec); | ||||
| } | } | ||||
| static int ui_do_but_HSVCIRCLE(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | static int ui_do_but_HSVCIRCLE(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) | ||||
| { | { | ||||
| ColorPicker *cpicker = but->custom_data; | ColorPicker *cpicker = but->custom_data; | ||||
| float *hsv = cpicker->color_data; | float *hsv = cpicker->color_data; | ||||
| int mx, my; | int mx, my; | ||||
| Show All 18 Lines | if (data->state == BUTTON_STATE_HIGHLIGHT) { | ||||
| } | } | ||||
| else if (event->type == NDOF_MOTION) { | else if (event->type == NDOF_MOTION) { | ||||
| const enum eSnapType snap = ui_event_to_snap(event); | const enum eSnapType snap = ui_event_to_snap(event); | ||||
| const wmNDOFMotionData *ndof = event->customdata; | const wmNDOFMotionData *ndof = event->customdata; | ||||
| ui_ndofedit_but_HSVCIRCLE(but, data, ndof, snap, event->shift != 0); | ui_ndofedit_but_HSVCIRCLE(but, data, ndof, snap, event->shift != 0); | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| ui_apply_button(C, but->block, but, data, true); | ui_apply_but(C, but->block, but, data, true); | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| /* XXX hardcoded keymap check.... */ | /* XXX hardcoded keymap check.... */ | ||||
| else if (event->type == BACKSPACEKEY && event->val == KM_PRESS) { | else if (event->type == BACKSPACEKEY && event->val == KM_PRESS) { | ||||
| int len; | int len; | ||||
| /* reset only saturation */ | /* reset only saturation */ | ||||
| len = RNA_property_array_length(&but->rnapoin, but->rnaprop); | len = RNA_property_array_length(&but->rnapoin, but->rnaprop); | ||||
| if (len >= 3) { | if (len >= 3) { | ||||
| float rgb[3], def_hsv[3]; | float rgb[3], def_hsv[3]; | ||||
| float *def; | float *def; | ||||
| def = MEM_callocN(sizeof(float) * len, "reset_defaults - float"); | def = MEM_callocN(sizeof(float) * len, "reset_defaults - float"); | ||||
| RNA_property_float_get_default_array(&but->rnapoin, but->rnaprop, def); | RNA_property_float_get_default_array(&but->rnapoin, but->rnaprop, def); | ||||
| ui_color_picker_to_rgb_v(def, def_hsv); | ui_color_picker_to_rgb_v(def, def_hsv); | ||||
| ui_get_but_vectorf(but, rgb); | ui_but_v3_get(but, rgb); | ||||
| ui_rgb_to_color_picker_compat_v(rgb, hsv); | ui_rgb_to_color_picker_compat_v(rgb, hsv); | ||||
| def_hsv[0] = hsv[0]; | def_hsv[0] = hsv[0]; | ||||
| def_hsv[2] = hsv[2]; | def_hsv[2] = hsv[2]; | ||||
| hsv_to_rgb_v(def_hsv, rgb); | hsv_to_rgb_v(def_hsv, rgb); | ||||
| ui_set_but_vectorf(but, rgb); | ui_but_v3_set(but, rgb); | ||||
| RNA_property_update(C, &but->rnapoin, but->rnaprop); | RNA_property_update(C, &but->rnapoin, but->rnaprop); | ||||
| MEM_freeN(def); | MEM_freeN(def); | ||||
| } | } | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| } | } | ||||
| else if (data->state == BUTTON_STATE_NUM_EDITING) { | else if (data->state == BUTTON_STATE_NUM_EDITING) { | ||||
| if (event->type == ESCKEY || event->type == RIGHTMOUSE) { | if (event->type == ESCKEY || event->type == RIGHTMOUSE) { | ||||
| if (event->val == KM_PRESS) { | if (event->val == KM_PRESS) { | ||||
| data->cancel = true; | data->cancel = true; | ||||
| data->escapecancel = true; | data->escapecancel = true; | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| } | } | ||||
| } | } | ||||
| /* XXX hardcoded keymap check.... */ | /* XXX hardcoded keymap check.... */ | ||||
| else if (event->type == WHEELDOWNMOUSE) { | else if (event->type == WHEELDOWNMOUSE) { | ||||
| hsv[2] = CLAMPIS(hsv[2] - 0.05f, 0.0f, 1.0f); | hsv[2] = CLAMPIS(hsv[2] - 0.05f, 0.0f, 1.0f); | ||||
| ui_set_but_hsv(but); /* converts to rgb */ | ui_but_hsv_set(but); /* converts to rgb */ | ||||
| ui_numedit_apply(C, block, but, data); | ui_numedit_apply(C, block, but, data); | ||||
| } | } | ||||
| else if (event->type == WHEELUPMOUSE) { | else if (event->type == WHEELUPMOUSE) { | ||||
| hsv[2] = CLAMPIS(hsv[2] + 0.05f, 0.0f, 1.0f); | hsv[2] = CLAMPIS(hsv[2] + 0.05f, 0.0f, 1.0f); | ||||
| ui_set_but_hsv(but); /* converts to rgb */ | ui_but_hsv_set(but); /* converts to rgb */ | ||||
| ui_numedit_apply(C, block, but, data); | ui_numedit_apply(C, block, but, data); | ||||
| } | } | ||||
| else if (event->type == MOUSEMOVE) { | else if (event->type == MOUSEMOVE) { | ||||
| if (mx != data->draglastx || my != data->draglasty) { | if (mx != data->draglastx || my != data->draglasty) { | ||||
| const enum eSnapType snap = ui_event_to_snap(event); | const enum eSnapType snap = ui_event_to_snap(event); | ||||
| if (ui_numedit_but_HSVCIRCLE(but, data, mx, my, snap, event->shift != 0)) { | if (ui_numedit_but_HSVCIRCLE(but, data, mx, my, snap, event->shift != 0)) { | ||||
| ui_numedit_apply(C, block, but, data); | ui_numedit_apply(C, block, but, data); | ||||
| ▲ Show 20 Lines • Show All 160 Lines • ▼ Show 20 Lines | if (data->dragsel != -1) { | ||||
| if (moved_point) { | if (moved_point) { | ||||
| data->draglastx = evtx; | data->draglastx = evtx; | ||||
| data->draglasty = evty; | data->draglasty = evty; | ||||
| changed = true; | changed = true; | ||||
| #ifdef USE_CONT_MOUSE_CORRECT | #ifdef USE_CONT_MOUSE_CORRECT | ||||
| /* note: using 'cmp_last' is weak since there may be multiple points selected, | /* note: using 'cmp_last' is weak since there may be multiple points selected, | ||||
| * but in practice this isnt really an issue */ | * but in practice this isnt really an issue */ | ||||
| if (ui_is_a_warp_but(but)) { | if (ui_but_is_cursor_warp(but)) { | ||||
| /* OK but can go outside bounds */ | /* OK but can go outside bounds */ | ||||
| data->ungrab_mval[0] = but->rect.xmin + ((cmp_last->x - cumap->curr.xmin) * zoomx); | data->ungrab_mval[0] = but->rect.xmin + ((cmp_last->x - cumap->curr.xmin) * zoomx); | ||||
| data->ungrab_mval[1] = but->rect.ymin + ((cmp_last->y - cumap->curr.ymin) * zoomy); | data->ungrab_mval[1] = but->rect.ymin + ((cmp_last->y - cumap->curr.ymin) * zoomy); | ||||
| BLI_rctf_clamp_pt_v(&but->rect, data->ungrab_mval); | BLI_rctf_clamp_pt_v(&but->rect, data->ungrab_mval); | ||||
| } | } | ||||
| #endif | #endif | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 459 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| wmWindowManager *wm = CTX_wm_manager(C); | wmWindowManager *wm = CTX_wm_manager(C); | ||||
| uiBlock *block; | uiBlock *block; | ||||
| uiBut *but = (uiBut *)arg; | uiBut *but = (uiBut *)arg; | ||||
| wmKeyMap *km; | wmKeyMap *km; | ||||
| wmKeyMapItem *kmi; | wmKeyMapItem *kmi; | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| uiLayout *layout; | uiLayout *layout; | ||||
| uiStyle *style = UI_GetStyleDraw(); | uiStyle *style = UI_style_get_dpi(); | ||||
| IDProperty *prop = (but->opptr) ? but->opptr->data : NULL; | IDProperty *prop = (but->opptr) ? but->opptr->data : NULL; | ||||
| int kmi_id = WM_key_event_operator_id(C, but->optype->idname, but->opcontext, prop, true, &km); | int kmi_id = WM_key_event_operator_id(C, but->optype->idname, but->opcontext, prop, true, &km); | ||||
| kmi = WM_keymap_item_find_id(km, kmi_id); | kmi = WM_keymap_item_find_id(km, kmi_id); | ||||
| RNA_pointer_create(&wm->id, &RNA_KeyMapItem, kmi, &ptr); | RNA_pointer_create(&wm->id, &RNA_KeyMapItem, kmi, &ptr); | ||||
| block = uiBeginBlock(C, ar, "_popup", UI_EMBOSS); | block = UI_block_begin(C, ar, "_popup", UI_EMBOSS); | ||||
| uiBlockSetHandleFunc(block, but_shortcut_name_func, but); | UI_block_func_handle_set(block, but_shortcut_name_func, but); | ||||
| uiBlockSetFlag(block, UI_BLOCK_MOVEMOUSE_QUIT); | UI_block_flag_enable(block, UI_BLOCK_MOVEMOUSE_QUIT); | ||||
| uiBlockSetDirection(block, UI_CENTER); | UI_block_direction_set(block, UI_DIR_CENTER_Y); | ||||
| layout = uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 200, 20, 0, style); | layout = UI_block_layout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 200, 20, 0, style); | ||||
| uiItemR(layout, &ptr, "type", UI_ITEM_R_FULL_EVENT | UI_ITEM_R_IMMEDIATE, "", ICON_NONE); | uiItemR(layout, &ptr, "type", UI_ITEM_R_FULL_EVENT | UI_ITEM_R_IMMEDIATE, "", ICON_NONE); | ||||
| uiPopupBoundsBlock(block, 6, -50, 26); | UI_block_bounds_set_popup(block, 6, -50, 26); | ||||
| return block; | return block; | ||||
| } | } | ||||
| static uiBlock *menu_add_shortcut(bContext *C, ARegion *ar, void *arg) | static uiBlock *menu_add_shortcut(bContext *C, ARegion *ar, void *arg) | ||||
| { | { | ||||
| wmWindowManager *wm = CTX_wm_manager(C); | wmWindowManager *wm = CTX_wm_manager(C); | ||||
| uiBlock *block; | uiBlock *block; | ||||
| uiBut *but = (uiBut *)arg; | uiBut *but = (uiBut *)arg; | ||||
| wmKeyMap *km; | wmKeyMap *km; | ||||
| wmKeyMapItem *kmi; | wmKeyMapItem *kmi; | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| uiLayout *layout; | uiLayout *layout; | ||||
| uiStyle *style = UI_GetStyleDraw(); | uiStyle *style = UI_style_get_dpi(); | ||||
| IDProperty *prop = (but->opptr) ? but->opptr->data : NULL; | IDProperty *prop = (but->opptr) ? but->opptr->data : NULL; | ||||
| int kmi_id; | int kmi_id; | ||||
| /* XXX this guess_opname can potentially return a different keymap than being found on adding later... */ | /* XXX this guess_opname can potentially return a different keymap than being found on adding later... */ | ||||
| km = WM_keymap_guess_opname(C, but->optype->idname); | km = WM_keymap_guess_opname(C, but->optype->idname); | ||||
| kmi = WM_keymap_add_item(km, but->optype->idname, AKEY, KM_PRESS, 0, 0); | kmi = WM_keymap_add_item(km, but->optype->idname, AKEY, KM_PRESS, 0, 0); | ||||
| kmi_id = kmi->id; | kmi_id = kmi->id; | ||||
| /* copy properties, prop can be NULL for reset */ | /* copy properties, prop can be NULL for reset */ | ||||
| if (prop) | if (prop) | ||||
| prop = IDP_CopyProperty(prop); | prop = IDP_CopyProperty(prop); | ||||
| WM_keymap_properties_reset(kmi, prop); | WM_keymap_properties_reset(kmi, prop); | ||||
| /* update and get pointers again */ | /* update and get pointers again */ | ||||
| WM_keyconfig_update(wm); | WM_keyconfig_update(wm); | ||||
| km = WM_keymap_guess_opname(C, but->optype->idname); | km = WM_keymap_guess_opname(C, but->optype->idname); | ||||
| kmi = WM_keymap_item_find_id(km, kmi_id); | kmi = WM_keymap_item_find_id(km, kmi_id); | ||||
| RNA_pointer_create(&wm->id, &RNA_KeyMapItem, kmi, &ptr); | RNA_pointer_create(&wm->id, &RNA_KeyMapItem, kmi, &ptr); | ||||
| block = uiBeginBlock(C, ar, "_popup", UI_EMBOSS); | block = UI_block_begin(C, ar, "_popup", UI_EMBOSS); | ||||
| uiBlockSetHandleFunc(block, but_shortcut_name_func, but); | UI_block_func_handle_set(block, but_shortcut_name_func, but); | ||||
| uiBlockSetDirection(block, UI_CENTER); | UI_block_direction_set(block, UI_DIR_CENTER_Y); | ||||
| layout = uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 200, 20, 0, style); | layout = UI_block_layout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 200, 20, 0, style); | ||||
| uiItemR(layout, &ptr, "type", UI_ITEM_R_FULL_EVENT | UI_ITEM_R_IMMEDIATE, "", ICON_NONE); | uiItemR(layout, &ptr, "type", UI_ITEM_R_FULL_EVENT | UI_ITEM_R_IMMEDIATE, "", ICON_NONE); | ||||
| uiPopupBoundsBlock(block, 6, -50, 26); | UI_block_bounds_set_popup(block, 6, -50, 26); | ||||
| return block; | return block; | ||||
| } | } | ||||
| static void menu_add_shortcut_cancel(struct bContext *C, void *arg1) | static void menu_add_shortcut_cancel(struct bContext *C, void *arg1) | ||||
| { | { | ||||
| uiBut *but = (uiBut *)arg1; | uiBut *but = (uiBut *)arg1; | ||||
| wmKeyMap *km; | wmKeyMap *km; | ||||
| wmKeyMapItem *kmi; | wmKeyMapItem *kmi; | ||||
| IDProperty *prop = (but->opptr) ? but->opptr->data : NULL; | IDProperty *prop = (but->opptr) ? but->opptr->data : NULL; | ||||
| int kmi_id = WM_key_event_operator_id(C, but->optype->idname, but->opcontext, prop, true, &km); | int kmi_id = WM_key_event_operator_id(C, but->optype->idname, but->opcontext, prop, true, &km); | ||||
| kmi = WM_keymap_item_find_id(km, kmi_id); | kmi = WM_keymap_item_find_id(km, kmi_id); | ||||
| WM_keymap_remove_item(km, kmi); | WM_keymap_remove_item(km, kmi); | ||||
| } | } | ||||
| static void popup_change_shortcut_func(bContext *C, void *arg1, void *UNUSED(arg2)) | static void popup_change_shortcut_func(bContext *C, void *arg1, void *UNUSED(arg2)) | ||||
| { | { | ||||
| uiBut *but = (uiBut *)arg1; | uiBut *but = (uiBut *)arg1; | ||||
| button_timers_tooltip_remove(C, but); | button_timers_tooltip_remove(C, but); | ||||
| uiPupBlock(C, menu_change_shortcut, but); | UI_popup_block_invoke(C, menu_change_shortcut, but); | ||||
| } | } | ||||
| static void remove_shortcut_func(bContext *C, void *arg1, void *UNUSED(arg2)) | static void remove_shortcut_func(bContext *C, void *arg1, void *UNUSED(arg2)) | ||||
| { | { | ||||
| uiBut *but = (uiBut *)arg1; | uiBut *but = (uiBut *)arg1; | ||||
| wmKeyMap *km; | wmKeyMap *km; | ||||
| wmKeyMapItem *kmi; | wmKeyMapItem *kmi; | ||||
| IDProperty *prop = (but->opptr) ? but->opptr->data : NULL; | IDProperty *prop = (but->opptr) ? but->opptr->data : NULL; | ||||
| int kmi_id = WM_key_event_operator_id(C, but->optype->idname, but->opcontext, prop, true, &km); | int kmi_id = WM_key_event_operator_id(C, but->optype->idname, but->opcontext, prop, true, &km); | ||||
| kmi = WM_keymap_item_find_id(km, kmi_id); | kmi = WM_keymap_item_find_id(km, kmi_id); | ||||
| WM_keymap_remove_item(km, kmi); | WM_keymap_remove_item(km, kmi); | ||||
| but_shortcut_name_func(C, but, 0); | but_shortcut_name_func(C, but, 0); | ||||
| } | } | ||||
| static void popup_add_shortcut_func(bContext *C, void *arg1, void *UNUSED(arg2)) | static void popup_add_shortcut_func(bContext *C, void *arg1, void *UNUSED(arg2)) | ||||
| { | { | ||||
| uiBut *but = (uiBut *)arg1; | uiBut *but = (uiBut *)arg1; | ||||
| button_timers_tooltip_remove(C, but); | button_timers_tooltip_remove(C, but); | ||||
| uiPupBlockEx(C, menu_add_shortcut, NULL, menu_add_shortcut_cancel, but); | UI_popup_block_ex(C, menu_add_shortcut, NULL, menu_add_shortcut_cancel, but); | ||||
| } | } | ||||
| /** | /** | ||||
| * menu to chow when right clicking on the panel header | * menu to chow when right clicking on the panel header | ||||
| */ | */ | ||||
| void ui_panel_menu(bContext *C, ARegion *ar, Panel *pa) | void ui_panel_menu(bContext *C, ARegion *ar, Panel *pa) | ||||
| { | { | ||||
| bScreen *sc = CTX_wm_screen(C); | bScreen *sc = CTX_wm_screen(C); | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| uiPopupMenu *pup; | uiPopupMenu *pup; | ||||
| uiLayout *layout; | uiLayout *layout; | ||||
| RNA_pointer_create(&sc->id, &RNA_Panel, pa, &ptr); | RNA_pointer_create(&sc->id, &RNA_Panel, pa, &ptr); | ||||
| pup = uiPupMenuBegin(C, IFACE_("Panel"), ICON_NONE); | pup = UI_popup_menu_begin(C, IFACE_("Panel"), ICON_NONE); | ||||
| layout = uiPupMenuLayout(pup); | layout = UI_popup_menu_layout(pup); | ||||
| if (UI_panel_category_is_visible(ar)) { | if (UI_panel_category_is_visible(ar)) { | ||||
| char tmpstr[80]; | char tmpstr[80]; | ||||
| BLI_snprintf(tmpstr, sizeof(tmpstr), "%s" UI_SEP_CHAR_S "%s", IFACE_("Pin"), IFACE_("Shift+Left Mouse")); | BLI_snprintf(tmpstr, sizeof(tmpstr), "%s" UI_SEP_CHAR_S "%s", IFACE_("Pin"), IFACE_("Shift+Left Mouse")); | ||||
| uiItemR(layout, &ptr, "use_pin", 0, tmpstr, ICON_NONE); | uiItemR(layout, &ptr, "use_pin", 0, tmpstr, ICON_NONE); | ||||
| /* evil, force shortcut flag */ | /* evil, force shortcut flag */ | ||||
| { | { | ||||
| uiBlock *block = uiLayoutGetBlock(layout); | uiBlock *block = uiLayoutGetBlock(layout); | ||||
| uiBut *but = block->buttons.last; | uiBut *but = block->buttons.last; | ||||
| but->flag |= UI_BUT_HAS_SEP_CHAR; | but->flag |= UI_BUT_HAS_SEP_CHAR; | ||||
| } | } | ||||
| } | } | ||||
| uiPupMenuEnd(C, pup); | UI_popup_menu_end(C, pup); | ||||
| } | } | ||||
| static bool ui_but_menu(bContext *C, uiBut *but) | static bool ui_but_menu(bContext *C, uiBut *but) | ||||
| { | { | ||||
| uiPopupMenu *pup; | uiPopupMenu *pup; | ||||
| uiLayout *layout; | uiLayout *layout; | ||||
| bool is_array, is_array_component; | bool is_array, is_array_component; | ||||
| uiStringInfo label = {BUT_GET_LABEL, NULL}; | uiStringInfo label = {BUT_GET_LABEL, NULL}; | ||||
| /* if ((but->rnapoin.data && but->rnaprop) == 0 && but->optype == NULL)*/ | /* if ((but->rnapoin.data && but->rnaprop) == 0 && but->optype == NULL)*/ | ||||
| /* return 0;*/ | /* return 0;*/ | ||||
| /* having this menu for some buttons makes no sense */ | /* having this menu for some buttons makes no sense */ | ||||
| if (but->type == BUT_IMAGE) { | if (but->type == UI_BTYPE_IMAGE) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| button_timers_tooltip_remove(C, but); | button_timers_tooltip_remove(C, but); | ||||
| /* highly unlikely getting the label ever fails */ | /* highly unlikely getting the label ever fails */ | ||||
| uiButGetStrInfo(C, but, &label, NULL); | UI_but_string_info_get(C, but, &label, NULL); | ||||
| pup = uiPupMenuBegin(C, label.strinfo ? label.strinfo : "", ICON_NONE); | pup = UI_popup_menu_begin(C, label.strinfo ? label.strinfo : "", ICON_NONE); | ||||
| layout = uiPupMenuLayout(pup); | layout = UI_popup_menu_layout(pup); | ||||
| if (label.strinfo) | if (label.strinfo) | ||||
| MEM_freeN(label.strinfo); | MEM_freeN(label.strinfo); | ||||
| uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT); | uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT); | ||||
| if (but->rnapoin.data && but->rnaprop) { | if (but->rnapoin.data && but->rnaprop) { | ||||
| PointerRNA *ptr = &but->rnapoin; | PointerRNA *ptr = &but->rnapoin; | ||||
| PropertyRNA *prop = but->rnaprop; | PropertyRNA *prop = but->rnaprop; | ||||
| ▲ Show 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | if (kmi_id) | ||||
| kmi = WM_keymap_item_find_id(km, kmi_id); | kmi = WM_keymap_item_find_id(km, kmi_id); | ||||
| /* keyboard shortcuts */ | /* keyboard shortcuts */ | ||||
| if ((kmi) && ISKEYBOARD(kmi->type)) { | if ((kmi) && ISKEYBOARD(kmi->type)) { | ||||
| /* would rather use a block but, but gets weirdly positioned... */ | /* would rather use a block but, but gets weirdly positioned... */ | ||||
| //uiDefBlockBut(block, menu_change_shortcut, but, "Change Shortcut", 0, 0, uiLayoutGetWidth(layout), UI_UNIT_Y, ""); | //uiDefBlockBut(block, menu_change_shortcut, but, "Change Shortcut", 0, 0, uiLayoutGetWidth(layout), UI_UNIT_Y, ""); | ||||
| but2 = uiDefIconTextBut(block, BUT, 0, 0, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Change Shortcut"), | but2 = uiDefIconTextBut(block, UI_BTYPE_BUT, 0, 0, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Change Shortcut"), | ||||
| 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, ""); | 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, ""); | ||||
| uiButSetFunc(but2, popup_change_shortcut_func, but, NULL); | UI_but_func_set(but2, popup_change_shortcut_func, but, NULL); | ||||
| but2 = uiDefIconTextBut(block, BUT, 0, 0, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Remove Shortcut"), | but2 = uiDefIconTextBut(block, UI_BTYPE_BUT, 0, 0, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Remove Shortcut"), | ||||
| 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, ""); | 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, ""); | ||||
| uiButSetFunc(but2, remove_shortcut_func, but, NULL); | UI_but_func_set(but2, remove_shortcut_func, but, NULL); | ||||
| } | } | ||||
| /* only show 'add' if there's a suitable key map for it to go in */ | /* only show 'add' if there's a suitable key map for it to go in */ | ||||
| else if (WM_keymap_guess_opname(C, but->optype->idname)) { | else if (WM_keymap_guess_opname(C, but->optype->idname)) { | ||||
| but2 = uiDefIconTextBut(block, BUT, 0, 0, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add Shortcut"), | but2 = uiDefIconTextBut(block, UI_BTYPE_BUT, 0, 0, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Add Shortcut"), | ||||
| 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, ""); | 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, ""); | ||||
| uiButSetFunc(but2, popup_add_shortcut_func, but, NULL); | UI_but_func_set(but2, popup_add_shortcut_func, but, NULL); | ||||
| } | } | ||||
| uiItemS(layout); | uiItemS(layout); | ||||
| } | } | ||||
| /* Show header tools for header buttons. */ | /* Show header tools for header buttons. */ | ||||
| { | { | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | #endif | ||||
| } | } | ||||
| /* perhaps we should move this into (G.debug & G_DEBUG) - campbell */ | /* perhaps we should move this into (G.debug & G_DEBUG) - campbell */ | ||||
| if (ui_block_is_menu(but->block) == false) { | if (ui_block_is_menu(but->block) == false) { | ||||
| uiItemFullO(layout, "UI_OT_editsource", NULL, ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, 0); | uiItemFullO(layout, "UI_OT_editsource", NULL, ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, 0); | ||||
| } | } | ||||
| uiItemFullO(layout, "UI_OT_edittranslation_init", NULL, ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, 0); | uiItemFullO(layout, "UI_OT_edittranslation_init", NULL, ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, 0); | ||||
| uiPupMenuEnd(C, pup); | UI_popup_menu_end(C, pup); | ||||
| return true; | return true; | ||||
| } | } | ||||
| static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent *event) | static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent *event) | ||||
| { | { | ||||
| uiHandleButtonData *data; | uiHandleButtonData *data; | ||||
| int retval; | int retval; | ||||
| data = but->active; | data = but->active; | ||||
| retval = WM_UI_HANDLER_CONTINUE; | retval = WM_UI_HANDLER_CONTINUE; | ||||
| if (but->flag & UI_BUT_DISABLED) | if (but->flag & UI_BUT_DISABLED) | ||||
| return WM_UI_HANDLER_CONTINUE; | return WM_UI_HANDLER_CONTINUE; | ||||
| if ((data->state == BUTTON_STATE_HIGHLIGHT) || (event->type == EVT_DROP)) { | if ((data->state == BUTTON_STATE_HIGHLIGHT) || (event->type == EVT_DROP)) { | ||||
| /* handle copy-paste */ | /* handle copy-paste */ | ||||
| if (ELEM(event->type, CKEY, VKEY) && event->val == KM_PRESS && (event->ctrl || event->oskey)) { | if (ELEM(event->type, CKEY, VKEY) && event->val == KM_PRESS && (event->ctrl || event->oskey)) { | ||||
| /* Specific handling for listrows, we try to find their overlapping tex button. */ | /* Specific handling for listrows, we try to find their overlapping tex button. */ | ||||
| if (but->type == LISTROW) { | if (but->type == UI_BTYPE_LISTROW) { | ||||
| uiBut *labelbut = ui_but_list_row_text_activate(C, but, data, event, BUTTON_ACTIVATE_OVER); | uiBut *labelbut = ui_but_list_row_text_activate(C, but, data, event, BUTTON_ACTIVATE_OVER); | ||||
| if (labelbut) { | if (labelbut) { | ||||
| but = labelbut; | but = labelbut; | ||||
| data = but->active; | data = but->active; | ||||
| } | } | ||||
| } | } | ||||
| ui_but_copy_paste(C, but, data, (event->type == CKEY) ? 'c' : 'v'); | ui_but_copy_paste(C, but, data, (event->type == CKEY) ? 'c' : 'v'); | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| /* handle drop */ | /* handle drop */ | ||||
| else if (event->type == EVT_DROP) { | else if (event->type == EVT_DROP) { | ||||
| ui_but_drop(C, event, but, data); | ui_but_drop(C, event, but, data); | ||||
| } | } | ||||
| /* handle eyedropper */ | /* handle eyedropper */ | ||||
| else if ((event->type == EKEY) && (event->val == KM_PRESS)) { | else if ((event->type == EKEY) && (event->val == KM_PRESS)) { | ||||
| if (event->alt || event->shift || event->ctrl || event->oskey) { | if (event->alt || event->shift || event->ctrl || event->oskey) { | ||||
| /* pass */ | /* pass */ | ||||
| } | } | ||||
| else { | else { | ||||
| if (but->type == COLOR) { | if (but->type == UI_BTYPE_COLOR) { | ||||
| WM_operator_name_call(C, "UI_OT_eyedropper_color", WM_OP_INVOKE_DEFAULT, NULL); | WM_operator_name_call(C, "UI_OT_eyedropper_color", WM_OP_INVOKE_DEFAULT, NULL); | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| else if (but->type == SEARCH_MENU_UNLINK) { | else if (but->type == UI_BTYPE_SEARCH_MENU_UNLINK) { | ||||
| if (but->rnaprop && RNA_property_type(but->rnaprop) == PROP_POINTER) { | if (but->rnaprop && RNA_property_type(but->rnaprop) == PROP_POINTER) { | ||||
| StructRNA *type = RNA_property_pointer_type(&but->rnapoin, but->rnaprop); | StructRNA *type = RNA_property_pointer_type(&but->rnapoin, but->rnaprop); | ||||
| const short idcode = RNA_type_to_ID_code(type); | const short idcode = RNA_type_to_ID_code(type); | ||||
| if ((idcode == ID_OB) || OB_DATA_SUPPORT_ID(idcode)) { | if ((idcode == ID_OB) || OB_DATA_SUPPORT_ID(idcode)) { | ||||
| WM_operator_name_call(C, "UI_OT_eyedropper_id", WM_OP_INVOKE_DEFAULT, NULL); | WM_operator_name_call(C, "UI_OT_eyedropper_id", WM_OP_INVOKE_DEFAULT, NULL); | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | else if (but->pointype && but->poin == NULL) { | ||||
| /* there's a pointer needed */ | /* there's a pointer needed */ | ||||
| BKE_reportf(NULL, RPT_WARNING, "DoButton pointer error: %s", but->str); | BKE_reportf(NULL, RPT_WARNING, "DoButton pointer error: %s", but->str); | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| } | } | ||||
| switch (but->type) { | switch (but->type) { | ||||
| case BUT: | case UI_BTYPE_BUT: | ||||
| retval = ui_do_but_BUT(C, but, data, event); | retval = ui_do_but_BUT(C, but, data, event); | ||||
| break; | break; | ||||
| case KEYEVT: | case UI_BTYPE_KEY_EVENT: | ||||
| retval = ui_do_but_KEYEVT(C, but, data, event); | retval = ui_do_but_KEYEVT(C, but, data, event); | ||||
| break; | break; | ||||
| case HOTKEYEVT: | case UI_BTYPE_HOTKEY_EVENT: | ||||
| retval = ui_do_but_HOTKEYEVT(C, but, data, event); | retval = ui_do_but_HOTKEYEVT(C, but, data, event); | ||||
| break; | break; | ||||
| case TOGBUT: | case UI_BTYPE_BUT_TOGGLE: | ||||
| case TOG: | case UI_BTYPE_TOGGLE: | ||||
| case ICONTOG: | case UI_BTYPE_ICON_TOGGLE: | ||||
| case ICONTOGN: | case UI_BTYPE_ICON_TOGGLE_N: | ||||
| case TOGN: | case UI_BTYPE_TOGGLE_N: | ||||
| case OPTION: | case UI_BTYPE_CHECKBOX: | ||||
| case OPTIONN: | case UI_BTYPE_CHECKBOX_N: | ||||
| retval = ui_do_but_TOG(C, but, data, event); | retval = ui_do_but_TOG(C, but, data, event); | ||||
| break; | break; | ||||
| case SCROLL: | case UI_BTYPE_SCROLL: | ||||
| retval = ui_do_but_SCROLL(C, block, but, data, event); | retval = ui_do_but_SCROLL(C, block, but, data, event); | ||||
| break; | break; | ||||
| case GRIP: | case UI_BTYPE_GRIP: | ||||
| retval = ui_do_but_GRIP(C, block, but, data, event); | retval = ui_do_but_GRIP(C, block, but, data, event); | ||||
| break; | break; | ||||
| case NUM: | case UI_BTYPE_NUM: | ||||
| retval = ui_do_but_NUM(C, block, but, data, event); | retval = ui_do_but_NUM(C, block, but, data, event); | ||||
| break; | break; | ||||
| case NUMSLI: | case UI_BTYPE_NUM_SLIDER: | ||||
| retval = ui_do_but_SLI(C, block, but, data, event); | retval = ui_do_but_SLI(C, block, but, data, event); | ||||
| break; | break; | ||||
| case LISTBOX: | case UI_BTYPE_LISTBOX: | ||||
| /* Nothing to do! */ | /* Nothing to do! */ | ||||
| break; | break; | ||||
| case LISTROW: | case UI_BTYPE_LISTROW: | ||||
| retval = ui_do_but_LISTROW(C, but, data, event); | retval = ui_do_but_LISTROW(C, but, data, event); | ||||
| break; | break; | ||||
| case ROUNDBOX: | case UI_BTYPE_ROUNDBOX: | ||||
| case LABEL: | case UI_BTYPE_LABEL: | ||||
| case ROW: | case UI_BTYPE_ROW: | ||||
| case BUT_IMAGE: | case UI_BTYPE_IMAGE: | ||||
| case PROGRESSBAR: | case UI_BTYPE_PROGRESS_BAR: | ||||
| case NODESOCKET: | case UI_BTYPE_NODE_SOCKET: | ||||
| retval = ui_do_but_EXIT(C, but, data, event); | retval = ui_do_but_EXIT(C, but, data, event); | ||||
| break; | break; | ||||
| case HISTOGRAM: | case UI_BTYPE_HISTOGRAM: | ||||
| retval = ui_do_but_HISTOGRAM(C, block, but, data, event); | retval = ui_do_but_HISTOGRAM(C, block, but, data, event); | ||||
| break; | break; | ||||
| case WAVEFORM: | case UI_BTYPE_WAVEFORM: | ||||
| retval = ui_do_but_WAVEFORM(C, block, but, data, event); | retval = ui_do_but_WAVEFORM(C, block, but, data, event); | ||||
| break; | break; | ||||
| case VECTORSCOPE: | case UI_BTYPE_VECTORSCOPE: | ||||
| /* Nothing to do! */ | /* Nothing to do! */ | ||||
| break; | break; | ||||
| case TEX: | case UI_BTYPE_TEXT: | ||||
| case SEARCH_MENU: | case UI_BTYPE_SEARCH_MENU: | ||||
| retval = ui_do_but_TEX(C, block, but, data, event); | retval = ui_do_but_TEX(C, block, but, data, event); | ||||
| break; | break; | ||||
| case SEARCH_MENU_UNLINK: | case UI_BTYPE_SEARCH_MENU_UNLINK: | ||||
| retval = ui_do_but_SEARCH_UNLINK(C, block, but, data, event); | retval = ui_do_but_SEARCH_UNLINK(C, block, but, data, event); | ||||
| break; | break; | ||||
| case MENU: | case UI_BTYPE_MENU: | ||||
| case BLOCK: | case UI_BTYPE_BLOCK: | ||||
| case PULLDOWN: | case UI_BTYPE_PULLDOWN: | ||||
| retval = ui_do_but_BLOCK(C, but, data, event); | retval = ui_do_but_BLOCK(C, but, data, event); | ||||
| break; | break; | ||||
| case BUTM: | case UI_BTYPE_BUT_MENU: | ||||
| retval = ui_do_but_BUT(C, but, data, event); | retval = ui_do_but_BUT(C, but, data, event); | ||||
| break; | break; | ||||
| case COLOR: | case UI_BTYPE_COLOR: | ||||
| if (but->a1 == -1) /* signal to prevent calling up color picker */ | if (but->a1 == -1) /* signal to prevent calling up color picker */ | ||||
| retval = ui_do_but_EXIT(C, but, data, event); | retval = ui_do_but_EXIT(C, but, data, event); | ||||
| else | else | ||||
| retval = ui_do_but_COLOR(C, but, data, event); | retval = ui_do_but_COLOR(C, but, data, event); | ||||
| break; | break; | ||||
| case BUT_NORMAL: | case UI_BTYPE_UNITVEC: | ||||
| retval = ui_do_but_NORMAL(C, block, but, data, event); | retval = ui_do_but_UNITVEC(C, block, but, data, event); | ||||
| break; | break; | ||||
| case BUT_COLORBAND: | case UI_BTYPE_COLORBAND: | ||||
| retval = ui_do_but_COLORBAND(C, block, but, data, event); | retval = ui_do_but_COLORBAND(C, block, but, data, event); | ||||
| break; | break; | ||||
| case BUT_CURVE: | case UI_BTYPE_CURVE: | ||||
| retval = ui_do_but_CURVE(C, block, but, data, event); | retval = ui_do_but_CURVE(C, block, but, data, event); | ||||
| break; | break; | ||||
| case HSVCUBE: | case UI_BTYPE_HSVCUBE: | ||||
| retval = ui_do_but_HSVCUBE(C, block, but, data, event); | retval = ui_do_but_HSVCUBE(C, block, but, data, event); | ||||
| break; | break; | ||||
| case HSVCIRCLE: | case UI_BTYPE_HSVCIRCLE: | ||||
| retval = ui_do_but_HSVCIRCLE(C, block, but, data, event); | retval = ui_do_but_HSVCIRCLE(C, block, but, data, event); | ||||
| break; | break; | ||||
| case LINK: | case UI_BTYPE_LINK: | ||||
| case INLINK: | case UI_BTYPE_INLINK: | ||||
| retval = ui_do_but_LINK(C, but, data, event); | retval = ui_do_but_LINK(C, but, data, event); | ||||
| break; | break; | ||||
| case TRACKPREVIEW: | case UI_BTYPE_TRACK_PREVIEW: | ||||
| retval = ui_do_but_TRACKPREVIEW(C, block, but, data, event); | retval = ui_do_but_TRACKPREVIEW(C, block, but, data, event); | ||||
| break; | break; | ||||
| /* quiet warnings for unhandled types */ | /* quiet warnings for unhandled types */ | ||||
| case SEPR: | case UI_BTYPE_SEPR: | ||||
| case SEPRLINE: | case UI_BTYPE_SEPR_LINE: | ||||
| case BUT_EXTRA: | case UI_BTYPE_EXTRA: | ||||
| break; | break; | ||||
| } | } | ||||
| /* reset to default (generic function, only use if not handled by switch above) */ | /* reset to default (generic function, only use if not handled by switch above) */ | ||||
| /* XXX hardcoded keymap check.... */ | /* XXX hardcoded keymap check.... */ | ||||
| data = but->active; | data = but->active; | ||||
| if (data && data->state == BUTTON_STATE_HIGHLIGHT) { | if (data && data->state == BUTTON_STATE_HIGHLIGHT) { | ||||
| if ((retval == WM_UI_HANDLER_CONTINUE) && | if ((retval == WM_UI_HANDLER_CONTINUE) && | ||||
| (event->type == BACKSPACEKEY && event->val == KM_PRESS)) | (event->type == BACKSPACEKEY && event->val == KM_PRESS)) | ||||
| { | { | ||||
| /* ctrl+backspace = reset active button; backspace = reset a whole array*/ | /* ctrl+backspace = reset active button; backspace = reset a whole array*/ | ||||
| ui_set_but_default(C, !event->ctrl, true); | ui_but_default_set(C, !event->ctrl, true); | ||||
| ED_region_tag_redraw(data->region); | ED_region_tag_redraw(data->region); | ||||
| retval = WM_UI_HANDLER_BREAK; | retval = WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| } | } | ||||
| #ifdef USE_DRAG_MULTINUM | #ifdef USE_DRAG_MULTINUM | ||||
| if (data) { | if (data) { | ||||
| if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE) || | if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE) || | ||||
| /* if we started dragging, progress on any event */ | /* if we started dragging, progress on any event */ | ||||
| (data->multi_data.init == BUTTON_MULTI_INIT_SETUP)) | (data->multi_data.init == BUTTON_MULTI_INIT_SETUP)) | ||||
| { | { | ||||
| if (ELEM(but->type, NUM, NUMSLI) && | if (ELEM(but->type, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER) && | ||||
| ELEM(data->state, BUTTON_STATE_TEXT_EDITING, BUTTON_STATE_NUM_EDITING)) | ELEM(data->state, BUTTON_STATE_TEXT_EDITING, BUTTON_STATE_NUM_EDITING)) | ||||
| { | { | ||||
| /* initialize! */ | /* initialize! */ | ||||
| if (data->multi_data.init == BUTTON_MULTI_INIT_UNSET) { | if (data->multi_data.init == BUTTON_MULTI_INIT_UNSET) { | ||||
| /* --> (BUTTON_MULTI_INIT_SETUP | BUTTON_MULTI_INIT_DISABLE) */ | /* --> (BUTTON_MULTI_INIT_SETUP | BUTTON_MULTI_INIT_DISABLE) */ | ||||
| const float margin_y = DRAG_MULTINUM_THRESHOLD_DRAG_Y / sqrtf(block->aspect); | const float margin_y = DRAG_MULTINUM_THRESHOLD_DRAG_Y / sqrtf(block->aspect); | ||||
| ▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | static bool ui_but_isect_pie_seg(uiBlock *block, uiBut *but) | ||||
| ui_but_pie_dir(but->pie_dir, vec); | ui_but_pie_dir(but->pie_dir, vec); | ||||
| if (saacos(dot_v2v2(vec, block->pie_data.pie_dir)) < angle_range) | if (saacos(dot_v2v2(vec, block->pie_data.pie_dir)) < angle_range) | ||||
| return true; | return true; | ||||
| return false; | return false; | ||||
| } | } | ||||
| uiBut *ui_but_find_activated(ARegion *ar) | uiBut *ui_but_find_active_in_region(ARegion *ar) | ||||
| { | { | ||||
| uiBlock *block; | uiBlock *block; | ||||
| uiBut *but; | uiBut *but; | ||||
| for (block = ar->uiblocks.first; block; block = block->next) | for (block = ar->uiblocks.first; block; block = block->next) | ||||
| for (but = block->buttons.first; but; but = but->next) | for (but = block->buttons.first; but; but = but->next) | ||||
| if (but->active) | if (but->active) | ||||
| return but; | return but; | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| bool ui_button_is_active(ARegion *ar) | bool ui_but_is_active(ARegion *ar) | ||||
| { | { | ||||
| return (ui_but_find_activated(ar) != NULL); | return (ui_but_find_active_in_region(ar) != NULL); | ||||
| } | } | ||||
| /* is called by notifier */ | /* is called by notifier */ | ||||
| void uiFreeActiveButtons(const bContext *C, bScreen *screen) | void UI_screen_free_active_but(const bContext *C, bScreen *screen) | ||||
| { | { | ||||
| ScrArea *sa = screen->areabase.first; | ScrArea *sa = screen->areabase.first; | ||||
| for (; sa; sa = sa->next) { | for (; sa; sa = sa->next) { | ||||
| ARegion *ar = sa->regionbase.first; | ARegion *ar = sa->regionbase.first; | ||||
| for (; ar; ar = ar->next) { | for (; ar; ar = ar->next) { | ||||
| uiBut *but = ui_but_find_activated(ar); | uiBut *but = ui_but_find_active_in_region(ar); | ||||
| if (but) { | if (but) { | ||||
| uiHandleButtonData *data = but->active; | uiHandleButtonData *data = but->active; | ||||
| if (data->menu == NULL && data->searchbox == NULL) | if (data->menu == NULL && data->searchbox == NULL) | ||||
| if (data->state == BUTTON_STATE_HIGHLIGHT) | if (data->state == BUTTON_STATE_HIGHLIGHT) | ||||
| ui_button_active_free(C, but); | ui_but_active_free(C, but); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* returns true if highlighted button allows drop of names */ | /* returns true if highlighted button allows drop of names */ | ||||
| /* called in region context */ | /* called in region context */ | ||||
| bool UI_but_active_drop_name(bContext *C) | bool UI_but_active_drop_name(bContext *C) | ||||
| { | { | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| uiBut *but = ui_but_find_activated(ar); | uiBut *but = ui_but_find_active_in_region(ar); | ||||
| if (but) { | if (but) { | ||||
| if (ELEM(but->type, TEX, SEARCH_MENU, SEARCH_MENU_UNLINK)) | if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| bool UI_but_active_drop_color(bContext *C) | bool UI_but_active_drop_color(bContext *C) | ||||
| { | { | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| if (ar) { | if (ar) { | ||||
| uiBut *but = ui_but_find_activated(ar); | uiBut *but = ui_but_find_active_in_region(ar); | ||||
| if (but && but->type == COLOR) | if (but && but->type == UI_BTYPE_COLOR) | ||||
| return true; | return true; | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| static void ui_blocks_set_tooltips(ARegion *ar, const bool enable) | static void ui_blocks_set_tooltips(ARegion *ar, const bool enable) | ||||
| { | { | ||||
| uiBlock *block; | uiBlock *block; | ||||
| if (!ar) | if (!ar) | ||||
| return; | return; | ||||
| /* we disabled buttons when when they were already shown, and | /* we disabled buttons when when they were already shown, and | ||||
| * re-enable them on mouse move */ | * re-enable them on mouse move */ | ||||
| for (block = ar->uiblocks.first; block; block = block->next) | for (block = ar->uiblocks.first; block; block = block->next) | ||||
| block->tooltipdisabled = !enable; | block->tooltipdisabled = !enable; | ||||
| } | } | ||||
| static bool ui_mouse_inside_region(ARegion *ar, int x, int y) | static bool ui_region_contains_point_px(ARegion *ar, int x, int y) | ||||
| { | { | ||||
| uiBlock *block; | uiBlock *block; | ||||
| /* check if the mouse is in the region */ | /* check if the mouse is in the region */ | ||||
| if (!BLI_rcti_isect_pt(&ar->winrct, x, y)) { | if (!BLI_rcti_isect_pt(&ar->winrct, x, y)) { | ||||
| for (block = ar->uiblocks.first; block; block = block->next) | for (block = ar->uiblocks.first; block; block = block->next) | ||||
| block->auto_open = false; | block->auto_open = false; | ||||
| Show All 17 Lines | if (ar->v2d.mask.xmin != ar->v2d.mask.xmax) { | ||||
| /* check if in the rect */ | /* check if in the rect */ | ||||
| if (!BLI_rcti_isect_pt(&v2d->mask, mx, my)) | if (!BLI_rcti_isect_pt(&v2d->mask, mx, my)) | ||||
| return false; | return false; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| static bool ui_mouse_inside_button(ARegion *ar, uiBut *but, int x, int y) | static bool ui_but_contains_point_px(ARegion *ar, uiBut *but, int x, int y) | ||||
| { | { | ||||
| uiBlock *block = but->block; | uiBlock *block = but->block; | ||||
| float mx, my; | float mx, my; | ||||
| if (!ui_mouse_inside_region(ar, x, y)) | if (!ui_region_contains_point_px(ar, x, y)) | ||||
| return false; | return false; | ||||
| mx = x; | mx = x; | ||||
| my = y; | my = y; | ||||
| ui_window_to_block_fl(ar, block, &mx, &my); | ui_window_to_block_fl(ar, block, &mx, &my); | ||||
| if (but->pie_dir != UI_RADIAL_NONE) { | if (but->pie_dir != UI_RADIAL_NONE) { | ||||
| if (!ui_but_isect_pie_seg(block, but)) { | if (!ui_but_isect_pie_seg(block, but)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| else if (!ui_but_contains_pt(but, mx, my)) { | else if (!ui_but_contains_pt(but, mx, my)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| /** | /** | ||||
| * Can we mouse over the button or is it hidden/disabled/layout. | * Can we mouse over the button or is it hidden/disabled/layout. | ||||
| * Note: ctrl is kind of a hack currently, so that non-embossed TEX button behaves as a label when ctrl is not pressed. | * Note: ctrl is kind of a hack currently, so that non-embossed UI_BTYPE_TEXT button behaves as a label when ctrl is not pressed. | ||||
| */ | */ | ||||
| static bool ui_is_but_interactive(const uiBut *but, const bool labeledit) | static bool ui_but_is_interactive(const uiBut *but, const bool labeledit) | ||||
| { | { | ||||
| /* note, LABEL is included for highlights, this allows drags */ | /* note, UI_BTYPE_LABEL is included for highlights, this allows drags */ | ||||
| if ((but->type == LABEL) && but->dragpoin == NULL) | if ((but->type == UI_BTYPE_LABEL) && but->dragpoin == NULL) | ||||
| return false; | return false; | ||||
| if (ELEM(but->type, ROUNDBOX, SEPR, SEPRLINE, LISTBOX)) | if (ELEM(but->type, UI_BTYPE_ROUNDBOX, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE, UI_BTYPE_LISTBOX)) | ||||
| return false; | return false; | ||||
| if (but->flag & UI_HIDDEN) | if (but->flag & UI_HIDDEN) | ||||
| return false; | return false; | ||||
| if (but->flag & UI_SCROLLED) | if (but->flag & UI_SCROLLED) | ||||
| return false; | return false; | ||||
| if ((but->type == TEX) && (but->dt == UI_EMBOSSN) && !labeledit) | if ((but->type == UI_BTYPE_TEXT) && (but->dt == UI_EMBOSS_NONE) && !labeledit) | ||||
| return false; | return false; | ||||
| if ((but->type == LISTROW) && labeledit) | if ((but->type == UI_BTYPE_LISTROW) && labeledit) | ||||
| return false; | return false; | ||||
| return true; | return true; | ||||
| } | } | ||||
| bool ui_is_but_search_unlink_visible(const uiBut *but) | bool ui_but_is_search_unlink_visible(const uiBut *but) | ||||
| { | { | ||||
| BLI_assert(but->type == SEARCH_MENU_UNLINK); | BLI_assert(but->type == UI_BTYPE_SEARCH_MENU_UNLINK); | ||||
| return ((but->editstr == NULL) && | return ((but->editstr == NULL) && | ||||
| (but->drawstr[0] != '\0')); | (but->drawstr[0] != '\0')); | ||||
| } | } | ||||
| /* x and y are only used in case event is NULL... */ | /* x and y are only used in case event is NULL... */ | ||||
| static uiBut *ui_but_find_mouse_over_ex(ARegion *ar, const int x, const int y, const bool labeledit) | static uiBut *ui_but_find_mouse_over_ex(ARegion *ar, const int x, const int y, const bool labeledit) | ||||
| { | { | ||||
| uiBlock *block; | uiBlock *block; | ||||
| uiBut *but, *butover = NULL; | uiBut *but, *butover = NULL; | ||||
| float mx, my; | float mx, my; | ||||
| // if (!win->active) | // if (!win->active) | ||||
| // return NULL; | // return NULL; | ||||
| if (!ui_mouse_inside_region(ar, x, y)) | if (!ui_region_contains_point_px(ar, x, y)) | ||||
| return NULL; | return NULL; | ||||
| for (block = ar->uiblocks.first; block; block = block->next) { | for (block = ar->uiblocks.first; block; block = block->next) { | ||||
| mx = x; | mx = x; | ||||
| my = y; | my = y; | ||||
| ui_window_to_block_fl(ar, block, &mx, &my); | ui_window_to_block_fl(ar, block, &mx, &my); | ||||
| for (but = block->buttons.last; but; but = but->prev) { | for (but = block->buttons.last; but; but = but->prev) { | ||||
| if (ui_is_but_interactive(but, labeledit)) { | if (ui_but_is_interactive(but, labeledit)) { | ||||
| if (but->pie_dir != UI_RADIAL_NONE) { | if (but->pie_dir != UI_RADIAL_NONE) { | ||||
| if (ui_but_isect_pie_seg(block, but)) { | if (ui_but_isect_pie_seg(block, but)) { | ||||
| butover = but; | butover = but; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| else if (ui_but_contains_pt(but, mx, my)) { | else if (ui_but_contains_pt(but, mx, my)) { | ||||
| butover = but; | butover = but; | ||||
| Show All 21 Lines | |||||
| static uiBut *ui_list_find_mouse_over(ARegion *ar, int x, int y) | static uiBut *ui_list_find_mouse_over(ARegion *ar, int x, int y) | ||||
| { | { | ||||
| uiBlock *block; | uiBlock *block; | ||||
| uiBut *but; | uiBut *but; | ||||
| float mx, my; | float mx, my; | ||||
| if (!ui_mouse_inside_region(ar, x, y)) | if (!ui_region_contains_point_px(ar, x, y)) | ||||
| return NULL; | return NULL; | ||||
| for (block = ar->uiblocks.first; block; block = block->next) { | for (block = ar->uiblocks.first; block; block = block->next) { | ||||
| mx = x; | mx = x; | ||||
| my = y; | my = y; | ||||
| ui_window_to_block_fl(ar, block, &mx, &my); | ui_window_to_block_fl(ar, block, &mx, &my); | ||||
| for (but = block->buttons.last; but; but = but->prev) { | for (but = block->buttons.last; but; but = but->prev) { | ||||
| if (but->type == LISTBOX && ui_but_contains_pt(but, mx, my)) { | if (but->type == UI_BTYPE_LISTBOX && ui_but_contains_pt(but, mx, my)) { | ||||
| return but; | return but; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState state) | ||||
| /* highlight has timers for tooltips and auto open */ | /* highlight has timers for tooltips and auto open */ | ||||
| if (state == BUTTON_STATE_HIGHLIGHT) { | if (state == BUTTON_STATE_HIGHLIGHT) { | ||||
| but->flag &= ~UI_SELECT; | but->flag &= ~UI_SELECT; | ||||
| button_tooltip_timer_reset(C, but); | button_tooltip_timer_reset(C, but); | ||||
| /* automatic open pulldown block timer */ | /* automatic open pulldown block timer */ | ||||
| if (ELEM(but->type, BLOCK, PULLDOWN)) { | if (ELEM(but->type, UI_BTYPE_BLOCK, UI_BTYPE_PULLDOWN)) { | ||||
| if (data->used_mouse && !data->autoopentimer) { | if (data->used_mouse && !data->autoopentimer) { | ||||
| int time; | int time; | ||||
| if (but->block->auto_open == true) { /* test for toolbox */ | if (but->block->auto_open == true) { /* test for toolbox */ | ||||
| time = 1; | time = 1; | ||||
| } | } | ||||
| else if ((but->block->flag & UI_BLOCK_LOOP && but->type != BLOCK) || but->block->auto_open == true) { | else if ((but->block->flag & UI_BLOCK_LOOP && but->type != UI_BTYPE_BLOCK) || but->block->auto_open == true) { | ||||
| time = 5 * U.menuthreshold2; | time = 5 * U.menuthreshold2; | ||||
| } | } | ||||
| else if (U.uiflag & USER_MENUOPENAUTO) { | else if (U.uiflag & USER_MENUOPENAUTO) { | ||||
| time = 5 * U.menuthreshold1; | time = 5 * U.menuthreshold1; | ||||
| } | } | ||||
| else { | else { | ||||
| time = -1; /* do nothing */ | time = -1; /* do nothing */ | ||||
| } | } | ||||
| Show All 14 Lines | if (state == BUTTON_STATE_TEXT_EDITING && data->state != BUTTON_STATE_TEXT_SELECTING) | ||||
| ui_textedit_begin(C, but, data); | ui_textedit_begin(C, but, data); | ||||
| else if (data->state == BUTTON_STATE_TEXT_EDITING && state != BUTTON_STATE_TEXT_SELECTING) | else if (data->state == BUTTON_STATE_TEXT_EDITING && state != BUTTON_STATE_TEXT_SELECTING) | ||||
| ui_textedit_end(C, but, data); | ui_textedit_end(C, but, data); | ||||
| else if (data->state == BUTTON_STATE_TEXT_SELECTING && state != BUTTON_STATE_TEXT_EDITING) | else if (data->state == BUTTON_STATE_TEXT_SELECTING && state != BUTTON_STATE_TEXT_EDITING) | ||||
| ui_textedit_end(C, but, data); | ui_textedit_end(C, but, data); | ||||
| /* number editing */ | /* number editing */ | ||||
| if (state == BUTTON_STATE_NUM_EDITING) { | if (state == BUTTON_STATE_NUM_EDITING) { | ||||
| if (ui_is_a_warp_but(but)) | if (ui_but_is_cursor_warp(but)) | ||||
| WM_cursor_grab_enable(CTX_wm_window(C), true, true, NULL); | WM_cursor_grab_enable(CTX_wm_window(C), true, true, NULL); | ||||
| ui_numedit_begin(but, data); | ui_numedit_begin(but, data); | ||||
| } | } | ||||
| else if (data->state == BUTTON_STATE_NUM_EDITING) { | else if (data->state == BUTTON_STATE_NUM_EDITING) { | ||||
| ui_numedit_end(but, data); | ui_numedit_end(but, data); | ||||
| if (but->flag & UI_BUT_DRIVEN) | if (but->flag & UI_BUT_DRIVEN) | ||||
| WM_report(C, RPT_INFO, "Can't edit driven number value, see graph editor for the driver setup."); | WM_report(C, RPT_INFO, "Can't edit driven number value, see graph editor for the driver setup."); | ||||
| if (ui_is_a_warp_but(but)) { | if (ui_but_is_cursor_warp(but)) { | ||||
| #ifdef USE_CONT_MOUSE_CORRECT | #ifdef USE_CONT_MOUSE_CORRECT | ||||
| if (data->ungrab_mval[0] != FLT_MAX) { | if (data->ungrab_mval[0] != FLT_MAX) { | ||||
| int mouse_ungrab_xy[2]; | int mouse_ungrab_xy[2]; | ||||
| ui_block_to_window_fl(data->region, but->block, &data->ungrab_mval[0], &data->ungrab_mval[1]); | ui_block_to_window_fl(data->region, but->block, &data->ungrab_mval[0], &data->ungrab_mval[1]); | ||||
| mouse_ungrab_xy[0] = data->ungrab_mval[0]; | mouse_ungrab_xy[0] = data->ungrab_mval[0]; | ||||
| mouse_ungrab_xy[1] = data->ungrab_mval[1]; | mouse_ungrab_xy[1] = data->ungrab_mval[1]; | ||||
| WM_cursor_grab_disable(data->window, mouse_ungrab_xy); | WM_cursor_grab_disable(data->window, mouse_ungrab_xy); | ||||
| } | } | ||||
| else { | else { | ||||
| WM_cursor_grab_disable(data->window, NULL); | WM_cursor_grab_disable(data->window, NULL); | ||||
| } | } | ||||
| #else | #else | ||||
| WM_cursor_grab_disable(data->window, NULL); | WM_cursor_grab_disable(data->window, NULL); | ||||
| #endif | #endif | ||||
| } | } | ||||
| } | } | ||||
| /* menu open */ | /* menu open */ | ||||
| if (state == BUTTON_STATE_MENU_OPEN) | if (state == BUTTON_STATE_MENU_OPEN) | ||||
| ui_blockopen_begin(C, but, data); | ui_block_open_begin(C, but, data); | ||||
| else if (data->state == BUTTON_STATE_MENU_OPEN) | else if (data->state == BUTTON_STATE_MENU_OPEN) | ||||
| ui_blockopen_end(C, but, data); | ui_block_open_end(C, but, data); | ||||
| /* add a short delay before exiting, to ensure there is some feedback */ | /* add a short delay before exiting, to ensure there is some feedback */ | ||||
| if (state == BUTTON_STATE_WAIT_FLASH) { | if (state == BUTTON_STATE_WAIT_FLASH) { | ||||
| data->flashtimer = WM_event_add_timer(data->wm, data->window, TIMER, BUTTON_FLASH_DELAY); | data->flashtimer = WM_event_add_timer(data->wm, data->window, TIMER, BUTTON_FLASH_DELAY); | ||||
| } | } | ||||
| else if (data->flashtimer) { | else if (data->flashtimer) { | ||||
| WM_event_remove_timer(data->wm, data->window, data->flashtimer); | WM_event_remove_timer(data->wm, data->window, data->flashtimer); | ||||
| data->flashtimer = NULL; | data->flashtimer = NULL; | ||||
| Show All 17 Lines | #endif | ||||
| /* wait for mousemove to enable drag */ | /* wait for mousemove to enable drag */ | ||||
| if (state == BUTTON_STATE_WAIT_DRAG) { | if (state == BUTTON_STATE_WAIT_DRAG) { | ||||
| but->flag &= ~UI_SELECT; | but->flag &= ~UI_SELECT; | ||||
| } | } | ||||
| data->state = state; | data->state = state; | ||||
| if (state != BUTTON_STATE_EXIT) { | if (state != BUTTON_STATE_EXIT) { | ||||
| /* When objects for eg. are removed, running ui_check_but() can access | /* When objects for eg. are removed, running ui_but_update() can access | ||||
| * the removed data - so disable update on exit. Also in case of | * the removed data - so disable update on exit. Also in case of | ||||
| * highlight when not in a popup menu, we remove because data used in | * highlight when not in a popup menu, we remove because data used in | ||||
| * button below popup might have been removed by action of popup. Needs | * button below popup might have been removed by action of popup. Needs | ||||
| * a more reliable solution... */ | * a more reliable solution... */ | ||||
| if (state != BUTTON_STATE_HIGHLIGHT || (but->block->flag & UI_BLOCK_LOOP)) | if (state != BUTTON_STATE_HIGHLIGHT || (but->block->flag & UI_BLOCK_LOOP)) | ||||
| ui_check_but(but); | ui_but_update(but); | ||||
| } | } | ||||
| /* redraw */ | /* redraw */ | ||||
| ED_region_tag_redraw(data->region); | ED_region_tag_redraw(data->region); | ||||
| } | } | ||||
| static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonActivateType type) | static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonActivateType type) | ||||
| { | { | ||||
| uiHandleButtonData *data; | uiHandleButtonData *data; | ||||
| /* setup struct */ | /* setup struct */ | ||||
| data = MEM_callocN(sizeof(uiHandleButtonData), "uiHandleButtonData"); | data = MEM_callocN(sizeof(uiHandleButtonData), "uiHandleButtonData"); | ||||
| data->wm = CTX_wm_manager(C); | data->wm = CTX_wm_manager(C); | ||||
| data->window = CTX_wm_window(C); | data->window = CTX_wm_window(C); | ||||
| data->region = ar; | data->region = ar; | ||||
| #ifdef USE_CONT_MOUSE_CORRECT | #ifdef USE_CONT_MOUSE_CORRECT | ||||
| copy_v2_fl(data->ungrab_mval, FLT_MAX); | copy_v2_fl(data->ungrab_mval, FLT_MAX); | ||||
| #endif | #endif | ||||
| if (ELEM(but->type, BUT_CURVE, SEARCH_MENU, SEARCH_MENU_UNLINK)) { | if (ELEM(but->type, UI_BTYPE_CURVE, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)) { | ||||
| /* XXX curve is temp */ | /* XXX curve is temp */ | ||||
| } | } | ||||
| else { | else { | ||||
| data->interactive = true; | data->interactive = true; | ||||
| } | } | ||||
| data->state = BUTTON_STATE_INIT; | data->state = BUTTON_STATE_INIT; | ||||
| Show All 10 Lines | #endif | ||||
| if (type == BUTTON_ACTIVATE_OVER) { | if (type == BUTTON_ACTIVATE_OVER) { | ||||
| data->used_mouse = true; | data->used_mouse = true; | ||||
| } | } | ||||
| button_activate_state(C, but, BUTTON_STATE_HIGHLIGHT); | button_activate_state(C, but, BUTTON_STATE_HIGHLIGHT); | ||||
| /* activate right away */ | /* activate right away */ | ||||
| if (but->flag & UI_BUT_IMMEDIATE) { | if (but->flag & UI_BUT_IMMEDIATE) { | ||||
| if (but->type == HOTKEYEVT) | if (but->type == UI_BTYPE_HOTKEY_EVENT) | ||||
| button_activate_state(C, but, BUTTON_STATE_WAIT_KEY_EVENT); | button_activate_state(C, but, BUTTON_STATE_WAIT_KEY_EVENT); | ||||
| /* .. more to be added here */ | /* .. more to be added here */ | ||||
| } | } | ||||
| if (type == BUTTON_ACTIVATE_OPEN) { | if (type == BUTTON_ACTIVATE_OPEN) { | ||||
| button_activate_state(C, but, BUTTON_STATE_MENU_OPEN); | button_activate_state(C, but, BUTTON_STATE_MENU_OPEN); | ||||
| /* activate first button in submenu */ | /* activate first button in submenu */ | ||||
| Show All 10 Lines | if (data->menu && data->menu->region) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else if (type == BUTTON_ACTIVATE_TEXT_EDITING) | else if (type == BUTTON_ACTIVATE_TEXT_EDITING) | ||||
| button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); | button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING); | ||||
| else if (type == BUTTON_ACTIVATE_APPLY) | else if (type == BUTTON_ACTIVATE_APPLY) | ||||
| button_activate_state(C, but, BUTTON_STATE_WAIT_FLASH); | button_activate_state(C, but, BUTTON_STATE_WAIT_FLASH); | ||||
| if (but->type == GRIP) { | if (but->type == UI_BTYPE_GRIP) { | ||||
| const bool horizontal = (BLI_rctf_size_x(&but->rect) < BLI_rctf_size_y(&but->rect)); | const bool horizontal = (BLI_rctf_size_x(&but->rect) < BLI_rctf_size_y(&but->rect)); | ||||
| WM_cursor_modal_set(data->window, horizontal ? CURSOR_X_MOVE : CURSOR_Y_MOVE); | WM_cursor_modal_set(data->window, horizontal ? CURSOR_X_MOVE : CURSOR_Y_MOVE); | ||||
| } | } | ||||
| } | } | ||||
| static void button_activate_exit(bContext *C, uiBut *but, uiHandleButtonData *data, | static void button_activate_exit(bContext *C, uiBut *but, uiHandleButtonData *data, | ||||
| const bool mousemove, const bool onfree) | const bool mousemove, const bool onfree) | ||||
| { | { | ||||
| uiBlock *block = but->block; | uiBlock *block = but->block; | ||||
| uiBut *bt; | uiBut *bt; | ||||
| if (but->type == GRIP) { | if (but->type == UI_BTYPE_GRIP) { | ||||
| WM_cursor_modal_restore(data->window); | WM_cursor_modal_restore(data->window); | ||||
| } | } | ||||
| /* ensure we are in the exit state */ | /* ensure we are in the exit state */ | ||||
| if (data->state != BUTTON_STATE_EXIT) | if (data->state != BUTTON_STATE_EXIT) | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| /* apply the button action or value */ | /* apply the button action or value */ | ||||
| if (!onfree) | if (!onfree) | ||||
| ui_apply_button(C, block, but, data, false); | ui_apply_but(C, block, but, data, false); | ||||
| #ifdef USE_DRAG_MULTINUM | #ifdef USE_DRAG_MULTINUM | ||||
| if (data->multi_data.has_mbuts) { | if (data->multi_data.has_mbuts) { | ||||
| for (bt = block->buttons.first; bt; bt = bt->next) { | for (bt = block->buttons.first; bt; bt = bt->next) { | ||||
| if (bt->flag & UI_BUT_DRAG_MULTI) { | if (bt->flag & UI_BUT_DRAG_MULTI) { | ||||
| bt->flag &= ~UI_BUT_DRAG_MULTI; | bt->flag &= ~UI_BUT_DRAG_MULTI; | ||||
| if (!data->cancel) { | if (!data->cancel) { | ||||
| ui_apply_autokey(C, bt); | ui_apply_but_autokey(C, bt); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ui_multibut_free(data, block); | ui_multibut_free(data, block); | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* if this button is in a menu, this will set the button return | /* if this button is in a menu, this will set the button return | ||||
| * value to the button value and the menu return value to ok, the | * value to the button value and the menu return value to ok, the | ||||
| * menu return value will be picked up and the menu will close */ | * menu return value will be picked up and the menu will close */ | ||||
| if (block->handle && !(block->flag & UI_BLOCK_KEEP_OPEN)) { | if (block->handle && !(block->flag & UI_BLOCK_KEEP_OPEN)) { | ||||
| if (!data->cancel || data->escapecancel) { | if (!data->cancel || data->escapecancel) { | ||||
| uiPopupBlockHandle *menu; | uiPopupBlockHandle *menu; | ||||
| menu = block->handle; | menu = block->handle; | ||||
| menu->butretval = data->retval; | menu->butretval = data->retval; | ||||
| menu->menuretval = (data->cancel) ? UI_RETURN_CANCEL : UI_RETURN_OK; | menu->menuretval = (data->cancel) ? UI_RETURN_CANCEL : UI_RETURN_OK; | ||||
| } | } | ||||
| } | } | ||||
| if (!onfree && !data->cancel) { | if (!onfree && !data->cancel) { | ||||
| /* autokey & undo push */ | /* autokey & undo push */ | ||||
| ui_apply_undo(but); | ui_apply_but_undo(but); | ||||
| ui_apply_autokey(C, but); | ui_apply_but_autokey(C, but); | ||||
| /* popup menu memory */ | /* popup menu memory */ | ||||
| if (block->flag & UI_BLOCK_POPUP_MEMORY) | if (block->flag & UI_BLOCK_POPUP_MEMORY) | ||||
| ui_popup_menu_memory_set(block, but); | ui_popup_menu_memory_set(block, but); | ||||
| } | } | ||||
| /* disable tooltips until mousemove + last active flag */ | /* disable tooltips until mousemove + last active flag */ | ||||
| for (block = data->region->uiblocks.first; block; block = block->next) { | for (block = data->region->uiblocks.first; block; block = block->next) { | ||||
| Show All 18 Lines | #endif | ||||
| if (but->active) { | if (but->active) { | ||||
| MEM_freeN(but->active); | MEM_freeN(but->active); | ||||
| but->active = NULL; | but->active = NULL; | ||||
| } | } | ||||
| but->flag &= ~(UI_ACTIVE | UI_SELECT); | but->flag &= ~(UI_ACTIVE | UI_SELECT); | ||||
| but->flag |= UI_BUT_LAST_ACTIVE; | but->flag |= UI_BUT_LAST_ACTIVE; | ||||
| if (!onfree) | if (!onfree) | ||||
| ui_check_but(but); | ui_but_update(but); | ||||
| /* adds empty mousemove in queue for re-init handler, in case mouse is | /* adds empty mousemove in queue for re-init handler, in case mouse is | ||||
| * still over a button. we cannot just check for this ourselfs because | * still over a button. we cannot just check for this ourselfs because | ||||
| * at this point the mouse may be over a button in another region */ | * at this point the mouse may be over a button in another region */ | ||||
| if (mousemove) | if (mousemove) | ||||
| WM_event_add_mousemove(C); | WM_event_add_mousemove(C); | ||||
| } | } | ||||
| void ui_button_active_free(const bContext *C, uiBut *but) | void ui_but_active_free(const bContext *C, uiBut *but) | ||||
| { | { | ||||
| uiHandleButtonData *data; | uiHandleButtonData *data; | ||||
| /* this gets called when the button somehow disappears while it is still | /* this gets called when the button somehow disappears while it is still | ||||
| * active, this is bad for user interaction, but we need to handle this | * active, this is bad for user interaction, but we need to handle this | ||||
| * case cleanly anyway in case it happens */ | * case cleanly anyway in case it happens */ | ||||
| if (but->active) { | if (but->active) { | ||||
| data = but->active; | data = but->active; | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| return (but->rnapoin.data != NULL); | return (but->rnapoin.data != NULL); | ||||
| } | } | ||||
| static uiBut *ui_context_rna_button_active(const bContext *C) | static uiBut *ui_context_rna_button_active(const bContext *C) | ||||
| { | { | ||||
| return ui_context_button_active(C, ui_context_rna_button_active_test); | return ui_context_button_active(C, ui_context_rna_button_active_test); | ||||
| } | } | ||||
| uiBut *uiContextActiveButton(const struct bContext *C) | uiBut *UI_context_active_but_get(const struct bContext *C) | ||||
| { | { | ||||
| return ui_context_button_active(C, NULL); | return ui_context_button_active(C, NULL); | ||||
| } | } | ||||
| /* helper function for insert keyframe, reset to default, etc operators */ | /* helper function for insert keyframe, reset to default, etc operators */ | ||||
| void uiContextActiveProperty(const bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index) | void UI_context_active_but_prop_get(const bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index) | ||||
| { | { | ||||
| uiBut *activebut = ui_context_rna_button_active(C); | uiBut *activebut = ui_context_rna_button_active(C); | ||||
| memset(ptr, 0, sizeof(*ptr)); | memset(ptr, 0, sizeof(*ptr)); | ||||
| if (activebut && activebut->rnapoin.data) { | if (activebut && activebut->rnapoin.data) { | ||||
| *ptr = activebut->rnapoin; | *ptr = activebut->rnapoin; | ||||
| *prop = activebut->rnaprop; | *prop = activebut->rnaprop; | ||||
| *index = activebut->rnaindex; | *index = activebut->rnaindex; | ||||
| } | } | ||||
| else { | else { | ||||
| *prop = NULL; | *prop = NULL; | ||||
| *index = 0; | *index = 0; | ||||
| } | } | ||||
| } | } | ||||
| void uiContextActivePropertyHandle(bContext *C) | void UI_context_active_but_prop_handle(bContext *C) | ||||
| { | { | ||||
| uiBut *activebut = ui_context_rna_button_active(C); | uiBut *activebut = ui_context_rna_button_active(C); | ||||
| if (activebut) { | if (activebut) { | ||||
| /* TODO, look into a better way to handle the button change | /* TODO, look into a better way to handle the button change | ||||
| * currently this is mainly so reset defaults works for the | * currently this is mainly so reset defaults works for the | ||||
| * operator redo panel - campbell */ | * operator redo panel - campbell */ | ||||
| uiBlock *block = activebut->block; | uiBlock *block = activebut->block; | ||||
| if (block->handle_func) { | if (block->handle_func) { | ||||
| block->handle_func(C, block->handle_func_arg, activebut->retval); | block->handle_func(C, block->handle_func_arg, activebut->retval); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| wmOperator *uiContextActiveOperator(const struct bContext *C) | wmOperator *UI_context_active_operator_get(const struct bContext *C) | ||||
| { | { | ||||
| ARegion *ar_ctx = CTX_wm_region(C); | ARegion *ar_ctx = CTX_wm_region(C); | ||||
| uiBlock *block; | uiBlock *block; | ||||
| /* background mode */ | /* background mode */ | ||||
| if (ar_ctx == NULL) { | if (ar_ctx == NULL) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| Show All 21 Lines | for (ar = sc->regionbase.first; ar; ar = ar->next) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* helper function for insert keyframe, reset to default, etc operators */ | /* helper function for insert keyframe, reset to default, etc operators */ | ||||
| void uiContextAnimUpdate(const bContext *C) | void UI_context_update_anim_flag(const bContext *C) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| uiBlock *block; | uiBlock *block; | ||||
| uiBut *but, *activebut; | uiBut *but, *activebut; | ||||
| while (ar) { | while (ar) { | ||||
| /* find active button */ | /* find active button */ | ||||
| ▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | if (but) { | ||||
| button_activate_init(C, ar, but, BUTTON_ACTIVATE_OVER); | button_activate_init(C, ar, but, BUTTON_ACTIVATE_OVER); | ||||
| ui_do_button(C, but->block, but, event); | ui_do_button(C, but->block, but, event); | ||||
| } | } | ||||
| } | } | ||||
| return WM_UI_HANDLER_CONTINUE; | return WM_UI_HANDLER_CONTINUE; | ||||
| } | } | ||||
| /* exported to interface.c: uiButActiveOnly() */ | /* exported to interface.c: UI_but_active_only() */ | ||||
| void ui_button_activate_do(bContext *C, ARegion *ar, uiBut *but) | void ui_but_activate_event(bContext *C, ARegion *ar, uiBut *but) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| wmEvent event; | wmEvent event; | ||||
| button_activate_init(C, ar, but, BUTTON_ACTIVATE_OVER); | button_activate_init(C, ar, but, BUTTON_ACTIVATE_OVER); | ||||
| 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.customdata = but; | event.customdata = but; | ||||
| event.customdatafree = false; | event.customdatafree = false; | ||||
| ui_do_button(C, but->block, but, &event); | ui_do_button(C, but->block, but, &event); | ||||
| } | } | ||||
| /** | /** | ||||
| * Simulate moving the mouse over a button (or navigating to it with arrow keys). | * Simulate moving the mouse over a button (or navigating to it with arrow keys). | ||||
| * | * | ||||
| * exported so menus can start with a highlighted button, | * exported so menus can start with a highlighted button, | ||||
| * even if the mouse isnt over it | * even if the mouse isnt over it | ||||
| */ | */ | ||||
| void ui_button_activate_over(bContext *C, ARegion *ar, uiBut *but) | void ui_but_activate_over(bContext *C, ARegion *ar, uiBut *but) | ||||
| { | { | ||||
| button_activate_init(C, ar, but, BUTTON_ACTIVATE_OVER); | button_activate_init(C, ar, but, BUTTON_ACTIVATE_OVER); | ||||
| } | } | ||||
| void ui_button_execute_begin(struct bContext *UNUSED(C), struct ARegion *ar, uiBut *but, void **active_back) | void ui_but_execute_begin(struct bContext *UNUSED(C), struct ARegion *ar, uiBut *but, void **active_back) | ||||
| { | { | ||||
| /* note: ideally we would not have to change 'but->active' however | /* note: ideally we would not have to change 'but->active' however | ||||
| * some functions we call don't use data (as they should be doing) */ | * some functions we call don't use data (as they should be doing) */ | ||||
| uiHandleButtonData *data; | uiHandleButtonData *data; | ||||
| *active_back = but->active; | *active_back = but->active; | ||||
| data = MEM_callocN(sizeof(uiHandleButtonData), "uiHandleButtonData_Fake"); | data = MEM_callocN(sizeof(uiHandleButtonData), "uiHandleButtonData_Fake"); | ||||
| but->active = data; | but->active = data; | ||||
| data->region = ar; | data->region = ar; | ||||
| } | } | ||||
| void ui_button_execute_end(struct bContext *C, struct ARegion *UNUSED(ar), uiBut *but, void *active_back) | void ui_but_execute_end(struct bContext *C, struct ARegion *UNUSED(ar), uiBut *but, void *active_back) | ||||
| { | { | ||||
| ui_apply_button(C, but->block, but, but->active, true); | ui_apply_but(C, but->block, but, but->active, true); | ||||
| if ((but->flag & UI_BUT_DRAG_MULTI) == 0) { | if ((but->flag & UI_BUT_DRAG_MULTI) == 0) { | ||||
| ui_apply_autokey(C, but); | ui_apply_but_autokey(C, but); | ||||
| } | } | ||||
| /* use onfree event so undo is handled by caller and apply is already done above */ | /* use onfree event so undo is handled by caller and apply is already done above */ | ||||
| button_activate_exit((bContext *)C, but, but->active, false, true); | button_activate_exit((bContext *)C, but, but->active, false, true); | ||||
| but->active = active_back; | but->active = active_back; | ||||
| } | } | ||||
| static void ui_handle_button_activate(bContext *C, ARegion *ar, uiBut *but, uiButtonActivateType type) | static void ui_handle_button_activate(bContext *C, ARegion *ar, uiBut *but, uiButtonActivateType type) | ||||
| { | { | ||||
| uiBut *oldbut; | uiBut *oldbut; | ||||
| uiHandleButtonData *data; | uiHandleButtonData *data; | ||||
| oldbut = ui_but_find_activated(ar); | oldbut = ui_but_find_active_in_region(ar); | ||||
| if (oldbut) { | if (oldbut) { | ||||
| data = oldbut->active; | data = oldbut->active; | ||||
| data->cancel = true; | data->cancel = true; | ||||
| button_activate_exit(C, oldbut, data, false, false); | button_activate_exit(C, oldbut, data, false, false); | ||||
| } | } | ||||
| button_activate_init(C, ar, but, type); | button_activate_init(C, ar, but, type); | ||||
| } | } | ||||
| Show All 22 Lines | switch (event->type) { | ||||
| retval = WM_UI_HANDLER_CONTINUE; | retval = WM_UI_HANDLER_CONTINUE; | ||||
| break; | break; | ||||
| case MOUSEMOVE: | case MOUSEMOVE: | ||||
| { | { | ||||
| uiBut *but_other = ui_but_find_mouse_over(ar, event); | uiBut *but_other = ui_but_find_mouse_over(ar, event); | ||||
| bool exit = false; | bool exit = false; | ||||
| if ((!ui_block_is_menu(block) || ui_block_is_pie_menu(but->block)) && | if ((!ui_block_is_menu(block) || ui_block_is_pie_menu(but->block)) && | ||||
| !ui_mouse_inside_button(ar, but, event->x, event->y)) | !ui_but_contains_point_px(ar, but, event->x, event->y)) | ||||
| { | { | ||||
| exit = true; | exit = true; | ||||
| } | } | ||||
| else if (but_other && ui_but_is_editable(but_other) && (but_other != but)) { | else if (but_other && ui_but_is_editable(but_other) && (but_other != but)) { | ||||
| exit = true; | exit = true; | ||||
| } | } | ||||
| if (exit) { | if (exit) { | ||||
| Show All 18 Lines | switch (event->type) { | ||||
| if (!data->tooltip) | if (!data->tooltip) | ||||
| data->tooltip = ui_tooltip_create(C, data->region, but); | data->tooltip = ui_tooltip_create(C, data->region, but); | ||||
| } | } | ||||
| /* handle menu auto open timer */ | /* handle menu auto open timer */ | ||||
| else if (event->customdata == data->autoopentimer) { | else if (event->customdata == data->autoopentimer) { | ||||
| WM_event_remove_timer(data->wm, data->window, data->autoopentimer); | WM_event_remove_timer(data->wm, data->window, data->autoopentimer); | ||||
| data->autoopentimer = NULL; | data->autoopentimer = NULL; | ||||
| if (ui_mouse_inside_button(ar, but, event->x, event->y)) | if (ui_but_contains_point_px(ar, but, event->x, event->y)) | ||||
| button_activate_state(C, but, BUTTON_STATE_MENU_OPEN); | button_activate_state(C, but, BUTTON_STATE_MENU_OPEN); | ||||
| } | } | ||||
| retval = WM_UI_HANDLER_CONTINUE; | retval = WM_UI_HANDLER_CONTINUE; | ||||
| break; | break; | ||||
| } | } | ||||
| /* XXX hardcoded keymap check... but anyway, while view changes, tooltips should be removed */ | /* XXX hardcoded keymap check... but anyway, while view changes, tooltips should be removed */ | ||||
| case WHEELUPMOUSE: | case WHEELUPMOUSE: | ||||
| Show All 11 Lines | static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but) | ||||
| else if (data->state == BUTTON_STATE_WAIT_RELEASE) { | else if (data->state == BUTTON_STATE_WAIT_RELEASE) { | ||||
| switch (event->type) { | switch (event->type) { | ||||
| case WINDEACTIVATE: | case WINDEACTIVATE: | ||||
| data->cancel = true; | data->cancel = true; | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| break; | break; | ||||
| case MOUSEMOVE: | case MOUSEMOVE: | ||||
| if (ELEM(but->type, LINK, INLINK)) { | if (ELEM(but->type, UI_BTYPE_LINK, UI_BTYPE_INLINK)) { | ||||
| ARegion *ar = data->region; | ARegion *ar = data->region; | ||||
| but->flag |= UI_SELECT; | but->flag |= UI_SELECT; | ||||
| ui_do_button(C, block, but, event); | ui_do_button(C, block, but, event); | ||||
| ED_region_tag_redraw(ar); | ED_region_tag_redraw(ar); | ||||
| } | } | ||||
| else { | else { | ||||
| /* deselect the button when moving the mouse away */ | /* deselect the button when moving the mouse away */ | ||||
| /* also de-activate for buttons that only show higlights */ | /* also de-activate for buttons that only show higlights */ | ||||
| if (ui_mouse_inside_button(ar, but, event->x, event->y)) { | if (ui_but_contains_point_px(ar, but, event->x, event->y)) { | ||||
| if (!(but->flag & UI_SELECT)) { | if (!(but->flag & UI_SELECT)) { | ||||
| but->flag |= (UI_SELECT | UI_ACTIVE); | but->flag |= (UI_SELECT | UI_ACTIVE); | ||||
| data->cancel = false; | data->cancel = false; | ||||
| ED_region_tag_redraw(data->region); | ED_region_tag_redraw(data->region); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| if (but->flag & UI_SELECT) { | if (but->flag & UI_SELECT) { | ||||
| Show All 28 Lines | static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but) | ||||
| else if (data->state == BUTTON_STATE_MENU_OPEN) { | else if (data->state == BUTTON_STATE_MENU_OPEN) { | ||||
| /* check for exit because of mouse-over another button */ | /* check for exit because of mouse-over another button */ | ||||
| switch (event->type) { | switch (event->type) { | ||||
| case MOUSEMOVE: | case MOUSEMOVE: | ||||
| { | { | ||||
| uiBut *bt; | uiBut *bt; | ||||
| if (data->menu && data->menu->region) { | if (data->menu && data->menu->region) { | ||||
| if (ui_mouse_inside_region(data->menu->region, event->x, event->y)) { | if (ui_region_contains_point_px(data->menu->region, event->x, event->y)) { | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| bt = ui_but_find_mouse_over(ar, event); | bt = ui_but_find_mouse_over(ar, event); | ||||
| if (bt && bt->active != data) { | if (bt && bt->active != data) { | ||||
| if (but->type != COLOR) { /* exception */ | if (but->type != UI_BTYPE_COLOR) { /* exception */ | ||||
| data->cancel = true; | data->cancel = true; | ||||
| } | } | ||||
| button_activate_state(C, but, BUTTON_STATE_EXIT); | button_activate_state(C, but, BUTTON_STATE_EXIT); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | if (ELEM(type, UPARROWKEY, DOWNARROWKEY) || | ||||
| RNA_property_int_range(&but->rnapoin, but->rnaprop, &min, &max); | RNA_property_int_range(&but->rnapoin, but->rnaprop, &min, &max); | ||||
| CLAMP(value, min, max); | CLAMP(value, min, max); | ||||
| if (value != value_orig) { | if (value != value_orig) { | ||||
| RNA_property_int_set(&but->rnapoin, but->rnaprop, value); | RNA_property_int_set(&but->rnapoin, but->rnaprop, value); | ||||
| RNA_property_update(C, &but->rnapoin, but->rnaprop); | RNA_property_update(C, &but->rnapoin, but->rnaprop); | ||||
| ui_apply_undo(but); | ui_apply_but_undo(but); | ||||
| ui_list->flag |= UILST_SCROLL_TO_ACTIVE_ITEM; | ui_list->flag |= UILST_SCROLL_TO_ACTIVE_ITEM; | ||||
| ED_region_tag_redraw(ar); | ED_region_tag_redraw(ar); | ||||
| } | } | ||||
| retval = WM_UI_HANDLER_BREAK; | retval = WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| else if (ELEM(type, WHEELUPMOUSE, WHEELDOWNMOUSE) && event->shift) { | else if (ELEM(type, WHEELUPMOUSE, WHEELDOWNMOUSE) && event->shift) { | ||||
| /* We now have proper grip, but keep this anyway! */ | /* We now have proper grip, but keep this anyway! */ | ||||
| Show All 27 Lines | static void ui_handle_button_return_submenu(bContext *C, const wmEvent *event, uiBut *but) | ||||
| uiHandleButtonData *data; | uiHandleButtonData *data; | ||||
| uiPopupBlockHandle *menu; | uiPopupBlockHandle *menu; | ||||
| data = but->active; | data = but->active; | ||||
| menu = data->menu; | menu = data->menu; | ||||
| /* copy over return values from the closing menu */ | /* copy over return values from the closing menu */ | ||||
| if ((menu->menuretval & UI_RETURN_OK) || (menu->menuretval & UI_RETURN_UPDATE)) { | if ((menu->menuretval & UI_RETURN_OK) || (menu->menuretval & UI_RETURN_UPDATE)) { | ||||
| if (but->type == COLOR) | if (but->type == UI_BTYPE_COLOR) | ||||
| copy_v3_v3(data->vec, menu->retvec); | copy_v3_v3(data->vec, menu->retvec); | ||||
| else if (but->type == MENU) | else if (but->type == UI_BTYPE_MENU) | ||||
| data->value = menu->retvalue; | data->value = menu->retvalue; | ||||
| } | } | ||||
| if (menu->menuretval & UI_RETURN_UPDATE) { | if (menu->menuretval & UI_RETURN_UPDATE) { | ||||
| if (data->interactive) { | if (data->interactive) { | ||||
| ui_apply_button(C, but->block, but, data, true); | ui_apply_but(C, but->block, but, data, true); | ||||
| } | } | ||||
| else { | else { | ||||
| ui_check_but(but); | ui_but_update(but); | ||||
| } | } | ||||
| menu->menuretval = 0; | menu->menuretval = 0; | ||||
| } | } | ||||
| /* now change button state or exit, which will close the submenu */ | /* now change button state or exit, which will close the submenu */ | ||||
| if ((menu->menuretval & UI_RETURN_OK) || (menu->menuretval & UI_RETURN_CANCEL)) { | if ((menu->menuretval & UI_RETURN_OK) || (menu->menuretval & UI_RETURN_CANCEL)) { | ||||
| if (menu->menuretval != UI_RETURN_OK) | if (menu->menuretval != UI_RETURN_OK) | ||||
| data->cancel = true; | data->cancel = true; | ||||
| button_activate_exit(C, but, data, true, false); | button_activate_exit(C, but, data, true, false); | ||||
| } | } | ||||
| else if (menu->menuretval & UI_RETURN_OUT) { | else if (menu->menuretval & UI_RETURN_OUT) { | ||||
| if (event->type == MOUSEMOVE && ui_mouse_inside_button(data->region, but, event->x, event->y)) { | if (event->type == MOUSEMOVE && ui_but_contains_point_px(data->region, but, event->x, event->y)) { | ||||
| button_activate_state(C, but, BUTTON_STATE_HIGHLIGHT); | button_activate_state(C, but, BUTTON_STATE_HIGHLIGHT); | ||||
| } | } | ||||
| else { | else { | ||||
| if (ISKEYBOARD(event->type)) { | if (ISKEYBOARD(event->type)) { | ||||
| /* keyboard menu hierarchy navigation, going back to previous level */ | /* keyboard menu hierarchy navigation, going back to previous level */ | ||||
| but->active->used_mouse = false; | but->active->used_mouse = false; | ||||
| button_activate_state(C, but, BUTTON_STATE_HIGHLIGHT); | button_activate_state(C, but, BUTTON_STATE_HIGHLIGHT); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 243 Lines • ▼ Show 20 Lines | static bool ui_menu_pass_event_to_parent_if_nonactive(uiPopupBlockHandle *menu, const uiBut *but, | ||||
| else { | else { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| static int ui_handle_menu_button(bContext *C, const wmEvent *event, uiPopupBlockHandle *menu) | static int ui_handle_menu_button(bContext *C, const wmEvent *event, uiPopupBlockHandle *menu) | ||||
| { | { | ||||
| ARegion *ar = menu->region; | ARegion *ar = menu->region; | ||||
| uiBut *but = ui_but_find_activated(ar); | uiBut *but = ui_but_find_active_in_region(ar); | ||||
| int retval; | int retval; | ||||
| if (but) { | if (but) { | ||||
| /* Its possible there is an active menu item NOT under the mouse, | /* Its possible there is an active menu item NOT under the mouse, | ||||
| * in this case ignore mouse clicks outside the button (but Enter etc is accepted) */ | * in this case ignore mouse clicks outside the button (but Enter etc is accepted) */ | ||||
| if (event->val == KM_RELEASE) { | if (event->val == KM_RELEASE) { | ||||
| /* pass, needed so we can exit active menu-items when click-dragging out of them */ | /* pass, needed so we can exit active menu-items when click-dragging out of them */ | ||||
| } | } | ||||
| else if (!ui_block_is_menu(but->block) || ui_block_is_pie_menu(but->block)) { | else if (!ui_block_is_menu(but->block) || ui_block_is_pie_menu(but->block)) { | ||||
| /* pass, skip for dialogs */ | /* pass, skip for dialogs */ | ||||
| } | } | ||||
| else if (!ui_mouse_inside_region(but->active->region, event->x, event->y)) { | else if (!ui_region_contains_point_px(but->active->region, event->x, event->y)) { | ||||
| /* pass, needed to click-exit outside of non-flaoting menus */ | /* pass, needed to click-exit outside of non-flaoting menus */ | ||||
| } | } | ||||
| else if ((!ELEM(event->type, MOUSEMOVE, WHEELUPMOUSE, WHEELDOWNMOUSE, MOUSEPAN)) && ISMOUSE(event->type)) { | else if ((!ELEM(event->type, MOUSEMOVE, WHEELUPMOUSE, WHEELDOWNMOUSE, MOUSEPAN)) && ISMOUSE(event->type)) { | ||||
| if (!ui_mouse_inside_button(but->active->region, but, event->x, event->y)) { | if (!ui_but_contains_point_px(but->active->region, but, event->x, event->y)) { | ||||
| but = NULL; | but = NULL; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (but) { | if (but) { | ||||
| ScrArea *ctx_area = CTX_wm_area(C); | ScrArea *ctx_area = CTX_wm_area(C); | ||||
| ARegion *ctx_region = CTX_wm_region(C); | ARegion *ctx_region = CTX_wm_region(C); | ||||
| if (menu->ctx_area) CTX_wm_area_set(C, menu->ctx_area); | if (menu->ctx_area) CTX_wm_area_set(C, menu->ctx_area); | ||||
| if (menu->ctx_region) CTX_wm_region_set(C, menu->ctx_region); | if (menu->ctx_region) CTX_wm_region_set(C, menu->ctx_region); | ||||
| retval = ui_handle_button_event(C, event, but); | retval = ui_handle_button_event(C, event, but); | ||||
| if (menu->ctx_area) CTX_wm_area_set(C, ctx_area); | if (menu->ctx_area) CTX_wm_area_set(C, ctx_area); | ||||
| if (menu->ctx_region) CTX_wm_region_set(C, ctx_region); | if (menu->ctx_region) CTX_wm_region_set(C, ctx_region); | ||||
| } | } | ||||
| else { | else { | ||||
| retval = ui_handle_button_over(C, event, ar); | retval = ui_handle_button_over(C, event, ar); | ||||
| } | } | ||||
| return retval; | return retval; | ||||
| } | } | ||||
| float ui_block_calculate_pie_segment(uiBlock *block, const float event_xy[2]) | float ui_block_calc_pie_segment(uiBlock *block, const float event_xy[2]) | ||||
| { | { | ||||
| float seg1[2]; | float seg1[2]; | ||||
| float seg2[2]; | float seg2[2]; | ||||
| float len; | float len; | ||||
| if (block->pie_data.flags & UI_PIE_INITIAL_DIRECTION) { | if (block->pie_data.flags & UI_PIE_INITIAL_DIRECTION) { | ||||
| copy_v2_v2(seg1, block->pie_data.pie_center_init); | copy_v2_v2(seg1, block->pie_data.pie_center_init); | ||||
| } | } | ||||
| Show All 34 Lines | static int ui_handle_menu_event( | ||||
| my = event->y; | my = event->y; | ||||
| ui_window_to_block(ar, block, &mx, &my); | ui_window_to_block(ar, block, &mx, &my); | ||||
| /* check if mouse is inside block */ | /* check if mouse is inside block */ | ||||
| inside = BLI_rctf_isect_pt(&block->rect, mx, my); | inside = BLI_rctf_isect_pt(&block->rect, mx, my); | ||||
| inside_title = inside && ((my + (UI_UNIT_Y * 1.5f)) > block->rect.ymax); | inside_title = inside && ((my + (UI_UNIT_Y * 1.5f)) > block->rect.ymax); | ||||
| /* if there's an active modal button, don't check events or outside, except for search menu */ | /* if there's an active modal button, don't check events or outside, except for search menu */ | ||||
| but = ui_but_find_activated(ar); | but = ui_but_find_active_in_region(ar); | ||||
| #ifdef USE_DRAG_POPUP | #ifdef USE_DRAG_POPUP | ||||
| if (menu->is_grab) { | if (menu->is_grab) { | ||||
| if (event->type == LEFTMOUSE) { | if (event->type == LEFTMOUSE) { | ||||
| menu->is_grab = false; | menu->is_grab = false; | ||||
| retval = WM_UI_HANDLER_BREAK; | retval = WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| else { | else { | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | else { | ||||
| /* opening sublevels of pulldowns */ | /* opening sublevels of pulldowns */ | ||||
| case RIGHTARROWKEY: | case RIGHTARROWKEY: | ||||
| if (event->val == KM_PRESS && (block->flag & UI_BLOCK_LOOP)) { | if (event->val == KM_PRESS && (block->flag & UI_BLOCK_LOOP)) { | ||||
| if (ui_menu_pass_event_to_parent_if_nonactive(menu, but, level, retval)) | if (ui_menu_pass_event_to_parent_if_nonactive(menu, but, level, retval)) | ||||
| break; | break; | ||||
| but = ui_but_find_activated(ar); | but = ui_but_find_active_in_region(ar); | ||||
| if (!but) { | if (!but) { | ||||
| /* no item active, we make first active */ | /* no item active, we make first active */ | ||||
| if (block->direction & UI_TOP) but = ui_but_last(block); | if (block->direction & UI_DIR_UP) but = ui_but_last(block); | ||||
| else but = ui_but_first(block); | else but = ui_but_first(block); | ||||
| } | } | ||||
| if (but && ELEM(but->type, BLOCK, PULLDOWN)) | if (but && ELEM(but->type, UI_BTYPE_BLOCK, UI_BTYPE_PULLDOWN)) | ||||
| ui_handle_button_activate(C, ar, but, BUTTON_ACTIVATE_OPEN); | ui_handle_button_activate(C, ar, but, BUTTON_ACTIVATE_OPEN); | ||||
| } | } | ||||
| retval = WM_UI_HANDLER_BREAK; | retval = WM_UI_HANDLER_BREAK; | ||||
| break; | break; | ||||
| case UPARROWKEY: | case UPARROWKEY: | ||||
| case DOWNARROWKEY: | case DOWNARROWKEY: | ||||
| case WHEELUPMOUSE: | case WHEELUPMOUSE: | ||||
| case WHEELDOWNMOUSE: | case WHEELDOWNMOUSE: | ||||
| case MOUSEPAN: | case MOUSEPAN: | ||||
| /* arrowkeys: only handle for block_loop blocks */ | /* arrowkeys: only handle for block_loop blocks */ | ||||
| if (event->alt || event->shift || event->ctrl || event->oskey) { | if (event->alt || event->shift || event->ctrl || event->oskey) { | ||||
| /* pass */ | /* pass */ | ||||
| } | } | ||||
| else if (inside || (block->flag & UI_BLOCK_LOOP)) { | else if (inside || (block->flag & UI_BLOCK_LOOP)) { | ||||
| int type = event->type; | int type = event->type; | ||||
| int val = event->val; | int val = event->val; | ||||
| /* convert pan to scrollwheel */ | /* convert pan to scrollwheel */ | ||||
| if (type == MOUSEPAN) | if (type == MOUSEPAN) | ||||
| ui_pan_to_scroll(event, &type, &val); | ui_pan_to_scroll(event, &type, &val); | ||||
| if (val == KM_PRESS) { | if (val == KM_PRESS) { | ||||
| const eButType type_flip = BUT | ROW; | const eButType type_flip = UI_BTYPE_BUT | UI_BTYPE_ROW; | ||||
| if (ui_menu_pass_event_to_parent_if_nonactive(menu, but, level, retval)) | if (ui_menu_pass_event_to_parent_if_nonactive(menu, but, level, retval)) | ||||
| break; | break; | ||||
| #ifdef USE_KEYNAV_LIMIT | #ifdef USE_KEYNAV_LIMIT | ||||
| ui_mouse_motion_keynav_init(&menu->keynav_state, event); | ui_mouse_motion_keynav_init(&menu->keynav_state, event); | ||||
| #endif | #endif | ||||
| but = ui_but_find_activated(ar); | but = ui_but_find_active_in_region(ar); | ||||
| if (but) { | if (but) { | ||||
| /* is there a situation where UI_LEFT or UI_RIGHT would also change navigation direction? */ | /* is there a situation where UI_DIR_LEFT or UI_DIR_RIGHT would also change navigation direction? */ | ||||
| if (((ELEM(type, DOWNARROWKEY, WHEELDOWNMOUSE)) && (block->direction & UI_DOWN)) || | if (((ELEM(type, DOWNARROWKEY, WHEELDOWNMOUSE)) && (block->direction & UI_DIR_DOWN)) || | ||||
| ((ELEM(type, DOWNARROWKEY, WHEELDOWNMOUSE)) && (block->direction & UI_RIGHT)) || | ((ELEM(type, DOWNARROWKEY, WHEELDOWNMOUSE)) && (block->direction & UI_DIR_RIGHT)) || | ||||
| ((ELEM(type, UPARROWKEY, WHEELUPMOUSE)) && (block->direction & UI_TOP))) | ((ELEM(type, UPARROWKEY, WHEELUPMOUSE)) && (block->direction & UI_DIR_UP))) | ||||
| { | { | ||||
| /* the following is just a hack - uiBut->type set to BUT and BUTM have there menus built | /* the following is just a hack - uiBut->type set to UI_BTYPE_BUT and UI_BTYPE_BUT_MENU have there menus built | ||||
| * opposite ways - this should be changed so that all popup-menus use the same uiBlock->direction */ | * opposite ways - this should be changed so that all popup-menus use the same uiBlock->direction */ | ||||
| if (but->type & type_flip) | if (but->type & type_flip) | ||||
| but = ui_but_next(but); | but = ui_but_next(but); | ||||
| else | else | ||||
| but = ui_but_prev(but); | but = ui_but_prev(but); | ||||
| } | } | ||||
| else { | else { | ||||
| if (but->type & type_flip) | if (but->type & type_flip) | ||||
| but = ui_but_prev(but); | but = ui_but_prev(but); | ||||
| else | else | ||||
| but = ui_but_next(but); | but = ui_but_next(but); | ||||
| } | } | ||||
| if (but) { | if (but) { | ||||
| ui_handle_button_activate(C, ar, but, BUTTON_ACTIVATE); | ui_handle_button_activate(C, ar, but, BUTTON_ACTIVATE); | ||||
| ui_menu_scroll(ar, block, my, but); | ui_menu_scroll(ar, block, my, but); | ||||
| } | } | ||||
| } | } | ||||
| if (!but) { | if (!but) { | ||||
| if (((ELEM(type, UPARROWKEY, WHEELUPMOUSE)) && (block->direction & UI_DOWN)) || | if (((ELEM(type, UPARROWKEY, WHEELUPMOUSE)) && (block->direction & UI_DIR_DOWN)) || | ||||
| ((ELEM(type, UPARROWKEY, WHEELUPMOUSE)) && (block->direction & UI_RIGHT)) || | ((ELEM(type, UPARROWKEY, WHEELUPMOUSE)) && (block->direction & UI_DIR_RIGHT)) || | ||||
| ((ELEM(type, DOWNARROWKEY, WHEELDOWNMOUSE)) && (block->direction & UI_TOP))) | ((ELEM(type, DOWNARROWKEY, WHEELDOWNMOUSE)) && (block->direction & UI_DIR_UP))) | ||||
| { | { | ||||
| if ((bt = ui_but_first(block)) && (bt->type & type_flip)) { | if ((bt = ui_but_first(block)) && (bt->type & type_flip)) { | ||||
| bt = ui_but_last(block); | bt = ui_but_last(block); | ||||
| } | } | ||||
| else { | else { | ||||
| /* keep ui_but_first() */ | /* keep ui_but_first() */ | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | #endif | ||||
| break; | break; | ||||
| if (event->alt) act += 10; | if (event->alt) act += 10; | ||||
| count = 0; | count = 0; | ||||
| for (but = block->buttons.first; but; but = but->next) { | for (but = block->buttons.first; but; but = but->next) { | ||||
| bool doit = false; | bool doit = false; | ||||
| if (!ELEM(but->type, LABEL, SEPR, SEPRLINE)) | if (!ELEM(but->type, UI_BTYPE_LABEL, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE)) | ||||
| count++; | count++; | ||||
| /* exception for rna layer buts */ | /* exception for rna layer buts */ | ||||
| if (but->rnapoin.data && but->rnaprop && | if (but->rnapoin.data && but->rnaprop && | ||||
| ELEM(RNA_property_subtype(but->rnaprop), PROP_LAYER, PROP_LAYER_MEMBER)) | ELEM(RNA_property_subtype(but->rnaprop), PROP_LAYER, PROP_LAYER_MEMBER)) | ||||
| { | { | ||||
| if (but->rnaindex == act - 1) { | if (but->rnaindex == act - 1) { | ||||
| doit = true; | doit = true; | ||||
| } | } | ||||
| } | } | ||||
| else if (count == act) { | else if (count == act) { | ||||
| doit = true; | doit = true; | ||||
| } | } | ||||
| if (doit) { | if (doit) { | ||||
| /* activate buttons but open menu's */ | /* activate buttons but open menu's */ | ||||
| uiButtonActivateType activate; | uiButtonActivateType activate; | ||||
| if (but->type == PULLDOWN) { | if (but->type == UI_BTYPE_PULLDOWN) { | ||||
| activate = BUTTON_ACTIVATE_OPEN; | activate = BUTTON_ACTIVATE_OPEN; | ||||
| } | } | ||||
| else { | else { | ||||
| activate = BUTTON_ACTIVATE_APPLY; | activate = BUTTON_ACTIVATE_APPLY; | ||||
| } | } | ||||
| ui_handle_button_activate(C, ar, but, activate); | ui_handle_button_activate(C, ar, but, activate); | ||||
| break; | break; | ||||
| Show All 38 Lines | #endif | ||||
| (event->oskey == 0)) | (event->oskey == 0)) | ||||
| { | { | ||||
| if (ui_menu_pass_event_to_parent_if_nonactive(menu, but, level, retval)) | if (ui_menu_pass_event_to_parent_if_nonactive(menu, but, level, retval)) | ||||
| break; | break; | ||||
| for (but = block->buttons.first; but; but = but->next) { | for (but = block->buttons.first; but; but = but->next) { | ||||
| if (but->menu_key == event->type) { | if (but->menu_key == event->type) { | ||||
| if (ELEM(but->type, BUT, BUTM)) { | if (ELEM(but->type, UI_BTYPE_BUT, UI_BTYPE_BUT_MENU)) { | ||||
| /* mainly for operator buttons */ | /* mainly for operator buttons */ | ||||
| ui_handle_button_activate(C, ar, but, BUTTON_ACTIVATE_APPLY); | ui_handle_button_activate(C, ar, but, BUTTON_ACTIVATE_APPLY); | ||||
| } | } | ||||
| else if (ELEM(but->type, BLOCK, PULLDOWN)) { | else if (ELEM(but->type, UI_BTYPE_BLOCK, UI_BTYPE_PULLDOWN)) { | ||||
| /* open submenus (like right arrow key) */ | /* open submenus (like right arrow key) */ | ||||
| ui_handle_button_activate(C, ar, but, BUTTON_ACTIVATE_OPEN); | ui_handle_button_activate(C, ar, but, BUTTON_ACTIVATE_OPEN); | ||||
| } | } | ||||
| else if (but->type == MENU) { | else if (but->type == UI_BTYPE_MENU) { | ||||
| /* activate menu items */ | /* activate menu items */ | ||||
| ui_handle_button_activate(C, ar, but, BUTTON_ACTIVATE); | ui_handle_button_activate(C, ar, but, BUTTON_ACTIVATE); | ||||
| } | } | ||||
| else { | else { | ||||
| printf("%s: error, but->menu_key type: %d\n", __func__, but->type); | printf("%s: error, but->menu_key type: %d\n", __func__, but->type); | ||||
| } | } | ||||
| break; | break; | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | |||||
| #endif | #endif | ||||
| else if (event->type == ESCKEY && event->val == KM_PRESS) { | else if (event->type == ESCKEY && event->val == KM_PRESS) { | ||||
| /* esc cancels this and all preceding menus */ | /* esc cancels this and all preceding menus */ | ||||
| menu->menuretval = UI_RETURN_CANCEL; | menu->menuretval = UI_RETURN_CANCEL; | ||||
| } | } | ||||
| else if (ELEM(event->type, RETKEY, PADENTER) && event->val == KM_PRESS) { | else if (ELEM(event->type, RETKEY, PADENTER) && event->val == KM_PRESS) { | ||||
| /* enter will always close this block, we let the event | /* enter will always close this block, we let the event | ||||
| * get handled by the button if it is activated, otherwise we cancel */ | * get handled by the button if it is activated, otherwise we cancel */ | ||||
| if (!ui_but_find_activated(ar)) | if (!ui_but_find_active_in_region(ar)) | ||||
| menu->menuretval = UI_RETURN_CANCEL | UI_RETURN_POPUP_OK; | menu->menuretval = UI_RETURN_CANCEL | UI_RETURN_POPUP_OK; | ||||
| } | } | ||||
| #ifdef USE_DRAG_POPUP | #ifdef USE_DRAG_POPUP | ||||
| else if ((event->type == LEFTMOUSE) && (event->val == KM_PRESS) && | else if ((event->type == LEFTMOUSE) && (event->val == KM_PRESS) && | ||||
| (inside && is_floating && inside_title)) | (inside && is_floating && inside_title)) | ||||
| { | { | ||||
| if (!but || !ui_mouse_inside_button(ar, but, event->x, event->y)) { | if (!but || !ui_but_contains_point_px(ar, but, event->x, event->y)) { | ||||
| if (but) { | if (but) { | ||||
| button_timers_tooltip_remove(C, but); | button_timers_tooltip_remove(C, but); | ||||
| } | } | ||||
| menu->is_grab = true; | menu->is_grab = true; | ||||
| copy_v2_v2_int(menu->grab_xy_prev, &event->x); | copy_v2_v2_int(menu->grab_xy_prev, &event->x); | ||||
| retval = WM_UI_HANDLER_BREAK; | retval = WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | static int ui_handle_menu_return_submenu(bContext *C, const wmEvent *event, uiPopupBlockHandle *menu) | ||||
| uiBut *but; | uiBut *but; | ||||
| uiBlock *block; | uiBlock *block; | ||||
| uiHandleButtonData *data; | uiHandleButtonData *data; | ||||
| uiPopupBlockHandle *submenu; | uiPopupBlockHandle *submenu; | ||||
| ar = menu->region; | ar = menu->region; | ||||
| block = ar->uiblocks.first; | block = ar->uiblocks.first; | ||||
| but = ui_but_find_activated(ar); | but = ui_but_find_active_in_region(ar); | ||||
| data = but->active; | data = but->active; | ||||
| submenu = data->menu; | submenu = data->menu; | ||||
| if (submenu->menuretval) { | if (submenu->menuretval) { | ||||
| bool update; | bool update; | ||||
| /* first decide if we want to close our own menu cascading, if | /* first decide if we want to close our own menu cascading, if | ||||
| * so pass on the sub menu return value to our own menu handle */ | * so pass on the sub menu return value to our own menu handle */ | ||||
| Show All 25 Lines | static int ui_handle_menu_return_submenu(bContext *C, const wmEvent *event, uiPopupBlockHandle *menu) | ||||
| } | } | ||||
| else { | else { | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| } | } | ||||
| static bool ui_but_pie_menu_supported_apply(uiBut *but) | static bool ui_but_pie_menu_supported_apply(uiBut *but) | ||||
| { | { | ||||
| return (!ELEM(but->type, NUMSLI, NUM)); | return (!ELEM(but->type, UI_BTYPE_NUM_SLIDER, UI_BTYPE_NUM)); | ||||
| } | } | ||||
| static int ui_but_pie_menu_apply(bContext *C, uiPopupBlockHandle *menu, uiBut *but, bool force_close) | static int ui_but_pie_menu_apply(bContext *C, uiPopupBlockHandle *menu, uiBut *but, bool force_close) | ||||
| { | { | ||||
| int retval = WM_UI_HANDLER_BREAK; | int retval = WM_UI_HANDLER_BREAK; | ||||
| if (but && ui_but_pie_menu_supported_apply(but)) { | if (but && ui_but_pie_menu_supported_apply(but)) { | ||||
| if (but->type == MENU) { | if (but->type == UI_BTYPE_MENU) { | ||||
| /* forcing the pie menu to close will not handle menus */ | /* forcing the pie menu to close will not handle menus */ | ||||
| if (!force_close) { | if (!force_close) { | ||||
| uiBut *active_but = ui_but_find_activated(menu->region); | uiBut *active_but = ui_but_find_active_in_region(menu->region); | ||||
| if (active_but) { | if (active_but) { | ||||
| button_activate_exit(C, active_but, active_but->active, false, false); | button_activate_exit(C, active_but, active_but->active, false, false); | ||||
| } | } | ||||
| button_activate_init(C, menu->region, but, BUTTON_ACTIVATE_OPEN); | button_activate_init(C, menu->region, but, BUTTON_ACTIVATE_OPEN); | ||||
| return retval; | return retval; | ||||
| } | } | ||||
| else { | else { | ||||
| menu->menuretval = UI_RETURN_CANCEL; | menu->menuretval = UI_RETURN_CANCEL; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| ui_apply_button(C, but->block, but, but->active, false); | ui_apply_but(C, but->block, but, but->active, false); | ||||
| button_activate_exit((bContext *)C, but, but->active, false, true); | button_activate_exit((bContext *)C, but, but->active, false, true); | ||||
| menu->menuretval = UI_RETURN_OK; | menu->menuretval = UI_RETURN_OK; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| menu->menuretval = UI_RETURN_CANCEL; | menu->menuretval = UI_RETURN_CANCEL; | ||||
| ED_region_tag_redraw(menu->region); | ED_region_tag_redraw(menu->region); | ||||
| } | } | ||||
| return retval; | return retval; | ||||
| } | } | ||||
| static uiBut *ui_block_pie_dir_activate(uiBlock *block, const wmEvent *event, RadialDirection dir) | static uiBut *ui_block_pie_dir_activate(uiBlock *block, const wmEvent *event, RadialDirection dir) | ||||
| { | { | ||||
| uiBut *but; | uiBut *but; | ||||
| if ((block->flag & UI_BLOCK_NUMSELECT) && event->val == KM_PRESS) { | if ((block->flag & UI_BLOCK_NUMSELECT) && event->val == KM_PRESS) { | ||||
| for (but = block->buttons.first; but; but = but->next) { | for (but = block->buttons.first; but; but = but->next) { | ||||
| if (but->pie_dir == dir && !ELEM(but->type, SEPR, SEPRLINE)) { | if (but->pie_dir == dir && !ELEM(but->type, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE)) { | ||||
| return but; | return but; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| static int ui_but_pie_button_activate(bContext *C, uiBut *but, uiPopupBlockHandle *menu) | static int ui_but_pie_button_activate(bContext *C, uiBut *but, uiPopupBlockHandle *menu) | ||||
| { | { | ||||
| uiBut *active_but; | uiBut *active_but; | ||||
| if (but == NULL) | if (but == NULL) | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| active_but = ui_but_find_activated(menu->region); | active_but = ui_but_find_active_in_region(menu->region); | ||||
| if (active_but) | if (active_but) | ||||
| button_activate_exit(C, active_but, active_but->active, false, false); | button_activate_exit(C, active_but, active_but->active, false, false); | ||||
| button_activate_init(C, menu->region, but, BUTTON_ACTIVATE_OVER); | button_activate_init(C, menu->region, but, BUTTON_ACTIVATE_OVER); | ||||
| return ui_but_pie_menu_apply(C, menu, but, false); | return ui_but_pie_menu_apply(C, menu, but, false); | ||||
| } | } | ||||
| static int ui_handler_pie(bContext *C, const wmEvent *event, uiPopupBlockHandle *menu) | static int ui_pie_handler(bContext *C, const wmEvent *event, uiPopupBlockHandle *menu) | ||||
| { | { | ||||
| ARegion *ar; | ARegion *ar; | ||||
| uiBlock *block; | uiBlock *block; | ||||
| uiBut *but; | uiBut *but; | ||||
| float event_xy[2]; | float event_xy[2]; | ||||
| double duration; | double duration; | ||||
| bool is_click_style; | bool is_click_style; | ||||
| float dist; | float dist; | ||||
| Show All 20 Lines | static int ui_pie_handler(bContext *C, const wmEvent *event, uiPopupBlockHandle *menu) | ||||
| duration = menu->scrolltimer->duration; | duration = menu->scrolltimer->duration; | ||||
| event_xy[0] = event->x; | event_xy[0] = event->x; | ||||
| event_xy[1] = event->y; | event_xy[1] = event->y; | ||||
| ui_window_to_block_fl(ar, block, &event_xy[0], &event_xy[1]); | ui_window_to_block_fl(ar, block, &event_xy[0], &event_xy[1]); | ||||
| dist = ui_block_calculate_pie_segment(block, event_xy); | dist = ui_block_calc_pie_segment(block, event_xy); | ||||
| if (event->type == TIMER) { | if (event->type == TIMER) { | ||||
| if (event->customdata == menu->scrolltimer) { | if (event->customdata == menu->scrolltimer) { | ||||
| /* deactivate initial direction after a while */ | /* deactivate initial direction after a while */ | ||||
| if (duration > 0.01 * U.pie_initial_timeout) { | if (duration > 0.01 * U.pie_initial_timeout) { | ||||
| block->pie_data.flags &= ~UI_PIE_INITIAL_DIRECTION; | block->pie_data.flags &= ~UI_PIE_INITIAL_DIRECTION; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | if (block->pie_data.flags & UI_PIE_GESTURE_END_WAIT) { | ||||
| /* use a time threshold to ensure we leave time to the mouse to move */ | /* use a time threshold to ensure we leave time to the mouse to move */ | ||||
| if (duration - block->pie_data.duration_gesture > 0.02) { | if (duration - block->pie_data.duration_gesture > 0.02) { | ||||
| len_sq = len_squared_v2v2(event_xy, block->pie_data.last_pos); | len_sq = len_squared_v2v2(event_xy, block->pie_data.last_pos); | ||||
| copy_v2_v2(block->pie_data.last_pos, event_xy); | copy_v2_v2(block->pie_data.last_pos, event_xy); | ||||
| block->pie_data.duration_gesture = duration; | block->pie_data.duration_gesture = duration; | ||||
| } | } | ||||
| if (len_sq < 1.0) { | if (len_sq < 1.0) { | ||||
| uiBut *but = ui_but_find_activated(menu->region); | uiBut *but = ui_but_find_active_in_region(menu->region); | ||||
| if (but) { | if (but) { | ||||
| return ui_but_pie_menu_apply(C, menu, but, true); | return ui_but_pie_menu_apply(C, menu, but, true); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 9 Lines | if (event->val != KM_RELEASE) { | ||||
| ED_region_tag_redraw(ar); | ED_region_tag_redraw(ar); | ||||
| } | } | ||||
| else { | else { | ||||
| /* distance from initial point */ | /* distance from initial point */ | ||||
| if (!(block->pie_data.flags & UI_PIE_DRAG_STYLE)) { | if (!(block->pie_data.flags & UI_PIE_DRAG_STYLE)) { | ||||
| block->pie_data.flags |= UI_PIE_CLICK_STYLE; | block->pie_data.flags |= UI_PIE_CLICK_STYLE; | ||||
| } | } | ||||
| else { | else { | ||||
| uiBut *but = ui_but_find_activated(menu->region); | uiBut *but = ui_but_find_active_in_region(menu->region); | ||||
| if (but && (U.pie_menu_confirm > 0) && | if (but && (U.pie_menu_confirm > 0) && | ||||
| (dist >= U.pie_menu_threshold + U.pie_menu_confirm)) | (dist >= U.pie_menu_threshold + U.pie_menu_confirm)) | ||||
| { | { | ||||
| if (but) | if (but) | ||||
| return ui_but_pie_menu_apply(C, menu, but, true); | return ui_but_pie_menu_apply(C, menu, but, true); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| uiBut *but; | uiBut *but; | ||||
| uiHandleButtonData *data; | uiHandleButtonData *data; | ||||
| uiPopupBlockHandle *submenu; | uiPopupBlockHandle *submenu; | ||||
| int retval = WM_UI_HANDLER_CONTINUE; | int retval = WM_UI_HANDLER_CONTINUE; | ||||
| bool do_towards_reinit = false; | bool do_towards_reinit = false; | ||||
| /* check if we have a submenu, and handle events for it first */ | /* check if we have a submenu, and handle events for it first */ | ||||
| but = ui_but_find_activated(menu->region); | but = ui_but_find_active_in_region(menu->region); | ||||
| data = (but) ? but->active : NULL; | data = (but) ? but->active : NULL; | ||||
| submenu = (data) ? data->menu : NULL; | submenu = (data) ? data->menu : NULL; | ||||
| if (submenu) { | if (submenu) { | ||||
| uiBlock *block = menu->region->uiblocks.first; | uiBlock *block = menu->region->uiblocks.first; | ||||
| const bool is_menu = ui_block_is_menu(block); | const bool is_menu = ui_block_is_menu(block); | ||||
| bool inside = false; | bool inside = false; | ||||
| /* root pie menus accept the key that spawned them as double click to improve responsiveness */ | /* root pie menus accept the key that spawned them as double click to improve responsiveness */ | ||||
| Show All 10 Lines | if (do_recursion) { | ||||
| } | } | ||||
| retval = ui_handle_menus_recursive(C, event, submenu, level + 1, is_parent_inside || inside, is_menu, false); | retval = ui_handle_menus_recursive(C, event, submenu, level + 1, is_parent_inside || inside, is_menu, false); | ||||
| } | } | ||||
| } | } | ||||
| /* now handle events for our own menu */ | /* now handle events for our own menu */ | ||||
| if (retval == WM_UI_HANDLER_CONTINUE || event->type == TIMER) { | if (retval == WM_UI_HANDLER_CONTINUE || event->type == TIMER) { | ||||
| const bool do_but_search = (but && ELEM(but->type, SEARCH_MENU, SEARCH_MENU_UNLINK)); | const bool do_but_search = (but && ELEM(but->type, UI_BTYPE_SEARCH_MENU, UI_BTYPE_SEARCH_MENU_UNLINK)); | ||||
| if (submenu && submenu->menuretval) { | if (submenu && submenu->menuretval) { | ||||
| const bool do_ret_out_parent = (submenu->menuretval & UI_RETURN_OUT_PARENT) != 0; | const bool do_ret_out_parent = (submenu->menuretval & UI_RETURN_OUT_PARENT) != 0; | ||||
| retval = ui_handle_menu_return_submenu(C, event, menu); | retval = ui_handle_menu_return_submenu(C, event, menu); | ||||
| submenu = NULL; /* hint not to use this, it may be freed by call above */ | submenu = NULL; /* hint not to use this, it may be freed by call above */ | ||||
| (void)submenu; | (void)submenu; | ||||
| /* we may want to quit the submenu and handle the even in this menu, | /* we may want to quit the submenu and handle the even in this menu, | ||||
| * if its important to use it, check 'data->menu' first */ | * if its important to use it, check 'data->menu' first */ | ||||
| if (((retval == WM_UI_HANDLER_BREAK) && do_ret_out_parent) == 0) { | if (((retval == WM_UI_HANDLER_BREAK) && do_ret_out_parent) == 0) { | ||||
| /* skip applying the event */ | /* skip applying the event */ | ||||
| return retval; | return retval; | ||||
| } | } | ||||
| } | } | ||||
| if (do_but_search) { | if (do_but_search) { | ||||
| uiBlock *block = menu->region->uiblocks.first; | uiBlock *block = menu->region->uiblocks.first; | ||||
| retval = ui_handle_menu_button(C, event, menu); | retval = ui_handle_menu_button(C, event, menu); | ||||
| if (block->flag & UI_BLOCK_MOVEMOUSE_QUIT) { | if (block->flag & UI_BLOCK_MOVEMOUSE_QUIT) { | ||||
| /* when there is a active search button and we close it, | /* when there is a active search button and we close it, | ||||
| * we need to reinit the mouse coords [#35346] */ | * we need to reinit the mouse coords [#35346] */ | ||||
| if (ui_but_find_activated(menu->region) != but) { | if (ui_but_find_active_in_region(menu->region) != but) { | ||||
| do_towards_reinit = true; | do_towards_reinit = true; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| uiBlock *block = menu->region->uiblocks.first; | uiBlock *block = menu->region->uiblocks.first; | ||||
| if (block->flag & UI_BLOCK_RADIAL) | if (block->flag & UI_BLOCK_RADIAL) | ||||
| retval = ui_handler_pie(C, event, menu); | retval = ui_pie_handler(C, event, menu); | ||||
| else if (event->type == LEFTMOUSE || event->val != KM_DBL_CLICK) | else if (event->type == LEFTMOUSE || event->val != KM_DBL_CLICK) | ||||
| retval = ui_handle_menu_event(C, event, menu, level, is_parent_inside, is_parent_menu, is_floating); | retval = ui_handle_menu_event(C, event, menu, level, is_parent_inside, is_parent_menu, is_floating); | ||||
| } | } | ||||
| } | } | ||||
| if (do_towards_reinit) { | if (do_towards_reinit) { | ||||
| ui_mouse_motion_towards_reinit(menu, &event->x); | ui_mouse_motion_towards_reinit(menu, &event->x); | ||||
| } | } | ||||
| return retval; | return retval; | ||||
| } | } | ||||
| /* *************** UI event handlers **************** */ | /* *************** UI event handlers **************** */ | ||||
| static int ui_handler_region(bContext *C, const wmEvent *event, void *UNUSED(userdata)) | static int ui_region_handler(bContext *C, const wmEvent *event, void *UNUSED(userdata)) | ||||
| { | { | ||||
| ARegion *ar; | ARegion *ar; | ||||
| uiBut *but; | uiBut *but; | ||||
| int retval; | int retval; | ||||
| /* here we handle buttons at the region level, non-modal */ | /* here we handle buttons at the region level, non-modal */ | ||||
| ar = CTX_wm_region(C); | ar = CTX_wm_region(C); | ||||
| retval = WM_UI_HANDLER_CONTINUE; | retval = WM_UI_HANDLER_CONTINUE; | ||||
| if (ar == NULL || BLI_listbase_is_empty(&ar->uiblocks)) { | if (ar == NULL || BLI_listbase_is_empty(&ar->uiblocks)) { | ||||
| return retval; | return retval; | ||||
| } | } | ||||
| /* either handle events for already activated button or try to activate */ | /* either handle events for already activated button or try to activate */ | ||||
| but = ui_but_find_activated(ar); | but = ui_but_find_active_in_region(ar); | ||||
| retval = ui_handler_panel_region(C, event, ar); | retval = ui_handler_panel_region(C, event, ar); | ||||
| if (retval == WM_UI_HANDLER_CONTINUE) | if (retval == WM_UI_HANDLER_CONTINUE) | ||||
| retval = ui_handle_list_event(C, event, ar); | retval = ui_handle_list_event(C, event, ar); | ||||
| if (retval == WM_UI_HANDLER_CONTINUE) { | if (retval == WM_UI_HANDLER_CONTINUE) { | ||||
| if (but) | if (but) | ||||
| retval = ui_handle_button_event(C, event, but); | retval = ui_handle_button_event(C, event, but); | ||||
| else | else | ||||
| retval = ui_handle_button_over(C, event, ar); | retval = ui_handle_button_over(C, event, ar); | ||||
| } | } | ||||
| /* re-enable tooltips */ | /* re-enable tooltips */ | ||||
| if (event->type == MOUSEMOVE && (event->x != event->prevx || event->y != event->prevy)) | if (event->type == MOUSEMOVE && (event->x != event->prevx || event->y != event->prevy)) | ||||
| ui_blocks_set_tooltips(ar, true); | ui_blocks_set_tooltips(ar, true); | ||||
| /* delayed apply callbacks */ | /* delayed apply callbacks */ | ||||
| ui_apply_but_funcs_after(C); | ui_apply_but_funcs_after(C); | ||||
| return retval; | return retval; | ||||
| } | } | ||||
| static void ui_handler_remove_region(bContext *C, void *UNUSED(userdata)) | static void ui_region_handler_remove(bContext *C, void *UNUSED(userdata)) | ||||
| { | { | ||||
| bScreen *sc; | bScreen *sc; | ||||
| ARegion *ar; | ARegion *ar; | ||||
| ar = CTX_wm_region(C); | ar = CTX_wm_region(C); | ||||
| if (ar == NULL) return; | if (ar == NULL) return; | ||||
| uiFreeBlocks(C, &ar->uiblocks); | UI_blocklist_free(C, &ar->uiblocks); | ||||
| sc = CTX_wm_screen(C); | sc = CTX_wm_screen(C); | ||||
| if (sc == NULL) return; | if (sc == NULL) return; | ||||
| /* delayed apply callbacks, but not for screen level regions, those | /* delayed apply callbacks, but not for screen level regions, those | ||||
| * we rather do at the very end after closing them all, which will | * we rather do at the very end after closing them all, which will | ||||
| * be done in ui_handler_region/window */ | * be done in ui_region_handler/window */ | ||||
| if (BLI_findindex(&sc->regionbase, ar) == -1) | if (BLI_findindex(&sc->regionbase, ar) == -1) | ||||
| ui_apply_but_funcs_after(C); | ui_apply_but_funcs_after(C); | ||||
| } | } | ||||
| static int ui_handler_region_menu(bContext *C, const wmEvent *event, void *UNUSED(userdata)) | static int ui_handler_region_menu(bContext *C, const wmEvent *event, void *UNUSED(userdata)) | ||||
| { | { | ||||
| ARegion *ar; | ARegion *ar; | ||||
| uiBut *but; | uiBut *but; | ||||
| /* here we handle buttons at the window level, modal, for example | /* here we handle buttons at the window level, modal, for example | ||||
| * while number sliding, text editing, or when a menu block is open */ | * while number sliding, text editing, or when a menu block is open */ | ||||
| ar = CTX_wm_menu(C); | ar = CTX_wm_menu(C); | ||||
| if (!ar) | if (!ar) | ||||
| ar = CTX_wm_region(C); | ar = CTX_wm_region(C); | ||||
| but = ui_but_find_activated(ar); | but = ui_but_find_active_in_region(ar); | ||||
| if (but) { | if (but) { | ||||
| uiBut *but_other; | uiBut *but_other; | ||||
| uiHandleButtonData *data; | uiHandleButtonData *data; | ||||
| /* handle activated button events */ | /* handle activated button events */ | ||||
| data = but->active; | data = but->active; | ||||
| if ((data->state == BUTTON_STATE_MENU_OPEN) && | if ((data->state == BUTTON_STATE_MENU_OPEN) && | ||||
| (but->type == PULLDOWN) && | (but->type == UI_BTYPE_PULLDOWN) && | ||||
| (but_other = ui_but_find_mouse_over(ar, event)) && | (but_other = ui_but_find_mouse_over(ar, event)) && | ||||
| (but != but_other) && | (but != but_other) && | ||||
| (but->type == but_other->type)) | (but->type == but_other->type)) | ||||
| { | { | ||||
| /* if mouse moves to a different root-level menu button, | /* if mouse moves to a different root-level menu button, | ||||
| * open it to replace the current menu */ | * open it to replace the current menu */ | ||||
| ui_handle_button_activate(C, ar, but_other, BUTTON_ACTIVATE_OVER); | ui_handle_button_activate(C, ar, but_other, BUTTON_ACTIVATE_OVER); | ||||
| button_activate_state(C, but_other, BUTTON_STATE_MENU_OPEN); | button_activate_state(C, but_other, BUTTON_STATE_MENU_OPEN); | ||||
| Show All 29 Lines | static int ui_handler_region_menu(bContext *C, const wmEvent *event, void *UNUSED(userdata)) | ||||
| /* delayed apply callbacks */ | /* delayed apply callbacks */ | ||||
| ui_apply_but_funcs_after(C); | ui_apply_but_funcs_after(C); | ||||
| /* we block all events, this is modal interaction */ | /* we block all events, this is modal interaction */ | ||||
| return WM_UI_HANDLER_BREAK; | return WM_UI_HANDLER_BREAK; | ||||
| } | } | ||||
| /* two types of popups, one with operator + enum, other with regular callbacks */ | /* two types of popups, one with operator + enum, other with regular callbacks */ | ||||
| static int ui_handler_popup(bContext *C, const wmEvent *event, void *userdata) | static int ui_popup_handler(bContext *C, const wmEvent *event, void *userdata) | ||||
| { | { | ||||
| uiPopupBlockHandle *menu = userdata; | uiPopupBlockHandle *menu = userdata; | ||||
| struct ARegion *menu_region; | struct ARegion *menu_region; | ||||
| /* we block all events, this is modal interaction, except for drop events which is described below */ | /* we block all events, this is modal interaction, except for drop events which is described below */ | ||||
| int retval = WM_UI_HANDLER_BREAK; | int retval = WM_UI_HANDLER_BREAK; | ||||
| bool reset_pie = false; | bool reset_pie = false; | ||||
| menu_region = CTX_wm_menu(C); | menu_region = CTX_wm_menu(C); | ||||
| Show All 19 Lines | if (menu->menuretval) { | ||||
| /* set last pie event to allow chained pie spawning */ | /* set last pie event to allow chained pie spawning */ | ||||
| if (block->flag & UI_BLOCK_RADIAL) { | if (block->flag & UI_BLOCK_RADIAL) { | ||||
| win->last_pie_event = block->pie_data.event; | win->last_pie_event = block->pie_data.event; | ||||
| reset_pie = true; | reset_pie = true; | ||||
| } | } | ||||
| ui_popup_block_free(C, menu); | ui_popup_block_free(C, menu); | ||||
| UI_remove_popup_handlers(&win->modalhandlers, menu); | UI_popup_handlers_remove(&win->modalhandlers, menu); | ||||
| #ifdef USE_DRAG_TOGGLE | #ifdef USE_DRAG_TOGGLE | ||||
| { | { | ||||
| WM_event_free_ui_handler_all(C, &win->modalhandlers, | WM_event_free_ui_handler_all(C, &win->modalhandlers, | ||||
| ui_handler_region_drag_toggle, ui_handler_region_drag_toggle_remove); | ui_handler_region_drag_toggle, ui_handler_region_drag_toggle_remove); | ||||
| } | } | ||||
| #endif | #endif | ||||
| Show All 25 Lines | if (win) | ||||
| win->last_pie_event = EVENT_NONE; | win->last_pie_event = EVENT_NONE; | ||||
| } | } | ||||
| CTX_wm_region_set(C, menu_region); | CTX_wm_region_set(C, menu_region); | ||||
| return retval; | return retval; | ||||
| } | } | ||||
| static void ui_handler_remove_popup(bContext *C, void *userdata) | static void ui_popup_handler_remove(bContext *C, void *userdata) | ||||
| { | { | ||||
| uiPopupBlockHandle *menu = userdata; | uiPopupBlockHandle *menu = userdata; | ||||
| /* free menu block if window is closed for some reason */ | /* free menu block if window is closed for some reason */ | ||||
| ui_popup_block_free(C, menu); | ui_popup_block_free(C, menu); | ||||
| /* delayed apply callbacks */ | /* delayed apply callbacks */ | ||||
| ui_apply_but_funcs_after(C); | ui_apply_but_funcs_after(C); | ||||
| } | } | ||||
| void UI_add_region_handlers(ListBase *handlers) | void UI_region_handlers_add(ListBase *handlers) | ||||
| { | { | ||||
| WM_event_remove_ui_handler(handlers, ui_handler_region, ui_handler_remove_region, NULL, false); | WM_event_remove_ui_handler(handlers, ui_region_handler, ui_region_handler_remove, NULL, false); | ||||
| WM_event_add_ui_handler(NULL, handlers, ui_handler_region, ui_handler_remove_region, NULL, false); | WM_event_add_ui_handler(NULL, handlers, ui_region_handler, ui_region_handler_remove, NULL, false); | ||||
| } | } | ||||
| void UI_add_popup_handlers(bContext *C, ListBase *handlers, uiPopupBlockHandle *popup, const bool accept_dbl_click) | void UI_popup_handlers_add(bContext *C, ListBase *handlers, uiPopupBlockHandle *popup, const bool accept_dbl_click) | ||||
| { | { | ||||
| WM_event_add_ui_handler(C, handlers, ui_handler_popup, ui_handler_remove_popup, popup, accept_dbl_click); | WM_event_add_ui_handler(C, handlers, ui_popup_handler, ui_popup_handler_remove, popup, accept_dbl_click); | ||||
| } | } | ||||
| void UI_remove_popup_handlers(ListBase *handlers, uiPopupBlockHandle *popup) | void UI_popup_handlers_remove(ListBase *handlers, uiPopupBlockHandle *popup) | ||||
| { | { | ||||
| WM_event_remove_ui_handler(handlers, ui_handler_popup, ui_handler_remove_popup, popup, false); | WM_event_remove_ui_handler(handlers, ui_popup_handler, ui_popup_handler_remove, popup, false); | ||||
| } | } | ||||
| void UI_remove_popup_handlers_all(bContext *C, ListBase *handlers) | void UI_popup_handlers_remove_all(bContext *C, ListBase *handlers) | ||||
| { | { | ||||
| WM_event_free_ui_handler_all(C, handlers, ui_handler_popup, ui_handler_remove_popup); | WM_event_free_ui_handler_all(C, handlers, ui_popup_handler, ui_popup_handler_remove); | ||||
| } | } | ||||
| bool UI_textbutton_activate_rna(const bContext *C, ARegion *ar, | bool UI_textbutton_activate_rna(const bContext *C, ARegion *ar, | ||||
| const void *rna_poin_data, const char *rna_prop_id) | const void *rna_poin_data, const char *rna_prop_id) | ||||
| { | { | ||||
| uiBlock *block; | uiBlock *block; | ||||
| uiBut *but = NULL; | uiBut *but = NULL; | ||||
| for (block = ar->uiblocks.first; block; block = block->next) { | for (block = ar->uiblocks.first; block; block = block->next) { | ||||
| for (but = block->buttons.first; but; but = but->next) { | for (but = block->buttons.first; but; but = but->next) { | ||||
| if (but->type == TEX) { | if (but->type == UI_BTYPE_TEXT) { | ||||
| if (but->rnaprop && but->rnapoin.data == rna_poin_data) { | if (but->rnaprop && but->rnapoin.data == rna_poin_data) { | ||||
| if (STREQ(RNA_property_identifier(but->rnaprop), rna_prop_id)) { | if (STREQ(RNA_property_identifier(but->rnaprop), rna_prop_id)) { | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (but) | if (but) | ||||
| break; | break; | ||||
| } | } | ||||
| if (but) { | if (but) { | ||||
| uiButActiveOnly(C, ar, block, but); | UI_but_active_only(C, ar, block, but); | ||||
| return true; | return true; | ||||
| } | } | ||||
| else { | else { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| bool UI_textbutton_activate_but(const bContext *C, uiBut *actbut) | bool UI_textbutton_activate_but(const bContext *C, uiBut *actbut) | ||||
| { | { | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| uiBlock *block; | uiBlock *block; | ||||
| uiBut *but = NULL; | uiBut *but = NULL; | ||||
| for (block = ar->uiblocks.first; block; block = block->next) { | for (block = ar->uiblocks.first; block; block = block->next) { | ||||
| for (but = block->buttons.first; but; but = but->next) | for (but = block->buttons.first; but; but = but->next) | ||||
| if (but == actbut && but->type == TEX) | if (but == actbut && but->type == UI_BTYPE_TEXT) | ||||
| break; | break; | ||||
| if (but) | if (but) | ||||
| break; | break; | ||||
| } | } | ||||
| if (but) { | if (but) { | ||||
| uiButActiveOnly(C, ar, block, but); | UI_but_active_only(C, ar, block, but); | ||||
| return true; | return true; | ||||
| } | } | ||||
| else { | else { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| void ui_button_clipboard_free(void) | void ui_but_clipboard_free(void) | ||||
| { | { | ||||
| curvemapping_free_data(&but_copypaste_curve); | curvemapping_free_data(&but_copypaste_curve); | ||||
| } | } | ||||