') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); GitHub - GuOrg/Gu.Wpf.Geometry · GitHub
Skip to content

Repository files navigation

Gu.Wpf.Geometry

LicenseGitterNuGetBuild statusBuild Statusci

Small library with WPF geometries and shaders.

Contents

Geometries

Balloon

A ContentControlfor showing balloons.

Note: WPF Popup clips to bounds so the connector will be clipped when used in a popup.

<geometry:Balloon Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
ConnectorAngle="25"
CornerRadius="15"
PlacementOptions="Bottom, Center"
PlacementTarget="{Binding ElementName=Target}">
<Grid Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Text="{Binding Text, ElementName=TextBox}" />
<UniformGrid Grid.Row="1"
Rows="1">
<Ellipse Width="20"
Height="20"
Fill="Blue" />
<Ellipse Width="20"
Height="20"
Fill="Yellow" />
<Ellipse Width="20"
Height="20"
Fill="Red" />
</UniformGrid>
</Grid>
</geometry:Balloon>

balloon

BoxBalloon

Draws a border with a connector. Note: the connector is drawn outside the bounds of the element.

Simple
<geometry:BoxBalloon Grid.Row="1"
Grid.Column="1"ConnectorAngle="45"ConnectorOffset="-10,-0"CornerRadius="10"Stroke="CornflowerBlue"StrokeThickness="4" />

simple balloon

ConnectorAngle

connector angle

ConnectorOffset

connector offset

With PlacementTarget
<Canvas>
<Grid>
<Grid.RowDefinitions>
<RowDefinitionHeight="100" />
<RowDefinitionHeight="100" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinitionWidth="100" />
<ColumnDefinitionWidth="100" />
<ColumnDefinitionWidth="100" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ListBoxx:Name="Placements"
Grid.Row="0"
Grid.RowSpan="3"
Grid.Column="2"SelectedIndex="0">
<geometry:PlacementOptions>Auto</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto 5</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto -5</geometry:PlacementOptions>
<geometry:PlacementOptions>Center</geometry:PlacementOptions>
<geometry:PlacementOptions>Center 5</geometry:PlacementOptions>
<geometry:PlacementOptions>Center -5</geometry:PlacementOptions>
<geometry:PlacementOptions>Top Left</geometry:PlacementOptions>
<geometry:PlacementOptions>Top Center</geometry:PlacementOptions>
<geometry:PlacementOptions>Top Right</geometry:PlacementOptions>
<geometry:PlacementOptions>Bottom Left</geometry:PlacementOptions>
<geometry:PlacementOptions>Bottom Center</geometry:PlacementOptions>
<geometry:PlacementOptions>Bottom Right</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto Center</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto Left</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto Right</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto Top</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto Bottom</geometry:PlacementOptions>
</ListBox>
<geometry:BoxBalloon Grid.Row="1"
Grid.Column="1"Margin="6"ConnectorAngle="45"CornerRadius="10"PlacementOptions="{Binding SelectedItem, ElementName=Placements}"PlacementTarget="{Binding ElementName=Target}"Stroke="HotPink"StrokeThickness="4" />
</Grid>
<Rectanglex:Name="Target"
Canvas.Left="100"
Canvas.Top="50"Width="100"Height="10"Fill="Gainsboro"MouseLeftButtonDown="OnTargetMouseLeftDown" />
</Canvas>

connected balloon

