Skip to content

Commit d6bc1ca

Browse files
committed
icons and utils
1 parent c7ddd3f commit d6bc1ca

21 files changed

+237
-121
lines changed

SimpleStateMachineNodeEditor/App.xaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@
4747
<!--#region Header-->
4848
<ResourceDictionary Source="Styles/MainWindow/ToolBar/ToolButtonTemplate.xaml"/>
4949
<ResourceDictionary Source="Styles/MainWindow/ToolBarTemplate.xaml"/>
50-
<ResourceDictionary Source="Styles/MainWindow/Header/StyleHeaderButton.xaml"/>
51-
<ResourceDictionary Source="Styles/MainWindow/Header/StyleHeaderButtonPath.xaml"/>
52-
<ResourceDictionary Source="Styles/MainWindow/Header/StyleHeaderButtonClosePath.xaml"/>
50+
<ResourceDictionary Source="Styles/MainWindow/Header/StyleHeaderButton.xaml"/>
51+
<ResourceDictionary Source="Styles/MainWindow/Header/StyleHeaderButtonClosePath.xaml"/>
5352
<!--#endregion Header-->
5453

5554
<!--#endregion MainWindow-->

SimpleStateMachineNodeEditor/Helpers/MyUtils.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
using System.Windows.Media;
33
using System;
44
using System.Collections.Generic;
5+
using System.Windows.Controls;
6+
using SimpleStateMachineNodeEditor.Helpers.Enums;
7+
using System.Windows.Media.Imaging;
8+
using System.IO;
59

610
namespace SimpleStateMachineNodeEditor.Helpers
711
{
@@ -24,7 +28,26 @@ public static TParent FindParent<TParent>(DependencyObject currentObject) where
2428

2529
return result;
2630
}
31+
public static TParent FindChild<TParent>(DependencyObject currentObject) where TParent : DependencyObject
32+
{
33+
TParent child = default(TParent);
2734

35+
int numVisuals = VisualTreeHelper.GetChildrenCount(currentObject);
36+
for (int i = 0; i < numVisuals; i++)
37+
{
38+
Visual v = (Visual)VisualTreeHelper.GetChild(currentObject, i);
39+
child = v as TParent;
40+
if (child == null)
41+
{
42+
child = FindChild<TParent>(v);
43+
}
44+
if (child != null)
45+
{
46+
break;
47+
}
48+
}
49+
return child;
50+
}
2851
public static void FindParents<TParent1, TParent2>(DependencyObject currentObject, out TParent1 parent1, out TParent2 parent2) where TParent1 : DependencyObject where TParent2 : DependencyObject
2952
{
3053
DependencyObject foundObject = currentObject;
@@ -54,6 +77,41 @@ public static void FindParents<TParent1, TParent2>(DependencyObject currentObjec
5477
} while ((parent1 == default(TParent1)) || (parent2 == default(TParent2)));
5578
}
5679

