Commit: f01a10d07de02b363fcc91071198dfeb17f8eeca
Author: Joshua Leung
Date:   Thu Oct 23 17:50:14 2014 +1300
Branches: GPencil_EditStrokes
https://developer.blender.org/rBf01a10d07de02b363fcc91071198dfeb17f8eeca

GPencil: Refactor out space conversion APIs in response to Sergey's changes

===================================================================

M       source/blender/editors/gpencil/CMakeLists.txt
M       source/blender/editors/gpencil/gpencil_intern.h
M       source/blender/editors/gpencil/gpencil_paint.c
M       source/blender/editors/gpencil/gpencil_select.c
A       source/blender/editors/gpencil/gpencil_utils.c

===================================================================

diff --git a/source/blender/editors/gpencil/CMakeLists.txt 
b/source/blender/editors/gpencil/CMakeLists.txt
index 5175f84..581344b 100644
--- a/source/blender/editors/gpencil/CMakeLists.txt
+++ b/source/blender/editors/gpencil/CMakeLists.txt
@@ -45,6 +45,7 @@ set(SRC
        gpencil_paint.c
        gpencil_select.c
        gpencil_undo.c
+       gpencil_utils.c
 
        gpencil_intern.h
 )
diff --git a/source/blender/editors/gpencil/gpencil_intern.h 
b/source/blender/editors/gpencil/gpencil_intern.h
index f2745f6..ae79e74 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -31,23 +31,40 @@
 #ifndef __GPENCIL_INTERN_H__
 #define __GPENCIL_INTERN_H__
 
-/* internal exports only */
 
+#include "DNA_vec_types.h"
+
+
+/* internal exports only */
 struct bGPdata;
 struct bGPDstroke;
 struct bGPDspoint;
 
 struct ARegion;
 struct View2D;
-struct rctf;
 struct wmOperatorType;
 
 
-
 /* ***************************************************** */
 /* Internal API */
 
 /* Stroke Coordinates API ------------------------------ */
+/* gpencil_utils.c */
+
+typedef struct GP_SpaceConversion {
+       struct bGPdata *gpd;
+       struct bGPDlayer *gpl;
+       
+       struct ScrArea *sa;
+       struct ARegion *ar;
+       struct View2D *v2d;
+       
+       rctf *subrect;       /* for using the camera rect within the 3d view */
+       rctf subrect_data;
+       
+       float mat[4][4];     /* transform matrix on the strokes (introduced in 
[b770964]) */
+} GP_SpaceConversion;
+
 
 /** 
  * Check whether a given stroke segment is inside a circular brush 
@@ -62,15 +79,21 @@ struct wmOperatorType;
 bool gp_stroke_inside_circle(const int mval[2], const int UNUSED(mvalo[2]),
                              int rad, int x0, int y0, int x1, int y1);
 
+
+/**
+ * Init settings for stroke point space conversions 
+ *
+ * \param[out] r_gsc  The space conversion settings struct, populated with 
necessary params
+ */
+void gp_point_conversion_init(struct bContext *C, GP_SpaceConversion *r_gsc);
+
 /**
  * Convert a Grease Pencil coordinate (i.e. can be 2D or 3D) to screenspace 
(2D)
  *
- * \param subrect   For the camera view in the 3D Viewport
  * \param[out] r_x  The screen-space x-coordinate of the point
  * \param[out] r_y  The screen-space y-coordinate of the point
  */
