Added ColorBox source

Added direction buttons functionality
This commit is contained in:
SpoinkyNL committed 2016-10-07 00:01:31 +02:00
1 parent 2657ebd05c
commit ef27b23116
24 files changed
+3846 -9

No files matched your search

+138
View 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);
}
}
}