[Bf-blender-cvs] [84936ce0ee5] master: Defaults: refactor startup.blend code, more consistely apply to templates

Brecht Van Lommel noreply at git.blender.org
Thu Jun 13 17:56:59 CEST 2019


Commit: 84936ce0ee51453a8690a41e8eda8c7d424c928e
Author: Brecht Van Lommel
Date:   Thu Jun 13 17:40:04 2019 +0200
Branches: master
https://developer.blender.org/rB84936ce0ee51453a8690a41e8eda8c7d424c928e

Defaults: refactor startup.blend code, more consistely apply to templates

There were various changes only applied to specific builtin templates even
though they should apply to all, since it's possible to do e.g. use grease
pencil objects in the general template or use mesh sculpting in the grease
pencil template.

Also, nearly all changes now apply to builtin templates only. This was
already the case for most, and the distinction seems to have been more by
accident than intent.

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

M	source/blender/blenloader/intern/versioning_defaults.c

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

diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c
index 5b241d613e3..617329ef5f2 100644
--- a/source/blender/blenloader/intern/versioning_defaults.c
+++ b/source/blender/blenloader/intern/versioning_defaults.c
@@ -152,315 +152,285 @@ static ID *rename_id_for_versioning(Main *bmain,
   return id;
 }
 
-/**
- * Update defaults in startup.blend, without having to save and embed the file.
- * This function can be emptied each time the startup.blend is updated. */
-void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
+static bool blo_is_builtin_template(const char *app_template)
 {
   /* For all builtin templates shipped with Blender. */
-  const bool builtin_template =
-      (!app_template ||
-       STR_ELEM(app_template, "2D_Animation", "Sculpting", "VFX", "Video_Editing"));
-
-  /* For all startup.blend files. */
-  for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
-    for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
-      for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
-        if (builtin_template) {
-          /* Remove all stored panels, we want to use defaults
-           * (order, open/closed) as defined by UI code here! */
-          BKE_area_region_panels_free(&ar->panels);
-          BLI_freelistN(&ar->panels_category_active);
-
-          /* Reset size so it uses consistent defaults from the region types. */
-          ar->sizex = 0;
-          ar->sizey = 0;
-        }
+  return (!app_template ||
+          STR_ELEM(app_template, "2D_Animation", "Sculpting", "VFX", "Video_Editing"));
+}
 
-        /* some toolbars have been saved as initialized,
-         * we don't want them to have odd zoom-level or scrolling set, see: T47047 */
-        if (ELEM(ar->regiontype, RGN_TYPE_UI, RGN_TYPE_TOOLS, RGN_TYPE_TOOL_PROPS)) {
-          ar->v2d.flag &= ~V2D_IS_INITIALISED;
-        }
+static void blo_update_defaults_screen(bScreen *screen,
+                                       const char *app_template,
+                                       const char *workspace_name)
+{
+  /* For all app templates. */
+  for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+    for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
+      /* Some toolbars have been saved as initialized,
+       * we don't want them to have odd zoom-level or scrolling set, see: T47047 */
+      if (ELEM(ar->regiontype, RGN_TYPE_UI, RGN_TYPE_TOOLS, RGN_TYPE_TOOL_PROPS)) {
+        ar->v2d.flag &= ~V2D_IS_INITIALISED;
       }
+    }
 
