Fix: Inconsistent input drag color pick in Square HSV input #112064

Open
Guillermo Venegas wants to merge 6 commits from guishe/blender:fix-mouse-drag-edit-square-hsv into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
1 changed files with 34 additions and 35 deletions

View File

@ -6511,24 +6511,40 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but,
int mx,
int my,
const enum eSnapType snap,
const bool shift)
const bool shift,
const bool use_continuous_grab)
{
const uiButHSVCube *hsv_but = (uiButHSVCube *)but;
ColorPicker *cpicker = static_cast<ColorPicker *>(but->custom_data);
float *hsv = cpicker->hsv_perceptual;
float rgb[3];
float x, y;
float mx_fl, my_fl;
const bool changed = true;
ui_mouse_scale_warp(data, mx, my, &mx_fl, &my_fl, shift);
/* If `use_continuous_grab = false` stores the absolute mouse position.
* If `use_continuous_grab = true` stores relative mouse position within the `HSVCUBE`, this
* position will depend on mouse movement rather than the absolute mouse position.
*/
static float mval[2];
if (use_continuous_grab) {
rcti rect;
BLI_rcti_rctf_copy(&rect, &but->rect);
const float fac = ui_mouse_scale_warp_factor(shift);
mval[0] = (float(mx) - float(data->draglastx)) * fac + mval[0];
mval[1] = (float(my) - float(data->draglasty)) * fac + mval[1];
BLI_rctf_clamp_pt_v(&but->rect, mval);
}
else {
mval[0] = mx;
mval[1] = my;
}
#ifdef USE_CONT_MOUSE_CORRECT
if (ui_but_is_cursor_warp(but)) {
/* OK but can go outside bounds */
data->ungrab_mval[0] = mx_fl;
data->ungrab_mval[1] = my_fl;
BLI_rctf_clamp_pt_v(&but->rect, data->ungrab_mval);
if (use_continuous_grab) {
data->ungrab_mval[0] = mval[0];
data->ungrab_mval[1] = mval[1];
}
#endif
@ -6537,31 +6553,9 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but,
ui_rgb_to_color_picker_HSVCUBE_compat_v(hsv_but, rgb, hsv);
/* only apply the delta motion, not absolute */
if (shift) {
rcti rect_i;
float xpos, ypos, hsvo[3];
BLI_rcti_rctf_copy(&rect_i, &but->rect);
/* calculate original hsv again */
copy_v3_v3(rgb, data->origvec);
ui_scene_linear_to_perceptual_space(but, rgb);
copy_v3_v3(hsvo, hsv);
ui_rgb_to_color_picker_HSVCUBE_compat_v(hsv_but, rgb, hsvo);
/* and original position */
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);
}
/* relative position within box */
x = (float(mx_fl) - but->rect.xmin) / BLI_rctf_size_x(&but->rect);
y = (float(my_fl) - but->rect.ymin) / BLI_rctf_size_y(&but->rect);
x = (float(mval[0]) - but->rect.xmin) / BLI_rctf_size_x(&but->rect);
y = (float(mval[1]) - but->rect.ymin) / BLI_rctf_size_y(&but->rect);
CLAMP(x, 0.0f, 1.0f);
CLAMP(y, 0.0f, 1.0f);
@ -6713,7 +6707,10 @@ static int ui_do_but_HSVCUBE(
button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
/* also do drag the first time */
if (ui_numedit_but_HSVCUBE(but, data, mx, my, snap, event->modifier & KM_SHIFT)) {
const bool shift = event->modifier & KM_SHIFT;
/* On KM_PRESS the mouse is within the cube, use `use_continuous_grab` to pick color at mouse
* position. */
if (ui_numedit_but_HSVCUBE(but, data, mx, my, snap, shift, false)) {
ui_numedit_apply(C, block, but, data);
}
@ -6775,8 +6772,10 @@ static int ui_do_but_HSVCUBE(
else if ((event->type == MOUSEMOVE) || ui_event_is_snap(event)) {
if (mx != data->draglastx || my != data->draglasty || event->type != MOUSEMOVE) {
const enum eSnapType snap = ui_event_to_snap(event);
if (ui_numedit_but_HSVCUBE(but, data, mx, my, snap, event->modifier & KM_SHIFT)) {
const bool shift = event->modifier & KM_SHIFT;
const bool use_continuous_grab = ui_but_is_cursor_warp(but) &&
event->tablet.active == EVT_TABLET_NONE;
if (ui_numedit_but_HSVCUBE(but, data, mx, my, snap, shift, use_continuous_grab)) {
ui_numedit_apply(C, block, but, data);
}
}