-/* gpencil_paint.c */
-void gp_point_to_xy(struct ARegion *ar, struct View2D *v2d, struct rctf 
*subrect, struct bGPDstroke *gps, struct bGPDspoint *pt,
+void gp_point_to_xy(GP_SpaceConversion *settings, struct bGPDstroke *gps, 
struct bGPDspoint *pt,
                     int *r_x, int *r_y);
 
 /* ***************************************************** */
diff --git a/source/blender/editors/gpencil/gpencil_paint.c 
b/source/blender/editors/gpencil/gpencil_paint.c
index 4c04a6f..605c74f 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -86,6 +86,8 @@ typedef struct tGPsdata {
        rctf *subrect;      /* for using the camera rect within the 3d view */
        rctf subrect_data;
        
+       GP_SpaceConversion gsc; /* settings to pass to gp_points_to_xy() */
+       
        PointerRNA ownerPtr; /* pointer to owner of gp-datablock */
        bGPdata *gpd;       /* gp-datablock layer comes from */
        bGPDlayer *gpl;     /* layer we're working on */
@@ -875,61 +877,6 @@ static bool gp_stroke_eraser_is_occluded(tGPsdata *p,
        return false;
 }
 
-/* eraser tool - check if part of stroke occurs within last segment drawn by 
eraser */
-bool gp_stroke_inside_circle(const int mval[2], const int UNUSED(mvalo[2]),
-                             int rad, int x0, int y0, int x1, int y1)
-{
-       /* simple within-radius check for now */
-       const float mval_fl[2]     = {mval[0], mval[1]};
-       const float screen_co_a[2] = {x0, y0};
-       const float screen_co_b[2] = {x1, y1};
-       
-       if (edge_inside_circle(mval_fl, rad, screen_co_a, screen_co_b)) {
-               return true;
-       }
-       
-       /* not inside */
-       return false;
-} 
-
-
-void gp_point_to_xy(ARegion *ar, View2D *v2d, rctf *subrect, bGPDstroke *gps, 
bGPDspoint *pt,
-                    int *r_x, int *r_y)
-//static void gp_point_to_xy(tGPsdata *p, bGPDstroke *gps, bGPDspoint *pt,
-//                           int *r_x, int *r_y)
-{
-       ARegion *ar = p->ar;
-       View2D *v2d = p->v2d;
-       rctf *subrect = p->subrect;
-       int xyval[2];
-
-       if (gps->flag & GP_STROKE_3DSPACE) {
-               if (ED_view3d_project_int_global(ar, &pt->x, xyval, 
V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
-                       *r_x = xyval[0];
-                       *r_y = xyval[1];
-               }
-               else {
-                       *r_x = V2D_IS_CLIPPED;
-                       *r_y = V2D_IS_CLIPPED;
-               }
-       }
-       else if (gps->flag & GP_STROKE_2DSPACE) {
-               float vec[3] = {pt->x, pt->y, 0.0f};
-               mul_m4_v3(p->mat, vec);
-               UI_view2d_view_to_region_clip(v2d, vec[0], vec[1], r_x, r_y);
-       }
-       else {
-               if (subrect == NULL) { /* normal 3D view */
-                       *r_x = (int)(pt->x / 100 * ar->winx);
-                       *r_y = (int)(pt->y / 100 * ar->winy);
-               }
-               else { /* camera view, use subrect */
-                       *r_x = (int)((pt->x / 100) * BLI_rctf_size_x(subrect)) 
+ subrect->xmin;
-                       *r_y = (int)((pt->y / 100) * BLI_rctf_size_y(subrect)) 
+ subrect->ymin;
-               }
-       }
-}
-
 
 /* eraser tool - evaluation per stroke */
 /* TODO: this could really do with some optimization (KD-Tree/BVH?) */
@@ -948,7 +895,7 @@ static void gp_stroke_eraser_dostroke(tGPsdata *p,
                BLI_freelinkN(&gpf->strokes, gps);
        }
        else if (gps->totpoints == 1) {
-               gp_point_to_xy(p, gps, gps->points, &x0, &y0);
+               gp_point_to_xy(&p->gsc, gps, gps->points, &x0, &y0);
                
                /* do boundbox check first */
                if ((!ELEM(V2D_IS_CLIPPED, x0, y0)) && BLI_rcti_isect_pt(rect, 
x0, y0)) {
@@ -969,8 +916,8 @@ static void gp_stroke_eraser_dostroke(tGPsdata *p,
                        pt1 = gps->points + i;
                        pt2 = gps->points + i + 1;
                        
-                       gp_point_to_xy(p, gps, pt1, &x0, &y0);
-                       gp_point_to_xy(p, gps, pt2, &x1, &y1);
+                       gp_point_to_xy(&p->gsc, gps, pt1, &x0, &y0);
+                       gp_point_to_xy(&p->gsc, gps, pt2, &x1, &y1);
                        
                        /* check that point segment of the boundbox of the 
eraser stroke */
                        if (((!ELEM(V2D_IS_CLIPPED, x0, y0)) && 
BLI_rcti_isect_pt(rect, x0, y0)) ||
@@ -1157,7 +1104,9 @@ static int gp_session_initdata(bContext *C, tGPsdata *p)
                                p->imat[3][0] -= marker->pos[0];
                                p->imat[3][1] -= marker->pos[1];
                        }
+                       
                        invert_m4_m4(p->mat, p->imat);
+                       copy_m4_m4(p->gsc.mat, p->mat);
                        break;
                }
                /* unsupported views */
@@ -1293,7 +1242,19 @@ static void gp_paint_initstroke(tGPsdata *p, short 
paintmode)
                        }
                }
        }
-
+       
+       /* init stroke point space-conversion settings... */
+       p->gsc.gpd = p->gpd;
+       p->gsc.gpl = p->gpl;
+       
+       p->gsc.sa = p->sa;
+       p->gsc.ar = p->ar;
+       p->gsc.v2d = p->v2d;
+       
+       p->gsc.subrect_data = p->subrect_data;
+       p->gsc.subrect = p->subrect;
+       
+       
        /* check if points will need to be made in view-aligned space */
        if (p->gpd->flag & GP_DATA_VIEWALIGN) {
                switch (p->sa->spacetype) {
diff --git a/source/blender/editors/gpencil/gpencil_select.c 
b/source/blender/editors/gpencil/gpencil_select.c
index 7e07c23..681ea75 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -209,7 +209,7 @@ void GPENCIL_OT_select_all(wmOperatorType *ot)
 /* NOTE: Code here is adapted (i.e. copied directly) from 
gpencil_paint.c::gp_stroke_eraser_dostroke()
  *       It would be great to de-duplicate the logic here sometime, but that 
can wait...
  */
-static bool gp_stroke_do_circle_sel(bGPDstroke *gps, ARegion *ar, View2D *v2d, 
rctf *subrect,
+static bool gp_stroke_do_circle_sel(bGPDstroke *gps, GP_SpaceConversion *gsc,
                                     const int mx, const int my, const int 
radius, 
                                     const bool select, rcti *rect)
 {
@@ -219,7 +219,7 @@ static bool gp_stroke_do_circle_sel(bGPDstroke *gps, 
ARegion *ar, View2D *v2d, r
        bool changed = false;
        
        if (gps->totpoints == 1) {
-               gp_point_to_xy(ar, v2d, subrect, gps, gps->points, &x0, &y0);
+               gp_point_to_xy(gsc, gps, gps->points, &x0, &y0);
                
                /* do boundbox check first */
                if ((!ELEM(V2D_IS_CLIPPED, x0, y0)) && BLI_rcti_isect_pt(rect, 
x0, y0)) {
@@ -248,8 +248,8 @@ static bool gp_stroke_do_circle_sel(bGPDstroke *gps, 
ARegion *ar, View2D *v2d, r
                        pt1 = gps->points + i;
                        pt2 = gps->points + i + 1;
                        
-                       gp_point_to_xy(ar, v2d, subrect, gps, pt1, &x0, &y0);
-                       gp_point_to_xy(ar, v2d, subrect, gps, pt2, &x1, &y1);
+                       gp_point_to_xy(gsc, gps, pt1, &x0, &y0);
+                       gp_point_to_xy(gsc, gps, pt2, &x1, &y1);
                        
                        /* check that point segment of the boundbox of the 
selection stroke */
                        if (((!ELEM(V2D_IS_CLIPPED, x0, y0)) && 
BLI_rcti_isect_pt(rect, x0, y0)) ||
@@ -296,8 +296,6 @@ static int gpencil_circle_select_exec(bContext *C, 
wmOperator *op)
        ScrArea *sa = CTX_wm_area(C);
        ARegion *ar = CTX_wm_region(C);
        
-       
-       
        const int mx = RNA_int_get(op->ptr, "x");
        const int my = RNA_int_get(op->ptr, "y");
        const int radius = RNA_int_get(op->ptr, "radius");
@@ -305,36 +303,21 @@ static int gpencil_circle_select_exec(bContext *C, 
wmOperator *op)
        const int gesture_mode = RNA_int_get(op->ptr, "gesture_mode");
        const bool select = (gesture_mode == GESTURE_MODAL_SELECT);
        
-       rctf *subrect = NULL;       /* for using the camera rect within the 3d 
view */
-       rctf subrect_data = {0.0f};
+       GP_SpaceConversion gsc = {0};
        rcti rect = {0};            /* for bounding rect around circle (for 
quicky intersection testing) */
        
        bool changed = false;
        
+       
        /* sanity checks */
        if (sa == NULL) {
                BKE_report(op->reports, RPT_ERROR, "No active area");
                return OPERATOR_CANCELLED;
        }
        
-       /* for 3D View, init depth buffer stuff used for 3D projections... */
-       if (sa->spacetype == SPACE_VIEW3D) {
-               wmWindow *win = CTX_wm_window(C);
-               Scene *scene = CTX_data_scene(C);
-               View3D *v3d = (View3D *)CTX_wm_space_data(C);
-               RegionView3D *rv3d = ar->regiondata;
-               
-               /* init 3d depth buffers */
-               view3d_operator_needs_opengl(C);
-               view3d_region_operator_needs_opengl(win, ar);
-               ED_view3d_autodist_init(scene, ar, v3d, 0);
-               
-               /* for camera view set the subrect */
-               if (rv3d->persp == RV3D_CAMOB) {
-                       ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, 
&subrect_data, true); /* no shift */
-                       subrect = &subrect_data;
-               }
-       }
+       /* init space conversion stuff */
+       gp_point_conversion_init(C, &gsc);
+       
        
        /* rect is rectangle of selection cir

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to