Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alphanumeric Padding #472

Merged
merged 4 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions LibDmd/DmdDevice/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,12 @@ public VirtualAlphaNumericDisplayConfig(IniData data, Configuration parent) : ba
case "skewangle":
_styles[styleName].SkewAngle = -(float)GetDouble(keyValues.Current.KeyName, 0);
break;
case "linepad":
_styles[styleName].LinePad = (float)GetDouble(keyValues.Current.KeyName, 0);
break;
case "outerpad":
_styles[styleName].OuterPad = (float)GetDouble(keyValues.Current.KeyName, 0);
break;
case "weight":
_styles[styleName].SegmentWeight = GetEnum(keyValues.Current.KeyName, SegmentWeight.Thin);
break;
Expand Down Expand Up @@ -694,6 +700,8 @@ public void SetStyle(string name, RasterizeStyleDefinition style)
DoWrite = false;

Set(prefix + "skewangle", -style.SkewAngle);
Set(prefix + "linepad", style.LinePad);
Set(prefix + "outerpad", style.OuterPad);
Set(prefix + "weight", style.SegmentWeight);
Set(prefix + "backgroundcolor", style.BackgroundColor);
SetLayerStyle(name, "foreground", style.Foreground);
Expand All @@ -712,6 +720,8 @@ public void RemoveStyle(string name)
DoWrite = false;
Remove("style");
Remove(prefix + "skewangle");
Remove(prefix + "linepad");
Remove(prefix + "outerpad");
Remove(prefix + "backgroundcolor");
RemoveLayerStyle(name, "foreground");
RemoveLayerStyle(name, "innerglow");
Expand Down
30 changes: 21 additions & 9 deletions LibDmd/Output/Virtual/AlphaNumeric/AlphaNumericSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image x:Name="Preview" Height="108" Width="453" Grid.Row="0" />

Expand All @@ -45,11 +47,21 @@
<TextBox x:Name="SkewAngleValue" Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Center" Width="30"/>


<alphaNumeric:VirtualAlphaNumericLayerSetting Grid.Row="3" x:Name="ForegroundStyle" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,8,0,8"/>
<alphaNumeric:VirtualAlphaNumericLayerSetting Grid.Row="4" x:Name="InnerGlowStyle" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,0,0,8"/>
<alphaNumeric:VirtualAlphaNumericLayerSetting Grid.Row="5" x:Name="OuterGlowStyle" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,0,0,8"/>
<alphaNumeric:VirtualAlphaNumericLayerSetting Grid.Row="6" x:Name="BackgroundStyle" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,0,0,8"/>
<GroupBox x:Name="SaveGroup" Grid.Row="7" Header="Load, save and delete from DmdDevice.ini" Padding="8,0,8,8" Margin="0,0,0,16">
<Label Grid.Row="3" Content="Line Padding Percentage" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,190,0"/>
<Slider x:Name="LinePadSlider" Grid.Row="3" HorizontalAlignment="Right" VerticalAlignment="Center" Width="150" Maximum="30" Margin="0,0,38,0" SmallChange="1"/>
<TextBox x:Name="LinePadValue" Grid.Row="3" HorizontalAlignment="Right" VerticalAlignment="Center" Width="30"/>


<Label Grid.Row="4" Content="Outer Padding Percentage" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,190,0"/>
<Slider x:Name="OuterPadSlider" Grid.Row="4" HorizontalAlignment="Right" VerticalAlignment="Center" Width="150" Maximum="30" Margin="0,0,38,0" SmallChange="1"/>
<TextBox x:Name="OuterPadValue" Grid.Row="4" HorizontalAlignment="Right" VerticalAlignment="Center" Width="30"/>


