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