Bugfixes for Grease Pencil and the Image Editor (includes fix for #20921):
authorJoshua Leung <aligorith@gmail.com>
Mon, 5 Apr 2010 06:52:27 +0000 (06:52 +0000)
committerJoshua Leung <aligorith@gmail.com>
Mon, 5 Apr 2010 06:52:27 +0000 (06:52 +0000)
* Fixed crash with when/after undoing Grease Pencil sketches in the Image Editor. To get this working, I've had to sacrifice the backwards-compat loading for old .blend files from 2.49 which were using the same pointer as the new data (local data vs datablock data). If anyone has any ingenious hacks to fix this, go ahead, but otherwise, some caution is advised here...

* Grease Pencil block used for Image Editor instances can now be changed

* Enabled proper active polls on the advanced 3D-view projection methods for drawing. These are not valid in views other than the 3D-View, and so should not be shown as available for use elsewhere (though may still be shown just so that users know what mode an 'imported' datablock may be using).

* Enabled proper updates for Grease Pencil editing in the Image Editor. Was missing notifiers for this stuff.

* When drawing in the Image Editor with no image active, the system now (quietly) switches to using screen-space 'view' vs 'cursor' space for the strokes, since the previous behaviour was confusing with strokes disappearing after drawing them. IMO this is a much better option than the confusion that occurred before, even though it does change the user's settings under their feet!

source/blender/blenloader/intern/readfile.c
source/blender/editors/gpencil/gpencil_buttons.c
source/blender/editors/gpencil/gpencil_paint.c
source/blender/editors/space_image/space_image.c
source/blender/makesrna/intern/rna_space.c

index b23b0edb285828db2a3eb2f0c0b96995c3278ada..856b4eaa8ba5f6aa5f59f742d44d5a906261b928 100644 (file)
@@ -4610,6 +4610,11 @@ static void lib_link_screen(FileData *fd, Main *main)
                                                SpaceImage *sima= (SpaceImage *)sl;
 
                                                sima->image= newlibadr_us(fd, sc->id.lib, sima->image);
+                                               
+                                               /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data
+                                                * so fingers crossed this works fine!
+                                                */
+                                               sima->gpd= newlibadr_us(fd, sc->id.lib, sima->gpd);
                                        }
                                        else if(sl->spacetype==SPACE_NLA){
                                                SpaceNla *snla= (SpaceNla *)sl;
@@ -4824,6 +4829,11 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene)
                                        SpaceImage *sima= (SpaceImage *)sl;
 
                                        sima->image= restore_pointer_by_name(newmain, (ID *)sima->image, 1);
