Skip to content

Commit

Permalink
#1155 Add global option to switch off ReaLearn panel background colors
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Sep 3, 2024
1 parent dca8d07 commit a03b6f7
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 1 deletion.
31 changes: 31 additions & 0 deletions main/src/infrastructure/plugin/backbone_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions main/src/infrastructure/ui/color_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,6 +73,9 @@ impl View for ColorPanel {
_device_context: DeviceContext,
_window: Window,
) -> Option<Hbrush> {
if !BackboneShell::get().config().background_colors_enabled() {
return None;
}
util::view::get_brush_for_color_pair(self.desc.color_pair)
}
}
Expand Down
27 changes: 27 additions & 0 deletions main/src/infrastructure/ui/header_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -3072,6 +3098,7 @@ enum MainMenuAction {
ToggleUpperFloorMembership,
SetStayActiveWhenProjectInBackground(StayActiveWhenProjectInBackground),
ToggleServer,
ToggleBackgroundColors,
ToggleUseUnitPresetLinksOnly,
AddFirewallRule,
ChangeSessionId,
Expand Down
7 changes: 6 additions & 1 deletion main/src/infrastructure/ui/instance_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -306,6 +308,9 @@ impl View for InstancePanel {
_device_context: DeviceContext,
_window: Window,
) -> Option<Hbrush> {
if !BackboneShell::get().config().background_colors_enabled() {
return None;
}
util::view::get_brush_for_color_pair(colors::instance_panel_background())
}
}
6 changes: 6 additions & 0 deletions main/src/infrastructure/ui/mapping_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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())
Expand Down
6 changes: 6 additions & 0 deletions main/src/infrastructure/ui/mapping_row_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
Expand Down

0 comments on commit a03b6f7

Please sign in to comment.