[Bf-blender-cvs] [04bac387315] master: Graph Editor: drag to box select keyframes
Jacques Lucke
noreply at git.blender.org
Tue Jun 4 11:38:38 CEST 2019
Commit: 04bac387315ce09822c36bc20e0fe4e7d533fec8
Author: Jacques Lucke
Date: Tue Jun 4 11:35:57 2019 +0200
Branches: master
https://developer.blender.org/rB04bac387315ce09822c36bc20e0fe4e7d533fec8
Graph Editor: drag to box select keyframes
There is a keymap conflict with ctrl+tweak.
Therefore, I did not include this yet.
Reviewers: brecht
Differential Revision: https://developer.blender.org/D4999
===================================================================
M release/scripts/presets/keyconfig/keymap_data/blender_default.py
M source/blender/editors/space_graph/graph_select.c
===================================================================
diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 64b4f7b1cac..ef466c2f3c5 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -1369,6 +1369,10 @@ def km_graph_editor(params):
{"properties": [("axis_range", False), ("include_handles", True)]}),
("graph.select_box", {"type": 'B', "value": 'PRESS', "ctrl": True, "alt": True},
{"properties": [("axis_range", True), ("include_handles", True)]}),
+ ("graph.select_box", {"type": params.select_tweak, "value": 'ANY'},
+ {"properties": [("tweak", True), ("mode", 'SET')]}),
+ ("graph.select_box", {"type": params.select_tweak, "value": 'ANY', "shift": True},
+ {"properties": [("tweak", True), ("mode", 'ADD')]}),
("graph.select_lasso", {"type": params.action_tweak, "value": 'ANY', "ctrl": True},
{"properties": [("mode", 'ADD')]}),
("graph.select_lasso", {"type": params.action_tweak, "value": 'ANY', "shift": True, "ctrl": True},
diff --git a/source/blender/editors/space_graph/graph_select.c b/source/blender/editors/space_graph/graph_select.c
index 5ea07c56286..4bd738fca95 100644
--- a/source/blender/editors/space_graph/graph_select.c
+++ b/source/blender/editors/space_graph/graph_select.c
@@ -59,904 +59,859 @@
/* ************************************************************************** */
/* KEYFRAMES STUFF */
-/* ******************** Deselect All Operator ***************************** */
-/* This operator works in one of three ways:
- * 1) (de)select all (AKEY) - test if select all or deselect all
- * 2) invert all (CTRL-IKEY) - invert selection of all keyframes
- * 3) (de)select all - no testing is done; only for use internal tools as normal function...
- */
-
-/* Deselects keyframes in the Graph Editor
- * - This is called by the deselect all operator, as well as other ones!
- *
- * - test: check if select or deselect all
- * - sel: how to select keyframes
- * 0 = deselect
- * 1 = select
- * 2 = invert
- * - do_channels: whether to affect selection status of channels
- */
-void deselect_graph_keys(bAnimContext *ac, bool test, short sel, bool do_channels)
-{
- ListBase anim_data = {NULL, NULL};
- bAnimListElem *ale;
- int filter;
-
- SpaceGraph *sipo = (SpaceGraph *)ac->sl;
- KeyframeEditData ked = {{NULL}};
- KeyframeEditFunc test_cb, sel_cb;
-
- /* determine type-based settings */
- filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS);
-
- /* filter data */
- ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
-
- /* init BezTriple looping data */
- test_cb = ANIM_editkeyframes_ok(BEZT_OK_SELECTED);
+/* temp info for caching handle vertices close */
+typedef struct tNearestVertInfo {
+ struct tNearestVertInfo *next, *prev;
- /* See if we should be selecting or deselecting */
- if (test) {
- for (ale = anim_data.first; ale; ale = ale->next) {
- if (ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, test_cb, NULL)) {
- sel = SELECT_SUBTRACT;
- break;
- }
- }
- }
+ FCurve *fcu; /* F-Curve that keyframe comes from */
- /* convert sel to selectmode, and use that to get editor */
- sel_cb = ANIM_editkeyframes_select(sel);
+ BezTriple *bezt; /* keyframe to consider */
+ FPoint *fpt; /* sample point to consider */
- /* Now set the flags */
- for (ale = anim_data.first; ale; ale = ale->next) {
- FCurve *fcu = (FCurve *)ale->key_data;
+ short hpoint; /* the handle index that we hit (eHandleIndex) */
+ short sel; /* whether the handle is selected or not */
+ int dist; /* distance from mouse to vert */
- /* Keyframes First */
- ANIM_fcurve_keyframes_loop(&ked, ale->key_data, NULL, sel_cb, NULL);
+ eAnim_ChannelType ctype; /* type of animation channel this FCurve comes from */
- /* affect channel selection status? */
- if (do_channels) {
- /* Only change selection of channel when the visibility of keyframes
- * doesn't depend on this. */
- if ((sipo->flag & SIPO_SELCUVERTSONLY) == 0) {
- /* deactivate the F-Curve, and deselect if deselecting keyframes.
- * otherwise select the F-Curve too since we've selected all the keyframes
- */
- if (sel == SELECT_SUBTRACT) {
- fcu->flag &= ~FCURVE_SELECTED;
- }
- else {
- fcu->flag |= FCURVE_SELECTED;
- }
- }
+ float frame; /* frame that point was on when it matched (global time) */
+} tNearestVertInfo;
- /* always deactivate all F-Curves if we perform batch ops for selection */
- fcu->flag &= ~FCURVE_ACTIVE;
- }
- }
+/* Tags for the type of graph vert that we have */
+typedef enum eGraphVertIndex {
+ NEAREST_HANDLE_LEFT = -1,
+ NEAREST_HANDLE_KEY,
+ NEAREST_HANDLE_RIGHT,
+} eGraphVertIndex;
- /* Cleanup */
- ANIM_animdata_freelist(&anim_data);
-}
+/* Tolerance for absolute radius (in pixels) of the vert from the cursor to use */
+// TODO: perhaps this should depend a bit on the size that the user set the vertices to be?
+#define GVERTSEL_TOL (10 * U.pixelsize)
-/* ------------------- */
+/* ....... */
-static int graphkeys_deselectall_exec(bContext *C, wmOperator *op)
+/* check if its ok to select a handle */
+// XXX also need to check for int-values only?
+static bool fcurve_handle_sel_check(SpaceGraph *sipo, BezTriple *bezt)
{
- bAnimContext ac;
- bAnimListElem *ale_active = NULL;
-
- /* get editor data */
- if (ANIM_animdata_get_context(C, &ac) == 0) {
- return OPERATOR_CANCELLED;
+ if (sipo->flag & SIPO_NOHANDLES) {
+ return 0;
}
-
- /* find active F-Curve, and preserve this for later
- * or else it becomes annoying with the current active
- * curve keeps fading out even while you're editing it
- */
- ale_active = get_active_fcurve_channel(&ac);
-
- /* 'standard' behavior - check if selected, then apply relevant selection */
- const int action = RNA_enum_get(op->ptr, "action");
- switch (action) {
- case SEL_TOGGLE:
- deselect_graph_keys(&ac, 1, SELECT_ADD, true);
- break;
- case SEL_SELECT:
- deselect_graph_keys(&ac, 0, SELECT_ADD, true);
- break;
- case SEL_DESELECT:
- deselect_graph_keys(&ac, 0, SELECT_SUBTRACT, true);
- break;
- case SEL_INVERT:
- deselect_graph_keys(&ac, 0, SELECT_INVERT, true);
- break;
- default:
- BLI_assert(0);
- break;
+ if ((sipo->flag & SIPO_SELVHANDLESONLY) && BEZT_ISSEL_ANY(bezt) == 0) {
+ return 0;
}
+ return 1;
+}
- /* restore active F-Curve... */
- if (ale_active) {
- FCurve *fcu = (FCurve *)ale_active->data;
+/* check if the given vertex is within bounds or not */
+// TODO: should we return if we hit something?
+static void nearest_fcurve_vert_store(ListBase *matches,
+ View2D *v2d,
+ FCurve *fcu,
+ eAnim_ChannelType ctype,
+ BezTriple *bezt,
+ FPoint *fpt,
+ short hpoint,
+ const int mval[2],
+ float unit_scale,
+ float offset)
+{
+ /* Keyframes or Samples? */
+ if (bezt) {
+ int screen_co[2], dist;
- /* all others should not be disabled, so we should be able to just set this directly...
- * - selection needs to be set too, or else this won't work...
+ /* convert from data-space to screen coordinates
+ * NOTE: hpoint+1 gives us 0,1,2 respectively for each handle,
+ * needed to access the relevant vertex coordinates in the 3x3
+ * 'vec' matrix
*/
- fcu->flag |= (FCURVE_SELECTED | FCURVE_ACTIVE);
-
- MEM_freeN(ale_active);
- ale_active = NULL;
- }
+ if (UI_view2d_view_to_region_clip(v2d,
+ bezt->vec[hpoint + 1][0],
+ (bezt->vec[hpoint + 1][1] + offset) * unit_scale,
+ &screen_co[0],
+ &screen_co[1]) &&
+ /* check if distance from mouse cursor to vert in screen space is within tolerance */
+ ((dist = len_v2v2_int(mval, screen_co)) <= GVERTSEL_TOL)) {
+ tNearestVertInfo *nvi = (tNearestVertInfo *)matches->last;
+ bool replace = false;
- /* set notifier that things have changed */
- WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL);
+ /* If there is already a point for the F-Curve,
+ * check if this point is closer than that was. */
+ if ((nvi) && (nvi->fcu == fcu)) {
+ /* replace if we are closer, or if equal and that one wasn't selected but we are... */
+ if ((nvi->dist > dist) || ((nvi->sel == 0) && BEZT_ISSEL_ANY(bezt))) {
+ replace = 1;
+ }
+ }
+ /* add new if not replacing... */
+ if (replace == 0) {
+ nvi = MEM_callocN(sizeof(tNearestVertInfo), "Nearest Graph Vert Info - Bezt");
+ }
- return OPERATOR_FINISHED;
-}
+ /* store values */
+ nvi->fcu = fcu;
+ nvi->ctype = ctype;
-void GRAPH_OT_select_all(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Select All";
- ot->idname = "GRAPH_OT_select_all";
- ot->description = "Toggle selection of all keyframes";
+ nvi->bezt = bezt;
+ nvi->hpoint = hpoint;
+ nvi->dist = dist;
- /* api callbacks */
- ot->exec = graphkeys_deselectall_exec;
- ot->poll = graphop_visible_keyframes_poll;
+ nvi->frame = bezt->vec[1][0]; /* currently in global time... */
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ nvi->sel = BEZT_ISSEL_ANY(bezt); // XXX... should this use the individual verts instead?
- /* properties */
- WM_operator_properties_select_all(ot);
+ /* add to list of matches if appropriate... */
+ if (replace == 0) {
+ BLI_addtail(matches, nvi);
+ }
+ }
+ }
+ else if (fpt) {
+ /* TODO... */
+ }
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list