DopeSheet: GPencil-Mode supports Circle and Lasso Select
authorJoshua Leung <aligorith@gmail.com>
Thu, 23 Jun 2016 14:52:13 +0000 (02:52 +1200)
committerJoshua Leung <aligorith@gmail.com>
Thu, 23 Jun 2016 15:18:36 +0000 (03:18 +1200)
To get this working the least effort, I've had to expose the helper functions
used by the lasso and circle select keyframe-test callbacks (which are generic)
and expose them for use by the GP keyframe editing code too. Hopefully in time
we clean this all up and just write the code once to operate on "keyframes"

source/blender/editors/animation/keyframes_edit.c
source/blender/editors/gpencil/editaction_gpencil.c
source/blender/editors/include/ED_gpencil.h
source/blender/editors/include/ED_keyframes_edit.h
source/blender/editors/space_action/action_select.c

index f909b39cca31536d7ba717b3cbe0cabcfd47ccd2..7b35a154fc84752636f5447d1294c48db366874d 100644 (file)
@@ -541,7 +541,7 @@ static short ok_bezier_region(KeyframeEditData *ked, BezTriple *bezt)
 /**
  * Called from #ok_bezier_region_lasso and #ok_bezier_channel_lasso
  */
-static bool bezier_region_lasso_test(
+bool keyframe_region_lasso_test(
         const KeyframeEdit_LassoData *data_lasso,
         const float xy[2])
 {
@@ -564,7 +564,7 @@ static short ok_bezier_region_lasso(KeyframeEditData *ked, BezTriple *bezt)
        if (ked->data) {
                short ok = 0;
                
-#define KEY_CHECK_OK(_index) bezier_region_lasso_test(ked->data, bezt->vec[_index])
+#define KEY_CHECK_OK(_index) keyframe_region_lasso_test(ked->data, bezt->vec[_index])
                KEYFRAME_OK_CHECKS(KEY_CHECK_OK);
 #undef KEY_CHECK_OK
                
@@ -596,7 +596,7 @@ static short ok_bezier_channel_lasso(KeyframeEditData *ked, BezTriple *bezt)
                pt[0] = bezt->vec[1][0];
                pt[1] = ked->channel_y;
                
-               if (bezier_region_lasso_test(data, pt))
+               if (keyframe_region_lasso_test(data, pt))
                        return KEYFRAME_OK_KEY;
        }
        return 0;
@@ -605,7 +605,7 @@ static short ok_bezier_channel_lasso(KeyframeEditData *ked, BezTriple *bezt)
 /**
  * Called from #ok_bezier_region_circle and #ok_bezier_channel_circle
  */
-static bool bezier_region_circle_test(
+bool keyframe_region_circle_test(
         const KeyframeEdit_CircleData *data_circle,
         const float xy[2])
 {
@@ -629,7 +629,7 @@ static short ok_bezier_region_circle(KeyframeEditData *ked, BezTriple *bezt)
        if (ked->data) {
                short ok = 0;
                
-#define KEY_CHECK_OK(_index) bezier_region_circle_test(ked->data, bezt->vec[_index])
+#define KEY_CHECK_OK(_index) keyframe_region_circle_test(ked->data, bezt->vec[_index])
                KEYFRAME_OK_CHECKS(KEY_CHECK_OK);
 #undef KEY_CHECK_OK
                
@@ -661,7 +661,7 @@ static short ok_bezier_channel_circle(KeyframeEditData *ked, BezTriple *bezt)
                pt[0] = bezt->vec[1][0];
                pt[1] = ked->channel_y;
                
-               if (bezier_region_circle_test(data, pt))
+               if (keyframe_region_circle_test(data, pt))
                        return KEYFRAME_OK_KEY;
        }
        return 0;
index a49b33621558bb2c118a52cf3dbcc81cebc03b56..738496a67c6ac72a333922d0a30f046df11a8891 100644 (file)
@@ -205,6 +205,36 @@ void ED_gplayer_frames_select_border(bGPDlayer *gpl, float min, float max, short
        }
 }
 
+/* select the frames in this layer that occur within the lasso/circle region specified */
+void ED_gplayer_frames_select_region(KeyframeEditData *ked, bGPDlayer *gpl, short tool, short select_mode)
+{
+       bGPDframe *gpf;
+       
+       if (gpl == NULL)
+               return;
+       
+       /* only select frames which are within the region */
+       for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
+               /* construct a dummy point coordinate to do this testing with */
+               float pt[2] = {0};
+               
+               pt[0] = gpf->framenum;
+               pt[1] = ked->channel_y;
+               
+               /* check the necessary regions */
+               if (tool == BEZT_OK_CHANNEL_LASSO) {
+                       /* Lasso */     
+                       if (keyframe_region_lasso_test(ked->data, pt))
+                               gpframe_select(gpf, select_mode);
+               }
+               else if (tool == BEZT_OK_CHANNEL_CIRCLE) {
+                       /* Circle */
+                       if (keyframe_region_circle_test(ked->data, pt))
+                               gpframe_select(gpf, select_mode);
+               }
+       }
+}
+
 /* ***************************************** */
 /* Frame Editing Tools */
 
index 255827db37348d8d7a82f644ec44231ea6d48ec6..de5ab80a88f5b6fbbc3525cddf440883aa51d470 100644 (file)
@@ -42,6 +42,7 @@ struct bGPDlayer;
 struct bGPDframe;
 struct bGPDstroke;
 struct bAnimContext;
+struct KeyframeEditData;
 struct PointerRNA;
 struct wmWindowManager;
 struct wmKeyConfig;
@@ -120,6 +121,7 @@ void ED_gplayer_make_cfra_list(struct bGPDlayer *gpl, ListBase *elems, bool only
 bool  ED_gplayer_frame_select_check(struct bGPDlayer *gpl);
 void  ED_gplayer_frame_select_set(struct bGPDlayer *gpl, short mode);
 void  ED_gplayer_frames_select_border(struct bGPDlayer *gpl, float min, float max, short select_mode);
+void  ED_gplayer_frames_select_region(struct KeyframeEditData *ked, struct bGPDlayer *gpl, short tool, short select_mode);
 void  ED_gpencil_select_frames(struct bGPDlayer *gpl, short select_mode);
 void  ED_gpencil_select_frame(struct bGPDlayer *gpl, int selx, short select_mode);
 
index 0d352ab5eadeb18b4fa4d672523aa4526bd3c987..c0eb88cd982e0952b1f236194298ac7d13e83586 100644 (file)
@@ -266,6 +266,18 @@ short bezt_to_cfraelem(KeyframeEditData *ked, struct BezTriple *bezt);
  */
 void bezt_remap_times(KeyframeEditData *ked, struct BezTriple *bezt);
 
+/* ------ 1.5-D Region Testing Uitls (Lasso/Circle Select) ------- */
+/* XXX: These are temporary, until we can unify GP/Mask Keyframe handling and standard FCurve Keyframe handling */
+
+bool keyframe_region_lasso_test(
+        const KeyframeEdit_LassoData *data_lasso,
+        const float xy[2]);
+
+bool keyframe_region_circle_test(
+        const KeyframeEdit_CircleData *data_circle,
+        const float xy[2]);
+
+
 /* ************************************************ */
 /* Destructive Editing API (keyframes_general.c) */
 
index c9a4922eb0b41be76183cc2e0694f8292326ab97..62050f129a99ad057558fe3115642e763739addb 100644 (file)
@@ -468,13 +468,13 @@ static void region_select_action_keys(bAnimContext *ac, const rctf *rectf_view,
                                        bGPdata *gpd = ale->data;
                                        bGPDlayer *gpl;
                                        for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
-                                               //ED_gplayer_frames_select_border(gpl, rectf.xmin, rectf.xmax, selectmode);
+                                               ED_gplayer_frames_select_region(&ked, ale->data, mode, selectmode);
                                        }
                                        break;
                                }
                                case ANIMTYPE_GPLAYER:
                                {
-                                       //ED_gplayer_frames_select_border(ale->data, rectf.xmin, rectf.xmax, selectmode);
+                                       ED_gplayer_frames_select_region(&ked, ale->data, mode, selectmode);
                                        break;
                                }
                                case ANIMTYPE_MASKDATABLOCK: