Gooseberry request, circle select for graph editor
This commit is contained in:
parent
491839b3c8
commit
233c650d55
@ -546,6 +546,44 @@ static short ok_bezier_region_lasso(KeyframeEditData *ked, BezTriple *bezt)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* only called from #ok_bezier_region_circle
|
||||
*/
|
||||
static bool bezier_region_circle_test(
|
||||
const struct KeyframeEdit_CircleData *data_circle,
|
||||
const float xy[2])
|
||||
{
|
||||
if (BLI_rctf_isect_pt_v(data_circle->rectf_scaled, xy)) {
|
||||
float xy_view[2];
|
||||
|
||||
BLI_rctf_transform_pt_v(data_circle->rectf_view, data_circle->rectf_scaled, xy_view, xy);
|
||||
|
||||
xy_view[0] = xy_view[0] - data_circle->mval[0];
|
||||
xy_view[1] = xy_view[1] - data_circle->mval[1];
|
||||
return len_squared_v2(xy_view) < data_circle->radius_squared;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static short ok_bezier_region_circle(KeyframeEditData *ked, BezTriple *bezt)
|
||||
{
|
||||
/* rect is stored in data property (it's of type rectf, but may not be set) */
|
||||
if (ked->data) {
|
||||
short ok = 0;
|
||||
|
||||
#define KEY_CHECK_OK(_index) bezier_region_circle_test(ked->data, bezt->vec[_index])
|
||||
KEYFRAME_OK_CHECKS(KEY_CHECK_OK);
|
||||
#undef KEY_CHECK_OK
|
||||
|
||||
/* return ok flags */
|
||||
return ok;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
KeyframeEditFunc ANIM_editkeyframes_ok(short mode)
|
||||
{
|
||||
@ -565,6 +603,8 @@ KeyframeEditFunc ANIM_editkeyframes_ok(short mode)
|
||||
return ok_bezier_region;
|
||||
case BEZT_OK_REGION_LASSO: /* only if the point falls within KeyframeEdit_LassoData defined data */
|
||||
return ok_bezier_region_lasso;
|
||||
case BEZT_OK_REGION_CIRCLE: /* only if the point falls within KeyframeEdit_LassoData defined data */
|
||||
return ok_bezier_region_circle;
|
||||
default: /* nothing was ok */
|
||||
return NULL;
|
||||
}
|
||||
|
@ -58,6 +58,7 @@ typedef enum eEditKeyframes_Validate {
|
||||
BEZT_OK_VALUERANGE,
|
||||
BEZT_OK_REGION,
|
||||
BEZT_OK_REGION_LASSO,
|
||||
BEZT_OK_REGION_CIRCLE,
|
||||
} eEditKeyframes_Validate;
|
||||
|
||||
/* ------------ */
|
||||
@ -107,6 +108,14 @@ struct KeyframeEdit_LassoData {
|
||||
int mcords_tot;
|
||||
};
|
||||
|
||||
/* use with BEZT_OK_REGION_CIRCLE */
|
||||
struct KeyframeEdit_CircleData {
|
||||
const rctf *rectf_scaled;
|
||||
const rctf *rectf_view;
|
||||
float mval[2];
|
||||
float radius_squared;
|
||||
};
|
||||
|
||||
|
||||
/* ************************************************ */
|
||||
/* Non-Destuctive Editing API (keyframes_edit.c) */
|
||||
|
@ -62,6 +62,7 @@ void graph_draw_ghost_curves(struct bAnimContext *ac, struct SpaceIpo *sipo, str
|
||||
void GRAPH_OT_select_all_toggle(struct wmOperatorType *ot);
|
||||
void GRAPH_OT_select_border(struct wmOperatorType *ot);
|
||||
void GRAPH_OT_select_lasso(struct wmOperatorType *ot);
|
||||
void GRAPH_OT_select_circle(struct wmOperatorType *ot);
|
||||
void GRAPH_OT_select_column(struct wmOperatorType *ot);
|
||||
void GRAPH_OT_select_linked(struct wmOperatorType *ot);
|
||||
void GRAPH_OT_select_more(struct wmOperatorType *ot);
|
||||
|
@ -393,6 +393,7 @@ void graphedit_operatortypes(void)
|
||||
WM_operatortype_append(GRAPH_OT_select_all_toggle);
|
||||
WM_operatortype_append(GRAPH_OT_select_border);
|
||||
WM_operatortype_append(GRAPH_OT_select_lasso);
|
||||
WM_operatortype_append(GRAPH_OT_select_circle);
|
||||
WM_operatortype_append(GRAPH_OT_select_column);
|
||||
WM_operatortype_append(GRAPH_OT_select_linked);
|
||||
WM_operatortype_append(GRAPH_OT_select_more);
|
||||
@ -531,6 +532,8 @@ static void graphedit_keymap_keyframes(wmKeyConfig *keyconf, wmKeyMap *keymap)
|
||||
kmi = WM_keymap_add_item(keymap, "GRAPH_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL | KM_SHIFT, 0);
|
||||
RNA_boolean_set(kmi->ptr, "deselect", true);
|
||||
|
||||
WM_keymap_add_item(keymap, "GRAPH_OT_select_circle", CKEY, KM_PRESS, 0, 0);
|
||||
|
||||
/* column select */
|
||||
RNA_enum_set(WM_keymap_add_item(keymap, "GRAPH_OT_select_column", KKEY, KM_PRESS, 0, 0)->ptr, "mode", GRAPHKEYS_COLUMNSEL_KEYS);
|
||||
RNA_enum_set(WM_keymap_add_item(keymap, "GRAPH_OT_select_column", KKEY, KM_PRESS, KM_CTRL, 0)->ptr, "mode", GRAPHKEYS_COLUMNSEL_CFRA);
|
||||
@ -613,7 +616,7 @@ static void graphedit_keymap_keyframes(wmKeyConfig *keyconf, wmKeyMap *keymap)
|
||||
kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, KM_CTRL, 0);
|
||||
RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
|
||||
RNA_string_set(kmi->ptr, "value", "INDIVIDUAL_ORIGINS");
|
||||
|
||||
|
||||
/* special markers hotkeys for anim editors: see note in definition of this function */
|
||||
ED_marker_keymap_animedit_conflictfree(keymap);
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ void GRAPH_OT_select_all_toggle(wmOperatorType *ot)
|
||||
*/
|
||||
static void borderselect_graphkeys(
|
||||
bAnimContext *ac, const rctf *rectf_view, short mode, short selectmode, bool incl_handles,
|
||||
struct KeyframeEdit_LassoData *data_lasso)
|
||||
void *data)
|
||||
{
|
||||
ListBase anim_data = {NULL, NULL};
|
||||
bAnimListElem *ale;
|
||||
@ -244,10 +244,16 @@ static void borderselect_graphkeys(
|
||||
|
||||
/* init editing data */
|
||||
memset(&ked, 0, sizeof(KeyframeEditData));
|
||||
if (data_lasso) {
|
||||
if (mode == BEZT_OK_REGION_LASSO) {
|
||||
struct KeyframeEdit_LassoData *data_lasso = data;
|
||||
data_lasso->rectf_scaled = &scaled_rectf;
|
||||
ked.data = data_lasso;
|
||||
}
|
||||
if (mode == BEZT_OK_REGION_CIRCLE) {
|
||||
struct KeyframeEdit_CircleData *data_circle = data;
|
||||
data_circle->rectf_scaled = &scaled_rectf;
|
||||
ked.data = data;
|
||||
}
|
||||
else {
|
||||
ked.data = &scaled_rectf;
|
||||
}
|
||||
@ -485,6 +491,81 @@ void GRAPH_OT_select_lasso(wmOperatorType *ot)
|
||||
RNA_def_boolean(ot->srna, "extend", true, "Extend", "Extend selection instead of deselecting everything first");
|
||||
}
|
||||
|
||||
static int graph_circle_select_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
bAnimContext ac;
|
||||
const int gesture_mode = RNA_int_get(op->ptr, "gesture_mode");
|
||||
short selectmode;
|
||||
bool incl_handles;
|
||||
rctf rect_fl;
|
||||
struct KeyframeEdit_CircleData data;
|
||||
float x = RNA_int_get(op->ptr, "x");
|
||||
float y = RNA_int_get(op->ptr, "y");
|
||||
float radius = RNA_int_get(op->ptr, "radius");
|
||||
|
||||
/* get editor data */
|
||||
if (ANIM_animdata_get_context(C, &ac) == 0)
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
data.mval[0] = x;
|
||||
data.mval[1] = y;
|
||||
data.radius_squared = radius * radius;
|
||||
data.rectf_view = &rect_fl;
|
||||
|
||||
if (gesture_mode == GESTURE_MODAL_SELECT)
|
||||
selectmode = SELECT_ADD;
|
||||
else
|
||||
selectmode = SELECT_SUBTRACT;
|
||||
|
||||
rect_fl.xmin = x - radius;
|
||||
rect_fl.xmax = x + radius;
|
||||
rect_fl.ymin = y - radius;
|
||||
rect_fl.ymax = y + radius;
|
||||
|
||||
if (ac.spacetype == SPACE_IPO) {
|
||||
SpaceIpo *sipo = (SpaceIpo *)ac.sl;
|
||||
if (selectmode == SELECT_ADD) {
|
||||
incl_handles = ((sipo->flag & SIPO_SELVHANDLESONLY) ||
|
||||
(sipo->flag & SIPO_NOHANDLES)) == 0;
|
||||
}
|
||||
else {
|
||||
incl_handles = (sipo->flag & SIPO_NOHANDLES) == 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
incl_handles = false;
|
||||
}
|
||||
|
||||
/* apply borderselect action */
|
||||
borderselect_graphkeys(&ac, &rect_fl, BEZT_OK_REGION_CIRCLE, selectmode, incl_handles, &data);
|
||||
|
||||
/* send notifier that keyframe selection has changed */
|
||||
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
void GRAPH_OT_select_circle(wmOperatorType *ot)
|
||||
{
|
||||
ot->name = "Circle Select";
|
||||
ot->description = "Select keyframe points using circle selection";
|
||||
ot->idname = "GRAPH_OT_select_circle";
|
||||
|
||||
ot->invoke = WM_gesture_circle_invoke;
|
||||
ot->modal = WM_gesture_circle_modal;
|
||||
ot->exec = graph_circle_select_exec;
|
||||
ot->poll = graphop_visible_keyframes_poll;
|
||||
ot->cancel = WM_gesture_circle_cancel;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_UNDO;
|
||||
|
||||
RNA_def_int(ot->srna, "x", 0, INT_MIN, INT_MAX, "X", "", INT_MIN, INT_MAX);
|
||||
RNA_def_int(ot->srna, "y", 0, INT_MIN, INT_MAX, "Y", "", INT_MIN, INT_MAX);
|
||||
RNA_def_int(ot->srna, "radius", 1, 1, INT_MAX, "Radius", "", 1, INT_MAX);
|
||||
RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Event Type", "", INT_MIN, INT_MAX);
|
||||
}
|
||||
|
||||
/* ******************** Column Select Operator **************************** */
|
||||
/* This operator works in one of four ways:
|
||||
* - 1) select all keyframes in the same frame as a selected one (KKEY)
|
||||
|
@ -4802,6 +4802,7 @@ static void gesture_circle_modal_keymap(wmKeyConfig *keyconf)
|
||||
WM_modalkeymap_assign(keymap, "MASK_OT_select_circle");
|
||||
WM_modalkeymap_assign(keymap, "NODE_OT_select_circle");
|
||||
WM_modalkeymap_assign(keymap, "GPENCIL_OT_select_circle");
|
||||
WM_modalkeymap_assign(keymap, "GRAPH_OT_select_circle");
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user