With PlacementRectangle
<Canvas>
<Grid>
<Grid.RowDefinitions>
<RowDefinitionHeight="100" />
<RowDefinitionHeight="100" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinitionWidth="100" />
<ColumnDefinitionWidth="100" />
<ColumnDefinitionWidth="100" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ListBoxx:Name="Placements"
Grid.Row="0"
Grid.RowSpan="3"
Grid.Column="2"SelectedIndex="0">
<geometry:PlacementOptions>Auto</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto 5</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto -5</geometry:PlacementOptions>
<geometry:PlacementOptions>Center</geometry:PlacementOptions>
<geometry:PlacementOptions>Center 5</geometry:PlacementOptions>
<geometry:PlacementOptions>Center -5</geometry:PlacementOptions>
<geometry:PlacementOptions>Top Left</geometry:PlacementOptions>
<geometry:PlacementOptions>Top Center</geometry:PlacementOptions>
<geometry:PlacementOptions>Top Right</geometry:PlacementOptions>
<geometry:PlacementOptions>Bottom Left</geometry:PlacementOptions>
<geometry:PlacementOptions>Bottom Center</geometry:PlacementOptions>
<geometry:PlacementOptions>Bottom Right</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto Center</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto Left</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto Right</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto Top</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto Bottom</geometry:PlacementOptions>
</ListBox>
<geometry:BoxBalloon Grid.Row="1"
Grid.Column="1"Margin="6"ConnectorAngle="45"CornerRadius="10"PlacementOptions="{Binding SelectedItem, ElementName=Placements}"PlacementRectangle="100, 50, 100, 10"Stroke="HotPink"StrokeThickness="4" />
</Grid>
<Rectanglex:Name="Target"
Canvas.Left="100"
Canvas.Top="50"Width="100"Height="10"Fill="Gainsboro"MouseLeftButtonDown="OnTargetMouseLeftDown" />
</Canvas>

connected balloon

With PlacementRectangle and PlacementTarget
<Canvas>
<Grid>
<Grid.RowDefinitions>
<RowDefinitionHeight="100" />
<RowDefinitionHeight="100" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinitionWidth="100" />
<ColumnDefinitionWidth="100" />
<ColumnDefinitionWidth="100" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ListBoxx:Name="Placements"
Grid.Row="0"
Grid.RowSpan="3"
Grid.Column="2"SelectedIndex="0">
<geometry:PlacementOptions>Auto</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto 5</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto -5</geometry:PlacementOptions>
<geometry:PlacementOptions>Center</geometry:PlacementOptions>
<geometry:PlacementOptions>Center 5</geometry:PlacementOptions>
<geometry:PlacementOptions>Center -5</geometry:PlacementOptions>
<geometry:PlacementOptions>Top Left</geometry:PlacementOptions>
<geometry:PlacementOptions>Top Center</geometry:PlacementOptions>
<geometry:PlacementOptions>Top Right</geometry:PlacementOptions>
<geometry:PlacementOptions>Bottom Left</geometry:PlacementOptions>
<geometry:PlacementOptions>Bottom Center</geometry:PlacementOptions>
<geometry:PlacementOptions>Bottom Right</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto Center</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto Left</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto Right</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto Top</geometry:PlacementOptions>
<geometry:PlacementOptions>Auto Bottom</geometry:PlacementOptions>
</ListBox>
<geometry:BoxBalloon Grid.Row="1"
Grid.Column="1"Margin="6"ConnectorAngle="45"CornerRadius="10"PlacementOptions="{Binding SelectedItem, ElementName=Placements}"PlacementRectangle="0, 0, 100, 10"PlacementTarget={Binding ElementName=Target}
Stroke="HotPink"StrokeThickness="4" />
</Grid>
<Rectanglex:Name="Target"
Canvas.Left="100"
Canvas.Top="50"Width="100"Height="10"Fill="Gainsboro"MouseLeftButtonDown="OnTargetMouseLeftDown" />
</Canvas>

connected balloon

PlacementTarget

The UIElement to connect the balloon to.

PlacementRectangle

The rectangle to connect the balloon to. If used with PlacementTarget, the rectangle coordinates are relative to it. If used alone, the coordinates are relative to the parent UIElement.

PlacementOptions

Where on the connected element the connector should be attached.

In xaml either input a string <geometry:BoxBalloon PlacementOptions="Top Left" .../> Or use the PlacementOptionsExtension:

<geometry:BoxBalloonPlacementOptions="{geometry:PlacementOptions Horizontal=Auto, Vertical=Top, Offset=5}"
...
/>

EllipseBalloon

Same API as BoxBalloon but renders:

EllipseBallon

GradientPath

Based on this blog post

