2.5 UI:
[blender.git] / source / blender / editors / interface / resources.c
1 /**
2  * $Id: resources.c 12755 2007-12-02 05:50:38Z aligorith $
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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_listBase.h"
46 #include "DNA_userdef_types.h"
47 #include "DNA_screen_types.h"
48 #include "DNA_space_types.h"
49
50 #include "BLI_blenlib.h"
51
52 #include "IMB_imbuf.h"
53 #include "IMB_imbuf_types.h"
54
55 #include "BKE_DerivedMesh.h"
56 #include "BKE_global.h"
57 #include "BKE_main.h"
58 #include "BKE_texture.h"
59 #include "BKE_utildefines.h"
60
61 #include "BIF_gl.h"
62
63 #include "UI_interface.h"
64 #include "UI_resources.h"
65 #include "UI_interface_icons.h"
66
67 #include "interface_intern.h"
68
69 /* global for themes */
70 typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha);
71
72 static bTheme *theme_active=NULL;
73 static int theme_spacetype= SPACE_VIEW3D;
74 static int theme_regionid= RGN_TYPE_WINDOW;
75
76 void ui_resources_init(void)
77 {
78         UI_icons_init(BIFICONID_LAST+1);
79 }
80
81 void ui_resources_free(void)
82 {
83         UI_icons_free();
84 }
85
86
87 /* ******************************************************** */
88 /*    THEMES */
89 /* ******************************************************** */
90
91 char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
92 {
93         ThemeSpace *ts= NULL;
94         static char error[4]={240, 0, 240, 255};
95         static char alert[4]={240, 60, 60, 255};
96         static char headerdesel[4]={0,0,0,255};
97         
98         char *cp= error;
99         
100         if(btheme) {
101         
102                 // first check for ui buttons theme
103                 if(colorid < TH_THEMEUI) {
104                 
105                         switch(colorid) {
106
107                         case TH_REDALERT:
108                                 cp= alert; break;
109                         }
110                 }
111                 else {
112                 
113                         switch(spacetype) {
114                         case SPACE_BUTS:
115                                 ts= &btheme->tbuts;
116                                 break;
117                         case SPACE_VIEW3D:
118                                 ts= &btheme->tv3d;
119                                 break;
120                         case SPACE_IPO:
121                                 ts= &btheme->tipo;
122                                 break;
123                         case SPACE_FILE:
124                                 ts= &btheme->tfile;
125                                 break;
126                         case SPACE_NLA:
127                                 ts= &btheme->tnla;
128                                 break;
129                         case SPACE_ACTION:
130                                 ts= &btheme->tact;
131                                 break;
132                         case SPACE_SEQ:
133                                 ts= &btheme->tseq;
134                                 break;
135                         case SPACE_IMAGE:
136                                 ts= &btheme->tima;
137                                 break;
138                         case SPACE_IMASEL:
139                                 ts= &btheme->timasel;
140                                 break;
141                         case SPACE_TEXT:
142                                 ts= &btheme->text;
143                                 break;
144                         case SPACE_OUTLINER:
145                                 ts= &btheme->toops;
146                                 break;
147                         case SPACE_SOUND:
148                                 ts= &btheme->tsnd;
149                                 break;
150                         case SPACE_INFO:
151                                 ts= &btheme->tinfo;
152                                 break;
153                         case SPACE_TIME:
154                                 ts= &btheme->ttime;
155                                 break;
156                         case SPACE_NODE:
157                                 ts= &btheme->tnode;
158                                 break;
159                         default:
160                                 ts= &btheme->tv3d;
161                                 break;
162                         }
163                         
164                         switch(colorid) {
165                         case TH_BACK:
166                                 if(theme_regionid==RGN_TYPE_WINDOW)
167                                         cp= ts->back;
168                                 else if(theme_regionid==RGN_TYPE_CHANNELS)
169                                         cp= ts->list;
170                                 else if(theme_regionid==RGN_TYPE_HEADER)
171                                         cp= ts->header;
172                                 else
173                                         cp= ts->button; 
174                                 break;
175                         case TH_TEXT:
176                                 if(theme_regionid==RGN_TYPE_WINDOW)
177                                         cp= ts->text; 
178                                 else if(theme_regionid==RGN_TYPE_CHANNELS)
179                                         cp= ts->list_text;
180                                 else if(theme_regionid==RGN_TYPE_HEADER)
181                                         cp= ts->header_text;
182                                 else
183                                         cp= ts->button_text; 
184                                 break;
185                         case TH_TEXT_HI:
186                                 if(theme_regionid==RGN_TYPE_WINDOW)
187                                         cp= ts->text_hi;
188                                 else if(theme_regionid==RGN_TYPE_CHANNELS)
189                                         cp= ts->list_text_hi;
190                                 else if(theme_regionid==RGN_TYPE_HEADER)
191                                         cp= ts->header_text_hi;
192                                 else
193                                         cp= ts->button_text_hi; 
194                                 break;
195                         case TH_TITLE:
196                                 if(theme_regionid==RGN_TYPE_WINDOW)
197                                         cp= ts->title;
198                                 else if(theme_regionid==RGN_TYPE_CHANNELS)
199                                         cp= ts->list_title;
200                                 else if(theme_regionid==RGN_TYPE_HEADER)
201                                         cp= ts->header_title;
202                                 else
203                                         cp= ts->button_title; 
204                                 break;
205                                 
206                         case TH_HEADER:
207                                 cp= ts->header; break;
208                         case TH_HEADERDESEL:
209                                 /* we calculate a dynamic builtin header deselect color, also for pulldowns... */
210                                 cp= ts->header; 
211                                 headerdesel[0]= cp[0]>10?cp[0]-10:0;
212                                 headerdesel[1]= cp[1]>10?cp[1]-10:0;
213                                 headerdesel[2]= cp[2]>10?cp[2]-10:0;
214                                 cp= headerdesel;
215                                 break;
216                         case TH_HEADER_TEXT:
217                                 cp= ts->header_text; break;
218                         case TH_HEADER_TEXT_HI:
219                                 cp= ts->header_text_hi; break;
220                                 
221                         case TH_PANEL:
222                                 cp= ts->panel; break;
223                         case TH_PANEL_TEXT:
224                                 cp= ts->panel_text; break;
225                         case TH_PANEL_TEXT_HI:
226                                 cp= ts->panel_text_hi; break;
227                                 
228                         case TH_BUTBACK:
229                                 cp= ts->button; break;
230                         case TH_BUTBACK_TEXT:
231                                 cp= ts->button_text; break;
232                         case TH_BUTBACK_TEXT_HI:
233                                 cp= ts->button_text_hi; break;
234                                 
235                         case TH_SHADE1:
236                                 cp= ts->shade1; break;
237                         case TH_SHADE2:
238                                 cp= ts->shade2; break;
239                         case TH_HILITE:
240                                 cp= ts->hilite; break;
241                                 
242                         case TH_GRID:
243                                 cp= ts->grid; break;
244                         case TH_WIRE:
245                                 cp= ts->wire; break;
246                         case TH_LAMP:
247                                 cp= ts->lamp; break;
248                         case TH_SELECT:
249                                 cp= ts->select; break;
250                         case TH_ACTIVE:
251                                 cp= ts->active; break;
252                         case TH_GROUP:
253                                 cp= ts->group; break;
254                         case TH_GROUP_ACTIVE:
255                                 cp= ts->group_active; break;
256                         case TH_TRANSFORM:
257                                 cp= ts->transform; break;
258                         case TH_VERTEX:
259                                 cp= ts->vertex; break;
260                         case TH_VERTEX_SELECT:
261                                 cp= ts->vertex_select; break;
262                         case TH_VERTEX_SIZE:
263                                 cp= &ts->vertex_size; break;
264                         case TH_EDGE:
265                                 cp= ts->edge; break;
266                         case TH_EDGE_SELECT:
267                                 cp= ts->edge_select; break;
268                         case TH_EDGE_SEAM:
269                                 cp= ts->edge_seam; break;
270                         case TH_EDGE_SHARP:
271                                 cp= ts->edge_sharp; break;
272                         case TH_EDITMESH_ACTIVE:
273                                 cp= ts->editmesh_active; break;
274                         case TH_EDGE_FACESEL:
275                                 cp= ts->edge_facesel; break;
276                         case TH_FACE:
277                                 cp= ts->face; break;
278                         case TH_FACE_SELECT:
279                                 cp= ts->face_select; break;
280                         case TH_FACE_DOT:
281                                 cp= ts->face_dot; break;
282                         case TH_FACEDOT_SIZE:
283                                 cp= &ts->facedot_size; break;
284                         case TH_NORMAL:
285                                 cp= ts->normal; break;
286                         case TH_BONE_SOLID:
287                                 cp= ts->bone_solid; break;
288                         case TH_BONE_POSE:
289                                 cp= ts->bone_pose; break;
290                         case TH_STRIP:
291                                 cp= ts->strip; break;
292                         case TH_STRIP_SELECT:
293                                 cp= ts->strip_select; break;
294                         case TH_CFRAME:
295                                 cp= ts->cframe; break;
296                                 
297                         case TH_SYNTAX_B:
298                                 cp= ts->syntaxb; break;
299                         case TH_SYNTAX_V:
300                                 cp= ts->syntaxv; break;
301                         case TH_SYNTAX_C:
302                                 cp= ts->syntaxc; break;
303                         case TH_SYNTAX_L:
304                                 cp= ts->syntaxl; break;
305                         case TH_SYNTAX_N:
306                                 cp= ts->syntaxn; break;
307
308                         case TH_NODE:
309                                 cp= ts->syntaxl; break;
310                         case TH_NODE_IN_OUT:
311                                 cp= ts->syntaxn; break;
312                         case TH_NODE_OPERATOR:
313                                 cp= ts->syntaxb; break;
314                         case TH_NODE_CONVERTOR:
315                                 cp= ts->syntaxv; break;
316                         case TH_NODE_GROUP:
317                                 cp= ts->syntaxc; break;
318                                 
319                         case TH_SEQ_MOVIE:
320                                 cp= ts->movie; break;
321                         case TH_SEQ_IMAGE:
322                                 cp= ts->image; break;
323                         case TH_SEQ_SCENE:
324                                 cp= ts->scene; break;
325                         case TH_SEQ_AUDIO:
326                                 cp= ts->audio; break;
327                         case TH_SEQ_EFFECT:
328                                 cp= ts->effect; break;
329                         case TH_SEQ_PLUGIN:
330                                 cp= ts->plugin; break;
331                         case TH_SEQ_TRANSITION:
332                                 cp= ts->transition; break;
333                         case TH_SEQ_META:
334                                 cp= ts->meta; break;
335                                 
336                         case TH_HANDLE_VERTEX:
337                                 cp= ts->handle_vertex;
338                                 break;
339                         case TH_HANDLE_VERTEX_SELECT:
340                                 cp= ts->handle_vertex_select;
341                                 break;
342                         case TH_HANDLE_VERTEX_SIZE:
343                                 cp= &ts->handle_vertex_size;
344                                 break;
345                                 
346                         case TH_DOPESHEET_CHANNELOB:
347                                 cp= ts->ds_channel;
348                                 break;
349                         case TH_DOPESHEET_CHANNELSUBOB:
350                                 cp= ts->ds_subchannel;
351                                 break;  
352                                 
353                         }
354                 }
355         }
356         
357         return cp;
358 }
359
360 #define SETCOLTEST(col, r, g, b, a)  if(col[3]==0) {col[0]=r; col[1]=g; col[2]= b; col[3]= a;}
361
362 /* use this call to init new variables in themespace, if they're same for all */
363 static void ui_theme_init_new_do(ThemeSpace *ts)
364 {
365         SETCOLTEST(ts->header_text,             0, 0, 0, 255);
366         SETCOLTEST(ts->header_title,    0, 0, 0, 255);
367         SETCOLTEST(ts->header_text_hi,  255, 255, 255, 255);
368         
369         SETCOLTEST(ts->panel_text,              0, 0, 0, 255);
370         SETCOLTEST(ts->panel_title,             0, 0, 0, 255);
371         SETCOLTEST(ts->panel_text_hi,   255, 255, 255, 255);
372         
373         SETCOLTEST(ts->button,                  145, 145, 145, 245);
374         SETCOLTEST(ts->button_title,    0, 0, 0, 255);
375         SETCOLTEST(ts->button_text,             0, 0, 0, 255);
376         SETCOLTEST(ts->button_text_hi,  255, 255, 255, 255);
377         
378         SETCOLTEST(ts->list,                    165, 165, 165, 255);
379         SETCOLTEST(ts->list_title,              0, 0, 0, 255);
380         SETCOLTEST(ts->list_text,               0, 0, 0, 255);
381         SETCOLTEST(ts->list_text_hi,    255, 255, 255, 255);
382 }
383
384 static void ui_theme_init_new(bTheme *btheme)
385 {
386         ui_theme_init_new_do(&btheme->tbuts);
387         ui_theme_init_new_do(&btheme->tv3d);
388         ui_theme_init_new_do(&btheme->tfile);
389         ui_theme_init_new_do(&btheme->tipo);
390         ui_theme_init_new_do(&btheme->tinfo);
391         ui_theme_init_new_do(&btheme->tsnd);
392         ui_theme_init_new_do(&btheme->tact);
393         ui_theme_init_new_do(&btheme->tnla);
394         ui_theme_init_new_do(&btheme->tseq);
395         ui_theme_init_new_do(&btheme->tima);
396         ui_theme_init_new_do(&btheme->timasel);
397         ui_theme_init_new_do(&btheme->text);
398         ui_theme_init_new_do(&btheme->toops);
399         ui_theme_init_new_do(&btheme->ttime);
400         ui_theme_init_new_do(&btheme->tnode);
401         
402 }
403
404 #define SETCOL(col, r, g, b, a)  col[0]=r; col[1]=g; col[2]= b; col[3]= a;
405 #define SETCOLF(col, r, g, b, a)  col[0]=r*255; col[1]=g*255; col[2]= b*255; col[3]= a*255;
406
407 /* initialize default theme, can't be edited
408    Note: when you add new colors, created & saved themes need initialized
409    use function below, init_userdef_do_versions() 
410 */
411 void ui_theme_init_userdef(void)
412 {
413         bTheme *btheme= U.themes.first;
414         
415         /* we search for the theme with name Default */
416         for(btheme= U.themes.first; btheme; btheme= btheme->next) {
417                 if(strcmp("Default", btheme->name)==0) break;
418         }
419         
420         if(btheme==NULL) {
421                 btheme= MEM_callocN(sizeof(bTheme), "theme");
422                 BLI_addtail(&U.themes, btheme);
423                 strcpy(btheme->name, "Default");
424         }
425         
426         UI_SetTheme(0, 0);      // make sure the global used in this file is set
427
428         /* UI buttons */
429         ui_widget_color_init(&btheme->tui);
430
431         /* common (new) variables */
432         ui_theme_init_new(btheme);
433         
434         /* space view3d */
435         SETCOLF(btheme->tv3d.back,       0.225, 0.225, 0.225, 1.0);
436         SETCOL(btheme->tv3d.text,       0, 0, 0, 255);
437         SETCOL(btheme->tv3d.text_hi, 255, 255, 255, 255);
438         
439         SETCOLF(btheme->tv3d.header,    0.45, 0.45, 0.45, 1.0);
440         SETCOL(btheme->tv3d.panel,      165, 165, 165, 127);
441         
442         SETCOL(btheme->tv3d.shade1,  160, 160, 160, 100);
443         SETCOL(btheme->tv3d.shade2,  0x7f, 0x70, 0x70, 100);
444
445         SETCOLF(btheme->tv3d.grid,     0.251, 0.251, 0.251, 1.0);
446         SETCOL(btheme->tv3d.wire,       0x0, 0x0, 0x0, 255);
447         SETCOL(btheme->tv3d.lamp,       0, 0, 0, 40);
448         SETCOL(btheme->tv3d.select, 241, 88, 0, 255);
449         SETCOL(btheme->tv3d.active, 255, 140, 25, 255);
450         SETCOL(btheme->tv3d.group,      16, 64, 16, 255);
451         SETCOL(btheme->tv3d.group_active, 85, 187, 85, 255);
452         SETCOL(btheme->tv3d.transform, 0xff, 0xff, 0xff, 255);
453         SETCOL(btheme->tv3d.vertex, 0, 0, 0, 255);
454         SETCOL(btheme->tv3d.vertex_select, 255, 133, 0, 255);
455         btheme->tv3d.vertex_size= 3;
456         SETCOL(btheme->tv3d.edge,       0x0, 0x0, 0x0, 255);
457         SETCOL(btheme->tv3d.edge_select, 255, 160, 0, 255);
458         SETCOL(btheme->tv3d.edge_seam, 219, 37, 18, 255);
459         SETCOL(btheme->tv3d.edge_facesel, 75, 75, 75, 255);
460         SETCOL(btheme->tv3d.face,       0, 0, 0, 18);
461         SETCOL(btheme->tv3d.face_select, 255, 133, 0, 60);
462         SETCOL(btheme->tv3d.normal, 0x22, 0xDD, 0xDD, 255);
463         SETCOL(btheme->tv3d.face_dot, 255, 133, 0, 255);
464         btheme->tv3d.facedot_size= 4;
465         SETCOL(btheme->tv3d.cframe, 0x60, 0xc0,  0x40, 255);
466
467         SETCOL(btheme->tv3d.bone_solid, 200, 200, 200, 255);
468         SETCOL(btheme->tv3d.bone_pose, 80, 200, 255, 80);               // alpha 80 is not meant editable, used for wire+action draw
469         
470         
471         /* space buttons */
472         /* to have something initialized */
473         btheme->tbuts= btheme->tv3d;
474
475         SETCOLF(btheme->tbuts.back,     0.45, 0.45, 0.45, 1.0);
476         SETCOL(btheme->tbuts.panel, 0x82, 0x82, 0x82, 255);
477
478         /* graph editor */
479         btheme->tipo= btheme->tv3d;
480         SETCOLF(btheme->tipo.back,      0.42, 0.42, 0.42, 1.0);
481         SETCOLF(btheme->tipo.list,      0.4, 0.4, 0.4, 1.0);
482         SETCOL(btheme->tipo.grid,       94, 94, 94, 255);
483         SETCOL(btheme->tipo.panel,  255, 255, 255, 150);
484         SETCOL(btheme->tipo.shade1,             150, 150, 150, 100);    /* scrollbars */
485         SETCOL(btheme->tipo.shade2,             0x70, 0x70, 0x70, 100);
486         SETCOL(btheme->tipo.vertex,             0, 0, 0, 255);
487         SETCOL(btheme->tipo.vertex_select, 255, 133, 0, 255);
488         SETCOL(btheme->tipo.hilite, 0x60, 0xc0, 0x40, 255); 
489         btheme->tipo.vertex_size= 3;
490
491         SETCOL(btheme->tipo.handle_vertex,              0, 0, 0, 255);
492         SETCOL(btheme->tipo.handle_vertex_select, 255, 133, 0, 255);
493         btheme->tipo.handle_vertex_size= 3;
494         
495         SETCOL(btheme->tipo.ds_channel,         82, 96, 110, 255);
496         SETCOL(btheme->tipo.ds_subchannel,      124, 137, 150, 255);
497         SETCOL(btheme->tipo.group, 79, 101, 73, 255);
498         SETCOL(btheme->tipo.group_active, 135, 177, 125, 255);
499
500         /* dopesheet */
501         btheme->tact= btheme->tipo;
502
503         /* space file */
504         /* to have something initialized */
505         btheme->tfile= btheme->tv3d;
506         SETCOL(btheme->tfile.back,      90, 90, 90, 255);
507         SETCOL(btheme->tfile.text,      250, 250, 250, 255);
508         SETCOL(btheme->tfile.text_hi, 15, 15, 15, 255);
509         SETCOL(btheme->tfile.panel, 180, 180, 180, 255);        // bookmark/ui regions
510         SETCOL(btheme->tfile.active, 130, 130, 130, 255); // selected files
511         SETCOL(btheme->tfile.hilite, 255, 140, 25, 255); // selected files
512         
513         SETCOL(btheme->tfile.grid,      250, 250, 250, 255);
514         SETCOL(btheme->tfile.image,     250, 250, 250, 255);
515         SETCOL(btheme->tfile.movie,     250, 250, 250, 255);
516         SETCOL(btheme->tfile.scene,     250, 250, 250, 255);
517
518         
519         
520
521         /* space nla */
522         btheme->tnla= btheme->tv3d;
523         SETCOL(btheme->tnla.back,       116, 116, 116, 255);
524         SETCOL(btheme->tnla.text,       0, 0, 0, 255);
525         SETCOL(btheme->tnla.text_hi, 255, 255, 255, 255);
526         SETCOL(btheme->tnla.grid,  94, 94, 94, 255);    
527         SETCOL(btheme->tnla.shade1,  172, 172, 172, 255);               // sliders
528         SETCOL(btheme->tnla.shade2,  84, 44, 31, 100);  // bar
529         SETCOL(btheme->tnla.hilite,  17, 27, 60, 100);  // bar
530         SETCOL(btheme->tnla.strip_select,       0xff, 0xff, 0xaa, 255);
531         SETCOL(btheme->tnla.strip, 0xe4, 0x9c, 0xc6, 255);
532         
533         /* space seq */
534         btheme->tseq= btheme->tv3d;
535         SETCOL(btheme->tseq.back,       116, 116, 116, 255);
536         SETCOL(btheme->tseq.movie,      81, 105, 135, 255);
537         SETCOL(btheme->tseq.image,      109, 88, 129, 255);
538         SETCOL(btheme->tseq.scene,      78, 152, 62, 255);
539         SETCOL(btheme->tseq.audio,      46, 143, 143, 255);
540         SETCOL(btheme->tseq.effect,     169, 84, 124, 255);
541         SETCOL(btheme->tseq.plugin,     126, 126, 80, 255);
542         SETCOL(btheme->tseq.transition, 162, 95, 111, 255);
543         SETCOL(btheme->tseq.meta,       109, 145, 131, 255);
544         
545
546         /* space image */
547         btheme->tima= btheme->tv3d;
548         SETCOL(btheme->tima.back,       53, 53, 53, 255);
549         SETCOL(btheme->tima.vertex, 0, 0, 0, 255);
550         SETCOL(btheme->tima.vertex_select, 255, 133, 0, 255);
551         btheme->tima.vertex_size= 3;
552         btheme->tima.facedot_size= 3;
553         SETCOL(btheme->tima.face,   255, 255, 255, 10);
554         SETCOL(btheme->tima.face_select, 255, 133, 0, 60);
555         SETCOL(btheme->tima.editmesh_active, 255, 255, 255, 128);
556
557         /* space imageselect */
558         btheme->timasel= btheme->tv3d;
559         SETCOL(btheme->timasel.active,  195, 195, 195, 255); /* active tile */
560         SETCOL(btheme->timasel.grid,  94, 94, 94, 255); /* active file text */
561         SETCOL(btheme->timasel.back,    110, 110, 110, 255);
562         SETCOL(btheme->timasel.shade1,  94, 94, 94, 255);       /* bar */
563         SETCOL(btheme->timasel.shade2,  172, 172, 172, 255); /* sliders */
564         SETCOL(btheme->timasel.hilite,  17, 27, 60, 100);       /* selected tile */
565         SETCOL(btheme->timasel.text,    0, 0, 0, 255);
566         SETCOL(btheme->timasel.text_hi, 255, 255, 255, 255);
567         SETCOL(btheme->timasel.panel,   132, 132, 132, 255);
568
569         /* space text */
570         btheme->text= btheme->tv3d;
571         SETCOL(btheme->text.back,       153, 153, 153, 255);
572         SETCOL(btheme->text.shade1,     143, 143, 143, 255);
573         SETCOL(btheme->text.shade2,     0xc6, 0x77, 0x77, 255);
574         SETCOL(btheme->text.hilite,     255, 0, 0, 255);
575         
576         /* syntax highlighting */
577         SETCOL(btheme->text.syntaxn,    0, 0, 200, 255);        /* Numbers  Blue*/
578         SETCOL(btheme->text.syntaxl,    100, 0, 0, 255);        /* Strings  red */
579         SETCOL(btheme->text.syntaxc,    0, 100, 50, 255);       /* Comments greenish */
580         SETCOL(btheme->text.syntaxv,    95, 95, 0, 255);        /* Special */
581         SETCOL(btheme->text.syntaxb,    128, 0, 80, 255);       /* Builtin, red-purple */
582         
583         /* space oops */
584         btheme->toops= btheme->tv3d;
585         SETCOLF(btheme->toops.back,     0.45, 0.45, 0.45, 1.0);
586         
587         /* space info */
588         btheme->tinfo= btheme->tv3d;
589         SETCOL(btheme->tinfo.back,      153, 153, 153, 255);
590
591         /* space sound */
592         btheme->tsnd= btheme->tv3d;
593         SETCOLF(btheme->tsnd.back,      0.45, 0.45, 0.45, 1.0);
594         SETCOLF(btheme->tsnd.grid,      0.36, 0.36, 0.36, 1.0);
595         SETCOL(btheme->tsnd.shade1,  173, 173, 173, 255);               // sliders
596         
597         /* space time */
598         btheme->ttime= btheme->tsnd;    // same as sound space
599         
600         /* space node, re-uses syntax color storage */
601         btheme->tnode= btheme->tv3d;
602         SETCOL(btheme->tnode.edge_select, 255, 255, 255, 255);
603         SETCOL(btheme->tnode.syntaxl, 150, 150, 150, 255);      /* TH_NODE, backdrop */
604         SETCOL(btheme->tnode.syntaxn, 129, 131, 144, 255);      /* in/output */
605         SETCOL(btheme->tnode.syntaxb, 127,127,127, 255);        /* operator */
606         SETCOL(btheme->tnode.syntaxv, 142, 138, 145, 255);      /* generator */
607         SETCOL(btheme->tnode.syntaxc, 120, 145, 120, 255);      /* group */
608
609 }
610
611
612 void UI_SetTheme(int spacetype, int regionid)
613 {
614         if(spacetype==0) {      // called for safety, when delete themes
615                 theme_active= U.themes.first;
616                 theme_spacetype= SPACE_VIEW3D;
617                 theme_regionid= RGN_TYPE_WINDOW;
618         }
619         else {
620                 // later on, a local theme can be found too
621                 theme_active= U.themes.first;
622                 theme_spacetype= spacetype;
623                 theme_regionid= regionid;
624         }
625 }
626
627 // for space windows only
628 void UI_ThemeColor(int colorid)
629 {
630         char *cp;
631         
632         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
633         glColor3ub(cp[0], cp[1], cp[2]);
634
635 }
636
637 // plus alpha
638 void UI_ThemeColor4(int colorid)
639 {
640         char *cp;
641         
642         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
643         glColor4ub(cp[0], cp[1], cp[2], cp[3]);
644
645 }
646
647 // set the color with offset for shades
648 void UI_ThemeColorShade(int colorid, int offset)
649 {
650         int r, g, b;
651         char *cp;
652         
653         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
654         r= offset + (int) cp[0];
655         CLAMP(r, 0, 255);
656         g= offset + (int) cp[1];
657         CLAMP(g, 0, 255);
658         b= offset + (int) cp[2];
659         CLAMP(b, 0, 255);
660         //glColor3ub(r, g, b);
661         glColor4ub(r, g, b, cp[3]);
662 }
663 void UI_ThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset)
664 {
665         int r, g, b, a;
666         char *cp;
667         
668         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
669         r= coloffset + (int) cp[0];
670         CLAMP(r, 0, 255);
671         g= coloffset + (int) cp[1];
672         CLAMP(g, 0, 255);
673         b= coloffset + (int) cp[2];
674         CLAMP(b, 0, 255);
675         a= alphaoffset + (int) cp[3];
676         CLAMP(a, 0, 255);
677         glColor4ub(r, g, b, a);
678 }
679
680 // blend between to theme colors, and set it
681 void UI_ThemeColorBlend(int colorid1, int colorid2, float fac)
682 {
683         int r, g, b;
684         char *cp1, *cp2;
685         
686         cp1= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
687         cp2= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
688
689         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
690         r= floor((1.0-fac)*cp1[0] + fac*cp2[0]);
691         g= floor((1.0-fac)*cp1[1] + fac*cp2[1]);
692         b= floor((1.0-fac)*cp1[2] + fac*cp2[2]);
693         
694         glColor3ub(r, g, b);
695 }
696
697 // blend between to theme colors, shade it, and set it
698 void UI_ThemeColorBlendShade(int colorid1, int colorid2, float fac, int offset)
699 {
700         int r, g, b;
701         char *cp1, *cp2;
702         
703         cp1= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
704         cp2= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
705
706         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
707         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
708         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
709         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
710         
711         CLAMP(r, 0, 255);
712         CLAMP(g, 0, 255);
713         CLAMP(b, 0, 255);
714         
715         glColor3ub(r, g, b);
716 }
717
718 // blend between to theme colors, shade it, and set it
719 void UI_ThemeColorBlendShadeAlpha(int colorid1, int colorid2, float fac, int offset, int alphaoffset)
720 {
721         int r, g, b, a;
722         char *cp1, *cp2;
723         
724         cp1= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
725         cp2= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
726
727         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
728         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
729         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
730         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
731         a= alphaoffset+floor((1.0-fac)*cp1[3] + fac*cp2[3]);
732         
733         CLAMP(r, 0, 255);
734         CLAMP(g, 0, 255);
735         CLAMP(b, 0, 255);
736         CLAMP(a, 0, 255);
737
738         glColor4ub(r, g, b, a);
739 }
740
741
742 // get individual values, not scaled
743 float UI_GetThemeValuef(int colorid)
744 {
745         char *cp;
746         
747         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
748         return ((float)cp[0]);
749
750 }
751
752 // get individual values, not scaled
753 int UI_GetThemeValue(int colorid)
754 {
755         char *cp;
756         
757         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
758         return ((int) cp[0]);
759
760 }
761
762
763 // get the color, range 0.0-1.0
764 void UI_GetThemeColor3fv(int colorid, float *col)
765 {
766         char *cp;
767         
768         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
769         col[0]= ((float)cp[0])/255.0;
770         col[1]= ((float)cp[1])/255.0;
771         col[2]= ((float)cp[2])/255.0;
772 }
773
774 // get the color, in char pointer
775 void UI_GetThemeColor3ubv(int colorid, char *col)
776 {
777         char *cp;
778         
779         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
780         col[0]= cp[0];
781         col[1]= cp[1];
782         col[2]= cp[2];
783 }
784
785 // get the color, in char pointer
786 void UI_GetThemeColor4ubv(int colorid, char *col)
787 {
788         char *cp;
789         
790         cp= UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
791         col[0]= cp[0];
792         col[1]= cp[1];
793         col[2]= cp[2];
794         col[3]= cp[3];
795 }
796
797 void UI_GetThemeColorType4ubv(int colorid, int spacetype, char *col)
798 {
799         char *cp;
800         
801         cp= UI_ThemeGetColorPtr(theme_active, spacetype, colorid);
802         col[0]= cp[0];
803         col[1]= cp[1];
804         col[2]= cp[2];
805         col[3]= cp[3];
806 }
807
808 // blends and shades between two char color pointers
809 void UI_ColorPtrBlendShade3ubv(char *cp1, char *cp2, float fac, int offset)
810 {
811         int r, g, b;
812         
813         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
814         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
815         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
816         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
817         
818         r= r<0?0:(r>255?255:r);
819         g= g<0?0:(g>255?255:g);
820         b= b<0?0:(b>255?255:b);
821         
822         glColor3ub(r, g, b);
823 }
824
825 // get a 3 byte color, blended and shaded between two other char color pointers
826 void UI_GetColorPtrBlendShade3ubv(char *cp1, char *cp2, char *col, float fac, int offset)
827 {
828         int r, g, b;
829         
830         if(fac<0.0) fac=0.0; else if(fac>1.0) fac= 1.0;
831         r= offset+floor((1.0-fac)*cp1[0] + fac*cp2[0]);
832         g= offset+floor((1.0-fac)*cp1[1] + fac*cp2[1]);
833         b= offset+floor((1.0-fac)*cp1[2] + fac*cp2[2]);
834         
835         r= r<0?0:(r>255?255:r);
836         g= g<0?0:(g>255?255:g);
837         b= b<0?0:(b>255?255:b);
838         
839         col[0] = r;
840         col[1] = g;
841         col[2] = b;
842 }
843
844 void UI_make_axis_color(char *src_col, char *dst_col, char axis)
845 {
846         switch(axis)
847         {
848                 case 'x':
849                 case 'X':
850                         dst_col[0]= src_col[0]>219?255:src_col[0]+36;
851                         dst_col[1]= src_col[1]<26?0:src_col[1]-26;
852                         dst_col[2]= src_col[2]<26?0:src_col[2]-26;
853                         break;
854                 case 'y':
855                 case 'Y':
856                         dst_col[0]= src_col[0]<46?0:src_col[0]-36;
857                         dst_col[1]= src_col[1]>189?255:src_col[1]+66;
858                         dst_col[2]= src_col[2]<46?0:src_col[2]-36;
859                         break;
860                 default: 
861                         dst_col[0]= src_col[0]<26?0:src_col[0]-26; 
862                         dst_col[1]= src_col[1]<26?0:src_col[1]-26; 
863                         dst_col[2]= src_col[2]>209?255:src_col[2]+46;
864         }
865 }
866
867 /* ************************************************************* */
868
869 /* patching UserDef struct and Themes */
870 void init_userdef_do_versions(void)
871 {
872 //      countall();
873         
874         /* the UserDef struct is not corrected with do_versions() .... ugh! */
875         if(U.wheellinescroll == 0) U.wheellinescroll = 3;
876         if(U.menuthreshold1==0) {
877                 U.menuthreshold1= 5;
878                 U.menuthreshold2= 2;
879         }
880         if(U.tb_leftmouse==0) {
881                 U.tb_leftmouse= 5;
882                 U.tb_rightmouse= 5;
883         }
884         if(U.mixbufsize==0) U.mixbufsize= 2048;
885         if (BLI_streq(U.tempdir, "/")) {
886                 char *tmp= getenv("TEMP");
887                 
888                 strcpy(U.tempdir, tmp?tmp:"/tmp/");
889         }
890         if (U.savetime <= 0) {
891                 U.savetime = 1;
892 // XXX          error(".B.blend is buggy, please consider removing it.\n");
893         }
894         /* transform widget settings */
895         if(U.tw_hotspot==0) {
896                 U.tw_hotspot= 14;
897                 U.tw_size= 20;                  // percentage of window size
898                 U.tw_handlesize= 16;    // percentage of widget radius
899         }
900         if(U.pad_rot_angle==0)
901                 U.pad_rot_angle= 15;
902         
903         if(U.flag & USER_CUSTOM_RANGE) 
904                 vDM_ColorBand_store(&U.coba_weight); /* signal for derivedmesh to use colorband */
905         
906         if (G.main->versionfile <= 191) {
907                 strcpy(U.plugtexdir, U.textudir);
908                 strcpy(U.sounddir, "/");
909         }
910         
911         /* patch to set Dupli Armature */
912         if (G.main->versionfile < 220) {
913                 U.dupflag |= USER_DUP_ARM;
914         }
915         
916         /* added seam, normal color, undo */
917         if (G.main->versionfile <= 234) {
918                 bTheme *btheme;
919                 
920                 U.uiflag |= USER_GLOBALUNDO;
921                 if (U.undosteps==0) U.undosteps=32;
922                 
923                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
924                         /* check for alpha==0 is safe, then color was never set */
925                         if(btheme->tv3d.edge_seam[3]==0) {
926                                 SETCOL(btheme->tv3d.edge_seam, 230, 150, 50, 255);
927                         }
928                         if(btheme->tv3d.normal[3]==0) {
929                                 SETCOL(btheme->tv3d.normal, 0x22, 0xDD, 0xDD, 255);
930                         }
931                         if(btheme->tv3d.face_dot[3]==0) {
932                                 SETCOL(btheme->tv3d.face_dot, 255, 138, 48, 255);
933                                 btheme->tv3d.facedot_size= 4;
934                         }
935                 }
936         }
937         if (G.main->versionfile <= 235) {
938                 /* illegal combo... */
939                 if (U.flag & USER_LMOUSESELECT) 
940                         U.flag &= ~USER_TWOBUTTONMOUSE;
941         }
942         if (G.main->versionfile <= 236) {
943                 bTheme *btheme;
944                 /* new space type */
945                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
946                         /* check for alpha==0 is safe, then color was never set */
947                         if(btheme->ttime.back[3]==0) {
948                                 btheme->ttime = btheme->tsnd;   // copy from sound
949                         }
950                         if(btheme->text.syntaxn[3]==0) {
951                                 SETCOL(btheme->text.syntaxn,    0, 0, 200, 255);        /* Numbers  Blue*/
952                                 SETCOL(btheme->text.syntaxl,    100, 0, 0, 255);        /* Strings  red */
953                                 SETCOL(btheme->text.syntaxc,    0, 100, 50, 255);       /* Comments greenish */
954                                 SETCOL(btheme->text.syntaxv,    95, 95, 0, 255);        /* Special */
955                                 SETCOL(btheme->text.syntaxb,    128, 0, 80, 255);       /* Builtin, red-purple */
956                         }
957                 }
958         }
959         if (G.main->versionfile <= 237) {
960                 bTheme *btheme;
961                 /* bone colors */
962                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
963                         /* check for alpha==0 is safe, then color was never set */
964                         if(btheme->tv3d.bone_solid[3]==0) {
965                                 SETCOL(btheme->tv3d.bone_solid, 200, 200, 200, 255);
966                                 SETCOL(btheme->tv3d.bone_pose, 80, 200, 255, 80);
967                         }
968                 }
969         }
970         if (G.main->versionfile <= 238) {
971                 bTheme *btheme;
972                 /* bone colors */
973                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
974                         /* check for alpha==0 is safe, then color was never set */
975                         if(btheme->tnla.strip[3]==0) {
976                                 SETCOL(btheme->tnla.strip_select,       0xff, 0xff, 0xaa, 255);
977                                 SETCOL(btheme->tnla.strip, 0xe4, 0x9c, 0xc6, 255);
978                         }
979                 }
980         }
981         if (G.main->versionfile <= 239) {
982                 bTheme *btheme;
983                 
984                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
985                         /* Lamp theme, check for alpha==0 is safe, then color was never set */
986                         if(btheme->tv3d.lamp[3]==0) {
987                                 SETCOL(btheme->tv3d.lamp,       0, 0, 0, 40);
988 /* TEMPORAL, remove me! (ton) */                                
989                                 U.uiflag |= USER_PLAINMENUS;
990                         }
991                         
992                 }
993                 if(U.obcenter_dia==0) U.obcenter_dia= 6;
994         }
995         if (G.main->versionfile <= 241) {
996                 bTheme *btheme;
997                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
998                         /* Node editor theme, check for alpha==0 is safe, then color was never set */
999                         if(btheme->tnode.syntaxn[3]==0) {
1000                                 /* re-uses syntax color storage */
1001                                 btheme->tnode= btheme->tv3d;
1002                                 SETCOL(btheme->tnode.edge_select, 255, 255, 255, 255);
1003                                 SETCOL(btheme->tnode.syntaxl, 150, 150, 150, 255);      /* TH_NODE, backdrop */
1004                                 SETCOL(btheme->tnode.syntaxn, 129, 131, 144, 255);      /* in/output */
1005                                 SETCOL(btheme->tnode.syntaxb, 127,127,127, 255);        /* operator */
1006                                 SETCOL(btheme->tnode.syntaxv, 142, 138, 145, 255);      /* generator */
1007                                 SETCOL(btheme->tnode.syntaxc, 120, 145, 120, 255);      /* group */
1008                         }
1009                         /* Group theme colors */
1010                         if(btheme->tv3d.group[3]==0) {
1011                                 SETCOL(btheme->tv3d.group, 0x10, 0x40, 0x10, 255);
1012                                 SETCOL(btheme->tv3d.group_active, 0x66, 0xFF, 0x66, 255);
1013                         }
1014                         /* Sequence editor theme*/
1015                         if(btheme->tseq.movie[3]==0) {
1016                                 SETCOL(btheme->tseq.movie,      81, 105, 135, 255);
1017                                 SETCOL(btheme->tseq.image,      109, 88, 129, 255);
1018                                 SETCOL(btheme->tseq.scene,      78, 152, 62, 255);
1019                                 SETCOL(btheme->tseq.audio,      46, 143, 143, 255);
1020                                 SETCOL(btheme->tseq.effect,     169, 84, 124, 255);
1021                                 SETCOL(btheme->tseq.plugin,     126, 126, 80, 255);
1022                                 SETCOL(btheme->tseq.transition, 162, 95, 111, 255);
1023                                 SETCOL(btheme->tseq.meta,       109, 145, 131, 255);
1024                         }
1025                 }
1026                 
1027                 /* set defaults for 3D View rotating axis indicator */ 
1028                 /* since size can't be set to 0, this indicates it's not saved in .B.blend */
1029                 if (U.rvisize == 0) {
1030                         U.rvisize = 15;
1031                         U.rvibright = 8;
1032                         U.uiflag |= USER_SHOW_ROTVIEWICON;
1033                 }
1034                 
1035         }
1036         if (G.main->versionfile <= 242) {
1037                 bTheme *btheme;
1038                 
1039                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1040                         /* long keyframe color */
1041                         /* check for alpha==0 is safe, then color was never set */
1042                         if(btheme->tact.strip[3]==0) {
1043                                 SETCOL(btheme->tv3d.edge_sharp, 255, 32, 32, 255);
1044                                 SETCOL(btheme->tact.strip_select,       0xff, 0xff, 0xaa, 204);
1045                                 SETCOL(btheme->tact.strip, 0xe4, 0x9c, 0xc6, 204);
1046                         }
1047                         
1048                         /* IPO-Editor - Vertex Size*/
1049                         if(btheme->tipo.vertex_size == 0) {
1050                                 btheme->tipo.vertex_size= 3;
1051                         }
1052                 }
1053         }
1054         if (G.main->versionfile <= 243) {
1055                 /* set default number of recently-used files (if not set) */
1056                 if (U.recent_files == 0) U.recent_files = 10;
1057         }
1058         if (G.main->versionfile < 245 || (G.main->versionfile == 245 && G.main->subversionfile < 3)) {
1059                 bTheme *btheme;
1060                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1061                         SETCOL(btheme->tv3d.editmesh_active, 255, 255, 255, 128);
1062                 }
1063                 if(U.coba_weight.tot==0)
1064                         init_colorband(&U.coba_weight, 1);
1065         }
1066         if ((G.main->versionfile < 245) || (G.main->versionfile == 245 && G.main->subversionfile < 11)) {
1067                 bTheme *btheme;
1068                 for (btheme= U.themes.first; btheme; btheme= btheme->next) {
1069                         /* these should all use the same colour */
1070                         SETCOL(btheme->tv3d.cframe, 0x60, 0xc0, 0x40, 255);
1071                         SETCOL(btheme->tipo.cframe, 0x60, 0xc0, 0x40, 255);
1072                         SETCOL(btheme->tact.cframe, 0x60, 0xc0, 0x40, 255);
1073                         SETCOL(btheme->tnla.cframe, 0x60, 0xc0, 0x40, 255);
1074                         SETCOL(btheme->tseq.cframe, 0x60, 0xc0, 0x40, 255);
1075                         SETCOL(btheme->tsnd.cframe, 0x60, 0xc0, 0x40, 255);
1076                         SETCOL(btheme->ttime.cframe, 0x60, 0xc0, 0x40, 255);
1077                 }
1078         }
1079         if ((G.main->versionfile < 245) || (G.main->versionfile == 245 && G.main->subversionfile < 11)) {
1080                 bTheme *btheme;
1081                 for (btheme= U.themes.first; btheme; btheme= btheme->next) {
1082                         /* these should all use the same color */
1083                         SETCOL(btheme->tv3d.cframe, 0x60, 0xc0, 0x40, 255);
1084                         SETCOL(btheme->tipo.cframe, 0x60, 0xc0, 0x40, 255);
1085                         SETCOL(btheme->tact.cframe, 0x60, 0xc0, 0x40, 255);
1086                         SETCOL(btheme->tnla.cframe, 0x60, 0xc0, 0x40, 255);
1087                         SETCOL(btheme->tseq.cframe, 0x60, 0xc0, 0x40, 255);
1088                         SETCOL(btheme->tsnd.cframe, 0x60, 0xc0, 0x40, 255);
1089                         SETCOL(btheme->ttime.cframe, 0x60, 0xc0, 0x40, 255);
1090                 }
1091         }
1092         if ((G.main->versionfile < 245) || (G.main->versionfile == 245 && G.main->subversionfile < 13)) {
1093                 bTheme *btheme;
1094                 for (btheme= U.themes.first; btheme; btheme= btheme->next) {
1095                         /* action channel groups (recolor anyway) */
1096                         SETCOL(btheme->tact.group, 0x39, 0x7d, 0x1b, 255);
1097                         SETCOL(btheme->tact.group_active, 0x7d, 0xe9, 0x60, 255);
1098                         
1099                         /* bone custom-color sets */
1100                         // FIXME: this check for initialised colors is bad
1101                         if (btheme->tarm[0].solid[3] == 0) {
1102                                         /* set 1 */
1103                                 SETCOL(btheme->tarm[0].solid, 0x9a, 0x00, 0x00, 255);
1104                                 SETCOL(btheme->tarm[0].select, 0xbd, 0x11, 0x11, 255);
1105                                 SETCOL(btheme->tarm[0].active, 0xf7, 0x0a, 0x0a, 255);
1106                                         /* set 2 */
1107                                 SETCOL(btheme->tarm[1].solid, 0xf7, 0x40, 0x18, 255);
1108                                 SETCOL(btheme->tarm[1].select, 0xf6, 0x69, 0x13, 255);
1109                                 SETCOL(btheme->tarm[1].active, 0xfa, 0x99, 0x00, 255);
1110                                         /* set 3 */
1111                                 SETCOL(btheme->tarm[2].solid, 0x1e, 0x91, 0x09, 255);
1112                                 SETCOL(btheme->tarm[2].select, 0x59, 0xb7, 0x0b, 255);
1113                                 SETCOL(btheme->tarm[2].active, 0x83, 0xef, 0x1d, 255);
1114                                         /* set 4 */
1115                                 SETCOL(btheme->tarm[3].solid, 0x0a, 0x36, 0x94, 255);
1116                                 SETCOL(btheme->tarm[3].select, 0x36, 0x67, 0xdf, 255);
1117                                 SETCOL(btheme->tarm[3].active, 0x5e, 0xc1, 0xef, 255);
1118                                         /* set 5 */
1119                                 SETCOL(btheme->tarm[4].solid, 0xa9, 0x29, 0x4e, 255);
1120                                 SETCOL(btheme->tarm[4].select, 0xc1, 0x41, 0x6a, 255);
1121                                 SETCOL(btheme->tarm[4].active, 0xf0, 0x5d, 0x91, 255);
1122                                         /* set 6 */
1123                                 SETCOL(btheme->tarm[5].solid, 0x43, 0x0c, 0x78, 255);
1124                                 SETCOL(btheme->tarm[5].select, 0x54, 0x3a, 0xa3, 255);
1125                                 SETCOL(btheme->tarm[5].active, 0x87, 0x64, 0xd5, 255);
1126                                         /* set 7 */
1127                                 SETCOL(btheme->tarm[6].solid, 0x24, 0x78, 0x5a, 255);
1128                                 SETCOL(btheme->tarm[6].select, 0x3c, 0x95, 0x79, 255);
1129                                 SETCOL(btheme->tarm[6].active, 0x6f, 0xb6, 0xab, 255);
1130                                         /* set 8 */
1131                                 SETCOL(btheme->tarm[7].solid, 0x4b, 0x70, 0x7c, 255);
1132                                 SETCOL(btheme->tarm[7].select, 0x6a, 0x86, 0x91, 255);
1133                                 SETCOL(btheme->tarm[7].active, 0x9b, 0xc2, 0xcd, 255);
1134                                         /* set 9 */
1135                                 SETCOL(btheme->tarm[8].solid, 0xf4, 0xc9, 0x0c, 255);
1136                                 SETCOL(btheme->tarm[8].select, 0xee, 0xc2, 0x36, 255);
1137                                 SETCOL(btheme->tarm[8].active, 0xf3, 0xff, 0x00, 255);
1138                                         /* set 10 */
1139                                 SETCOL(btheme->tarm[9].solid, 0x1e, 0x20, 0x24, 255);
1140                                 SETCOL(btheme->tarm[9].select, 0x48, 0x4c, 0x56, 255);
1141                                 SETCOL(btheme->tarm[9].active, 0xff, 0xff, 0xff, 255);
1142                                         /* set 11 */
1143                                 SETCOL(btheme->tarm[10].solid, 0x6f, 0x2f, 0x6a, 255);
1144                                 SETCOL(btheme->tarm[10].select, 0x98, 0x45, 0xbe, 255);
1145                                 SETCOL(btheme->tarm[10].active, 0xd3, 0x30, 0xd6, 255);
1146                                         /* set 12 */
1147                                 SETCOL(btheme->tarm[11].solid, 0x6c, 0x8e, 0x22, 255);
1148                                 SETCOL(btheme->tarm[11].select, 0x7f, 0xb0, 0x22, 255);
1149                                 SETCOL(btheme->tarm[11].active, 0xbb, 0xef, 0x5b, 255);
1150                                         /* set 13 */
1151                                 SETCOL(btheme->tarm[12].solid, 0x8d, 0x8d, 0x8d, 255);
1152                                 SETCOL(btheme->tarm[12].select, 0xb0, 0xb0, 0xb0, 255);
1153                                 SETCOL(btheme->tarm[12].active, 0xde, 0xde, 0xde, 255);
1154                                         /* set 14 */
1155                                 SETCOL(btheme->tarm[13].solid, 0x83, 0x43, 0x26, 255);
1156                                 SETCOL(btheme->tarm[13].select, 0x8b, 0x58, 0x11, 255);
1157                                 SETCOL(btheme->tarm[13].active, 0xbd, 0x6a, 0x11, 255);
1158                                         /* set 15 */
1159                                 SETCOL(btheme->tarm[14].solid, 0x08, 0x31, 0x0e, 255);
1160                                 SETCOL(btheme->tarm[14].select, 0x1c, 0x43, 0x0b, 255);
1161                                 SETCOL(btheme->tarm[14].active, 0x34, 0x62, 0x2b, 255);
1162                         }
1163                 }
1164         }
1165         if ((G.main->versionfile < 245) || (G.main->versionfile == 245 && G.main->subversionfile < 16)) {
1166                 U.flag |= USER_ADD_VIEWALIGNED|USER_ADD_EDITMODE;
1167         }
1168         if ((G.main->versionfile < 247) || (G.main->versionfile == 247 && G.main->subversionfile <= 2)) {
1169                 bTheme *btheme;
1170                 
1171                 /* adjust themes */
1172                 for (btheme= U.themes.first; btheme; btheme= btheme->next) {
1173                         char *col;
1174                         
1175                         /* IPO Editor: Handles/Vertices */
1176                         col = btheme->tipo.vertex;
1177                         SETCOL(btheme->tipo.handle_vertex, col[0], col[1], col[2], 255);
1178                         col = btheme->tipo.vertex_select;
1179                         SETCOL(btheme->tipo.handle_vertex_select, col[0], col[1], col[2], 255);
1180                         btheme->tipo.handle_vertex_size= btheme->tipo.vertex_size;
1181                         
1182                         /* Sequence/Image Editor: colors for GPencil text */
1183                         col = btheme->tv3d.bone_pose;
1184                         SETCOL(btheme->tseq.bone_pose, col[0], col[1], col[2], 255);
1185                         SETCOL(btheme->tima.bone_pose, col[0], col[1], col[2], 255);
1186                         col = btheme->tv3d.vertex_select;
1187                         SETCOL(btheme->tseq.vertex_select, col[0], col[1], col[2], 255);
1188                 }
1189         }
1190         if (G.main->versionfile < 250) {
1191                 bTheme *btheme;
1192                 
1193                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1194                         /* this was not properly initialized in 2.45 */
1195                         if(btheme->tima.face_dot[3]==0) {
1196                                 SETCOL(btheme->tima.editmesh_active, 255, 255, 255, 128);
1197                                 SETCOL(btheme->tima.face_dot, 255, 133, 0, 255);
1198                                 btheme->tima.facedot_size= 2;
1199                         }
1200                         
1201                         /* DopeSheet - (Object) Channel color */
1202                         SETCOL(btheme->tact.ds_channel,         82, 96, 110, 255);
1203                         SETCOL(btheme->tact.ds_subchannel,      124, 137, 150, 255);
1204                         /* DopeSheet - Group Channel color (saner version) */
1205                         SETCOL(btheme->tact.group, 79, 101, 73, 255);
1206                         SETCOL(btheme->tact.group_active, 135, 177, 125, 255);
1207                         
1208                         /* Graph Editor - (Object) Channel color */
1209                         SETCOL(btheme->tipo.ds_channel,         82, 96, 110, 255);
1210                         SETCOL(btheme->tipo.ds_subchannel,      124, 137, 150, 255);
1211                         /* Graph Editor - Group Channel color */
1212                         SETCOL(btheme->tipo.group, 79, 101, 73, 255);
1213                         SETCOL(btheme->tipo.group_active, 135, 177, 125, 255);
1214                 }
1215                 
1216                 /* adjust grease-pencil distances */
1217                 U.gp_manhattendist= 1;
1218                 U.gp_euclideandist= 2;
1219                 
1220                 /* adjust default interpolation for new IPO-curves */
1221                 U.ipo_new= BEZT_IPO_BEZ;
1222         }
1223         
1224         if (G.main->versionfile < 250 || (G.main->versionfile == 250 && G.main->subversionfile < 1)) {
1225                 bTheme *btheme;
1226
1227                 for(btheme= U.themes.first; btheme; btheme= btheme->next) {
1228                         
1229                         /* common (new) variables, it checks for alpha==0 */
1230                         ui_theme_init_new(btheme);
1231
1232                         if(btheme->tui.wcol_num.outline[3]==0)
1233                                 ui_widget_color_init(&btheme->tui);
1234                 }
1235         }
1236         
1237         /* GL Texture Garbage Collection (variable abused above!) */
1238         if (U.textimeout == 0) {
1239                 U.texcollectrate = 60;
1240                 U.textimeout = 120;
1241         }
1242         if (U.memcachelimit <= 0) {
1243                 U.memcachelimit = 32;
1244         }
1245         if (U.frameserverport == 0) {
1246                 U.frameserverport = 8080;
1247         }
1248
1249         /* funny name, but it is GE stuff, moves userdef stuff to engine */
1250 // XXX  space_set_commmandline_options();
1251         /* this timer uses U */
1252 // XXX  reset_autosave();
1253
1254 }
1255
1256
1257