Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/blender/editors/interface/interface.c3
-rw-r--r--source/blender/editors/interface/interface_handlers.c66
2 files changed, 67 insertions, 2 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index c0045580ede..810cbc25862 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -2619,6 +2619,9 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str,
uiBut *but;
int slen;
+ BLI_assert(width >= 0);
+ BLI_assert(height >= 0);
+
/* we could do some more error checks here */
if ((type & BUTTYPE) == LABEL) {
BLI_assert((poin != NULL || min != 0.0f || max != 0.0f || (a1 == 0.0f && a2 != 0.0f) || (a1 != 0.0f && a1 != 1.0f)) == FALSE);
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index e61b0a625ef..0da029f1363 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -78,6 +78,9 @@
#include "WM_api.h"
#include "WM_types.h"
+/* place the mouse at the scaled down location when un-grabbing */
+#define USE_CONT_MOUSE_CORRECT
+
/* proto */
static void ui_add_smart_controller(bContext *C, uiBut *from, uiBut *to);
static void ui_add_link(bContext *C, uiBut *from, uiBut *to);
@@ -152,6 +155,12 @@ typedef struct uiHandleButtonData {
float dragf, dragfstart;
CBData *dragcbd;
+#ifdef USE_CONT_MOUSE_CORRECT
+ /* when ungrabbing buttons which are #ui_is_a_warp_but(), we may want to position them
+ * FLT_MAX signifies do-nothing, use #ui_block_to_window_fl() to get this into a usable space */
+ float ungrab_mval[2];
+#endif
+
/* menu open (watch uiFreeActiveButtons) */
uiPopupBlockHandle *menu;
int menuretval;
@@ -3191,6 +3200,15 @@ static int ui_numedit_but_HSVCUBE(uiBut *but, uiHandleButtonData *data, int mx,
ui_mouse_scale_warp(data, mx, my, &mx_fl, &my_fl, shift);
+#ifdef USE_CONT_MOUSE_CORRECT
+ if (ui_is_a_warp_but(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);
+ }
+#endif
+
if (but->rnaprop) {
if (RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA)
color_profile = FALSE;
@@ -3415,6 +3433,22 @@ static int ui_numedit_but_HSVCIRCLE(uiBut *but, uiHandleButtonData *data, float
ui_mouse_scale_warp(data, mx, my, &mx_fl, &my_fl, shift);
+#ifdef USE_CONT_MOUSE_CORRECT
+ if (ui_is_a_warp_but(but)) {
+ /* OK but can go outside bounds */
+ data->ungrab_mval[0] = mx_fl;
+ data->ungrab_mval[1] = my_fl;
+ { /* clamp */
+ const float radius = minf(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 len = len_v2v2(cent, data->ungrab_mval);
+ if (len > radius) {
+ dist_ensure_v2_v2fl(data->ungrab_mval, cent, radius);
+ }
+ }
+ }
+#endif
+
BLI_rcti_rctf_copy(&rect, &but->rect);
ui_get_but_vectorf(but, rgb);
@@ -3706,9 +3740,10 @@ static int ui_numedit_but_CURVE(uiBut *but, uiHandleButtonData *data, int snap,
}
if (data->dragsel != -1) {
+ CurveMapPoint *cmp_last = NULL;
const float mval_factor = ui_mouse_scale_warp_factor(shift);
int moved_point = 0; /* for ctrl grid, can't use orig coords because of sorting */
-
+
fx = (mx - data->draglastx) / zoomx;
fy = (my - data->draglasty) / zoomy;
@@ -3726,6 +3761,8 @@ static int ui_numedit_but_CURVE(uiBut *but, uiHandleButtonData *data, int snap,
}
if (cmp[a].x != origx || cmp[a].y != origy)
moved_point = 1;
+
+ cmp_last = &cmp[a];
}
}
@@ -3735,6 +3772,18 @@ static int ui_numedit_but_CURVE(uiBut *but, uiHandleButtonData *data, int snap,
data->draglastx = mx;
data->draglasty = my;
changed = 1;
+
+#ifdef USE_CONT_MOUSE_CORRECT
+ /* note: using 'cmp_last' is weak since there may be multiple points selected,
+ * but in practice this isnt really an issue */
+ if (ui_is_a_warp_but(but)) {
+ /* OK but can go outside bounds */
+ 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);
+ BLI_rctf_clamp_pt_v(&but->rect, data->ungrab_mval);
+ }
+#endif
+
}
data->dragchange = 1; /* mark for selection */
@@ -5322,8 +5371,17 @@ static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState s
}
else if (data->state == BUTTON_STATE_NUM_EDITING) {
ui_numedit_end(but, data);
- if (ui_is_a_warp_but(but))
+ if (ui_is_a_warp_but(but)) {
WM_cursor_grab_disable(CTX_wm_window(C));
+
+ /* XXX, you can see that the cursor is revealed, then moved - should do at once */
+#ifdef USE_CONT_MOUSE_CORRECT
+ if (data->ungrab_mval[0] != FLT_MAX) {
+ ui_block_to_window_fl(data->region, but->block, &data->ungrab_mval[0], &data->ungrab_mval[1]);
+ WM_cursor_warp(CTX_wm_window(C), data->ungrab_mval[0], data->ungrab_mval[1]);
+ }
+#endif
+ }
}
/* menu open */
if (state == BUTTON_STATE_MENU_OPEN)
@@ -5386,6 +5444,10 @@ static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonA
data->window = CTX_wm_window(C);
data->region = ar;
+#ifdef USE_CONT_MOUSE_CORRECT
+ copy_v2_fl(data->ungrab_mval, FLT_MAX);
+#endif
+
if (ELEM(but->type, BUT_CURVE, SEARCH_MENU)) {
/* XXX curve is temp */
}