Skip to content

Commit

Permalink
Gradient changes, RL changes, ColorBox changes
Browse files Browse the repository at this point in the history
  • Loading branch information
antonpup committed Jun 26, 2016
1 parent dcc58ed commit d5c6804
Show file tree
Hide file tree
Showing 38 changed files with 4,193 additions and 730 deletions.
96 changes: 96 additions & 0 deletions ColorBox/ColorBox.csproj
@@ -0,0 +1,96 @@
<?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="Implementation\AlphaSelector.cs" />
<Compile Include="Implementation\BaseSelector.cs" />
<Compile Include="Implementation\BrushChangedEventArgs.cs" />
<Compile Include="Implementation\ColorBox.cs" />
<Compile Include="Implementation\ColorChangedEventArgs.cs" />
<Compile Include="Implementation\DoubleUpDown.cs" />
<Compile Include="Implementation\Enums.cs" />
<Compile Include="Implementation\GradientStopAdder.cs" />
<Compile Include="Implementation\GradientStopSlider.cs" />
<Compile Include="Implementation\HueSelector.cs" />
<Compile Include="Implementation\SaturationBrightnessSelector.cs" />
<Compile Include="Implementation\SpinEventArgs .cs" />
<Compile Include="Implementation\Spinner.cs" />
<Compile Include="Utils\TextBoxBehavior.cs" />
<Compile Include="Implementation\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>
<ItemGroup>
<Content Include="LICENSE.txt" />
</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>
Binary file added ColorBox/ColorBox.snk
Binary file not shown.
138 changes: 138 additions & 0 deletions ColorBox/Implementation/AlphaSelector.cs
@@ -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;
using System.Windows.Media;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace ColorBox
{
class AlphaSelector : BaseSelector
{
public double Alpha
{
get { return (double)GetValue(AlphaProperty); }
set { SetValue(AlphaProperty, value); }
}
public static readonly DependencyProperty AlphaProperty =
DependencyProperty.Register("Alpha", typeof(double), typeof(AlphaSelector),
new FrameworkPropertyMetadata(1.0, new PropertyChangedCallback(AlphaChanged), new CoerceValueCallback(AlphaCoerce)));
public static void AlphaChanged(object o, DependencyPropertyChangedEventArgs e)
{
AlphaSelector h = (AlphaSelector)o;
h.SetAlphaOffset();
h.SetColor();
}
public static object AlphaCoerce(DependencyObject d, object Brightness)
{
double v = (double)Brightness;
if (v < 0) return 0.0;
if (v > 1) return 1.0;
return v;
}


public double AlphaOffset
{
get { return (double)GetValue(AlphaOffsetProperty); }
private set { SetValue(AlphaOffsetProperty, value); }
}
public static readonly DependencyProperty AlphaOffsetProperty =
DependencyProperty.Register("AlphaOffset", typeof(double), typeof(AlphaSelector), new UIPropertyMetadata(0.0));


protected override void OnMouseMove(MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
Point p = e.GetPosition(this);

if (Orientation == Orientation.Vertical)
{
Alpha = 1 - (p.Y / this.ActualHeight);
}
else
{
Alpha = 1 - (p.X / this.ActualWidth);
}
}
base.OnMouseMove(e);
}

protected override void OnMouseDown(MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
Point p = e.GetPosition(this);

if (Orientation == Orientation.Vertical)
{
Alpha = 1 - (p.Y / this.ActualHeight);
}
else
{
Alpha = 1 - (p.X / this.ActualWidth);
}
}
Mouse.Capture(this);
base.OnMouseMove(e);
}

protected override void OnMouseUp(MouseButtonEventArgs e)
{
this.ReleaseMouseCapture();
base.OnMouseUp(e);
}

protected override void OnRender(DrawingContext dc)
{
LinearGradientBrush 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()
{
double 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);
}
}
}
38 changes: 38 additions & 0 deletions ColorBox/Implementation/BaseSelector.cs
@@ -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;
using System.Windows.Media;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace ColorBox
{
abstract class BaseSelector : FrameworkElement
{
public Orientation Orientation
{
get { return (Orientation)GetValue(OrientationProperty); }
set { SetValue(OrientationProperty, value); }
}
public static readonly DependencyProperty OrientationProperty =
DependencyProperty.Register("Orientation", typeof(Orientation), typeof(BaseSelector), new UIPropertyMetadata(Orientation.Vertical));

public Color Color
{
get { return (Color)GetValue(ColorProperty); }
protected set { SetValue(ColorProperty, value); }
}
public static readonly DependencyProperty ColorProperty =
DependencyProperty.Register("Color", typeof(Color), typeof(BaseSelector), new UIPropertyMetadata(Colors.Red));
}
}
22 changes: 22 additions & 0 deletions ColorBox/Implementation/BrushChangedEventArgs.cs
@@ -0,0 +1,22 @@
using System.Windows.Media;
using System.Windows;

namespace ColorBox
{
public class BrushChangedEventArgs : RoutedEventArgs
{
public BrushChangedEventArgs(RoutedEvent routedEvent, Brush brush)
{
this.RoutedEvent = routedEvent;
this.Brush = brush;
}

private Brush _Brush;
public Brush Brush
{
get { return _Brush; }
set { _Brush = value; }
}
}
}

0 comments on commit d5c6804

Please sign in to comment.