Cleanup: clear deprecated UI flags
[blender.git] / source / blender / blenloader / intern / versioning_defaults.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Blender Foundation
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  *
22  */
23
24 /** \file blender/blenloader/intern/versioning_defaults.c
25  *  \ingroup blenloader
26  */
27
28 #include "BLI_utildefines.h"
29 #include "BLI_listbase.h"
30 #include "BLI_math.h"
31
32 #include "DNA_brush_types.h"
33 #include "DNA_freestyle_types.h"
34 #include "DNA_linestyle_types.h"
35 #include "DNA_scene_types.h"
36 #include "DNA_screen_types.h"
37 #include "DNA_space_types.h"
38 #include "DNA_userdef_types.h"
39 #include "DNA_mesh_types.h"
40 #include "DNA_material_types.h"
41 #include "DNA_object_types.h"
42
43 #include "BKE_brush.h"
44 #include "BKE_library.h"
45 #include "BKE_main.h"
46
47 #include "BLO_readfile.h"
48
49
50 /**
51  * Override values in in-memory startup.blend, avoids resaving for small changes.
52  */
53 void BLO_update_defaults_userpref_blend(void)
54 {
55         /* defaults from T37518 */
56
57         U.uiflag |= USER_ZBUF_CURSOR;
58         U.uiflag |= USER_QUIT_PROMPT;
59         U.uiflag |= USER_CONTINUOUS_MOUSE;
60
61         /* See T45301 */
62         U.uiflag |= USER_LOCK_CURSOR_ADJUST;
63
64         U.versions = 1;
65         U.savetime = 2;
66
67         /* default from T47064 */
68         U.audiorate = 48000;
69
70         /* Keep this a very small, non-zero number so zero-alpha doesn't mask out objects behind it.
71          * but take care since some hardware has driver bugs here (T46962).
72          * Further hardware workarounds should be made in gpu_extensions.c */
73         U.glalphaclip = (1.0f / 255);
74
75         /* default so DPI is detected automatically */
76         U.dpi = 0;
77         U.ui_scale = 1.0f;
78
79 #ifdef WITH_PYTHON_SECURITY
80         /* use alternative setting for security nuts
81          * otherwise we'd need to patch the binary blob - startup.blend.c */
82         U.flag |= USER_SCRIPT_AUTOEXEC_DISABLE;
83 #else
84         U.flag &= ~USER_SCRIPT_AUTOEXEC_DISABLE;
85 #endif
86 }
87
88 /**
89  * Update defaults in startup.blend, without having to save and embed the file.
90  * This function can be emptied each time the startup.blend is updated. */
91 void BLO_update_defaults_startup_blend(Main *bmain)
92 {
93         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
94                 scene->r.im_format.planes = R_IMF_PLANES_RGBA;
95                 scene->r.im_format.compress = 15;
96
97                 for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
98                         srl->freestyleConfig.sphere_radius = 0.1f;
99                         srl->pass_alpha_threshold = 0.5f;
100                 }
101
102                 if (scene->toolsettings) {
103                         ToolSettings *ts = scene->toolsettings;
104
105                         if (ts->sculpt) {
106                                 Sculpt *sculpt = ts->sculpt;
107                                 sculpt->paint.symmetry_flags |= PAINT_SYMM_X;
108                                 sculpt->flags |= SCULPT_DYNTOPO_COLLAPSE;
109                                 sculpt->detail_size = 12;
110                         }
111                         
112                         if (ts->gp_sculpt.brush[0].size == 0) {
113                                 GP_BrushEdit_Settings *gset = &ts->gp_sculpt;
114                                 GP_EditBrush_Data *brush;
115                                 
116                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_SMOOTH];
117                                 brush->size = 25;
118                                 brush->strength = 0.3f;
119                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF | GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE;
120                                 
121                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_THICKNESS];
122                                 brush->size = 25;
123                                 brush->strength = 0.5f;
124                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
125                                 
126                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_STRENGTH];
127                                 brush->size = 25;
128                                 brush->strength = 0.5f;
129                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
130
131                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_GRAB];
132                                 brush->size = 50;
133                                 brush->strength = 0.3f;
134                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
135                                 
136                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PUSH];
137                                 brush->size = 25;
138                                 brush->strength = 0.3f;
139                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
140                                 
141                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_TWIST];
142                                 brush->size = 50;
143                                 brush->strength = 0.3f; // XXX?
144                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
145                                 
146                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PINCH];
147                                 brush->size = 50;
148                                 brush->strength = 0.5f; // XXX?
149                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
150                                 
151                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_RANDOMIZE];
152                                 brush->size = 25;
153                                 brush->strength = 0.5f;
154                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
155                         }
156                         
157                         ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
158                         ts->gpencil_v2d_align = GP_PROJECT_VIEWSPACE;
159                         ts->gpencil_seq_align = GP_PROJECT_VIEWSPACE;
160                         ts->gpencil_ima_align = GP_PROJECT_VIEWSPACE;
161
162                         ParticleEditSettings *pset = &ts->particle;
163                         for (int a = 0; a < PE_TOT_BRUSH; a++) {
164                                 pset->brush[a].strength = 0.5f;
165                                 pset->brush[a].count = 10;
166                         }
167                         pset->brush[PE_BRUSH_CUT].strength = 1.0f;
168                 }
169
170                 scene->gm.lodflag |= SCE_LOD_USE_HYST;
171                 scene->gm.scehysteresis = 10;
172
173                 scene->r.ffcodecdata.audio_mixrate = 48000;
174         }
175
176         for (FreestyleLineStyle *linestyle = bmain->linestyle.first; linestyle; linestyle = linestyle->id.next) {
177                 linestyle->flag = LS_SAME_OBJECT | LS_NO_SORTING | LS_TEXTURE;
178                 linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
179                 linestyle->integration_type = LS_INTEGRATION_MEAN;
180                 linestyle->texstep = 1.0;
181                 linestyle->chain_count = 10;
182         }
183
184         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
185                 ScrArea *area;
186                 for (area = screen->areabase.first; area; area = area->next) {
187                         SpaceLink *space_link;
188                         ARegion *ar;
189
190                         for (space_link = area->spacedata.first; space_link; space_link = space_link->next) {
191                                 if (space_link->spacetype == SPACE_CLIP) {
192                                         SpaceClip *space_clip = (SpaceClip *) space_link;
193                                         space_clip->flag &= ~SC_MANUAL_CALIBRATION;
194                                 }
195                         }
196
197                         for (ar = area->regionbase.first; ar; ar = ar->next) {
198                                 /* Remove all stored panels, we want to use defaults (order, open/closed) as defined by UI code here! */
199                                 BLI_freelistN(&ar->panels);
200
201                                 /* some toolbars have been saved as initialized,
202                                  * we don't want them to have odd zoom-level or scrolling set, see: T47047 */
203                                 if (ELEM(ar->regiontype, RGN_TYPE_UI, RGN_TYPE_TOOLS, RGN_TYPE_TOOL_PROPS)) {
204                                         ar->v2d.flag &= ~V2D_IS_INITIALISED;
205                                 }
206                         }
207                 }
208         }
209
210         for (Mesh *me = bmain->mesh.first; me; me = me->id.next) {
211                 me->smoothresh = DEG2RADF(180.0f);
212                 me->flag &= ~ME_TWOSIDED;
213         }
214
215         for (Material *mat = bmain->mat.first; mat; mat = mat->id.next) {
216                 mat->line_col[0] = mat->line_col[1] = mat->line_col[2] = 0.0f;
217                 mat->line_col[3] = 1.0f;
218         }
219
220         {
221                 Object *ob;
222
223                 ob = (Object *)BKE_libblock_find_name_ex(bmain, ID_OB, "Camera");
224                 if (ob) {
225                         ob->rot[1] = 0.0f;
226                 }
227         }
228
229         {
230                 Brush *br;
231
232                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Fill");
233                 if (!br) {
234                         br = BKE_brush_add(bmain, "Fill", OB_MODE_TEXTURE_PAINT);
235                         br->imagepaint_tool = PAINT_TOOL_FILL;
236                         br->ob_mode = OB_MODE_TEXTURE_PAINT;
237                 }
238
239                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Mask");
240                 if (br) {
241                         br->imagepaint_tool = PAINT_TOOL_MASK;
242                         br->ob_mode |= OB_MODE_TEXTURE_PAINT;
243                 }
244
245                 /* remove polish brush (flatten/contrast does the same) */
246                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Polish");
247                 if (br) {
248                         BKE_libblock_delete(bmain, br);
249                 }
250
251                 /* remove brush brush (huh?) from some modes (draw brushes do the same) */
252                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Brush");
253                 if (br) {
254                         BKE_libblock_delete(bmain, br);
255                 }
256
257                 /* remove draw brush from texpaint (draw brushes do the same) */
258                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Draw");
259                 if (br) {
260                         br->ob_mode &= ~OB_MODE_TEXTURE_PAINT;
261                 }
262
263                 /* rename twist brush to rotate brush to match rotate tool */
264                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Twist");
265                 if (br) {
266                         BKE_libblock_rename(bmain, &br->id, "Rotate");
267                 }
268
269                 /* use original normal for grab brush (otherwise flickers with normal weighting). */
270                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Grab");
271                 if (br) {
272                         br->flag |= BRUSH_ORIGINAL_NORMAL;
273                 }
274
275                 /* increase strength, better for smoothing method */
276                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Blur");
277                 if (br) {
278                         br->alpha = 1.0f;
279                 }
280
281                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Flatten/Contrast");
282                 if (br) {
283                         br->flag |= BRUSH_ACCUMULATE;
284                 }
285         }
286 }
287