Skip to content

Commit

Permalink
Input and output can now be offset for better positioning control
Browse files Browse the repository at this point in the history
  • Loading branch information
KeithSwanger committed Aug 5, 2020
1 parent a43d236 commit 77cc34e
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 9 deletions.
8 changes: 8 additions & 0 deletions PathMarkupGenerator/PathMarkupGenerator/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
<TextBox Text="{Binding ReferenceWidth, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="50" Padding="3" VerticalContentAlignment="Center"/>
<TextBlock Text="Input Height: " VerticalAlignment="Center" Margin="10,0,0,0"/>
<TextBox Text="{Binding ReferenceHeight, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="50" Padding="3" VerticalContentAlignment="Center"/>
<TextBlock Text="Input Width Offset: " VerticalAlignment="Center" Margin="10,0,0,0"/>
<TextBox Text="{Binding WidthOffset, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="50" Padding="3" VerticalContentAlignment="Center"/>
<TextBlock Text="Input Height Offset: " VerticalAlignment="Center" Margin="10,0,0,0"/>
<TextBox Text="{Binding HeightOffset, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="50" Padding="3" VerticalContentAlignment="Center"/>
</StackPanel>
</StackPanel>
<TextBlock Grid.Row="2" Text="Path Data Input" FontWeight="Bold"/>
Expand All @@ -45,6 +49,10 @@
<TextBox Text="{Binding TargetWidth, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="50" Padding="3" VerticalContentAlignment="Center"/>
<TextBlock Text="Target Height: " VerticalAlignment="Center" Margin="10,0,0,0"/>
<TextBox Text="{Binding TargetHeight, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="50" Padding="3" VerticalContentAlignment="Center"/>
<TextBlock Text="Output Width Offset: " VerticalAlignment="Center" Margin="10,0,0,0"/>
<TextBox Text="{Binding WidthOutputOffset, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="50" Padding="3" VerticalContentAlignment="Center"/>
<TextBlock Text="Output Height Offset: " VerticalAlignment="Center" Margin="10,0,0,0"/>
<TextBox Text="{Binding HeightOutputOffset, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="50" Padding="3" VerticalContentAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button Click="Button_Click_Generate" Content="Generate" FontWeight="Bold" Width="314" HorizontalAlignment="Left"/>
Expand Down
62 changes: 59 additions & 3 deletions PathMarkupGenerator/PathMarkupGenerator/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,62 @@ public string ReferenceHeight
}
}

private string _widthOffset = "0";
public string WidthOffset
{
get
{
return _widthOffset;
}
set
{
_widthOffset = value;
OnPropertyChanged();
}
}

private string _heightOffset = "0";
public string HeightOffset
{
get
{
return _heightOffset;
}
set
{
_heightOffset = value;
OnPropertyChanged();
}
}

private string _widthOutputOffset = "0";
public string WidthOutputOffset
{
get
{
return _widthOutputOffset;
}
set
{
_widthOutputOffset = value;
OnPropertyChanged();
}
}

private string _heightOutputOffset = "0";
public string HeightOutputOffset
{
get
{
return _heightOutputOffset;
}
set
{
_heightOutputOffset = value;
OnPropertyChanged();
}
}