-      for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
-        switch (sl->spacetype) {
-          case SPACE_VIEW3D: {
-            View3D *v3d = (View3D *)sl;
-            v3d->overlay.texture_paint_mode_opacity = 1.0f;
-            v3d->overlay.weight_paint_mode_opacity = 1.0f;
-            v3d->overlay.vertex_paint_mode_opacity = 1.0f;
-            /* Use dimmed selected edges. */
-            v3d->overlay.edit_flag &= ~V3D_OVERLAY_EDIT_EDGES;
-            /* grease pencil settings */
-            v3d->vertex_opacity = 1.0f;
-            v3d->gp_flag |= V3D_GP_SHOW_EDIT_LINES;
-            /* Remove dither pattern in wireframe mode. */
-            v3d->shading.xray_alpha_wire = 0.0f;
-            /* Skip startups that use the viewport color by default. */
-            if (v3d->shading.background_type != V3D_SHADING_BACKGROUND_VIEWPORT) {
-              copy_v3_fl(v3d->shading.background_color, 0.05f);
-            }
-            break;
-          }
-          case SPACE_FILE: {
-            SpaceFile *sfile = (SpaceFile *)sl;
-            if (sfile->params) {
-              const char *dir_default = BKE_appdir_folder_default();
-              if (dir_default) {
-                STRNCPY(sfile->params->dir, dir_default);
-                sfile->params->file[0] = '\0';
-              }
-            }
-            break;
+    /* Set default folder. */
+    for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
+      if (sl->spacetype == SPACE_FILE) {
+        SpaceFile *sfile = (SpaceFile *)sl;
+        if (sfile->params) {
+          const char *dir_default = BKE_appdir_folder_default();
+          if (dir_default) {
+            STRNCPY(sfile->params->dir, dir_default);
+            sfile->params->file[0] = '\0';
           }
         }
       }
     }
   }
 
