Skip to content

Commit

Permalink
NeverShowElements implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
A-tG committed May 1, 2022
1 parent 37b955b commit 2f8ff66
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 31 deletions.
20 changes: 10 additions & 10 deletions VoicemeeterOsdProgram/Core/OsdWindowManager.Visibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,49 @@ private static bool UpdateOsdElementsVis()
{
m_wpfControl.AllowAutoUpdateSeparators = false;

bool hasAnyChildVisible = false;
bool hasAnyElementVisible = false;
var children = m_wpfControl.MainContent.Children;
var len = children.Count;
for (int i = 0; i < len; i++)
{
var strip = (StripControl)children[i];
// 2 checks to imitate "lazy" evaluation
bool hasChanges = strip.HasChangesFlag;
if (!hasChanges) continue;
if (!strip.HasChangesFlag || !strip.HasAnyChildVisibleFlag) continue;

bool isIgnore = OptionsStorage.Osd.IgnoreStripsIndexes.Contains((uint)i);
if (isIgnore) continue;

strip.Visibility = Visibility.Visible;
UpdateAlwaysVisibleElements(strip);
hasAnyChildVisible = true;
hasAnyElementVisible = true;
}

m_wpfControl.UpdateSeparators();
m_wpfControl.AllowAutoUpdateSeparators = true;

return hasAnyChildVisible;
return hasAnyElementVisible;
}

private static void UpdateAlwaysVisibleElements(StripControl strip)
{
var options = OptionsStorage.Osd;
foreach (ButtonContainer btnCont in strip.BusBtnsContainer.Children)
{
if (!options.AlwaysShowElements.Contains(StripElements.Buses)) break;

btnCont.Visibility = Visibility.Visible;
if (btnCont.IsAlwaysVisible())
{
btnCont.Visibility = Visibility.Visible;
}
}

foreach (ButtonContainer btnCont in strip.ControlBtnsContainer.Children)
{
if (btnCont.IsAlwaysVisible?.Invoke() ?? false)
if (btnCont.IsAlwaysVisible())
{
btnCont.Visibility = Visibility.Visible;
}
}

if (options.AlwaysShowElements.Contains(StripElements.Fader))
if (strip.FaderCont.IsAlwaysVisible())
{
strip.FaderCont.Visibility = Visibility.Visible;
}
Expand Down
23 changes: 18 additions & 5 deletions VoicemeeterOsdProgram/Factories/OsdContentFactory.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using AtgDev.Voicemeeter.Types;
using System.Collections.Generic;
using VoicemeeterOsdProgram.Core;
using VoicemeeterOsdProgram.Core.Types;
using VoicemeeterOsdProgram.Options;
using VoicemeeterOsdProgram.Types;
using VoicemeeterOsdProgram.UiControls.OSD;
using VoicemeeterOsdProgram.UiControls.OSD.Strip;

Expand Down Expand Up @@ -56,7 +57,7 @@ private static void AddVirtualOutputs(OsdControl osd)
strip.StripLabel.Text = name;

MakeFaderParam(strip, stripIndex, StripType.Output);
strip.FaderCont.OsdParent = strip;
InitFader(strip);

osd.MainContent.Children.Add(strip);
}
Expand All @@ -72,7 +73,7 @@ private static void AddPhysicalOutputs(OsdControl osd)

MakeLabelParam(strip, i, name, StripType.Output);
MakeFaderParam(strip, i, StripType.Output);
strip.FaderCont.OsdParent = strip;
InitFader(strip);

osd.MainContent.Children.Add(strip);
}
Expand All @@ -88,7 +89,7 @@ private static void AddVirtualInputs(OsdControl osd)

MakeLabelParam(strip, stripIndex, $"VirtIn{i + 1}", StripType.Input);
MakeFaderParam(strip, stripIndex, StripType.Input);
strip.FaderCont.OsdParent = strip;
InitFader(strip);

osd.MainContent.Children.Add(strip);
}
Expand All @@ -102,7 +103,7 @@ private static void AddHardwareInputs(OsdControl osd)

MakeLabelParam(strip, i, $"HardIn{i + 1}", StripType.Input);
MakeFaderParam(strip, i, StripType.Input);
strip.FaderCont.OsdParent = strip;
InitFader(strip);

