mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Added ColorBox source
Added direction buttons functionality
This commit is contained in:
parent
7ddc3d7672
commit
81a8011338
@ -9,6 +9,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Razer2Artemis", "Razer2Arte
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnrealTournament2Artemis", "UnrealTournament2Artemis\UnrealTournament2Artemis.vcxproj", "{3541864F-1662-4BD6-8328-2C87AE61D152}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ColorBox", "ColorBox\ColorBox.csproj", "{40085232-ACED-4CBE-945B-90BA8153C151}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
CD_ROM|Any CPU = CD_ROM|Any CPU
|
||||
@ -114,6 +116,36 @@ Global
|
||||
{3541864F-1662-4BD6-8328-2C87AE61D152}.SingleImage|x64.Build.0 = Release|x64
|
||||
{3541864F-1662-4BD6-8328-2C87AE61D152}.SingleImage|x86.ActiveCfg = Release|Win32
|
||||
{3541864F-1662-4BD6-8328-2C87AE61D152}.SingleImage|x86.Build.0 = Release|Win32
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.CD_ROM|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.CD_ROM|Any CPU.Build.0 = Release|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.CD_ROM|x64.ActiveCfg = Release|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.CD_ROM|x64.Build.0 = Release|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.CD_ROM|x86.ActiveCfg = Release|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.CD_ROM|x86.Build.0 = Release|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.DVD-5|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.DVD-5|Any CPU.Build.0 = Debug|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.DVD-5|x64.ActiveCfg = Debug|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.DVD-5|x64.Build.0 = Debug|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.DVD-5|x86.ActiveCfg = Debug|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.DVD-5|x86.Build.0 = Debug|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.Release|x64.Build.0 = Release|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.Release|x86.Build.0 = Release|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.SingleImage|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.SingleImage|Any CPU.Build.0 = Release|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.SingleImage|x64.ActiveCfg = Release|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.SingleImage|x64.Build.0 = Release|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.SingleImage|x86.ActiveCfg = Release|Any CPU
|
||||
{40085232-ACED-4CBE-945B-90BA8153C151}.SingleImage|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@ -143,10 +143,6 @@
|
||||
<HintPath>..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="ColorBox, Version=1.1.0.0, Culture=neutral, PublicKeyToken=f971124b2576acfc, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>lib\ColorBox.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Corale.Colore, Version=5.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Colore.5.0.0\lib\net35\Corale.Colore.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
@ -886,7 +882,12 @@
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ColorBox\ColorBox.csproj">
|
||||
<Project>{40085232-aced-4cbe-945b-90ba8153c151}</Project>
|
||||
<Name>ColorBox</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\packages\CUE.NET.1.1.0.1\build\net45\CUE.NET.targets" Condition="Exists('..\packages\CUE.NET.1.1.0.1\build\net45\CUE.NET.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
|
||||
@ -646,7 +646,7 @@
|
||||
<!-- Directions -->
|
||||
<UniformGrid Rows="1">
|
||||
<Button ToolTip="Horizontal"
|
||||
Command="{x:Static nc:ColorBox.ReverseGradientStop}"
|
||||
Command="{x:Static nc:ColorBox.DirectionHorizontal}"
|
||||
VerticalAlignment="Top" Width="32">
|
||||
<Button.Content>
|
||||
<Rectangle
|
||||
@ -666,7 +666,7 @@
|
||||
</Button>
|
||||
|
||||
<Button ToolTip="Vertical"
|
||||
Command="{x:Static nc:ColorBox.ReverseGradientStop}"
|
||||
Command="{x:Static nc:ColorBox.DirectionVertical}"
|
||||
VerticalAlignment="Top" Width="32">
|
||||
<Button.Content>
|
||||
<Rectangle
|
||||
@ -682,7 +682,7 @@
|
||||
</Button>
|
||||
|
||||
<Button ToolTip="Top left to bottom right"
|
||||
Command="{x:Static nc:ColorBox.ReverseGradientStop}"
|
||||
Command="{x:Static nc:ColorBox.DirectionTopLeftBottomRight}"
|
||||
VerticalAlignment="Top" Width="32">
|
||||
<Button.Content>
|
||||
<Rectangle
|
||||
@ -702,7 +702,7 @@
|
||||
</Button>
|
||||
|
||||
<Button ToolTip="Top right to bottom left"
|
||||
Command="{x:Static nc:ColorBox.ReverseGradientStop}"
|
||||
Command="{x:Static nc:ColorBox.DirectionTopRightBottomLeft}"
|
||||
VerticalAlignment="Top" Width="32">
|
||||
<Button.Content>
|
||||
<Rectangle
|
||||
|
||||
134
Artemis/ColorBox/AlphaSelector.cs
Normal file
134
Artemis/ColorBox/AlphaSelector.cs
Normal file
@ -0,0 +1,134 @@
|
||||
/***************** NCore Softwares Pvt. Ltd., India **************************
|
||||
|
||||
ColorBox
|
||||
|
||||
Copyright (C) 2013 NCore Softwares Pvt. Ltd.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://colorbox.codeplex.com/license
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace ColorBox
|
||||
{
|
||||
public class AlphaSelector : BaseSelector
|
||||
{
|
||||
public static readonly DependencyProperty AlphaProperty =
|
||||
DependencyProperty.Register("Alpha", typeof(double), typeof(AlphaSelector),
|
||||
new FrameworkPropertyMetadata(1.0, AlphaChanged, AlphaCoerce));
|
||||
|
||||
public static readonly DependencyProperty AlphaOffsetProperty =
|
||||
DependencyProperty.Register("AlphaOffset", typeof(double), typeof(AlphaSelector),
|
||||
new UIPropertyMetadata(0.0));
|
||||
|
||||
public double Alpha
|
||||
{
|
||||
get { return (double) GetValue(AlphaProperty); }
|
||||
set { SetValue(AlphaProperty, value); }
|
||||
}
|
||||
|
||||
|
||||
public double AlphaOffset
|
||||
{
|
||||
get { return (double) GetValue(AlphaOffsetProperty); }
|
||||
private set { SetValue(AlphaOffsetProperty, value); }
|
||||
}
|
||||
|
||||
public static void AlphaChanged(object o, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var h = (AlphaSelector) o;
|
||||
h.SetAlphaOffset();
|
||||
h.SetColor();
|
||||
}
|
||||
|
||||
public static object AlphaCoerce(DependencyObject d, object brightness)
|
||||
{
|
||||
var v = (double) brightness;
|
||||
if (v < 0) return 0.0;
|
||||
if (v > 1) return 1.0;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
var p = e.GetPosition(this);
|
||||
|
||||
if (Orientation == Orientation.Vertical)
|
||||
Alpha = 1 - p.Y/ActualHeight;
|
||||
else
|
||||
Alpha = 1 - p.X/ActualWidth;
|
||||
}
|
||||
base.OnMouseMove(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
var p = e.GetPosition(this);
|
||||
|
||||
if (Orientation == Orientation.Vertical)
|
||||
Alpha = 1 - p.Y/ActualHeight;
|
||||
else
|
||||
Alpha = 1 - p.X/ActualWidth;
|
||||
}
|
||||
Mouse.Capture(this);
|
||||
base.OnMouseMove(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseButtonEventArgs e)
|
||||
{
|
||||
ReleaseMouseCapture();
|
||||
base.OnMouseUp(e);
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext dc)
|
||||
{
|
||||
var lb = new LinearGradientBrush();
|
||||
|
||||
lb.StartPoint = new Point(0, 0);
|
||||
|
||||
if (Orientation == Orientation.Vertical)
|
||||
lb.EndPoint = new Point(0, 1);
|
||||
else
|
||||
lb.EndPoint = new Point(1, 0);
|
||||
|
||||
lb.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x00, 0x00, 0x00), 0.00));
|
||||
lb.GradientStops.Add(new GradientStop(Color.FromArgb(0x00, 0x00, 0x00, 0x00), 1.00));
|
||||
|
||||
dc.DrawRectangle(lb, null, new Rect(0, 0, ActualWidth, ActualHeight));
|
||||
|
||||
SetAlphaOffset();
|
||||
}
|
||||
|
||||
protected override Size ArrangeOverride(Size finalSize)
|
||||
{
|
||||
SetAlphaOffset();
|
||||
return base.ArrangeOverride(finalSize);
|
||||
}
|
||||
|
||||
|
||||
private void SetAlphaOffset()
|
||||
{
|
||||
var length = ActualHeight;
|
||||
if (Orientation == Orientation.Horizontal)
|
||||
length = ActualWidth;
|
||||
AlphaOffset = length - length*Alpha;
|
||||
}
|
||||
|
||||
private void SetColor()
|
||||
{
|
||||
Color = Color.FromArgb((byte) Math.Round(Alpha*255), 0, 0, 0);
|
||||
//Brush = new SolidColorBrush(Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
39
Artemis/ColorBox/BaseSelector.cs
Normal file
39
Artemis/ColorBox/BaseSelector.cs
Normal file
@ -0,0 +1,39 @@
|
||||
/***************** NCore Softwares Pvt. Ltd., India **************************
|
||||
|
||||
ColorBox
|
||||
|
||||
Copyright (C) 2013 NCore Softwares Pvt. Ltd.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://colorbox.codeplex.com/license
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace ColorBox
|
||||
{
|
||||
public abstract class BaseSelector : FrameworkElement
|
||||
{
|
||||
public static readonly DependencyProperty OrientationProperty =
|
||||
DependencyProperty.Register("Orientation", typeof(Orientation), typeof(BaseSelector),
|
||||
new UIPropertyMetadata(Orientation.Vertical));
|
||||
|
||||
public static readonly DependencyProperty ColorProperty =
|
||||
DependencyProperty.Register("Color", typeof(Color), typeof(BaseSelector), new UIPropertyMetadata(Colors.Red));
|
||||
|
||||
public Orientation Orientation
|
||||
{
|
||||
get { return (Orientation) GetValue(OrientationProperty); }
|
||||
set { SetValue(OrientationProperty, value); }
|
||||
}
|
||||
|
||||
public Color Color
|
||||
{
|
||||
get { return (Color) GetValue(ColorProperty); }
|
||||
protected set { SetValue(ColorProperty, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Artemis/ColorBox/BrushTypes.cs
Normal file
21
Artemis/ColorBox/BrushTypes.cs
Normal file
@ -0,0 +1,21 @@
|
||||
/***************** NCore Softwares Pvt. Ltd., India **************************
|
||||
|
||||
ColorBox
|
||||
|
||||
Copyright (C) 2013 NCore Softwares Pvt. Ltd.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://colorbox.codeplex.com/license
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
namespace ColorBox
|
||||
{
|
||||
internal enum BrushTypes
|
||||
{
|
||||
None,
|
||||
Solid,
|
||||
Linear,
|
||||
Radial
|
||||
}
|
||||
}
|
||||
916
Artemis/ColorBox/ColorBox.cs
Normal file
916
Artemis/ColorBox/ColorBox.cs
Normal file
@ -0,0 +1,916 @@
|
||||
/***************** NCore Softwares Pvt. Ltd., India **************************
|
||||
|
||||
ColorBox
|
||||
|
||||
Copyright (C) 2013 NCore Softwares Pvt. Ltd.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://colorbox.codeplex.com/license
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace ColorBox
|
||||
{
|
||||
[TemplatePart(Name = PartCurrentColor, Type = typeof(TextBox))]
|
||||
public class ColorBox : Control
|
||||
{
|
||||
internal const string PartCurrentColor = "PART_CurrentColor";
|
||||
|
||||
public static RoutedCommand RemoveGradientStop = new RoutedCommand();
|
||||
public static RoutedCommand ReverseGradientStop = new RoutedCommand();
|
||||
public static RoutedCommand DirectionHorizontal = new RoutedCommand();
|
||||
public static RoutedCommand DirectionVertical = new RoutedCommand();
|
||||
public static RoutedCommand DirectionTopLeftBottomRight = new RoutedCommand();
|
||||
public static RoutedCommand DirectionTopRightBottomLeft = new RoutedCommand();
|
||||
internal bool BrushSetInternally;
|
||||
internal bool BrushTypeSetInternally;
|
||||
|
||||
//internal bool _GradientStopSetInternally = false;
|
||||
internal bool HsbSetInternally;
|
||||
internal bool RgbSetInternally;
|
||||
internal bool UpdateBrush = true;
|
||||
|
||||
static ColorBox()
|
||||
{
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(ColorBox), new FrameworkPropertyMetadata(typeof(ColorBox)));
|
||||
}
|
||||
|
||||
internal TextBox CurrentColorTextBox { get; private set; }
|
||||
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
|
||||
CurrentColorTextBox = GetTemplateChild(PartCurrentColor) as TextBox;
|
||||
if (CurrentColorTextBox != null)
|
||||
CurrentColorTextBox.PreviewKeyDown += CurrentColorTextBox_PreviewKeyDown;
|
||||
|
||||
CommandBindings.Add(new CommandBinding(RemoveGradientStop, RemoveGradientStop_Executed));
|
||||
CommandBindings.Add(new CommandBinding(ReverseGradientStop, ReverseGradientStop_Executed));
|
||||
CommandBindings.Add(new CommandBinding(DirectionHorizontal, DirectionHorizontal_Executed));
|
||||
CommandBindings.Add(new CommandBinding(DirectionVertical, DirectionVertical_Executed));
|
||||
CommandBindings.Add(new CommandBinding(DirectionTopLeftBottomRight, DirectionTopLeftBottomRight_Executed));
|
||||
CommandBindings.Add(new CommandBinding(DirectionTopRightBottomLeft, DirectionTopRightBottomLeft_Executed));
|
||||
}
|
||||
|
||||
private void CurrentColorTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.Enter)
|
||||
{
|
||||
var be = CurrentColorTextBox.GetBindingExpression(TextBox.TextProperty);
|
||||
if (be != null)
|
||||
be.UpdateSource();
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveGradientStop_Executed(object sender, ExecutedRoutedEventArgs e)
|
||||
{
|
||||
if ((Gradients != null) && (Gradients.Count > 2))
|
||||
{
|
||||
Gradients.Remove(SelectedGradient);
|
||||
SetBrush();
|
||||
}
|
||||
}
|
||||
|
||||
private void ReverseGradientStop_Executed(object sender, ExecutedRoutedEventArgs e)
|
||||
{
|
||||
UpdateBrush = false;
|
||||
BrushSetInternally = true;
|
||||
foreach (var gs in Gradients)
|
||||
gs.Offset = 1.0 - gs.Offset;
|
||||
UpdateBrush = true;
|
||||
BrushSetInternally = false;
|
||||
SetBrush();
|
||||
}
|
||||
|
||||
private void DirectionHorizontal_Executed(object sender, ExecutedRoutedEventArgs e)
|
||||
{
|
||||
UpdateBrush = false;
|
||||
BrushSetInternally = true;
|
||||
|
||||
StartX = 1.0;
|
||||
StartY = 0.0;
|
||||
EndX = 1.0;
|
||||
EndY = 1.0;
|
||||
|
||||
UpdateBrush = true;
|
||||
BrushSetInternally = false;
|
||||
SetBrush();
|
||||
}
|
||||
|
||||
private void DirectionVertical_Executed(object sender, ExecutedRoutedEventArgs e)
|
||||
{
|
||||
UpdateBrush = false;
|
||||
BrushSetInternally = true;
|
||||
|
||||
StartX = 0.0;
|
||||
StartY = 0.0;
|
||||
EndX = 1.0;
|
||||
EndY = 0.0;
|
||||
|
||||
UpdateBrush = true;
|
||||
BrushSetInternally = false;
|
||||
SetBrush();
|
||||
}
|
||||
|
||||
private void DirectionTopLeftBottomRight_Executed(object sender, ExecutedRoutedEventArgs e)
|
||||
{
|
||||
UpdateBrush = false;
|
||||
BrushSetInternally = true;
|
||||
|
||||
StartX = 0.0;
|
||||
StartY = 1.0;
|
||||
EndX = 1.0;
|
||||
EndY = 0.0;
|
||||
|
||||
UpdateBrush = true;
|
||||
BrushSetInternally = false;
|
||||
SetBrush();
|
||||
}
|
||||
|
||||
private void DirectionTopRightBottomLeft_Executed(object sender, ExecutedRoutedEventArgs e)
|
||||
{
|
||||
UpdateBrush = false;
|
||||
BrushSetInternally = true;
|
||||
|
||||
StartX = 0.0;
|
||||
StartY = 0.0;
|
||||
EndX = 1.0;
|
||||
EndY = 1.0;
|
||||
|
||||
UpdateBrush = true;
|
||||
BrushSetInternally = false;
|
||||
SetBrush();
|
||||
}
|
||||
|
||||
private void InitTransform()
|
||||
{
|
||||
if ((Brush.Transform == null) || Brush.Transform.Value.IsIdentity)
|
||||
{
|
||||
BrushSetInternally = true;
|
||||
|
||||
var tg = new TransformGroup();
|
||||
tg.Children.Add(new RotateTransform());
|
||||
tg.Children.Add(new ScaleTransform());
|
||||
tg.Children.Add(new SkewTransform());
|
||||
tg.Children.Add(new TranslateTransform());
|
||||
Brush.Transform = tg;
|
||||
|
||||
BrushSetInternally = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shared property changed callback to update the Color property
|
||||
/// </summary>
|
||||
public static void UpdateColorHsb(object o, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var c = (ColorBox) o;
|
||||
var n = ColorHelper.ColorFromAhsb(c.Alpha, c.Hue, c.Saturation, c.Brightness);
|
||||
|
||||
c.HsbSetInternally = true;
|
||||
|
||||
c.Color = n;
|
||||
|
||||
if (c.SelectedGradient != null)
|
||||
c.SelectedGradient.Color = n;
|
||||
|
||||
c.SetBrush();
|
||||
|
||||
c.HsbSetInternally = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shared property changed callback to update the Color property
|
||||
/// </summary>
|
||||
public static void UpdateColorRgb(object o, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var c = (ColorBox) o;
|
||||
var n = Color.FromArgb((byte) c.A, (byte) c.R, (byte) c.G, (byte) c.B);
|
||||
|
||||
c.RgbSetInternally = true;
|
||||
|
||||
c.Color = n;
|
||||
|
||||
if (c.SelectedGradient != null)
|
||||
c.SelectedGradient.Color = n;
|
||||
|
||||
c.SetBrush();
|
||||
|
||||
c.RgbSetInternally = false;
|
||||
}
|
||||
|
||||
internal void SetBrush()
|
||||
{
|
||||
if (!UpdateBrush)
|
||||
return;
|
||||
|
||||
BrushSetInternally = true;
|
||||
|
||||
// retain old opacity
|
||||
double opacity = 1;
|
||||
TransformGroup tempTg = null;
|
||||
if (Brush != null)
|
||||
{
|
||||
opacity = Brush.Opacity;
|
||||
tempTg = Brush.Transform as TransformGroup;
|
||||
}
|
||||
|
||||
switch (BrushType)
|
||||
{
|
||||
case BrushTypes.None:
|
||||
Brush = null;
|
||||
break;
|
||||
|
||||
case BrushTypes.Solid:
|
||||
|
||||
Brush = new SolidColorBrush(Color);
|
||||
|
||||
break;
|
||||
|
||||
case BrushTypes.Linear:
|
||||
|
||||
var brush = new LinearGradientBrush();
|
||||
foreach (var g in Gradients)
|
||||
brush.GradientStops.Add(new GradientStop(g.Color, g.Offset));
|
||||
brush.StartPoint = new Point(StartX, StartY);
|
||||
brush.EndPoint = new Point(EndX, EndY);
|
||||
brush.MappingMode = MappingMode;
|
||||
brush.SpreadMethod = SpreadMethod;
|
||||
Brush = brush;
|
||||
|
||||
break;
|
||||
|
||||
case BrushTypes.Radial:
|
||||
|
||||
var brush1 = new RadialGradientBrush();
|
||||
foreach (var g in Gradients)
|
||||
brush1.GradientStops.Add(new GradientStop(g.Color, g.Offset));
|
||||
brush1.GradientOrigin = new Point(GradientOriginX, GradientOriginY);
|
||||
brush1.Center = new Point(CenterX, CenterY);
|
||||
brush1.RadiusX = RadiusX;
|
||||
brush1.RadiusY = RadiusY;
|
||||
brush1.MappingMode = MappingMode;
|
||||
brush1.SpreadMethod = SpreadMethod;
|
||||
Brush = brush1;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (BrushType != BrushTypes.None)
|
||||
{
|
||||
Brush.Opacity = opacity; // retain old opacity
|
||||
if (tempTg != null)
|
||||
Brush.Transform = tempTg;
|
||||
}
|
||||
|
||||
BrushSetInternally = false;
|
||||
}
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private double StartX
|
||||
{
|
||||
get { return (double) GetValue(StartXProperty); }
|
||||
set { SetValue(StartXProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty StartXProperty =
|
||||
DependencyProperty.Register("StartX", typeof(double), typeof(ColorBox),
|
||||
new PropertyMetadata(0.5, StartXChanged));
|
||||
|
||||
private static void StartXChanged(DependencyObject property, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
var cp = property as ColorBox;
|
||||
if (cp.Brush is LinearGradientBrush)
|
||||
{
|
||||
cp.BrushSetInternally = true;
|
||||
(cp.Brush as LinearGradientBrush).StartPoint = new Point((double) args.NewValue,
|
||||
(cp.Brush as LinearGradientBrush).StartPoint.Y);
|
||||
cp.BrushSetInternally = false;
|
||||
}
|
||||
}
|
||||
|
||||
private double StartY
|
||||
{
|
||||
get { return (double) GetValue(StartYProperty); }
|
||||
set { SetValue(StartYProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty StartYProperty =
|
||||
DependencyProperty.Register("StartY", typeof(double), typeof(ColorBox),
|
||||
new PropertyMetadata(0.0, StartYChanged));
|
||||
|
||||
private static void StartYChanged(DependencyObject property, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
var cp = property as ColorBox;
|
||||
if (cp.Brush is LinearGradientBrush)
|
||||
{
|
||||
cp.BrushSetInternally = true;
|
||||
(cp.Brush as LinearGradientBrush).StartPoint = new Point(
|
||||
(cp.Brush as LinearGradientBrush).StartPoint.X, (double) args.NewValue);
|
||||
cp.BrushSetInternally = false;
|
||||
}
|
||||
}
|
||||
|
||||
private double EndX
|
||||
{
|
||||
get { return (double) GetValue(EndXProperty); }
|
||||
set { SetValue(EndXProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty EndXProperty =
|
||||
DependencyProperty.Register("EndX", typeof(double), typeof(ColorBox), new PropertyMetadata(0.5, EndXChanged));
|
||||
|
||||
private static void EndXChanged(DependencyObject property, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
var cp = property as ColorBox;
|
||||
if (cp.Brush is LinearGradientBrush)
|
||||
{
|
||||
cp.BrushSetInternally = true;
|
||||
(cp.Brush as LinearGradientBrush).EndPoint = new Point((double) args.NewValue,
|
||||
(cp.Brush as LinearGradientBrush).EndPoint.Y);
|
||||
cp.BrushSetInternally = false;
|
||||
}
|
||||
}
|
||||
|
||||
private double EndY
|
||||
{
|
||||
get { return (double) GetValue(EndYProperty); }
|
||||
set { SetValue(EndYProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty EndYProperty =
|
||||
DependencyProperty.Register("EndY", typeof(double), typeof(ColorBox), new PropertyMetadata(1.0, EndYChanged));
|
||||
|
||||
private static void EndYChanged(DependencyObject property, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
var cp = property as ColorBox;
|
||||
if (cp.Brush is LinearGradientBrush)
|
||||
{
|
||||
cp.BrushSetInternally = true;
|
||||
(cp.Brush as LinearGradientBrush).EndPoint = new Point((cp.Brush as LinearGradientBrush).EndPoint.X,
|
||||
(double) args.NewValue);
|
||||
cp.BrushSetInternally = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private double GradientOriginX
|
||||
{
|
||||
get { return (double) GetValue(GradientOriginXProperty); }
|
||||
set { SetValue(GradientOriginXProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty GradientOriginXProperty =
|
||||
DependencyProperty.Register("GradientOriginX", typeof(double), typeof(ColorBox),
|
||||
new PropertyMetadata(0.5, GradientOriginXChanged));
|
||||
|
||||
private static void GradientOriginXChanged(DependencyObject property, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
var cp = property as ColorBox;
|
||||
if (cp.Brush is RadialGradientBrush)
|
||||
{
|
||||
cp.BrushSetInternally = true;
|
||||
(cp.Brush as RadialGradientBrush).GradientOrigin = new Point((double) args.NewValue,
|
||||
(cp.Brush as RadialGradientBrush).GradientOrigin.Y);
|
||||
cp.BrushSetInternally = false;
|
||||
}
|
||||
}
|
||||
|
||||
private double GradientOriginY
|
||||
{
|
||||
get { return (double) GetValue(GradientOriginYProperty); }
|
||||
set { SetValue(GradientOriginYProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty GradientOriginYProperty =
|
||||
DependencyProperty.Register("GradientOriginY", typeof(double), typeof(ColorBox),
|
||||
new PropertyMetadata(0.5, GradientOriginYChanged));
|
||||
|
||||
private static void GradientOriginYChanged(DependencyObject property, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
var cp = property as ColorBox;
|
||||
if (cp.Brush is RadialGradientBrush)
|
||||
{
|
||||
cp.BrushSetInternally = true;
|
||||
(cp.Brush as RadialGradientBrush).GradientOrigin =
|
||||
new Point((cp.Brush as RadialGradientBrush).GradientOrigin.X, (double) args.NewValue);
|
||||
cp.BrushSetInternally = false;
|
||||
}
|
||||
}
|
||||
|
||||
private double CenterX
|
||||
{
|
||||
get { return (double) GetValue(CenterXProperty); }
|
||||
set { SetValue(CenterXProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty CenterXProperty =
|
||||
DependencyProperty.Register("CenterX", typeof(double), typeof(ColorBox),
|
||||
new PropertyMetadata(0.5, CenterXChanged));
|
||||
|
||||
private static void CenterXChanged(DependencyObject property, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
var cp = property as ColorBox;
|
||||
if (cp.Brush is RadialGradientBrush)
|
||||
{
|
||||
cp.BrushSetInternally = true;
|
||||
(cp.Brush as RadialGradientBrush).Center = new Point((double) args.NewValue,
|
||||
(cp.Brush as RadialGradientBrush).Center.Y);
|
||||
cp.BrushSetInternally = false;
|
||||
}
|
||||
}
|
||||
|
||||
private double CenterY
|
||||
{
|
||||
get { return (double) GetValue(CenterYProperty); }
|
||||
set { SetValue(CenterYProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty CenterYProperty =
|
||||
DependencyProperty.Register("CenterY", typeof(double), typeof(ColorBox),
|
||||
new PropertyMetadata(0.5, CenterYChanged));
|
||||
|
||||
private static void CenterYChanged(DependencyObject property, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
var cp = property as ColorBox;
|
||||
if (cp.Brush is RadialGradientBrush)
|
||||
{
|
||||
cp.BrushSetInternally = true;
|
||||
(cp.Brush as RadialGradientBrush).Center = new Point((cp.Brush as RadialGradientBrush).Center.X,
|
||||
(double) args.NewValue);
|
||||
cp.BrushSetInternally = false;
|
||||
}
|
||||
}
|
||||
|
||||
private double RadiusX
|
||||
{
|
||||
get { return (double) GetValue(RadiusXProperty); }
|
||||
set { SetValue(RadiusXProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty RadiusXProperty =
|
||||
DependencyProperty.Register("RadiusX", typeof(double), typeof(ColorBox),
|
||||
new PropertyMetadata(0.5, RadiusXChanged));
|
||||
|
||||
private static void RadiusXChanged(DependencyObject property, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
var cp = property as ColorBox;
|
||||
if (cp.Brush is RadialGradientBrush)
|
||||
{
|
||||
cp.BrushSetInternally = true;
|
||||
(cp.Brush as RadialGradientBrush).RadiusX = (double) args.NewValue;
|
||||
cp.BrushSetInternally = false;
|
||||
}
|
||||
}
|
||||
|
||||
private double RadiusY
|
||||
{
|
||||
get { return (double) GetValue(RadiusYProperty); }
|
||||
set { SetValue(RadiusYProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty RadiusYProperty =
|
||||
DependencyProperty.Register("RadiusY", typeof(double), typeof(ColorBox),
|
||||
new PropertyMetadata(0.5, RadiusYChanged));
|
||||
|
||||
private static void RadiusYChanged(DependencyObject property, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
var cp = property as ColorBox;
|
||||
if (cp.Brush is RadialGradientBrush)
|
||||
{
|
||||
cp.BrushSetInternally = true;
|
||||
(cp.Brush as RadialGradientBrush).RadiusY = (double) args.NewValue;
|
||||
cp.BrushSetInternally = false;
|
||||
}
|
||||
}
|
||||
|
||||
private double BrushOpacity
|
||||
{
|
||||
get { return (double) GetValue(BrushOpacityProperty); }
|
||||
set { SetValue(BrushOpacityProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty BrushOpacityProperty =
|
||||
DependencyProperty.Register("BrushOpacity", typeof(double), typeof(ColorBox), new PropertyMetadata(1.0));
|
||||
|
||||
//static void BrushOpacityChanged(DependencyObject property, DependencyPropertyChangedEventArgs args)
|
||||
//{
|
||||
// ColorBox cp = property as ColorBox;
|
||||
// cp._BrushSetInternally = true;
|
||||
// cp.Brush.Opacity = (double)args.NewValue;
|
||||
// cp._BrushSetInternally = false;
|
||||
//}
|
||||
|
||||
private GradientSpreadMethod SpreadMethod
|
||||
{
|
||||
get { return (GradientSpreadMethod) GetValue(SpreadMethodProperty); }
|
||||
set { SetValue(SpreadMethodProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty SpreadMethodProperty =
|
||||
DependencyProperty.Register("SpreadMethod", typeof(GradientSpreadMethod), typeof(ColorBox),
|
||||
new PropertyMetadata(GradientSpreadMethod.Pad, SpreadMethodChanged));
|
||||
|
||||
private static void SpreadMethodChanged(DependencyObject property, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
var cp = property as ColorBox;
|
||||
if (cp.Brush is GradientBrush)
|
||||
{
|
||||
cp.BrushSetInternally = true;
|
||||
(cp.Brush as GradientBrush).SpreadMethod = (GradientSpreadMethod) args.NewValue;
|
||||
cp.BrushSetInternally = false;
|
||||
}
|
||||
}
|
||||
|
||||
private BrushMappingMode MappingMode
|
||||
{
|
||||
get { return (BrushMappingMode) GetValue(MappingModeProperty); }
|
||||
set { SetValue(MappingModeProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty MappingModeProperty =
|
||||
DependencyProperty.Register("MappingMode", typeof(BrushMappingMode), typeof(ColorBox),
|
||||
new PropertyMetadata(BrushMappingMode.RelativeToBoundingBox, MappingModeChanged));
|
||||
|
||||
private static void MappingModeChanged(DependencyObject property, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
var cp = property as ColorBox;
|
||||
if (cp.Brush is GradientBrush)
|
||||
{
|
||||
cp.BrushSetInternally = true;
|
||||
(cp.Brush as GradientBrush).MappingMode = (BrushMappingMode) args.NewValue;
|
||||
cp.BrushSetInternally = false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Properties
|
||||
|
||||
internal ObservableCollection<GradientStop> Gradients
|
||||
{
|
||||
get { return (ObservableCollection<GradientStop>) GetValue(GradientsProperty); }
|
||||
set { SetValue(GradientsProperty, value); }
|
||||
}
|
||||
|
||||
internal static readonly DependencyProperty GradientsProperty =
|
||||
DependencyProperty.Register("Gradients", typeof(ObservableCollection<GradientStop>), typeof(ColorBox));
|
||||
|
||||
internal GradientStop SelectedGradient
|
||||
{
|
||||
get { return (GradientStop) GetValue(SelectedGradientProperty); }
|
||||
set { SetValue(SelectedGradientProperty, value); }
|
||||
}
|
||||
|
||||
internal static readonly DependencyProperty SelectedGradientProperty =
|
||||
DependencyProperty.Register("SelectedGradient", typeof(GradientStop), typeof(ColorBox));
|
||||
|
||||
internal BrushTypes BrushType
|
||||
{
|
||||
get { return (BrushTypes) GetValue(BrushTypeProperty); }
|
||||
set { SetValue(BrushTypeProperty, value); }
|
||||
}
|
||||
|
||||
internal static readonly DependencyProperty BrushTypeProperty =
|
||||
DependencyProperty.Register("BrushType", typeof(BrushTypes), typeof(ColorBox),
|
||||
new FrameworkPropertyMetadata(BrushTypes.None, BrushTypeChanged));
|
||||
|
||||
private static void BrushTypeChanged(DependencyObject property, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
var c = property as ColorBox;
|
||||
if (!c.BrushTypeSetInternally)
|
||||
{
|
||||
if (c.Gradients == null)
|
||||
{
|
||||
c.Gradients = new ObservableCollection<GradientStop>();
|
||||
c.Gradients.Add(new GradientStop(Colors.Black, 0));
|
||||
c.Gradients.Add(new GradientStop(Colors.White, 1));
|
||||
}
|
||||
|
||||
c.SetBrush();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public IEnumerable<Enum> SpreadMethodTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
var temp = GradientSpreadMethod.Pad | GradientSpreadMethod.Reflect | GradientSpreadMethod.Repeat;
|
||||
foreach (Enum value in Enum.GetValues(temp.GetType()))
|
||||
if (temp.HasFlag(value))
|
||||
yield return value;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Enum> MappingModeTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
var temp = BrushMappingMode.Absolute | BrushMappingMode.RelativeToBoundingBox;
|
||||
foreach (Enum value in Enum.GetValues(temp.GetType()))
|
||||
if (temp.HasFlag(value))
|
||||
yield return value;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Enum> AvailableBrushTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
var temp = BrushTypes.None | BrushTypes.Solid | BrushTypes.Linear | BrushTypes.Radial;
|
||||
foreach (Enum value in Enum.GetValues(temp.GetType()))
|
||||
if (temp.HasFlag(value))
|
||||
yield return value;
|
||||
}
|
||||
}
|
||||
|
||||
public Brush Brush
|
||||
{
|
||||
get { return (Brush) GetValue(BrushProperty); }
|
||||
set { SetValue(BrushProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty BrushProperty =
|
||||
DependencyProperty.Register("Brush", typeof(Brush), typeof(ColorBox)
|
||||
, new FrameworkPropertyMetadata(null, BrushChanged));
|
||||
|
||||
private static void BrushChanged(DependencyObject property, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
var c = property as ColorBox;
|
||||
var brush = args.NewValue as Brush;
|
||||
|
||||
if (!c.BrushSetInternally)
|
||||
{
|
||||
c.BrushTypeSetInternally = true;
|
||||
|
||||
if (brush == null)
|
||||
{
|
||||
c.BrushType = BrushTypes.None;
|
||||
}
|
||||
else if (brush is SolidColorBrush)
|
||||
{
|
||||
c.BrushType = BrushTypes.Solid;
|
||||
c.Color = (brush as SolidColorBrush).Color;
|
||||
}
|
||||
else if (brush is LinearGradientBrush)
|
||||
{
|
||||
var lgb = brush as LinearGradientBrush;
|
||||
//c.Opacity = lgb.Opacity;
|
||||
c.StartX = lgb.StartPoint.X;
|
||||
c.StartY = lgb.StartPoint.Y;
|
||||
c.EndX = lgb.EndPoint.X;
|
||||
c.EndY = lgb.EndPoint.Y;
|
||||
c.MappingMode = lgb.MappingMode;
|
||||
c.SpreadMethod = lgb.SpreadMethod;
|
||||
c.Gradients = new ObservableCollection<GradientStop>(lgb.GradientStops);
|
||||
c.BrushType = BrushTypes.Linear;
|
||||
//c.Color = lgb.GradientStops.OrderBy(x => x.Offset).Last().Color;
|
||||
//c.SelectedGradient = lgb.GradientStops.OrderBy(x => x.Offset).Last();
|
||||
}
|
||||
else
|
||||
{
|
||||
var rgb = brush as RadialGradientBrush;
|
||||
c.GradientOriginX = rgb.GradientOrigin.X;
|
||||
c.GradientOriginY = rgb.GradientOrigin.Y;
|
||||
c.RadiusX = rgb.RadiusX;
|
||||
c.RadiusY = rgb.RadiusY;
|
||||
c.CenterX = rgb.Center.X;
|
||||
c.CenterY = rgb.Center.Y;
|
||||
c.MappingMode = rgb.MappingMode;
|
||||
c.SpreadMethod = rgb.SpreadMethod;
|
||||
c.Gradients = new ObservableCollection<GradientStop>(rgb.GradientStops);
|
||||
c.BrushType = BrushTypes.Radial;
|
||||
//c.Color = rgb.GradientStops.OrderBy(x => x.Offset).Last().Color;
|
||||
//c.SelectedGradient = rgb.GradientStops.OrderBy(x => x.Offset).Last();
|
||||
}
|
||||
|
||||
c.BrushTypeSetInternally = false;
|
||||
}
|
||||
}
|
||||
|
||||
public Color Color
|
||||
{
|
||||
get { return (Color) GetValue(ColorProperty); }
|
||||
set { SetValue(ColorProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ColorProperty =
|
||||
DependencyProperty.Register("Color", typeof(Color), typeof(ColorBox),
|
||||
new UIPropertyMetadata(Colors.Black, OnColorChanged));
|
||||
|
||||
public static void OnColorChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var c = (ColorBox) o;
|
||||
|
||||
if (e.NewValue is Color)
|
||||
{
|
||||
var color = (Color) e.NewValue;
|
||||
|
||||
if (!c.HsbSetInternally)
|
||||
{
|
||||
// update HSB value based on new value of color
|
||||
|
||||
double h = 0;
|
||||
double s = 0;
|
||||
double b = 0;
|
||||
ColorHelper.HsbFromColor(color, ref h, ref s, ref b);
|
||||
|
||||
c.HsbSetInternally = true;
|
||||
|
||||
c.Alpha = color.A/255d;
|
||||
c.Hue = h;
|
||||
c.Saturation = s;
|
||||
c.Brightness = b;
|
||||
|
||||
c.HsbSetInternally = false;
|
||||
}
|
||||
|
||||
if (!c.RgbSetInternally)
|
||||
{
|
||||
// update RGB value based on new value of color
|
||||
|
||||
c.RgbSetInternally = true;
|
||||
|
||||
c.A = color.A;
|
||||
c.R = color.R;
|
||||
c.G = color.G;
|
||||
c.B = color.B;
|
||||
|
||||
c.RgbSetInternally = false;
|
||||
}
|
||||
|
||||
c.RaiseColorChangedEvent((Color) e.NewValue);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Color Specific Properties
|
||||
|
||||
private double Hue
|
||||
{
|
||||
get { return (double) GetValue(HueProperty); }
|
||||
set { SetValue(HueProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty HueProperty =
|
||||
DependencyProperty.Register("Hue", typeof(double), typeof(ColorBox),
|
||||
new FrameworkPropertyMetadata(1.0, UpdateColorHsb, HueCoerce));
|
||||
|
||||
private static object HueCoerce(DependencyObject d, object hue)
|
||||
{
|
||||
var v = (double) hue;
|
||||
if (v < 0) return 0.0;
|
||||
if (v > 1) return 1.0;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
private double Brightness
|
||||
{
|
||||
get { return (double) GetValue(BrightnessProperty); }
|
||||
set { SetValue(BrightnessProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty BrightnessProperty =
|
||||
DependencyProperty.Register("Brightness", typeof(double), typeof(ColorBox),
|
||||
new FrameworkPropertyMetadata(0.0, UpdateColorHsb, BrightnessCoerce));
|
||||
|
||||
private static object BrightnessCoerce(DependencyObject d, object brightness)
|
||||
{
|
||||
var v = (double) brightness;
|
||||
if (v < 0) return 0.0;
|
||||
if (v > 1) return 1.0;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
private double Saturation
|
||||
{
|
||||
get { return (double) GetValue(SaturationProperty); }
|
||||
set { SetValue(SaturationProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty SaturationProperty =
|
||||
DependencyProperty.Register("Saturation", typeof(double), typeof(ColorBox),
|
||||
new FrameworkPropertyMetadata(0.0, UpdateColorHsb, SaturationCoerce));
|
||||
|
||||
private static object SaturationCoerce(DependencyObject d, object saturation)
|
||||
{
|
||||
var v = (double) saturation;
|
||||
if (v < 0) return 0.0;
|
||||
if (v > 1) return 1.0;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
private double Alpha
|
||||
{
|
||||
get { return (double) GetValue(AlphaProperty); }
|
||||
set { SetValue(AlphaProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty AlphaProperty =
|
||||
DependencyProperty.Register("Alpha", typeof(double), typeof(ColorBox),
|
||||
new FrameworkPropertyMetadata(1.0, UpdateColorHsb, AlphaCoerce));
|
||||
|
||||
private static object AlphaCoerce(DependencyObject d, object alpha)
|
||||
{
|
||||
var v = (double) alpha;
|
||||
if (v < 0) return 0.0;
|
||||
if (v > 1) return 1.0;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
private int A
|
||||
{
|
||||
get { return (int) GetValue(AProperty); }
|
||||
set { SetValue(AProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty AProperty =
|
||||
DependencyProperty.Register("A", typeof(int), typeof(ColorBox),
|
||||
new FrameworkPropertyMetadata(255, UpdateColorRgb, RgbCoerce));
|
||||
|
||||
|
||||
private int R
|
||||
{
|
||||
get { return (int) GetValue(RProperty); }
|
||||
set { SetValue(RProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty RProperty =
|
||||
DependencyProperty.Register("R", typeof(int), typeof(ColorBox),
|
||||
new FrameworkPropertyMetadata(default(int), UpdateColorRgb, RgbCoerce));
|
||||
|
||||
|
||||
private int G
|
||||
{
|
||||
get { return (int) GetValue(GProperty); }
|
||||
set { SetValue(GProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty GProperty =
|
||||
DependencyProperty.Register("G", typeof(int), typeof(ColorBox),
|
||||
new FrameworkPropertyMetadata(default(int), UpdateColorRgb, RgbCoerce));
|
||||
|
||||
|
||||
private int B
|
||||
{
|
||||
get { return (int) GetValue(BProperty); }
|
||||
set { SetValue(BProperty, value); }
|
||||
}
|
||||
|
||||
private static readonly DependencyProperty BProperty =
|
||||
DependencyProperty.Register("B", typeof(int), typeof(ColorBox),
|
||||
new FrameworkPropertyMetadata(default(int), UpdateColorRgb, RgbCoerce));
|
||||
|
||||
|
||||
private static object RgbCoerce(DependencyObject d, object value)
|
||||
{
|
||||
var v = (int) value;
|
||||
if (v < 0) return 0;
|
||||
if (v > 255) return 255;
|
||||
return v;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ColorChanged Event
|
||||
|
||||
public delegate void ColorChangedEventHandler(object sender, ColorChangedEventArgs e);
|
||||
|
||||
public static readonly RoutedEvent ColorChangedEvent =
|
||||
EventManager.RegisterRoutedEvent("ColorChanged", RoutingStrategy.Bubble, typeof(ColorChangedEventHandler),
|
||||
typeof(ColorBox));
|
||||
|
||||
public event ColorChangedEventHandler ColorChanged
|
||||
{
|
||||
add { AddHandler(ColorChangedEvent, value); }
|
||||
remove { RemoveHandler(ColorChangedEvent, value); }
|
||||
}
|
||||
|
||||
private void RaiseColorChangedEvent(Color color)
|
||||
{
|
||||
var newEventArgs = new ColorChangedEventArgs(ColorChangedEvent, color);
|
||||
RaiseEvent(newEventArgs);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
93
Artemis/ColorBox/ColorBox.csproj
Normal file
93
Artemis/ColorBox/ColorBox.csproj
Normal file
@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{40085232-ACED-4CBE-945B-90BA8153C151}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ColorBox</RootNamespace>
|
||||
<AssemblyName>ColorBox</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SccProjectName>SAK</SccProjectName>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccProvider>SAK</SccProvider>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>ColorBox.snk</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xaml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AlphaSelector.cs" />
|
||||
<Compile Include="BaseSelector.cs" />
|
||||
<Compile Include="ColorBox.cs" />
|
||||
<Compile Include="ColorChangedEventArgs.cs" />
|
||||
<Compile Include="BrushTypes.cs" />
|
||||
<Compile Include="DoubleUpDown.cs" />
|
||||
<Compile Include="Enums.cs" />
|
||||
<Compile Include="GradientStopAdder.cs" />
|
||||
<Compile Include="GradientStopSlider.cs" />
|
||||
<Compile Include="HueSelector.cs" />
|
||||
<Compile Include="SaturationBrightnessSelector.cs" />
|
||||
<Compile Include="SpinEventArgs .cs" />
|
||||
<Compile Include="Spinner.cs" />
|
||||
<Compile Include="Utils\TextBoxBehavior.cs" />
|
||||
<Compile Include="UpDownBase.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Utils\ColorHelper.cs" />
|
||||
<Compile Include="Utils\InputValidationErrorEventArgs .cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Include="Themes\Generic.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="ColorBox.snk" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
BIN
Artemis/ColorBox/ColorBox.snk
Normal file
BIN
Artemis/ColorBox/ColorBox.snk
Normal file
Binary file not shown.
27
Artemis/ColorBox/ColorChangedEventArgs.cs
Normal file
27
Artemis/ColorBox/ColorChangedEventArgs.cs
Normal file
@ -0,0 +1,27 @@
|
||||
/***************** NCore Softwares Pvt. Ltd., India **************************
|
||||
|
||||
ColorBox
|
||||
|
||||
Copyright (C) 2013 NCore Softwares Pvt. Ltd.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://colorbox.codeplex.com/license
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace ColorBox
|
||||
{
|
||||
public class ColorChangedEventArgs : RoutedEventArgs
|
||||
{
|
||||
public ColorChangedEventArgs(RoutedEvent routedEvent, Color color)
|
||||
{
|
||||
RoutedEvent = routedEvent;
|
||||
Color = color;
|
||||
}
|
||||
|
||||
public Color Color { get; set; }
|
||||
}
|
||||
}
|
||||
201
Artemis/ColorBox/DoubleUpDown.cs
Normal file
201
Artemis/ColorBox/DoubleUpDown.cs
Normal file
@ -0,0 +1,201 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
|
||||
namespace ColorBox
|
||||
{
|
||||
public class DoubleUpDown : UpDownBase
|
||||
{
|
||||
private readonly FromDecimal _fromDecimal;
|
||||
private readonly Func<double, double, bool> _fromGreaterThan;
|
||||
private readonly Func<double, double, bool> _fromLowerThan;
|
||||
|
||||
private readonly FromText _fromText;
|
||||
|
||||
protected DoubleUpDown(FromText fromText, FromDecimal fromDecimal, Func<double, double, bool> fromLowerThan,
|
||||
Func<double, double, bool> fromGreaterThan)
|
||||
{
|
||||
if (fromText == null)
|
||||
throw new ArgumentNullException("parseMethod");
|
||||
|
||||
if (fromDecimal == null)
|
||||
throw new ArgumentNullException("fromDecimal");
|
||||
|
||||
if (fromLowerThan == null)
|
||||
throw new ArgumentNullException("fromLowerThan");
|
||||
|
||||
if (fromGreaterThan == null)
|
||||
throw new ArgumentNullException("fromGreaterThan");
|
||||
|
||||
_fromText = fromText;
|
||||
_fromDecimal = fromDecimal;
|
||||
_fromLowerThan = fromLowerThan;
|
||||
_fromGreaterThan = fromGreaterThan;
|
||||
}
|
||||
|
||||
protected static void UpdateMetadata(Type type, double? increment, double? minValue, double? maxValue)
|
||||
{
|
||||
DefaultStyleKeyProperty.OverrideMetadata(type, new FrameworkPropertyMetadata(type));
|
||||
IncrementProperty.OverrideMetadata(type, new FrameworkPropertyMetadata(increment));
|
||||
MaximumProperty.OverrideMetadata(type, new FrameworkPropertyMetadata(maxValue));
|
||||
MinimumProperty.OverrideMetadata(type, new FrameworkPropertyMetadata(minValue));
|
||||
}
|
||||
|
||||
private bool IsLowerThan(double? value1, double? value2)
|
||||
{
|
||||
if ((value1 == null) || (value2 == null))
|
||||
return false;
|
||||
|
||||
return _fromLowerThan(value1.Value, value2.Value);
|
||||
}
|
||||
|
||||
private bool IsGreaterThan(double? value1, double? value2)
|
||||
{
|
||||
if ((value1 == null) || (value2 == null))
|
||||
return false;
|
||||
|
||||
return _fromGreaterThan(value1.Value, value2.Value);
|
||||
}
|
||||
|
||||
private bool HandleNullSpin()
|
||||
{
|
||||
if (!Value.HasValue)
|
||||
{
|
||||
var forcedValue = DefaultValue.HasValue
|
||||
? DefaultValue.Value
|
||||
: default(double);
|
||||
|
||||
Value = CoerceValueMinMax(forcedValue);
|
||||
|
||||
return true;
|
||||
}
|
||||
if (!Increment.HasValue)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private double CoerceValueMinMax(double value)
|
||||
{
|
||||
if (IsLowerThan(value, Minimum))
|
||||
return Minimum;
|
||||
if (IsGreaterThan(value, Maximum))
|
||||
return Maximum;
|
||||
return value;
|
||||
}
|
||||
|
||||
private void ValidateDefaultMinMax(double? value)
|
||||
{
|
||||
if (Equals(value, DefaultValue))
|
||||
return;
|
||||
|
||||
if (IsLowerThan(value, Minimum))
|
||||
throw new ArgumentOutOfRangeException("Minimum",
|
||||
string.Format("Value must be greater than MinValue of {0}", Minimum));
|
||||
if (IsGreaterThan(value, Maximum))
|
||||
throw new ArgumentOutOfRangeException("Maximum",
|
||||
string.Format("Value must be less than MaxValue of {0}", Maximum));
|
||||
}
|
||||
|
||||
protected delegate double FromText(string s, NumberStyles style, IFormatProvider provider);
|
||||
|
||||
protected delegate double FromDecimal(decimal d);
|
||||
|
||||
#region Base Class Overrides
|
||||
|
||||
protected override void OnIncrement()
|
||||
{
|
||||
if (!HandleNullSpin())
|
||||
{
|
||||
double? result = Value.Value + Increment.Value;
|
||||
Value = CoerceValueMinMax(result.Value);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDecrement()
|
||||
{
|
||||
if (!HandleNullSpin())
|
||||
{
|
||||
double? result = Value.Value - Increment.Value;
|
||||
Value = CoerceValueMinMax(result.Value);
|
||||
}
|
||||
}
|
||||
|
||||
protected override string ConvertValueToText()
|
||||
{
|
||||
if (Value == null)
|
||||
return string.Empty;
|
||||
|
||||
return Value.Value.ToString(FormatString, CultureInfo);
|
||||
}
|
||||
|
||||
protected override double? ConvertTextToValue(string text)
|
||||
{
|
||||
double? result = 0;
|
||||
|
||||
if (string.IsNullOrEmpty(text))
|
||||
return result;
|
||||
|
||||
var currentValueText = ConvertValueToText();
|
||||
if (Equals(currentValueText, text))
|
||||
return Value;
|
||||
|
||||
result = FormatString.Contains("P")
|
||||
? _fromDecimal(ParsePercent(text, CultureInfo))
|
||||
: _fromText(text, ParsingNumberStyle, CultureInfo);
|
||||
|
||||
ValidateDefaultMinMax(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override void SetValidSpinDirection()
|
||||
{
|
||||
var validDirections = ValidSpinDirections.None;
|
||||
|
||||
if ((Increment != null) && !IsReadOnly)
|
||||
{
|
||||
if (IsLowerThan(Value, Maximum) || !Value.HasValue)
|
||||
validDirections = validDirections | ValidSpinDirections.Increase;
|
||||
|
||||
if (IsGreaterThan(Value, Minimum) || !Value.HasValue)
|
||||
validDirections = validDirections | ValidSpinDirections.Decrease;
|
||||
}
|
||||
|
||||
if (Spinner != null)
|
||||
Spinner.ValidSpinDirection = validDirections;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
static DoubleUpDown()
|
||||
{
|
||||
UpdateMetadata(typeof(DoubleUpDown), 1d, double.NegativeInfinity, double.PositiveInfinity);
|
||||
}
|
||||
|
||||
public DoubleUpDown()
|
||||
: this(double.Parse, decimal.ToDouble, (v1, v2) => v1 < v2, (v1, v2) => v1 > v2)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
43
Artemis/ColorBox/Enums.cs
Normal file
43
Artemis/ColorBox/Enums.cs
Normal file
@ -0,0 +1,43 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
namespace ColorBox
|
||||
{
|
||||
public enum SpinDirection
|
||||
{
|
||||
Increase,
|
||||
Decrease
|
||||
}
|
||||
|
||||
|
||||
public enum ValidSpinDirections
|
||||
{
|
||||
None,
|
||||
Increase,
|
||||
Decrease
|
||||
}
|
||||
|
||||
|
||||
internal enum AllowedSpecialValues
|
||||
{
|
||||
None = 0,
|
||||
NaN = 1,
|
||||
PositiveInfinity = 2,
|
||||
NegativeInfinity = 4,
|
||||
AnyInfinity = PositiveInfinity | NegativeInfinity,
|
||||
Any = NaN | AnyInfinity
|
||||
}
|
||||
}
|
||||
82
Artemis/ColorBox/GradientStopAdder.cs
Normal file
82
Artemis/ColorBox/GradientStopAdder.cs
Normal file
@ -0,0 +1,82 @@
|
||||
/***************** NCore Softwares Pvt. Ltd., India **************************
|
||||
|
||||
ColorBox
|
||||
|
||||
Copyright (C) 2013 NCore Softwares Pvt. Ltd.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://colorbox.codeplex.com/license
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace ColorBox
|
||||
{
|
||||
public class GradientStopAdder : Button
|
||||
{
|
||||
public static readonly DependencyProperty ColorBoxProperty =
|
||||
DependencyProperty.Register("ColorBox", typeof(ColorBox), typeof(GradientStopAdder));
|
||||
|
||||
public ColorBox ColorBox
|
||||
{
|
||||
get { return (ColorBox) GetValue(ColorBoxProperty); }
|
||||
set { SetValue(ColorBoxProperty, value); }
|
||||
}
|
||||
|
||||
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
|
||||
{
|
||||
base.OnPreviewMouseLeftButtonDown(e);
|
||||
|
||||
if (e.Source is GradientStopAdder && (ColorBox != null))
|
||||
{
|
||||
var btn = e.Source as Button;
|
||||
|
||||
var gs = new GradientStop();
|
||||
gs.Offset = Mouse.GetPosition(btn).X/btn.ActualWidth;
|
||||
//_gs.Color = this.ColorBox.Color;
|
||||
gs.Color = GetColorFromImage(e.GetPosition(this));
|
||||
ColorBox.Gradients.Add(gs);
|
||||
ColorBox.SelectedGradient = gs;
|
||||
ColorBox.Color = gs.Color;
|
||||
ColorBox.SetBrush();
|
||||
}
|
||||
}
|
||||
|
||||
private Color GetColorFromImage(Point p)
|
||||
{
|
||||
try
|
||||
{
|
||||
var bounds = VisualTreeHelper.GetDescendantBounds(this);
|
||||
var rtb = new RenderTargetBitmap((int) bounds.Width, (int) bounds.Height, 96, 96, PixelFormats.Default);
|
||||
rtb.Render(this);
|
||||
|
||||
byte[] arr;
|
||||
var png = new PngBitmapEncoder();
|
||||
png.Frames.Add(BitmapFrame.Create(rtb));
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
png.Save(stream);
|
||||
arr = stream.ToArray();
|
||||
}
|
||||
|
||||
BitmapSource bitmap = BitmapFrame.Create(new MemoryStream(arr));
|
||||
|
||||
var pixels = new byte[4];
|
||||
var cb = new CroppedBitmap(bitmap, new Int32Rect((int) p.X, (int) p.Y, 1, 1));
|
||||
cb.CopyPixels(pixels, 4, 0);
|
||||
return Color.FromArgb(pixels[3], pixels[2], pixels[1], pixels[0]);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return ColorBox.Color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
74
Artemis/ColorBox/GradientStopSlider.cs
Normal file
74
Artemis/ColorBox/GradientStopSlider.cs
Normal file
@ -0,0 +1,74 @@
|
||||
/***************** NCore Softwares Pvt. Ltd., India **************************
|
||||
|
||||
ColorBox
|
||||
|
||||
Copyright (C) 2013 NCore Softwares Pvt. Ltd.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://colorbox.codeplex.com/license
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace ColorBox
|
||||
{
|
||||
public class GradientStopSlider : Slider
|
||||
{
|
||||
public static readonly DependencyProperty ColorBoxProperty =
|
||||
DependencyProperty.Register("ColorBox", typeof(ColorBox), typeof(GradientStopSlider));
|
||||
|
||||
public static readonly DependencyProperty SelectedGradientProperty =
|
||||
DependencyProperty.Register("SelectedGradient", typeof(GradientStop), typeof(GradientStopSlider));
|
||||
|
||||
public ColorBox ColorBox
|
||||
{
|
||||
get { return (ColorBox) GetValue(ColorBoxProperty); }
|
||||
set { SetValue(ColorBoxProperty, value); }
|
||||
}
|
||||
|
||||
public GradientStop SelectedGradient
|
||||
{
|
||||
get { return (GradientStop) GetValue(SelectedGradientProperty); }
|
||||
set { SetValue(SelectedGradientProperty, value); }
|
||||
}
|
||||
|
||||
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
|
||||
{
|
||||
base.OnPreviewMouseLeftButtonDown(e);
|
||||
|
||||
if (ColorBox != null)
|
||||
{
|
||||
ColorBox.BrushSetInternally = true;
|
||||
ColorBox.UpdateBrush = false;
|
||||
|
||||
ColorBox.SelectedGradient = SelectedGradient;
|
||||
ColorBox.Color = SelectedGradient.Color;
|
||||
|
||||
ColorBox.UpdateBrush = true;
|
||||
//this.ColorBox._BrushSetInternally = false;
|
||||
|
||||
//e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnValueChanged(double oldValue, double newValue)
|
||||
{
|
||||
base.OnValueChanged(oldValue, newValue);
|
||||
|
||||
if (ColorBox != null)
|
||||
{
|
||||
//this.ColorBox._HSBSetInternally = true;
|
||||
//this.ColorBox._RGBSetInternally = true;
|
||||
ColorBox.BrushSetInternally = true;
|
||||
ColorBox.SetBrush();
|
||||
ColorBox.HsbSetInternally = false;
|
||||
//this.ColorBox._RGBSetInternally = false;
|
||||
//this.ColorBox._BrushSetInternally = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
138
Artemis/ColorBox/HueSelector.cs
Normal file
138
Artemis/ColorBox/HueSelector.cs
Normal file
@ -0,0 +1,138 @@
|
||||
/***************** NCore Softwares Pvt. Ltd., India **************************
|
||||
|
||||
ColorBox
|
||||
|
||||
Copyright (C) 2013 NCore Softwares Pvt. Ltd.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://colorbox.codeplex.com/license
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace ColorBox
|
||||
{
|
||||
public class HueSelector : BaseSelector
|
||||
{
|
||||
public static readonly DependencyProperty HueProperty =
|
||||
DependencyProperty.Register("Hue", typeof(double), typeof(HueSelector),
|
||||
new FrameworkPropertyMetadata(0.0, HueChanged, HueCoerce));
|
||||
|
||||
public static readonly DependencyProperty HueOffsetProperty =
|
||||
DependencyProperty.Register("HueOffset", typeof(double), typeof(HueSelector), new UIPropertyMetadata(0.0));
|
||||
|
||||
public double Hue
|
||||
{
|
||||
get { return (double) GetValue(HueProperty); }
|
||||
set { SetValue(HueProperty, value); }
|
||||
}
|
||||
|
||||
|
||||
public double HueOffset
|
||||
{
|
||||
get { return (double) GetValue(HueOffsetProperty); }
|
||||
private set { SetValue(HueOffsetProperty, value); }
|
||||
}
|
||||
|
||||
public static void HueChanged(object o, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var h = (HueSelector) o;
|
||||
h.SetHueOffset();
|
||||
h.SetColor();
|
||||
}
|
||||
|
||||
public static object HueCoerce(DependencyObject d, object brightness)
|
||||
{
|
||||
var v = (double) brightness;
|
||||
if (v < 0) return 0.0;
|
||||
if (v > 1) return 1.0;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
var p = e.GetPosition(this);
|
||||
|
||||
if (Orientation == Orientation.Vertical)
|
||||
Hue = 1 - p.Y/ActualHeight;
|
||||
else
|
||||
Hue = 1 - p.X/ActualWidth;
|
||||
}
|
||||
base.OnMouseMove(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
var p = e.GetPosition(this);
|
||||
|
||||
if (Orientation == Orientation.Vertical)
|
||||
Hue = 1 - p.Y/ActualHeight;
|
||||
else
|
||||
Hue = 1 - p.X/ActualWidth;
|
||||
}
|
||||
Mouse.Capture(this);
|
||||
base.OnMouseMove(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseButtonEventArgs e)
|
||||
{
|
||||
ReleaseMouseCapture();
|
||||
base.OnMouseUp(e);
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext dc)
|
||||
{
|
||||
var lb = new LinearGradientBrush();
|
||||
|
||||
lb.StartPoint = new Point(0, 0);
|
||||
|
||||
if (Orientation == Orientation.Vertical)
|
||||
lb.EndPoint = new Point(0, 1);
|
||||
else
|
||||
lb.EndPoint = new Point(1, 0);
|
||||
|
||||
lb.GradientStops.Add(new GradientStop(Color.FromRgb(0xFF, 0x00, 0x00), 1.00));
|
||||
lb.GradientStops.Add(new GradientStop(Color.FromRgb(0xFF, 0xFF, 0x00), 0.85));
|
||||
lb.GradientStops.Add(new GradientStop(Color.FromRgb(0x00, 0xFF, 0x00), 0.76));
|
||||
lb.GradientStops.Add(new GradientStop(Color.FromRgb(0x00, 0xFF, 0xFF), 0.50));
|
||||
lb.GradientStops.Add(new GradientStop(Color.FromRgb(0x00, 0x00, 0xFF), 0.33));
|
||||
lb.GradientStops.Add(new GradientStop(Color.FromRgb(0xFF, 0x00, 0xFF), 0.16));
|
||||
lb.GradientStops.Add(new GradientStop(Color.FromRgb(0xFF, 0x00, 0x00), 0.00));
|
||||
|
||||
dc.DrawRectangle(lb, null, new Rect(0, 0, ActualWidth, ActualHeight));
|
||||
|
||||
SetHueOffset();
|
||||
}
|
||||
|
||||
protected override Size ArrangeOverride(Size finalSize)
|
||||
{
|
||||
SetHueOffset();
|
||||
return base.ArrangeOverride(finalSize);
|
||||
}
|
||||
|
||||
|
||||
private void SetHueOffset()
|
||||
{
|
||||
var length = ActualHeight;
|
||||
if (Orientation == Orientation.Horizontal)
|
||||
length = ActualWidth;
|
||||
|
||||
HueOffset = length - length*Hue;
|
||||
}
|
||||
|
||||
private void SetColor()
|
||||
{
|
||||
Color = ColorHelper.ColorFromHsb(Hue, 1, 1);
|
||||
//base.Brush = new SolidColorBrush(Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
38
Artemis/ColorBox/Properties/AssemblyInfo.cs
Normal file
38
Artemis/ColorBox/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,38 @@
|
||||
/***************** NCore Softwares Pvt. Ltd., India **************************
|
||||
|
||||
ColorBox
|
||||
|
||||
Copyright (C) 2013 NCore Softwares Pvt. Ltd.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://colorbox.codeplex.com/license
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Markup;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
|
||||
[assembly: AssemblyTitle("ColorBox Library")]
|
||||
[assembly:
|
||||
AssemblyDescription(
|
||||
"This assembly implements a solid and gradient brush picker control for Windows Presentation Foundation. ")]
|
||||
[assembly: AssemblyCompany("NCore Softwares Pvt. Ltd.")]
|
||||
[assembly: AssemblyProduct("ColorBox")]
|
||||
[assembly: AssemblyCopyright("Copyright © NCore Softwares Pvt. Ltd. 2013")]
|
||||
[assembly: ThemeInfo(ResourceDictionaryLocation.SourceAssembly, ResourceDictionaryLocation.SourceAssembly)]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: AssemblyVersion("1.1")]
|
||||
[assembly: AssemblyFileVersion("1.1")]
|
||||
[assembly: XmlnsPrefix("http://schemas.ncore.com/wpf/xaml/colorbox", "ncore")]
|
||||
[assembly: XmlnsDefinition("http://schemas.ncore.com/wpf/xaml/colorbox", "ColorBox")]
|
||||
189
Artemis/ColorBox/SaturationBrightnessSelector.cs
Normal file
189
Artemis/ColorBox/SaturationBrightnessSelector.cs
Normal file
@ -0,0 +1,189 @@
|
||||
/***************** NCore Softwares Pvt. Ltd., India **************************
|
||||
|
||||
ColorBox
|
||||
|
||||
Copyright (C) 2013 NCore Softwares Pvt. Ltd.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://colorbox.codeplex.com/license
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace ColorBox
|
||||
{
|
||||
public class SaturationBrightnessSelector : BaseSelector
|
||||
{
|
||||
public static readonly DependencyProperty OffsetPaddingProperty =
|
||||
DependencyProperty.Register("OffsetPadding", typeof(Thickness), typeof(SaturationBrightnessSelector),
|
||||
new UIPropertyMetadata(new Thickness(0.0)));
|
||||
|
||||
public static readonly DependencyProperty HueProperty =
|
||||
DependencyProperty.Register("Hue", typeof(double), typeof(SaturationBrightnessSelector), new
|
||||
FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender, HueChanged));
|
||||
|
||||
public static readonly DependencyProperty SaturationOffsetProperty =
|
||||
DependencyProperty.Register("SaturationOffset", typeof(double), typeof(SaturationBrightnessSelector),
|
||||
new UIPropertyMetadata(0.0));
|
||||
|
||||
public static readonly DependencyProperty SaturationProperty =
|
||||
DependencyProperty.Register("Saturation", typeof(double), typeof(SaturationBrightnessSelector),
|
||||
new FrameworkPropertyMetadata(0.0, SaturationChanged, SaturationCoerce));
|
||||
|
||||
public static readonly DependencyProperty BrightnessOffsetProperty =
|
||||
DependencyProperty.Register("BrightnessOffset", typeof(double), typeof(SaturationBrightnessSelector),
|
||||
new UIPropertyMetadata(0.0));
|
||||
|
||||
public static readonly DependencyProperty BrightnessProperty =
|
||||
DependencyProperty.Register("Brightness", typeof(double), typeof(SaturationBrightnessSelector),
|
||||
new FrameworkPropertyMetadata(0.0, BrightnessChanged, BrightnessCoerce));
|
||||
|
||||
public Thickness OffsetPadding
|
||||
{
|
||||
get { return (Thickness) GetValue(OffsetPaddingProperty); }
|
||||
set { SetValue(OffsetPaddingProperty, value); }
|
||||
}
|
||||
|
||||
|
||||
public double Hue
|
||||
{
|
||||
private get { return (double) GetValue(HueProperty); }
|
||||
set { SetValue(HueProperty, value); }
|
||||
}
|
||||
|
||||
|
||||
public double SaturationOffset
|
||||
{
|
||||
get { return (double) GetValue(SaturationOffsetProperty); }
|
||||
set { SetValue(SaturationOffsetProperty, value); }
|
||||
}
|
||||
|
||||
|
||||
public double Saturation
|
||||
{
|
||||
get { return (double) GetValue(SaturationProperty); }
|
||||
set { SetValue(SaturationProperty, value); }
|
||||
}
|
||||
|
||||
|
||||
public double BrightnessOffset
|
||||
{
|
||||
get { return (double) GetValue(BrightnessOffsetProperty); }
|
||||
set { SetValue(BrightnessOffsetProperty, value); }
|
||||
}
|
||||
|
||||
|
||||
public double Brightness
|
||||
{
|
||||
get { return (double) GetValue(BrightnessProperty); }
|
||||
set { SetValue(BrightnessProperty, value); }
|
||||
}
|
||||
|
||||
public static void HueChanged(object o, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var h = (SaturationBrightnessSelector) o;
|
||||
h.SetColor();
|
||||
}
|
||||
|
||||
public static void SaturationChanged(object o, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var h = (SaturationBrightnessSelector) o;
|
||||
h.SetSaturationOffset();
|
||||
}
|
||||
|
||||
public static object SaturationCoerce(DependencyObject d, object brightness)
|
||||
{
|
||||
var v = (double) brightness;
|
||||
if (v < 0) return 0.0;
|
||||
if (v > 1) return 1.0;
|
||||
return v;
|
||||
}
|
||||
|
||||
public static void BrightnessChanged(object o, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var h = (SaturationBrightnessSelector) o;
|
||||
h.SetBrightnessOffset();
|
||||
}
|
||||
|
||||
public static object BrightnessCoerce(DependencyObject d, object brightness)
|
||||
{
|
||||
var v = (double) brightness;
|
||||
if (v < 0) return 0.0;
|
||||
if (v > 1) return 1.0;
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
var p = e.GetPosition(this);
|
||||
Saturation = p.X/(ActualWidth - OffsetPadding.Right);
|
||||
Brightness = (ActualHeight - OffsetPadding.Bottom - p.Y)/(ActualHeight - OffsetPadding.Bottom);
|
||||
SetColor();
|
||||
}
|
||||
base.OnMouseMove(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseButtonEventArgs e)
|
||||
{
|
||||
var p = e.GetPosition(this);
|
||||
Saturation = p.X/(ActualWidth - OffsetPadding.Right);
|
||||
Brightness = (ActualHeight - OffsetPadding.Bottom - p.Y)/(ActualHeight - OffsetPadding.Bottom);
|
||||
SetColor();
|
||||
|
||||
Mouse.Capture(this);
|
||||
base.OnMouseDown(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseButtonEventArgs e)
|
||||
{
|
||||
ReleaseMouseCapture();
|
||||
base.OnMouseUp(e);
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext dc)
|
||||
{
|
||||
var h = new LinearGradientBrush();
|
||||
h.StartPoint = new Point(0, 0);
|
||||
h.EndPoint = new Point(1, 0);
|
||||
h.GradientStops.Add(new GradientStop(Colors.White, 0.00));
|
||||
h.GradientStops.Add(new GradientStop(ColorHelper.ColorFromHsb(Hue, 1, 1), 1.0));
|
||||
dc.DrawRectangle(h, null, new Rect(0, 0, ActualWidth, ActualHeight));
|
||||
|
||||
var v = new LinearGradientBrush();
|
||||
v.StartPoint = new Point(0, 0);
|
||||
v.EndPoint = new Point(0, 1);
|
||||
v.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0, 0, 0), 1.00));
|
||||
v.GradientStops.Add(new GradientStop(Color.FromArgb(0x80, 0, 0, 0), 0.50));
|
||||
v.GradientStops.Add(new GradientStop(Color.FromArgb(0x00, 0, 0, 0), 0.00));
|
||||
dc.DrawRectangle(v, null, new Rect(0, 0, ActualWidth, ActualHeight));
|
||||
|
||||
SetSaturationOffset();
|
||||
SetBrightnessOffset();
|
||||
}
|
||||
|
||||
private void SetSaturationOffset()
|
||||
{
|
||||
SaturationOffset = OffsetPadding.Left +
|
||||
(ActualWidth - (OffsetPadding.Right + OffsetPadding.Left))*Saturation;
|
||||
}
|
||||
|
||||
private void SetBrightnessOffset()
|
||||
{
|
||||
BrightnessOffset = OffsetPadding.Top +
|
||||
(ActualHeight - (OffsetPadding.Bottom + OffsetPadding.Top) -
|
||||
(ActualHeight - (OffsetPadding.Bottom + OffsetPadding.Top))*Brightness);
|
||||
}
|
||||
|
||||
public void SetColor()
|
||||
{
|
||||
Color = ColorHelper.ColorFromHsb(Hue, Saturation, Brightness);
|
||||
//Brush = new SolidColorBrush(Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
30
Artemis/ColorBox/SpinEventArgs .cs
Normal file
30
Artemis/ColorBox/SpinEventArgs .cs
Normal file
@ -0,0 +1,30 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System.Windows;
|
||||
|
||||
namespace ColorBox
|
||||
{
|
||||
public class SpinEventArgs : RoutedEventArgs
|
||||
{
|
||||
public SpinEventArgs(SpinDirection direction)
|
||||
{
|
||||
Direction = direction;
|
||||
}
|
||||
|
||||
public SpinDirection Direction { get; private set; }
|
||||
}
|
||||
}
|
||||
56
Artemis/ColorBox/Spinner.cs
Normal file
56
Artemis/ColorBox/Spinner.cs
Normal file
@ -0,0 +1,56 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace ColorBox
|
||||
{
|
||||
public class Spinner : ContentControl
|
||||
{
|
||||
public static readonly DependencyProperty ValidSpinDirectionProperty =
|
||||
DependencyProperty.Register("ValidSpinDirection", typeof(ValidSpinDirections), typeof(Spinner),
|
||||
new PropertyMetadata(ValidSpinDirections.Increase | ValidSpinDirections.Decrease,
|
||||
OnValidSpinDirectionPropertyChanged));
|
||||
|
||||
static Spinner()
|
||||
{
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(Spinner), new FrameworkPropertyMetadata(typeof(Spinner)));
|
||||
}
|
||||
|
||||
public ValidSpinDirections ValidSpinDirection
|
||||
{
|
||||
get { return (ValidSpinDirections) GetValue(ValidSpinDirectionProperty); }
|
||||
set { SetValue(ValidSpinDirectionProperty, value); }
|
||||
}
|
||||
|
||||
public static void OnValidSpinDirectionPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var oldvalue = (ValidSpinDirections) e.OldValue;
|
||||
var newvalue = (ValidSpinDirections) e.NewValue;
|
||||
}
|
||||
|
||||
public event EventHandler<SpinEventArgs> Spin;
|
||||
|
||||
public virtual void OnSpin(SpinEventArgs e)
|
||||
{
|
||||
var handler = Spin;
|
||||
if (handler != null)
|
||||
handler(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
759
Artemis/ColorBox/Themes/Generic.xaml
Normal file
759
Artemis/ColorBox/Themes/Generic.xaml
Normal file
@ -0,0 +1,759 @@
|
||||
<!--***************** NCore Softwares Pvt. Ltd., India **************************
|
||||
|
||||
ColorBox
|
||||
|
||||
Copyright (C) 2013 NCore Softwares Pvt. Ltd.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://colorbox.codeplex.com/license
|
||||
|
||||
*********************************************************************************** -->
|
||||
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:ColorBox">
|
||||
|
||||
<Geometry x:Key="SkewIcon">M456.021,227.816L545.590,227.816L456.021,362.171L366.452,362.171L456.021,227.816</Geometry>
|
||||
<Geometry x:Key="TranslateIcon">M384,289.828L384,363L457.171,363M384,363L457.171,289.828M480,267L480,310.011L435.711,267L480,267</Geometry>
|
||||
<Geometry x:Key="RotateIcon">F1 M 32.0034,13.0019L 35.0033,16.002L 35.0034,24.0019L 27.0033,24.002L 24.0034,21.0019L 29.5944,21.0014C 28.2209,19.4668 26.2249,18.501 24.0033,18.501C 19.8606,18.501 16.5022,21.8593 16.5022,26.002C 16.5022,28.0734 17.3418,29.9486 18.6992,31.3061L 16.2241,33.7812C 14.2332,31.7903 13.0018,29.0399 13.0018,26.0019C 13.0018,19.926 17.9274,15.0004 24.0033,15.0004C 27.1557,15.0004 29.9984,16.3263 32.0042,18.4508L 32.0034,13.0019 Z</Geometry>
|
||||
<Geometry x:Key="ScaleIcon">F1 M 28,13L 36,13L 36,21L 33,24L 33,18.5L 24,27.5L 21.5,25L 30.5,16L 25,16L 28,13 Z M 13,18L 26,18L 23,21L 16,21L 16,33L 28,33L 28,26L 31,23L 31,36L 13,36L 13,18 Z</Geometry>
|
||||
<Geometry x:Key="CenterIcon">M502.672,272.601C502.672,298.366 481.785,319.252 456.021,319.252 430.257,319.252 409.370,298.366 409.370,272.601 409.370,246.837 430.257,225.950 456.021,225.950 481.785,225.950 502.672,246.837 502.672,272.601zM502.672,272.601C502.672,298.366 481.785,319.252 456.021,319.252 430.257,319.252 409.370,298.366 409.370,272.601 409.370,246.837 430.257,225.950 456.021,225.950 481.785,225.950 502.672,246.837 502.672,272.601zM470.531,272.601C470.531,280.615 464.035,287.111 456.021,287.111 448.007,287.111 441.511,280.615 441.511,272.601 441.511,264.588 448.007,258.091 456.021,258.091 464.035,258.091 470.531,264.588 470.531,272.601z</Geometry>
|
||||
<Geometry x:Key="FlipIcon">M384,267L384,363L480,363M384,363L459.026,286.973L438,267L479.000,267L479.000,307.000L459.026,286.973</Geometry>
|
||||
|
||||
<BooleanToVisibilityConverter x:Key="BoolToVis" />
|
||||
|
||||
<VisualBrush x:Key="AlphaBrush" Stretch="None" TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,8,8">
|
||||
<VisualBrush.Visual>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="4" />
|
||||
<ColumnDefinition Width="4" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="4" />
|
||||
<RowDefinition Height="4" />
|
||||
</Grid.RowDefinitions>
|
||||
<Rectangle Fill="#FFF" Grid.Row="0" Grid.Column="0" />
|
||||
<Rectangle Fill="#AAA" Grid.Row="0" Grid.Column="1" />
|
||||
<Rectangle Fill="#AAA" Grid.Row="1" Grid.Column="0" />
|
||||
<Rectangle Fill="#FFF" Grid.Row="1" Grid.Column="1" />
|
||||
</Grid>
|
||||
</VisualBrush.Visual>
|
||||
</VisualBrush>
|
||||
|
||||
<Style TargetType="Path" x:Key="IconStyle">
|
||||
<Setter Property="Height" Value="16" />
|
||||
<Setter Property="Width" Value="16" />
|
||||
<Setter Property="Fill" Value="#000000" />
|
||||
<Setter Property="Stretch" Value="Fill" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="Slider" x:Key="OpacitySliderStyle">
|
||||
<Setter Property="Value"
|
||||
Value="{Binding Brush.Opacity, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" />
|
||||
<Setter Property="IsMoveToPointEnabled" Value="True" />
|
||||
<Setter Property="Margin" Value="2" />
|
||||
<Setter Property="Minimum" Value="0" />
|
||||
<Setter Property="Maximum" Value="1" />
|
||||
</Style>
|
||||
|
||||
<!-- Gradient Stop Thumb Style -->
|
||||
<Style x:Key="SliderThumbStyle" TargetType="Thumb">
|
||||
<Setter Property="SnapsToDevicePixels" Value="True" />
|
||||
<Setter Property="BorderBrush" Value="#000000" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Thumb">
|
||||
<Grid>
|
||||
<Path Data="M468.9,240 A71.7,71.7,0,1,0,593, 240 M468.9,240 L531,152 L593,240"
|
||||
Height="16" Width="14" Stretch="Fill"
|
||||
Fill="#FFFFFF" Stroke="{TemplateBinding BorderBrush}" />
|
||||
|
||||
<Path Data="M468.9,240 A71.7,71.7,0,1,0,593,240 M468.9,240 L531,152 L593,240"
|
||||
Height="12" Width="8" Stretch="Fill"
|
||||
Fill="{TemplateBinding Background}" />
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- Gradient Stop Slider Style -->
|
||||
<Style x:Key="GradientStopSliderStyle" TargetType="Slider">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Slider">
|
||||
<Track x:Name="PART_Track">
|
||||
<Track.Thumb>
|
||||
<Thumb Style="{StaticResource SliderThumbStyle}"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}" />
|
||||
</Track.Thumb>
|
||||
</Track>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
|
||||
<!-- ******* DoubleUpDown ******* -->
|
||||
|
||||
<Style x:Key="NumericUpDown" TargetType="{x:Type local:UpDownBase}">
|
||||
<Setter Property="SnapsToDevicePixels" Value="True" />
|
||||
<Setter Property="Foreground" Value="#000000" />
|
||||
<Setter Property="Background" Value="#FFFFFF" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="IsTabStop" Value="False" />
|
||||
<Setter Property="Margin" Value="2" />
|
||||
<Setter Property="Padding" Value="5,1" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="local:UpDownBase">
|
||||
<local:Spinner IsTabStop="False"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}">
|
||||
|
||||
<TextBox x:Name="PART_TextBox"
|
||||
FocusVisualStyle="{x:Null}"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
ContextMenu="{TemplateBinding ContextMenu}"
|
||||
FontFamily="{TemplateBinding FontFamily}"
|
||||
FontSize="{TemplateBinding FontSize}"
|
||||
FontStretch="{TemplateBinding FontStretch}"
|
||||
FontStyle="{TemplateBinding FontStyle}"
|
||||
FontWeight="{TemplateBinding FontWeight}"
|
||||
Foreground="{TemplateBinding Foreground}"
|
||||
IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
MinWidth="20"
|
||||
AcceptsReturn="False"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
TabIndex="{TemplateBinding TabIndex}"
|
||||
local:TextBoxBehavior.SelectAllTextOnFocus="True" />
|
||||
</local:Spinner>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style TargetType="{x:Type local:DoubleUpDown}" BasedOn="{StaticResource NumericUpDown}">
|
||||
<Setter Property="Increment" Value=".1" />
|
||||
<Setter Property="FormatString" Value="F1" />
|
||||
</Style>
|
||||
|
||||
|
||||
<!-- ******* Spinner ******* -->
|
||||
|
||||
<Style TargetType="{x:Type local:Spinner}">
|
||||
<Setter Property="SnapsToDevicePixels" Value="True" />
|
||||
<Setter Property="Background" Value="#FFFFFF" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="Focusable" Value="False" />
|
||||
<Setter Property="IsTabStop" Value="True" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type local:Spinner}">
|
||||
<Border Background="{TemplateBinding Background}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}">
|
||||
<ContentPresenter />
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
|
||||
<!-- ******* ColorBox ******* -->
|
||||
<Style TargetType="{x:Type local:ColorBox}">
|
||||
<Setter Property="SnapsToDevicePixels" Value="True" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="Background" Value="#E7E8E8" />
|
||||
<Setter Property="BorderBrush" Value="#000000" />
|
||||
<Setter Property="VerticalAlignment" Value="Top" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type local:ColorBox}">
|
||||
<Border x:Name="PART_Root"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}">
|
||||
<Border.InputBindings>
|
||||
<KeyBinding Key="Delete" Command="{x:Static local:ColorBox.RemoveGradientStop}" />
|
||||
</Border.InputBindings>
|
||||
|
||||
<StackPanel Margin="5">
|
||||
|
||||
<StackPanel.Resources>
|
||||
<Style x:Key="TbStyle" TargetType="TextBlock">
|
||||
<Setter Property="Margin" Value="2" />
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
</Style>
|
||||
</StackPanel.Resources>
|
||||
|
||||
<ListBox x:Name="listAvailableBrushType"
|
||||
HorizontalContentAlignment="Center"
|
||||
SelectedItem="{Binding BrushType, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
|
||||
ItemsSource="{Binding AvailableBrushTypes, RelativeSource={RelativeSource TemplatedParent}}">
|
||||
<ListBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<UniformGrid Rows="1" Columns="4" />
|
||||
</ItemsPanelTemplate>
|
||||
</ListBox.ItemsPanel>
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ListBoxItem">
|
||||
<Border x:Name="Border" Background="Transparent" Padding="0,3">
|
||||
<Path x:Name="Icon" Height="12" Width="20" Stretch="Fill"
|
||||
Fill="#FF403C3C" StrokeThickness="1" Stroke="#000000"
|
||||
Data="M371,190L557,190 557,293 371,293 371,190z" />
|
||||
</Border>
|
||||
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="Gray"
|
||||
TargetName="Border" />
|
||||
<Setter Property="Foreground" Value="#FFFFFF" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="Background" Value="Gray"
|
||||
TargetName="Border" />
|
||||
<Setter Property="Foreground" Value="#FFFFFF" />
|
||||
</Trigger>
|
||||
|
||||
<DataTrigger Binding="{Binding}" Value="None">
|
||||
<Setter Property="ToolTip" Value="No Brush" />
|
||||
<Setter Property="StrokeThickness" TargetName="Icon"
|
||||
Value="0" />
|
||||
<Setter TargetName="Icon" Property="Data">
|
||||
<Setter.Value>
|
||||
<Geometry>M612,189L452.949,189L452.949,266.024L612,189 M612,196.999L452.949,273.999L612,273.999L612,196.999</Geometry>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding}" Value="Solid">
|
||||
<Setter Property="ToolTip" Value="Solid Color Brush" />
|
||||
<Setter Property="Fill" TargetName="Icon" Value="#FF403C3C" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding}" Value="Linear">
|
||||
<Setter Property="ToolTip" Value="Linear Gradient Brush" />
|
||||
<Setter Property="Fill" TargetName="Icon">
|
||||
<Setter.Value>
|
||||
<LinearGradientBrush StartPoint="0,.5"
|
||||
EndPoint="1,.5">
|
||||
<GradientStop Color="#FF403C3C" Offset="0" />
|
||||
<GradientStop Color="#FFFFFF" Offset="1" />
|
||||
</LinearGradientBrush>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding}" Value="Radial">
|
||||
<Setter Property="ToolTip" Value="Radial Gradient Brush" />
|
||||
<Setter Property="Fill" TargetName="Icon">
|
||||
<Setter.Value>
|
||||
<RadialGradientBrush>
|
||||
<GradientStop Color="#FF403C3C" Offset="1" />
|
||||
<GradientStop Color="#FFFFFF" />
|
||||
</RadialGradientBrush>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</DataTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
|
||||
</ListBox>
|
||||
|
||||
<ScrollViewer Margin="0,5,0,5" HorizontalScrollBarVisibility="Disabled"
|
||||
VerticalScrollBarVisibility="Disabled">
|
||||
<ScrollViewer.Style>
|
||||
<Style TargetType="ScrollViewer">
|
||||
<Style.Triggers>
|
||||
<DataTrigger
|
||||
Binding="{Binding ElementName=listAvailableBrushType, Path=SelectedValue}"
|
||||
Value="None">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ScrollViewer.Style>
|
||||
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="5" />
|
||||
<ColumnDefinition Width="20" />
|
||||
<ColumnDefinition Width="5" />
|
||||
<ColumnDefinition Width="20" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- saturation / brightness selector -->
|
||||
<Grid Grid.Column="0" ClipToBounds="true">
|
||||
<local:SaturationBrightnessSelector x:Name="SV" MinHeight="128"
|
||||
Saturation="{Binding Path=Saturation,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Brightness="{Binding Path=Brightness,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Hue="{Binding ElementName=H,Path=Hue}" />
|
||||
|
||||
<Grid VerticalAlignment="Top" HorizontalAlignment="Left" Margin="-6,-6,0,0"
|
||||
Width="12" Height="12">
|
||||
<Ellipse Stroke="#000000" />
|
||||
<Ellipse Stroke="#FFFFFF" Margin="1" />
|
||||
<Grid.RenderTransform>
|
||||
<TranslateTransform X="{Binding ElementName=SV,Path=SaturationOffset}"
|
||||
Y="{Binding ElementName=SV,Path=BrightnessOffset}" />
|
||||
</Grid.RenderTransform>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<!-- hue selector -->
|
||||
<local:HueSelector x:Name="H" Grid.Column="2"
|
||||
Hue="{Binding Path=Hue,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
<Path Grid.Column="2" HorizontalAlignment="Left" Margin="0,-5,0,5" Stroke="#FFFFFF"
|
||||
Fill="#000000" Data="M 0 0 L 7 5 L 0 10Z">
|
||||
<Path.RenderTransform>
|
||||
<TranslateTransform Y="{Binding ElementName=H,Path=HueOffset}" />
|
||||
</Path.RenderTransform>
|
||||
</Path>
|
||||
<Path Grid.Column="2" HorizontalAlignment="Right" Margin="0,-5,0,5"
|
||||
Stroke="#FFFFFF" Fill="#000000" Data="M 0 5 L 7 0 L 7 10 Z">
|
||||
<Path.RenderTransform>
|
||||
<TranslateTransform Y="{Binding ElementName=H,Path=HueOffset}" />
|
||||
</Path.RenderTransform>
|
||||
</Path>
|
||||
|
||||
<!-- alpha selector -->
|
||||
<Rectangle Grid.Column="4" Fill="{StaticResource AlphaBrush}" />
|
||||
<local:AlphaSelector x:Name="A" Grid.Column="4"
|
||||
Alpha="{Binding Path=Alpha,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
<Path Grid.Column="4" HorizontalAlignment="Left" Margin="0,-5,0,5" Stroke="#FFFFFF"
|
||||
Fill="#000000" Data="M 0 0 L 7 5 L 0 10Z">
|
||||
<Path.RenderTransform>
|
||||
<TranslateTransform Y="{Binding ElementName=A,Path=AlphaOffset}" />
|
||||
</Path.RenderTransform>
|
||||
</Path>
|
||||
<Path Grid.Column="4" HorizontalAlignment="Right" Margin="0,-5,0,5"
|
||||
Stroke="#FFFFFF" Fill="#000000" Data="M 0 5 L 7 0 L 7 10 Z">
|
||||
<Path.RenderTransform>
|
||||
<TranslateTransform Y="{Binding ElementName=A,Path=AlphaOffset}" />
|
||||
</Path.RenderTransform>
|
||||
</Path>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
|
||||
<Grid Height="20">
|
||||
|
||||
<!-- Hide when brush type is None -->
|
||||
<Grid.Style>
|
||||
<Style TargetType="Grid">
|
||||
<Style.Triggers>
|
||||
<DataTrigger
|
||||
Binding="{Binding ElementName=listAvailableBrushType, Path=SelectedValue}"
|
||||
Value="None">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Grid.Style>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="5" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Rectangle>
|
||||
<Rectangle.Fill>
|
||||
<SolidColorBrush
|
||||
Color="{Binding Color, RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
</Rectangle.Fill>
|
||||
</Rectangle>
|
||||
|
||||
<TextBox x:Name="PART_CurrentColor"
|
||||
Text="{Binding Color, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
local:TextBoxBehavior.SelectAllTextOnFocus="True"
|
||||
Grid.Column="2" MinWidth="100">
|
||||
<TextBox.Style>
|
||||
<Style TargetType="TextBox">
|
||||
<Setter Property="BorderBrush"
|
||||
Value="{Binding BorderBrush, RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="TextBox">
|
||||
<Border BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="1" Padding="0">
|
||||
<ScrollViewer x:Name="PART_ContentHost" Margin="0" />
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</TextBox.Style>
|
||||
</TextBox>
|
||||
|
||||
</Grid>
|
||||
|
||||
<Grid Margin="0,5,0,0" Focusable="False">
|
||||
|
||||
<Grid.Style>
|
||||
<Style TargetType="Grid">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger
|
||||
Binding="{Binding ElementName=listAvailableBrushType, Path=SelectedValue}"
|
||||
Value="Linear">
|
||||
<Setter Property="Visibility" Value="Visible" />
|
||||
</DataTrigger>
|
||||
<DataTrigger
|
||||
Binding="{Binding ElementName=listAvailableBrushType, Path=SelectedValue}"
|
||||
Value="Radial">
|
||||
<Setter Property="Visibility" Value="Visible" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Grid.Style>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="5" />
|
||||
<ColumnDefinition Width="Auto" MinWidth="45" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Grid.Column="0" Focusable="False">
|
||||
|
||||
<!-- Click to add gradient stop -->
|
||||
<local:GradientStopAdder Height="20" Margin="7,0"
|
||||
Focusable="False"
|
||||
IsTabStop="False"
|
||||
FocusVisualStyle="{x:Null}"
|
||||
ColorBox="{Binding RelativeSource={RelativeSource TemplatedParent}}">
|
||||
<local:GradientStopAdder.Background>
|
||||
<LinearGradientBrush
|
||||
GradientStops="{Binding Brush.GradientStops, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
StartPoint="0,.5" EndPoint="1,.5" />
|
||||
</local:GradientStopAdder.Background>
|
||||
<Button.Style>
|
||||
<Style TargetType="Button">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Border BorderThickness="0"
|
||||
Background="{TemplateBinding Background}" />
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
</local:GradientStopAdder>
|
||||
|
||||
<!-- gradient stops -->
|
||||
<ListBox x:Name="lbGradientStops"
|
||||
ItemsSource="{Binding Path=Gradients, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
SelectedItem="{Binding SelectedGradient,RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Background="{x:Null}" Style="{x:Null}" BorderThickness="0"
|
||||
FocusVisualStyle="{x:Null}" Focusable="False" IsTabStop="False">
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
|
||||
<Setter Property="IsTabStop" Value="False" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ListBoxItem">
|
||||
<local:GradientStopSlider x:Name="PART_Slider"
|
||||
BorderBrush="#000000"
|
||||
IsTabStop="False"
|
||||
Style="{StaticResource GradientStopSliderStyle}"
|
||||
Value="{Binding Offset}"
|
||||
Minimum="0" Maximum="1"
|
||||
ColorBox="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ColorBox}}}"
|
||||
SelectedGradient="{Binding}"
|
||||
Margin="0,0,0,2">
|
||||
<local:GradientStopSlider.Background>
|
||||
<SolidColorBrush Color="{Binding Color}" />
|
||||
</local:GradientStopSlider.Background>
|
||||
</local:GradientStopSlider>
|
||||
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="BorderBrush"
|
||||
TargetName="PART_Slider" Value="Orange" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="BorderBrush"
|
||||
TargetName="PART_Slider" Value="Blue" />
|
||||
<Setter Property="Effect" TargetName="PART_Slider">
|
||||
<Setter.Value>
|
||||
<DropShadowEffect ShadowDepth="2"
|
||||
BlurRadius="2"
|
||||
Direction="270" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
|
||||
<ListBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Grid IsItemsHost="True" />
|
||||
</ItemsPanelTemplate>
|
||||
</ListBox.ItemsPanel>
|
||||
|
||||
</ListBox>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
<Button Grid.Column="2"
|
||||
Command="{x:Static local:ColorBox.ReverseGradientStop}"
|
||||
Background="Transparent"
|
||||
BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
ToolTip="Reverse gradient stops">
|
||||
<Button.Style>
|
||||
<Style TargetType="Button">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Border Name="Border"
|
||||
BorderThickness="1"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
Background="{TemplateBinding Background}">
|
||||
<Path x:Name="Icon"
|
||||
Data="F1 M 10.0001,27L 10,16L 29.25,16L 25,12L 31.5,12L 38,18L 31.5,24L 25,24L 29.25,20L 14,20L 14,23.5L 10.0001,27 Z M 38,21L 38,32L 18.75,32L 23,36L 16.5,36L 10,30L 16.5,24L 23,24L 18.75,28L 34,28L 34,24.5L 38,21 Z"
|
||||
StrokeThickness="0" Fill="#000000" Height="16"
|
||||
Width="20" Stretch="Fill" />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="Icon" Property="Fill">
|
||||
<Setter.Value>
|
||||
<SolidColorBrush
|
||||
Color="{Binding Color, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ColorBox}}}" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="BorderBrush" TargetName="Border">
|
||||
<Setter.Value>
|
||||
<SolidColorBrush
|
||||
Color="{Binding Color, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ColorBox}}}" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
</Button>
|
||||
|
||||
</Grid>
|
||||
|
||||
<StackPanel Margin="0,5,0,0">
|
||||
<StackPanel.Style>
|
||||
<Style TargetType="StackPanel">
|
||||
<Style.Triggers>
|
||||
<DataTrigger
|
||||
Binding="{Binding ElementName=listAvailableBrushType, Path=SelectedValue}"
|
||||
Value="None">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</StackPanel.Style>
|
||||
|
||||
<ToggleButton x:Name="PART_AdditionalPropertyOpen"
|
||||
BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
ToolTip="Additional Properties"
|
||||
Height="20">
|
||||
<ToggleButton.Style>
|
||||
<Style TargetType="ToggleButton">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ToggleButton">
|
||||
<Border x:Name="Border"
|
||||
BorderThickness="1"
|
||||
Background="Transparent"
|
||||
BorderBrush="{TemplateBinding BorderBrush}">
|
||||
<Path x:Name="Icon"
|
||||
Data="M518.000,395.000C509.500,377.166,484.333,306.833,467.000,288C449.666,269.166,405.500,262.000,414,282C422.499,301.999,484.166,408,518.000,408C551.833,408,609,301.999,617.000,282C625.000,262.000,582.500,269.166,566.000,288C549.500,306.833,526.000,377.166,518.000,395.000"
|
||||
Height="12" Width="18"
|
||||
Fill="{TemplateBinding Foreground}"
|
||||
Stretch="Fill"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center"
|
||||
RenderTransformOrigin=".5,.5" />
|
||||
</Border>
|
||||
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter TargetName="Icon" Property="RenderTransform">
|
||||
<Setter.Value>
|
||||
<ScaleTransform ScaleY="-1" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="Icon" Property="Fill">
|
||||
<Setter.Value>
|
||||
<SolidColorBrush
|
||||
Color="{Binding Color, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ColorBox}}}" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ToggleButton.Style>
|
||||
</ToggleButton>
|
||||
|
||||
|
||||
<StackPanel Margin="0,5,0,0"
|
||||
Visibility="{Binding ElementName=PART_AdditionalPropertyOpen, Path=IsChecked, Converter={StaticResource BoolToVis}}">
|
||||
|
||||
<!-- Solid brush -->
|
||||
<DockPanel Margin="0,2">
|
||||
<DockPanel.Style>
|
||||
<Style TargetType="DockPanel">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger
|
||||
Binding="{Binding ElementName=listAvailableBrushType, Path=SelectedValue}"
|
||||
Value="Solid">
|
||||
<Setter Property="Visibility" Value="Visible" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DockPanel.Style>
|
||||
|
||||
<TextBlock Text="Opacity" VerticalAlignment="Center" />
|
||||
<Slider Style="{StaticResource OpacitySliderStyle}" Margin="10,0,0,0" />
|
||||
</DockPanel>
|
||||
|
||||
<!-- Linear brush -->
|
||||
<DockPanel>
|
||||
<DockPanel.Style>
|
||||
<Style TargetType="DockPanel">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger
|
||||
Binding="{Binding ElementName=listAvailableBrushType, Path=SelectedValue}"
|
||||
Value="Linear">
|
||||
<Setter Property="Visibility" Value="Visible" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DockPanel.Style>
|
||||
|
||||
<UniformGrid Rows="5" DockPanel.Dock="Left" Margin="0,0,5,0">
|
||||
<TextBlock Text="Start Point" VerticalAlignment="Center" />
|
||||
<TextBlock Text="End Point" VerticalAlignment="Center" />
|
||||
<TextBlock Text="Mapping Mode" VerticalAlignment="Center" />
|
||||
<TextBlock Text="Spread Method" VerticalAlignment="Center" />
|
||||
<TextBlock Text="Opacity" VerticalAlignment="Center" />
|
||||
</UniformGrid>
|
||||
|
||||
<UniformGrid Rows="5" DockPanel.Dock="Right">
|
||||
<UniformGrid Rows="1">
|
||||
<local:DoubleUpDown
|
||||
Value="{Binding StartX, RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
<local:DoubleUpDown
|
||||
Value="{Binding StartY, RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
</UniformGrid>
|
||||
|
||||
<UniformGrid Rows="1">
|
||||
<local:DoubleUpDown
|
||||
Value="{Binding EndX, RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
<local:DoubleUpDown
|
||||
Value="{Binding EndY, RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
</UniformGrid>
|
||||
|
||||
<ComboBox Margin="2"
|
||||
ItemsSource="{Binding MappingModeTypes, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
SelectedItem="{Binding MappingMode, RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
|
||||
<ComboBox Margin="2"
|
||||
ItemsSource="{Binding SpreadMethodTypes, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
SelectedItem="{Binding SpreadMethod, RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
|
||||
<Slider Style="{StaticResource OpacitySliderStyle}" />
|
||||
</UniformGrid>
|
||||
</DockPanel>
|
||||
|
||||
<!-- Radial brush -->
|
||||
<DockPanel>
|
||||
<DockPanel.Style>
|
||||
<Style TargetType="DockPanel">
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger
|
||||
Binding="{Binding ElementName=listAvailableBrushType, Path=SelectedValue}"
|
||||
Value="Radial">
|
||||
<Setter Property="Visibility" Value="Visible" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DockPanel.Style>
|
||||
|
||||
<UniformGrid Rows="7" DockPanel.Dock="Left" Margin="0,0,5,0">
|
||||
<TextBlock Text="Gradient Origin" VerticalAlignment="Center" />
|
||||
<TextBlock Text="Center" VerticalAlignment="Center" />
|
||||
<TextBlock Text="Radius X" VerticalAlignment="Center" />
|
||||
<TextBlock Text="Radius Y" VerticalAlignment="Center" />
|
||||
<TextBlock Text="Mapping Mode" VerticalAlignment="Center" />
|
||||
<TextBlock Text="Spread Method" VerticalAlignment="Center" />
|
||||
<TextBlock Text="Opacity" VerticalAlignment="Center" />
|
||||
</UniformGrid>
|
||||
|
||||
<UniformGrid Rows="7" DockPanel.Dock="Right">
|
||||
<UniformGrid Rows="1">
|
||||
<local:DoubleUpDown
|
||||
Value="{Binding GradientOriginX, RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
<local:DoubleUpDown
|
||||
Value="{Binding GradientOriginY, RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
</UniformGrid>
|
||||
|
||||
<UniformGrid Rows="1">
|
||||
<local:DoubleUpDown
|
||||
Value="{Binding CenterX, RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
<local:DoubleUpDown
|
||||
Value="{Binding CenterY, RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
</UniformGrid>
|
||||
|
||||
<local:DoubleUpDown
|
||||
Value="{Binding RadiusX, RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
|
||||
<local:DoubleUpDown
|
||||
Value="{Binding RadiusY, RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
|
||||
<ComboBox Margin="2"
|
||||
ItemsSource="{Binding MappingModeTypes, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
SelectedItem="{Binding MappingMode, RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
|
||||
<ComboBox Margin="2"
|
||||
ItemsSource="{Binding SpreadMethodTypes, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
SelectedItem="{Binding SpreadMethod, RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
|
||||
<Slider Style="{StaticResource OpacitySliderStyle}" />
|
||||
</UniformGrid>
|
||||
</DockPanel>
|
||||
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
653
Artemis/ColorBox/UpDownBase.cs
Normal file
653
Artemis/ColorBox/UpDownBase.cs
Normal file
@ -0,0 +1,653 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace ColorBox
|
||||
{
|
||||
[TemplatePart(Name = PartTextBox, Type = typeof(TextBox))]
|
||||
[TemplatePart(Name = PartSpinner, Type = typeof(Spinner))]
|
||||
public abstract class UpDownBase : Control, IValidateInput
|
||||
{
|
||||
#region Event Handlers
|
||||
|
||||
private void OnSpinnerSpin(object sender, SpinEventArgs e)
|
||||
{
|
||||
if (AllowSpin && !IsReadOnly)
|
||||
OnSpin(e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Members
|
||||
|
||||
internal const string PartTextBox = "PART_TextBox";
|
||||
internal const string PartSpinner = "PART_Spinner";
|
||||
private bool _isSyncingTextAndValueProperties;
|
||||
private bool _isTextChangedFromUi;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
internal Spinner Spinner { get; private set; }
|
||||
|
||||
internal TextBox TextBox { get; private set; }
|
||||
|
||||
#region CultureInfo
|
||||
|
||||
public static readonly DependencyProperty CultureInfoProperty = DependencyProperty.Register("CultureInfo",
|
||||
typeof(CultureInfo), typeof(UpDownBase),
|
||||
new UIPropertyMetadata(CultureInfo.CurrentCulture, OnCultureInfoChanged));
|
||||
|
||||
public CultureInfo CultureInfo
|
||||
{
|
||||
get { return (CultureInfo) GetValue(CultureInfoProperty); }
|
||||
set { SetValue(CultureInfoProperty, value); }
|
||||
}
|
||||
|
||||
private static void OnCultureInfoChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var inputBase = o as UpDownBase;
|
||||
if (inputBase != null)
|
||||
inputBase.OnCultureInfoChanged((CultureInfo) e.OldValue, (CultureInfo) e.NewValue);
|
||||
}
|
||||
|
||||
#endregion //CultureInfo
|
||||
|
||||
#region IsReadOnly
|
||||
|
||||
public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register("IsReadOnly",
|
||||
typeof(bool), typeof(UpDownBase), new UIPropertyMetadata(false, OnReadOnlyChanged));
|
||||
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get { return (bool) GetValue(IsReadOnlyProperty); }
|
||||
set { SetValue(IsReadOnlyProperty, value); }
|
||||
}
|
||||
|
||||
private static void OnReadOnlyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var inputBase = o as UpDownBase;
|
||||
if (inputBase != null)
|
||||
inputBase.OnReadOnlyChanged((bool) e.OldValue, (bool) e.NewValue);
|
||||
}
|
||||
|
||||
#endregion //IsReadOnly
|
||||
|
||||
#region Text
|
||||
|
||||
public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string),
|
||||
typeof(UpDownBase),
|
||||
new FrameworkPropertyMetadata(default(string), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
||||
OnTextChanged, null, false, UpdateSourceTrigger.LostFocus));
|
||||
|
||||
public string Text
|
||||
{
|
||||
get { return (string) GetValue(TextProperty); }
|
||||
set { SetValue(TextProperty, value); }
|
||||
}
|
||||
|
||||
private static void OnTextChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var inputBase = o as UpDownBase;
|
||||
if (inputBase != null)
|
||||
inputBase.OnTextChanged((string) e.OldValue, (string) e.NewValue);
|
||||
}
|
||||
|
||||
#endregion //Text
|
||||
|
||||
#region FormatString
|
||||
|
||||
public static readonly DependencyProperty FormatStringProperty = DependencyProperty.Register("FormatString",
|
||||
typeof(string), typeof(UpDownBase), new UIPropertyMetadata(string.Empty, OnFormatStringChanged));
|
||||
|
||||
public string FormatString
|
||||
{
|
||||
get { return (string) GetValue(FormatStringProperty); }
|
||||
set { SetValue(FormatStringProperty, value); }
|
||||
}
|
||||
|
||||
private static void OnFormatStringChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var numericUpDown = o as UpDownBase;
|
||||
if (numericUpDown != null)
|
||||
numericUpDown.OnFormatStringChanged((string) e.OldValue, (string) e.NewValue);
|
||||
}
|
||||
|
||||
protected virtual void OnFormatStringChanged(string oldValue, string newValue)
|
||||
{
|
||||
if (IsInitialized)
|
||||
SyncTextAndValue(false, null);
|
||||
}
|
||||
|
||||
#endregion //FormatString
|
||||
|
||||
#region Increment
|
||||
|
||||
public static readonly DependencyProperty IncrementProperty = DependencyProperty.Register("Increment",
|
||||
typeof(double?), typeof(UpDownBase),
|
||||
new PropertyMetadata(default(double), OnIncrementChanged, OnCoerceIncrement));
|
||||
|
||||
public double? Increment
|
||||
{
|
||||
get { return (double?) GetValue(IncrementProperty); }
|
||||
set { SetValue(IncrementProperty, value); }
|
||||
}
|
||||
|
||||
private static void OnIncrementChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var numericUpDown = o as UpDownBase;
|
||||
if (numericUpDown != null)
|
||||
numericUpDown.OnIncrementChanged((double) e.OldValue, (double) e.NewValue);
|
||||
}
|
||||
|
||||
protected virtual void OnIncrementChanged(double oldValue, double newValue)
|
||||
{
|
||||
if (IsInitialized)
|
||||
SetValidSpinDirection();
|
||||
}
|
||||
|
||||
private static object OnCoerceIncrement(DependencyObject d, object baseValue)
|
||||
{
|
||||
var numericUpDown = d as UpDownBase;
|
||||
if (numericUpDown != null)
|
||||
return numericUpDown.OnCoerceIncrement((double) baseValue);
|
||||
|
||||
return baseValue;
|
||||
}
|
||||
|
||||
protected virtual double? OnCoerceIncrement(double? baseValue)
|
||||
{
|
||||
return baseValue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Maximum
|
||||
|
||||
public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register("Maximum",
|
||||
typeof(double), typeof(UpDownBase),
|
||||
new UIPropertyMetadata(default(double), OnMaximumChanged, OnCoerceMaximum));
|
||||
|
||||
public double Maximum
|
||||
{
|
||||
get { return (double) GetValue(MaximumProperty); }
|
||||
set { SetValue(MaximumProperty, value); }
|
||||
}
|
||||
|
||||
private static void OnMaximumChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var numericUpDown = o as UpDownBase;
|
||||
if (numericUpDown != null)
|
||||
numericUpDown.OnMaximumChanged((double) e.OldValue, (double) e.NewValue);
|
||||
}
|
||||
|
||||
protected virtual void OnMaximumChanged(double oldValue, double newValue)
|
||||
{
|
||||
if (IsInitialized)
|
||||
SetValidSpinDirection();
|
||||
}
|
||||
|
||||
private static object OnCoerceMaximum(DependencyObject d, object baseValue)
|
||||
{
|
||||
var numericUpDown = d as UpDownBase;
|
||||
if (numericUpDown != null)
|
||||
return numericUpDown.OnCoerceMaximum((double) baseValue);
|
||||
|
||||
return baseValue;
|
||||
}
|
||||
|
||||
protected virtual double OnCoerceMaximum(double baseValue)
|
||||
{
|
||||
return baseValue;
|
||||
}
|
||||
|
||||
#endregion //Maximum
|
||||
|
||||
#region Minimum
|
||||
|
||||
public static readonly DependencyProperty MinimumProperty = DependencyProperty.Register("Minimum",
|
||||
typeof(double), typeof(UpDownBase),
|
||||
new UIPropertyMetadata(default(double), OnMinimumChanged, OnCoerceMinimum));
|
||||
|
||||
public double Minimum
|
||||
{
|
||||
get { return (double) GetValue(MinimumProperty); }
|
||||
set { SetValue(MinimumProperty, value); }
|
||||
}
|
||||
|
||||
private static void OnMinimumChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var numericUpDown = o as UpDownBase;
|
||||
if (numericUpDown != null)
|
||||
numericUpDown.OnMinimumChanged((double) e.OldValue, (double) e.NewValue);
|
||||
}
|
||||
|
||||
protected virtual void OnMinimumChanged(double oldValue, double newValue)
|
||||
{
|
||||
if (IsInitialized)
|
||||
SetValidSpinDirection();
|
||||
}
|
||||
|
||||
private static object OnCoerceMinimum(DependencyObject d, object baseValue)
|
||||
{
|
||||
var numericUpDown = d as UpDownBase;
|
||||
if (numericUpDown != null)
|
||||
return numericUpDown.OnCoerceMinimum((double) baseValue);
|
||||
|
||||
return baseValue;
|
||||
}
|
||||
|
||||
protected virtual double? OnCoerceMinimum(double baseValue)
|
||||
{
|
||||
return baseValue;
|
||||
}
|
||||
|
||||
#endregion //Minimum
|
||||
|
||||
#region AllowSpin
|
||||
|
||||
public static readonly DependencyProperty AllowSpinProperty = DependencyProperty.Register("AllowSpin",
|
||||
typeof(bool), typeof(UpDownBase), new UIPropertyMetadata(true));
|
||||
|
||||
public bool AllowSpin
|
||||
{
|
||||
get { return (bool) GetValue(AllowSpinProperty); }
|
||||
set { SetValue(AllowSpinProperty, value); }
|
||||
}
|
||||
|
||||
#endregion //AllowSpin
|
||||
|
||||
#region DefaultValue
|
||||
|
||||
public static readonly DependencyProperty DefaultValueProperty = DependencyProperty.Register("DefaultValue",
|
||||
typeof(double?), typeof(UpDownBase), new UIPropertyMetadata(default(double), OnDefaultValueChanged));
|
||||
|
||||
public double? DefaultValue
|
||||
{
|
||||
get { return (double?) GetValue(DefaultValueProperty); }
|
||||
set { SetValue(DefaultValueProperty, value); }
|
||||
}
|
||||
|
||||
private static void OnDefaultValueChanged(DependencyObject source, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
((UpDownBase) source).OnDefaultValueChanged((double) args.OldValue, (double) args.NewValue);
|
||||
}
|
||||
|
||||
private void OnDefaultValueChanged(double oldValue, double newValue)
|
||||
{
|
||||
if (IsInitialized && string.IsNullOrEmpty(Text))
|
||||
SyncTextAndValue(true, Text);
|
||||
}
|
||||
|
||||
#endregion //DefaultValue
|
||||
|
||||
#region AllowInputSpecialValues
|
||||
|
||||
private static readonly DependencyProperty AllowInputSpecialValuesProperty =
|
||||
DependencyProperty.Register("AllowInputSpecialValues", typeof(AllowedSpecialValues), typeof(UpDownBase),
|
||||
new UIPropertyMetadata(AllowedSpecialValues.None));
|
||||
|
||||
private AllowedSpecialValues AllowInputSpecialValues
|
||||
{
|
||||
get { return (AllowedSpecialValues) GetValue(AllowInputSpecialValuesProperty); }
|
||||
set { SetValue(AllowInputSpecialValuesProperty, value); }
|
||||
}
|
||||
|
||||
#endregion //AllowInputSpecialValues
|
||||
|
||||
#region ParsingNumberStyle
|
||||
|
||||
public static readonly DependencyProperty ParsingNumberStyleProperty =
|
||||
DependencyProperty.Register("ParsingNumberStyle", typeof(NumberStyles), typeof(UpDownBase),
|
||||
new UIPropertyMetadata(NumberStyles.Any));
|
||||
|
||||
public NumberStyles ParsingNumberStyle
|
||||
{
|
||||
get { return (NumberStyles) GetValue(ParsingNumberStyleProperty); }
|
||||
set { SetValue(ParsingNumberStyleProperty, value); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Value
|
||||
|
||||
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(double?),
|
||||
typeof(UpDownBase),
|
||||
new FrameworkPropertyMetadata(default(double), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
||||
OnValueChanged, OnCoerceValue, false, UpdateSourceTrigger.PropertyChanged));
|
||||
|
||||
public double? Value
|
||||
{
|
||||
get { return (double?) GetValue(ValueProperty); }
|
||||
set { SetValue(ValueProperty, value); }
|
||||
}
|
||||
|
||||
private static object OnCoerceValue(DependencyObject o, object basevalue)
|
||||
{
|
||||
return ((UpDownBase) o).OnCoerceValue(basevalue);
|
||||
}
|
||||
|
||||
protected virtual object OnCoerceValue(object newValue)
|
||||
{
|
||||
return newValue;
|
||||
}
|
||||
|
||||
private static void OnValueChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var upDownBase = o as UpDownBase;
|
||||
if (upDownBase != null)
|
||||
upDownBase.OnValueChanged((double) e.OldValue, (double) e.NewValue);
|
||||
}
|
||||
|
||||
protected virtual void OnValueChanged(double oldValue, double newValue)
|
||||
{
|
||||
if (IsInitialized)
|
||||
SyncTextAndValue(false, null);
|
||||
|
||||
SetValidSpinDirection();
|
||||
|
||||
var args = new RoutedPropertyChangedEventArgs<object>(oldValue, newValue);
|
||||
args.RoutedEvent = ValueChangedEvent;
|
||||
RaiseEvent(args);
|
||||
}
|
||||
|
||||
#endregion //Value
|
||||
|
||||
#endregion //Properties
|
||||
|
||||
#region Base Class Overrides
|
||||
|
||||
protected override void OnAccessKey(AccessKeyEventArgs e)
|
||||
{
|
||||
if (TextBox != null)
|
||||
TextBox.Focus();
|
||||
|
||||
base.OnAccessKey(e);
|
||||
}
|
||||
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
|
||||
TextBox = GetTemplateChild(PartTextBox) as TextBox;
|
||||
if (TextBox != null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Text))
|
||||
TextBox.Text = "0.0";
|
||||
else
|
||||
TextBox.Text = Text;
|
||||
|
||||
TextBox.LostFocus += TextBox_LostFocus;
|
||||
TextBox.TextChanged += TextBox_TextChanged;
|
||||
}
|
||||
|
||||
if (Spinner != null)
|
||||
Spinner.Spin -= OnSpinnerSpin;
|
||||
|
||||
Spinner = GetTemplateChild(PartSpinner) as Spinner;
|
||||
|
||||
if (Spinner != null)
|
||||
Spinner.Spin += OnSpinnerSpin;
|
||||
|
||||
SetValidSpinDirection();
|
||||
}
|
||||
|
||||
protected override void OnGotFocus(RoutedEventArgs e)
|
||||
{
|
||||
if (TextBox != null)
|
||||
TextBox.Focus();
|
||||
}
|
||||
|
||||
protected override void OnPreviewKeyDown(KeyEventArgs e)
|
||||
{
|
||||
switch (e.Key)
|
||||
{
|
||||
case Key.Up:
|
||||
{
|
||||
if (AllowSpin && !IsReadOnly)
|
||||
DoIncrement();
|
||||
e.Handled = true;
|
||||
break;
|
||||
}
|
||||
case Key.Down:
|
||||
{
|
||||
if (AllowSpin && !IsReadOnly)
|
||||
DoDecrement();
|
||||
e.Handled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
switch (e.Key)
|
||||
{
|
||||
case Key.Enter:
|
||||
{
|
||||
var commitSuccess = CommitInput();
|
||||
e.Handled = !commitSuccess;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseWheel(MouseWheelEventArgs e)
|
||||
{
|
||||
base.OnMouseWheel(e);
|
||||
|
||||
if (!e.Handled && AllowSpin && !IsReadOnly && TextBox.IsFocused)
|
||||
{
|
||||
if (e.Delta < 0)
|
||||
DoDecrement();
|
||||
else if (0 < e.Delta)
|
||||
DoIncrement();
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnTextChanged(string oldValue, string newValue)
|
||||
{
|
||||
if (IsInitialized)
|
||||
SyncTextAndValue(true, Text);
|
||||
}
|
||||
|
||||
protected void OnCultureInfoChanged(CultureInfo oldValue, CultureInfo newValue)
|
||||
{
|
||||
if (IsInitialized)
|
||||
SyncTextAndValue(false, null);
|
||||
}
|
||||
|
||||
protected void OnReadOnlyChanged(bool oldValue, bool newValue)
|
||||
{
|
||||
SetValidSpinDirection();
|
||||
}
|
||||
|
||||
public void OnSpin(SpinEventArgs e)
|
||||
{
|
||||
if (e == null)
|
||||
throw new ArgumentNullException("e");
|
||||
|
||||
if (e.Direction == SpinDirection.Increase)
|
||||
DoIncrement();
|
||||
else
|
||||
DoDecrement();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
public event InputValidationErrorEventHandler InputValidationError;
|
||||
|
||||
#region ValueChanged Event
|
||||
|
||||
public static readonly RoutedEvent ValueChangedEvent = EventManager.RegisterRoutedEvent("ValueChanged",
|
||||
RoutingStrategy.Bubble, typeof(RoutedPropertyChangedEventHandler<object>), typeof(UpDownBase));
|
||||
|
||||
public event RoutedPropertyChangedEventHandler<object> ValueChanged
|
||||
{
|
||||
add { AddHandler(ValueChangedEvent, value); }
|
||||
remove { RemoveHandler(ValueChangedEvent, value); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion //Events
|
||||
|
||||
#region Methods
|
||||
|
||||
private void DoDecrement()
|
||||
{
|
||||
if (Spinner == null)
|
||||
OnDecrement();
|
||||
}
|
||||
|
||||
private void DoIncrement()
|
||||
{
|
||||
if (Spinner == null)
|
||||
OnIncrement();
|
||||
}
|
||||
|
||||
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_isTextChangedFromUi = true;
|
||||
Text = ((TextBox) sender).Text;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isTextChangedFromUi = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CommitInput();
|
||||
}
|
||||
|
||||
private void RaiseInputValidationError(Exception e)
|
||||
{
|
||||
if (InputValidationError != null)
|
||||
{
|
||||
var args = new InputValidationErrorEventArgs(e);
|
||||
InputValidationError(this, args);
|
||||
if (args.ThrowException)
|
||||
throw args.Exception;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CommitInput()
|
||||
{
|
||||
return SyncTextAndValue(true, Text);
|
||||
}
|
||||
|
||||
protected bool SyncTextAndValue(bool updateValueFromText, string text)
|
||||
{
|
||||
if (_isSyncingTextAndValueProperties)
|
||||
return true;
|
||||
|
||||
_isSyncingTextAndValueProperties = true;
|
||||
var parsedTextIsValid = true;
|
||||
try
|
||||
{
|
||||
if (updateValueFromText)
|
||||
if (string.IsNullOrEmpty(text))
|
||||
Value = DefaultValue;
|
||||
else
|
||||
try
|
||||
{
|
||||
Value = ConvertTextToValue(text);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
parsedTextIsValid = false;
|
||||
|
||||
// From the UI, just allow any input.
|
||||
if (!_isTextChangedFromUi)
|
||||
RaiseInputValidationError(e);
|
||||
}
|
||||
|
||||
// Do not touch the ongoing text input from user.
|
||||
if (!_isTextChangedFromUi)
|
||||
{
|
||||
// Don't replace the empty Text with the non-empty representation of DefaultValue.
|
||||
var shouldKeepEmpty = string.IsNullOrEmpty(Text) && Equals(Value, DefaultValue);
|
||||
if (!shouldKeepEmpty)
|
||||
Text = ConvertValueToText();
|
||||
|
||||
// Sync Text and textBox
|
||||
if (TextBox != null)
|
||||
if (string.IsNullOrEmpty(Text))
|
||||
TextBox.Text = "0.0";
|
||||
else
|
||||
TextBox.Text = Text;
|
||||
}
|
||||
|
||||
if (_isTextChangedFromUi && !parsedTextIsValid)
|
||||
{
|
||||
//// Text input was made from the user and the text
|
||||
//// repesents an invalid value. Disable the spinner
|
||||
//// in this case.
|
||||
if (Spinner != null)
|
||||
Spinner.ValidSpinDirection = ValidSpinDirections.None;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetValidSpinDirection();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isSyncingTextAndValueProperties = false;
|
||||
}
|
||||
return parsedTextIsValid;
|
||||
}
|
||||
|
||||
protected static decimal ParsePercent(string text, IFormatProvider cultureInfo)
|
||||
{
|
||||
var info = NumberFormatInfo.GetInstance(cultureInfo);
|
||||
|
||||
text = text.Replace(info.PercentSymbol, null);
|
||||
|
||||
var result = decimal.Parse(text, NumberStyles.Any, info);
|
||||
result = result/100;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Abstract
|
||||
|
||||
protected abstract double? ConvertTextToValue(string text);
|
||||
protected abstract string ConvertValueToText();
|
||||
protected abstract void OnIncrement();
|
||||
protected abstract void OnDecrement();
|
||||
protected abstract void SetValidSpinDirection();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
209
Artemis/ColorBox/Utils/ColorHelper.cs
Normal file
209
Artemis/ColorBox/Utils/ColorHelper.cs
Normal file
@ -0,0 +1,209 @@
|
||||
/***************** NCore Softwares Pvt. Ltd., India **************************
|
||||
|
||||
ColorBox
|
||||
|
||||
Copyright (C) 2013 NCore Softwares Pvt. Ltd.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://colorbox.codeplex.com/license
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace ColorBox
|
||||
{
|
||||
internal static class ColorHelper
|
||||
{
|
||||
private static readonly char[] HexArray =
|
||||
{
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
|
||||
'E', 'F'
|
||||
};
|
||||
|
||||
public static string MakeValidColorString(string S)
|
||||
{
|
||||
var s = S;
|
||||
|
||||
for (var i = 0; i < s.Length; i++)
|
||||
{
|
||||
var c = s[i];
|
||||
|
||||
if (!((c >= 'a') && (c <= 'f')) && !((c >= 'A') && (c <= 'F')) && !((c >= '0') && (c <= '9')))
|
||||
{
|
||||
s = s.Remove(i, 1);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
if (s.Length > 8) s = s.Substring(0, 8);
|
||||
|
||||
while ((s.Length <= 8) && (s.Length != 3) && (s.Length != 4) && (s.Length != 6) && (s.Length != 8))
|
||||
s = s + "0";
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public static Color ColorFromString(string S)
|
||||
{
|
||||
var s = MakeValidColorString(S);
|
||||
|
||||
byte a = 255;
|
||||
byte r = 0;
|
||||
byte g = 0;
|
||||
byte b = 0;
|
||||
|
||||
if (s.Length == 3)
|
||||
{
|
||||
r = byte.Parse(s.Substring(0, 1) + s.Substring(0, 1), NumberStyles.HexNumber);
|
||||
g = byte.Parse(s.Substring(1, 1) + s.Substring(1, 1), NumberStyles.HexNumber);
|
||||
b = byte.Parse(s.Substring(2, 1) + s.Substring(2, 1), NumberStyles.HexNumber);
|
||||
}
|
||||
|
||||
if (s.Length == 4)
|
||||
{
|
||||
a = byte.Parse(s.Substring(0, 1) + s.Substring(0, 1), NumberStyles.HexNumber);
|
||||
r = byte.Parse(s.Substring(1, 1) + s.Substring(1, 1), NumberStyles.HexNumber);
|
||||
g = byte.Parse(s.Substring(2, 1) + s.Substring(2, 1), NumberStyles.HexNumber);
|
||||
b = byte.Parse(s.Substring(3, 1) + s.Substring(3, 1), NumberStyles.HexNumber);
|
||||
}
|
||||
|
||||
if (s.Length == 6)
|
||||
{
|
||||
r = byte.Parse(s.Substring(0, 2), NumberStyles.HexNumber);
|
||||
g = byte.Parse(s.Substring(1, 2), NumberStyles.HexNumber);
|
||||
b = byte.Parse(s.Substring(2, 2), NumberStyles.HexNumber);
|
||||
}
|
||||
|
||||
if (s.Length == 8)
|
||||
{
|
||||
a = byte.Parse(s.Substring(0, 2), NumberStyles.HexNumber);
|
||||
r = byte.Parse(s.Substring(1, 2), NumberStyles.HexNumber);
|
||||
g = byte.Parse(s.Substring(2, 2), NumberStyles.HexNumber);
|
||||
b = byte.Parse(s.Substring(3, 2), NumberStyles.HexNumber);
|
||||
}
|
||||
|
||||
return Color.FromArgb(a, r, g, b);
|
||||
}
|
||||
|
||||
public static string StringFromColor(Color c)
|
||||
{
|
||||
var bytes = new byte[4] {c.A, c.R, c.G, c.B};
|
||||
|
||||
var chars = new char[bytes.Length*2];
|
||||
|
||||
for (var i = 0; i < bytes.Length; i++)
|
||||
{
|
||||
int b = bytes[i];
|
||||
chars[i*2] = HexArray[b >> 4];
|
||||
chars[i*2 + 1] = HexArray[b & 0xF];
|
||||
}
|
||||
|
||||
return new string(chars);
|
||||
}
|
||||
|
||||
public static Color ColorFromHsb(double H, double S, double b)
|
||||
{
|
||||
double red = 0.0, green = 0.0, blue = 0.0;
|
||||
|
||||
if (S == 0.0)
|
||||
{
|
||||
red = green = blue = b;
|
||||
}
|
||||
else
|
||||
{
|
||||
var h = H*360;
|
||||
while (h >= 360.0)
|
||||
h -= 360.0;
|
||||
|
||||
h = h/60.0;
|
||||
var i = (int) h;
|
||||
|
||||
var f = h - i;
|
||||
var r = b*(1.0 - S);
|
||||
var s = b*(1.0 - S*f);
|
||||
var t = b*(1.0 - S*(1.0 - f));
|
||||
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
red = b;
|
||||
green = t;
|
||||
blue = r;
|
||||
break;
|
||||
case 1:
|
||||
red = s;
|
||||
green = b;
|
||||
blue = r;
|
||||
break;
|
||||
case 2:
|
||||
red = r;
|
||||
green = b;
|
||||
blue = t;
|
||||
break;
|
||||
case 3:
|
||||
red = r;
|
||||
green = s;
|
||||
blue = b;
|
||||
break;
|
||||
case 4:
|
||||
red = t;
|
||||
green = r;
|
||||
blue = b;
|
||||
break;
|
||||
case 5:
|
||||
red = b;
|
||||
green = r;
|
||||
blue = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
byte iRed = (byte) (red*255.0), iGreen = (byte) (green*255.0), iBlue = (byte) (blue*255.0);
|
||||
return Color.FromRgb(iRed, iGreen, iBlue);
|
||||
}
|
||||
|
||||
public static void HsbFromColor(Color c, ref double h, ref double s, ref double b)
|
||||
{
|
||||
var red = c.R;
|
||||
var green = c.G;
|
||||
var blue = c.B;
|
||||
|
||||
int imax = red, imin = red;
|
||||
|
||||
if (green > imax) imax = green;
|
||||
else if (green < imin) imin = green;
|
||||
if (blue > imax) imax = blue;
|
||||
else if (blue < imin) imin = blue;
|
||||
double max = imax/255.0, min = imin/255.0;
|
||||
|
||||
var value = max;
|
||||
var saturation = max > 0 ? (max - min)/max : 0.0;
|
||||
double hue = 0;
|
||||
|
||||
if (imax > imin)
|
||||
{
|
||||
var f = 1.0/((max - min)*255.0);
|
||||
hue = imax == red
|
||||
? 0.0 + f*(green - blue)
|
||||
: imax == green ? 2.0 + f*(blue - red) : 4.0 + f*(red - green);
|
||||
hue = hue*60.0;
|
||||
if (hue < 0.0)
|
||||
hue += 360.0;
|
||||
}
|
||||
|
||||
h = hue/360;
|
||||
s = saturation;
|
||||
b = value;
|
||||
}
|
||||
|
||||
public static Color ColorFromAhsb(double a, double h, double s, double b)
|
||||
{
|
||||
var r = ColorFromHsb(h, s, b);
|
||||
r.A = (byte) Math.Round(a*255);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
}
|
||||
41
Artemis/ColorBox/Utils/InputValidationErrorEventArgs .cs
Normal file
41
Artemis/ColorBox/Utils/InputValidationErrorEventArgs .cs
Normal file
@ -0,0 +1,41 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace ColorBox
|
||||
{
|
||||
public delegate void InputValidationErrorEventHandler(object sender, InputValidationErrorEventArgs e);
|
||||
|
||||
public class InputValidationErrorEventArgs : EventArgs
|
||||
{
|
||||
public InputValidationErrorEventArgs(Exception e)
|
||||
{
|
||||
Exception = e;
|
||||
}
|
||||
|
||||
|
||||
public Exception Exception { get; private set; }
|
||||
|
||||
public bool ThrowException { get; set; }
|
||||
}
|
||||
|
||||
internal interface IValidateInput
|
||||
{
|
||||
event InputValidationErrorEventHandler InputValidationError;
|
||||
bool CommitInput();
|
||||
}
|
||||
}
|
||||
61
Artemis/ColorBox/Utils/TextBoxBehavior.cs
Normal file
61
Artemis/ColorBox/Utils/TextBoxBehavior.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace ColorBox
|
||||
{
|
||||
public class TextBoxBehavior
|
||||
{
|
||||
public static readonly DependencyProperty SelectAllTextOnFocusProperty =
|
||||
DependencyProperty.RegisterAttached(
|
||||
"SelectAllTextOnFocus",
|
||||
typeof(bool),
|
||||
typeof(TextBoxBehavior),
|
||||
new UIPropertyMetadata(false, OnSelectAllTextOnFocusChanged));
|
||||
|
||||
public static bool GetSelectAllTextOnFocus(TextBox textBox)
|
||||
{
|
||||
return (bool) textBox.GetValue(SelectAllTextOnFocusProperty);
|
||||
}
|
||||
|
||||
public static void SetSelectAllTextOnFocus(TextBox textBox, bool value)
|
||||
{
|
||||
textBox.SetValue(SelectAllTextOnFocusProperty, value);
|
||||
}
|
||||
|
||||
private static void OnSelectAllTextOnFocusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var textBox = d as TextBox;
|
||||
if (textBox == null) return;
|
||||
|
||||
if (e.NewValue is bool == false) return;
|
||||
|
||||
if ((bool) e.NewValue)
|
||||
{
|
||||
textBox.GotFocus += SelectAll;
|
||||
textBox.PreviewMouseDown += IgnoreMouseButton;
|
||||
}
|
||||
else
|
||||
{
|
||||
textBox.GotFocus -= SelectAll;
|
||||
textBox.PreviewMouseDown -= IgnoreMouseButton;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SelectAll(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var textBox = e.OriginalSource as TextBox;
|
||||
if (textBox == null) return;
|
||||
textBox.SelectAll();
|
||||
}
|
||||
|
||||
private static void IgnoreMouseButton(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
var textBox = sender as TextBox;
|
||||
if ((textBox == null) || textBox.IsKeyboardFocusWithin) return;
|
||||
|
||||
e.Handled = true;
|
||||
textBox.Focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user