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