Cleanup: move theme versioning into own function
[blender.git] / source / blender / blenloader / intern / versioning_userdef.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  * ***** END GPL LICENSE BLOCK *****
19  *
20  */
21
22 /** \file blender/blenloader/intern/versioning_userdef.c
23  *  \ingroup blenloader
24  *
25  * Version patch user preferences.
26  */
27
28 #include <string.h>
29
30 #include "BLI_utildefines.h"
31
32 #include "DNA_userdef_types.h"
33 #include "DNA_curve_types.h"
34 #include "DNA_windowmanager_types.h"
35
36 #include "BKE_addon.h"
37 #include "BKE_colorband.h"
38 #include "BKE_main.h"
39
40 #include "BLO_readfile.h"  /* Own include. */
41
42 /* Disallow access to global userdef. */
43 #define U (_error_)
44
45 #define USER_VERSION_ATLEAST(ver, subver) MAIN_VERSION_ATLEAST(userdef, ver, subver)
46
47 static void do_versions_theme(UserDef *userdef, bTheme *btheme)
48 {
49         if (!USER_VERSION_ATLEAST(280, 20)) {
50                 memcpy(btheme, &U_theme_default, sizeof(*btheme));
51         }
52 }
53
54 #undef USER_VERSION_ATLEAST
55
56
57 /* patching UserDef struct and Themes */
58 void BLO_version_defaults_userpref_blend(Main *bmain, UserDef *userdef)
59 {
60 #define USER_VERSION_ATLEAST(ver, subver) MAIN_VERSION_ATLEAST(bmain, ver, subver)
61
62         /* the UserDef struct is not corrected with do_versions() .... ugh! */
63         if (userdef->wheellinescroll == 0) userdef->wheellinescroll = 3;
64         if (userdef->menuthreshold1 == 0) {
65                 userdef->menuthreshold1 = 5;
66                 userdef->menuthreshold2 = 2;
67         }
68         if (userdef->tb_leftmouse == 0) {
69                 userdef->tb_leftmouse = 5;
70                 userdef->tb_rightmouse = 5;
71         }
72         if (userdef->mixbufsize == 0) userdef->mixbufsize = 2048;
73         if (userdef->autokey_mode == 0) {
74                 /* 'add/replace' but not on */
75                 userdef->autokey_mode = 2;
76         }
77         if (userdef->savetime <= 0) {
78                 userdef->savetime = 1;
79 // XXX          error(STRINGIFY(BLENDER_STARTUP_FILE)" is buggy, please consider removing it.\n");
80         }
81         if (userdef->gizmo_size == 0) {
82                 userdef->gizmo_size = 75;
83                 userdef->gizmo_flag |= USER_GIZMO_DRAW;
84         }
85         if (userdef->pad_rot_angle == 0.0f)
86                 userdef->pad_rot_angle = 15.0f;
87
88         /* graph editor - unselected F-Curve visibility */
89         if (userdef->fcu_inactive_alpha == 0) {
90                 userdef->fcu_inactive_alpha = 0.25f;
91         }
92
93         if (!USER_VERSION_ATLEAST(192, 0)) {
94                 strcpy(userdef->sounddir, "/");
95         }
96
97         /* patch to set Dupli Armature */
98         if (!USER_VERSION_ATLEAST(220, 0)) {
99                 userdef->dupflag |= USER_DUP_ARM;
100         }
101
102         /* added seam, normal color, undo */
103         if (!USER_VERSION_ATLEAST(235, 0)) {
104                 userdef->uiflag |= USER_GLOBALUNDO;
105                 if (userdef->undosteps == 0) userdef->undosteps = 32;
106         }
107         if (!USER_VERSION_ATLEAST(236, 0)) {
108                 /* illegal combo... */
109                 if (userdef->flag & USER_LMOUSESELECT)
110                         userdef->flag &= ~USER_TWOBUTTONMOUSE;
111         }
112         if (!USER_VERSION_ATLEAST(240, 0)) {
113                 userdef->uiflag |= USER_PLAINMENUS;
114                 if (userdef->obcenter_dia == 0) userdef->obcenter_dia = 6;
115         }
116         if (!USER_VERSION_ATLEAST(242, 0)) {
117                 /* set defaults for 3D View rotating axis indicator */
118                 /* since size can't be set to 0, this indicates it's not saved in startup.blend */
119                 if (userdef->rvisize == 0) {
120                         userdef->rvisize = 15;
121                         userdef->rvibright = 8;
122                         userdef->uiflag |= USER_SHOW_GIZMO_AXIS;
123                 }
124
125         }
126         if (!USER_VERSION_ATLEAST(244, 0)) {
127                 /* set default number of recently-used files (if not set) */
128                 if (userdef->recent_files == 0) userdef->recent_files = 10;
129         }
130         if (!USER_VERSION_ATLEAST(245, 3)) {
131                 if (userdef->coba_weight.tot == 0)
132                         BKE_colorband_init(&userdef->coba_weight, true);
133         }
134         if (!USER_VERSION_ATLEAST(245, 3)) {
135                 userdef->flag |= USER_ADD_VIEWALIGNED | USER_ADD_EDITMODE;
136         }
137         if (!USER_VERSION_ATLEAST(250, 0)) {
138                 /* adjust grease-pencil distances */
139                 userdef->gp_manhattendist = 1;
140                 userdef->gp_euclideandist = 2;
141
142                 /* adjust default interpolation for new IPO-curves */
143                 userdef->ipo_new = BEZT_IPO_BEZ;
144         }
145
146         if (!USER_VERSION_ATLEAST(250, 3)) {
147                 /* new audio system */
148                 if (userdef->audiochannels == 0)
149                         userdef->audiochannels = 2;
150                 if (userdef->audioformat == 0)
151                         userdef->audioformat = 0x24;
152                 if (userdef->audiorate == 0)
153                         userdef->audiorate = 48000;
154         }
155
156         if (!USER_VERSION_ATLEAST(250, 8)) {
157                 wmKeyMap *km;
158
159                 for (km = userdef->user_keymaps.first; km; km = km->next) {
160                         if (STREQ(km->idname, "Armature_Sketch"))
161                                 strcpy(km->idname, "Armature Sketch");
162                         else if (STREQ(km->idname, "View3D"))
163                                 strcpy(km->idname, "3D View");
164                         else if (STREQ(km->idname, "View3D Generic"))
165                                 strcpy(km->idname, "3D View Generic");
166                         else if (STREQ(km->idname, "EditMesh"))
167                                 strcpy(km->idname, "Mesh");
168                         else if (STREQ(km->idname, "UVEdit"))
169                                 strcpy(km->idname, "UV Editor");
170                         else if (STREQ(km->idname, "Animation_Channels"))
171                                 strcpy(km->idname, "Animation Channels");
172                         else if (STREQ(km->idname, "GraphEdit Keys"))
173                                 strcpy(km->idname, "Graph Editor");
174                         else if (STREQ(km->idname, "GraphEdit Generic"))
175                                 strcpy(km->idname, "Graph Editor Generic");
176                         else if (STREQ(km->idname, "Action_Keys"))
177                                 strcpy(km->idname, "Dopesheet");
178                         else if (STREQ(km->idname, "NLA Data"))
179                                 strcpy(km->idname, "NLA Editor");
180                         else if (STREQ(km->idname, "Node Generic"))
181                                 strcpy(km->idname, "Node Editor");
182                         else if (STREQ(km->idname, "Logic Generic"))
183                                 strcpy(km->idname, "Logic Editor");
184                         else if (STREQ(km->idname, "File"))
185                                 strcpy(km->idname, "File Browser");
186                         else if (STREQ(km->idname, "FileMain"))
187                                 strcpy(km->idname, "File Browser Main");
188                         else if (STREQ(km->idname, "FileButtons"))
189                                 strcpy(km->idname, "File Browser Buttons");
190                         else if (STREQ(km->idname, "Buttons Generic"))
191                                 strcpy(km->idname, "Property Editor");
192                 }
193         }
194
195         if (!USER_VERSION_ATLEAST(252, 3)) {
196                 if (userdef->flag & USER_LMOUSESELECT)
197                         userdef->flag &= ~USER_TWOBUTTONMOUSE;
198         }
199         if (!USER_VERSION_ATLEAST(252, 4)) {
200                 /* default new handle type is auto handles */
201                 userdef->keyhandles_new = HD_AUTO;
202         }
203
204         if (!USER_VERSION_ATLEAST(257, 0)) {
205                 /* clear "AUTOKEY_FLAG_ONLYKEYINGSET" flag from userprefs,
206                  * so that it doesn't linger around from old configs like a ghost */
207                 userdef->autokey_flag &= ~AUTOKEY_FLAG_ONLYKEYINGSET;
208         }
209
210         if (!USER_VERSION_ATLEAST(260, 3)) {
211                 /* if new keyframes handle default is stuff "auto", make it "auto-clamped" instead
212                  * was changed in 260 as part of GSoC11, but version patch was wrong
213                  */
214                 if (userdef->keyhandles_new == HD_AUTO)
215                         userdef->keyhandles_new = HD_AUTO_ANIM;
216
217                 /* enable (Cycles) addon by default */
218                 BKE_addon_ensure(&userdef->addons, "cycles");
219         }
220
221         if (!USER_VERSION_ATLEAST(261, 4)) {
222                 userdef->use_16bit_textures = true;
223         }
224
225         if (!USER_VERSION_ATLEAST(267, 0)) {
226
227                 /* GL Texture Garbage Collection */
228                 if (userdef->textimeout == 0) {
229                         userdef->texcollectrate = 60;
230                         userdef->textimeout = 120;
231                 }
232                 if (userdef->memcachelimit <= 0) {
233                         userdef->memcachelimit = 32;
234                 }
235                 if (userdef->dbl_click_time == 0) {
236                         userdef->dbl_click_time = 350;
237                 }
238                 if (userdef->v2d_min_gridsize == 0) {
239                         userdef->v2d_min_gridsize = 35;
240                 }
241                 if (userdef->dragthreshold == 0)
242                         userdef->dragthreshold = 5;
243                 if (userdef->widget_unit == 0)
244                         userdef->widget_unit = 20;
245                 if (userdef->anisotropic_filter <= 0)
246                         userdef->anisotropic_filter = 1;
247
248                 if (userdef->ndof_sensitivity == 0.0f) {
249                         userdef->ndof_sensitivity = 1.0f;
250                         userdef->ndof_flag = (NDOF_LOCK_HORIZON | NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM | NDOF_SHOULD_ROTATE);
251                 }
252
253                 if (userdef->ndof_orbit_sensitivity == 0.0f) {
254                         userdef->ndof_orbit_sensitivity = userdef->ndof_sensitivity;
255
256                         if (!(userdef->flag & USER_TRACKBALL))
257                                 userdef->ndof_flag |= NDOF_TURNTABLE;
258                 }
259                 if (userdef->tweak_threshold == 0)
260                         userdef->tweak_threshold = 10;
261         }
262
263         /* NOTE!! from now on use userdef->versionfile and userdef->subversionfile */
264 #undef USER_VERSION_ATLEAST
265 #define USER_VERSION_ATLEAST(ver, subver) MAIN_VERSION_ATLEAST(userdef, ver, subver)
266
267         if (!USER_VERSION_ATLEAST(271, 5)) {
268                 userdef->pie_menu_radius = 100;
269                 userdef->pie_menu_threshold = 12;
270                 userdef->pie_animation_timeout = 6;
271         }
272
273         if (!USER_VERSION_ATLEAST(275, 2)) {
274                 userdef->ndof_deadzone = 0.1;
275         }
276
277         if (!USER_VERSION_ATLEAST(275, 4)) {
278                 userdef->node_margin = 80;
279         }
280
281         if (!USER_VERSION_ATLEAST(278, 6)) {
282                 /* Clear preference flags for re-use. */
283                 userdef->flag &= ~(
284                     USER_FLAG_NUMINPUT_ADVANCED | USER_FLAG_DEPRECATED_2 | USER_FLAG_DEPRECATED_3 |
285                     USER_FLAG_DEPRECATED_6 | USER_FLAG_DEPRECATED_7 |
286                     USER_FLAG_DEPRECATED_9 | USER_DEVELOPER_UI);
287                 userdef->uiflag &= ~(
288                     USER_UIFLAG_DEPRECATED_7);
289                 userdef->transopts &= ~(
290                     USER_TR_DEPRECATED_2 | USER_TR_DEPRECATED_3 | USER_TR_DEPRECATED_4 |
291                     USER_TR_DEPRECATED_6 | USER_TR_DEPRECATED_7);
292
293                 userdef->uiflag |= USER_LOCK_CURSOR_ADJUST;
294         }
295
296
297         if (!USER_VERSION_ATLEAST(280, 20)) {
298                 userdef->gpu_viewport_quality = 0.6f;
299
300                 /* Reset theme, old themes will not be compatible with minor version updates from now on. */
301                 for (bTheme *btheme = userdef->themes.first; btheme; btheme = btheme->next) {
302                         memcpy(btheme, &U_theme_default, sizeof(*btheme));
303                 }
304
305                 /* Annotations - new layer color
306                  * Replace anything that used to be set if it looks like was left
307                  * on the old default (i.e. black), which most users used
308                  */
309                 if ((userdef->gpencil_new_layer_col[3] < 0.1f) || (userdef->gpencil_new_layer_col[0] < 0.1f)) {
310                         /* - New color matches the annotation pencil icon
311                          * - Non-full alpha looks better!
312                          */
313                         ARRAY_SET_ITEMS(userdef->gpencil_new_layer_col, 0.38f, 0.61f, 0.78f, 0.9f);
314                 }
315         }
316
317         /**
318          * Include next version bump.
319          */
320         {
321                 /* (keep this block even if it becomes empty). */
322         }
323
324         if (userdef->pixelsize == 0.0f)
325                 userdef->pixelsize = 1.0f;
326
327         if (userdef->image_draw_method == 0)
328                 userdef->image_draw_method = IMAGE_DRAW_METHOD_2DTEXTURE;
329
330         // we default to the first audio device
331         userdef->audiodevice = 0;
332
333         /* Not versioning, just avoid errors. */
334 #ifndef WITH_CYCLES
335         BKE_addon_remove_safe(&userdef->addons, "cycles");
336 #endif
337         /* this timer uses U */
338 // XXX  reset_autosave();
339
340         for (bTheme *btheme = userdef->themes.first; btheme; btheme = btheme->next) {
341                 do_versions_theme(userdef, btheme);
342         }
343 }