Fix [#21516] UI artifacts in array modifier
[blender.git] / source / blender / editors / interface / resources.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <math.h>
34 #include <stdlib.h>
35 #include <string.h>
36
37 #ifdef HAVE_CONFIG_H
38 #include <config.h>
39 #endif
40
41 #include "MEM_guardedalloc.h"
42
43
44 #include "DNA_curve_types.h"
45 #include "DNA_userdef_types.h"
46 #include "DNA_screen_types.h"
47 #include "DNA_space_types.h"
48 #include "DNA_windowmanager_types.h"
49
50 #include "BLI_blenlib.h"
51
52
53 #include "BKE_DerivedMesh.h"
54 #include "BKE_global.h"
55 #include "BKE_main.h"
56 #include "BKE_texture.h"
57 #include "BKE_utildefines.h"
58
59 #include "BIF_gl.h"
60
61 #include "UI_interface.h"
62 #include "UI_interface_icons.h"
63
64 #include "interface_intern.h"
65
66 /* global for themes */
67 typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha);
68
69 static bTheme *theme_active=NULL;
70 static int theme_spacetype= SPACE_VIEW3D;
71 static int theme_regionid= RGN_TYPE_WINDOW;
72
73 void ui_resources_init(void)
74 {
75         UI_icons_init(BIFICONID_LAST);
76 }
77
78 void ui_resources_free(void)
79 {
80         UI_icons_free();
81 }
82
83
84 /* ******************************************************** */
85 /*    THEMES */
86 /* ******************************************************** */
87
88 char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
89 {
90         ThemeSpace *ts= NULL;
91         static char error[4]={240, 0, 240, 255};
92         static char alert[4]={240, 60, 60, 255};
93         static char headerdesel[4]={0,0,0,255};
94         
95         char *cp= error;
96         
97         if(btheme) {
98         
99                 // first check for ui buttons theme
100                 if(colorid < TH_THEMEUI) {
101                 
102                         switch(colorid) {
103
104                         case TH_REDALERT:
105                                 cp= alert; break;
106                         }
107                 }
108                 else {
109                 
110                         switch(spacetype) {
111                         case SPACE_BUTS:
112                                 ts= &btheme->tbuts;
113                                 break;
114                         case SPACE_VIEW3D:
115                                 ts= &btheme->tv3d;
116                                 break;
117                         case SPACE_IPO:
118                                 ts= &btheme->tipo;
119                                 break;
120                         case SPACE_FILE:
121                                 ts= &btheme->tfile;
122                                 break;
123                         case SPACE_NLA:
124                                 ts= &btheme->tnla;
125                                 break;
126                         case SPACE_ACTION:
127                                 ts= &btheme->tact;
128                                 break;
129                         case SPACE_SEQ:
130                                 ts= &btheme->tseq;
131                                 break;
132                         case SPACE_IMAGE:
133                                 ts= &btheme->tima;
134                                 break;
135                         case SPACE_IMASEL:
136                                 ts= &btheme->timasel;
137                                 break;
138                         case SPACE_TEXT:
139                                 ts= &btheme->text;
140                                 break;
141                         case SPACE_OUTLINER:
142                                 ts= &btheme->toops;
143                                 break;
144                         case SPACE_SOUND:
145                                 ts= &btheme->tsnd;
146                                 break;
147                         case SPACE_INFO:
148                                 ts= &btheme->tinfo;
149                                 break;
150                         case SPACE_USERPREF:
151                                 ts= &btheme->tuserpref;
152                                 break;
153                         case SPACE_CONSOLE:
154                                 ts= &btheme->tconsole;
155                                 break;
156                         case SPACE_TIME:
157                                 ts= &btheme->ttime;
158                                 break;
159                         case SPACE_NODE:
160                                 ts= &btheme->tnode;
161                                 break;
162                         case SPACE_LOGIC:
163                                 ts= &btheme->tlogic;
164                                 break;
165                         default:
166                                 ts= &btheme->tv3d;
167                                 break;
168                         }
169                         
170                         switch(colorid) {
171                         case TH_BACK:
172                                 if(theme_regionid==RGN_TYPE_WINDOW)
173                                         cp= ts->back;
174                                 else if(theme_regionid==RGN_TYPE_CHANNELS)
175                                         cp= ts->list;
176                                 else if(theme_regionid==RGN_TYPE_HEADER)
177                                         cp= ts->header;
178                                 else
179                                         cp= ts->button; 
180                                 break;
181                         case TH_TEXT:
182                                 if(theme_regionid==RGN_TYPE_WINDOW)
183                                         cp= ts->text; 
184                                 else if(theme_regionid==RGN_TYPE_CHANNELS)
185                                         cp= ts->list_text;
186                                 else if(theme_regionid==RGN_TYPE_HEADER)
187                                         cp= ts->header_text;
188                                 else
189                                         cp= ts->button_text; 
190                                 break;
191                         case TH_TEXT_HI:
192                                 if(theme_regionid==RGN_TYPE_WINDOW)
193                                         cp= ts->text_hi;
194                                 else if(theme_regionid==RGN_TYPE_CHANNELS)
195                                         cp= ts->list_text_hi;
196                                 else if(theme_regionid==RGN_TYPE_HEADER)
197                                         cp= ts->header_text_hi;
198                                 else
199                                         cp= ts->button_text_hi; 
200                                 break;
201                         case TH_TITLE:
202                                 if(theme_regionid==RGN_TYPE_WINDOW)
203                                         cp= ts->title;
204                                 else if(theme_regionid==RGN_TYPE_CHANNELS)
205                                         cp= ts->list_title;
206                                 else if(theme_regionid==RGN_TYPE_HEADER)
207                                         cp= ts->header_title;
208                                 else
209                                         cp= ts->button_title; 
210                                 break;
211                                 
212                         case TH_HEADER:
213                                 cp= ts->header; break;
214                         case TH_HEADERDESEL:
215                                 /* we calculate a dynamic builtin header deselect color, also for pulldowns... */
216                                 cp= ts->header; 
217                                 headerdesel[0]= cp[0]>10?cp[0]-10:0;
218                                 headerdesel[1]= cp[1]>10?cp[1]-10:0;
219                                 headerdesel[2]= cp[2]>10?cp[2]-10:0;
220                                 cp= headerdesel;
221                                 break;
222                         case TH_HEADER_TEXT:
223                                 cp= ts->header_text; break;
224                         case TH_HEADER_TEXT_HI:
225                                 cp= ts->header_text_hi; break;
226                                 
227                         case TH_PANEL:
228                                 cp= ts->panel; break;
229                         case TH_PANEL_TEXT:
230                                 cp= ts->panel_text; break;
231                         case TH_PANEL_TEXT_HI:
232                                 cp= ts->panel_text_hi; break;
233                                 
234                         case TH_BUTBACK:
235                                 cp= ts->button; break;
236                         case TH_BUTBACK_TEXT:
237                                 cp= ts->button_text; break;
238                         case TH_BUTBACK_TEXT_HI:
239                                 cp= ts->button_text_hi; break;
240                                 
241                         case TH_SHADE1:
242                                 cp= ts->shade1; break;
243                         case TH_SHADE2:
244                                 cp= ts->shade2; break;
245                         case TH_HILITE:
246                                 cp= ts->hilite; break;
247                                 
248                         case TH_GRID:
249                                 cp= ts->grid; break;
250                         case TH_WIRE:
251                                 cp= ts->wire; break;
252                         case TH_LAMP:
253                                 cp= ts->lamp; break;
254                         case TH_SELECT:
255                                 cp= ts->select; break;
256                         case TH_ACTIVE:
257                                 cp= ts->active; break;
258                         case TH_GROUP:
259                                 cp= ts->group; break;
260                         case TH_GROUP_ACTIVE:
261                                 cp= ts->group_active; break;
262                         case TH_TRANSFORM:
263                                 cp= ts->transform; break;
264                         case TH_VERTEX:
265                                 cp= ts->vertex; break;
266                         case TH_VERTEX_SELECT:
267                                 cp= ts->vertex_select; break;
268                         case TH_VERTEX_SIZE:
269                                 cp= &ts->vertex_size; break;
270                         case TH_EDGE:
271                                 cp= ts->edge; break;
272                         case TH_EDGE_SELECT:
273                                 cp= ts->edge_select; break;
274                         case TH_EDGE_SEAM:
275                                 cp= ts->edge_seam; break;
276                         case TH_EDGE_SHARP:
277                                 cp= ts->edge_sharp; break;
278                         case TH_EDGE_CREASE:
279                                 cp= ts->edge_crease; break;
280                         case TH_EDITMESH_ACTIVE:
281                                 cp= ts->editmesh_active; break;
282                         case TH_EDGE_FACESEL:
283                                 cp= ts->edge_facesel; break;
284                         case TH_FACE:
285                                 cp= ts->face; break;
286                         case TH_FACE_SELECT:
287                                 cp= ts->face_select; break;
288                         case TH_FACE_DOT:
289                                 cp= ts->face_dot; break;
290                         case TH_FACEDOT_SIZE:
291                                 cp= &ts->facedot_size; break;
292                         case TH_NORMAL:
293                                 cp= ts->normal; break;
294                         case TH_VNORMAL:
295                                 cp= ts->vertex_normal; break;
296                         case TH_BONE_SOLID:
297                                 cp= ts->bone_solid; break;
298                         case TH_BONE_POSE:
299                                 cp= ts->bone_pose; break;
300                         case TH_STRIP:
301                                 cp= ts->strip; break;
302                         case TH_STRIP_SELECT:
303                                 cp= ts->strip_select; break;
304                         case TH_CFRAME:
305                                 cp= ts->cframe; break;
306                         case TH_NURB_ULINE:
307                                 cp= ts->nurb_uline; break;
308                         case TH_NURB_VLINE:
309                                 cp= ts->nurb_vline; break;
310                         case TH_NURB_SEL_ULINE:
311                                 cp= ts->nurb_sel_uline; break;
312                         case TH_NURB_SEL_VLINE:
313                                 cp= ts->nurb_sel_vline; break;
314                         case TH_ACTIVE_SPLINE:
315                                 cp= ts->act_spline; break;
316                         case TH_HANDLE_FREE:
317                                 cp= ts->handle_free; break;
318                         case TH_HANDLE_AUTO:
319                                 cp= ts->handle_auto; break;
320                         case TH_HANDLE_VECT:
321                                 cp= ts->handle_vect; break;
322                         case TH_HANDLE_ALIGN:
323                                 cp= ts->handle_align; break;
324                         case TH_HANDLE_SEL_FREE:
325                                 cp= ts->handle_sel_free; break;
326                         case TH_HANDLE_SEL_AUTO:
327                                 cp= ts->handle_sel_auto; break;
328                         case TH_HANDLE_SEL_VECT:
329                                 cp= ts->handle_sel_vect; break;
330                         case TH_HANDLE_SEL_ALIGN:
331                                 cp= ts->handle_sel_align; break;
332
333                         case TH_SYNTAX_B:
334                                 cp= ts->syntaxb; break;
335                         case TH_SYNTAX_V:
336                                 cp= ts->syntaxv; break;
337                         case TH_SYNTAX_C:
338                                 cp= ts->syntaxc; break;
339                         case TH_SYNTAX_L:
340                                 cp= ts->syntaxl; break;
341                         case TH_SYNTAX_N:
342                                 cp= ts->syntaxn; break;
343
344                         case TH_NODE:
345                                 cp= ts->syntaxl; break;
346                         case TH_NODE_IN_OUT:
347                                 cp= ts->syntaxn; break;
348                         case TH_NODE_OPERATOR:
349                                 cp= ts->syntaxb; break;
350                         case TH_NODE_CONVERTOR:
351                                 cp= ts->syntaxv; break;
352                         case TH_NODE_GROUP:
353                                 cp= ts->syntaxc; break;
354                                 
355                         case TH_SEQ_MOVIE:
356                                 cp= ts->movie; break;
357                         case TH_SEQ_IMAGE:
358                                 cp= ts->image; break;
359                         case TH_SEQ_SCENE:
360                                 cp= ts->scene; break;
361                         case TH_SEQ_AUDIO:
362                                 cp= ts->audio; break;
363                         case TH_SEQ_EFFECT:
364                                 cp= ts->effect; break;
365                         case TH_SEQ_PLUGIN:
366                                 cp= ts->plugin; break;
367                         case TH_SEQ_TRANSITION:
368                                 cp= ts->transition; break;
369                         case TH_SEQ_META:
370                                 cp= ts->meta; break;
371                                 
372                         case TH_CONSOLE_OUTPUT:
373                                 cp= ts->console_output; break;
374                         case TH_CONSOLE_INPUT:
375                                 cp= ts-> console_input; break;
376                         case TH_CONSOLE_INFO:
377                                 cp= ts->console_info; break;
378                         case TH_CONSOLE_ERROR:
379                                 cp= ts->console_error; break;
380                         case TH_CONSOLE_CURSOR:
381                                 cp= ts->console_cursor; break;
382
383                         case TH_HANDLE_VERTEX:
384                                 cp= ts->handle_vertex;
385                                 break;
386                         case TH_HANDLE_VERTEX_SELECT:
387                                 cp= ts->handle_vertex_select;
388                                 break;
389                         case TH_HANDLE_VERTEX_SIZE:
390                                 cp= &ts->handle_vertex_size;
391                                 break;
392                                 
393                         case TH_DOPESHEET_CHANNELOB:
394                                 cp= ts->ds_channel;
395                                 break;
396                         case TH_DOPESHEET_CHANNELSUBOB:
397                                 cp= ts->ds_subchannel;
398                                 break;  
399                                         
400                         case TH_PREVIEW_BACK:
401                                 cp= ts->preview_back;
402                                 break;  
403                         }
404                 }
405         }
406         
407         return cp;
408 }
409
410 #define SETCOLTEST(col, r, g, b, a)  if(col[3]==0) {col[0]=r; col[1]=g; col[2]= b; col[3]= a;}
411
412 /* use this call to init new variables in themespace, if they're same for all */
413 static void ui_theme_init_new_do(ThemeSpace *ts)
414 {
415         SETCOLTEST(ts->header_text,             0, 0, 0, 255);
416         SETCOLTEST(ts->header_title,    0, 0, 0, 255);
417         SETCOLTEST(ts->header_text_hi,  255, 255, 255, 255);
418         
419         SETCOLTEST(ts->panel_text,              0, 0, 0, 255);
420         SETCOLTEST(ts->panel_title,             0, 0, 0, 255);
421         SETCOLTEST(ts->panel_text_hi,   255, 255, 255, 255);
422         
423         SETCOLTEST(ts->button,                  145, 145, 145, 245);
424         SETCOLTEST(ts->button_title,    0, 0, 0, 255);
425         SETCOLTEST(ts->button_text,             0, 0, 0, 255);
426         SETCOLTEST(ts->button_text_hi,  255, 255, 255, 255);
427         
428         SETCOLTEST(ts->list,                    165, 165, 165, 255);
429         SETCOLTEST(ts->list_title,              0, 0, 0, 255);
430         SETCOLTEST(ts->list_text,               0, 0, 0, 255);
431         SETCOLTEST(ts->list_text_hi,    255, 255, 255, 255);
432 }
433
434 static void ui_theme_init_new(bTheme *btheme)
435 {
436         ui_theme_init_new_do(&btheme->tbuts);
437         ui_theme_init_new_do(&btheme->tv3d);
438         ui_theme_init_new_do(&btheme->tfile);
439         ui_theme_init_new_do(&btheme->tipo);
440         ui_theme_init_new_do(&btheme->tinfo);
441         ui_theme_init_new_do(&btheme->tsnd);
442         ui_theme_init_new_do(&btheme->tact);
443         ui_theme_init_new_do(&btheme->tnla);
444         ui_theme_init_new_do(&btheme->tseq);
445         ui_theme_init_new_do(&btheme->tima);
446         ui_theme_init_new_do(&btheme->timasel);
447         ui_theme_init_new_do(&btheme->text);
448         ui_theme_init_new_do(&btheme->toops);
449         ui_theme_init_new_do(&btheme->ttime);
450         ui_theme_init_new_do(&btheme->tnode);
451         ui_theme_init_new_do(&btheme->tlogic);
452         ui_theme_init_new_do(&btheme->tuserpref);
453         ui_theme_init_new_do(&btheme->tconsole);
454         
455 }
456
457 #define SETCOL(col, r, g, b, a)  col[0]=r; col[1]=g; col[2]= b; col[3]= a;
458 #define SETCOLF(col, r, g, b, a)  col[0]=r*255; col[1]=g*255; col[2]= b*255; col[3]= a*255;
459
460 /* initialize default theme
461    Note: when you add new colors, created & saved themes need initialized
462    use function below, init_userdef_do_versions() 
463 */
464 void ui_theme_init_default(void)
465 {
466         bTheme *btheme= U.themes.first;
467         
468         /* we search for the theme with name Default */
469         for(btheme= U.themes.first; btheme; btheme= btheme->next) {
470                 if(strcmp("Default", btheme->name)==0) break;
471         }
472         
473         if(btheme==NULL) {
474                 btheme= MEM_callocN(sizeof(bTheme), "theme");
475                 BLI_addtail(&U.themes, btheme);
476                 strcpy(btheme->name, "Default");
477         }
478         
479         UI_SetTheme(0, 0);      // make sure the global used in this file is set
480
481         /* UI buttons */
482         ui_widget_color_init(&btheme->tui);
483
484         /* common (new) variables */
485         ui_theme_init_new(btheme);
486         
487         /* space view3d */
488         SETCOLF(btheme->tv3d.back,       0.225, 0.225, 0.225, 1.0);
489         SETCOL(btheme->tv3d.text,       0, 0, 0, 255);
490         SETCOL(btheme->tv3d.text_hi, 255, 255, 255, 255);
491         
492         SETCOLF(btheme->tv3d.header,    0.45, 0.45, 0.45, 1.0);
493         SETCOLF(btheme->tv3d.button,    0.45, 0.45, 0.45, 1.0);
494         SETCOL(btheme->tv3d.panel,      165, 165, 165, 127);
495         
496         SETCOL(btheme->tv3d.shade1,  160, 160, 160, 100);
497         SETCOL(btheme->tv3d.shade2,  0x7f, 0x70, 0x70, 100);
498
499         SETCOLF(btheme->tv3d.grid,     0.251, 0.251, 0.251, 1.0);
500         SETCOL(btheme->tv3d.wire,       0x0, 0x0, 0x0, 255);
501         SETCOL(btheme->tv3d.lamp,       0, 0, 0, 40);
502         SETCOL(btheme->tv3d.select, 241, 88, 0, 255);
503         SETCOL(btheme->tv3d.active, 255, 140, 25, 255);
504         SETCOL(btheme->tv3d.group,      8, 48, 8, 255);
505         SETCOL(btheme->tv3d.group_active, 85, 187, 85, 255);
506         SETCOL(btheme->tv3d.transform, 0xff, 0xff, 0xff, 255);
507         SETCOL(btheme->tv3d.vertex, 0, 0, 0, 255);
508         SETCOL(btheme->tv3d.vertex_select, 255, 133, 0, 255);
509         btheme->tv3d.vertex_size= 3;
510         SETCOL(btheme->tv3d.edge,       0x0, 0x0, 0x0, 255);
511         SETCOL(btheme->tv3d.edge_select, 255, 160, 0, 255);
512         SETCOL(btheme->tv3d.edge_seam, 219, 37, 18, 255);
513         SETCOL(btheme->tv3d.edge_facesel, 75, 75, 75, 255);
514         SETCOL(btheme->tv3d.face,       0, 0, 0, 18);
515         SETCOL(btheme->tv3d.face_select, 255, 133, 0, 60);
516         SETCOL(btheme->tv3d.normal, 0x22, 0xDD, 0xDD, 255);
517         SETCOL(btheme->tv3d.vertex_normal, 0x23, 0x61, 0xDD, 255);
518         SETCOL(btheme->tv3d.face_dot, 255, 133, 0, 255);
519         btheme->tv3d.facedot_size= 4;
520         SETCOL(btheme->tv3d.cframe, 0x60, 0xc0,  0x40, 255);
521
522         SETCOL(btheme->tv3d.nurb_uline, 0x90, 0x90, 0x00, 255);
523         SETCOL(btheme->tv3d.nurb_vline, 0x80, 0x30, 0x60, 255);
524         SETCOL(btheme->tv3d.nurb_sel_uline, 0xf0, 0xff, 0x40, 255);
525         SETCOL(btheme->tv3d.nurb_sel_vline, 0xf0, 0x90, 0xa0, 255);
526
527         SETCOL(btheme->tv3d.handle_free, 0, 0, 0, 255);
528         SETCOL(btheme->tv3d.handle_auto, 0x90, 0x90, 0x00, 255);
529         SETCOL(btheme->tv3d.handle_vect, 0x40, 0x90, 0x30, 255);
530         SETCOL(btheme->tv3d.handle_align, 0x80, 0x30, 0x60, 255);
531         SETCOL(btheme->tv3d.handle_sel_free, 0, 0, 0, 255);
532         SETCOL(btheme->tv3d.handle_sel_auto, 0xf0, 0xff, 0x40, 255);
533         SETCOL(btheme->tv3d.handle_sel_vect, 0x40, 0xc0, 0x30, 255);
534         SETCOL(btheme->tv3d.handle_sel_align, 0xf0, 0x90, 0xa0, 255);
535
536         SETCOL(btheme->tv3d.act_spline, 0xdb, 0x25, 0x12, 255);
537
538         SETCOL(btheme->tv3d.bone_solid, 200, 200, 200, 255);
539         SETCOL(btheme->tv3d.bone_pose, 80, 200, 255, 80);               // alpha 80 is not meant editable, used for wire+action draw
540         
541         
542         /* space buttons */
543         /* to have something initialized */
544         btheme->tbuts= btheme->tv3d;
545
546         SETCOLF(btheme->tbuts.back,     0.45, 0.45, 0.45, 1.0);
547         SETCOL(btheme->tbuts.panel, 0x82, 0x82, 0x82, 255);
548
549         /* graph editor */
550         btheme->tipo= btheme->tv3d;
551         SETCOLF(btheme->tipo.back,      0.42, 0.42, 0.42, 1.0);
552         SETCOLF(btheme->tipo.list,      0.4, 0.4, 0.4, 1.0);
553         SETCOL(btheme->tipo.grid,       94, 94, 94, 255);
554         SETCOL(btheme->tipo.panel,  255, 255, 255, 150);
555         SETCOL(btheme->tipo.shade1,             150, 150, 150, 100);    /* scrollbars */
556         SETCOL(btheme->tipo.shade2,             0x70, 0x70, 0x70, 100);
557         SETCOL(btheme->tipo.vertex,             0, 0, 0, 255);
558         SETCOL(btheme->tipo.vertex_select, 255, 133, 0, 255);
559         SETCOL(btheme->tipo.hilite, 0x60, 0xc0, 0x40, 255); 
560         btheme->tipo.vertex_size= 3;
561
562         SETCOL(btheme->tipo.handle_vertex,              0, 0, 0, 255);
563         SETCOL(btheme->tipo.handle_vertex_select, 255, 133, 0, 255);
564         btheme->tipo.handle_vertex_size= 3;
565         
566         SETCOL(btheme->tipo.ds_channel,         82, 96, 110, 255);
567         SETCOL(btheme->tipo.ds_subchannel,      124, 137, 150, 255);
568         SETCOL(btheme->tipo.group, 79, 101, 73, 255);
569         SETCOL(btheme->tipo.group_active, 135, 177, 125, 255);
570
571         /* dopesheet */
572         btheme->tact= btheme->tipo;
573         SETCOL(btheme->tact.strip,                      12, 10, 10, 128); 
574         SETCOL(btheme->tact.strip_select,       255, 140, 0, 255); 
575         
576         /* space nla */
577         btheme->tnla= btheme->tact;
578         
579         /* space file */
580         /* to have something initialized */
581         btheme->tfile= btheme->tv3d;
582         SETCOLF(btheme->tfile.back, 0.3, 0.3, 0.3, 1);
583         SETCOLF(btheme->tfile.panel, 0.3, 0.3, 0.3, 1);
584         SETCOLF(btheme->tfile.list, 0.4, 0.4, 0.4, 1);
585         SETCOL(btheme->tfile.text,      250, 250, 250, 255);
586         SETCOL(btheme->tfile.text_hi, 15, 15, 15, 255);
587         SETCOL(btheme->tfile.panel, 145, 145, 145, 255);        // bookmark/ui regions
588         SETCOL(btheme->tfile.active, 130, 130, 130, 255); // selected files
589         SETCOL(btheme->tfile.hilite, 255, 140, 25, 255); // selected files
590         
591         SETCOL(btheme->tfile.grid,      250, 250, 250, 255);
592         SETCOL(btheme->tfile.image,     250, 250, 250, 255);
593         SETCOL(btheme->tfile.movie,     250, 250, 250, 255);
594         SETCOL(btheme->tfile.scene,     250, 250, 250, 255);
595
596         
597         /* space seq */
598         btheme->tseq= btheme->tv3d;
599         SETCOL(btheme->tseq.back,       116, 116, 116, 255);
600         SETCOL(btheme->tseq.movie,      81, 105, 135, 255);
601         SETCOL(btheme->tseq.image,      109, 88, 129, 255);
602         SETCOL(btheme->tseq.scene,      78, 152, 62, 255);
603         SETCOL(btheme->tseq.audio,      46, 143, 143, 255);
604         SETCOL(btheme->tseq.effect,     169, 84, 124, 255);
605         SETCOL(btheme->tseq.plugin,     126, 126, 80, 255);
606         SETCOL(btheme->tseq.transition, 162, 95, 111, 255);
607         SETCOL(btheme->tseq.meta,       109, 145, 131, 255);
608         
609
610         /* space image */
611         btheme->tima= btheme->tv3d;
612         SETCOL(btheme->tima.back,       53, 53, 53, 255);
613         SETCOL(btheme->tima.vertex, 0, 0, 0, 255);
614         SETCOL(btheme->tima.vertex_select, 255, 133, 0, 255);
615         btheme->tima.vertex_size= 3;
616         btheme->tima.facedot_size= 3;
617         SETCOL(btheme->tima.face,   255, 255, 255, 10);
618         SETCOL(btheme->tima.face_select, 255, 133, 0, 60);
619         SETCOL(btheme->tima.editmesh_active, 255, 255, 255, 128);
620         SETCOLF(btheme->tima.preview_back,      0.45, 0.45, 0.45, 1.0);
621
622         /* space imageselect */
623         btheme->timasel= btheme->tv3d;
624         SETCOL(btheme->timasel.active,  195, 195, 195, 255); /* active tile */
625         SETCOL(btheme->timasel.grid,  94, 94, 94, 255); /* active file text */
626         SETCOL(btheme->timasel.back,    110, 110, 110, 255);
627         SETCOL(btheme->timasel.shade1,  94, 94, 94, 255);       /* bar */
628         SETCOL(btheme->timasel.shade2,  172, 172, 172, 255); /* sliders */
629         SETCOL(btheme->timasel.hilite,  17, 27, 60, 100);       /* selected tile */
630         SETCOL(btheme->timasel.text,    0, 0, 0, 255);
631         SETCOL(btheme->timasel.text_hi, 255, 255, 255, 255);
632         SETCOL(btheme->timasel.panel,   132, 132, 132, 255);
633
634         /* space text */
635         btheme->text= btheme->tv3d;
636         SETCOL(btheme->text.back,       153, 153, 153, 255);
637         SETCOL(btheme->text.shade1,     143, 143, 143, 255);
638         SETCOL(btheme->text.shade2,     0xc6, 0x77, 0x77, 255);
639         SETCOL(btheme->text.hilite,     255, 0, 0, 255);
640         
641         /* syntax highlighting */
642         SETCOL(btheme->text.syntaxn,    0, 0, 200, 255);        /* Numbers  Blue*/
643         SETCOL(btheme->text.syntaxl,    100, 0, 0, 255);        /* Strings  red */
644         SETCOL(btheme->text.syntaxc,    0, 100, 50, 255);       /* Comments greenish */
645         SETCOL(btheme->text.syntaxv,    95, 95, 0, 255);        /* Special */
646         SETCOL(btheme->text.syntaxb,    128, 0, 80, 255);       /* Builtin, red-purple */
647         
648         /* space oops */
649         btheme->toops= btheme->tv3d;
650         SETCOLF(btheme->toops.back,     0.45, 0.45, 0.45, 1.0);
651         
652         /* space info */
653         btheme->tinfo= btheme->tv3d;
654         SETCOLF(btheme->tinfo.back,     0.45, 0.45, 0.45, 1.0);
655
656         /* space user preferences */
657         btheme->tuserpref= btheme->tv3d;
658         SETCOLF(btheme->tuserpref.back, 0.45, 0.45, 0.45, 1.0);
659         
660         /* space console */
661         btheme->tconsole= btheme->tv3d;
662         SETCOL(btheme->tconsole.back, 0, 0, 0, 255);
663         SETCOL(btheme->tconsole.console_output, 96, 128, 255, 255);
664         SETCOL(btheme->tconsole.console_input, 255, 255, 255, 255);
665         SETCOL(btheme->tconsole.console_info, 0, 170, 0, 255);
666         SETCOL(btheme->tconsole.console_error, 220, 96, 96, 255);
667         SETCOL(btheme->tconsole.console_cursor, 220, 96, 96, 255);
668         
669
670         /* space sound */
671         btheme->tsnd= btheme->tv3d;
672         SETCOLF(btheme->tsnd.back,      0.45, 0.45, 0.45, 1.0);
673         SETCOLF(btheme->tsnd.grid,      0.36, 0.36, 0.36, 1.0);
674         SETCOL(btheme->tsnd.shade1,  173, 173, 173, 255);               // sliders
675         
676         /* space time */
677         btheme->ttime= btheme->tsnd;    // same as sound space
678         
679         /* space node, re-uses syntax color storage */
680         btheme->tnode= btheme->tv3d;
681         SETCOL(btheme->tnode.edge_select, 255, 255, 255, 255);
682         SETCOL(btheme->tnode.syntaxl, 155, 155, 155, 160);      /* TH_NODE, backdrop */
683         SETCOL(btheme->tnode.syntaxn, 100, 100, 100, 255);      /* in/output */
684         SETCOL(btheme->tnode.syntaxb, 108, 105, 111, 255);      /* operator */
685         SETCOL(btheme->tnode.syntaxv, 104, 106, 117, 255);      /* generator */
686         SETCOL(btheme->tnode.syntaxc, 105, 117, 110, 255);      /* group */
687
688         /* space logic */
689         btheme->tlogic= btheme->tv3d;
690         SETCOL(btheme->tlogic.back, 100, 100, 100, 255);
691         
692 }
693
694
695 void UI_SetTheme(int spacetype, int regionid)
696 {
697         if(spacetype==0) {      // called for safety, when delete themes
698                 theme_active= U.themes.first;
699                 theme_spacetype= SPACE_VIEW3D;
700                 theme_regionid= RGN_TYPE_WINDOW;
701         }
702         else {
703                 // later on, a local theme can be found too
704                 theme_active= U.themes.first;
705                 theme_spacetype= spacetype;
706                 theme_regionid= regionid;
707         }
708 }
709
710 // for space windows only
711 void UI_ThemeColor(int colorid)
712 {
713         char *cp;
714         
715         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
716         glColor3ub(cp[0], cp[1], cp[2]);
717
718 }
719
720 // plus alpha
721 void UI_ThemeColor4(int colorid)
722 {
723         char *cp;
724         
725         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
726         glColor4ub(cp[0], cp[1], cp[2], cp[3]);
727
728 }
729
730 // set the color with offset for shades
731 void UI_ThemeColorShade(int colorid, int offset)
732 {
733         int r, g, b;
734         char *cp;
735         
736         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
737         r= offset + (int) cp[0];
738         CLAMP(r, 0, 255);
739         g= offset + (int) cp[1];
740         CLAMP(g, 0, 255);
741         b= offset + (int) cp[2];
742         CLAMP(b, 0, 255);
743         //glColor3ub(r, g, b);
744         glColor4ub(r, g, b, cp[3]);
745 }
746 void UI_ThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset)
747 {
748         int r, g, b, a;
749         char *cp;
750         
751         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
752         r= coloffset + (int) cp[0];
753         CLAMP(r, 0, 255);
754         g= coloffset + (int) cp[1];
755         CLAMP(g, 0, 255);
756         b= coloffset + (int) cp[2];
757         CLAMP(b, 0, 255);
758         a= alphaoffset + (int) cp[3];
759         CLAMP(a, 0, 255);
760         glColor4ub(r, g, b, a);
761 }
762
763 // blend between to theme colors, and set it
764 void UI_ThemeColorBlend(int colorid1, int colorid2, float fac)
765 {
766         int r, g, b;
767         char *cp1, *cp2;
768         
769         cp1= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
770         cp2= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
771
772         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
773         r= floor((1.0-fac)*cp1[0] + fac*cp2[0]);
774         g= floor((1.0-fac)*cp1[1] + fac*cp2[1]);
775         b= floor((1.0-fac)*cp1[2] + fac*cp2[2]);
776         
777         glColor3ub(r, g, b);
778 }
779
780 // blend between to theme colors, shade it, and set it
781 void UI_ThemeColorBlendShade(int colorid1, int colorid2, float fac, int offset)
782 {
783         int r, g, b;
784         char *cp1, *cp2;
785         
786         cp1= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
787         cp2= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
788
789         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
790         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
791         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
792         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
793         
794         CLAMP(r, 0, 255);
795         CLAMP(g, 0, 255);
796         CLAMP(b, 0, 255);
797         
798         glColor3ub(r, g, b);
799 }
800
801 // blend between to theme colors, shade it, and set it
802 void UI_ThemeColorBlendShadeAlpha(int colorid1, int colorid2, float fac, int offset, int alphaoffset)
803 {
804         int r, g, b, a;
805         char *cp1, *cp2;
806         
807         cp1= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
808         cp2= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
809
810         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
811         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
812         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
813         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
814         a= alphaoffset+floor((1.0-fac)*cp1[3] + fac*cp2[3]);
815         
816         CLAMP(r, 0, 255);
817         CLAMP(g, 0, 255);
818         CLAMP(b, 0, 255);
819         CLAMP(a, 0, 255);
820
821         glColor4ub(r, g, b, a);
822 }
823
824
825 // get individual values, not scaled
826 float UI_GetThemeValuef(int colorid)
827 {
828         char *cp;
829         
830         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
831         return ((float)cp[0]);
832
833 }
834
835 // get individual values, not scaled
836 int UI_GetThemeValue(int colorid)
837 {
838         char *cp;
839         
840         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
841         return ((int) cp[0]);
842
843 }
844
845
846 // get the color, range 0.0-1.0
847 void UI_GetThemeColor3fv(int colorid, float *col)
848 {
849         char *cp;
850         
851         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
852         col[0]= ((float)cp[0])/255.0;
853         col[1]= ((float)cp[1])/255.0;
854         col[2]= ((float)cp[2])/255.0;
855 }
856
857 // get the color, range 0.0-1.0, complete with shading offset
858 void UI_GetThemeColorShade3fv(int colorid, int offset, float *col)
859 {
860         int r, g, b;
861         char *cp;
862         
863         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
864         
865         r= offset + (int) cp[0];
866         CLAMP(r, 0, 255);
867         g= offset + (int) cp[1];
868         CLAMP(g, 0, 255);
869         b= offset + (int) cp[2];
870         CLAMP(b, 0, 255);
871         
872         col[0]= ((float)r)/255.0;
873         col[1]= ((float)g)/255.0;
874         col[2]= ((float)b)/255.0;
875 }
876
877 // get the color, in char pointer
878 void UI_GetThemeColor3ubv(int colorid, char *col)
879 {
880         char *cp;
881         
882         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
883         col[0]= cp[0];
884         col[1]= cp[1];
885         col[2]= cp[2];
886 }
887
888 // get the color, in char pointer
889 void UI_GetThemeColor4ubv(int colorid, char *col)
890 {
891         char *cp;
892         
893         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
894         col[0]= cp[0];
895         col[1]= cp[1];
896         col[2]= cp[2];
897         col[3]= cp[3];
898 }
899
900 void UI_GetThemeColorType4ubv(int colorid, int spacetype, char *col)
901 {
902         char *cp;
903         
904         cp= UI_ThemeGetColorPtr(theme_active, spacetype, colorid);
905         col[0]= cp[0];
906         col[1]= cp[1];
907         col[2]= cp[2];
908         col[3]= cp[3];
909 }
910
911 // blends and shades between two char color pointers
912 void UI_ColorPtrBlendShade3ubv(char *cp1, char *cp2, float fac, int offset)
913 {
914         int r, g, b;
915         
916         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
917         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
918         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
919         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
920         
921         r= r<0?0:(r>255?255:r);
922         g= g<0?0:(g>255?255:g);
923         b= b<0?0:(b>255?255:b);
924         
925         glColor3ub(r, g, b);
926 }
927
928 // get a 3 byte color, blended and shaded between two other char color pointers
929 void UI_GetColorPtrBlendShade3ubv(char *cp1, char *cp2, char *col, float fac, int offset)
930 {
931         int r, g, b;
932         
933         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
934         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
935         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
936         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
937         
938         r= r<0?0:(r>255?255:r);
939         g= g<0?0:(g>255?255:g);
940         b= b<0?0:(b>255?255:b);
941         
942         col[0] = r;
943         col[1] = g;
944         col[2] = b;
945 }
946
947 void UI_ThemeClearColor(int colorid)
948 {
949         float col[3];
950         
951         UI_GetThemeColor3fv(colorid, col);
952         glClearColor(col[0], col[1], col[2], 0.0);
953 }
954
955 void UI_make_axis_color(char *src_col, char *dst_col, char axis)
956 {
957         switch(axis)
958         {
959                 case 'x':
960                 case 'X':
961                         dst_col[0]= src_col[0]>219?255:src_col[0]+36;
962                         dst_col[1]= src_col[1]<26?0:src_col[1]-26;
963                         dst_col[2]= src_col[2]<26?0:src_col[2]-26;
964                         break;
965                 case 'y':
966                 case 'Y':
967                         dst_col[0]= src_col[0]<46?0:src_col[0]-36;
968                         dst_col[1]= src_col[1]>189?255:src_col[1]+66;
969                         dst_col[2]= src_col[2]<46?0:src_col[2]-36;
970                         break;
971                 default: 
972                         dst_col[0]= src_col[0]<26?0:src_col[0]-26; 
973                         dst_col[1]= src_col[1]<26?0:src_col[1]-26; 
974                         dst_col[2]= src_col[2]>209?255:src_col[2]+46;
975         }
976 }
977
978 /* ************************************************************* */
979
980 /* patching UserDef struct and Themes */
981 void init_userdef_do_versions(void)
982 {
983 //      countall();
984         
985         /* the UserDef struct is not corrected with do_versions() .... ugh! */
986         if(U.wheellinescroll == 0) U.wheellinescroll = 3;
987         if(U.menuthreshold1==0) {
988                 U.menuthreshold1= 5;
989                 U.menuthreshold2= 2;
990         }
991         if(U.tb_leftmouse==0) {
992                 U.tb_leftmouse= 5;
993                 U.tb_rightmouse= 5;
994         }
995         if(U.mixbufsize==0) U.mixbufsize= 2048;
996         if (BLI_streq(U.tempdir, "/")) {
997                 char *tmp= getenv("TEMP");
998                 
999                 strcpy(U.tempdir, tmp?tmp:"/tmp/");
1000         }
1001         if (U.savetime <= 0) {
1002                 U.savetime = 1;
1003 // XXX          error(".B.blend is buggy, please consider removing it.\n");
1004         }
1005         /* transform widget settings */
1006         if(U.tw_hotspot==0) {
1007                 U.tw_hotspot= 14;
1008                 U.tw_size= 20;                  // percentage of window size
1009                 U.tw_handlesize= 16;    // percentage of widget radius
1010         }
1011         if(U.pad_rot_angle==0)
1012                 U.pad_rot_angle= 15;
1013         
1014         if(U.flag & USER_CUSTOM_RANGE) 
1015                 vDM_ColorBand_store(&U.coba_weight); /* signal for derivedmesh to use colorband */
1016         
1017         if (G.main->versionfile <= 191) {
1018                 strcpy(U.plugtexdir, U.textudir);
1019                 strcpy(U.sounddir, "/");
1020         }
1021         
1022         /* patch to set Dupli Armature */
1023         if (G.main->versionfile < 220) {
1024                 U.dupflag |= USER_DUP_ARM;
1025         }
1026         
1027         /* added seam, normal color, undo */
1028         if (G.main->versionfile <= 234) {
1029                 bTheme *btheme;
1030                 
1031                 U.uiflag |= USER_GLOBALUNDO;
1032                 if (U.undosteps==0) U.undosteps=32;
1033                 
1034                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1035                         /* check for alpha==0 is safe, then color was never set */
1036                         if(btheme->tv3d.edge_seam[3]==0) {
1037                                 SETCOL(btheme->tv3d.edge_seam, 230, 150, 50, 255);
1038                         }
1039                         if(btheme->tv3d.normal[3]==0) {
1040                                 SETCOL(btheme->tv3d.normal, 0x22, 0xDD, 0xDD, 255);
1041                         }
1042                         if(btheme->tv3d.vertex_normal[3]==0) {
1043                                 SETCOL(btheme->tv3d.vertex_normal, 0x23, 0x61, 0xDD, 255);
1044                         }
1045                         if(btheme->tv3d.face_dot[3]==0) {
1046                                 SETCOL(btheme->tv3d.face_dot, 255, 138, 48, 255);
1047                                 btheme->tv3d.facedot_size= 4;
1048                         }
1049                 }
1050         }
1051         if (G.main->versionfile <= 235) {
1052                 /* illegal combo... */
1053                 if (U.flag & USER_LMOUSESELECT) 
1054                         U.flag &= ~USER_TWOBUTTONMOUSE;
1055         }
1056         if (G.main->versionfile <= 236) {
1057                 bTheme *btheme;
1058                 /* new space type */
1059                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1060                         /* check for alpha==0 is safe, then color was never set */
1061                         if(btheme->ttime.back[3]==0) {
1062                                 btheme->ttime = btheme->tsnd;   // copy from sound
1063                         }
1064                         if(btheme->text.syntaxn[3]==0) {
1065                                 SETCOL(btheme->text.syntaxn,    0, 0, 200, 255);        /* Numbers  Blue*/
1066                                 SETCOL(btheme->text.syntaxl,    100, 0, 0, 255);        /* Strings  red */
1067                                 SETCOL(btheme->text.syntaxc,    0, 100, 50, 255);       /* Comments greenish */
1068                                 SETCOL(btheme->text.syntaxv,    95, 95, 0, 255);        /* Special */
1069                                 SETCOL(btheme->text.syntaxb,    128, 0, 80, 255);       /* Builtin, red-purple */
1070                         }
1071                 }
1072         }
1073         if (G.main->versionfile <= 237) {
1074                 bTheme *btheme;
1075                 /* bone colors */
1076                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1077                         /* check for alpha==0 is safe, then color was never set */
1078                         if(btheme->tv3d.bone_solid[3]==0) {
1079                                 SETCOL(btheme->tv3d.bone_solid, 200, 200, 200, 255);
1080                                 SETCOL(btheme->tv3d.bone_pose, 80, 200, 255, 80);
1081                         }
1082                 }
1083         }
1084         if (G.main->versionfile <= 238) {
1085                 bTheme *btheme;
1086                 /* bone colors */
1087                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1088                         /* check for alpha==0 is safe, then color was never set */
1089                         if(btheme->tnla.strip[3]==0) {
1090                                 SETCOL(btheme->tnla.strip_select,       0xff, 0xff, 0xaa, 255);
1091                                 SETCOL(btheme->tnla.strip, 0xe4, 0x9c, 0xc6, 255);
1092                         }
1093                 }
1094         }
1095         if (G.main->versionfile <= 239) {
1096                 bTheme *btheme;
1097                 
1098                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1099                         /* Lamp theme, check for alpha==0 is safe, then color was never set */
1100                         if(btheme->tv3d.lamp[3]==0) {
1101                                 SETCOL(btheme->tv3d.lamp,       0, 0, 0, 40);
1102 /* TEMPORAL, remove me! (ton) */                                
1103                                 U.uiflag |= USER_PLAINMENUS;
1104                         }
1105                         
1106                 }
1107                 if(U.obcenter_dia==0) U.obcenter_dia= 6;
1108         }
1109         if (G.main->versionfile <= 241) {
1110                 bTheme *btheme;
1111                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1112                         /* Node editor theme, check for alpha==0 is safe, then color was never set */
1113                         if(btheme->tnode.syntaxn[3]==0) {
1114                                 /* re-uses syntax color storage */
1115                                 btheme->tnode= btheme->tv3d;
1116                                 SETCOL(btheme->tnode.edge_select, 255, 255, 255, 255);
1117                                 SETCOL(btheme->tnode.syntaxl, 150, 150, 150, 255);      /* TH_NODE, backdrop */
1118                                 SETCOL(btheme->tnode.syntaxn, 129, 131, 144, 255);      /* in/output */
1119                                 SETCOL(btheme->tnode.syntaxb, 127,127,127, 255);        /* operator */
1120                                 SETCOL(btheme->tnode.syntaxv, 142, 138, 145, 255);      /* generator */
1121                                 SETCOL(btheme->tnode.syntaxc, 120, 145, 120, 255);      /* group */
1122                         }
1123                         /* Group theme colors */
1124                         if(btheme->tv3d.group[3]==0) {
1125                                 SETCOL(btheme->tv3d.group, 0x0C, 0x30, 0x0C, 255);
1126                                 SETCOL(btheme->tv3d.group_active, 0x66, 0xFF, 0x66, 255);
1127                         }
1128                         /* Sequence editor theme*/
1129                         if(btheme->tseq.movie[3]==0) {
1130                                 SETCOL(btheme->tseq.movie,      81, 105, 135, 255);
1131                                 SETCOL(btheme->tseq.image,      109, 88, 129, 255);
1132                                 SETCOL(btheme->tseq.scene,      78, 152, 62, 255);
1133                                 SETCOL(btheme->tseq.audio,      46, 143, 143, 255);
1134                                 SETCOL(btheme->tseq.effect,     169, 84, 124, 255);
1135                                 SETCOL(btheme->tseq.plugin,     126, 126, 80, 255);
1136                                 SETCOL(btheme->tseq.transition, 162, 95, 111, 255);
1137                                 SETCOL(btheme->tseq.meta,       109, 145, 131, 255);
1138                         }
1139                 }
1140                 
1141                 /* set defaults for 3D View rotating axis indicator */ 
1142                 /* since size can't be set to 0, this indicates it's not saved in .B.blend */
1143                 if (U.rvisize == 0) {
1144                         U.rvisize = 15;
1145                         U.rvibright = 8;
1146                         U.uiflag |= USER_SHOW_ROTVIEWICON;
1147                 }
1148                 
1149         }
1150         if (G.main->versionfile <= 242) {
1151                 bTheme *btheme;
1152                 
1153                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1154                         /* long keyframe color */
1155                         /* check for alpha==0 is safe, then color was never set */
1156                         if(btheme->tact.strip[3]==0) {
1157                                 SETCOL(btheme->tv3d.edge_sharp, 255, 32, 32, 255);
1158                                 SETCOL(btheme->tact.strip_select,       0xff, 0xff, 0xaa, 204);
1159                                 SETCOL(btheme->tact.strip, 0xe4, 0x9c, 0xc6, 204);
1160                         }
1161                         
1162                         /* IPO-Editor - Vertex Size*/
1163                         if(btheme->tipo.vertex_size == 0) {
1164                                 btheme->tipo.vertex_size= 3;
1165                         }
1166                 }
1167         }
1168         if (G.main->versionfile <= 243) {
1169                 /* set default number of recently-used files (if not set) */
1170                 if (U.recent_files == 0) U.recent_files = 10;
1171         }
1172         if (G.main->versionfile < 245 || (G.main->versionfile == 245 && G.main->subversionfile < 3)) {
1173                 bTheme *btheme;
1174                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1175                         SETCOL(btheme->tv3d.editmesh_active, 255, 255, 255, 128);
1176                 }
1177                 if(U.coba_weight.tot==0)
1178                         init_colorband(&U.coba_weight, 1);
1179         }
1180         if ((G.main->versionfile < 245) || (G.main->versionfile == 245 && G.main->subversionfile < 11)) {
1181                 bTheme *btheme;
1182                 for (btheme= U.themes.first; btheme; btheme= btheme->next) {
1183                         /* these should all use the same colour */
1184                         SETCOL(btheme->tv3d.cframe, 0x60, 0xc0, 0x40, 255);
1185                         SETCOL(btheme->tipo.cframe, 0x60, 0xc0, 0x40, 255);
1186                         SETCOL(btheme->tact.cframe, 0x60, 0xc0, 0x40, 255);
1187                         SETCOL(btheme->tnla.cframe, 0x60, 0xc0, 0x40, 255);
1188                         SETCOL(btheme->tseq.cframe, 0x60, 0xc0, 0x40, 255);
1189                         SETCOL(btheme->tsnd.cframe, 0x60, 0xc0, 0x40, 255);
1190                         SETCOL(btheme->ttime.cframe, 0x60, 0xc0, 0x40, 255);
1191                 }
1192         }
1193         if ((G.main->versionfile < 245) || (G.main->versionfile == 245 && G.main->subversionfile < 13)) {
1194                 bTheme *btheme;
1195                 for (btheme= U.themes.first; btheme; btheme= btheme->next) {
1196                         /* action channel groups (recolor anyway) */
1197                         SETCOL(btheme->tact.group, 0x39, 0x7d, 0x1b, 255);
1198                         SETCOL(btheme->tact.group_active, 0x7d, 0xe9, 0x60, 255);
1199                         
1200                         /* bone custom-color sets */
1201                         // FIXME: this check for initialised colors is bad
1202                         if (btheme->tarm[0].solid[3] == 0) {
1203                                         /* set 1 */
1204                                 SETCOL(btheme->tarm[0].solid, 0x9a, 0x00, 0x00, 255);
1205                                 SETCOL(btheme->tarm[0].select, 0xbd, 0x11, 0x11, 255);
1206                                 SETCOL(btheme->tarm[0].active, 0xf7, 0x0a, 0x0a, 255);
1207                                         /* set 2 */
1208                                 SETCOL(btheme->tarm[1].solid, 0xf7, 0x40, 0x18, 255);
1209                                 SETCOL(btheme->tarm[1].select, 0xf6, 0x69, 0x13, 255);
1210                                 SETCOL(btheme->tarm[1].active, 0xfa, 0x99, 0x00, 255);
1211                                         /* set 3 */
1212                                 SETCOL(btheme->tarm[2].solid, 0x1e, 0x91, 0x09, 255);
1213                                 SETCOL(btheme->tarm[2].select, 0x59, 0xb7, 0x0b, 255);
1214                                 SETCOL(btheme->tarm[2].active, 0x83, 0xef, 0x1d, 255);
1215                                         /* set 4 */
1216                                 SETCOL(btheme->tarm[3].solid, 0x0a, 0x36, 0x94, 255);
1217                                 SETCOL(btheme->tarm[3].select, 0x36, 0x67, 0xdf, 255);
1218                                 SETCOL(btheme->tarm[3].active, 0x5e, 0xc1, 0xef, 255);
1219                                         /* set 5 */
1220                                 SETCOL(btheme->tarm[4].solid, 0xa9, 0x29, 0x4e, 255);
1221                                 SETCOL(btheme->tarm[4].select, 0xc1, 0x41, 0x6a, 255);
1222                                 SETCOL(btheme->tarm[4].active, 0xf0, 0x5d, 0x91, 255);
1223                                         /* set 6 */
1224                                 SETCOL(btheme->tarm[5].solid, 0x43, 0x0c, 0x78, 255);
1225                                 SETCOL(btheme->tarm[5].select, 0x54, 0x3a, 0xa3, 255);
1226                                 SETCOL(btheme->tarm[5].active, 0x87, 0x64, 0xd5, 255);
1227                                         /* set 7 */
1228                                 SETCOL(btheme->tarm[6].solid, 0x24, 0x78, 0x5a, 255);
1229                                 SETCOL(btheme->tarm[6].select, 0x3c, 0x95, 0x79, 255);
1230                                 SETCOL(btheme->tarm[6].active, 0x6f, 0xb6, 0xab, 255);
1231                                         /* set 8 */
1232                                 SETCOL(btheme->tarm[7].solid, 0x4b, 0x70, 0x7c, 255);
1233                                 SETCOL(btheme->tarm[7].select, 0x6a, 0x86, 0x91, 255);
1234                                 SETCOL(btheme->tarm[7].active, 0x9b, 0xc2, 0xcd, 255);
1235                                         /* set 9 */
1236                                 SETCOL(btheme->tarm[8].solid, 0xf4, 0xc9, 0x0c, 255);
1237                                 SETCOL(btheme->tarm[8].select, 0xee, 0xc2, 0x36, 255);
1238                                 SETCOL(btheme->tarm[8].active, 0xf3, 0xff, 0x00, 255);
1239                                         /* set 10 */
1240                                 SETCOL(btheme->tarm[9].solid, 0x1e, 0x20, 0x24, 255);
1241                                 SETCOL(btheme->tarm[9].select, 0x48, 0x4c, 0x56, 255);
1242                                 SETCOL(btheme->tarm[9].active, 0xff, 0xff, 0xff, 255);
1243                                         /* set 11 */
1244                                 SETCOL(btheme->tarm[10].solid, 0x6f, 0x2f, 0x6a, 255);
1245                                 SETCOL(btheme->tarm[10].select, 0x98, 0x45, 0xbe, 255);
1246                                 SETCOL(btheme->tarm[10].active, 0xd3, 0x30, 0xd6, 255);
1247                                         /* set 12 */
1248                                 SETCOL(btheme->tarm[11].solid, 0x6c, 0x8e, 0x22, 255);
1249                                 SETCOL(btheme->tarm[11].select, 0x7f, 0xb0, 0x22, 255);
1250                                 SETCOL(btheme->tarm[11].active, 0xbb, 0xef, 0x5b, 255);
1251                                         /* set 13 */
1252                                 SETCOL(btheme->tarm[12].solid, 0x8d, 0x8d, 0x8d, 255);
1253                                 SETCOL(btheme->tarm[12].select, 0xb0, 0xb0, 0xb0, 255);
1254                                 SETCOL(btheme->tarm[12].active, 0xde, 0xde, 0xde, 255);
1255                                         /* set 14 */
1256                                 SETCOL(btheme->tarm[13].solid, 0x83, 0x43, 0x26, 255);
1257                                 SETCOL(btheme->tarm[13].select, 0x8b, 0x58, 0x11, 255);
1258                                 SETCOL(btheme->tarm[13].active, 0xbd, 0x6a, 0x11, 255);
1259                                         /* set 15 */
1260                                 SETCOL(btheme->tarm[14].solid, 0x08, 0x31, 0x0e, 255);
1261                                 SETCOL(btheme->tarm[14].select, 0x1c, 0x43, 0x0b, 255);
1262                                 SETCOL(btheme->tarm[14].active, 0x34, 0x62, 0x2b, 255);
1263                         }
1264                 }
1265         }
1266         if ((G.main->versionfile < 245) || (G.main->versionfile == 245 && G.main->subversionfile < 16)) {
1267                 U.flag |= USER_ADD_VIEWALIGNED|USER_ADD_EDITMODE;
1268         }
1269         if ((G.main->versionfile < 247) || (G.main->versionfile == 247 && G.main->subversionfile <= 2)) {
1270                 bTheme *btheme;
1271                 
1272                 /* adjust themes */
1273                 for (btheme= U.themes.first; btheme; btheme= btheme->next) {
1274                         char *col;
1275                         
1276                         /* IPO Editor: Handles/Vertices */
1277                         col = btheme->tipo.vertex;
1278                         SETCOL(btheme->tipo.handle_vertex, col[0], col[1], col[2], 255);
1279                         col = btheme->tipo.vertex_select;
1280                         SETCOL(btheme->tipo.handle_vertex_select, col[0], col[1], col[2], 255);
1281                         btheme->tipo.handle_vertex_size= btheme->tipo.vertex_size;
1282                         
1283                         /* Sequence/Image Editor: colors for GPencil text */
1284                         col = btheme->tv3d.bone_pose;
1285                         SETCOL(btheme->tseq.bone_pose, col[0], col[1], col[2], 255);
1286                         SETCOL(btheme->tima.bone_pose, col[0], col[1], col[2], 255);
1287                         col = btheme->tv3d.vertex_select;
1288                         SETCOL(btheme->tseq.vertex_select, col[0], col[1], col[2], 255);
1289                 }
1290         }
1291         if (G.main->versionfile < 250) {
1292                 bTheme *btheme;
1293                 
1294                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1295                         /* this was not properly initialized in 2.45 */
1296                         if(btheme->tima.face_dot[3]==0) {
1297                                 SETCOL(btheme->tima.editmesh_active, 255, 255, 255, 128);
1298                                 SETCOL(btheme->tima.face_dot, 255, 133, 0, 255);
1299                                 btheme->tima.facedot_size= 2;
1300                         }
1301                         
1302                         /* DopeSheet - (Object) Channel color */
1303                         SETCOL(btheme->tact.ds_channel,         82, 96, 110, 255);
1304                         SETCOL(btheme->tact.ds_subchannel,      124, 137, 150, 255);
1305                         /* DopeSheet - Group Channel color (saner version) */
1306                         SETCOL(btheme->tact.group, 79, 101, 73, 255);
1307                         SETCOL(btheme->tact.group_active, 135, 177, 125, 255);
1308                         
1309                         /* Graph Editor - (Object) Channel color */
1310                         SETCOL(btheme->tipo.ds_channel,         82, 96, 110, 255);
1311                         SETCOL(btheme->tipo.ds_subchannel,      124, 137, 150, 255);
1312                         /* Graph Editor - Group Channel color */
1313                         SETCOL(btheme->tipo.group, 79, 101, 73, 255);
1314                         SETCOL(btheme->tipo.group_active, 135, 177, 125, 255);
1315                         
1316                         /* Nla Editor - (Object) Channel color */
1317                         SETCOL(btheme->tnla.ds_channel,         82, 96, 110, 255);
1318                         SETCOL(btheme->tnla.ds_subchannel,      124, 137, 150, 255);
1319                         /* NLA Editor - New Strip colors */
1320                         SETCOL(btheme->tnla.strip,                      12, 10, 10, 128); 
1321                         SETCOL(btheme->tnla.strip_select,       255, 140, 0, 255);
1322                 }
1323                 
1324                 /* adjust grease-pencil distances */
1325                 U.gp_manhattendist= 1;
1326                 U.gp_euclideandist= 2;
1327                 
1328                 /* adjust default interpolation for new IPO-curves */
1329                 U.ipo_new= BEZT_IPO_BEZ;
1330         }
1331         
1332         if (G.main->versionfile < 250 || (G.main->versionfile == 250 && G.main->subversionfile < 1)) {
1333                 bTheme *btheme;
1334
1335                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1336                         
1337                         /* common (new) variables, it checks for alpha==0 */
1338                         ui_theme_init_new(btheme);
1339
1340                         if(btheme->tui.wcol_num.outline[3]==0)
1341                                 ui_widget_color_init(&btheme->tui);
1342                         
1343                         /* Logic editor theme, check for alpha==0 is safe, then color was never set */
1344                         if(btheme->tlogic.syntaxn[3]==0) {
1345                                 /* re-uses syntax color storage */
1346                                 btheme->tlogic= btheme->tv3d;
1347                                 SETCOL(btheme->tlogic.back, 100, 100, 100, 255);
1348                         }
1349
1350                         SETCOLF(btheme->tinfo.back, 0.45, 0.45, 0.45, 1.0);
1351                         SETCOLF(btheme->tuserpref.back, 0.45, 0.45, 0.45, 1.0);
1352                 }
1353         }
1354
1355         if (G.main->versionfile < 250 || (G.main->versionfile == 250 && G.main->subversionfile < 3)) {
1356                 /* new audio system */
1357                 if(U.audiochannels == 0)
1358                         U.audiochannels = 2;
1359                 if(U.audiodevice == 0) {
1360 #ifdef WITH_OPENAL
1361                         U.audiodevice = 2;
1362 #endif
1363 #ifdef WITH_SDL
1364                         U.audiodevice = 1;
1365 #endif
1366                 }
1367                 if(U.audioformat == 0)
1368                         U.audioformat = 0x24;
1369                 if(U.audiorate == 0)
1370                         U.audiorate = 44100;
1371         }
1372
1373         if (G.main->versionfile < 250 || (G.main->versionfile == 250 && G.main->subversionfile < 5))
1374                 U.gameflags |= USER_DISABLE_VBO;
1375         
1376         if (G.main->versionfile < 250 || (G.main->versionfile == 250 && G.main->subversionfile < 8)) {
1377                 wmKeyMap *km;
1378                 
1379                 for(km=U.keymaps.first; km; km=km->next) {
1380                         if (strcmp(km->idname, "Armature_Sketch")==0)
1381                                 strcpy(km->idname, "Armature Sketch");
1382                         else if (strcmp(km->idname, "View3D")==0)
1383                                 strcpy(km->idname, "3D View");
1384                         else if (strcmp(km->idname, "View3D Generic")==0)
1385                                 strcpy(km->idname, "3D View Generic");
1386                         else if (strcmp(km->idname, "EditMesh")==0)
1387                                 strcpy(km->idname, "Mesh");
1388                         else if (strcmp(km->idname, "TimeLine")==0)
1389                                 strcpy(km->idname, "Timeline");
1390                         else if (strcmp(km->idname, "UVEdit")==0)
1391                                 strcpy(km->idname, "UV Editor");
1392                         else if (strcmp(km->idname, "Animation_Channels")==0)
1393                                 strcpy(km->idname, "Animation Channels");
1394                         else if (strcmp(km->idname, "GraphEdit Keys")==0)
1395                                 strcpy(km->idname, "Graph Editor");
1396                         else if (strcmp(km->idname, "GraphEdit Generic")==0)
1397                                 strcpy(km->idname, "Graph Editor Generic");
1398                         else if (strcmp(km->idname, "Action_Keys")==0)
1399                                 strcpy(km->idname, "Dopesheet");
1400                         else if (strcmp(km->idname, "NLA Data")==0)
1401                                 strcpy(km->idname, "NLA Editor");
1402                         else if (strcmp(km->idname, "Node Generic")==0)
1403                                 strcpy(km->idname, "Node Editor");
1404                         else if (strcmp(km->idname, "Logic Generic")==0)
1405                                 strcpy(km->idname, "Logic Editor");
1406                         else if (strcmp(km->idname, "File")==0)
1407                                 strcpy(km->idname, "File Browser");
1408                         else if (strcmp(km->idname, "FileMain")==0)
1409                                 strcpy(km->idname, "File Browser Main");
1410                         else if (strcmp(km->idname, "FileButtons")==0)
1411                                 strcpy(km->idname, "File Browser Buttons");
1412                         else if (strcmp(km->idname, "Buttons Generic")==0)
1413                                 strcpy(km->idname, "Property Editor");
1414                 }
1415         }
1416         if (G.main->versionfile < 250 || (G.main->versionfile == 250 && G.main->subversionfile < 16)) {
1417                 if(U.wmdrawmethod == USER_DRAW_TRIPLE)
1418                         U.wmdrawmethod = USER_DRAW_AUTOMATIC;
1419         }
1420         
1421         if (G.main->versionfile < 252 || (G.main->versionfile == 252 && G.main->subversionfile < 3)) {
1422                 if (U.flag & USER_LMOUSESELECT) 
1423                         U.flag &= ~USER_TWOBUTTONMOUSE;
1424         }
1425         if (G.main->versionfile < 252 || (G.main->versionfile == 252 && G.main->subversionfile < 4)) {
1426                 bTheme *btheme;
1427                 
1428                 /* default new handle type is auto handles */
1429                 U.keyhandles_new = HD_AUTO;
1430                 
1431                 /* init new curve colors */
1432                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1433                         /* init colors used for handles in 3D-View  */
1434                         SETCOL(btheme->tv3d.handle_free, 0, 0, 0, 255);
1435                         SETCOL(btheme->tv3d.handle_auto, 0x90, 0x90, 0x00, 255);
1436                         SETCOL(btheme->tv3d.handle_vect, 0x40, 0x90, 0x30, 255);
1437                         SETCOL(btheme->tv3d.handle_align, 0x80, 0x30, 0x60, 255);
1438                         SETCOL(btheme->tv3d.handle_sel_free, 0, 0, 0, 255);
1439                         SETCOL(btheme->tv3d.handle_sel_auto, 0xf0, 0xff, 0x40, 255);
1440                         SETCOL(btheme->tv3d.handle_sel_vect, 0x40, 0xc0, 0x30, 255);
1441                         SETCOL(btheme->tv3d.handle_sel_align, 0xf0, 0x90, 0xa0, 255);
1442                         SETCOL(btheme->tv3d.act_spline, 0xdb, 0x25, 0x12, 255);
1443                         
1444                         /* same colors again for Graph Editor... */
1445                         SETCOL(btheme->tipo.handle_free, 0, 0, 0, 255);
1446                         SETCOL(btheme->tipo.handle_auto, 0x90, 0x90, 0x00, 255);
1447                         SETCOL(btheme->tipo.handle_vect, 0x40, 0x90, 0x30, 255);
1448                         SETCOL(btheme->tipo.handle_align, 0x80, 0x30, 0x60, 255);
1449                         SETCOL(btheme->tipo.handle_sel_free, 0, 0, 0, 255);
1450                         SETCOL(btheme->tipo.handle_sel_auto, 0xf0, 0xff, 0x40, 255);
1451                         SETCOL(btheme->tipo.handle_sel_vect, 0x40, 0xc0, 0x30, 255);
1452                         SETCOL(btheme->tipo.handle_sel_align, 0xf0, 0x90, 0xa0, 255);
1453                         
1454                         /* edge crease */
1455                         SETCOLF(btheme->tv3d.edge_crease, 0.8, 0, 0.6, 1.0);
1456                 }
1457         }
1458
1459         
1460         /* GL Texture Garbage Collection (variable abused above!) */
1461         if (U.textimeout == 0) {
1462                 U.texcollectrate = 60;
1463                 U.textimeout = 120;
1464         }
1465         if (U.memcachelimit <= 0) {
1466                 U.memcachelimit = 32;
1467         }
1468         if (U.frameserverport == 0) {
1469                 U.frameserverport = 8080;
1470         }
1471         if (U.dbl_click_time == 0) {
1472                 U.dbl_click_time = 350;
1473         }
1474         if (U.anim_player_preset == 0) {
1475                 U.anim_player_preset =1 ;
1476         }
1477         if (U.scrcastfps == 0) {
1478                 U.scrcastfps = 10;
1479                 U.scrcastwait = 50;
1480         }
1481         if (U.v2d_min_gridsize == 0) {
1482                 U.v2d_min_gridsize= 35;
1483         }
1484
1485         /* funny name, but it is GE stuff, moves userdef stuff to engine */
1486 // XXX  space_set_commmandline_options();
1487         /* this timer uses U */
1488 // XXX  reset_autosave();
1489
1490 }
1491
1492
1493