Skip to content

Commit

Permalink
Remove WpfDesigner Dependecy to SD Widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
jogibear9988 committed Oct 5, 2015
1 parent 3e1bd35 commit 57f3c9d
Show file tree
Hide file tree
Showing 24 changed files with 1,844 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
root = true
[*]
indent_style = tab
2 changes: 1 addition & 1 deletion samples/XamlDesigner/Toolbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void LoadSettings()
{
AddAssembly(Environment.ExpandEnvironmentVariables(path), false);
}
catch (Exception ex)
catch (Exception)
{ }
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media.Animation;

namespace ICSharpCode.WpfDesign.Designer.Controls
{
/// <summary>
/// Allows animated collapsing of the content of this panel.
/// </summary>
public class CollapsiblePanel : ContentControl
{
static CollapsiblePanel()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CollapsiblePanel),
new FrameworkPropertyMetadata(typeof(CollapsiblePanel)));
FocusableProperty.OverrideMetadata(typeof(CollapsiblePanel),
new FrameworkPropertyMetadata(false));
}

public static readonly DependencyProperty IsCollapsedProperty = DependencyProperty.Register(
"IsCollapsed", typeof(bool), typeof(CollapsiblePanel),
new UIPropertyMetadata(false, new PropertyChangedCallback(OnIsCollapsedChanged)));

public bool IsCollapsed {
get { return (bool)GetValue(IsCollapsedProperty); }
set { SetValue(IsCollapsedProperty, value); }
}

public static readonly DependencyProperty CollapseOrientationProperty =
DependencyProperty.Register("CollapseOrientation", typeof(Orientation), typeof(CollapsiblePanel),
new FrameworkPropertyMetadata(Orientation.Vertical));

public Orientation CollapseOrientation {
get { return (Orientation)GetValue(CollapseOrientationProperty); }
set { SetValue(CollapseOrientationProperty, value); }
}

public static readonly DependencyProperty DurationProperty = DependencyProperty.Register(
"Duration", typeof(TimeSpan), typeof(CollapsiblePanel),
new UIPropertyMetadata(TimeSpan.FromMilliseconds(250)));

/// <summary>
/// The duration in milliseconds of the animation.
/// </summary>
public TimeSpan Duration {
get { return (TimeSpan)GetValue(DurationProperty); }
set { SetValue(DurationProperty, value); }
}

protected internal static readonly DependencyProperty AnimationProgressProperty = DependencyProperty.Register(
"AnimationProgress", typeof(double), typeof(CollapsiblePanel),
new FrameworkPropertyMetadata(1.0));

/// <summary>
/// Value between 0 and 1 specifying how far the animation currently is.
/// </summary>
protected internal double AnimationProgress {
get { return (double)GetValue(AnimationProgressProperty); }
set { SetValue(AnimationProgressProperty, value); }
}

protected internal static readonly DependencyProperty AnimationProgressXProperty = DependencyProperty.Register(
"AnimationProgressX", typeof(double), typeof(CollapsiblePanel),
new FrameworkPropertyMetadata(1.0));

/// <summary>
/// Value between 0 and 1 specifying how far the animation currently is.
/// </summary>
protected internal double AnimationProgressX {
get { return (double)GetValue(AnimationProgressXProperty); }
set { SetValue(AnimationProgressXProperty, value); }
}

protected internal static readonly DependencyProperty AnimationProgressYProperty = DependencyProperty.Register(
"AnimationProgressY", typeof(double), typeof(CollapsiblePanel),
new FrameworkPropertyMetadata(1.0));

/// <summary>
/// Value between 0 and 1 specifying how far the animation currently is.
/// </summary>
protected internal double AnimationProgressY {
get { return (double)GetValue(AnimationProgressYProperty); }
set { SetValue(AnimationProgressYProperty, value); }
}

static void OnIsCollapsedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((CollapsiblePanel)d).SetupAnimation((bool)e.NewValue);
}

void SetupAnimation(bool isCollapsed)
{
if (this.IsLoaded) {
// If the animation is already running, calculate remaining portion of the time
double currentProgress = AnimationProgress;
if (!isCollapsed) {
currentProgress = 1.0 - currentProgress;
}

DoubleAnimation animation = new DoubleAnimation();
animation.To = isCollapsed ? 0.0 : 1.0;
animation.Duration = TimeSpan.FromSeconds(Duration.TotalSeconds * currentProgress);
animation.FillBehavior = FillBehavior.HoldEnd;

this.BeginAnimation(AnimationProgressProperty, animation);
if (CollapseOrientation == Orientation.Horizontal) {
this.BeginAnimation(AnimationProgressXProperty, animation);
this.AnimationProgressY = 1.0;
} else {
this.AnimationProgressX = 1.0;
this.BeginAnimation(AnimationProgressYProperty, animation);
}
} else {
this.AnimationProgress = isCollapsed ? 0.0 : 1.0;
this.AnimationProgressX = (CollapseOrientation == Orientation.Horizontal) ? this.AnimationProgress : 1.0;
this.AnimationProgressY = (CollapseOrientation == Orientation.Vertical) ? this.AnimationProgress : 1.0;
}
}
}

sealed class CollapsiblePanelProgressToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is double)
return (double)value > 0 ? Visibility.Visible : Visibility.Collapsed;
else
return Visibility.Visible;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}

public class SelfCollapsingPanel : CollapsiblePanel
{
public static readonly DependencyProperty CanCollapseProperty =
DependencyProperty.Register("CanCollapse", typeof(bool), typeof(SelfCollapsingPanel),
new FrameworkPropertyMetadata(false, new PropertyChangedCallback(OnCanCollapseChanged)));

public bool CanCollapse {
get { return (bool)GetValue(CanCollapseProperty); }
set { SetValue(CanCollapseProperty, value); }
}

static void OnCanCollapseChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
SelfCollapsingPanel panel = (SelfCollapsingPanel)d;
if ((bool)e.NewValue) {
if (!panel.HeldOpenByMouse)
panel.IsCollapsed = true;
} else {
panel.IsCollapsed = false;
}
}

bool HeldOpenByMouse {
get { return IsMouseOver || IsMouseCaptureWithin; }
}

protected override void OnMouseLeave(MouseEventArgs e)
{
base.OnMouseLeave(e);
if (CanCollapse && !HeldOpenByMouse)
IsCollapsed = true;
}

protected override void OnLostMouseCapture(MouseEventArgs e)
{
base.OnLostMouseCapture(e);
if (CanCollapse && !HeldOpenByMouse)
IsCollapsed = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

using System;
using System.Windows.Media;

namespace ICSharpCode.WpfDesign.Designer.Controls
{
public static class ColorHelper
{
public static Color ColorFromString(string s)
{
if (string.IsNullOrEmpty(s)) {
return Colors.White;
}
if (s[0] != '#') s = "#" + s;
try {
return (Color)ColorConverter.ConvertFromString(s);
}
catch {
return Colors.White;
}
}

public static string StringFromColor(Color c)
{
return c.ToString().Substring(1);
}

public static Color ColorFromHsv(double h, double s, double v)
{
double r, g, b;
RgbFromHsv(h, s, v, out r, out g, out b);
return Color.FromRgb((byte)(r * 255), (byte)(g * 255), (byte)(b * 255));

}

public static void HsvFromColor(Color c, out double h, out double s, out double v)
{
HsvFromRgb(c.R / 255.0, c.G / 255.0, c.B / 255.0, out h, out s, out v);
}

// http://en.wikipedia.org/wiki/HSV_color_space
public static void HsvFromRgb(double r, double g, double b, out double h, out double s, out double v)
{
var max = Math.Max(r, Math.Max(g, b));
var min = Math.Min(r, Math.Min(g, b));

if (max == min) {
h = 0;
}
else if (max == r) {
h = (60 * (g - b) / (max - min)) % 360;
}
else if (max == g) {
h = 60 * (b - r) / (max - min) + 120;
}
else {
h = 60 * (r - g) / (max - min) + 240;
}

if (h < 0) h += 360; // C# '%' can return negative values, use real modulus instead

if (max == 0) {
s = 0;
}
else {
s = 1 - min / max;
}

v = max;
}

// http://en.wikipedia.org/wiki/HSV_color_space
public static void RgbFromHsv(double h, double s, double v, out double r, out double g, out double b)
{
h = h % 360;
if (h < 0) h += 360; // C# '%' can return negative values, use real modulus instead
int hi = (int)(h / 60) % 6;
var f = h / 60 - (int)(h / 60);
var p = v * (1 - s);
var q = v * (1 - f * s);
var t = v * (1 - (1 - f) * s);

switch (hi) {
case 0: r = v; g = t; b = p; break;
case 1: r = q; g = v; b = p; break;
case 2: r = p; g = v; b = t; break;
case 3: r = p; g = q; b = v; break;
case 4: r = t; g = p; b = v; break;
default: r = v; g = p; b = q; break;
}
}
}
}
Loading

0 comments on commit 57f3c9d

Please sign in to comment.