<alphaNumeric:VirtualAlphaNumericLayerSetting Grid.Row="5" x:Name="ForegroundStyle" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,8,0,8"/>
<alphaNumeric:VirtualAlphaNumericLayerSetting Grid.Row="6" x:Name="InnerGlowStyle" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,0,0,8"/>
<alphaNumeric:VirtualAlphaNumericLayerSetting Grid.Row="7" x:Name="OuterGlowStyle" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,0,0,8"/>
<alphaNumeric:VirtualAlphaNumericLayerSetting Grid.Row="8" x:Name="BackgroundStyle" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,0,0,8"/>
<GroupBox x:Name="SaveGroup" Grid.Row="9" Header="Load, save and delete from DmdDevice.ini" Padding="8,0,8,8" Margin="0,0,0,16">
<Grid>
<ComboBox ItemsSource="{Binding StyleNames}" SelectedValue="{Binding NewStyleName, Mode=TwoWay}" IsSynchronizedWithCurrentItem="True" x:Name="StyleNameComboBox" Width="220" HorizontalAlignment="Left" Margin="0,8,0,0" IsEditable="True"/>
<Button x:Name="LoadStyleButton" Width="60" HorizontalAlignment="Right" VerticalAlignment="Center" Height="24" Margin="0,7,136,0" Content="Load" Click="LoadFromIniClicked"/>
Expand All @@ -58,8 +70,8 @@
</Grid>
</GroupBox>

<Button x:Name="ApplyButton" Content="Apply" Grid.Row="8" HorizontalAlignment="Right" VerticalAlignment="Top" Width="60" Height="24" IsDefault="True" Click="ApplyClicked"/>
<Button Content="Close" Grid.Row="8" HorizontalAlignment="Right" VerticalAlignment="Top" Width="60" Height="24" Margin="0,0,68,0" IsCancel="True" Click="CancelClicked"/>
<Button Content="Reset" Grid.Row="8" HorizontalAlignment="Left" VerticalAlignment="Top" Width="60" Height="24" Margin="0,0,68,0" IsCancel="True" Click="ResetClicked"/>
<Button x:Name="ApplyButton" Content="Apply" Grid.Row="10" HorizontalAlignment="Right" VerticalAlignment="Top" Width="60" Height="24" IsDefault="True" Click="ApplyClicked"/>
<Button Content="Close" Grid.Row="10" HorizontalAlignment="Right" VerticalAlignment="Top" Width="60" Height="24" Margin="0,0,68,0" IsCancel="True" Click="CancelClicked"/>
<Button Content="Reset" Grid.Row="10" HorizontalAlignment="Left" VerticalAlignment="Top" Width="60" Height="24" Margin="0,0,68,0" IsCancel="True" Click="ResetClicked"/>
</Grid>
</Window>
</Window>
26 changes: 24 additions & 2 deletions LibDmd/Output/Virtual/AlphaNumeric/AlphaNumericSettings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public VirtualAlphaNumericSettings(RasterizeStyleDefinition styleDefinition, dou
});
BackgroundStyle.OnLayerChanged.DistinctUntilChanged().Subscribe(layerStyle => {
_displaySetting.ApplyLayerStyle(RasterizeLayer.Background, layerStyle);
Res.RasterizeLayer(_displaySetting, RasterizeLayer.Background, layerStyle, _displaySetting.Style.Background, new [] { AlphaNumericResources.FullSegment }, _displaySetting.StyleDefinition.SkewAngle);
Res.RasterizeLayer(_displaySetting, RasterizeLayer.Background, layerStyle, _displaySetting.Style.Background, new[] { AlphaNumericResources.FullSegment }, _displaySetting.StyleDefinition.SkewAngle);
});

Res.Rasterize(_displaySetting, true);
Expand All @@ -110,23 +110,45 @@ private void SetupTriggers()
};
StyleNameComboBox.KeyUp += (sender, e) => StyleSelectionChanged(StyleNameComboBox.Text);


SkewAngleSlider.ValueChanged += (sender, e) => SkewAngleValue.Text = DoubleToString(SkewAngleSlider.Value);
SkewAngleValue.TextChanged += (sender, e) => SkewAngleSlider.Value = StringToDouble(SkewAngleValue.Text, SkewAngleSlider.Value);
SkewAngleSlider.ValueChanged += (sender, e) => _displaySetting.StyleDefinition.SkewAngle = -(float)SkewAngleSlider.Value;
SkewAngleSlider.ValueChanged += (sender, e) => RasterizeAll();