private string _targetWidth;
public string TargetWidth
{
Expand Down Expand Up @@ -165,9 +221,9 @@ protected void OnPropertyChanged([CallerMemberName] string name = null)
public void GenerateOutput()
{

if (Int32.TryParse(ReferenceWidth, out int refW) && Int32.TryParse(ReferenceHeight, out int refH) && Int32.TryParse(TargetWidth, out int tarW) && Int32.TryParse(TargetHeight, out int tarH))
if (Int32.TryParse(ReferenceWidth, out int refW) && Int32.TryParse(ReferenceHeight, out int refH) && Single.TryParse(WidthOffset, out float offW) && Single.TryParse(HeightOffset, out float offH) && Int32.TryParse(TargetWidth, out int tarW) && Int32.TryParse(TargetHeight, out int tarH) && Single.TryParse(WidthOutputOffset, out float outOffW) && Single.TryParse(HeightOutputOffset, out float outOffH))
{
OutputData = PathConverter.ResizePathData(refW, refH, tarW, tarH, InputData);
OutputData = PathConverter.ResizePathData(refW, refH, offW, offH, tarW, tarH, outOffW, outOffH, InputData);
}
}

Expand All @@ -177,7 +233,7 @@ private void Button_Click_Generate(object sender, RoutedEventArgs e)
}
private void Button_Click_Preview(object sender, RoutedEventArgs e)
{
if (Int32.TryParse(ReferenceWidth, out int refW) && Int32.TryParse(ReferenceHeight, out int refH) && Int32.TryParse(TargetWidth, out int tarW) && Int32.TryParse(TargetHeight, out int tarH))
if (Int32.TryParse(ReferenceWidth, out int refW) && Int32.TryParse(ReferenceHeight, out int refH) && Single.TryParse(WidthOffset, out float offW) && Single.TryParse(HeightOffset, out float offH) && Int32.TryParse(TargetWidth, out int tarW) && Int32.TryParse(TargetHeight, out int tarH) && Single.TryParse(WidthOffset, out float outOffW) && Single.TryParse(HeightOffset, out float outOffH))
{
ShowPreview();
}
Expand Down
18 changes: 12 additions & 6 deletions PathMarkupGenerator/PathMarkupGenerator/PathConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ public static class PathConverter
{


public static string ResizePathData(float refW, float refH, float targetW, float targetH, string data)
public static string ResizePathData(float refW, float refH, float inputOffsetW, float inputOffsetH, float targetW, float targetH, float outputOffsetW, float outputOffsetH, string data)
{
string[] parsedData = ParseString(data);
List<string> finalProcessedData = new List<string>();

Vector2 lastPosition = new Vector2(0f, 0f);
Vector2 lastPosition = new Vector2(0f + inputOffsetW, 0f + inputOffsetH);
for (int i = 0; i < parsedData.Length; i++)
{
string d = parsedData[i];
Expand All @@ -31,7 +31,7 @@ public static string ResizePathData(float refW, float refH, float targetW, float
while (j < parsedData.Length && parsedData[j].Contains(","))
{
string[] splitPos = parsedData[j].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
Vector2 pos = new Vector2(float.Parse(splitPos[0]), float.Parse(splitPos[1]));
Vector2 pos = new Vector2(float.Parse(splitPos[0]) + inputOffsetW, float.Parse(splitPos[1]) + inputOffsetH);

// if lower case is used, then this is a relative position, so offset the last position
if (char.IsLower(d[0]))
Expand All @@ -41,6 +41,8 @@ public static string ResizePathData(float refW, float refH, float targetW, float
}

Vector2 mappedPos = MapPointToTarget(refW, refH, targetW, targetH, pos);
mappedPos.x += outputOffsetW;
mappedPos.y += outputOffsetH;

finalProcessedData.Add(mappedPos.ToString());

Expand All @@ -55,13 +57,14 @@ public static string ResizePathData(float refW, float refH, float targetW, float

int j = i + 1;

Vector2 pos = new Vector2(float.Parse(parsedData[j]), lastPosition.y);
Vector2 pos = new Vector2(float.Parse(parsedData[j]) + inputOffsetW, lastPosition.y);
if (char.IsLower(d[0]))
{
pos.x += lastPosition.x;
}

Vector2 mappedPos = MapPointToTarget(refW, refH, targetW, targetH, pos);
mappedPos.x += outputOffsetW;

finalProcessedData.Add(mappedPos.x.ToString());

Expand All @@ -73,13 +76,14 @@ public static string ResizePathData(float refW, float refH, float targetW, float

int j = i + 1;

Vector2 pos = new Vector2(lastPosition.x, float.Parse(parsedData[j]));
Vector2 pos = new Vector2(lastPosition.x, float.Parse(parsedData[j]) + inputOffsetH);
if (char.IsLower(d[0]))
{
pos.y += lastPosition.y;
}

Vector2 mappedPos = MapPointToTarget(refW, refH, targetW, targetH, pos);
mappedPos.y += outputOffsetH;

finalProcessedData.Add(mappedPos.y.ToString());

Expand Down Expand Up @@ -113,7 +117,7 @@ public static string ResizePathData(float refW, float refH, float targetW, float

// End Point
splitPos = parsedData[j].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
pos = new Vector2(float.Parse(splitPos[0]), float.Parse(splitPos[1]));
pos = new Vector2(float.Parse(splitPos[0]) + inputOffsetW, float.Parse(splitPos[1]) + inputOffsetH);

if (char.IsLower(d[0]))
{
Expand All @@ -122,6 +126,8 @@ public static string ResizePathData(float refW, float refH, float targetW, float
}

mappedPos = MapPointToTarget(refW, refH, targetW, targetH, pos);
mappedPos.x += outputOffsetW;
mappedPos.y += outputOffsetH;

finalProcessedData.Add(mappedPos.ToString());

Expand Down
2 changes: 2 additions & 0 deletions PathMarkupGenerator/PathMarkupGenerator/ShapePreset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class ShapePreset
public string Name { get; set; }
public int ReferenceWidth { get; set; }
public int ReferenceHeight { get; set; }
public int WidthOffset { get; set; } = 0;
public int HeightOffset { get; set; } = 0;
public string PathData { get; set; }
}

Expand Down
14 changes: 14 additions & 0 deletions PathMarkupGenerator/PathMarkupGenerator/ShapePresets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,27 @@ static ShapePresets()
PathData = "M 0,0 L 100,0 100,100 0,100 Z"
},
new ShapePreset()
{
Name = "Check-Bold (Michael Richins)",
ReferenceWidth = 24,
ReferenceHeight = 24,
PathData = "M 9,20.42 L 2.79,14.21 L 5.62,11.38 L 9,14.77 L 18.88,4.88 L 21.71,7.71 L 9,20.42 Z"
},
new ShapePreset()
{
Name = "Material Design Gear",
ReferenceWidth = 24,
ReferenceHeight = 24,
PathData = "M 12,15.5 A 3.5,3.5 0 0 1 8.5,12 A 3.5,3.5 0 0 1 12,8.5 A 3.5,3.5 0 0 1 15.5,12 A 3.5,3.5 0 0 1 12,15.5 M 19.43,12.97 C 19.47,12.65 19.5,12.33 19.5,12 C 19.5,11.67 19.47,11.34 19.43,11 L 21.54,9.37 C 21.73,9.22 21.78,8.95 21.66,8.73 L 19.66,5.27 C 19.54,5.05 19.27,4.96 19.05,5.05 L 16.56,6.05 C 16.04,5.66 15.5,5.32 14.87,5.07 L 14.5,2.42 C 14.46,2.18 14.25,2 14,2 H 10 C 9.75,2 9.54,2.18 9.5,2.42 L 9.13,5.07 C 8.5,5.32 7.96,5.66 7.44,6.05 L 4.95,5.05 C 4.73,4.96 4.46,5.05 4.34,5.27 L 2.34,8.73 C 2.21,8.95 2.27,9.22 2.46,9.37 L 4.57,11 C 4.53,11.34 4.5,11.67 4.5,12 C 4.5,12.33 4.53,12.65 4.57,12.97 L 2.46,14.63 C 2.27,14.78 2.21,15.05 2.34,15.27 L 4.34,18.73 C 4.46,18.95 4.73,19.03 4.95,18.95 L 7.44,17.94 C 7.96,18.34 8.5,18.68 9.13,18.93 L 9.5,21.58 C 9.54,21.82 9.75,22 10,22 H 14 C 14.25,22 14.46,21.82 14.5,21.58 L 14.87,18.93 C 15.5,18.67 16.04,18.34 16.56,17.94 L 19.05,18.95 C 19.27,19.03 19.54,18.95 19.66,18.73 L 21.66,15.27 C 21.78,15.05 21.73,14.78 21.54,14.63 L 19.43,12.97 Z"
},
new ShapePreset()
{
Name = "Material Design Gear (Small Margin)",
ReferenceWidth = 22,
ReferenceHeight = 22,
PathData = "M 11,14.5 A 3.5,3.5 0 0 1 7.5,11 A 3.5,3.5 0 0 1 11,7.5 A 3.5,3.5 0 0 1 14.5,11 A 3.5,3.5 0 0 1 11,14.5 M 18.43,11.97 C 18.47,11.65 18.5,11.33 18.5,11 C 18.5,10.67 18.47,10.34 18.43,10 L 20.54,8.37 C 20.73,8.22 20.78,7.95 20.66,7.73 L 18.66,4.27 C 18.54,4.05 18.27,3.96 18.05,4.05 L 15.56,5.05 C 15.04,4.66 14.5,4.32 13.87,4.07 L 13.5,1.42 C 13.46,1.18 13.25,1 13,1 H 9 C 8.75,1 8.54,1.18 8.5,1.42 L 8.13,4.07 C 7.5,4.32 6.96,4.66 6.44,5.05 L 3.95,4.05 C 3.73,3.96 3.46,4.05 3.34,4.27 L 1.34,7.73 C 1.21,7.95 1.27,8.22 1.46,8.37 L 3.57,10 C 3.53,10.34 3.5,10.67 3.5,11 C 3.5,11.33 3.53,11.65 3.57,11.97 L 1.46,13.63 C 1.27,13.78 1.21,14.05 1.34,14.27 L 3.34,17.73 C 3.46,17.95 3.73,18.03 3.95,17.95 L 6.44,16.94 C 6.96,17.34 7.5,17.68 8.13,17.93 L 8.5,20.58 C 8.54,20.82 8.75,21 9,21 H 13 C 13.25,21 13.46,20.82 13.5,20.58 L 13.87,17.93 C 14.5,17.67 15.04,17.34 15.56,16.94 L 18.05,17.95 C 18.27,18.03 18.54,17.95 18.66,17.73 L 20.66,14.27 C 20.78,14.05 20.73,13.78 20.54,13.63 L 18.43,11.97 Z"
},
new ShapePreset()
{
Name = "Material Design Play",
ReferenceWidth = 112,
Expand Down

0 comments on commit 77cc34e

Please sign in to comment.