80+
public static void PanelToImage(Panel panel, string filename, ImageFormats format)
81+
{
82+
int width = (int)panel.ActualWidth;
83+
int height = (int)panel.ActualHeight;
84+
85+
var pSource = PresentationSource.FromVisual(Application.Current.MainWindow);
86+
Matrix m = pSource.CompositionTarget.TransformToDevice;
87+
double dpiX = m.M11 * 96;
88+
double dpiY = m.M22 * 96;
89+
90+
RenderTargetBitmap renderBitmap = new RenderTargetBitmap(width, height, dpiX, dpiY, PixelFormats.Default);
91+
92+
//var crop = new CroppedBitmap(renderBitmap, new Int32Rect(50, 50, 250, 250));
93+
// needed otherwise the image output is black
94+
//this.Canvas.Measure(new Size(width, height));
95+
//this.Canvas.Arrange(new Rect(new Size(width, height)));
96+
97+
renderBitmap.Render(panel);
98+
BitmapEncoder encoder;
99+
100+
if (format == ImageFormats.JPEG)
101+
encoder = new JpegBitmapEncoder();
102+
else
103+
encoder = new PngBitmapEncoder();
104+
105+
encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
106+
107+
using (FileStream file = File.Create(filename))
108+
{
109+
encoder.Save(file);
110+
file.Flush();
111+
file.Close();
112+
}
113+
}
114+
57115
public static bool CheckIntersectTwoRectangles(MyPoint a1, MyPoint a2, MyPoint b1, MyPoint b2)
58116
{
59117
bool par1 = a1.X > b2.X; //second before first

SimpleStateMachineNodeEditor/Icons/CollapseUp.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
<DrawingBrush.Drawing>
55
<DrawingGroup>
66
<DrawingGroup.Children>
7-
<GeometryDrawing Brush="#00FFFFFF" Geometry="F1M16,16L0,16 0,0 16,0z" />
8-
<GeometryDrawing Brush="#FFF6F6F6" Geometry="F1M8.0879,3.6289L13.0699,8.6159 10.7579,10.9299 8.0289,8.1969 5.0639,10.8969 2.7569,8.5909z" />
9-
<GeometryDrawing Brush="#FF424242" Geometry="F1M10.7588,9.5146L11.6558,8.6166 8.0628,5.0186 4.1968,8.6166 5.0958,9.5146 8.0628,6.8156z" />
7+
<GeometryDrawing Brush="#00FFFFFF" Geometry="M8,4L13,9 14,8 8,2 2,8 3,9z" />
8+
<GeometryDrawing Brush="#7ac0ff" Geometry="F1M8,8L13,13 14,12 8,6 2,12 3,13z " />
9+
1010
</DrawingGroup.Children>
1111
</DrawingGroup>
1212
</DrawingBrush.Drawing>

SimpleStateMachineNodeEditor/Icons/Error.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<DrawingBrush.Drawing>
55
<DrawingGroup>
66
<DrawingGroup.Children>
7-
<GeometryDrawing Brush="#00FFFFFF" Geometry="F1M16,16L0,16 0,0 16,0z" />
87
<GeometryDrawing Brush="#FFF6F6F6" Geometry="F1M2,8C2,4.687 4.687,2 8,2 11.313,2 14,4.687 14,8 14,11.313 11.313,14 8,14 4.687,14 2,11.313 2,8" />
98
<GeometryDrawing Brush="#FFE51300" Geometry="F1M11,10L10,11 8,9 6,11 5,10 7,7.972 5,6 6,5 8,7 10,5 11,6 9,7.972z M8,3C5.238,3 3,5.238 3,8 3,10.762 5.238,13 8,13 10.762,13 13,10.762 13,8 13,5.238 10.762,3 8,3" />
109
<GeometryDrawing Brush="#FFFFFFFF" Geometry="F1M9,7.9722L11,10.0002 10,11.0002 8,9.0002 6,11.0002 5,10.0002 7,7.9722 5,6.0002 6,5.0002 8,7.0002 10,5.0002 11,6.0002z" />
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
3+
<DrawingBrush x:Key="IconExit" >
4+
<DrawingBrush.Drawing>
5+
<DrawingGroup>
6+
<DrawingGroup.Children>
7+
<GeometryDrawing Brush="#FFA1260D" Geometry="F1M12,11L10,11 8,8.999 6,11 4,11 7,7.999 4,4.999 6,4.999 8,6.999 10,4.999 12,4.999 9,7.999z M2,13L14,13 14,2.999 2,2.999z" />
8+
</DrawingGroup.Children>
9+
</DrawingGroup>
10+
</DrawingBrush.Drawing>
11+
</DrawingBrush>
12+
</ResourceDictionary>

SimpleStateMachineNodeEditor/Icons/ExpandDown.xaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
<DrawingBrush.Drawing>
55
<DrawingGroup>
66
<DrawingGroup.Children>
7-
<GeometryDrawing Brush="#00FFFFFF" Geometry="F1M16,16L0,16 0,0 16,0z" />
8-
<GeometryDrawing Brush="#FFF6F6F6" Geometry="F1M8.0001,8.5561L3.0301,3.5861 0.555099999999999,6.0601 8.0001,13.5051 15.4441,6.0601 12.9701,3.5861z" />
9-
<GeometryDrawing Brush="#FF424242" Geometry="F1M14.0303,6.0605L8.0003,12.0905 1.9693,6.0605 3.0303,4.9995 8.0003,9.9695 12.9693,4.9995z" />
7+
<GeometryDrawing Brush="#00FFFFFF" Geometry="M3,6L2,7 8,13 14,7 13,6 8,11z" />
8+
<GeometryDrawing Brush="#7ac0ff" Geometry="F1M3,2L2,3 8,9 14,3 13,2 8,7z" />
109
</DrawingGroup.Children>
1110
</DrawingGroup>
1211
</DrawingBrush.Drawing>

SimpleStateMachineNodeEditor/Icons/Icons.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<ResourceDictionary Source="Restore.xaml"/>
1717
<ResourceDictionary Source="Minimize.xaml"/>
1818
<ResourceDictionary Source="Maximize.xaml"/>
19+
<ResourceDictionary Source="Exit.xaml"/>
1920
<ResourceDictionary Source="SelectAll.xaml"/>
2021
<ResourceDictionary Source="Loop.xaml"/>
2122
<ResourceDictionary Source="Close.xaml"/>

SimpleStateMachineNodeEditor/Icons/Loop.xaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3-
xmlns:local="clr-namespace:SimpleStateMachineNodeEditor.Icons">
3+
xmlns:local="clr-namespace:SimpleStateMachineNodeEditor.Icons"
4+
xmlns:theme="clr-namespace:SimpleStateMachineNodeEditor.Styles.Themes">
45
<DrawingBrush x:Key="IconLoop" TileMode="Tile">
56
<DrawingBrush.Drawing>
6-
<GeometryDrawing Brush="{StaticResource ColorConnector}" >
7+
<GeometryDrawing Brush="{DynamicResource ColorConnector}" >
78
<GeometryDrawing.Geometry >
89
<PathGeometry Figures="M515.216,32.2104 C 471.039,64.9407 316.749,210.919 285,241.156 354.528,309.155 476.402,421.505 519.933,456.569 529.209,459.558 539.111,457.671 546.19,451.542 555.782,443.051 556.092,441.322 556.092,390.691 L 556.092,345.094 623.066,352.167 C 685.164,363.02 743.338,384.245 783.587,410.973 803.716,424.34 824.621,444.779 836.101,462.072 880.591,529.527 843.806,607.354 743.497,657.827 729.504,664.899 727.459,667.262 727.459,676.538 727.459,685.029 733.429,691 741.919,691 753.399,691 811.097,665.843 844.894,646.188 927.43,597.919 979,534.238 990.947,466.004 994.562,444.938 993.302,412.543 987.959,392.261 955.415,268.204 795.052,169.621 581.556,142.267 L 556.877,139.119 C 556.409,139.119 556.092,119.148 556.092,94.7828 556.092,52.9599 555.933,50.1294 552.794,43.6835 546.348,30.4748 528.265,24.9723 515.216,32.2104 Z" FillRule="Nonzero" >
910
<PathGeometry.Transform>

SimpleStateMachineNodeEditor/Icons/Maximize.xaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
<DrawingBrush x:Key="IconMaximize" >
44
<DrawingBrush.Drawing>
55
<DrawingGroup>
6-
<DrawingGroup.Children>
7-
<!--<GeometryDrawing Brush="#00FFFFFF" Geometry="F1M16,16L0,16 0,0 16,0z" />-->
8-
<GeometryDrawing Brush="LightGray" Geometry="F1M12,12L4,12 4,4 12,4z M3,13L13,13 13,3 3,3z" />
6+
<DrawingGroup.Children>
7+
<GeometryDrawing Brush="LightGray" Geometry="F1M12,12L4,12 4,4 12,4z M3,13L13,13 13,3 3,3z" />
98
</DrawingGroup.Children>
109
</DrawingGroup>
1110
</DrawingBrush.Drawing>

SimpleStateMachineNodeEditor/Icons/Test.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
mc:Ignorable="d"
88
d:DesignHeight="450" d:DesignWidth="800">
99

10-
<Path Data="M9,9v6h6V9H12.3V7h-1V9Zm5,5H10V11h4ZM9,1V5H7V3H1V9H2V5H6V8H2V9H7V6H9V7h6V1Zm5,5H10V3h4Z " Fill="Yellow" />
10+
<Path Data="M15 7V1H9v1H4v3H1v6h3v3h5v1h6V9H9v4H5v-2h2V5H5V3h4v4h6zm-5-4h4v3h-4V3zm0 8h4v3h-4v-3zM6 7v3H2V7h4z" Fill="LightGray" />
1111

1212
<!--M5.8,15l-1.1-2.6L3,14.2V7l5.4,5H5.9L7,14.5L5.8,15z-->
1313
<!--<Viewbox Width="16" Height="16" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">

0 commit comments

Comments
 (0)