diff --git a/main/src/infrastructure/plugin/backbone_shell.rs b/main/src/infrastructure/plugin/backbone_shell.rs index 76729e25..95f7dd57 100644 --- a/main/src/infrastructure/plugin/backbone_shell.rs +++ b/main/src/infrastructure/plugin/backbone_shell.rs @@ -1016,6 +1016,10 @@ impl BackboneShell { self.server.borrow_mut().stop(); } + pub fn toggle_background_colors(&self) { + self.change_config(BackboneConfig::toggle_background_colors); + } + /// Requires REAPER version >= 711+dev0305. pub fn toggle_toolbar_button_dynamically(&self, command_name: &str) -> anyhow::Result<()> { self.change_config(|config| { @@ -2126,6 +2130,18 @@ impl BackboneConfig { Url::parse(&self.main.companion_web_app_url).expect("invalid companion web app URL") } + pub fn background_colors_enabled(&self) -> bool { + self.main.background_colors_enabled > 0 + } + + pub fn toggle_background_colors(&mut self) { + self.main.background_colors_enabled = if self.background_colors_enabled() { + 0 + } else { + 1 + }; + } + pub fn toolbar_button_is_enabled(&self, command_name: &str) -> bool { self.toolbar.get(command_name).is_some_and(|v| *v != 0) } @@ -2160,11 +2176,25 @@ struct MainConfig { )] companion_web_app_url: String, showed_welcome_screen: u8, + #[serde( + default = "default_background_colors_enabled", + skip_serializing_if = "is_default_background_colors_enabled" + )] + background_colors_enabled: u8, } const DEFAULT_SERVER_HTTP_PORT: u16 = 39080; const DEFAULT_SERVER_HTTPS_PORT: u16 = 39443; const DEFAULT_SERVER_GRPC_PORT: u16 = 39051; +const DEFAULT_BACKGROUND_COLORS_ENABLED: u8 = 1; + +fn default_background_colors_enabled() -> u8 { + DEFAULT_BACKGROUND_COLORS_ENABLED +} + +fn is_default_background_colors_enabled(v: &u8) -> bool { + *v == DEFAULT_BACKGROUND_COLORS_ENABLED +} fn default_server_http_port() -> u16 { DEFAULT_SERVER_HTTP_PORT @@ -2207,6 +2237,7 @@ impl Default for MainConfig { server_grpc_port: default_server_grpc_port(), companion_web_app_url: default_companion_web_app_url(), showed_welcome_screen: 0, + background_colors_enabled: default_background_colors_enabled(), } } } diff --git a/main/src/infrastructure/ui/color_panel.rs b/main/src/infrastructure/ui/color_panel.rs index 3e2de039..8552268f 100644 --- a/main/src/infrastructure/ui/color_panel.rs +++ b/main/src/infrastructure/ui/color_panel.rs @@ -3,6 +3,7 @@ use reaper_medium::Hbrush; use std::fmt::Debug; use std::ptr::null_mut; +use crate::infrastructure::plugin::BackboneShell; use crate::infrastructure::ui::bindings::root; use crate::infrastructure::ui::util; use crate::infrastructure::ui::util::colors::ColorPair; @@ -72,6 +73,9 @@ impl View for ColorPanel { _device_context: DeviceContext, _window: Window, ) -> Option { + if !BackboneShell::get().config().background_colors_enabled() { + return None; + } util::view::get_brush_for_color_pair(self.desc.color_pair) } } diff --git a/main/src/infrastructure/ui/header_panel.rs b/main/src/infrastructure/ui/header_panel.rs index 0094ac78..e72a1b2d 100644 --- a/main/src/infrastructure/ui/header_panel.rs +++ b/main/src/infrastructure/ui/header_panel.rs @@ -681,6 +681,19 @@ impl HeaderPanel { ), separator(), // Global scope + menu( + "User interface", + vec![ + item_with_opts( + "Background colors", + ItemOpts { + enabled: true, + checked: BackboneShell::get().config().background_colors_enabled(), + }, + MainMenuAction::ToggleBackgroundColors, + ), + ], + ), menu( "Server", vec![ @@ -789,6 +802,13 @@ impl HeaderPanel { MainMenuAction::SetStayActiveWhenProjectInBackground(option) => { self.set_stay_active_when_project_in_background(option) } + MainMenuAction::ToggleBackgroundColors => { + BackboneShell::get().toggle_background_colors(); + self.view.require_window().alert( + "Helgobox", + "You might need to restart REAPER for this to take effect.", + ); + } MainMenuAction::ToggleServer => { if app.server_is_running() { app.stop_server_persistently(); @@ -2705,6 +2725,9 @@ impl View for HeaderPanel { // On macOS/Linux we use color panels as real child windows. return false; } + if !BackboneShell::get().config().background_colors_enabled() { + return false; + } let window = self.view.require_window(); self.show_color_panel.paint_manually(device_context, window); true @@ -2720,6 +2743,9 @@ impl View for HeaderPanel { // anyway because SWELL macOS can't distinguish between different child controls. return None; } + if !BackboneShell::get().config().background_colors_enabled() { + return None; + } device_context.set_bk_mode_to_transparent(); let color_pair = match window.resource_id() { root::ID_HEADER_PANEL_SHOW_LABEL_TEXT @@ -3072,6 +3098,7 @@ enum MainMenuAction { ToggleUpperFloorMembership, SetStayActiveWhenProjectInBackground(StayActiveWhenProjectInBackground), ToggleServer, + ToggleBackgroundColors, ToggleUseUnitPresetLinksOnly, AddFirewallRule, ChangeSessionId, diff --git a/main/src/infrastructure/ui/instance_panel.rs b/main/src/infrastructure/ui/instance_panel.rs index 7cdad257..9ff1e143 100644 --- a/main/src/infrastructure/ui/instance_panel.rs +++ b/main/src/infrastructure/ui/instance_panel.rs @@ -7,7 +7,9 @@ use std::sync; use std::sync::Arc; use crate::domain::{InstanceId, SharedInstance, UnitId}; -use crate::infrastructure::plugin::{reaper_main_window, InstanceShell, SharedInstanceShell}; +use crate::infrastructure::plugin::{ + reaper_main_window, BackboneShell, InstanceShell, SharedInstanceShell, +}; use crate::infrastructure::ui::bindings::root; use crate::infrastructure::ui::util::colors; use swell_ui::{DeviceContext, Dimensions, Pixels, SharedView, View, ViewContext, Window}; @@ -306,6 +308,9 @@ impl View for InstancePanel { _device_context: DeviceContext, _window: Window, ) -> Option { + if !BackboneShell::get().config().background_colors_enabled() { + return None; + } util::view::get_brush_for_color_pair(colors::instance_panel_background()) } } diff --git a/main/src/infrastructure/ui/mapping_panel.rs b/main/src/infrastructure/ui/mapping_panel.rs index f571d7a4..05a2ffd0 100644 --- a/main/src/infrastructure/ui/mapping_panel.rs +++ b/main/src/infrastructure/ui/mapping_panel.rs @@ -7143,6 +7143,9 @@ impl View for MappingPanel { // On macOS/Linux we use color panels as real child windows. return false; } + if !BackboneShell::get().config().background_colors_enabled() { + return false; + } let window = self.view.require_window(); self.mapping_color_panel .paint_manually(device_context, window); @@ -7165,6 +7168,9 @@ impl View for MappingPanel { // anyway because SWELL macOS can't distinguish between different child controls. return None; } + if !BackboneShell::get().config().background_colors_enabled() { + return None; + } device_context.set_bk_mode_to_transparent(); let section = Section::from_resource_id(window.resource_id())?; view::get_brush_for_color_pair(section.color_pair()) diff --git a/main/src/infrastructure/ui/mapping_row_panel.rs b/main/src/infrastructure/ui/mapping_row_panel.rs index 840bc99c..11ab3e3e 100644 --- a/main/src/infrastructure/ui/mapping_row_panel.rs +++ b/main/src/infrastructure/ui/mapping_row_panel.rs @@ -883,6 +883,9 @@ impl View for MappingRowPanel { // On macOS/Linux we use color panels as real child windows. return false; } + if !BackboneShell::get().config().background_colors_enabled() { + return false; + } let window = self.view.require_window(); // Must be the first because we want it below the others self.mapping_color_panel @@ -904,6 +907,9 @@ impl View for MappingRowPanel { // anyway because SWELL macOS can't distinguish between different child controls. return None; } + if !BackboneShell::get().config().background_colors_enabled() { + return None; + } device_context.set_bk_mode_to_transparent(); let color_pair = match window.resource_id() { root::ID_MAPPING_ROW_SOURCE_LABEL_TEXT => colors::source(),