1 /*
2  * Copyright (C) 2020-2021 Alexandros Theodotou <alex at zrythm dot org>
3  *
4  * This file is part of ZLFO
5  *
6  * ZLFO is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as
8  * published by the Free Software Foundation, either version 3 of the
9  * License, or (at your option) any later version.
10  *
11  * ZLFO is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  */
16 
17 #ifndef __ZLFO_UI_THEME_H__
18 #define __ZLFO_UI_THEME_H__
19 
20 #include PLUGIN_CONFIG
21 
22 #include "lv2/log/logger.h"
23 
24 #include <ztoolkit/ztk.h>
25 
26 #include <glib.h>
27 
28 /**
29  * Theme for the ZLFO UI.
30  */
31 typedef struct LfoUiTheme
32 {
33   /** Background color. */
34   ZtkColor bg;
35 
36   /** Selected area background color. */
37   ZtkColor selected_bg;
38 
39   /** Button color. */
40   ZtkColor button_normal;
41 
42   /** Button hover color. */
43   ZtkColor button_hover;
44 
45   /** Active grey color. */
46   ZtkColor button_active;
47 
48   /** Button click color. */
49   ZtkColor button_click;
50 
51   /** Left button click color. */
52   ZtkColor left_button_click;
53 
54   /** Bright click color. */
55   ZtkColor bright_click;
56 
57   /** Line/curve color. */
58   ZtkColor line;
59 
60   /** Grid line color. */
61   ZtkColor grid;
62 
63   /** Grid strong line color. */
64   ZtkColor grid_strong;
65 
66   /** Line below or above the button when hovered. */
67   ZtkColor button_lining_active;
68   ZtkColor button_lining_hover;
69 
70   ZtkRsvgHandle * sine_svg;
71   ZtkRsvgHandle * saw_svg;
72   ZtkRsvgHandle * triangle_svg;
73   ZtkRsvgHandle * square_svg;
74   ZtkRsvgHandle * custom_svg;
75   ZtkRsvgHandle * curve_svg;
76   ZtkRsvgHandle * step_svg;
77   ZtkRsvgHandle * curve_active_svg;
78   ZtkRsvgHandle * step_active_svg;
79 
80   ZtkRsvgHandle * range_svg;
81 
82   ZtkRsvgHandle * sync_svg;
83   ZtkRsvgHandle * freeb_svg;
84   ZtkRsvgHandle * sync_black_svg;
85   ZtkRsvgHandle * freeb_black_svg;
86 
87   ZtkRsvgHandle * zrythm_svg;
88   ZtkRsvgHandle * zrythm_hover_svg;
89   ZtkRsvgHandle * zrythm_orange_svg;
90 
91   ZtkRsvgHandle * grid_snap_svg;
92   ZtkRsvgHandle * grid_snap_hover_svg;
93   ZtkRsvgHandle * grid_snap_click_svg;
94   ZtkRsvgHandle * hmirror_svg;
95   ZtkRsvgHandle * hmirror_hover_svg;
96   ZtkRsvgHandle * hmirror_click_svg;
97   ZtkRsvgHandle * vmirror_svg;
98   ZtkRsvgHandle * vmirror_hover_svg;
99   ZtkRsvgHandle * vmirror_click_svg;
100   ZtkRsvgHandle * invert_svg;
101   ZtkRsvgHandle * shift_svg;
102 
103   ZtkRsvgHandle * down_arrow_svg;
104 
105 } LfoUiTheme;
106 
107 static inline int
zlfo_ui_theme_init(LfoUiTheme * theme,LV2_Log_Logger * logger,const char * bundle_path)108 zlfo_ui_theme_init (
109   LfoUiTheme *     theme,
110   LV2_Log_Logger * logger,
111   const char *     bundle_path)
112 {
113 
114 #define SET_COLOR(cname,_hex) \
115   ztk_color_parse_hex ( \
116     &theme->cname, _hex); \
117   theme->cname.alpha = 1.0
118 
119   SET_COLOR (bg, "#323232");
120   SET_COLOR (button_normal, "#4A4A4A");
121   SET_COLOR (button_hover, "#5D5D5D");
122   SET_COLOR (button_active, "#6D6D6D");
123   SET_COLOR (button_click, "#F79616");
124   SET_COLOR (left_button_click, "#D68A0C");
125   SET_COLOR (bright_click, "#FF6501");
126   SET_COLOR (line, "#D68A0C");
127   SET_COLOR (selected_bg, "#262626");
128   SET_COLOR (grid_strong, "#DDDDDD");
129   SET_COLOR (grid, "#999999");
130   SET_COLOR (button_lining_active, "#2EB398");
131   SET_COLOR (button_lining_hover, "#19664c");
132 
133   char * abs_path;
134 #define LOAD_SVG(name) \
135   abs_path = \
136     g_build_filename ( \
137       bundle_path, "resources", #name ".svg", \
138       NULL); \
139   theme->name##_svg = \
140     ztk_rsvg_load_svg (abs_path); \
141   if (!theme->name##_svg) \
142     { \
143       lv2_log_error ( \
144         logger, \
145         "Failed loading SVG: %s", abs_path); \
146       return -1; \
147     }
148 
149   LOAD_SVG (sine);
150   LOAD_SVG (triangle);
151   LOAD_SVG (saw);
152   LOAD_SVG (square);
153   LOAD_SVG (custom);
154   LOAD_SVG (curve);
155   LOAD_SVG (step);
156   LOAD_SVG (curve_active);
157   LOAD_SVG (step_active);
158   LOAD_SVG (range);
159   LOAD_SVG (sync);
160   LOAD_SVG (freeb);
161   LOAD_SVG (sync_black);
162   LOAD_SVG (freeb_black);
163   LOAD_SVG (zrythm);
164   LOAD_SVG (zrythm_hover);
165   LOAD_SVG (zrythm_orange);
166   LOAD_SVG (grid_snap);
167   LOAD_SVG (grid_snap_hover);
168   LOAD_SVG (grid_snap_click);
169   LOAD_SVG (hmirror);
170   LOAD_SVG (hmirror_hover);
171   LOAD_SVG (hmirror_click);
172   LOAD_SVG (vmirror);
173   LOAD_SVG (vmirror_hover);
174   LOAD_SVG (vmirror_click);
175   LOAD_SVG (invert);
176   LOAD_SVG (shift);
177   LOAD_SVG (down_arrow);
178 
179   return 0;
180 }
181 
182 /**
183  * Sets the cairo color to that in the theme.
184  */
185 #define zlfo_ui_theme_set_cr_color(theme,cr,color_name) \
186   ztk_color_set_for_cairo ( \
187     &(theme)->color_name, cr)
188 
189 #define zlfo_ui_theme_set_cr_color_with_alpha( \
190   theme,cr,color_name,alpha) \
191   cairo_set_source_rgba ( \
192     cr, (theme)->color_name.red, \
193     (theme)->color_name.green, \
194     (theme)->color_name.blue, alpha)
195 
196 #endif
197