+                                       
+                                       /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data
+                                        * so assume that here we're doing for undo only...
+                                        */
+                                       sima->gpd= restore_pointer_by_name(newmain, (ID *)sima->gpd, 1);
                                }
                                else if(sl->spacetype==SPACE_NLA){
                                        SpaceNla *snla= (SpaceNla *)sl;
@@ -5086,13 +5096,18 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
                                SpaceImage *sima= (SpaceImage *)sl;
                                
                                sima->cumap= newdataadr(fd, sima->cumap);
-                               sima->gpd= newdataadr(fd, sima->gpd);
-                               if (sima->gpd)
-                                       direct_link_gpencil(fd, sima->gpd);
                                if(sima->cumap)
                                        direct_link_curvemapping(fd, sima->cumap);
+                               
                                sima->iuser.scene= NULL;
                                sima->iuser.ok= 1;
+                               
+                               /* WARNING: gpencil data is no longer stored directly in sima after 2.5 
+                                * so sacrifice a few old files for now to avoid crashes with new files!
+                                */
+                               //sima->gpd= newdataadr(fd, sima->gpd);
+                               //if (sima->gpd)
+                               //      direct_link_gpencil(fd, sima->gpd);
                        }
                        else if(sl->spacetype==SPACE_NODE) {
                                SpaceNode *snode= (SpaceNode *)sl;
index cc4a05c34219b3c647f079e9715380c3292b034e..e719d9ab3923322cae93d1dbc3006cab2333353f 100644 (file)
@@ -227,6 +227,7 @@ static void draw_gpencil_panel (bContext *C, uiLayout *layout, bGPdata *gpd, Poi
        PointerRNA gpd_ptr;
        bGPDlayer *gpl;
        uiLayout *col, *row;
+       short v3d_stroke_opts_on = 0;
        
        /* make new PointerRNA for Grease Pencil block */
        RNA_id_pointer_create((ID *)gpd, &gpd_ptr);
@@ -255,17 +256,24 @@ static void draw_gpencil_panel (bContext *C, uiLayout *layout, bGPdata *gpd, Poi
                /* label */
                uiItemL(col, "Drawing Settings:", 0);
                
-               /* 'stick to view' option */
+               /* check whether advanced 3D-View drawing space options can be used */
+               if (CTX_wm_view3d(C)) {
+                       if (gpd->flag & (GP_DATA_DEPTH_STROKE|GP_DATA_DEPTH_VIEW))
+                               v3d_stroke_opts_on = 1;
+               }
+               
+               /* drawing space options */
                row= uiLayoutRow(col, 1);
-               uiItemEnumR_string(row, &gpd_ptr, "draw_mode", "VIEW", NULL, 0);
-               uiItemEnumR_string(row, &gpd_ptr, "draw_mode", "CURSOR", NULL, 0);
+                       uiItemEnumR_string(row, &gpd_ptr, "draw_mode", "VIEW", NULL, 0);
+                       uiItemEnumR_string(row, &gpd_ptr, "draw_mode", "CURSOR", NULL, 0);
                row= uiLayoutRow(col, 1);
-               uiItemEnumR_string(row, &gpd_ptr, "draw_mode", "SURFACE", NULL, 0);
-               uiItemEnumR_string(row, &gpd_ptr, "draw_mode", "STROKE", NULL, 0);
+                       uiLayoutSetActive(row, v3d_stroke_opts_on);
+                       uiItemEnumR_string(row, &gpd_ptr, "draw_mode", "SURFACE", NULL, 0);
+                       uiItemEnumR_string(row, &gpd_ptr, "draw_mode", "STROKE", NULL, 0);
                
                row= uiLayoutRow(col, 0);
-               uiLayoutSetActive(row, (gpd->flag & (GP_DATA_DEPTH_STROKE|GP_DATA_DEPTH_VIEW)) ? 1:0);
-               uiItemR(row, &gpd_ptr, "use_stroke_endpoints", 0, NULL, 0);
+                       uiLayoutSetActive(row, v3d_stroke_opts_on);
+                       uiItemR(row, &gpd_ptr, "use_stroke_endpoints", 0, NULL, 0);
 }      
 
 
index 59c9150fc148eeae4e0bc53a3ded49a2ae6636d3..c4df1bde1c297a70d01196f912263b10081e10cb 100644 (file)
@@ -1096,7 +1096,20 @@ static void gp_paint_initstroke (tGPsdata *p, short paintmode)
 #endif
                        case SPACE_IMAGE:
                        {
-                               p->gpd->sbuffer_sflag |= GP_STROKE_2DSPACE;
+                               SpaceImage *sima= (SpaceImage *)p->sa->spacedata.first;
+                               
+                               /* only set these flags if the image editor doesn't have an image active,
+                                * otherwise user will be confused by strokes not appearing after they're drawn
+                                *
+                                * Admittedly, this is a bit hacky, but it works much nicer from an ergonomic standpoint!
+                                */
+                               if ELEM(NULL, sima, sima->image) {
+                                       /* make strokes be drawn in screen space */
+                                       p->gpd->sbuffer_sflag &= ~GP_STROKE_2DSPACE;
+                                       p->gpd->flag &= ~GP_DATA_VIEWALIGN;
+                               }       
+                               else
+                                       p->gpd->sbuffer_sflag |= GP_STROKE_2DSPACE;
                        }
                                break;
                }
index e641f720054298c2fbe3455c11aa2c6d9f1d23b2..0eb377450e966f93918447bebc9056512b015060 100644 (file)
@@ -781,7 +781,10 @@ static void image_main_area_listener(ARegion *ar, wmNotifier *wmn)
 {
        /* context changes */
        switch(wmn->category) {
-               /* nothing yet */
+               case NC_SCREEN:
+                       if (wmn->data==ND_GPENCIL)
+                               ED_region_tag_redraw(ar);
+               break;
        }
 }
 
@@ -807,6 +810,10 @@ static void image_buttons_area_listener(ARegion *ar, wmNotifier *wmn)
 {
        /* context changes */
        switch(wmn->category) {
+               case NC_SCREEN:
+                       if (wmn->data==ND_GPENCIL)
+                               ED_region_tag_redraw(ar);
+                       break;
                case NC_BRUSH:
                        if(wmn->action==NA_EDITED)
                                ED_region_tag_redraw(ar);
index 8dad6f5c435d53f19866e782126edc0b10cb23a9..8b3a54af4c2b0f95851a2b647cc3690de57bdf9e 100644 (file)
@@ -1263,7 +1263,8 @@ static void rna_def_space_image(BlenderRNA *brna)
        /* grease pencil */
        prop= RNA_def_property(srna, "grease_pencil", PROP_POINTER, PROP_NONE);
        RNA_def_property_pointer_sdna(prop, NULL, "gpd");
-       RNA_def_property_struct_type(prop, "UnknownType");
+       RNA_def_property_flag(prop, PROP_EDITABLE);
+       RNA_def_property_struct_type(prop, "GreasePencil");
        RNA_def_property_ui_text(prop, "Grease Pencil", "Grease pencil data for this space");
 
        prop= RNA_def_property(srna, "use_grease_pencil", PROP_BOOLEAN, PROP_NONE);