<geometry:GradientPathGradientMode="Parallel"StrokeThickness="10"UseLayoutRounding="True">
<geometry:GradientPath.Data>
<PathGeometry>
<PathFigureStartPoint="35,400">
<LineSegmentPoint="100,300" />
<BezierSegmentPoint1="300,10"Point2="500,600"Point3="700,300" />
<LineSegmentPoint="800,100" />
</PathFigure>
<PathFigureStartPoint="200,200">
<LineSegmentPoint="200,400" />
<LineSegmentPoint="400,400" />
</PathFigure>
</PathGeometry>
</geometry:GradientPath.Data>
<geometry:GradientPath.GradientStops>
<GradientStopOffset="0"Color="#4C0000FF" />
<GradientStopOffset="0.5"Color="#4CFF0000" />
<GradientStopOffset="1"Color="#4CFFFF00" />
</geometry:GradientPath.GradientStops>
</geometry:GradientPath>

screenie

Controls

Zoombox

Panel for zooming & panning. Handles touch but IsManipulationEnabled has default value false meaning no touch.

<UserControl ...
xmlns:effects="http://gu.se/Geometry">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinitionHeight="Auto" />
</Grid.RowDefinitions>
<effects:Zoomboxx:Name="ImageBox"IsManipulationEnabled="True"MaxZoom="10"MinZoom="0.1">
<ImageSource="Images/Circles.png" />
</effects:Zoombox>
<UniformGrid Grid.Row="1"Rows="1">
<ButtonCommand="effects:ZoomCommands.Increase"CommandParameter="2.0"CommandTarget="{Binding ElementName=ImageBox}"Content="Increase" />
<ButtonCommand="effects:ZoomCommands.Decrease"CommandParameter="2.0"CommandTarget="{Binding ElementName=ImageBox}"Content="Decrease" />
<ButtonCommand="effects:ZoomCommands.None"CommandTarget="{Binding ElementName=ImageBox}"Content="None" />
<ButtonCommand="effects:ZoomCommands.Uniform"CommandTarget="{Binding ElementName=ImageBox}"Content="Uniform" />
<ButtonCommand="effects:ZoomCommands.UniformToFill"CommandTarget="{Binding ElementName=ImageBox}"Content="UniformToFill" />
</UniformGrid>
</Grid>
</UserControl>

Effects

A collection of pixel shaders.

DesaturateEffect

Desaturate an image, brush or WPF controls. It has only one property Strength 0 means the effect does nothing and 1 means a grayscale image is returned.

<UserControl
...
xmlns:effects="http://gu.se/Geometry">
<Grid>
<ImageSource="Images/Hustler.jpg">
<Image.Effect>
<effects:DesaturateEffectStrength="{Binding ElementName=Slider, Path=Value}" />
</Image.Effect>
</Image>
<Sliderx:Name="Slider"VerticalAlignment="Bottom"Maximum="1"Minimum="0" />
</Grid>
</UserControl>

FadeEffect

Fade an image to a colour.

<UserControl ...
xmlns:effects="http://gu.se/Geometry">
<Grid>
<ImageSource="../Images/Hustler.jpg">
<Image.Effect>
<effects:FadeEffectTo="Black"Strength="{Binding ElementName=StrengthSlider, Path=Value}" />
</Image.Effect>
</Image>
<Sliderx:Name="StrengthSlider"VerticalAlignment="Bottom"Maximum="1"Minimum="0" />
</Grid>
</UserControl>

MaskEffect

Render an image as a selection mask.

<UserControl ...
xmlns:effects="http://gu.se/Geometry">
<Grid>
<ImageSource="../Images/Circle.png">
<Image.Effect>
<effects:MaskEffect />
</Image.Effect>
</Image>
</Grid>
</UserControl>

AngularGradientEffect

A gradient that changes value along the angle. Perhaps useful for spinners. Replaces the pixels of the owning element. The owning element must have a Brush set the brush can be any color that is not transparent.

StartAngle

The angle for the StartColor -360 - 360 degrees, positive clockwise. Zero at 12 o'clock.

CentralAngle

The anglular extent of the gradient -360 - 360 degrees, positive clockwise.

CenterPoint

