UI: Preferences Redesign Part 2
[blender.git] / source / blender / editors / interface / resources.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * 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_screen_types.h"
39 #include "DNA_space_types.h"
40 #include "DNA_userdef_types.h"
41
42 #include "BLI_blenlib.h"
43 #include "BLI_utildefines.h"
44 #include "BLI_math.h"
45
46 #include "BKE_addon.h"
47 #include "BKE_appdir.h"
48 #include "BKE_main.h"
49 #include "BKE_mesh_runtime.h"
50
51 #include "BLO_readfile.h"  /* for UserDef version patching. */
52
53 #include "BLF_api.h"
54
55 #include "ED_screen.h"
56
57 #include "UI_interface.h"
58 #include "UI_interface_icons.h"
59
60 #include "interface_intern.h"
61 #include "GPU_framebuffer.h"
62
63 /* global for themes */
64 typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha);
65
66 /* be sure to keep 'bThemeState' in sync */
67 static struct bThemeState g_theme_state = {
68     NULL,
69     SPACE_VIEW3D,
70     RGN_TYPE_WINDOW,
71 };
72
73 #define theme_active g_theme_state.theme
74 #define theme_spacetype g_theme_state.spacetype
75 #define theme_regionid g_theme_state.regionid
76
77 void ui_resources_init(void)
78 {
79         UI_icons_init();
80 }
81
82 void ui_resources_free(void)
83 {
84         UI_icons_free();
85 }
86
87
88 /* ******************************************************** */
89 /*    THEMES */
90 /* ******************************************************** */
91
92 const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
93 {
94         ThemeSpace *ts = NULL;
95         static char error[4] = {240, 0, 240, 255};
96         static char alert[4] = {240, 60, 60, 255};
97         static char headerdesel[4] = {0, 0, 0, 255};
98         static char back[4] = {0, 0, 0, 255};
99         static char setting = 0;
100         const char *cp = error;
101
102         /* ensure we're not getting a color after running BKE_blender_userdef_free */
103         BLI_assert(BLI_findindex(&U.themes, theme_active) != -1);
104         BLI_assert(colorid != TH_UNDEFINED);
105
106         if (btheme) {
107
108                 /* first check for ui buttons theme */
109                 if (colorid < TH_THEMEUI) {
110
111                         switch (colorid) {
112
113                                 case TH_REDALERT:
114                                         cp = alert; break;
115                         }
116                 }
117                 else {
118
119                         switch (spacetype) {
120                                 case SPACE_BUTS:
121                                         ts = &btheme->tbuts;
122                                         break;
123                                 case SPACE_VIEW3D:
124                                         ts = &btheme->tv3d;
125                                         break;
126                                 case SPACE_IPO:
127                                         ts = &btheme->tipo;
128                                         break;
129                                 case SPACE_FILE:
130                                         ts = &btheme->tfile;
131                                         break;
132                                 case SPACE_NLA:
133                                         ts = &btheme->tnla;
134                                         break;
135                                 case SPACE_ACTION:
136                                         ts = &btheme->tact;
137                                         break;
138                                 case SPACE_SEQ:
139                                         ts = &btheme->tseq;
140                                         break;
141                                 case SPACE_IMAGE:
142                                         ts = &btheme->tima;
143                                         break;
144                                 case SPACE_TEXT:
145                                         ts = &btheme->text;
146                                         break;
147                                 case SPACE_OUTLINER:
148                                         ts = &btheme->toops;
149                                         break;
150                                 case SPACE_INFO:
151                                         ts = &btheme->tinfo;
152                                         break;
153                                 case SPACE_USERPREF:
154                                         ts = &btheme->tuserpref;
155                                         break;
156                                 case SPACE_CONSOLE:
157                                         ts = &btheme->tconsole;
158                                         break;
159                                 case SPACE_NODE:
160                                         ts = &btheme->tnode;
161                                         break;
162                                 case SPACE_CLIP:
163                                         ts = &btheme->tclip;
164                                         break;
165                                 case SPACE_TOPBAR:
166                                         ts = &btheme->ttopbar;
167                                         break;
168                                 case SPACE_STATUSBAR:
169                                         ts = &btheme->tstatusbar;
170                                         break;
171                                 default:
172                                         ts = &btheme->tv3d;
173                                         break;
174                         }
175
176                         switch (colorid) {
177                                 case TH_BACK:
178                                         if (ELEM(theme_regionid, RGN_TYPE_WINDOW, RGN_TYPE_PREVIEW))
179                                                 cp = ts->back;
180                                         else if (theme_regionid == RGN_TYPE_CHANNELS)
181                                                 cp = ts->list;
182                                         else if (theme_regionid == RGN_TYPE_HEADER)
183                                                 cp = ts->header;
184                                         else if (theme_regionid == RGN_TYPE_NAV_BAR)
185                                                 cp = ts->navigation_bar;
186                                         else if (theme_regionid == RGN_TYPE_EXECUTE)
187                                                 cp = ts->execution_buts;
188                                         else
189                                                 cp = ts->button;
190
191                                         copy_v4_v4_char(back, cp);
192                                         if (!ED_region_is_overlap(spacetype, theme_regionid)) {
193                                                 back[3] = 255;
194                                         }
195                                         cp = back;
196                                         break;
197                                 case TH_LOW_GRAD:
198                                         cp = ts->gradients.gradient;
199                                         break;
200                                 case TH_HIGH_GRAD:
201                                         cp = ts->gradients.high_gradient;
202                                         break;
203                                 case TH_SHOW_BACK_GRAD:
204                                         cp = &setting;
205                                         setting = ts->gradients.show_grad;
206                                         break;
207                                 case TH_TEXT:
208                                         if (theme_regionid == RGN_TYPE_WINDOW)
209                                                 cp = ts->text;
210                                         else if (theme_regionid == RGN_TYPE_CHANNELS)
211                                                 cp = ts->list_text;
212                                         else if (theme_regionid == RGN_TYPE_HEADER)
213                                                 cp = ts->header_text;
214                                         else
215                                                 cp = ts->button_text;
216                                         break;
217                                 case TH_TEXT_HI:
218                                         if (theme_regionid == RGN_TYPE_WINDOW)
219                                                 cp = ts->text_hi;
220                                         else if (theme_regionid == RGN_TYPE_CHANNELS)
221                                                 cp = ts->list_text_hi;
222                                         else if (theme_regionid == RGN_TYPE_HEADER)
223                                                 cp = ts->header_text_hi;
224                                         else
225                                                 cp = ts->button_text_hi;
226                                         break;
227                                 case TH_TITLE:
228                                         if (theme_regionid == RGN_TYPE_WINDOW)
229                                                 cp = ts->title;
230                                         else if (theme_regionid == RGN_TYPE_CHANNELS)
231                                                 cp = ts->list_title;
232                                         else if (theme_regionid == RGN_TYPE_HEADER)
233                                                 cp = ts->header_title;
234                                         else
235                                                 cp = ts->button_title;
236                                         break;
237
238                                 case TH_HEADER:
239                                         cp = ts->header; break;
240                                 case TH_HEADERDESEL:
241                                         /* we calculate a dynamic builtin header deselect color, also for pulldowns... */
242                                         cp = ts->header;
243                                         headerdesel[0] = cp[0] > 10 ? cp[0] - 10 : 0;
244                                         headerdesel[1] = cp[1] > 10 ? cp[1] - 10 : 0;
245                                         headerdesel[2] = cp[2] > 10 ? cp[2] - 10 : 0;
246                                         headerdesel[3] = cp[3];
247                                         cp = headerdesel;
248                                         break;
249                                 case TH_HEADER_TEXT:
250                                         cp = ts->header_text; break;
251                                 case TH_HEADER_TEXT_HI:
252                                         cp = ts->header_text_hi; break;
253
254                                 case TH_PANEL_HEADER:
255                                         cp = ts->panelcolors.header; break;
256                                 case TH_PANEL_BACK:
257                                         cp = ts->panelcolors.back; break;
258                                 case TH_PANEL_SUB_BACK:
259                                         cp = ts->panelcolors.sub_back; break;
260
261                                 case TH_BUTBACK:
262                                         cp = ts->button; break;
263                                 case TH_BUTBACK_TEXT:
264                                         cp = ts->button_text; break;
265                                 case TH_BUTBACK_TEXT_HI:
266                                         cp = ts->button_text_hi; break;
267
268                                 case TH_TAB_ACTIVE:
269                                         cp = ts->tab_active; break;
270                                 case TH_TAB_INACTIVE:
271                                         cp = ts->tab_inactive; break;
272                                 case TH_TAB_BACK:
273                                         cp = ts->tab_back; break;
274                                 case TH_TAB_OUTLINE:
275                                         cp = ts->tab_outline; break;
276
277                                 case TH_SHADE1:
278                                         cp = ts->shade1; break;
279                                 case TH_SHADE2:
280                                         cp = ts->shade2; break;
281                                 case TH_HILITE:
282                                         cp = ts->hilite; break;
283
284                                 case TH_GRID:
285                                         cp = ts->grid; break;
286                                 case TH_VIEW_OVERLAY:
287                                         cp = ts->view_overlay; break;
288                                 case TH_WIRE:
289                                         cp = ts->wire; break;
290                                 case TH_WIRE_INNER:
291                                         cp = ts->syntaxr; break;
292                                 case TH_WIRE_EDIT:
293                                         cp = ts->wire_edit; break;
294                                 case TH_LAMP:
295                                         cp = ts->lamp; break;
296                                 case TH_SPEAKER:
297                                         cp = ts->speaker; break;
298                                 case TH_CAMERA:
299                                         cp = ts->camera; break;
300                                 case TH_EMPTY:
301                                         cp = ts->empty; break;
302                                 case TH_SELECT:
303                                         cp = ts->select; break;
304                                 case TH_ACTIVE:
305                                         cp = ts->active; break;
306                                 case TH_GROUP:
307                                         cp = ts->group; break;
308                                 case TH_GROUP_ACTIVE:
309                                         cp = ts->group_active; break;
310                                 case TH_TRANSFORM:
311                                         cp = ts->transform; break;
312                                 case TH_VERTEX:
313                                         cp = ts->vertex; break;
314                                 case TH_VERTEX_SELECT:
315                                         cp = ts->vertex_select; break;
316                                 case TH_VERTEX_BEVEL:
317                                         cp = ts->vertex_bevel; break;
318                                 case TH_VERTEX_UNREFERENCED:
319                                         cp = ts->vertex_unreferenced; break;
320                                 case TH_VERTEX_SIZE:
321                                         cp = &ts->vertex_size; break;
322                                 case TH_OUTLINE_WIDTH:
323                                         cp = &ts->outline_width; break;
324                                 case TH_EDGE:
325                                         cp = ts->edge; break;
326                                 case TH_EDGE_SELECT:
327                                         cp = ts->edge_select; break;
328                                 case TH_EDGE_SEAM:
329                                         cp = ts->edge_seam; break;
330                                 case TH_EDGE_SHARP:
331                                         cp = ts->edge_sharp; break;
332                                 case TH_EDGE_CREASE:
333                                         cp = ts->edge_crease; break;
334                                 case TH_EDGE_BEVEL:
335                                         cp = ts->edge_bevel; break;
336                                 case TH_EDITMESH_ACTIVE:
337                                         cp = ts->editmesh_active; break;
338                                 case TH_EDGE_FACESEL:
339                                         cp = ts->edge_facesel; break;
340                                 case TH_FACE:
341                                         cp = ts->face; break;
342                                 case TH_FACE_SELECT:
343                                         cp = ts->face_select; break;
344                                 case TH_FACE_DOT:
345                                         cp = ts->face_dot; break;
346                                 case TH_FACEDOT_SIZE:
347                                         cp = &ts->facedot_size; break;
348                                 case TH_DRAWEXTRA_EDGELEN:
349                                         cp = ts->extra_edge_len; break;
350                                 case TH_DRAWEXTRA_EDGEANG:
351                                         cp = ts->extra_edge_angle; break;
352                                 case TH_DRAWEXTRA_FACEAREA:
353                                         cp = ts->extra_face_area; break;
354                                 case TH_DRAWEXTRA_FACEANG:
355                                         cp = ts->extra_face_angle; break;
356                                 case TH_NORMAL:
357                                         cp = ts->normal; break;
358                                 case TH_VNORMAL:
359                                         cp = ts->vertex_normal; break;
360                                 case TH_LNORMAL:
361                                         cp = ts->loop_normal; break;
362                                 case TH_BONE_SOLID:
363                                         cp = ts->bone_solid; break;
364                                 case TH_BONE_POSE:
365                                         cp = ts->bone_pose; break;
366                                 case TH_BONE_POSE_ACTIVE:
367                                         cp = ts->bone_pose_active; break;
368                                 case TH_STRIP:
369                                         cp = ts->strip; break;
370                                 case TH_STRIP_SELECT:
371                                         cp = ts->strip_select; break;
372                                 case TH_KEYTYPE_KEYFRAME:
373                                         cp = ts->keytype_keyframe; break;
374                                 case TH_KEYTYPE_KEYFRAME_SELECT:
375                                         cp = ts->keytype_keyframe_select; break;
376                                 case TH_KEYTYPE_EXTREME:
377                                         cp = ts->keytype_extreme; break;
378                                 case TH_KEYTYPE_EXTREME_SELECT:
379                                         cp = ts->keytype_extreme_select; break;
380                                 case TH_KEYTYPE_BREAKDOWN:
381                                         cp = ts->keytype_breakdown; break;
382                                 case TH_KEYTYPE_BREAKDOWN_SELECT:
383                                         cp = ts->keytype_breakdown_select; break;
384                                 case TH_KEYTYPE_JITTER:
385                                         cp = ts->keytype_jitter; break;
386                                 case TH_KEYTYPE_JITTER_SELECT:
387                                         cp = ts->keytype_jitter_select; break;
388                                 case TH_KEYTYPE_MOVEHOLD:
389                                         cp = ts->keytype_movehold; break;
390                                 case TH_KEYTYPE_MOVEHOLD_SELECT:
391                                         cp = ts->keytype_movehold_select; break;
392                                 case TH_KEYBORDER:
393                                         cp = ts->keyborder; break;
394                                 case TH_KEYBORDER_SELECT:
395                                         cp = ts->keyborder_select; break;
396                                 case TH_CFRAME:
397                                         cp = ts->cframe; break;
398                                 case TH_TIME_KEYFRAME:
399                                         cp = ts->time_keyframe; break;
400                                 case TH_TIME_GP_KEYFRAME:
401                                         cp = ts->time_gp_keyframe; break;
402                                 case TH_NURB_ULINE:
403                                         cp = ts->nurb_uline; break;
404                                 case TH_NURB_VLINE:
405                                         cp = ts->nurb_vline; break;
406                                 case TH_NURB_SEL_ULINE:
407                                         cp = ts->nurb_sel_uline; break;
408                                 case TH_NURB_SEL_VLINE:
409                                         cp = ts->nurb_sel_vline; break;
410                                 case TH_ACTIVE_SPLINE:
411                                         cp = ts->act_spline; break;
412                                 case TH_ACTIVE_VERT:
413                                         cp = ts->lastsel_point; break;
414                                 case TH_HANDLE_FREE:
415                                         cp = ts->handle_free; break;
416                                 case TH_HANDLE_AUTO:
417                                         cp = ts->handle_auto; break;
418                                 case TH_HANDLE_AUTOCLAMP:
419                                         cp = ts->handle_auto_clamped; break;
420                                 case TH_HANDLE_VECT:
421                                         cp = ts->handle_vect; break;
422                                 case TH_HANDLE_ALIGN:
423                                         cp = ts->handle_align; break;
424                                 case TH_HANDLE_SEL_FREE:
425                                         cp = ts->handle_sel_free; break;
426                                 case TH_HANDLE_SEL_AUTO:
427                                         cp = ts->handle_sel_auto; break;
428                                 case TH_HANDLE_SEL_AUTOCLAMP:
429                                         cp = ts->handle_sel_auto_clamped; break;
430                                 case TH_HANDLE_SEL_VECT:
431                                         cp = ts->handle_sel_vect; break;
432                                 case TH_HANDLE_SEL_ALIGN:
433                                         cp = ts->handle_sel_align; break;
434                                 case TH_FREESTYLE_EDGE_MARK:
435                                         cp = ts->freestyle_edge_mark; break;
436                                 case TH_FREESTYLE_FACE_MARK:
437                                         cp = ts->freestyle_face_mark; break;
438
439                                 case TH_SYNTAX_B:
440                                         cp = ts->syntaxb; break;
441                                 case TH_SYNTAX_V:
442                                         cp = ts->syntaxv; break;
443                                 case TH_SYNTAX_C:
444                                         cp = ts->syntaxc; break;
445                                 case TH_SYNTAX_L:
446                                         cp = ts->syntaxl; break;
447                                 case TH_SYNTAX_D:
448                                         cp = ts->syntaxd; break;
449                                 case TH_SYNTAX_R:
450                                         cp = ts->syntaxr; break;
451                                 case TH_SYNTAX_N:
452                                         cp = ts->syntaxn; break;
453                                 case TH_SYNTAX_S:
454                                         cp = ts->syntaxs; break;
455
456                                 case TH_NODE:
457                                         cp = ts->syntaxl; break;
458                                 case TH_NODE_INPUT:
459                                         cp = ts->syntaxn; break;
460                                 case TH_NODE_OUTPUT:
461                                         cp = ts->nodeclass_output; break;
462                                 case TH_NODE_COLOR:
463                                         cp = ts->syntaxb; break;
464                                 case TH_NODE_FILTER:
465                                         cp = ts->nodeclass_filter; break;
466                                 case TH_NODE_VECTOR:
467                                         cp = ts->nodeclass_vector; break;
468                                 case TH_NODE_TEXTURE:
469                                         cp = ts->nodeclass_texture; break;
470                                 case TH_NODE_PATTERN:
471                                         cp = ts->nodeclass_pattern; break;
472                                 case TH_NODE_SCRIPT:
473                                         cp = ts->nodeclass_script; break;
474                                 case TH_NODE_LAYOUT:
475                                         cp = ts->nodeclass_layout; break;
476                                 case TH_NODE_SHADER:
477                                         cp = ts->nodeclass_shader; break;
478                                 case TH_NODE_CONVERTOR:
479                                         cp = ts->syntaxv; break;
480                                 case TH_NODE_GROUP:
481                                         cp = ts->syntaxc; break;
482                                 case TH_NODE_INTERFACE:
483                                         cp = ts->console_output; break;
484                                 case TH_NODE_FRAME:
485                                         cp = ts->movie; break;
486                                 case TH_NODE_MATTE:
487                                         cp = ts->syntaxs; break;
488                                 case TH_NODE_DISTORT:
489                                         cp = ts->syntaxd; break;
490                                 case TH_NODE_CURVING:
491                                         cp = &ts->noodle_curving; break;
492
493                                 case TH_SEQ_MOVIE:
494                                         cp = ts->movie; break;
495                                 case TH_SEQ_MOVIECLIP:
496                                         cp = ts->movieclip; break;
497                                 case TH_SEQ_MASK:
498                                         cp = ts->mask; break;
499                                 case TH_SEQ_IMAGE:
500                                         cp = ts->image; break;
501                                 case TH_SEQ_SCENE:
502                                         cp = ts->scene; break;
503                                 case TH_SEQ_AUDIO:
504                                         cp = ts->audio; break;
505                                 case TH_SEQ_EFFECT:
506                                         cp = ts->effect; break;
507                                 case TH_SEQ_TRANSITION:
508                                         cp = ts->transition; break;
509                                 case TH_SEQ_META:
510                                         cp = ts->meta; break;
511                                 case TH_SEQ_TEXT:
512                                         cp = ts->text_strip; break;
513                                 case TH_SEQ_PREVIEW:
514                                         cp = ts->preview_back; break;
515
516                                 case TH_CONSOLE_OUTPUT:
517                                         cp = ts->console_output; break;
518                                 case TH_CONSOLE_INPUT:
519                                         cp = ts->console_input; break;
520                                 case TH_CONSOLE_INFO:
521                                         cp = ts->console_info; break;
522                                 case TH_CONSOLE_ERROR:
523                                         cp = ts->console_error; break;
524                                 case TH_CONSOLE_CURSOR:
525                                         cp = ts->console_cursor; break;
526                                 case TH_CONSOLE_SELECT:
527                                         cp = ts->console_select; break;
528
529                                 case TH_HANDLE_VERTEX:
530                                         cp = ts->handle_vertex;
531                                         break;
532                                 case TH_HANDLE_VERTEX_SELECT:
533                                         cp = ts->handle_vertex_select;
534                                         break;
535                                 case TH_HANDLE_VERTEX_SIZE:
536                                         cp = &ts->handle_vertex_size;
537                                         break;
538
539                                 case TH_GP_VERTEX:
540                                         cp = ts->gp_vertex;
541                                         break;
542                                 case TH_GP_VERTEX_SELECT:
543                                         cp = ts->gp_vertex_select;
544                                         break;
545                                 case TH_GP_VERTEX_SIZE:
546                                         cp = &ts->gp_vertex_size;
547                                         break;
548
549                                 case TH_DOPESHEET_CHANNELOB:
550                                         cp = ts->ds_channel;
551                                         break;
552                                 case TH_DOPESHEET_CHANNELSUBOB:
553                                         cp = ts->ds_subchannel;
554                                         break;
555                                 case TH_DOPESHEET_IPOLINE:
556                                         cp = ts->ds_ipoline;
557                                         break;
558
559                                 case TH_PREVIEW_BACK:
560                                         cp = ts->preview_back;
561                                         break;
562
563                                 case TH_STITCH_PREVIEW_FACE:
564                                         cp = ts->preview_stitch_face;
565                                         break;
566
567                                 case TH_STITCH_PREVIEW_EDGE:
568                                         cp = ts->preview_stitch_edge;
569                                         break;
570
571                                 case TH_STITCH_PREVIEW_VERT:
572                                         cp = ts->preview_stitch_vert;
573                                         break;
574
575                                 case TH_STITCH_PREVIEW_STITCHABLE:
576                                         cp = ts->preview_stitch_stitchable;
577                                         break;
578
579                                 case TH_STITCH_PREVIEW_UNSTITCHABLE:
580                                         cp = ts->preview_stitch_unstitchable;
581                                         break;
582                                 case TH_STITCH_PREVIEW_ACTIVE:
583                                         cp = ts->preview_stitch_active;
584                                         break;
585
586                                 case TH_PAINT_CURVE_HANDLE:
587                                         cp = ts->paint_curve_handle;
588                                         break;
589                                 case TH_PAINT_CURVE_PIVOT:
590                                         cp = ts->paint_curve_pivot;
591                                         break;
592
593                                 case TH_METADATA_BG:
594                                         cp = ts->metadatabg;
595                                         break;
596                                 case TH_METADATA_TEXT:
597                                         cp = ts->metadatatext;
598                                         break;
599
600                                 case TH_UV_OTHERS:
601                                         cp = ts->uv_others;
602                                         break;
603                                 case TH_UV_SHADOW:
604                                         cp = ts->uv_shadow;
605                                         break;
606
607                                 case TH_MARKER_OUTLINE:
608                                         cp = ts->marker_outline; break;
609                                 case TH_MARKER:
610                                         cp = ts->marker; break;
611                                 case TH_ACT_MARKER:
612                                         cp = ts->act_marker; break;
613                                 case TH_SEL_MARKER:
614                                         cp = ts->sel_marker; break;
615                                 case TH_BUNDLE_SOLID:
616                                         cp = ts->bundle_solid; break;
617                                 case TH_DIS_MARKER:
618                                         cp = ts->dis_marker; break;
619                                 case TH_PATH_BEFORE:
620                                         cp = ts->path_before; break;
621                                 case TH_PATH_AFTER:
622                                         cp = ts->path_after; break;
623                                 case TH_CAMERA_PATH:
624                                         cp = ts->camera_path; break;
625                                 case TH_LOCK_MARKER:
626                                         cp = ts->lock_marker; break;
627
628                                 case TH_MATCH:
629                                         cp = ts->match;
630                                         break;
631
632                                 case TH_SELECT_HIGHLIGHT:
633                                         cp = ts->selected_highlight;
634                                         break;
635
636                                 case TH_SKIN_ROOT:
637                                         cp = ts->skin_root;
638                                         break;
639
640                                 case TH_ANIM_ACTIVE:
641                                         cp = ts->anim_active;
642                                         break;
643                                 case TH_ANIM_INACTIVE:
644                                         cp = ts->anim_non_active;
645                                         break;
646                                 case TH_ANIM_PREVIEW_RANGE:
647                                         cp = ts->anim_preview_range;
648                                         break;
649
650                                 case TH_NLA_TWEAK:
651                                         cp = ts->nla_tweaking;
652                                         break;
653                                 case TH_NLA_TWEAK_DUPLI:
654                                         cp = ts->nla_tweakdupli;
655                                         break;
656
657                                 case TH_NLA_TRANSITION:
658                                         cp = ts->nla_transition;
659                                         break;
660                                 case TH_NLA_TRANSITION_SEL:
661                                         cp = ts->nla_transition_sel;
662                                         break;
663                                 case TH_NLA_META:
664                                         cp = ts->nla_meta;
665                                         break;
666                                 case TH_NLA_META_SEL:
667                                         cp = ts->nla_meta_sel;
668                                         break;
669                                 case TH_NLA_SOUND:
670                                         cp = ts->nla_sound;
671                                         break;
672                                 case TH_NLA_SOUND_SEL:
673                                         cp = ts->nla_sound_sel;
674                                         break;
675
676                                 case TH_WIDGET_EMBOSS:
677                                         cp = btheme->tui.widget_emboss; break;
678
679                                 case TH_EDITOR_OUTLINE:
680                                         cp = btheme->tui.editor_outline;
681                                         break;
682                                 case TH_AXIS_X:
683                                         cp = btheme->tui.xaxis; break;
684                                 case TH_AXIS_Y:
685                                         cp = btheme->tui.yaxis; break;
686                                 case TH_AXIS_Z:
687                                         cp = btheme->tui.zaxis; break;
688
689                                 case TH_GIZMO_HI:
690                                         cp = btheme->tui.gizmo_hi; break;
691                                 case TH_GIZMO_PRIMARY:
692                                         cp = btheme->tui.gizmo_primary; break;
693                                 case TH_GIZMO_SECONDARY:
694                                         cp = btheme->tui.gizmo_secondary; break;
695                                 case TH_GIZMO_A:
696                                         cp = btheme->tui.gizmo_a; break;
697                                 case TH_GIZMO_B:
698                                         cp = btheme->tui.gizmo_b; break;
699
700                                 case TH_ICON_COLLECTION:
701                                         cp = btheme->tui.icon_collection; break;
702                                 case TH_ICON_OBJECT:
703                                         cp = btheme->tui.icon_object; break;
704                                 case TH_ICON_OBJECT_DATA:
705                                         cp = btheme->tui.icon_object_data; break;
706                                 case TH_ICON_MODIFIER:
707                                         cp = btheme->tui.icon_modifier; break;
708                                 case TH_ICON_SHADING:
709                                         cp = btheme->tui.icon_shading; break;
710
711                                 case TH_INFO_SELECTED:
712                                         cp = ts->info_selected;
713                                         break;
714                                 case TH_INFO_SELECTED_TEXT:
715                                         cp = ts->info_selected_text;
716                                         break;
717                                 case TH_INFO_ERROR:
718                                         cp = ts->info_error;
719                                         break;
720                                 case TH_INFO_ERROR_TEXT:
721                                         cp = ts->info_error_text;
722                                         break;
723                                 case TH_INFO_WARNING:
724                                         cp = ts->info_warning;
725                                         break;
726                                 case TH_INFO_WARNING_TEXT:
727                                         cp = ts->info_warning_text;
728                                         break;
729                                 case TH_INFO_INFO:
730                                         cp = ts->info_info;
731                                         break;
732                                 case TH_INFO_INFO_TEXT:
733                                         cp = ts->info_info_text;
734                                         break;
735                                 case TH_INFO_DEBUG:
736                                         cp = ts->info_debug;
737                                         break;
738                                 case TH_INFO_DEBUG_TEXT:
739                                         cp = ts->info_debug_text;
740                                         break;
741                                 case TH_V3D_CLIPPING_BORDER:
742                                         cp = ts->clipping_border_3d;
743                                         break;
744                         }
745                 }
746         }
747
748         return (const uchar *)cp;
749 }
750
751 /**
752  * initialize default theme
753  * \note: when you add new colors, created & saved themes need initialized
754  * use function below, init_userdef_do_versions()
755  */
756 void ui_theme_init_default(void)
757 {
758
759         /* we search for the theme with name Default */
760         bTheme *btheme = BLI_findstring(&U.themes, "Default", offsetof(bTheme, name));
761         if (btheme == NULL) {
762                 btheme = MEM_callocN(sizeof(bTheme), __func__);
763                 BLI_addtail(&U.themes, btheme);
764         }
765
766         UI_SetTheme(0, 0);  /* make sure the global used in this file is set */
767
768         const int active_theme_area = btheme->active_theme_area;
769         memcpy(btheme, &U_theme_default, sizeof(*btheme));
770         btheme->active_theme_area = active_theme_area;
771 }
772
773 void ui_style_init_default(void)
774 {
775         BLI_freelistN(&U.uistyles);
776         /* gets automatically re-allocated */
777         uiStyleInit();
778 }
779
780
781 void UI_SetTheme(int spacetype, int regionid)
782 {
783         if (spacetype) {
784                 /* later on, a local theme can be found too */
785                 theme_active = U.themes.first;
786                 theme_spacetype = spacetype;
787                 theme_regionid = regionid;
788         }
789         else if (regionid) {
790                 /* popups */
791                 theme_active = U.themes.first;
792                 theme_spacetype = SPACE_BUTS;
793                 theme_regionid = regionid;
794         }
795         else {
796                 /* for safety, when theme was deleted */
797                 theme_active = U.themes.first;
798                 theme_spacetype = SPACE_VIEW3D;
799                 theme_regionid = RGN_TYPE_WINDOW;
800         }
801 }
802
803 bTheme *UI_GetTheme(void)
804 {
805         return U.themes.first;
806 }
807
808 /**
809  * for the rare case we need to temp swap in a different theme (offscreen render)
810  */
811 void UI_Theme_Store(struct bThemeState *theme_state)
812 {
813         *theme_state = g_theme_state;
814 }
815 void UI_Theme_Restore(struct bThemeState *theme_state)
816 {
817         g_theme_state = *theme_state;
818 }
819
820 void UI_GetThemeColorShadeAlpha4ubv(int colorid, int coloffset, int alphaoffset, uchar col[4])
821 {
822         int r, g, b, a;
823         const uchar *cp;
824
825         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
826         r = coloffset + (int) cp[0];
827         CLAMP(r, 0, 255);
828         g = coloffset + (int) cp[1];
829         CLAMP(g, 0, 255);
830         b = coloffset + (int) cp[2];
831         CLAMP(b, 0, 255);
832         a = alphaoffset + (int) cp[3];
833         CLAMP(a, 0, 255);
834
835         col[0] = r;
836         col[1] = g;
837         col[2] = b;
838         col[3] = a;
839 }
840
841 void UI_GetThemeColorBlend3ubv(int colorid1, int colorid2, float fac, uchar col[3])
842 {
843         const uchar *cp1, *cp2;
844
845         cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
846         cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
847
848         CLAMP(fac, 0.0f, 1.0f);
849         col[0] = floorf((1.0f - fac) * cp1[0] + fac * cp2[0]);
850         col[1] = floorf((1.0f - fac) * cp1[1] + fac * cp2[1]);
851         col[2] = floorf((1.0f - fac) * cp1[2] + fac * cp2[2]);
852 }
853
854 void UI_GetThemeColorBlend3f(int colorid1, int colorid2, float fac, float r_col[3])
855 {
856         const uchar *cp1, *cp2;
857
858         cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
859         cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
860
861         CLAMP(fac, 0.0f, 1.0f);
862         r_col[0] = ((1.0f - fac) * cp1[0] + fac * cp2[0]) / 255.0f;
863         r_col[1] = ((1.0f - fac) * cp1[1] + fac * cp2[1]) / 255.0f;
864         r_col[2] = ((1.0f - fac) * cp1[2] + fac * cp2[2]) / 255.0f;
865 }
866
867 void UI_FontThemeColor(int fontid, int colorid)
868 {
869         uchar color[4];
870         UI_GetThemeColor4ubv(colorid, color);
871         BLF_color4ubv(fontid, color);
872 }
873
874 /* get individual values, not scaled */
875 float UI_GetThemeValuef(int colorid)
876 {
877         const uchar *cp;
878
879         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
880         return ((float)cp[0]);
881 }
882
883 /* get individual values, not scaled */
884 int UI_GetThemeValue(int colorid)
885 {
886         const uchar *cp;
887
888         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
889         return ((int) cp[0]);
890 }
891
892 /* versions of the function above, which take a space-type */
893 float UI_GetThemeValueTypef(int colorid, int spacetype)
894 {
895         const uchar *cp;
896
897         cp = UI_ThemeGetColorPtr(theme_active, spacetype, colorid);
898         return ((float)cp[0]);
899 }
900
901 int UI_GetThemeValueType(int colorid, int spacetype)
902 {
903         const uchar *cp;
904
905         cp = UI_ThemeGetColorPtr(theme_active, spacetype, colorid);
906         return ((int)cp[0]);
907 }
908
909
910 /* get the color, range 0.0-1.0 */
911 void UI_GetThemeColor3fv(int colorid, float col[3])
912 {
913         const uchar *cp;
914
915         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
916         col[0] = ((float)cp[0]) / 255.0f;
917         col[1] = ((float)cp[1]) / 255.0f;
918         col[2] = ((float)cp[2]) / 255.0f;
919 }
920
921 void UI_GetThemeColor4fv(int colorid, float col[4])
922 {
923         const uchar *cp;
924
925         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
926         col[0] = ((float)cp[0]) / 255.0f;
927         col[1] = ((float)cp[1]) / 255.0f;
928         col[2] = ((float)cp[2]) / 255.0f;
929         col[3] = ((float)cp[3]) / 255.0f;
930 }
931
932 /* get the color, range 0.0-1.0, complete with shading offset */
933 void UI_GetThemeColorShade3fv(int colorid, int offset, float col[3])
934 {
935         int r, g, b;
936         const uchar *cp;
937
938         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
939
940         r = offset + (int) cp[0];
941         CLAMP(r, 0, 255);
942         g = offset + (int) cp[1];
943         CLAMP(g, 0, 255);
944         b = offset + (int) cp[2];
945         CLAMP(b, 0, 255);
946
947         col[0] = ((float)r) / 255.0f;
948         col[1] = ((float)g) / 255.0f;
949         col[2] = ((float)b) / 255.0f;
950 }
951
952 void UI_GetThemeColorShade3ubv(int colorid, int offset, uchar col[3])
953 {
954         int r, g, b;
955         const uchar *cp;
956
957         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
958
959         r = offset + (int) cp[0];
960         CLAMP(r, 0, 255);
961         g = offset + (int) cp[1];
962         CLAMP(g, 0, 255);
963         b = offset + (int) cp[2];
964         CLAMP(b, 0, 255);
965
966         col[0] = r;
967         col[1] = g;
968         col[2] = b;
969 }
970
971 void UI_GetThemeColorBlendShade3ubv(int colorid1, int colorid2, float fac, int offset, uchar col[3])
972 {
973         const uchar *cp1, *cp2;
974
975         cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
976         cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
977
978         CLAMP(fac, 0.0f, 1.0f);
979
980         float blend[3];
981         blend[0] = offset + floorf((1.0f - fac) * cp1[0] + fac * cp2[0]);
982         blend[1] = offset + floorf((1.0f - fac) * cp1[1] + fac * cp2[1]);
983         blend[2] = offset + floorf((1.0f - fac) * cp1[2] + fac * cp2[2]);
984
985         unit_float_to_uchar_clamp_v3(col, blend);
986 }
987
988 void UI_GetThemeColorShade4ubv(int colorid, int offset, uchar col[4])
989 {
990         int r, g, b;
991         const uchar *cp;
992
993         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
994         r = offset + (int) cp[0];
995         CLAMP(r, 0, 255);
996         g = offset + (int) cp[1];
997         CLAMP(g, 0, 255);
998         b = offset + (int) cp[2];
999         CLAMP(b, 0, 255);
1000
1001         col[0] = r;
1002         col[1] = g;
1003         col[2] = b;
1004         col[3] = cp[3];
1005 }
1006
1007 void UI_GetThemeColorShadeAlpha4fv(int colorid, int coloffset, int alphaoffset, float col[4])
1008 {
1009         int r, g, b, a;
1010         const uchar *cp;
1011
1012         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1013
1014         r = coloffset + (int) cp[0];
1015         CLAMP(r, 0, 255);
1016         g = coloffset + (int) cp[1];
1017         CLAMP(g, 0, 255);
1018         b = coloffset + (int) cp[2];
1019         CLAMP(b, 0, 255);
1020         a = alphaoffset + (int) cp[3];
1021         CLAMP(b, 0, 255);
1022
1023         col[0] = ((float)r) / 255.0f;
1024         col[1] = ((float)g) / 255.0f;
1025         col[2] = ((float)b) / 255.0f;
1026         col[3] = ((float)a) / 255.0f;
1027 }
1028
1029 void UI_GetThemeColorBlendShade3fv(int colorid1, int colorid2, float fac, int offset, float col[3])
1030 {
1031         int r, g, b;
1032         const uchar *cp1, *cp2;
1033
1034         cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
1035         cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
1036
1037         CLAMP(fac, 0.0f, 1.0f);
1038
1039         r = offset + floorf((1.0f - fac) * cp1[0] + fac * cp2[0]);
1040         CLAMP(r, 0, 255);
1041         g = offset + floorf((1.0f - fac) * cp1[1] + fac * cp2[1]);
1042         CLAMP(g, 0, 255);
1043         b = offset + floorf((1.0f - fac) * cp1[2] + fac * cp2[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 void UI_GetThemeColorBlendShade4fv(int colorid1, int colorid2, float fac, int offset, float col[4])
1052 {
1053         int r, g, b, a;
1054         const uchar *cp1, *cp2;
1055
1056         cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
1057         cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
1058
1059         CLAMP(fac, 0.0f, 1.0f);
1060
1061         r = offset + floorf((1.0f - fac) * cp1[0] + fac * cp2[0]);
1062         CLAMP(r, 0, 255);
1063         g = offset + floorf((1.0f - fac) * cp1[1] + fac * cp2[1]);
1064         CLAMP(g, 0, 255);
1065         b = offset + floorf((1.0f - fac) * cp1[2] + fac * cp2[2]);
1066         CLAMP(b, 0, 255);
1067         a = offset + floorf((1.0f - fac) * cp1[3] + fac * cp2[3]);
1068         CLAMP(a, 0, 255);
1069
1070         col[0] = ((float)r) / 255.0f;
1071         col[1] = ((float)g) / 255.0f;
1072         col[2] = ((float)b) / 255.0f;
1073         col[3] = ((float)a) / 255.0f;
1074 }
1075
1076 /* get the color, in char pointer */
1077 void UI_GetThemeColor3ubv(int colorid, uchar col[3])
1078 {
1079         const uchar *cp;
1080
1081         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1082         col[0] = cp[0];
1083         col[1] = cp[1];
1084         col[2] = cp[2];
1085 }
1086
1087 /* get the color, range 0.0-1.0, complete with shading offset */
1088 void UI_GetThemeColorShade4fv(int colorid, int offset, float col[4])
1089 {
1090         int r, g, b, a;
1091         const uchar *cp;
1092
1093         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1094
1095         r = offset + (int) cp[0];
1096         CLAMP(r, 0, 255);
1097         g = offset + (int) cp[1];
1098         CLAMP(g, 0, 255);
1099         b = offset + (int) cp[2];
1100         CLAMP(b, 0, 255);
1101
1102         a = (int) cp[3]; /* no shading offset... */
1103         CLAMP(a, 0, 255);
1104
1105         col[0] = ((float)r) / 255.0f;
1106         col[1] = ((float)g) / 255.0f;
1107         col[2] = ((float)b) / 255.0f;
1108         col[3] = ((float)a) / 255.0f;
1109 }
1110
1111 /* get the color, in char pointer */
1112 void UI_GetThemeColor4ubv(int colorid, uchar col[4])
1113 {
1114         const uchar *cp;
1115
1116         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1117         col[0] = cp[0];
1118         col[1] = cp[1];
1119         col[2] = cp[2];
1120         col[3] = cp[3];
1121 }
1122
1123 void UI_GetThemeColorType3ubv(int colorid, int spacetype, uchar col[3])
1124 {
1125         const uchar *cp;
1126
1127         cp = UI_ThemeGetColorPtr(theme_active, spacetype, colorid);
1128         col[0] = cp[0];
1129         col[1] = cp[1];
1130         col[2] = cp[2];
1131 }
1132
1133 void UI_GetThemeColorType4ubv(int colorid, int spacetype, uchar col[4])
1134 {
1135         const uchar *cp;
1136
1137         cp = UI_ThemeGetColorPtr(theme_active, spacetype, colorid);
1138         col[0] = cp[0];
1139         col[1] = cp[1];
1140         col[2] = cp[2];
1141         col[3] = cp[3];
1142 }
1143
1144 bool UI_GetIconThemeColor4fv(int colorid, float col[4])
1145 {
1146         if (colorid == 0) {
1147                 return false;
1148         }
1149
1150         /* Only colored icons in outliner and popups, overall UI is intended
1151          * to stay monochrome and out of the way except a few places where it
1152          * is important to communicate different data types. */
1153         if (!((theme_spacetype == SPACE_OUTLINER) ||
1154               (theme_regionid == RGN_TYPE_TEMPORARY)))
1155         {
1156                 return false;
1157         }
1158
1159         const uchar *cp;
1160         cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
1161         col[0] = ((float)cp[0]) / 255.0f;
1162         col[1] = ((float)cp[1]) / 255.0f;
1163         col[2] = ((float)cp[2]) / 255.0f;
1164         col[3] = ((float)cp[3]) / 255.0f;
1165
1166         return true;
1167 }
1168
1169 void UI_GetColorPtrShade3ubv(const uchar cp[3], uchar col[3], int offset)
1170 {
1171         int r, g, b;
1172
1173         r = offset + (int)cp[0];
1174         g = offset + (int)cp[1];
1175         b = offset + (int)cp[2];
1176
1177         CLAMP(r, 0, 255);
1178         CLAMP(g, 0, 255);
1179         CLAMP(b, 0, 255);
1180
1181         col[0] = r;
1182         col[1] = g;
1183         col[2] = b;
1184 }
1185
1186 /* get a 3 byte color, blended and shaded between two other char color pointers */
1187 void UI_GetColorPtrBlendShade3ubv(
1188         const uchar cp1[3], const uchar cp2[3], uchar col[3],
1189         float fac, int offset)
1190 {
1191         int r, g, b;
1192
1193         CLAMP(fac, 0.0f, 1.0f);
1194         r = offset + floor((1.0f - fac) * cp1[0] + fac * cp2[0]);
1195         g = offset + floor((1.0f - fac) * cp1[1] + fac * cp2[1]);
1196         b = offset + floor((1.0f - fac) * cp1[2] + fac * cp2[2]);
1197
1198         CLAMP(r, 0, 255);
1199         CLAMP(g, 0, 255);
1200         CLAMP(b, 0, 255);
1201
1202         col[0] = r;
1203         col[1] = g;
1204         col[2] = b;
1205 }
1206
1207 void UI_ThemeClearColor(int colorid)
1208 {
1209         float col[3];
1210
1211         UI_GetThemeColor3fv(colorid, col);
1212         GPU_clear_color(col[0], col[1], col[2], 0.0f);
1213 }
1214
1215 void UI_ThemeClearColorAlpha(int colorid, float alpha)
1216 {
1217         float col[3];
1218         UI_GetThemeColor3fv(colorid, col);
1219         GPU_clear_color(col[0], col[1], col[2], alpha);
1220 }
1221
1222
1223 int UI_ThemeMenuShadowWidth(void)
1224 {
1225         bTheme *btheme = UI_GetTheme();
1226         return (int)(btheme->tui.menu_shadow_width * UI_DPI_FAC);
1227 }
1228
1229 void UI_make_axis_color(const uchar src_col[3], uchar dst_col[3], const char axis)
1230 {
1231         uchar col[3];
1232
1233         switch (axis) {
1234                 case 'X':
1235                         UI_GetThemeColor3ubv(TH_AXIS_X, col);
1236                         UI_GetColorPtrBlendShade3ubv(src_col, col, dst_col, 0.5f, -10);
1237                         break;
1238                 case 'Y':
1239                         UI_GetThemeColor3ubv(TH_AXIS_Y, col);
1240                         UI_GetColorPtrBlendShade3ubv(src_col, col, dst_col, 0.5f, -10);
1241                         break;
1242                 case 'Z':
1243                         UI_GetThemeColor3ubv(TH_AXIS_Z, col);
1244                         UI_GetColorPtrBlendShade3ubv(src_col, col, dst_col, 0.5f, -10);
1245                         break;
1246                 default:
1247                         BLI_assert(0);
1248                         break;
1249         }
1250 }
1251
1252 /* patching UserDef struct and Themes */
1253 void init_userdef_do_versions(Main *bmain)
1254 {
1255         BLO_version_defaults_userpref_blend(bmain, &U);
1256
1257         if (STREQ(U.tempdir, "/")) {
1258                 BKE_tempdir_system_init(U.tempdir);
1259         }
1260
1261         /* Not versioning, just avoid errors. */
1262 #ifndef WITH_CYCLES
1263         BKE_addon_remove_safe(&U.addons, "cycles");
1264 #endif
1265
1266 }