osd.MainContent.Children.Add(strip);
}
Expand Down Expand Up @@ -185,5 +186,17 @@ private static StripControl GetHardwareInputStrip(int stripIndex)
strip.ControlBtnsContainer.Children.Insert(0, btn);
return strip;
}

private static void InitFader(StripControl strip)
{
var f = strip.FaderCont;
f.OsdParent = strip;
f.IsAlwaysVisible = () =>
{
return !f.IsNeverShow() &&
OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.Fader);
};
f.IsNeverShow = () => OptionsStorage.Osd.NeverShowElements.Contains(StripElements.Fader);
}
}
}
45 changes: 38 additions & 7 deletions VoicemeeterOsdProgram/Factories/StripButtonFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public static class StripButtonFactory

public static ButtonContainer GetMono(IOsdRootElement parent)
{
var btnCont = GetCommonBtnCont(parent);
btnCont.IsAlwaysVisible = () => OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.Mono);
var btnCont = GetCommonMono(parent);

var btn = btnCont.Btn;
btnCont.Btn.Style = (Style)btnCont.Resources["MonoBtnStyle"];
Expand All @@ -28,8 +27,7 @@ public static ButtonContainer GetMono(IOsdRootElement parent)

public static ButtonContainer GetMonoWithReverse(IOsdRootElement parent)
{
var btnCont = GetCommonBtnCont(parent);
btnCont.IsAlwaysVisible = () => OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.Mono);
var btnCont = GetCommonMono(parent);

var btn = btnCont.Btn;
btn.Style = (Style)btnCont.Resources["MonoReverseBtnStyle"];
Expand All @@ -46,15 +44,25 @@ public static ButtonContainer GetMonoWithReverse(IOsdRootElement parent)
public static ButtonContainer GetSolo(IOsdRootElement parent)
{
var btnCont = GetCommonBtnCont(parent);
btnCont.IsAlwaysVisible = () => OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.Solo);
btnCont.IsAlwaysVisible = () =>
{
return !btnCont.IsNeverShow() &&
OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.Solo);
};
btnCont.IsNeverShow = () => OptionsStorage.Osd.NeverShowElements.Contains(StripElements.Solo);
btnCont.Btn.Style = (Style)btnCont.Resources["SoloBtnStyle"];
return btnCont;
}

public static ButtonContainer GetMute(IOsdRootElement parent)
{
var btnCont = GetCommonBtnCont(parent);
btnCont.IsAlwaysVisible = () => OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.Mute);
btnCont.IsAlwaysVisible = () =>
{
return !btnCont.IsNeverShow() &&
OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.Mute);
};
btnCont.IsNeverShow = () => OptionsStorage.Osd.NeverShowElements.Contains(StripElements.Mute);

var btn = btnCont.Btn;
btn.Style = (Style)btnCont.Resources["MuteBtnStyle"];
Expand All @@ -79,14 +87,25 @@ public static ButtonContainer GetSel(IOsdRootElement parent)
public static ButtonContainer GetBusSelect(IOsdRootElement parent, string name)
{
var btnCont = GetCommonBtnCont(parent);
btnCont.IsAlwaysVisible = () =>
{
return !btnCont.IsNeverShow() &&
OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.Buses);
};
btnCont.IsNeverShow = () => OptionsStorage.Osd.NeverShowElements.Contains(StripElements.Buses);
btnCont.Btn.Content = name;
return btnCont;
}

public static ButtonContainer GetEqOn(IOsdRootElement parent)
{
var btnCont = GetCommonBtnCont(parent);
btnCont.IsAlwaysVisible = () => OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.EQ);
btnCont.IsAlwaysVisible = () =>
{
return !btnCont.IsNeverShow() &&
OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.EQ);
};
btnCont.IsNeverShow = () => OptionsStorage.Osd.NeverShowElements.Contains(StripElements.EQ);
var btn = btnCont.Btn;
btn.Content = "EQ";
btn.Style = (Style)btnCont.Resources["EqOnBtnStyle"];
Expand All @@ -99,5 +118,17 @@ private static ButtonContainer GetCommonBtnCont(IOsdRootElement parent)
btnCont.OsdParent = parent;
return btnCont;
}