The center point of the gradient (0, 0) - (1, 1) default is (0.5, 0.5) fore a gradient around the center.

<Windowxmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:effects="http://gu.se/Geometry"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"Title="AngularGradientWindow"SizeToContent="WidthAndHeight"mc:Ignorable="d">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinitionWidth="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinitionHeight="Auto" />
<RowDefinitionHeight="Auto" />
<RowDefinitionHeight="Auto" />
<RowDefinitionHeight="Auto" />
<RowDefinitionHeight="Auto" />
<RowDefinitionHeight="Auto" />
</Grid.RowDefinitions>
<GroupBoxx:Name="Render"
Grid.Row="0"
Grid.Column="1"Margin="50"Background="LightGray"BorderThickness="0"Style="{StaticResource InvisibleGroupBoxStyle}">
<Ellipsex:Name="Ellipse"Width="200"Height="200"Stroke="White"StrokeThickness="25">
<Ellipse.Effect>
<effects:AngularGradientEffectCenterPoint="{Binding ElementName=CenterPoint, Path=Text}"CentralAngle="{Binding ElementName=CentralAngle, Path=Value}"EndColor="{Binding ElementName=EndColour, Path=Text}"StartAngle="{Binding ElementName=StartAngle, Path=Value}"StartColor="{Binding ElementName=StartColour, Path=Text}" />
</Ellipse.Effect>
</Ellipse>
</GroupBox>
<TextBlock Grid.Row="1"
Grid.Column="0"Text="Start colour:" />
<TextBoxx:Name="StartColour"
Grid.Row="1"
Grid.Column="1"Text="#FFFF0000" />
<TextBlock Grid.Row="2"
Grid.Column="0"Text="End colour:" />
<TextBoxx:Name="EndColour"
Grid.Row="2"
Grid.Column="1"Text="#00FF0000" />
<TextBlock Grid.Row="3"
Grid.Column="0"Text="Center point:" />
<TextBoxx:Name="CenterPoint"
Grid.Row="3"
Grid.Column="1"Text="0.5 0.5" />
<TextBlock Grid.Row="4"
Grid.Column="0"Text="Start angle:" />
<Sliderx:Name="StartAngle"
Grid.Row="4"
Grid.Column="1"Maximum="360"Minimum="-360" />
<TextBlock Grid.Row="5"
Grid.Column="0"Text="Central angle:" />
<Sliderx:Name="CentralAngle"
Grid.Row="5"
Grid.Column="1"Maximum="360"Minimum="-360"Value="360" />
</Grid>
</Window>

animation

HsvWheelEffect

A gradient that changes value along the angle. Perhaps useful for colour pickers. Note that the element must have a background or fill. The brush can be any colour.

<UserControl ...
xmlns:effects="http://gu.se/Geometry">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinitionWidth="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinitionHeight="Auto" />
<RowDefinitionHeight="Auto" />
</Grid.RowDefinitions>
<Ellipse Grid.ColumnSpan="2"Width="300"Height="300"HorizontalAlignment="Center"Fill="White">
<Ellipse.Effect>
<effects:HsvWheelEffectInnerRadius="{Binding ElementName=InnerRadius, Path=Value}"InnerSaturation="{Binding ElementName=InnerSaturation, Path=Value}" />
</Ellipse.Effect>
</Ellipse>
<Label Grid.Row="1"
Grid.Column="0"Content="Inner radius:" />
<Sliderx:Name="InnerRadius"
Grid.Row="1"
Grid.Column="1"Maximum="1"Minimum="0"Value="0" />
<Label Grid.Row="2"
Grid.Column="0"Content="Inner saturation:" />
<Sliderx:Name="InnerSaturation"
Grid.Row="2"
Grid.Column="1"Maximum="1"Minimum="0"Value="0" />
</Grid>
</UserControl>

HslWheelEffect

A gradient that changes value along the angle. Perhaps useful for colour pickers. Note that the element must have a background or fill. The brush can be any colour. Same API as HsvWheelEffect

About

No description, website, or topics provided.

Resources

Stars

170 stars

Watchers

13 watching

Forks

Releases

Packages

Used by

Contributors

Languages