diff options
Diffstat (limited to 'source/blender/blenloader/intern/versioning_defaults.c')
-rw-r--r-- | source/blender/blenloader/intern/versioning_defaults.c | 332 |
1 files changed, 177 insertions, 155 deletions
diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c index 80395177100..91d89254c90 100644 --- a/source/blender/blenloader/intern/versioning_defaults.c +++ b/source/blender/blenloader/intern/versioning_defaults.c @@ -71,7 +71,7 @@ static ID *rename_id_for_versioning(Main *bmain, /* We can ignore libraries */ ListBase *lb = which_libbase(bmain, id_type); ID *id = NULL; - for (ID *idtest = lb->first; idtest; idtest = idtest->next) { + LISTBASE_FOREACH (ID *, idtest, lb) { if (idtest->lib == NULL) { if (STREQ(idtest->name + 2, name_src)) { id = idtest; @@ -101,8 +101,8 @@ static void blo_update_defaults_screen(bScreen *screen, const char *workspace_name) { /* For all app templates. */ - for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { - for (ARegion *region = sa->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { /* Some toolbars have been saved as initialized, * we don't want them to have odd zoom-level or scrolling set, see: T47047 */ if (ELEM(region->regiontype, RGN_TYPE_UI, RGN_TYPE_TOOLS, RGN_TYPE_TOOL_PROPS)) { @@ -111,7 +111,7 @@ static void blo_update_defaults_screen(bScreen *screen, } /* Set default folder. */ - for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { if (sl->spacetype == SPACE_FILE) { SpaceFile *sfile = (SpaceFile *)sl; if (sfile->params) { @@ -130,8 +130,8 @@ static void blo_update_defaults_screen(bScreen *screen, return; } - for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { - for (ARegion *region = sa->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { /* Remove all stored panels, we want to use defaults * (order, open/closed) as defined by UI code here! */ BKE_area_region_panels_free(®ion->panels); @@ -142,48 +142,48 @@ static void blo_update_defaults_screen(bScreen *screen, region->sizey = 0; } - if (sa->spacetype == SPACE_IMAGE) { + if (area->spacetype == SPACE_IMAGE) { if (STREQ(workspace_name, "UV Editing")) { - SpaceImage *sima = sa->spacedata.first; + SpaceImage *sima = area->spacedata.first; if (sima->mode == SI_MODE_VIEW) { sima->mode = SI_MODE_UV; } } } - else if (sa->spacetype == SPACE_ACTION) { + else if (area->spacetype == SPACE_ACTION) { /* Show markers region, hide channels and collapse summary in timelines. */ - SpaceAction *saction = sa->spacedata.first; + SpaceAction *saction = area->spacedata.first; saction->flag |= SACTION_SHOW_MARKERS; if (saction->mode == SACTCONT_TIMELINE) { saction->ads.flag |= ADS_FLAG_SUMMARY_COLLAPSED; - for (ARegion *region = sa->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { if (region->regiontype == RGN_TYPE_CHANNELS) { region->flag |= RGN_FLAG_HIDDEN; } } } } - else if (sa->spacetype == SPACE_GRAPH) { - SpaceGraph *sipo = sa->spacedata.first; + else if (area->spacetype == SPACE_GRAPH) { + SpaceGraph *sipo = area->spacedata.first; sipo->flag |= SIPO_SHOW_MARKERS; } - else if (sa->spacetype == SPACE_NLA) { - SpaceNla *snla = sa->spacedata.first; + else if (area->spacetype == SPACE_NLA) { + SpaceNla *snla = area->spacedata.first; snla->flag |= SNLA_SHOW_MARKERS; } - else if (sa->spacetype == SPACE_SEQ) { - SpaceSeq *seq = sa->spacedata.first; - seq->flag |= SEQ_SHOW_MARKERS; + else if (area->spacetype == SPACE_SEQ) { + SpaceSeq *seq = area->spacedata.first; + seq->flag |= SEQ_SHOW_MARKERS | SEQ_SHOW_FCURVES; } - else if (sa->spacetype == SPACE_TEXT) { + else if (area->spacetype == SPACE_TEXT) { /* Show syntax and line numbers in Script workspace text editor. */ - SpaceText *stext = sa->spacedata.first; + SpaceText *stext = area->spacedata.first; stext->showsyntax = true; stext->showlinenrs = true; } - else if (sa->spacetype == SPACE_VIEW3D) { - View3D *v3d = sa->spacedata.first; + else if (area->spacetype == SPACE_VIEW3D) { + View3D *v3d = area->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; @@ -197,24 +197,27 @@ static void blo_update_defaults_screen(bScreen *screen, v3d->gp_flag |= V3D_GP_SHOW_EDIT_LINES; /* Remove dither pattern in wireframe mode. */ v3d->shading.xray_alpha_wire = 0.0f; + v3d->clip_start = 0.01f; /* 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); } + /* Disable Curve Normals. */ + v3d->overlay.edit_flag &= ~V3D_OVERLAY_EDIT_CU_NORMALS; } - else if (sa->spacetype == SPACE_CLIP) { - SpaceClip *sclip = sa->spacedata.first; + else if (area->spacetype == SPACE_CLIP) { + SpaceClip *sclip = area->spacedata.first; sclip->around = V3D_AROUND_CENTER_MEDIAN; } } /* Show tool-header by default (for most cases at least, hide for others). */ const bool hide_image_tool_header = STREQ(workspace_name, "Rendering"); - for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { - for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { - ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase; + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { + ListBase *regionbase = (sl == area->spacedata.first) ? &area->regionbase : &sl->regionbase; - for (ARegion *region = regionbase->first; region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, regionbase) { if (region->regiontype == RGN_TYPE_TOOL_HEADER) { if ((sl->spacetype == SPACE_IMAGE) && hide_image_tool_header) { region->flag |= RGN_FLAG_HIDDEN; @@ -229,20 +232,18 @@ static void blo_update_defaults_screen(bScreen *screen, /* 2D animation template. */ if (app_template && STREQ(app_template, "2D_Animation")) { - for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { - for (ARegion *region = sa->regionbase.first; region; region = region->next) { - if (sa->spacetype == SPACE_ACTION) { - SpaceAction *saction = sa->spacedata.first; - /* Enable Sliders. */ - saction->flag |= SACTION_SLIDERS; - } - else if (sa->spacetype == SPACE_VIEW3D) { - View3D *v3d = sa->spacedata.first; - /* Set Material Color by default. */ - v3d->shading.color_type = V3D_SHADING_MATERIAL_COLOR; - /* Enable Annotations. */ - v3d->flag2 |= V3D_SHOW_ANNOTATION; - } + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + if (area->spacetype == SPACE_ACTION) { + SpaceAction *saction = area->spacedata.first; + /* Enable Sliders. */ + saction->flag |= SACTION_SLIDERS; + } + else if (area->spacetype == SPACE_VIEW3D) { + View3D *v3d = area->spacedata.first; + /* Set Material Color by default. */ + v3d->shading.color_type = V3D_SHADING_MATERIAL_COLOR; + /* Enable Annotations. */ + v3d->flag2 |= V3D_SHOW_ANNOTATION; } } } @@ -250,8 +251,7 @@ static void blo_update_defaults_screen(bScreen *screen, void BLO_update_defaults_workspace(WorkSpace *workspace, const char *app_template) { - ListBase *layouts = BKE_workspace_layouts_get(workspace); - for (WorkSpaceLayout *layout = layouts->first; layout; layout = layout->next) { + LISTBASE_FOREACH (WorkSpaceLayout *, layout, &workspace->layouts) { if (layout->screen) { blo_update_defaults_screen(layout->screen, app_template, workspace->id.name + 2); } @@ -270,13 +270,13 @@ void BLO_update_defaults_workspace(WorkSpace *workspace, const char *app_templat /* For Sculpting template. */ if (STREQ(workspace->id.name + 2, "Sculpting")) { - for (WorkSpaceLayout *layout = layouts->first; layout; layout = layout->next) { + LISTBASE_FOREACH (WorkSpaceLayout *, layout, &workspace->layouts) { bScreen *screen = layout->screen; if (screen) { - for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { - for (ARegion *region = sa->regionbase.first; region; region = region->next) { - if (sa->spacetype == SPACE_VIEW3D) { - View3D *v3d = sa->spacedata.first; + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { + if (area->spacetype == SPACE_VIEW3D) { + View3D *v3d = area->spacedata.first; v3d->shading.flag &= ~V3D_SHADING_CAVITY; copy_v3_fl(v3d->shading.single_color, 1.0f); STRNCPY(v3d->shading.matcap, "basic_1"); @@ -297,7 +297,7 @@ static void blo_update_defaults_scene(Main *bmain, Scene *scene) /* Don't enable compositing nodes. */ if (scene->nodetree) { - ntreeFreeNestedTree(scene->nodetree); + ntreeFreeEmbeddedTree(scene->nodetree); MEM_freeN(scene->nodetree); scene->nodetree = NULL; scene->use_nodes = false; @@ -368,7 +368,13 @@ static void blo_update_defaults_scene(Main *bmain, Scene *scene) /** * 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. */ + * This function can be emptied each time the startup.blend is updated. + * + * \note Screen data may be cleared at this point, this will happen in the case + * an app-template's data needs to be versioned when read-file is called with "Load UI" disabled. + * Versioning the screen data can be safely skipped without "Load UI" since the screen data + * will have been versioned when it was first loaded. + */ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template) { /* For all app templates. */ @@ -376,30 +382,132 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template) BLO_update_defaults_workspace(workspace, app_template); } + /* New grease pencil brushes and vertex paint setup. */ + { + /* Update Grease Pencil brushes. */ + Brush *brush; + + /* Pencil brush. */ + rename_id_for_versioning(bmain, ID_BR, "Draw Pencil", "Pencil"); + + /* Pen brush. */ + rename_id_for_versioning(bmain, ID_BR, "Draw Pen", "Pen"); + + /* Pen Soft brush. */ + brush = (Brush *)rename_id_for_versioning(bmain, ID_BR, "Draw Soft", "Pencil Soft"); + if (brush) { + brush->gpencil_settings->icon_id = GP_BRUSH_ICON_PEN; + } + + /* Ink Pen brush. */ + rename_id_for_versioning(bmain, ID_BR, "Draw Ink", "Ink Pen"); + + /* Ink Pen Rough brush. */ + rename_id_for_versioning(bmain, ID_BR, "Draw Noise", "Ink Pen Rough"); + + /* Marker Bold brush. */ + rename_id_for_versioning(bmain, ID_BR, "Draw Marker", "Marker Bold"); + + /* Marker Chisel brush. */ + rename_id_for_versioning(bmain, ID_BR, "Draw Block", "Marker Chisel"); + + /* Remove useless Fill Area.001 brush. */ + brush = BLI_findstring(&bmain->brushes, "Fill Area.001", offsetof(ID, name) + 2); + if (brush) { + BKE_id_delete(bmain, brush); + } + + /* Rename and fix materials and enable default object lights on. */ + if (app_template && STREQ(app_template, "2D_Animation")) { + Material *ma = NULL; + rename_id_for_versioning(bmain, ID_MA, "Black", "Solid Stroke"); + rename_id_for_versioning(bmain, ID_MA, "Red", "Squares Stroke"); + rename_id_for_versioning(bmain, ID_MA, "Grey", "Solid Fill"); + rename_id_for_versioning(bmain, ID_MA, "Black Dots", "Dots Stroke"); + + /* Dots Stroke. */ + ma = BLI_findstring(&bmain->materials, "Dots Stroke", offsetof(ID, name) + 2); + if (ma == NULL) { + ma = BKE_gpencil_material_add(bmain, "Dots Stroke"); + } + ma->gp_style->mode = GP_MATERIAL_MODE_DOT; + + /* Squares Stroke. */ + ma = BLI_findstring(&bmain->materials, "Squares Stroke", offsetof(ID, name) + 2); + if (ma == NULL) { + ma = BKE_gpencil_material_add(bmain, "Squares Stroke"); + } + ma->gp_style->mode = GP_MATERIAL_MODE_SQUARE; + + /* Change Solid Stroke settings. */ + ma = BLI_findstring(&bmain->materials, "Solid Stroke", offsetof(ID, name) + 2); + if (ma != NULL) { + ma->gp_style->mix_rgba[3] = 1.0f; + ma->gp_style->texture_offset[0] = -0.5f; + ma->gp_style->mix_factor = 0.5f; + } + + /* Change Solid Fill settings. */ + ma = BLI_findstring(&bmain->materials, "Solid Fill", offsetof(ID, name) + 2); + if (ma != NULL) { + ma->gp_style->flag &= ~GP_MATERIAL_STROKE_SHOW; + ma->gp_style->mix_rgba[3] = 1.0f; + ma->gp_style->texture_offset[0] = -0.5f; + ma->gp_style->mix_factor = 0.5f; + } + + Object *ob = BLI_findstring(&bmain->objects, "Stroke", offsetof(ID, name) + 2); + if (ob && ob->type == OB_GPENCIL) { + ob->dtx |= OB_USE_GPENCIL_LIGHTS; + } + } + + /* Reset all grease pencil brushes. */ + Scene *scene = bmain->scenes.first; + BKE_brush_gpencil_paint_presets(bmain, scene->toolsettings, true); + BKE_brush_gpencil_sculpt_presets(bmain, scene->toolsettings, true); + BKE_brush_gpencil_vertex_presets(bmain, scene->toolsettings, true); + BKE_brush_gpencil_weight_presets(bmain, scene->toolsettings, true); + + /* Ensure new Paint modes. */ + BKE_paint_ensure_from_paintmode(scene, PAINT_MODE_VERTEX_GPENCIL); + BKE_paint_ensure_from_paintmode(scene, PAINT_MODE_SCULPT_GPENCIL); + BKE_paint_ensure_from_paintmode(scene, PAINT_MODE_WEIGHT_GPENCIL); + + /* Enable cursor. */ + GpPaint *gp_paint = scene->toolsettings->gp_paint; + gp_paint->paint.flags |= PAINT_SHOW_BRUSH; + + /* Ensure Palette by default. */ + BKE_gpencil_palette_ensure(bmain, scene); + } + /* For builtin templates only. */ if (!blo_is_builtin_template(app_template)) { return; } /* Workspaces. */ - 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); - - /* Name all screens by their workspaces (avoids 'Default.###' names). */ - /* Default only has one window. */ - if (layout->screen) { - 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); - } + LISTBASE_FOREACH (wmWindowManager *, wm, &bmain->wm) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { + LISTBASE_FOREACH (WorkSpace *, workspace, &bmain->workspaces) { + WorkSpaceLayout *layout = BKE_workspace_active_layout_for_workspace_get( + win->workspace_hook, workspace); + /* Name all screens by their workspaces (avoids 'Default.###' names). */ + /* Default only has one window. */ + if (layout->screen) { + 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 some reason we have unused screens, needed until re-saving. - * Clear unused layouts because they're visible in the outliner & Python API. */ - LISTBASE_FOREACH_MUTABLE (WorkSpaceLayout *, layout_iter, &workspace->layouts) { - if (layout != layout_iter) { - BKE_workspace_layout_remove(bmain, workspace, layout_iter); + /* For some reason we have unused screens, needed until re-saving. + * Clear unused layouts because they're visible in the outliner & Python API. */ + LISTBASE_FOREACH_MUTABLE (WorkSpaceLayout *, layout_iter, &workspace->layouts) { + if (layout != layout_iter) { + BKE_workspace_layout_remove(bmain, workspace, layout_iter); + } + } } } } @@ -472,7 +580,7 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template) ma->roughness = 0.4f; if (ma->nodetree) { - for (bNode *node = ma->nodetree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &ma->nodetree->nodes) { if (node->type == SH_NODE_BSDF_PRINCIPLED) { bNodeSocket *roughness_socket = nodeFindSocket(node, SOCK_IN, "Roughness"); bNodeSocketValueFloat *roughness_data = roughness_socket->default_value; @@ -598,90 +706,4 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template) } } } - - /* New grease pencil brushes and vertex paint setup. */ - { - /* Update Grease Pencil brushes. */ - Brush *brush; - - /* Pencil brush. */ - rename_id_for_versioning(bmain, ID_BR, "Draw Pencil", "Pencil"); - - /* Pen brush. */ - rename_id_for_versioning(bmain, ID_BR, "Draw Pen", "Pen"); - - /* Pen Soft brush. */ - brush = (Brush *)rename_id_for_versioning(bmain, ID_BR, "Draw Soft", "Pencil Soft"); - if (brush) { - brush->gpencil_settings->icon_id = GP_BRUSH_ICON_PEN; - } - - /* Ink Pen brush. */ - rename_id_for_versioning(bmain, ID_BR, "Draw Ink", "Ink Pen"); - - /* Ink Pen Rough brush. */ - rename_id_for_versioning(bmain, ID_BR, "Draw Noise", "Ink Pen Rough"); - - /* Marker Bold brush. */ - rename_id_for_versioning(bmain, ID_BR, "Draw Marker", "Marker Bold"); - - /* Marker Chisel brush. */ - rename_id_for_versioning(bmain, ID_BR, "Draw Block", "Marker Chisel"); - - /* Remove useless Fill Area.001 brush. */ - brush = BLI_findstring(&bmain->brushes, "Fill Area.001", offsetof(ID, name) + 2); - if (brush) { - BKE_id_delete(bmain, brush); - } - - /* Rename and fix materials and enable default object lights on. */ - if (app_template && STREQ(app_template, "2D_Animation")) { - Material *ma = NULL; - rename_id_for_versioning(bmain, ID_MA, "Black", "Solid Stroke"); - rename_id_for_versioning(bmain, ID_MA, "Red", "Squares Stroke"); - rename_id_for_versioning(bmain, ID_MA, "Grey", "Solid Fill"); - rename_id_for_versioning(bmain, ID_MA, "Black Dots", "Dots Stroke"); - - /* Dots Stroke. */ - ma = BLI_findstring(&bmain->materials, "Dots Stroke", offsetof(ID, name) + 2); - if (ma == NULL) { - ma = BKE_gpencil_material_add(bmain, "Dots Stroke"); - } - ma->gp_style->mode = GP_MATERIAL_MODE_DOT; - - /* Squares Stroke. */ - ma = BLI_findstring(&bmain->materials, "Squares Stroke", offsetof(ID, name) + 2); - if (ma == NULL) { - ma = BKE_gpencil_material_add(bmain, "Squares Stroke"); - } - ma->gp_style->mode = GP_MATERIAL_MODE_SQUARE; - - /* Change Solid Fill settings. */ - ma = BLI_findstring(&bmain->materials, "Solid Fill", offsetof(ID, name) + 2); - if (ma != NULL) { - ma->gp_style->flag &= ~GP_MATERIAL_STROKE_SHOW; - } - - Object *ob = BLI_findstring(&bmain->objects, "Stroke", offsetof(ID, name) + 2); - if (ob && ob->type == OB_GPENCIL) { - ob->dtx |= OB_USE_GPENCIL_LIGHTS; - } - } - - /* Reset all grease pencil brushes. */ - Scene *scene = bmain->scenes.first; - BKE_brush_gpencil_paint_presets(bmain, scene->toolsettings); - - /* Ensure new Paint modes. */ - BKE_paint_ensure_from_paintmode(scene, PAINT_MODE_VERTEX_GPENCIL); - BKE_paint_ensure_from_paintmode(scene, PAINT_MODE_SCULPT_GPENCIL); - BKE_paint_ensure_from_paintmode(scene, PAINT_MODE_WEIGHT_GPENCIL); - - /* Enable cursor. */ - GpPaint *gp_paint = scene->toolsettings->gp_paint; - gp_paint->paint.flags |= PAINT_SHOW_BRUSH; - - /* Ensure Palette by default. */ - BKE_gpencil_palette_ensure(bmain, scene); - } } |