LinePadSlider.ValueChanged += (sender, e) => LinePadValue.Text = DoubleToString(LinePadSlider.Value);
LinePadValue.TextChanged += (sender, e) => LinePadSlider.Value = StringToDouble(LinePadValue.Text, LinePadSlider.Value);
LinePadSlider.ValueChanged += (sender, e) => {
_displaySetting.StyleDefinition.LinePad = (float)LinePadSlider.Value;
_displaySetting.SetDimensions((int)Preview.Width, (int)Preview.Height);
RasterizeAll();
};

OuterPadSlider.ValueChanged += (sender, e) => OuterPadValue.Text = DoubleToString(OuterPadSlider.Value);
OuterPadValue.TextChanged += (sender, e) => OuterPadSlider.Value = StringToDouble(OuterPadValue.Text, OuterPadSlider.Value);
OuterPadSlider.ValueChanged += (sender, e) => {
_displaySetting.StyleDefinition.OuterPad = (float)OuterPadSlider.Value;
_displaySetting.SetDimensions((int)Preview.Width, (int)Preview.Height);
RasterizeAll();
};

ThinWeight.Checked += (sender, e) => RasterizeAll();
BoldWeight.Checked += (sender, e) => RasterizeAll();
BackgroundColor.SelectedColorChanged += (sender, e) =>
_displaySetting.StyleDefinition.BackgroundColor = new SKColor(BackgroundColor.SelectedColor.Value.R,
BackgroundColor.SelectedColor.Value.G, BackgroundColor.SelectedColor.Value.B,
BackgroundColor.SelectedColor.Value.A);

}
}

private void UpdateControls()
{
SkewAngleValue.Text = (-_displaySetting.StyleDefinition.SkewAngle).ToString(CultureInfo.InvariantCulture);
SkewAngleSlider.Value = -_displaySetting.StyleDefinition.SkewAngle;
LinePadValue.Text = (_displaySetting.StyleDefinition.LinePad).ToString(CultureInfo.InvariantCulture);
LinePadSlider.Value = _displaySetting.StyleDefinition.LinePad;
OuterPadValue.Text = (_displaySetting.StyleDefinition.OuterPad).ToString(CultureInfo.InvariantCulture);
OuterPadSlider.Value = _displaySetting.StyleDefinition.OuterPad;
BackgroundColor.SelectedColor = _displaySetting.StyleDefinition.BackgroundColor.ToColor();
ThinWeight.IsChecked = _displaySetting.StyleDefinition.SegmentWeight == SegmentWeight.Thin;
BoldWeight.IsChecked = _displaySetting.StyleDefinition.SegmentWeight == SegmentWeight.Bold;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public AlphanumericControl()

public void Init()
{
ObservableExtensions.Subscribe(Host.WindowResized, pos => CreateImage((int)pos.Width, (int)pos.Height));
Host.WindowResized.Subscribe(pos => CreateImage((int)pos.Width, (int)pos.Height));
_stopwatch.Start();
}

Expand Down Expand Up @@ -128,6 +128,7 @@ public void RenderSegments(ushort[] data)
public void UpdateStyle(RasterizeStyleDefinition styleDef)
{
DisplaySetting.ApplyStyle(styleDef);
CreateImage((int)ActualWidth, (int)ActualHeight);
Res.Rasterize(DisplaySetting, true);
}

Expand Down
4 changes: 2 additions & 2 deletions LibDmd/Output/Virtual/AlphaNumeric/DisplaySetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public DisplaySetting(int display, SegmentType segmentType, RasterizeStyleDefini
/// <param name="canvasHeight">Height of the canvas in pixels</param>
public void SetDimensions(int canvasWidth, int canvasHeight)
{
Dim = new RasterizeDimensions(_res.GetSvgSize(SegmentType, StyleDefinition.SegmentWeight), canvasHeight, NumChars, NumLines, StyleDefinition.SkewAngle);
Dim = new RasterizeDimensions(_res.GetSvgSize(SegmentType, StyleDefinition.SegmentWeight), canvasHeight, NumChars, NumLines, StyleDefinition.SkewAngle, StyleDefinition.LinePad / 100.0f, StyleDefinition.OuterPad / 100.0f);
Style = StyleDefinition.Scale(Dim.SvgScale);
}

Expand Down Expand Up @@ -94,4 +94,4 @@ public void ApplyLayerStyle(RasterizeLayer layer, RasterizeLayerStyleDefinition
Style = StyleDefinition.Scale(Dim.SvgScale);
}
}
}
}
19 changes: 3 additions & 16 deletions LibDmd/Output/Virtual/AlphaNumeric/RasterizeDimensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,15 @@ public class RasterizeDimensions : IEquatable<RasterizeDimensions>
/// </summary>
public SKMatrix SvgMatrix;

