Skip to content

Commit

Permalink
Fix FancyZones tools build (#24901)
Browse files Browse the repository at this point in the history
* Fix FancyZones Hit test build

* Fix DrawLayoutTest

* Fix Zonable tester

* Adress PR comments
  • Loading branch information
Aaron-Junker committed Mar 20, 2023
1 parent 08fe13a commit 7d6a774
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 78 deletions.
6 changes: 5 additions & 1 deletion tools/FancyZone_HitTest/FancyZone_HitTest/App.xaml.cs
@@ -1,4 +1,8 @@
using System;
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
Expand Down
13 changes: 6 additions & 7 deletions tools/FancyZone_HitTest/FancyZone_HitTest/AssemblyInfo.cs
@@ -1,10 +1,9 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
ResourceDictionaryLocation.None,
ResourceDictionaryLocation.SourceAssembly)]
26 changes: 13 additions & 13 deletions tools/FancyZone_HitTest/FancyZone_HitTest/MainWindow.xaml.cs
@@ -1,4 +1,8 @@
using System;
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections;
using System.Linq;
using System.Windows;
Expand All @@ -18,8 +22,8 @@ public MainWindow()
InitializeComponent();
}

static ArrayList _hitResultsList = new ArrayList();
static ArrayList _visualCalculationList = new ArrayList();
private static ArrayList _hitResultsList = new ArrayList();
private static ArrayList _visualCalculationList = new ArrayList();

private void Grid_MouseMove(object sender, MouseEventArgs e)
{
Expand All @@ -31,9 +35,7 @@ private void Grid_MouseMove(object sender, MouseEventArgs e)
_visualCalculationList.Clear();

// Set up a callback to receive the hit test result enumeration.
VisualTreeHelper.HitTest(hitTestGrid, null,
new HitTestResultCallback(MyHitTestResult),
new PointHitTestParameters(gridMouseLocation));
VisualTreeHelper.HitTest(hitTestGrid, null, new HitTestResultCallback(MyHitTestResult), new PointHitTestParameters(gridMouseLocation));

// Perform actions on the hit test results list.
if (_hitResultsList.Count > 0)
Expand Down Expand Up @@ -73,26 +75,24 @@ private void Grid_MouseMove(object sender, MouseEventArgs e)
item.RelativeMouseLocation, // 3
item.MouseDistanceFromCenter, // 4
item.Area, // 5
item.Area / item.MouseDistanceFromCenter, //6
item.Area / item.MouseDistanceFromCenter, // 6
item.Name, // 7
item.DistanceFromEdge, //8
item.DistanceFromEdgePercentage // 9
);
item.DistanceFromEdge, // 8
item.DistanceFromEdgePercentage); // 9
itemsHit.Text += Environment.NewLine;
}


if (reorderedVisualData.Count() > 0)
{
var rect = (hitTestGrid.FindName(reorderedVisualData.First().Name) as Rectangle);
var rect = hitTestGrid.FindName(reorderedVisualData.First().Name) as Rectangle;
rect.Opacity = .75;
rect.Stroke = Brushes.Black;
rect.StrokeThickness = 5;
}
}
else
{
itemsHit.Text = "";
itemsHit.Text = string.Empty;
}
}

Expand Down
7 changes: 4 additions & 3 deletions tools/FancyZone_HitTest/FancyZone_HitTest/Utilities.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Windows;
using System.Windows.Media;

