diff options
Diffstat (limited to 'source/blender/editors/interface/interface_handlers.c')
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 214 |
1 files changed, 137 insertions, 77 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index bcb4f7c672f..455c4fd5073 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -767,11 +767,12 @@ static void ui_apply_but_func(bContext *C, uiBut *but) after->rnapoin = but->rnapoin; after->rnaprop = but->rnaprop; - if (but->search != NULL) { - after->search_arg_free_fn = but->search->arg_free_fn; - after->search_arg = but->search->arg; - but->search->arg_free_fn = NULL; - but->search->arg = NULL; + if (but->type == UI_BTYPE_SEARCH_MENU) { + uiButSearch *search_but = (uiButSearch *)but; + after->search_arg_free_fn = search_but->arg_free_fn; + after->search_arg = search_but->arg; + search_but->arg_free_fn = NULL; + search_but->arg = NULL; } if (but->context) { @@ -1047,8 +1048,19 @@ static void ui_apply_but_TEX(bContext *C, uiBut *but, uiHandleButtonData *data) but->rename_orig = data->origstr; data->origstr = NULL; } + + void *orig_arg2 = but->func_arg2; + + /* If arg2 isn't in use already, pass the active search item through it. */ + if ((but->func_arg2 == NULL) && (but->type == UI_BTYPE_SEARCH_MENU)) { + uiButSearch *search_but = (uiButSearch *)but; + but->func_arg2 = search_but->item_active; + } + ui_apply_but_func(C, but); + but->func_arg2 = orig_arg2; + data->retval = but->retval; data->applied = true; } @@ -2013,6 +2025,8 @@ static void ui_apply_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonDat static void ui_apply_but( bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const bool interactive) { + const int but_type = but->type; /* Store as const to quiet maybe uninitialized warning. */ + char *editstr; double *editval; float *editvec; @@ -2074,19 +2088,38 @@ static void ui_apply_but( editstr = but->editstr; editval = but->editval; editvec = but->editvec; - editcoba = but->editcoba; - editcumap = but->editcumap; - editprofile = but->editprofile; + if (but_type == UI_BTYPE_COLORBAND) { + uiButColorBand *but_coba = (uiButColorBand *)but; + editcoba = but_coba->edit_coba; + } + else if (but_type == UI_BTYPE_CURVE) { + uiButCurveMapping *but_cumap = (uiButCurveMapping *)but; + editcumap = but_cumap->edit_cumap; + } + else if (but_type == UI_BTYPE_CURVEPROFILE) { + uiButCurveProfile *but_profile = (uiButCurveProfile *)but; + editprofile = but_profile->edit_profile; + } but->editstr = NULL; but->editval = NULL; but->editvec = NULL; - but->editcoba = NULL; - but->editcumap = NULL; - but->editprofile = NULL; + if (but_type == UI_BTYPE_COLORBAND) { + uiButColorBand *but_coba = (uiButColorBand *)but; + but_coba->edit_coba = NULL; + } + else if (but_type == UI_BTYPE_CURVE) { + uiButCurveMapping *but_cumap = (uiButCurveMapping *)but; + but_cumap->edit_cumap = NULL; + } + else if (but_type == UI_BTYPE_CURVEPROFILE) { + uiButCurveProfile *but_profile = (uiButCurveProfile *)but; + but_profile->edit_profile = NULL; + } /* handle different types */ - switch (but->type) { + switch (but_type) { case UI_BTYPE_BUT: + case UI_BTYPE_DECORATOR: ui_apply_but_BUT(C, but, data); break; case UI_BTYPE_TEXT: @@ -2190,9 +2223,18 @@ static void ui_apply_but( but->editstr = editstr; but->editval = editval; but->editvec = editvec; - but->editcoba = editcoba; - but->editcumap = editcumap; - but->editprofile = editprofile; + if (but_type == UI_BTYPE_COLORBAND) { + uiButColorBand *but_coba = (uiButColorBand *)but; + but_coba->edit_coba = editcoba; + } + else if (but_type == UI_BTYPE_CURVE) { + uiButCurveMapping *but_cumap = (uiButCurveMapping *)but; + but_cumap->edit_cumap = editcumap; + } + else if (but_type == UI_BTYPE_CURVEPROFILE) { + uiButCurveProfile *but_profile = (uiButCurveProfile *)but; + but_profile->edit_profile = editprofile; + } } /** \} */ @@ -2367,7 +2409,7 @@ static void ui_but_paste_numeric_value(bContext *C, { double value; - if (ui_but_string_set_eval_num(C, but, buf_paste, &value)) { + if (ui_but_string_eval_number(C, but, buf_paste, &value)) { button_activate_state(C, but, BUTTON_STATE_NUM_EDITING); data->value = value; ui_but_string_set(C, but, buf_paste); @@ -3023,7 +3065,7 @@ static bool ui_textedit_insert_buf(uiBut *but, static bool ui_textedit_insert_ascii(uiBut *but, uiHandleButtonData *data, char ascii) { - char buf[2] = {ascii, '\0'}; + const char buf[2] = {ascii, '\0'}; if (UI_but_is_utf8(but) && (BLI_str_utf8_size(buf) == -1)) { printf( @@ -3321,7 +3363,9 @@ static void ui_textedit_begin(bContext *C, uiBut *but, uiHandleButtonData *data) /* optional searchbox */ if (but->type == UI_BTYPE_SEARCH_MENU) { - data->searchbox = but->search->create_fn(C, data->region, but); + uiButSearch *search_but = (uiButSearch *)but; + + data->searchbox = search_but->popup_create_fn(C, data->region, search_but); ui_searchbox_update(C, data->searchbox, but, true); /* true = reset */ } @@ -3833,14 +3877,17 @@ static void ui_do_but_textedit_select( static void ui_numedit_begin(uiBut *but, uiHandleButtonData *data) { if (but->type == UI_BTYPE_CURVE) { - but->editcumap = (CurveMapping *)but->poin; + uiButCurveMapping *but_cumap = (uiButCurveMapping *)but; + but_cumap->edit_cumap = (CurveMapping *)but->poin; } - if (but->type == UI_BTYPE_CURVEPROFILE) { - but->editprofile = (CurveProfile *)but->poin; + else if (but->type == UI_BTYPE_CURVEPROFILE) { + uiButCurveProfile *but_profile = (uiButCurveProfile *)but; + but_profile->edit_profile = (CurveProfile *)but->poin; } else if (but->type == UI_BTYPE_COLORBAND) { + uiButColorBand *but_coba = (uiButColorBand *)but; data->coba = (ColorBand *)but->poin; - but->editcoba = data->coba; + but_coba->edit_coba = data->coba; } else if (ELEM(but->type, UI_BTYPE_UNITVEC, @@ -3926,10 +3973,18 @@ static void ui_numedit_end(uiBut *but, uiHandleButtonData *data) { but->editval = NULL; but->editvec = NULL; - but->editcoba = NULL; - but->editcumap = NULL; - but->editprofile = NULL; - + if (but->type == UI_BTYPE_COLORBAND) { + uiButColorBand *but_coba = (uiButColorBand *)but; + but_coba->edit_coba = NULL; + } + else if (but->type == UI_BTYPE_CURVE) { + uiButCurveMapping *but_cumap = (uiButCurveMapping *)but; + but_cumap->edit_cumap = NULL; + } + else if (but->type == UI_BTYPE_CURVEPROFILE) { + uiButCurveProfile *but_profile = (uiButCurveProfile *)but; + but_profile->edit_profile = NULL; + } data->dragstartx = 0; data->draglastx = 0; data->dragchange = false; @@ -4390,7 +4445,7 @@ static int ui_do_but_TEX( if (ELEM(event->type, EVT_PADENTER, EVT_RETKEY) && (!UI_but_is_utf8(but))) { /* pass - allow filesel, enter to execute */ } - else if (but->dt == UI_EMBOSS_NONE && !event->ctrl) { + else if (but->emboss == UI_EMBOSS_NONE && !event->ctrl) { /* pass */ } else { @@ -5698,21 +5753,24 @@ static bool ui_numedit_but_UNITVEC( return changed; } -static void ui_palette_set_active(uiBut *but) +static void ui_palette_set_active(uiButColor *color_but) { - if ((int)(but->a1) == UI_PALETTE_COLOR) { - Palette *palette = (Palette *)but->rnapoin.owner_id; - PaletteColor *color = but->rnapoin.data; + if (color_but->is_pallete_color) { + Palette *palette = (Palette *)color_but->but.rnapoin.owner_id; + PaletteColor *color = color_but->but.rnapoin.data; palette->active_color = BLI_findindex(&palette->colors, color); } } static int ui_do_but_COLOR(bContext *C, uiBut *but, uiHandleButtonData *data, const wmEvent *event) { + BLI_assert(but->type == UI_BTYPE_COLOR); + uiButColor *color_but = (uiButColor *)but; + if (data->state == BUTTON_STATE_HIGHLIGHT) { /* first handle click on icondrag type button */ if (event->type == LEFTMOUSE && but->dragpoin && event->val == KM_PRESS) { - ui_palette_set_active(but); + ui_palette_set_active(color_but); if (ui_but_contains_point_px_icon(but, data->region, event)) { button_activate_state(C, but, BUTTON_STATE_WAIT_DRAG); data->dragstartx = event->x; @@ -5722,7 +5780,7 @@ static int ui_do_but_COLOR(bContext *C, uiBut *but, uiHandleButtonData *data, co } #ifdef USE_DRAG_TOGGLE if (event->type == LEFTMOUSE && event->val == KM_PRESS) { - ui_palette_set_active(but); + ui_palette_set_active(color_but); button_activate_state(C, but, BUTTON_STATE_WAIT_DRAG); data->dragstartx = event->x; data->dragstarty = event->y; @@ -5731,7 +5789,7 @@ static int ui_do_but_COLOR(bContext *C, uiBut *but, uiHandleButtonData *data, co #endif /* regular open menu */ if (ELEM(event->type, LEFTMOUSE, EVT_PADENTER, EVT_RETKEY) && event->val == KM_PRESS) { - ui_palette_set_active(but); + ui_palette_set_active(color_but); button_activate_state(C, but, BUTTON_STATE_MENU_OPEN); return WM_UI_HANDLER_BREAK; } @@ -5762,8 +5820,7 @@ static int ui_do_but_COLOR(bContext *C, uiBut *but, uiHandleButtonData *data, co ui_apply_but(C, but->block, but, data, true); return WM_UI_HANDLER_BREAK; } - if ((int)(but->a1) == UI_PALETTE_COLOR && event->type == EVT_DELKEY && - event->val == KM_PRESS) { + if (color_but->is_pallete_color && (event->type == EVT_DELKEY) && (event->val == KM_PRESS)) { Palette *palette = (Palette *)but->rnapoin.owner_id; PaletteColor *color = but->rnapoin.data; @@ -5794,7 +5851,7 @@ static int ui_do_but_COLOR(bContext *C, uiBut *but, uiHandleButtonData *data, co } if (event->type == LEFTMOUSE && event->val == KM_RELEASE) { - if ((int)(but->a1) == UI_PALETTE_COLOR) { + if (color_but->is_pallete_color) { if (!event->ctrl) { float color[3]; Paint *paint = BKE_paint_get_active_from_context(C); @@ -5924,9 +5981,11 @@ static void clamp_axis_max_v3(float v[3], const float max) } } -static void ui_rgb_to_color_picker_HSVCUBE_compat_v(uiBut *but, const float rgb[3], float hsv[3]) +static void ui_rgb_to_color_picker_HSVCUBE_compat_v(const uiButHSVCube *hsv_but, + const float rgb[3], + float hsv[3]) { - if (but->a1 == UI_GRAD_L_ALT) { + if (hsv_but->gradient_type == UI_GRAD_L_ALT) { rgb_to_hsl_compat_v(rgb, hsv); } else { @@ -5934,9 +5993,11 @@ static void ui_rgb_to_color_picker_HSVCUBE_compat_v(uiBut *but, const float rgb[ } } -static void ui_rgb_to_color_picker_HSVCUBE_v(uiBut *but, const float rgb[3], float hsv[3]) +static void ui_rgb_to_color_picker_HSVCUBE_v(const uiButHSVCube *hsv_but, + const float rgb[3], + float hsv[3]) { - if (but->a1 == UI_GRAD_L_ALT) { + if (hsv_but->gradient_type == UI_GRAD_L_ALT) { rgb_to_hsl_v(rgb, hsv); } else { @@ -5944,9 +6005,11 @@ static void ui_rgb_to_color_picker_HSVCUBE_v(uiBut *but, const float rgb[3], flo } } -static void ui_color_picker_to_rgb_HSVCUBE_v(uiBut *but, const float hsv[3], float rgb[3]) +static void ui_color_picker_to_rgb_HSVCUBE_v(const uiButHSVCube *hsv_but, + const float hsv[3], + float rgb[3]) { - if (but->a1 == UI_GRAD_L_ALT) { + if (hsv_but->gradient_type == UI_GRAD_L_ALT) { hsl_to_rgb_v(hsv, rgb); } else { @@ -5961,6 +6024,7 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but, const enum eSnapType snap, const bool shift) { + const uiButHSVCube *hsv_but = (uiButHSVCube *)but; ColorPicker *cpicker = but->custom_data; float *hsv = cpicker->color_data; float rgb[3]; @@ -5982,7 +6046,7 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but, ui_but_v3_get(but, rgb); ui_scene_linear_to_color_picker_space(but, rgb); - ui_rgb_to_color_picker_HSVCUBE_compat_v(but, rgb, hsv); + ui_rgb_to_color_picker_HSVCUBE_compat_v(hsv_but, rgb, hsv); /* only apply the delta motion, not absolute */ if (shift) { @@ -5997,10 +6061,10 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but, copy_v3_v3(hsvo, hsv); - ui_rgb_to_color_picker_HSVCUBE_compat_v(but, rgb, hsvo); + ui_rgb_to_color_picker_HSVCUBE_compat_v(hsv_but, rgb, hsvo); /* and original position */ - ui_hsvcube_pos_from_vals(but, &rect_i, hsvo, &xpos, &ypos); + ui_hsvcube_pos_from_vals(hsv_but, &rect_i, hsvo, &xpos, &ypos); mx_fl = xpos - (data->dragstartx - mx_fl); my_fl = ypos - (data->dragstarty - my_fl); @@ -6012,7 +6076,7 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but, CLAMP(x, 0.0f, 1.0f); CLAMP(y, 0.0f, 1.0f); - switch ((int)but->a1) { + switch (hsv_but->gradient_type) { case UI_GRAD_SV: hsv[1] = x; hsv[2] = y; @@ -6050,16 +6114,16 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but, } if (snap != SNAP_OFF) { - if (ELEM((int)but->a1, UI_GRAD_HV, UI_GRAD_HS, UI_GRAD_H)) { + if (ELEM(hsv_but->gradient_type, UI_GRAD_HV, UI_GRAD_HS, UI_GRAD_H)) { ui_color_snap_hue(snap, &hsv[0]); } } - ui_color_picker_to_rgb_HSVCUBE_v(but, hsv, rgb); + ui_color_picker_to_rgb_HSVCUBE_v(hsv_but, hsv, rgb); ui_color_picker_to_scene_linear_space(but, rgb); /* clamp because with color conversion we can exceed range [#34295] */ - if (but->a1 == UI_GRAD_V_ALT) { + if (hsv_but->gradient_type == UI_GRAD_V_ALT) { clamp_axis_max_v3(rgb, but->softmax); } @@ -6072,23 +6136,23 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but, } #ifdef WITH_INPUT_NDOF -static void ui_ndofedit_but_HSVCUBE(uiBut *but, +static void ui_ndofedit_but_HSVCUBE(uiButHSVCube *hsv_but, uiHandleButtonData *data, const wmNDOFMotionData *ndof, const enum eSnapType snap, const bool shift) { - ColorPicker *cpicker = but->custom_data; + ColorPicker *cpicker = hsv_but->but.custom_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], hsv_but->but.softmax); float rgb[3]; float sensitivity = (shift ? 0.15f : 0.3f) * ndof->dt; - ui_but_v3_get(but, rgb); - ui_scene_linear_to_color_picker_space(but, rgb); - ui_rgb_to_color_picker_HSVCUBE_compat_v(but, rgb, hsv); + ui_but_v3_get(&hsv_but->but, rgb); + ui_scene_linear_to_color_picker_space(&hsv_but->but, rgb); + ui_rgb_to_color_picker_HSVCUBE_compat_v(hsv_but, rgb, hsv); - switch ((int)but->a1) { + switch (hsv_but->gradient_type) { case UI_GRAD_SV: hsv[1] += ndof->rvec[2] * sensitivity; hsv[2] += ndof->rvec[0] * sensitivity; @@ -6117,7 +6181,7 @@ static void ui_ndofedit_but_HSVCUBE(uiBut *but, /* exception only for value strip - use the range set in but->min/max */ hsv[2] += ndof->rvec[0] * sensitivity; - CLAMP(hsv[2], but->softmin, but->softmax); + CLAMP(hsv[2], hsv_but->but.softmin, hsv_but->but.softmax); break; default: assert(!"invalid hsv type"); @@ -6125,7 +6189,7 @@ static void ui_ndofedit_but_HSVCUBE(uiBut *but, } if (snap != SNAP_OFF) { - if (ELEM((int)but->a1, UI_GRAD_HV, UI_GRAD_HS, UI_GRAD_H)) { + if (ELEM(hsv_but->gradient_type, UI_GRAD_HV, UI_GRAD_HS, UI_GRAD_H)) { ui_color_snap_hue(snap, &hsv[0]); } } @@ -6133,17 +6197,18 @@ static void ui_ndofedit_but_HSVCUBE(uiBut *but, /* ndof specific: the changes above aren't clamping */ hsv_clamp_v(hsv, hsv_v_max); - ui_color_picker_to_rgb_HSVCUBE_v(but, hsv, rgb); - ui_color_picker_to_scene_linear_space(but, rgb); + ui_color_picker_to_rgb_HSVCUBE_v(hsv_but, hsv, rgb); + ui_color_picker_to_scene_linear_space(&hsv_but->but, rgb); copy_v3_v3(data->vec, rgb); - ui_but_v3_set(but, data->vec); + ui_but_v3_set(&hsv_but->but, data->vec); } #endif /* WITH_INPUT_NDOF */ static int ui_do_but_HSVCUBE( bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event) { + uiButHSVCube *hsv_but = (uiButHSVCube *)but; int mx, my; mx = event->x; @@ -6172,7 +6237,7 @@ static int ui_do_but_HSVCUBE( const wmNDOFMotionData *ndof = event->customdata; const enum eSnapType snap = ui_event_to_snap(event); - ui_ndofedit_but_HSVCUBE(but, data, ndof, snap, event->shift != 0); + ui_ndofedit_but_HSVCUBE(hsv_but, data, ndof, snap, event->shift != 0); button_activate_state(C, but, BUTTON_STATE_EXIT); ui_apply_but(C, but->block, but, data, true); @@ -6182,7 +6247,7 @@ static int ui_do_but_HSVCUBE( #endif /* WITH_INPUT_NDOF */ /* XXX hardcoded keymap check.... */ if (event->type == EVT_BACKSPACEKEY && event->val == KM_PRESS) { - if (ELEM(but->a1, UI_GRAD_V_ALT, UI_GRAD_L_ALT)) { + if (ELEM(hsv_but->gradient_type, UI_GRAD_V_ALT, UI_GRAD_L_ALT)) { int len; /* reset only value */ @@ -6195,15 +6260,15 @@ static int ui_do_but_HSVCUBE( float *hsv = cpicker->color_data; 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(hsv_but, def, def_hsv); 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(hsv_but, rgb, hsv); def_hsv[0] = hsv[0]; def_hsv[1] = hsv[1]; - ui_color_picker_to_rgb_HSVCUBE_v(but, def_hsv, rgb); + ui_color_picker_to_rgb_HSVCUBE_v(hsv_but, def_hsv, rgb); ui_but_v3_set(but, rgb); RNA_property_update(C, &but->rnapoin, but->rnaprop); @@ -6955,7 +7020,7 @@ static bool ui_numedit_but_CURVEPROFILE(uiBlock *block, fy *= mval_factor; /* Move all selected points. */ - float delta[2] = {fx, fy}; + const float delta[2] = {fx, fy}; for (a = 0; a < profile->path_len; a++) { /* Don't move the last and first control points. */ if ((pts[a].flag & PROF_SELECT) && (a != 0) && (a != profile->path_len)) { @@ -7129,7 +7194,7 @@ static int ui_do_but_CURVEPROFILE( dist_min_sq = square_f(U.dpi_fac * 8.0f); /* 8 pixel radius from each table point. */ /* Loop through the path's high resolution table and find what's near the click. */ - for (int i = 1; i <= PROF_N_TABLE(profile->path_len); i++) { + for (int i = 1; i <= PROF_TABLE_LEN(profile->path_len); i++) { copy_v2_v2(f_xy_prev, f_xy); BLI_rctf_transform_pt_v(&but->rect, &profile->view_rect, f_xy, &table[i].x); @@ -7522,6 +7587,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * switch (but->type) { case UI_BTYPE_BUT: + case UI_BTYPE_DECORATOR: retval = ui_do_but_BUT(C, but, data, event); break; case UI_BTYPE_KEY_EVENT: @@ -7597,13 +7663,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent * retval = ui_do_but_BUT(C, but, data, event); break; case UI_BTYPE_COLOR: - if (but->a1 == -1) { - /* signal to prevent calling up color picker */ - retval = ui_do_but_EXIT(C, but, data, event); - } - else { - retval = ui_do_but_COLOR(C, but, data, event); - } + retval = ui_do_but_COLOR(C, but, data, event); break; case UI_BTYPE_UNITVEC: retval = ui_do_but_UNITVEC(C, block, but, data, event); @@ -8430,7 +8490,7 @@ void UI_context_update_anim_flag(const bContext *C) ui_but_anim_flag(but, &anim_eval_context); ui_but_override_flag(CTX_data_main(C), but); if (UI_but_is_decorator(but)) { - ui_but_anim_decorate_update_from_flag(but); + ui_but_anim_decorate_update_from_flag((uiButDecorator *)but); } ED_region_tag_redraw(region); |