Skip to content

Commit 130c67a

Browse files
committed
Merge pull request #1440 from kellyelton/master
Added the ability to click through transparent areas of cards
2 parents dbd356f + a1311c4 commit 130c67a

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Windows;
6+
using System.Windows.Controls;
7+
using System.Windows.Media;
8+
using System.Windows.Media.Imaging;
9+
10+
namespace Octgn.Controls
11+
{
12+
public class OpaqueClickableImage : Image
13+
{
14+
protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters)
15+
{
16+
var source = (BitmapSource)Source;
17+
18+
// Get the pixel of the source that was hit
19+
var x = (int)(hitTestParameters.HitPoint.X / ActualWidth * source.PixelWidth);
20+
var y = (int)(hitTestParameters.HitPoint.Y / ActualHeight * source.PixelHeight);
21+
22+
// Copy the single pixel into a new byte array representing RGBA
23+
var pixel = new byte[4];
24+
if (x >= source.PixelWidth)
25+
x = source.PixelWidth - 1;
26+
if (y >= source.PixelHeight)
27+
y = source.PixelHeight - 1;
28+
source.CopyPixels(new Int32Rect(x, y, 1, 1), pixel, 4, 0);
29+
30+
// Check the alpha (transparency) of the pixel
31+
// - threshold can be adjusted from 0 to 255
32+
if (pixel[3] < 10)
33+
return null;
34+
35+
return new PointHitTestResult(this, hitTestParameters.HitPoint);
36+
}
37+
}
38+
}

octgnFX/Octgn/Octgn.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@
340340
<Compile Include="Controls\FeatureFundingMessage.xaml.cs">
341341
<DependentUpon>FeatureFundingMessage.xaml</DependentUpon>
342342
</Compile>
343+
<Compile Include="Controls\OpaqueClickableImage.cs" />
343344
<Compile Include="Controls\SpecialOfferBar.xaml.cs">
344345
<DependentUpon>SpecialOfferBar.xaml</DependentUpon>
345346
</Compile>

octgnFX/Octgn/Play/Gui/CardControl.xaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<UserControl x:Class="Octgn.Play.Gui.CardControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="me" mc:Ignorable="d"
33
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="294" d:DesignWidth="199">
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:controls="clr-namespace:Octgn.Controls"
6+
d:DesignHeight="294" d:DesignWidth="199">
57

68
<UserControl.Resources>
79
<!-- FIX: This hack is meant to work around the TextBlock style
@@ -88,9 +90,9 @@
8890
</Rectangle.Stroke>
8991
</Rectangle>
9092

91-
<Image x:Name="img" MouseLeftButtonDown="LeftButtonDownOverImage"
92-
Source="{Binding ElementName=me, Path=DisplayedPicture}" />
93-
93+
<!--<Image x:Name="img" MouseLeftButtonDown="LeftButtonDownOverImage"
94+
Source="{Binding ElementName=me, Path=DisplayedPicture}" IsHitTestVisible="False"/>-->
95+
<controls:OpaqueClickableImage x:Name="img" Image.MouseLeftButtonDown="LeftButtonDownOverImage" Source="{Binding ElementName=me, Path=DisplayedPicture}"/>
9496
<StackPanel Margin="0,8,1,0" HorizontalAlignment="Right" VerticalAlignment="Top">
9597
<Border x:Name="peekEye" Background="#80000000" CornerRadius="5,0,0,5" Visibility="{Binding PeekingPlayers.Count, Converter={StaticResource CountConverter}}">
9698
<Image x:Name="peekEyeIcon" Source="/Resources/Eye.png" Width="32" Margin="4,0,8,0" />

recentchanges.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Can now click through transparent areas of Cards - Kelly

0 commit comments

Comments
 (0)