Expand Down
31 changes: 21 additions & 10 deletions tools/FancyZone_HitTest/FancyZone_HitTest/VisualData.cs
@@ -1,4 +1,8 @@
using System;
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
Expand All @@ -8,14 +12,21 @@ namespace FancyZone_HitTest
{
public class VisualData
{
public Point RelativeMouseLocation;
public Point CenterMass;
public Point TopLeft;
public double MouseDistanceFromCenter;
public int Area;
public string Name;
public double DistanceFromEdge;
public double DistanceFromEdgePercentage;
public Point RelativeMouseLocation { get; set; }

public Point CenterMass { get; set; }

public Point TopLeft { get; set; }

public double MouseDistanceFromCenter { get; set; }

public int Area { get; set; }

public string Name { get; set; }

public double DistanceFromEdge { get; set; }

public double DistanceFromEdgePercentage { get; set; }

public VisualData(Shape item, MouseEventArgs e, Visual root)
{
Expand All @@ -36,7 +47,7 @@ public VisualData(Shape item, MouseEventArgs e, Visual root)
var horDist = (RelativeMouseLocation.X < CenterMass.X) ? RelativeMouseLocation.X : width - mouseX;
var vertDist = (RelativeMouseLocation.Y < CenterMass.Y) ? RelativeMouseLocation.Y : height - mouseY;

var isHorCalc = (horDist < vertDist);
var isHorCalc = horDist < vertDist;
DistanceFromEdge = Math.Floor(isHorCalc ? horDist : vertDist);

if (isHorCalc)
Expand Down
39 changes: 0 additions & 39 deletions tools/FancyZone_HitTest/FancyZone_HitTest/VisualDataComparer.cs

This file was deleted.

44 changes: 44 additions & 0 deletions tools/FancyZone_HitTest/FancyZone_HitTest/VisualDataComparer`1.cs
@@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;

namespace FancyZone_HitTest
{
public class VisualDataComparer<T> : IComparer<VisualData>
{
int IComparer<VisualData>.Compare(VisualData x, VisualData y)
{
// has quirks but workable
if (x.DistanceFromEdge == y.DistanceFromEdge)
{
return y.Area.CompareTo(x.Area);
}
else
{
return x.DistanceFromEdge.CompareTo(y.DistanceFromEdge);
}

// entire screen won't work
/*
if (x.MouseDistanceFromCenter == y.MouseDistanceFromCenter)
{
return y.Area.CompareTo(x.Area);
}
else
{
return x.MouseDistanceFromCenter.CompareTo(y.MouseDistanceFromCenter);
}
if (x.DistanceFromEdgePercentage == y.DistanceFromEdgePercentage)
{
return y.Area.CompareTo(x.Area);
}
else
{
return x.DistanceFromEdgePercentage.CompareTo(y.DistanceFromEdgePercentage);
}*/
}
}
}
4 changes: 2 additions & 2 deletions tools/FancyZones_DrawLayoutTest/FancyZones_DrawLayoutTest.cpp
Expand Up @@ -68,7 +68,7 @@ int GetHighlightedZoneIdx(const std::vector<RECT>& zones, const POINT& cursorPos
{
if (cursorPosition.x >= zones[i].left && cursorPosition.x < zones[i].right)
{
return i;
return static_cast<int>(i);
}
}
return -1;
Expand Down Expand Up @@ -361,7 +361,7 @@ void DrawZone(HDC hdc, const ColorSetting& colorSetting, const RECT& rect, size_
DrawIndex(hdc, rect, index);
}

inline BYTE OpacitySettingToAlpha(int opacity)
constexpr inline BYTE OpacitySettingToAlpha(int opacity)
{
return static_cast<BYTE>(opacity * 2.55);
}
Expand Down
Expand Up @@ -107,6 +107,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -121,6 +122,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down
Expand Up @@ -80,6 +80,7 @@
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down Expand Up @@ -110,6 +111,7 @@
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
6 changes: 3 additions & 3 deletions tools/FancyZones_zonable_tester/main.cpp
Expand Up @@ -11,7 +11,7 @@ std::wstring get_process_path(DWORD pid) noexcept
{
name.resize(MAX_PATH);
DWORD name_length = static_cast<DWORD>(name.length());
if (QueryFullProcessImageNameW(process, 0, (LPWSTR)name.data(), &name_length) == 0)
if (QueryFullProcessImageNameW(process, 0, static_cast<LPWSTR>(name.data()), &name_length) == 0)
{
name_length = 0;
}
Expand Down Expand Up @@ -185,8 +185,8 @@ bool test_window(HWND window)

auto style = GetWindowLongPtr(window, GWL_STYLE);
auto exStyle = GetWindowLongPtr(window, GWL_EXSTYLE);
std::cout << "style: 0x" << std::hex << style << ": " << window_styles(style) << "\n";
std::cout << "exStyle: 0x" << std::hex << exStyle << ": " << window_exstyles(exStyle) << " \n";
std::cout << "style: 0x" << std::hex << style << ": " << window_styles(static_cast<LONG>(style)) << "\n";
std::cout << "exStyle: 0x" << std::hex << exStyle << ": " << window_exstyles(static_cast<LONG>(exStyle)) << " \n";
std::array<char, 256> class_name;
GetClassNameA(window, class_name.data(), static_cast<int>(class_name.size()));
std::cout << "Window class: '" << class_name.data() << "' equals:\n";
Expand Down

0 comments on commit 7d6a774

Please sign in to comment.