From 19bbef4cade8176aed9177262a0152abb1daf2f5 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 28 Jan 2020 19:51:43 +0100 Subject: [PATCH] Added rotating rotation cursors (think about that one for a sec!) --- src/Artemis.UI/Artemis.UI.csproj | 13 +++ .../Properties/Resources.Designer.cs | 40 ++++++++ src/Artemis.UI/Properties/Resources.resx | 12 +++ .../Resources/aero_rotate_bl_ico.ico | Bin 0 -> 1826 bytes .../Resources/aero_rotate_br_ico.ico | Bin 0 -> 1826 bytes .../Resources/aero_rotate_tl_ico.ico | Bin 0 -> 1826 bytes .../Resources/aero_rotate_tr_ico.ico | Bin 0 -> 1826 bytes .../Visualization/Tools/EditToolView.xaml | 8 +- .../Visualization/Tools/EditToolViewModel.cs | 14 ++- src/Artemis.UI/Utilities/CursorRotator.cs | 86 ++++++++++++++++++ 10 files changed, 168 insertions(+), 5 deletions(-) create mode 100644 src/Artemis.UI/Resources/aero_rotate_bl_ico.ico create mode 100644 src/Artemis.UI/Resources/aero_rotate_br_ico.ico create mode 100644 src/Artemis.UI/Resources/aero_rotate_tl_ico.ico create mode 100644 src/Artemis.UI/Resources/aero_rotate_tr_ico.ico create mode 100644 src/Artemis.UI/Utilities/CursorRotator.cs diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj index 481cff2a0..0837eb5af 100644 --- a/src/Artemis.UI/Artemis.UI.csproj +++ b/src/Artemis.UI/Artemis.UI.csproj @@ -224,6 +224,7 @@ + @@ -570,6 +571,18 @@ + + + + + + + + + + + + diff --git a/src/Artemis.UI/Properties/Resources.Designer.cs b/src/Artemis.UI/Properties/Resources.Designer.cs index 0b1cc4c0d..2c6653c37 100644 --- a/src/Artemis.UI/Properties/Resources.Designer.cs +++ b/src/Artemis.UI/Properties/Resources.Designer.cs @@ -150,6 +150,16 @@ namespace Artemis.UI.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// + internal static System.Drawing.Icon aero_rotate_bl_ico { + get { + object obj = ResourceManager.GetObject("aero_rotate_bl_ico", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + /// /// Looks up a localized resource of type System.Byte[]. /// @@ -160,6 +170,16 @@ namespace Artemis.UI.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// + internal static System.Drawing.Icon aero_rotate_br_ico { + get { + object obj = ResourceManager.GetObject("aero_rotate_br_ico", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + /// /// Looks up a localized resource of type System.Byte[]. /// @@ -170,6 +190,16 @@ namespace Artemis.UI.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// + internal static System.Drawing.Icon aero_rotate_tl_ico { + get { + object obj = ResourceManager.GetObject("aero_rotate_tl_ico", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + /// /// Looks up a localized resource of type System.Byte[]. /// @@ -180,6 +210,16 @@ namespace Artemis.UI.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// + internal static System.Drawing.Icon aero_rotate_tr_ico { + get { + object obj = ResourceManager.GetObject("aero_rotate_tr_ico", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + /// /// Looks up a localized resource of type System.Byte[]. /// diff --git a/src/Artemis.UI/Properties/Resources.resx b/src/Artemis.UI/Properties/Resources.resx index 980545d14..b89137361 100644 --- a/src/Artemis.UI/Properties/Resources.resx +++ b/src/Artemis.UI/Properties/Resources.resx @@ -145,15 +145,27 @@ ..\Resources\aero_rotate_bl.cur;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Resources\aero_rotate_bl_ico.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\aero_rotate_br.cur;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Resources\aero_rotate_br_ico.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\aero_rotate_tl.cur;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Resources\aero_rotate_tl_ico.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\aero_rotate_tr.cur;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Resources\aero_rotate_tr_ico.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\bow.svg;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 diff --git a/src/Artemis.UI/Resources/aero_rotate_bl_ico.ico b/src/Artemis.UI/Resources/aero_rotate_bl_ico.ico new file mode 100644 index 0000000000000000000000000000000000000000..ec5dce6658f8f0878c7368e2703159fe3d9e2fed GIT binary patch literal 1826 zcmb`H!AiqG5I`r9wjNT6X|44l9>r5{f)sM5n z#2Ob>madpaNj_dfGhbQ-z^CyT|I5ifjsi}ViZTeF2oy>BP-N+COP1~vp_ubRRaG<$ z1AX7eAP7>$uQ9E2z9Gvue58Y3uZNS#1j8^y$8oUJ>7ce*!Rm&Lg7pnd(@bh`T^DP$ z8j{~3I>a7PPWSJHes9H@oOiq3#AR6)dtBm#SPJ&VQMAgXP~d1ZLeKNqtS4K?F~EiPA^t!MuPC^e#fd7bw0&KnV5~yb6Uv zTBNaoUR0FvpV)=4q=BXr{!Mmf_S? z99q*XnU}U{Jd3o@#$CmFpUt>R#2W)r1JW#pZNt-9!rL>AH_J4>EW`N4v?1g}UC4%V zP4-Iuah-)>$iDA$x7%ggwq+msdBAn+tL~Uw+pVzUI6N2(c(GXUd_Lz+rz6ZqNRBlRA=G7vYY-3Q*q4ms4k%Q%Zia zs5Q-|JXP;mIAKXVb0Im-EM`%bnkLQMmZdZGf1GekBd8D2K2(8>m^^3{#55V-635VI SNr5{f)sM(fLxk6qlWxkDFEb(9Gq68_ zFRO3y*%eip!M9y3u=MMTwLI5lRe6UGInVrrInc4L>uXt`_@5=%Fbw#Ngy&`Lx|U$u zw&An0PEHtqD#2kGa--3Jvz0I=OIKNf$Kx@3o(G>N>?R4Yk3fpEe%|SHqVHl^7M!kd zvh2kE41*x;xg40L8980o8RL0L{Gj<$@+wC^% zn`+ltWm18F+{Slhfd%{rg%Zlg$S#pyd&Zw@&sj-BDV_j3OH?&Z#5hRDE^J0y&!WTlAmM05t_pmRw4V)sd+=aZ?F zV~Zi5FfVP>c#?Swj4IVEhHc9XvxFxWml?&H65}!D9J)SgmiQ)jDfww47VVkFi!f!@ zzD;?dy)y^NggRo{G)5tR?4@NIp8}LQHe_CyfvNMs#dCM;)eVe?!=bQ-u_^PyI~e=E zFFb$ljqs3{S}dO1)o=| z)zo_^7K_5VjmRU-dLIl_uJkAJ@HL`i$blN!Y?eLGQ}JrGD)9$s!8Gfw-&eUZpyyxH zJ0@p#Q|venHyRBdjYd4cex*`Lv*fe5U~*Ss)-QCn=yto@Y&O|-UAApoSoH-+$g%8v z==%@LFusx6g_@8H+0a`1%beZc+PYN#{ebEmPz&lnKT(B7<^TWy literal 0 HcmV?d00001 diff --git a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/EditToolView.xaml b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/EditToolView.xaml index 376440aa6..6f3166fbf 100644 --- a/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/EditToolView.xaml +++ b/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/EditToolView.xaml @@ -19,28 +19,28 @@ Canvas.Left="{Binding TopLeft.X}" Canvas.Top="{Binding TopLeft.Y}" Fill="Transparent" - MouseDown="{s:Action ShapeEditMouseDown}" MouseUp="{s:Action ShapeEditMouseUp}" MouseMove="{s:Action Rotate}" Cursor="Cross" /> + MouseDown="{s:Action ShapeEditMouseDown}" MouseUp="{s:Action ShapeEditMouseUp}" MouseMove="{s:Action Rotate}" Cursor="{Binding TopLeftRotateCursor}" /> + MouseDown="{s:Action ShapeEditMouseDown}" MouseUp="{s:Action ShapeEditMouseUp}" MouseMove="{s:Action Rotate}" Cursor="{Binding TopRightRotateCursor}" /> + MouseDown="{s:Action ShapeEditMouseDown}" MouseUp="{s:Action ShapeEditMouseUp}" MouseMove="{s:Action Rotate}" Cursor="{Binding BottomRightRotateCursor}" /> + MouseDown="{s:Action ShapeEditMouseDown}" MouseUp="{s:Action ShapeEditMouseUp}" MouseMove="{s:Action Rotate}" Cursor="{Binding BottomLeftRotateCursor}" /> { var shapeGeometry = new RectangleGeometry(_layerEditorService.GetShapeRenderRect(layer.LayerShape)) @@ -92,7 +104,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools ShapeTransformCollection.Freeze(); }); } - + private void UpdateControls() { ControlSize = Math.Max(10 / ProfileViewModel.PanZoomViewModel.Zoom, 4); diff --git a/src/Artemis.UI/Utilities/CursorRotator.cs b/src/Artemis.UI/Utilities/CursorRotator.cs new file mode 100644 index 000000000..df9a77e1d --- /dev/null +++ b/src/Artemis.UI/Utilities/CursorRotator.cs @@ -0,0 +1,86 @@ +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.Windows.Input; + +namespace Artemis.UI.Utilities +{ + public static class CursorUtilities + { + public static Cursor GetRotatedCursor(Icon icon, float rotationAngle) + { + // Load as Bitmap, convert to BitmapSource + using (var iconStream = new MemoryStream()) + using (var rotatedStream = new MemoryStream()) + { + icon.Save(iconStream); + + // Open the source image and create the bitmap for the rotated image + using (var sourceImage = icon.ToBitmap()) + using (var rotateImage = new Bitmap(sourceImage.Width, sourceImage.Height)) + { + // Set the resolution for the rotation image + rotateImage.SetResolution(sourceImage.HorizontalResolution, sourceImage.VerticalResolution); + // Create a graphics object + using (var gdi = Graphics.FromImage(rotateImage)) + { + //Rotate the image + gdi.TranslateTransform((float) sourceImage.Width / 2, (float) sourceImage.Height / 2); + gdi.RotateTransform(rotationAngle); + gdi.TranslateTransform(-(float) sourceImage.Width / 2, -(float) sourceImage.Height / 2); + gdi.DrawImage(sourceImage, new Point(0, 0)); + } + + // Save to a file + IconFromImage(rotateImage).Save(rotatedStream); + } + + // Convert saved file into .cur format + rotatedStream.Seek(2, SeekOrigin.Begin); + rotatedStream.Write(iconStream.ToArray(), 2, 1); + rotatedStream.Seek(10, SeekOrigin.Begin); + rotatedStream.Write(iconStream.ToArray(), 10, 2); + rotatedStream.Seek(0, SeekOrigin.Begin); + + // Construct Cursor + return new Cursor(rotatedStream); + } + } + + public static Icon IconFromImage(Image img) + { + using (var ms = new MemoryStream()) + using (var bw = new BinaryWriter(ms)) + { + // Header + bw.Write((short) 0); // 0 : reserved + bw.Write((short) 1); // 2 : 1=ico, 2=cur + bw.Write((short) 1); // 4 : number of images + // Image directory + var w = img.Width; + if (w >= 256) w = 0; + bw.Write((byte) w); // 0 : width of image + var h = img.Height; + if (h >= 256) h = 0; + bw.Write((byte) h); // 1 : height of image + bw.Write((byte) 0); // 2 : number of colors in palette + bw.Write((byte) 0); // 3 : reserved + bw.Write((short) 0); // 4 : number of color planes + bw.Write((short) 0); // 6 : bits per pixel + var sizeHere = ms.Position; + bw.Write(0); // 8 : image size + var start = (int) ms.Position + 4; + bw.Write(start); // 12: offset of image data + // Image data + img.Save(ms, ImageFormat.Png); + var imageSize = (int) ms.Position - start; + ms.Seek(sizeHere, SeekOrigin.Begin); + bw.Write(imageSize); + ms.Seek(0, SeekOrigin.Begin); + + // And load it + return new Icon(ms); + } + } + } +} \ No newline at end of file