/// <summary>
/// Line padding as percentage of the line height
/// </summary>
public float LinePaddingPercentage { get; set; } = 0.2f;

/// <summary>
/// Outer padding as percentage of the display height
/// </summary>
public float OuterPaddingPercentage { get; set; } = 0.2f;

/// <summary>
/// Segment padding as percentage of the segment's diagonal
/// </summary>
public float SegmentPaddingPercentage { get; set; } = 0.3f;

public RasterizeDimensions(SKRect svgSize, int canvasHeight, int numChars, int numLines, float skewAngle)
public RasterizeDimensions(SKRect svgSize, int canvasHeight, int numChars, int numLines, float skewAngle, float linePaddingPercentage, float outerPaddingPercentage)
{
OuterPadding = (int)Math.Round(OuterPaddingPercentage * canvasHeight);
OuterPadding = (int)Math.Round(outerPaddingPercentage * canvasHeight);
SvgHeight = canvasHeight - 2 * OuterPadding;
SvgScale = SvgHeight / svgSize.Height;
SvgWidth = svgSize.Width * SvgScale;
LinePadding = (int)Math.Round(SvgHeight * LinePaddingPercentage);
LinePadding = (int)Math.Round(SvgHeight * linePaddingPercentage);
SvgMatrix = SKMatrix.CreateScale(SvgScale, SvgScale);
var svgSkewedWidth = SkewedWidth(SvgWidth, SvgHeight, skewAngle);
SegmentPadding = (int)Math.Round(Math.Sqrt(SvgWidth * SvgWidth + SvgHeight * SvgHeight) * SegmentPaddingPercentage);
Expand Down
14 changes: 13 additions & 1 deletion LibDmd/Output/Virtual/AlphaNumeric/RasterizeStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ public class RasterizeStyleDefinition
/// </summary>
public float SkewAngle { get; set; } = -12;

/// <summary>
/// Line padding percentage
/// </summary>
public float LinePad { get; set; } = 0.2f;

/// <summary>
/// Outer padding percentage
/// </summary>
public float OuterPad { get; set; } = 0.2f;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're dividing those by 100 later, shouldn't they be 20 instead of 0.2?


/// <summary>
/// Segment weight
/// </summary>
Expand Down Expand Up @@ -93,6 +103,8 @@ public RasterizeStyleDefinition Copy()
return new RasterizeStyleDefinition {
SegmentWeight = SegmentWeight,
SkewAngle = SkewAngle,
LinePad = LinePad,
OuterPad = OuterPad,
BackgroundColor = new SKColor(BackgroundColor.Red, BackgroundColor.Green, BackgroundColor.Blue, BackgroundColor.Alpha),
Foreground = Foreground.Copy(),
InnerGlow = InnerGlow.Copy(),
Expand Down Expand Up @@ -129,4 +141,4 @@ public class RasterizeStyle
/// </summary>
public RasterizeLayerStyle Background { get; set; }
}
}
}