-  if (builtin_template) {
-    /* Name all screens by their workspaces (avoids 'Default.###' names). */
-    /* Default only has one window. */
-    wmWindow *win = ((wmWindowManager *)bmain->wm.first)->windows.first;
-    for (WorkSpace *workspace = bmain->workspaces.first; workspace;
-         workspace = workspace->id.next) {
-      WorkSpaceLayout *layout = BKE_workspace_hook_layout_for_workspace_get(win->workspace_hook,
-                                                                            workspace);
-      bScreen *screen = layout->screen;
-      BLI_strncpy(screen->id.name + 2, workspace->id.name + 2, sizeof(screen->id.name) - 2);
-      BLI_libblock_ensure_unique_name(bmain, screen->id.name);
-    }
+  /* For builtin templates only. */
+  if (!blo_is_builtin_template(app_template)) {
+    return;
   }
 
-  if (app_template == NULL) {
-    /* 'UV Editing' should use UV mode. */
-    bScreen *screen = BLI_findstring(&bmain->screens, "UV Editing", offsetof(ID, name) + 2);
-    for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
-      for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
-        if (sl->spacetype == SPACE_IMAGE) {
-          SpaceImage *sima = (SpaceImage *)sl;
-          if (sima->mode == SI_MODE_VIEW) {
-            sima->mode = SI_MODE_UV;
-          }
+  for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+    for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
+      /* Remove all stored panels, we want to use defaults
+       * (order, open/closed) as defined by UI code here! */
+      BKE_area_region_panels_free(&ar->panels);
+      BLI_freelistN(&ar->panels_category_active);
+
+      /* Reset size so it uses consistent defaults from the region types. */
+      ar->sizex = 0;
+      ar->sizey = 0;
+    }
+
+    if (sa->spacetype == SPACE_IMAGE) {
+      if (STREQ(workspace_name, "UV Editing")) {
+        SpaceImage *sima = sa->spacedata.first;
+        if (sima->mode == SI_MODE_VIEW) {
+          sima->mode = SI_MODE_UV;
         }
       }
     }
-  }
+    else if (sa->spacetype == SPACE_ACTION) {
+      /* Show marker lines, hide channels and collapse summary in timelines. */
+      SpaceAction *saction = sa->spacedata.first;
+      saction->flag |= SACTION_SHOW_MARKER_LINES;
 
-  /* For 2D animation template. */
-  if (app_template && STREQ(app_template, "2D_Animation")) {
-    for (WorkSpace *workspace = bmain->workspaces.first; workspace;
-         workspace = workspace->id.next) {
-      const char *name = workspace->id.name + 2;
+      if (saction->mode == SACTCONT_TIMELINE) {
+        saction->ads.flag |= ADS_FLAG_SUMMARY_COLLAPSED;
 
-      if (STREQ(name, "Drawing")) {
-        workspace->object_mode = OB_MODE_PAINT_GPENCIL;
+        for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
+          if (ar->regiontype == RGN_TYPE_CHANNELS) {
+            ar->flag |= RGN_FLAG_HIDDEN;
+          }
+        }
       }
     }
-    /* set object in drawing mode */
-    for (Object *object = bmain->objects.first; object; object = object->id.next) {
-      if (object->type == OB_GPENCIL) {
-        bGPdata *gpd = (bGPdata *)object->data;
-        object->mode = OB_MODE_PAINT_GPENCIL;
-        gpd->flag |= GP_DATA_STROKE_PAINTMODE;
-        break;
-      }
+    else if (sa->spacetype == SPACE_GRAPH) {
+      SpaceGraph *sipo = sa->spacedata.first;
+      sipo->flag |= SIPO_MARKER_LINES;
     }
-
-    /* Be sure curfalloff and primitive are initializated */
-    for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
-      ToolSettings *ts = scene->toolsettings;
-      if (ts->gp_sculpt.cur_falloff == NULL) {
-        ts->gp_sculpt.cur_falloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
-        CurveMapping *gp_falloff_curve = ts->gp_sculpt.cur_falloff;
-        curvemapping_initialize(gp_falloff_curve);
-        curvemap_reset(gp_falloff_curve->cm,
-                       &gp_falloff_curve->clipr,
-                       CURVE_PRESET_GAUSS,
-                       CURVEMAP_SLOPE_POSITIVE);
-      }
-      if (ts->gp_sculpt.cur_primitive == NULL) {
-        ts->gp_sculpt.cur_primitive = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
-        CurveMapping *gp_primitive_curve = ts->gp_sculpt.cur_primitive;
-        curvemapping_initialize(gp_primitive_curve);
-        curvemap_reset(gp_primitive_curve->cm,
-                       &gp_primitive_curve->clipr,
-                       CURVE_PRESET_BELL,
-                       CURVEMAP_SLOPE_POSITIVE);
+    else if (sa->spacetype == SPACE_NLA) {
+      SpaceNla *snla = sa->spacedata.first;
+      snla->flag |= SNLA_SHOW_MARKER_LINES;
+    }
+    else if (sa->spacetype == SPACE_TEXT) {
+      /* Show syntax and line numbers in Script workspace text editor. */
+      SpaceText *stext = sa->spacedata.first;
+      stext->showsyntax = true;
+      stext->showlinenrs = true;
+    }
+    else if (sa->spacetype == SPACE_VIEW3D) {
+      View3D *v3d = sa->spacedata.first;
+      /* Screen space cavity by default for faster performance. */
+      v3d->shading.cavity_type = V3D_SHADING_CAVITY_CURVATURE;
+      v3d->shading.flag |= V3D_SHADING_SPECULAR_HIGHLIGHT;
+      v3d->overlay.texture_paint_mode_opacity = 1.0f;
+      v3d->overlay.weight_paint_mode_opacity = 1.0f;
+      v3d->overlay.vertex_paint_mode_opacity = 1.0f;
+      /* Use dimmed selected edges. */
+      v3d->overlay.edit_flag &= ~V3D_OVERLAY_EDIT_EDGES;
+      /* grease pencil settings */
+      v3d->vertex_opacity = 1.0f;
+      v3d->gp_flag |= V3D_GP_SHOW_EDIT_LINES;
+      /* Remove dither pattern in wireframe mode. */
+      v3d->shading.xray_alpha_wire = 0.0f;
+      /* Skip startups that use the viewport color by default. */
+      if (v3d->shading.background_type != V3D_SH

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list