private static ButtonContainer GetCommonMono(IOsdRootElement parent)
{
var btnCont = GetCommonBtnCont(parent);
btnCont.IsAlwaysVisible = () =>
{
return !btnCont.IsNeverShow() &&
OptionsStorage.Osd.AlwaysShowElements.Contains(StripElements.Mono);
};
btnCont.IsNeverShow = () => OptionsStorage.Osd.NeverShowElements.Contains(StripElements.Mono);
return btnCont;
}
}
}
1 change: 1 addition & 0 deletions VoicemeeterOsdProgram/Types/IOsdRootElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public interface IOsdRootElement
{
public bool HasChangesFlag { get; set; }
public bool HasAnyChildVisibleFlag { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using VoicemeeterOsdProgram.Core.Types;
using System.Windows;

namespace VoicemeeterOsdProgram.UiControls.OSD.Strip
{
partial class ButtonContainer
{
public Func<bool> IsAlwaysVisible = () => false;
public Func<bool> IsNeverShow = () => false;

private VoicemeeterNumParam m_vmParam;

Expand All @@ -27,23 +29,31 @@ public VoicemeeterNumParam VmParameter

m_vmParam = value;
m_vmParam.ReadValueChanged += OnVmValueChanged;
Btn.Click += OnBtnClick; ;
Btn.Click += OnBtnClick;
}
}

private void OnVmValueChanged(object sender, ValOldNew<float> e)
{
if (OsdParent is not null)
bool hasOsdParent = OsdParent is not null;
if (hasOsdParent)
{
OsdParent.HasChangesFlag = true;
}

Highlight();
Visibility = System.Windows.Visibility.Visible;
if (!IsNeverShow())
{
Highlight();
Visibility = Visibility.Visible;
if (hasOsdParent)
{
OsdParent.HasAnyChildVisibleFlag = true;
}
}
Btn.State = (uint)e.newVal;
}

private void OnBtnClick(object sender, System.Windows.RoutedEventArgs e)
private void OnBtnClick(object sender, RoutedEventArgs e)
{
if (sender is not OutlineTglBtn btn) return;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using VoicemeeterOsdProgram.Core.Types;
using System.Windows;

namespace VoicemeeterOsdProgram.UiControls.OSD.Strip
{
Expand Down Expand Up @@ -30,13 +31,21 @@ public VoicemeeterNumParam VmParameter

private void OnVmValueChanged(object sender, ValOldNew<float> e)
{
if (OsdParent is not null)
bool hasOsdParent = OsdParent is not null;
if (hasOsdParent)
{
OsdParent.HasChangesFlag = true;
}

Visibility = System.Windows.Visibility.Visible;
Highlight();
if (!IsNeverShow())
{
Visibility = Visibility.Visible;
Highlight();
if (hasOsdParent)
{
OsdParent.HasAnyChildVisibleFlag = true;
}
}

// To prevent triggering OnFaderValueChanged
Fader.isIgnoreValueChanged = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace VoicemeeterOsdProgram.UiControls.OSD.Strip
public partial class FaderContainer : ContentControl
{
public IOsdRootElement OsdParent;
public Func<bool> IsAlwaysVisible = () => false;
public Func<bool> IsNeverShow = () => false;

private DoubleAnimation m_highlightAnim = new()
{
Expand Down
20 changes: 19 additions & 1 deletion VoicemeeterOsdProgram/UiControls/OSD/Strip/StripControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace VoicemeeterOsdProgram.UiControls.OSD.Strip
public partial class StripControl : UserControl, IOsdRootElement
{
private bool m_hasChanges = false;
private bool m_hasChildVis = false;

private DoubleAnimation m_highlightAnim = new()
{
Expand All @@ -34,11 +35,28 @@ public bool HasChangesFlag
m_hasChanges = false;
return true;
}
return m_hasChanges;
return false;
}
set => m_hasChanges = value;
}

/// <summary>
/// Resets itself when read
/// </summary>
public bool HasAnyChildVisibleFlag
{
get
{
if (m_hasChildVis)
{
m_hasChildVis = false;
return true;
}
return false;
}
set => m_hasChildVis = value;
}

public StripControl()
{
InitializeComponent();
Expand Down

0 comments on commit 2f8ff66

Please sign in to comment.