├── WPFLight.Android ├── Resources │ └── Resource.Designer.cs └── Properties │ └── AssemblyInfo.cs ├── WPFLight ├── System │ ├── Windows │ │ ├── Controls │ │ │ ├── GameWindow.cs │ │ │ ├── ListBoxItem.cs │ │ │ ├── UserControl.cs │ │ │ ├── ItemCollection.cs │ │ │ ├── Primitives │ │ │ │ ├── TabPanel.cs │ │ │ │ ├── ToggleButton.cs │ │ │ │ └── Selector.cs │ │ │ ├── IDrawable.cs │ │ │ ├── IDrawable3D.cs │ │ │ ├── DataGridItemColleciton.cs │ │ │ ├── IDrawable2D.cs │ │ │ ├── DataGridItem.cs │ │ │ ├── ColumnHeader.cs │ │ │ ├── HeaderedContentControl.cs │ │ │ ├── IFocusable.cs │ │ │ ├── RowDefinition.cs │ │ │ ├── ColumnDefinition.cs │ │ │ ├── TabItem.cs │ │ │ ├── Canvas.cs │ │ │ ├── FocusableControl.cs │ │ │ ├── ItemsControl.cs │ │ │ ├── RepeatButton.cs │ │ │ ├── ListBoxCollection.cs │ │ │ ├── TabControl.cs │ │ │ ├── Image.cs │ │ │ ├── UIElementCollection.cs │ │ │ ├── RadioButton.cs │ │ │ ├── StackPanel.cs │ │ │ ├── Button.cs │ │ │ ├── WrapPanel.cs │ │ │ ├── Panel.cs │ │ │ ├── DialogBox.cs │ │ │ ├── ListBox.cs │ │ │ ├── Plane.cs │ │ │ ├── ScreenBase.cs │ │ │ ├── TrackBar.cs │ │ │ └── NumericUpDown.cs │ │ ├── ResourceDictionary.cs │ │ ├── PropertyChangedCallback.cs │ │ ├── Media │ │ │ ├── GradientStopCollection.cs │ │ │ ├── Animation │ │ │ │ ├── SingleKeyFrame.cs │ │ │ │ ├── IAnimationBase.cs │ │ │ │ ├── Timeline.cs │ │ │ │ ├── SingleAnimation.cs │ │ │ │ ├── Clock.cs │ │ │ │ ├── SingleKeyFrameAnimation.cs │ │ │ │ └── Storyboard.cs │ │ │ ├── DrawingContext.cs │ │ │ ├── GradientStop.cs │ │ │ ├── FontFamily.cs │ │ │ ├── BrushConverter.cs │ │ │ ├── Brush.cs │ │ │ ├── FontFamilyConverter.cs │ │ │ ├── FontContainer.cs │ │ │ ├── VisualTreeHelper.cs │ │ │ ├── ColorConverter.cs │ │ │ ├── ImageBrush.cs │ │ │ ├── SolidColorBrush.cs │ │ │ ├── RadialGradientBrush.cs │ │ │ ├── ColorHelper.cs │ │ │ ├── GradientBrush.cs │ │ │ └── LinearGradientBrush.cs │ │ ├── SetterCollection.cs │ │ ├── TriggerCollection.cs │ │ ├── Markup │ │ │ ├── ContentPropertyAttribute.cs │ │ │ ├── INameScopeDictionary.cs │ │ │ ├── INameScope.cs │ │ │ ├── XmlnsPrefixAttribute.cs │ │ │ └── XmlnsDefinitionAttribute.cs │ │ ├── Data │ │ │ └── BindingOperations.cs │ │ ├── DependencyPropertyChangedEventArgs.cs │ │ ├── Setter.cs │ │ ├── PropertyMetadata.cs │ │ ├── SizeChangedEventArgs.cs │ │ ├── Trigger.cs │ │ ├── PropertyPath.cs │ │ ├── Point.cs │ │ ├── GridLength.cs │ │ ├── GameWindow.cs │ │ ├── Thickness.cs │ │ ├── Size.cs │ │ ├── DependencyProperty.cs │ │ ├── Style.cs │ │ ├── MessageBox.cs │ │ ├── ThicknessConverter.cs │ │ ├── Vector2Converter.cs │ │ ├── Rect.cs │ │ └── Shapes │ │ │ └── Shape.cs │ ├── Collections │ │ ├── Specialized │ │ │ ├── INotifyCollectionChanged.cs │ │ │ ├── NotifyCollectionChangedEventHandler.cs │ │ │ └── NotifyCollectionChangedEventArgs.cs │ │ └── ObjectModel │ │ │ └── ObservableCollection.cs │ ├── ComponentModel │ │ ├── PropertyChangedEventArgs.cs │ │ └── TypeDescriptor.cs │ └── Xaml │ │ ├── NamespaceDeclaration.cs │ │ ├── NameScope.cs │ │ └── XamlReader.cs ├── Content │ ├── ArrowUp.png │ ├── ArrowDown.png │ ├── ArrowLeft.png │ ├── ArrowRight.png │ └── Background.png ├── Extensions │ ├── ArrayExtensions.cs │ └── EnumExtensions.cs ├── Resources │ └── Textures.cs ├── Helpers │ ├── ResourceHelper.cs │ └── ArrayHelper.cs └── Initializer.cs ├── WPFLightGUI.png ├── NOTICE ├── WPFLight.Test ├── Entitlements.plist ├── Tests │ ├── GridTests.cs │ ├── XamlTests.cs │ ├── StyleTests.cs │ └── LayoutTests.cs ├── Main.cs ├── Info.plist └── UnitTestAppDelegate.cs ├── README.md ├── WPFLight.iOS ├── Properties │ └── AssemblyInfo.cs └── Helpers │ └── ResourceHelper.cs ├── WPFLight.Win8 └── Properties │ └── AssemblyInfo.cs ├── WPFLight.XNA └── Properties │ └── AssemblyInfo.cs └── .gitignore /WPFLight.Android/Resources/Resource.Designer.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/GameWindow.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /WPFLightGUI.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ronnycsharp/WPFLight/HEAD/WPFLightGUI.png -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | WPFLight 2 | Copyright 2012-2014 Ronny Weidemann 3 | 4 | github.com/ronnycsharp/WPFLight -------------------------------------------------------------------------------- /WPFLight/Content/ArrowUp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ronnycsharp/WPFLight/HEAD/WPFLight/Content/ArrowUp.png -------------------------------------------------------------------------------- /WPFLight/Content/ArrowDown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ronnycsharp/WPFLight/HEAD/WPFLight/Content/ArrowDown.png -------------------------------------------------------------------------------- /WPFLight/Content/ArrowLeft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ronnycsharp/WPFLight/HEAD/WPFLight/Content/ArrowLeft.png -------------------------------------------------------------------------------- /WPFLight/Content/ArrowRight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ronnycsharp/WPFLight/HEAD/WPFLight/Content/ArrowRight.png -------------------------------------------------------------------------------- /WPFLight/Content/Background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ronnycsharp/WPFLight/HEAD/WPFLight/Content/Background.png -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/ListBoxItem.cs: -------------------------------------------------------------------------------- 1 | namespace System.Windows.Controls { 2 | public class ListBoxItem : RadioButton { } 3 | } 4 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/UserControl.cs: -------------------------------------------------------------------------------- 1 | namespace System.Windows.Controls { 2 | public abstract class UserControl : ContentControl { 3 | 4 | } 5 | } 6 | 7 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/ResourceDictionary.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | namespace System.Windows { 3 | public class ResourceDictionary : Dictionary { 4 | 5 | } 6 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/ItemCollection.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.ObjectModel; 2 | namespace System.Windows.Controls { 3 | public class ItemCollection : ObservableCollection {} 4 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/PropertyChangedCallback.cs: -------------------------------------------------------------------------------- 1 | namespace System.Windows { 2 | public delegate void PropertyChangedCallback( 3 | DependencyObject d, 4 | DependencyPropertyChangedEventArgs e); 5 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/Primitives/TabPanel.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls.Primitives; 2 | namespace System.Windows.Controls { 3 | public class TabControl : Selector { 4 | 5 | } 6 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/GradientStopCollection.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace System.Windows.Media 4 | { 5 | public class GradientStopCollection : List {} 6 | } 7 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/SetterCollection.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.ObjectModel; 2 | using System.Linq; 3 | 4 | namespace System.Windows { 5 | public class SetterCollection : Collection { 6 | 7 | } 8 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/TriggerCollection.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.ObjectModel; 2 | using System.Linq; 3 | 4 | namespace System.Windows { 5 | public class TriggerCollection : Collection { 6 | 7 | } 8 | } -------------------------------------------------------------------------------- /WPFLight.Test/Entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /WPFLight/System/Collections/Specialized/INotifyCollectionChanged.cs: -------------------------------------------------------------------------------- 1 | namespace System.Collections.Specialized { 2 | public interface INotifyCollectionChanged { 3 | event NotifyCollectionChangedEventHandler CollectionChanged; 4 | } 5 | } -------------------------------------------------------------------------------- /WPFLight/System/Collections/Specialized/NotifyCollectionChangedEventHandler.cs: -------------------------------------------------------------------------------- 1 | namespace System.Collections.Specialized { 2 | public delegate void NotifyCollectionChangedEventHandler ( 3 | Object sender, NotifyCollectionChangedEventArgs e ); 4 | } -------------------------------------------------------------------------------- /WPFLight.Test/Tests/GridTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | using NUnit.Framework; 5 | 6 | namespace WPFLight.Test { 7 | [TestFixture] 8 | public class GridTests { 9 | // some Grid layout-testing 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/Animation/SingleKeyFrame.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace System.Windows.Media.Animation 4 | { 5 | public struct SingleKeyFrame { 6 | public SingleKeyFrame ( TimeSpan time, float value ) { 7 | Time = time; 8 | Value = value; 9 | } 10 | 11 | public float Value; 12 | public TimeSpan Time; 13 | } 14 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/IDrawable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace System.Windows.Controls 4 | { 5 | public interface IDrawable 6 | { 7 | float Opacity { get; } 8 | bool Visible { get; } 9 | int DrawOrder { get; } 10 | 11 | event EventHandler DrawOrderChanged; 12 | event EventHandler VisibleChanged; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | WPFLight 2 | ======== 3 | 4 | Version 0.1 5 | 6 | WPFLight is a port of the Windows Presentation Foundation based on Microsoft XNA/MonoGame that allows you to build rich cross-gui applications for Windows Phone, Windows Store, Xamarin.iOS and Xamarin.Android. It's in an early preview state and I use it in my own apps on these platforms. My goal is to use the original namespaces and classes of the WPF. 7 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/IDrawable3D.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.Xna.Framework; 6 | 7 | namespace System.Windows.Controls 8 | { 9 | public interface IDrawable3D : IDrawable 10 | { 11 | void Draw ( GameTime time, Matrix world, Matrix view, Matrix projection, float alpha ); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/DataGridItemColleciton.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace System.Windows.Controls { 7 | public class DataGridItemColleciton : List { 8 | public void Add ( params string[] cells ) { 9 | this.Add ( new DataGridItem ( cells ) ); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /WPFLight/Extensions/ArrayExtensions.cs: -------------------------------------------------------------------------------- 1 | using WPFLight.Helpers; 2 | namespace WPFLight.Extensions { 3 | internal static class ArrayExtensions { 4 | public static void Fill (this T[] array, T value) { 5 | ArrayHelper.ArrayFill(array, value); 6 | } 7 | 8 | public static void Fill (this T[] array, T[] values) { 9 | ArrayHelper.ArrayFill(array, values); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/IDrawable2D.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.Xna.Framework; 6 | using Microsoft.Xna.Framework.Graphics; 7 | 8 | namespace System.Windows.Controls 9 | { 10 | public interface IDrawable2D : IDrawable 11 | { 12 | void Draw ( GameTime gameTime, SpriteBatch batch, float alpha, Matrix transform ); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /WPFLight/System/ComponentModel/PropertyChangedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace System.ComponentModel 4 | { 5 | public class PropertyChangedEventArgs : EventArgs 6 | { 7 | public PropertyChangedEventArgs (T newValue, T oldValue) : base ( ) 8 | { 9 | OldValue = oldValue; 10 | NewValue = newValue; 11 | } 12 | 13 | public T OldValue { get; private set;} 14 | public T NewValue { get; private set;} 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/Animation/IAnimationBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Xna.Framework; 3 | 4 | namespace System.Windows.Media.Animation 5 | { 6 | public interface IAnimationBase 7 | { 8 | void Begin(); 9 | void Begin(TimeSpan beginTime); 10 | void Pause(); 11 | void Resume(); 12 | void Stop(); 13 | void Update(GameTime gameTime); 14 | 15 | TimeSpan BeginTime { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/DataGridItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace System.Windows.Controls { 7 | public class DataGridItem { 8 | public DataGridItem ( params string[] cells ) { 9 | this.Cells = cells; 10 | } 11 | 12 | public double X { get; set; } 13 | public double Y { get; set; } 14 | 15 | public string[] Cells { get; private set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /WPFLight.Test/Main.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using MonoTouch.Foundation; 5 | using MonoTouch.UIKit; 6 | 7 | namespace WPFLight.Test { 8 | public class Application { 9 | // This is the main entry point of the application. 10 | static void Main (string[] args) { 11 | // if you want to use a different Application Delegate class from "UnitTestAppDelegate" 12 | // you can specify it here. 13 | UIApplication.Main (args, null, "UnitTestAppDelegate"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Markup/ContentPropertyAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace System.Windows.Markup { 3 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] 4 | public class ContentPropertyAttribute : Attribute { 5 | public ContentPropertyAttribute () { } 6 | 7 | public ContentPropertyAttribute (string name) { 8 | this.Name = name; 9 | } 10 | 11 | #region Eigenschaften 12 | 13 | public string Name { get; private set; } 14 | 15 | #endregion 16 | } 17 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/ColumnHeader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Xna.Framework; 3 | 4 | namespace System.Windows.Controls 5 | { 6 | public class ColumnHeader : ColumnDefinition { 7 | public ColumnHeader (string text, GridLength width ) : base ( width ) 8 | { 9 | if (width.IsAuto) 10 | throw new NotImplementedException ("Auto"); 11 | 12 | this.TextAlignment = TextAlignment.Left; 13 | this.Text = text; 14 | this.TextColor = Color.White; 15 | } 16 | 17 | public Color TextColor { get; set; } 18 | public TextAlignment TextAlignment { get; set; } 19 | public string Text { get; private set; } 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Data/BindingOperations.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace System.Windows.Data { 8 | public static class BindingOperations { 9 | static BindingOperations ( ) { 10 | 11 | } 12 | 13 | public static void SetBinding ( 14 | DependencyObject target, 15 | DependencyProperty property, 16 | Binding binding ) { 17 | 18 | throw new NotImplementedException ( ); 19 | } 20 | 21 | public static Binding GetBinding ( 22 | DependencyObject target, 23 | DependencyProperty property ) { 24 | throw new NotImplementedException (); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/DependencyPropertyChangedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace System.Windows { 2 | public delegate void DependencyPropertyChangedEventHandler ( object sender, DependencyPropertyChangedEventArgs e ); 3 | public class DependencyPropertyChangedEventArgs { 4 | public DependencyPropertyChangedEventArgs( 5 | DependencyProperty property, object oldValue, object newValue ) { 6 | this.Property = property; 7 | this.OldValue = oldValue; 8 | this.NewValue = newValue; 9 | } 10 | 11 | #region Eigenschaften 12 | 13 | public DependencyProperty Property { get; private set; } 14 | public object OldValue { get; private set; } 15 | public object NewValue { get; private set; } 16 | 17 | #endregion 18 | } 19 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/HeaderedContentControl.cs: -------------------------------------------------------------------------------- 1 | namespace System.Windows.Controls { 2 | public abstract class HeaderedContentControl : ContentControl { 3 | #region Eigenschaften 4 | 5 | public static DependencyProperty HeaderProperty = 6 | DependencyProperty.Register( 7 | "Header", 8 | typeof(Object), 9 | typeof(HeaderedContentControl)); 10 | 11 | public object Header { 12 | get { return (object)GetValue(HeaderProperty); } 13 | set { SetValue(HeaderProperty, value); } 14 | } 15 | 16 | public bool HasHeader { 17 | get { return Header != null; } 18 | } 19 | 20 | #endregion 21 | } 22 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/IFocusable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.Graphics; 8 | using Microsoft.Xna.Framework.Input; 9 | using Microsoft.Xna.Framework.Media; 10 | 11 | 12 | namespace System.Windows 13 | { 14 | public interface IFocusable 15 | { 16 | void Focus ( ); 17 | bool Focused { get; } 18 | bool Focusable { get; } 19 | 20 | event EventHandler LostFocus; 21 | event EventHandler GotFocus; 22 | 23 | void OnGotFocus ( ); 24 | void OnLostFocus ( ); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/Animation/Timeline.cs: -------------------------------------------------------------------------------- 1 | namespace System.Windows.Media.Animation { 2 | public abstract class Timeline : DependencyObject { 3 | public Timeline () { 4 | currentClock = AllocateClock(); 5 | } 6 | 7 | public event EventHandler Completed; 8 | 9 | #region Eigenschaften 10 | 11 | public TimeSpan BeginTime { get; set; } 12 | public TimeSpan Duration { get; set; } 13 | public bool AutoReverse { get; set; } 14 | public int RepeatBehavior { get; set; } 15 | 16 | #endregion 17 | 18 | protected virtual Clock AllocateClock () { 19 | return new Clock(this); 20 | } 21 | 22 | public void BeginAnimation ( ) { 23 | 24 | } 25 | 26 | private Clock currentClock; 27 | } 28 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Setter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace System.Windows { 7 | public class Setter { 8 | public Setter () { 9 | 10 | } 11 | 12 | public Setter ( DependencyProperty property, object value ) { 13 | if (property == null) 14 | throw new ArgumentNullException(); 15 | 16 | this.Property = property; 17 | this.Value = value; 18 | } 19 | 20 | #region Eigenschaften 21 | 22 | public string TargetName { get; internal set; } 23 | public DependencyProperty Property { get; internal set; } 24 | public object Value { get; internal set; } 25 | 26 | #endregion 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/PropertyMetadata.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | namespace System.Windows { 3 | public class PropertyMetadata { 4 | public PropertyMetadata ( ) { } 5 | 6 | public PropertyMetadata ( object defaultValue ) { 7 | this.DefaultValue = defaultValue; 8 | } 9 | 10 | public PropertyMetadata ( object defaultValue, PropertyChangedCallback callback ) { 11 | this.DefaultValue = defaultValue; 12 | this.PropertyChangedCallback = callback; 13 | } 14 | 15 | public PropertyMetadata ( PropertyChangedCallback callback ) { 16 | this.PropertyChangedCallback = callback; 17 | } 18 | 19 | #region Eigenschaften 20 | 21 | public PropertyChangedCallback PropertyChangedCallback { get; set; } 22 | public object DefaultValue { get; set; } 23 | 24 | #endregion 25 | } 26 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/DrawingContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using Microsoft.Xna.Framework.Graphics; 3 | using WPFLight.Helpers; 4 | namespace System.Windows.Media { 5 | public class DrawingContext { 6 | public DrawingContext () { 7 | //batch = new SpriteBatch(ScreenHelper.Device); 8 | } 9 | 10 | public void DrawText (SpriteFont spriteFont, string text, Vector2 position, Color color) { 11 | throw new NotImplementedException(); 12 | } 13 | 14 | public void DrawText (SpriteFont spriteFont, string text, Point position, Color color) { 15 | throw new NotImplementedException(); 16 | } 17 | 18 | public void DrawImage () { 19 | throw new NotImplementedException(); 20 | } 21 | 22 | //private SpriteBatch batch; 23 | } 24 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/GradientStop.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | 3 | namespace System.Windows.Media { 4 | public class GradientStop { 5 | public GradientStop () { } 6 | 7 | public GradientStop (float offset, Color color) { 8 | Offset = offset; 9 | Color = color; 10 | } 11 | 12 | public override bool Equals (object obj) { 13 | var gs = obj as GradientStop; 14 | return gs != null 15 | && gs.Offset == this.Offset 16 | && gs.Color == this.Color; 17 | } 18 | 19 | public override int GetHashCode () { 20 | return (this.Offset.ToString() + ";" 21 | + this.Color.PackedValue.ToString() + ";").GetHashCode(); 22 | } 23 | 24 | public float Offset { get; set; } 25 | public Color Color { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/SizeChangedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace System.Windows { 2 | public delegate void SizeChangedEventHandler ( object sender, SizeChangedEventArgs e ); 3 | public class SizeChangedEventArgs : EventArgs { 4 | internal SizeChangedEventArgs (Size newSize, Size previousSize) { 5 | this.NewSize = newSize; 6 | this.PreviousSize = previousSize; 7 | } 8 | 9 | #region properties 10 | 11 | public Size NewSize { get; private set; } 12 | public Size PreviousSize { get; private set; } 13 | 14 | public bool HeightChanged { 15 | get { 16 | return NewSize.Height != PreviousSize.Height; 17 | } 18 | } 19 | 20 | public bool WidthChanged { 21 | get { 22 | return NewSize.Width != PreviousSize.Width; 23 | } 24 | } 25 | 26 | #endregion 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/RowDefinition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace System.Windows 4 | { 5 | public class RowDefinition 6 | { 7 | static RowDefinition () 8 | { 9 | Auto = new RowDefinition { Height = GridLength.Auto }; 10 | Star = new RowDefinition { Height = GridLength.Star }; 11 | } 12 | 13 | public RowDefinition () 14 | { 15 | Height = GridLength.Star; 16 | } 17 | 18 | public RowDefinition (GridLength height, float? minHeight, float? maxHeight) 19 | { 20 | this.Height = height; 21 | this.MinHeight = minHeight; 22 | this.MaxHeight = maxHeight; 23 | } 24 | 25 | public RowDefinition (GridLength height) : this ( height, null, null ) 26 | { 27 | } 28 | 29 | public float? MinHeight { get; set; } 30 | 31 | public float? MaxHeight { get; set; } 32 | 33 | public GridLength Height { get; set; } 34 | 35 | public static RowDefinition Auto { get; private set; } 36 | 37 | public static RowDefinition Star { get; private set; } 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Trigger.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.ObjectModel; 2 | using System.Linq; 3 | using System.Windows.Markup; 4 | 5 | namespace System.Windows { 6 | [ContentProperty("Setters")] 7 | public class Trigger { 8 | public Trigger () { 9 | 10 | } 11 | 12 | public Trigger (DependencyProperty property, object value) { 13 | if (property == null) 14 | throw new ArgumentNullException (); 15 | 16 | this.Property = property; 17 | this.Value = value; 18 | } 19 | 20 | #region Eigenschaften 21 | 22 | public DependencyProperty Property { get; set; } 23 | 24 | public object Value { get; set; } 25 | 26 | public SetterCollection Setters { 27 | get { 28 | if (setters == null) 29 | setters = new SetterCollection(); 30 | 31 | return setters; 32 | } 33 | internal set { 34 | setters = value; 35 | } 36 | } 37 | 38 | #endregion 39 | 40 | private SetterCollection setters; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /WPFLight.iOS/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using MonoTouch.Foundation; 4 | 5 | [assembly: AssemblyTitle ("WPFLight")] 6 | [assembly: AssemblyDescription ("")] 7 | [assembly: AssemblyConfiguration ("")] 8 | [assembly: AssemblyCompany ("")] 9 | [assembly: AssemblyProduct ("")] 10 | [assembly: AssemblyCopyright ("Ronny Weidemann")] 11 | [assembly: AssemblyTrademark ("")] 12 | [assembly: AssemblyCulture ("")] 13 | 14 | [assembly: Preserve() ] 15 | 16 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 17 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 18 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 19 | 20 | [assembly: AssemblyVersion ("1.0.*")] 21 | 22 | // The following attributes are used to specify the signing key for the assembly, 23 | // if desired. See the Mono documentation for more information about signing. 24 | 25 | //[assembly: AssemblyDelaySign(false)] 26 | //[assembly: AssemblyKeyFile("")] 27 | 28 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/FontFamily.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | namespace System.Windows.Media { 3 | [TypeConverter (typeof(FontFamilyConverter))] 4 | public class FontFamily { 5 | public FontFamily ( string fontName ) { 6 | if (String.IsNullOrEmpty (fontName)) 7 | throw new ArgumentException (); 8 | 9 | this.Source = fontName; 10 | } 11 | 12 | public FontFamily ( string fontName, float spacing, int lineSpacing ) : this ( fontName ) { 13 | this.Spacing = spacing; 14 | this.LineSpacing = lineSpacing; 15 | } 16 | 17 | #region Properties 18 | 19 | public string Source { get; private set; } 20 | 21 | public float Spacing { get; private set; } 22 | 23 | public int LineSpacing { get; private set; } 24 | 25 | #endregion 26 | 27 | public override bool Equals (object obj) { 28 | var ff = obj as FontFamily; 29 | return ff != null 30 | && ff.Source.ToLower () == this.Source.ToLower (); 31 | } 32 | 33 | public override int GetHashCode () { 34 | return this.Source.ToLower ().GetHashCode (); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/ColumnDefinition.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace System.Windows.Controls 4 | { 5 | public class ColumnDefinition 6 | { 7 | static ColumnDefinition () 8 | { 9 | Auto = new ColumnDefinition { Width = GridLength.Auto }; 10 | Star = new ColumnDefinition { Width = GridLength.Star }; 11 | } 12 | 13 | public ColumnDefinition () 14 | { 15 | Width = GridLength.Star; 16 | } 17 | 18 | public ColumnDefinition (GridLength width, float? minWidth, float? maxWidth) 19 | { 20 | this.Width = width; 21 | this.MinWidth = minWidth; 22 | this.MaxWidth = maxWidth; 23 | } 24 | 25 | public ColumnDefinition (GridLength width) : this ( width, null, null ) 26 | { 27 | } 28 | 29 | #region Eigenschaften 30 | 31 | public float? MinWidth { get; set; } 32 | 33 | public float? MaxWidth { get; set; } 34 | 35 | public GridLength Width { get; set; } 36 | 37 | public static ColumnDefinition Auto { get; private set; } 38 | 39 | public static ColumnDefinition Star { get; private set; } 40 | 41 | #endregion 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/BrushConverter.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Globalization; 3 | 4 | namespace System.Windows.Media { 5 | public class BrushConverter : TypeConverter { 6 | public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType) { 7 | if (sourceType == typeof(String)) 8 | return true; 9 | 10 | if (sourceType == typeof(Microsoft.Xna.Framework.Color)) // TODO Replace with System.Windows.Media.Color 11 | return true; 12 | 13 | return base.CanConvertFrom (context, sourceType); 14 | } 15 | 16 | public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value) { 17 | String source = value as string; 18 | if (source != null) 19 | return Brush.Parse(source, context); 20 | 21 | return base.ConvertFrom (context, culture, value); 22 | } 23 | 24 | public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { 25 | return base.ConvertTo (context, culture, value, destinationType); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/PropertyPath.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Collections.ObjectModel; 6 | 7 | namespace System.Windows { 8 | // Zusammenfassung: 9 | // Implementiert eine Datenstruktur zum Beschreiben einer Eigenschaft als Pfad 10 | // unter einer anderen Eigenschaft oder unter einem besitzenden Typ. Eigenschaftenpfade 11 | // werden in der Datenbindung an Objekte sowie in Storyboards und Zeitachsen 12 | // für Animationen verwendet. 13 | public sealed class PropertyPath { 14 | public PropertyPath (object parameter) : this (SingleStepPath, parameter) { 15 | } 16 | 17 | public PropertyPath (string path, params object[] pathParameters) { 18 | this.Path = path; 19 | if (pathParameters != null) 20 | this.PathParameters = new Collection (pathParameters); 21 | } 22 | 23 | #region Eigenschaften 24 | 25 | public string Path { get; set; } 26 | 27 | public Collection PathParameters { get; private set; } 28 | 29 | #endregion 30 | 31 | const string SingleStepPath = "(0)"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /WPFLight/Resources/Textures.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework.Content; 2 | using Microsoft.Xna.Framework.Graphics; 3 | 4 | namespace WPFLight.Resources { 5 | public static class Textures { 6 | public static void LoadContent (ContentManager manager) { 7 | Background = manager.Load ("bg_button"); 8 | ArrowUp = manager.Load ("ArrowUp"); 9 | ArrowDown = manager.Load ("ArrowDown"); 10 | ArrowLeft = manager.Load ("ArrowLeft"); 11 | ArrowRight = manager.Load ("ArrowRight"); 12 | } 13 | 14 | public static void Dispose () { 15 | Background.Dispose (); 16 | ArrowUp.Dispose (); 17 | ArrowDown.Dispose (); 18 | ArrowLeft.Dispose (); 19 | ArrowRight.Dispose (); 20 | } 21 | 22 | #region Properties 23 | 24 | public static Texture2D Background { get; private set; } 25 | 26 | public static Texture2D ArrowUp { get; private set; } 27 | 28 | public static Texture2D ArrowDown { get; private set; } 29 | 30 | public static Texture2D ArrowLeft { get; private set; } 31 | 32 | public static Texture2D ArrowRight { get; private set; } 33 | 34 | #endregion 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Point.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | namespace System.Windows { 4 | [TypeConverter(typeof(PointConverter))] 5 | public struct Point { 6 | public Point (float x, float y) { 7 | X = x; 8 | Y = y; 9 | } 10 | 11 | #region Operators 12 | 13 | public static bool operator ==(Point p1, Point p2) { 14 | return p1.Equals(p2); 15 | } 16 | 17 | public static bool operator != (Point p1, Point p2) { 18 | return !p1.Equals(p2); 19 | } 20 | 21 | public static Point operator +(Point p1, Point p2) { 22 | return new Point (p1.X + p2.X, p1.Y + p2.Y); 23 | } 24 | 25 | public static Point operator -(Point p1, Point p2) { 26 | return new Point (p1.X - p2.X, p1.Y - p2.Y); 27 | } 28 | 29 | #endregion 30 | 31 | #region Properties 32 | 33 | public float X; 34 | public float Y; 35 | 36 | #endregion 37 | 38 | public override bool Equals (object obj) { 39 | if (obj is Point) { 40 | var p = (Point)obj; 41 | return p.X == this.X && p.Y == this.Y; 42 | } 43 | return false; 44 | } 45 | 46 | public override int GetHashCode () { 47 | return base.GetHashCode(); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/Primitives/ToggleButton.cs: -------------------------------------------------------------------------------- 1 | namespace System.Windows.Controls.Primitives { 2 | public class ToggleButton : Button { 3 | public ToggleButton () { } 4 | 5 | #region Ereignisse 6 | 7 | public event EventHandler CheckedChanged; 8 | 9 | #endregion 10 | 11 | #region Eigenschaften 12 | 13 | public static readonly DependencyProperty IsCheckedProperty = 14 | DependencyProperty.Register ( 15 | "IsChecked", 16 | typeof(bool), 17 | typeof(ToggleButton), 18 | new PropertyMetadata ( 19 | new PropertyChangedCallback ( 20 | ( sender, e) => { 21 | ((ToggleButton)sender).OnCheckedChanged ((bool)e.NewValue); 22 | }))); 23 | 24 | public bool IsChecked { 25 | get { return (bool)GetValue (IsCheckedProperty); } 26 | set { SetValue (IsCheckedProperty, value); } 27 | } 28 | 29 | #endregion 30 | 31 | protected virtual void OnCheckedChanged (bool chk) { 32 | if (this.CheckedChanged != null) 33 | this.CheckedChanged (this, EventArgs.Empty); 34 | } 35 | 36 | protected override void OnClick () { 37 | base.OnClick (); 38 | this.IsChecked = !this.IsChecked; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /WPFLight.Win8/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("WPFLight.Win8")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("WPFLight.Win8")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Version information for an assembly consists of the following four values: 18 | // 19 | // Major Version 20 | // Minor Version 21 | // Build Number 22 | // Revision 23 | // 24 | // You can specify all the values or you can default the Build and Revision Numbers 25 | // by using the '*' as shown below: 26 | // [assembly: AssemblyVersion("1.0.*")] 27 | [assembly: AssemblyVersion("1.0.0.0")] 28 | [assembly: AssemblyFileVersion("1.0.0.0")] 29 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /WPFLight.Test/Tests/XamlTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | using System.Windows.Media; 5 | using NUnit.Framework; 6 | 7 | namespace WPFLight.Test { 8 | [TestFixture] 9 | public class XamlTests { 10 | [SetUp] 11 | public void Setup ( ) { 12 | xml += ""; 22 | } 23 | 24 | [Test] 25 | public void TestStyle ( ) { 26 | var style = Style.Parse (xml); 27 | Assert.AreSame (style["Background"], Brushes.Red); 28 | Assert.AreSame (style["IsTouchDown", true].Setters["Background"], Brushes.Yellow); 29 | } 30 | 31 | private string xml; 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/GridLength.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace System.Windows 4 | { 5 | public struct GridLength 6 | { 7 | static GridLength () 8 | { 9 | Auto = new GridLength (0, GridUnitType.Auto); 10 | Star = new GridLength (1, GridUnitType.Star); 11 | } 12 | 13 | public GridLength (float value, GridUnitType unitType) 14 | { 15 | _value = value; 16 | _unitType = unitType; 17 | } 18 | 19 | #region Eigenschaften 20 | 21 | public float Value { get { return _value; } } 22 | 23 | public GridUnitType UnitType { get { return _unitType; } } 24 | 25 | public bool IsStar { 26 | get { 27 | return _unitType == GridUnitType.Star; 28 | } 29 | } 30 | 31 | public bool IsAuto { 32 | get { 33 | return _unitType == GridUnitType.Auto; 34 | } 35 | } 36 | 37 | public bool IsAbsolute { 38 | get { 39 | return _unitType == GridUnitType.Pixel; 40 | } 41 | } 42 | 43 | #endregion 44 | 45 | private float _value; 46 | private GridUnitType _unitType; 47 | public static readonly GridLength Auto; 48 | public static readonly GridLength Star; 49 | } 50 | 51 | public enum GridUnitType 52 | { 53 | Star, 54 | Auto, 55 | Pixel, 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/GameWindow.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Windows.Controls; 3 | using System.Windows.Media; 4 | using System.Windows.Media.Animation; 5 | 6 | namespace System.Windows { 7 | public abstract class GameWindow : Microsoft.Xna.Framework.Game { 8 | public GameWindow () { 9 | drawingContext = new DrawingContext(); 10 | } 11 | 12 | #region Eigenschaften 13 | 14 | public List Screens { get; private set; } 15 | 16 | #endregion 17 | 18 | protected override void Update (Microsoft.Xna.Framework.GameTime gameTime) { 19 | Clock.SetCurrentGlobalTime(gameTime.TotalGameTime); 20 | base.Update(gameTime); 21 | } 22 | 23 | protected override void Draw (Microsoft.Xna.Framework.GameTime gameTime) { 24 | base.Draw(gameTime); 25 | this.OnRender(drawingContext); 26 | } 27 | 28 | protected virtual void OnRender (DrawingContext dc) { 29 | // Screens rendern 30 | foreach (var screen in this.Screens) { 31 | screen.OnRender(dc); 32 | } 33 | } 34 | 35 | private DrawingContext drawingContext; 36 | } 37 | } -------------------------------------------------------------------------------- /WPFLight/Helpers/ResourceHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | 5 | namespace WPFLight.Helpers { 6 | internal static class ResourceHelper { 7 | static ResourceHelper ( ) { 8 | Resources = new Dictionary (); 9 | } 10 | 11 | public static object GetResourceKey ( object item ) { 12 | if ( Resources.ContainsValue ( item ) ) { 13 | foreach (var r in Resources) 14 | if (r.Value == item) 15 | return r.Key; 16 | } 17 | return null; 18 | } 19 | 20 | public static void SetResourceKey ( object key, object item ) { 21 | if (key == null || item == null ) 22 | throw new ArgumentNullException (); 23 | 24 | // Prüfen ob der Key bereits verwendet wird 25 | if (Resources.ContainsKey (key) ) 26 | throw new ArgumentException ("The key is already in use."); 27 | 28 | Resources [key] = item; 29 | } 30 | 31 | public static object GetResource ( object key ) { 32 | if (key == null) 33 | throw new ArgumentNullException (); 34 | 35 | if (key is Type ) 36 | return Resources.Where (r => r.Key.Equals (key)).Select (r => r.Value).FirstOrDefault (); 37 | else 38 | return Resources.Where (r => r.Key.Equals (key)).Select (r => r.Value).First (); 39 | } 40 | 41 | static Dictionary Resources; 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /WPFLight.iOS/Helpers/ResourceHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | 5 | namespace WPFLight.Helpers { 6 | internal static class ResourceHelper { 7 | static ResourceHelper ( ) { 8 | Resources = new Dictionary (); 9 | } 10 | 11 | public static object GetResourceKey ( object item ) { 12 | if ( Resources.ContainsValue ( item ) ) { 13 | foreach (var r in Resources) 14 | if (r.Value == item) 15 | return r.Key; 16 | } 17 | return null; 18 | } 19 | 20 | public static void SetResourceKey ( object key, object item ) { 21 | if (key == null || item == null ) 22 | throw new ArgumentNullException (); 23 | 24 | // Prüfen ob der Key bereits verwendet wird 25 | if (Resources.ContainsKey (key) ) 26 | throw new ArgumentException ("The key is already in use."); 27 | 28 | Resources [key] = item; 29 | } 30 | 31 | public static object GetResource ( object key ) { 32 | if (key == null) 33 | throw new ArgumentNullException (); 34 | 35 | if (key is Type ) 36 | return Resources.Where (r => r.Key.Equals (key)).Select (r => r.Value).FirstOrDefault (); 37 | else 38 | return Resources.Where (r => r.Key.Equals (key)).Select (r => r.Value).First (); 39 | } 40 | 41 | static Dictionary Resources; 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /WPFLight/Initializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Reflection; 4 | using System.Windows; 5 | using System.Windows.Markup; 6 | using Microsoft.Xna.Framework.Graphics; 7 | 8 | namespace WPFLight { 9 | public static class Initializer { 10 | 11 | #region Properties 12 | 13 | public static GraphicsDevice CurrentDevice { get; private set; } 14 | 15 | #endregion 16 | 17 | public static void Setup ( GraphicsDevice device ) { 18 | CurrentDevice = device; 19 | } 20 | 21 | /// 22 | /// load resource-dictionary and set default styles 23 | /// 24 | public static void Load () { 25 | using (Stream stream = Assembly.GetExecutingAssembly ().GetManifestResourceStream ("WPFLight.Themes.Default.xaml")){ 26 | XamlReader.Load (stream); 27 | } 28 | } 29 | 30 | public static ResourceDictionary LoadResourceDictionary ( Stream stream ) { 31 | return ( ResourceDictionary ) XamlReader.Load (stream); 32 | } 33 | 34 | public static ResourceDictionary LoadResourceDictionary ( string resourceId ) { 35 | if (String.IsNullOrEmpty (resourceId)) 36 | throw new ArgumentException (); 37 | 38 | using (Stream stream = Assembly.GetCallingAssembly ().GetManifestResourceStream (resourceId)){ 39 | return ( ResourceDictionary ) XamlReader.Load (stream); 40 | } 41 | } 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/TabItem.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls.Primitives; 2 | namespace System.Windows.Controls { 3 | public class TabItem : HeaderedContentControl { 4 | #region Eigenschaften 5 | 6 | public static DependencyProperty IsSelectedProperty = 7 | DependencyProperty.Register( 8 | "IsSelected", 9 | typeof(bool), 10 | typeof(TabItem), 11 | new PropertyMetadata( 12 | new PropertyChangedCallback( 13 | (s, e) => { 14 | if ((bool)e.NewValue) { 15 | ((TabItem)s).OnSelected(); 16 | } else { 17 | ((TabItem)s).OnUnselected(); 18 | } 19 | }))); 20 | 21 | public bool IsSelected { 22 | get { return (bool)GetValue(IsSelectedProperty); } 23 | set { SetValue(IsSelectedProperty, value); } 24 | } 25 | 26 | #endregion 27 | 28 | protected virtual void OnSelected () { 29 | var tabControl = this.Parent as TabControl; 30 | if (tabControl != null) 31 | tabControl.SelectedItem = this; 32 | } 33 | 34 | protected virtual void OnUnselected () { 35 | 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /WPFLight/Helpers/ArrayHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Input.Touch; 4 | using Microsoft.Xna.Framework.Graphics; 5 | using System.Windows; 6 | 7 | namespace WPFLight.Helpers { 8 | internal static class ArrayHelper { 9 | public static void ArrayFill (T[] arrayToFill, T fillValue) { 10 | // if called with a single value, wrap the value in an array and call the main function 11 | ArrayFill( 12 | arrayToFill, new T[] { fillValue }); 13 | } 14 | 15 | public static void ArrayFill (T[] arrayToFill, T[] fillValue) { 16 | if (fillValue.Length >= arrayToFill.Length) 17 | throw new ArgumentException("fillValue array length must be smaller than length of arrayToFill"); 18 | 19 | // set the initial array value 20 | Array.Copy(fillValue, arrayToFill, fillValue.Length); 21 | var arrayToFillHalfLength = arrayToFill.Length / 2; 22 | for (var i = fillValue.Length; i < arrayToFill.Length; i *= 2) { 23 | var copyLength = i; 24 | if (i > arrayToFillHalfLength) 25 | copyLength = arrayToFill.Length - i; 26 | 27 | Array.Copy( 28 | arrayToFill, 0, arrayToFill, i, copyLength); 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /WPFLight.Test/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDisplayName 6 | WPFLight.Test 7 | CFBundleIdentifier 8 | com.your-company.WPFLight.Test 9 | CFBundleShortVersionString 10 | 1.0 11 | CFBundleVersion 12 | 1.0 13 | LSRequiresIPhoneOS 14 | 15 | MinimumOSVersion 16 | 7.0 17 | UIDeviceFamily 18 | 19 | 1 20 | 2 21 | 22 | UIRequiredDeviceCapabilities 23 | 24 | armv7 25 | 26 | UISupportedInterfaceOrientations 27 | 28 | UIInterfaceOrientationPortrait 29 | UIInterfaceOrientationLandscapeLeft 30 | UIInterfaceOrientationLandscapeRight 31 | 32 | UISupportedInterfaceOrientations~ipad 33 | 34 | UIInterfaceOrientationPortrait 35 | UIInterfaceOrientationPortraitUpsideDown 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/Canvas.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | 6 | namespace System.Windows.Controls { 7 | public class Canvas : Panel { 8 | #region Properties 9 | 10 | public static readonly DependencyProperty LeftProperty = 11 | DependencyProperty.RegisterAttached ( 12 | "Left", 13 | typeof ( float ), 14 | typeof ( Canvas ) ); 15 | 16 | public static readonly DependencyProperty TopProperty = 17 | DependencyProperty.RegisterAttached ( 18 | "Top", 19 | typeof ( float ), 20 | typeof ( Canvas ) ); 21 | 22 | #endregion 23 | 24 | internal override float GetAbsoluteLeft (UIElement child) { 25 | return 26 | this.GetAbsoluteLeft () 27 | + Canvas.GetLeft (child); 28 | } 29 | 30 | internal override float GetAbsoluteTop (UIElement child) { 31 | return 32 | this.GetAbsoluteTop () 33 | + Canvas.GetTop (child); 34 | } 35 | 36 | public static float GetTop ( UIElement ctrl ) { 37 | return (float)ctrl.GetValue (TopProperty); 38 | } 39 | 40 | public static float GetLeft ( UIElement ctrl ) { 41 | return (float)ctrl.GetValue (LeftProperty); 42 | } 43 | 44 | public static void SetLeft ( UIElement ctrl, float value ) { 45 | ctrl.SetValue (LeftProperty, value); 46 | } 47 | 48 | public static void SetTop (UIElement ctrl, float value) { 49 | ctrl.SetValue (TopProperty, value); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /WPFLight.Android/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using Android.App; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle ( "WPFLight.Android" )] 10 | [assembly: AssemblyDescription ( "" )] 11 | [assembly: AssemblyConfiguration ( "" )] 12 | [assembly: AssemblyCompany ( "" )] 13 | [assembly: AssemblyProduct ( "WPFLight.Android" )] 14 | [assembly: AssemblyCopyright ( "Copyright © 2012-2014" )] 15 | [assembly: AssemblyTrademark ( "" )] 16 | [assembly: AssemblyCulture ( "" )] 17 | [assembly: ComVisible ( false )] 18 | 19 | // Version information for an assembly consists of the following four values: 20 | // 21 | // Major Version 22 | // Minor Version 23 | // Build Number 24 | // Revision 25 | // 26 | // You can specify all the values or you can default the Build and Revision Numbers 27 | // by using the '*' as shown below: 28 | // [assembly: AssemblyVersion("1.0.*")] 29 | [assembly: AssemblyVersion ( "1.0.0.0" )] 30 | [assembly: AssemblyFileVersion ( "1.0.0.0" )] 31 | 32 | // Add some common permissions, these can be removed if not needed 33 | [assembly: UsesPermission ( Android.Manifest.Permission.Internet )] 34 | [assembly: UsesPermission ( Android.Manifest.Permission.WriteExternalStorage )] 35 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/Brush.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.Xna.Framework.Graphics; 6 | using Microsoft.Xna.Framework; 7 | using WPFLight.Helpers; 8 | using System.ComponentModel; 9 | 10 | namespace System.Windows.Media { 11 | [TypeConverter (typeof(BrushConverter))] 12 | public abstract class Brush { 13 | public Brush () { 14 | this.Opacity = 1; 15 | this.GraphicsDevice = ScreenHelper.Device; 16 | } 17 | 18 | [Obsolete] 19 | public Brush (GraphicsDevice graphicsDevice) { 20 | this.GraphicsDevice = ScreenHelper.Device; 21 | } 22 | 23 | #region Eigenschaften 24 | 25 | public GraphicsDevice GraphicsDevice { get; private set; } 26 | 27 | public float Opacity { get; set; } 28 | 29 | #endregion 30 | 31 | internal abstract Color GetPixel (int x, int y, int width, int height); 32 | 33 | internal abstract int [] GetTextureData (int width, int height); 34 | 35 | public abstract void Draw (SpriteBatch batch, Rectangle bounds, Matrix transform, float alpha); 36 | 37 | internal static Brush Parse (string value, ITypeDescriptorContext context) { 38 | if (value == null) 39 | throw new ArgumentNullException (); 40 | 41 | if (value.StartsWith ("#")) { 42 | return new SolidColorBrush ( 43 | ColorHelper.ConvertFromHex (value)); 44 | } else { 45 | return Brushes.GetBrush ( 46 | ColorHelper.GetNamedColor (value)); 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/FontFamilyConverter.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | using System.ComponentModel; 3 | 4 | namespace System.Windows.Media { 5 | public class FontFamilyConverter : TypeConverter { 6 | public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType) { 7 | if (sourceType == typeof(string)) { 8 | return true; 9 | } 10 | return base.CanConvertFrom ( 11 | context, sourceType); 12 | } 13 | 14 | public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType) { 15 | if (destinationType == typeof(FontFamily)) 16 | return true; 17 | else if (destinationType == typeof(String)) 18 | return true; 19 | 20 | return base.CanConvertTo ( 21 | context, destinationType); 22 | } 23 | 24 | public override object ConvertFrom ( 25 | ITypeDescriptorContext context, CultureInfo culture, object value) { 26 | string strValue = value as string; 27 | if (!String.IsNullOrEmpty (strValue)) 28 | return new FontFamily (strValue); 29 | 30 | return base.ConvertFrom ( 31 | context, culture, value); 32 | } 33 | 34 | public override object ConvertTo ( 35 | ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { 36 | if (value is FontFamily 37 | && value != null 38 | && destinationType == typeof(string)) 39 | return ((FontFamily)value).Source; 40 | 41 | return base.ConvertTo ( 42 | context, culture, value, destinationType); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /WPFLight.Test/Tests/StyleTests.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls; 3 | using System.Windows.Media; 4 | using Microsoft.Xna.Framework; 5 | using NUnit.Framework; 6 | 7 | namespace WPFLight.Test { 8 | [TestFixture] 9 | public class StyleTests { 10 | [SetUp] 11 | public void Setup ( ) { 12 | root = new Grid (); 13 | root.Width = 500; 14 | root.Height = 400; 15 | button = new Button (); 16 | button2 = new Button (); 17 | 18 | root.Children.Add (button); 19 | root.Children.Add (button2); 20 | } 21 | 22 | [Test] 23 | public void TestSetter ( ) { 24 | var style = new Style (); 25 | style.TargetType = typeof(Button); 26 | style ["Width"] = 150; 27 | style ["Height"] = 120; 28 | style ["Background"] = new SolidColorBrush ( Color.Red ); 29 | 30 | Assert.AreEqual (button.ActualWidth, root.ActualWidth); 31 | Assert.AreEqual (button.ActualHeight, root.ActualHeight); 32 | 33 | button.Style = style; 34 | button2.Style = style; 35 | 36 | Assert.AreEqual (button.ActualWidth, style ["Width"]); 37 | Assert.AreEqual (button.ActualHeight, style ["Height"]); 38 | Assert.AreSame (button.Background, style ["Background"]); 39 | 40 | button.Width = 100; 41 | Assert.AreEqual (button.ActualWidth, button.Width); 42 | 43 | button.Style = style; 44 | Assert.AreEqual (button.ActualWidth, style ["Width"]); 45 | 46 | Assert.AreSame (button2.Background, button.Background); 47 | } 48 | 49 | private Grid root; 50 | private Button button; 51 | private Button button2; 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/Animation/SingleAnimation.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using System; 3 | 4 | namespace System.Windows.Media.Animation 5 | { 6 | public class SingleAnimation : SingleAnimationBase { 7 | 8 | /* 9 | public SingleAnimation ( Game game, float value ) : base ( game ) { 10 | this.To = value; 11 | this.From = value; 12 | } 13 | */ 14 | public SingleAnimation ( float from, float to, TimeSpan duration, bool autoReverse ) { 15 | this.Duration = duration; 16 | this.From = from; 17 | this.To = to; 18 | this.AutoReverse = autoReverse; 19 | } 20 | 21 | #region Eigenschaften 22 | 23 | public float From { get; set; } 24 | public float To { get; set; } 25 | 26 | #endregion 27 | 28 | public override float GetCurrentValue() { 29 | var currentTime = this.CurrentTime; 30 | if ( this.Duration == TimeSpan.Zero || currentTime > this.Duration ) 31 | return this.To; 32 | else if ( currentTime > TimeSpan.Zero && currentTime <= this.Duration ) 33 | return ComputeValue ( 34 | this.From, this.To, 1f / ( ( float ) this.Duration.Ticks / ( float ) currentTime.Ticks ) ); 35 | else 36 | return this.From; 37 | } 38 | 39 | public void SetFromToCurrent ( ) { 40 | this.From = GetCurrentValue(); 41 | } 42 | 43 | /* 44 | protected override void Reverse ( ) { 45 | float tmp = this.From; 46 | this.From = this.To; 47 | this.To = tmp; 48 | } 49 | * */ 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Markup/INameScopeDictionary.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2010 Novell Inc. http://novell.com 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining 5 | // a copy of this software and associated documentation files (the 6 | // "Software"), to deal in the Software without restriction, including 7 | // without limitation the rights to use, copy, modify, merge, publish, 8 | // distribute, sublicense, and/or sell copies of the Software, and to 9 | // permit persons to whom the Software is furnished to do so, subject to 10 | // the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be 13 | // included in all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | // 23 | using System; 24 | using System.Collections; 25 | using System.Collections.Generic; 26 | 27 | namespace System.Windows.Markup 28 | { 29 | public interface INameScopeDictionary : INameScope, IDictionary, ICollection>, IEnumerable>, IEnumerable 30 | { 31 | } 32 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Thickness.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace System.Windows { 8 | [TypeConverter(typeof(ThicknessConverter))] 9 | public struct Thickness : IEquatable { 10 | public Thickness (float thickness) { 11 | _left = thickness; 12 | _top = thickness; 13 | _right = thickness; 14 | _bottom = thickness; 15 | } 16 | 17 | public Thickness (Thickness thickness) { 18 | _left = thickness.Left; 19 | _top = thickness.Top; 20 | _right = thickness.Right; 21 | _bottom = thickness.Bottom; 22 | } 23 | 24 | public Thickness (float left, float top, float right, float bottom) { 25 | _left = left; 26 | _top = top; 27 | _right = right; 28 | _bottom = bottom; 29 | } 30 | 31 | public float Left { 32 | get { return _left; } 33 | } 34 | 35 | public float Top { 36 | get { return _top; } 37 | } 38 | 39 | public float Right { 40 | get { return _right; } 41 | } 42 | 43 | public float Bottom { 44 | get { return _bottom; } 45 | } 46 | 47 | public bool IsEmpty { 48 | get { 49 | return this.Left == 0 50 | && this.Top == 0 51 | && this.Right == 0 52 | && this.Bottom == 0; 53 | } 54 | } 55 | 56 | public bool Equals (Thickness t) { 57 | return Left == t.Left 58 | && Top == t.Top 59 | && Right == t.Right 60 | && Bottom == t.Bottom; 61 | } 62 | 63 | private float _left; 64 | private float _top; 65 | private float _right; 66 | private float _bottom; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/FocusableControl.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | 6 | namespace System.Windows.Controls 7 | { 8 | // TODO Replace Panel 9 | public abstract class FocusableControl : Panel, IFocusable 10 | { 11 | public FocusableControl ( ) : base ( ) 12 | { 13 | 14 | } 15 | 16 | #region Ereignisse 17 | 18 | 19 | 20 | #endregion 21 | 22 | #region Eigenschaften 23 | 24 | #endregion 25 | 26 | public bool Focused 27 | { 28 | get 29 | { 30 | if ( this.Focusable ) 31 | return (this.FocusableParent??this.Parent).IsFocused ( this ); 32 | 33 | return false; 34 | } 35 | } 36 | 37 | public void Focus ( ) 38 | { 39 | if ( this.Focusable ) 40 | (this.FocusableParent??this.Parent).Focus ( this ); 41 | } 42 | 43 | public virtual void OnLostFocus ( ) 44 | { 45 | if ( this.LostFocus != null ) 46 | this.LostFocus ( this, EventArgs.Empty ); 47 | 48 | if (this.FocusChanged != null) 49 | this.FocusChanged (this, EventArgs.Empty); 50 | } 51 | 52 | public virtual void OnGotFocus ( ) 53 | { 54 | if ( this.GotFocus != null ) 55 | this.GotFocus ( this, EventArgs.Empty ); 56 | 57 | if (this.FocusChanged != null) 58 | this.FocusChanged (this, EventArgs.Empty); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /WPFLight.Test/UnitTestAppDelegate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using MonoTouch.Foundation; 5 | using MonoTouch.UIKit; 6 | using MonoTouch.NUnit.UI; 7 | 8 | namespace WPFLight.Test { 9 | // The UIApplicationDelegate for the application. This class is responsible for launching the 10 | // User Interface of the application, as well as listening (and optionally responding) to 11 | // application events from iOS. 12 | [Register ("UnitTestAppDelegate")] 13 | public partial class UnitTestAppDelegate : UIApplicationDelegate { 14 | // class-level declarations 15 | UIWindow window; 16 | TouchRunner runner; 17 | // 18 | // This method is invoked when the application has loaded and is ready to run. In this 19 | // method you should instantiate the window, load the UI into it and then make the window 20 | // visible. 21 | // 22 | // You have 17 seconds to return from this method, or iOS will terminate your application. 23 | // 24 | public override bool FinishedLaunching (UIApplication app, NSDictionary options) { 25 | // create a new window instance based on the screen size 26 | window = new UIWindow (UIScreen.MainScreen.Bounds); 27 | runner = new TouchRunner (window); 28 | 29 | // register every tests included in the main application/assembly 30 | runner.Add (System.Reflection.Assembly.GetExecutingAssembly ()); 31 | 32 | window.RootViewController = new UINavigationController (runner.GetViewController ()); 33 | 34 | // make the window visible 35 | window.MakeKeyAndVisible (); 36 | 37 | return true; 38 | } 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/ItemsControl.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Collections.Specialized; 4 | using System.Windows.Markup; 5 | 6 | namespace System.Windows.Controls { 7 | [ContentProperty("Items")] 8 | public class ItemsControl : Control { 9 | public ItemsControl () { 10 | this.Items = new ItemCollection(); 11 | ((ItemCollection)this.Items).CollectionChanged += OnItemsCollectionChanged; 12 | } 13 | 14 | #region Eigenschaften 15 | 16 | public static DependencyProperty ItemsProperty = 17 | DependencyProperty.Register( 18 | "Items", 19 | typeof(IList), 20 | typeof(ItemsControl), 21 | new PropertyMetadata( 22 | new PropertyChangedCallback( 23 | (s,e)=>{ 24 | 25 | }))); 26 | 27 | public IList Items { 28 | get { return (IList)GetValue(ItemsProperty); } 29 | private set { SetValue(ItemsProperty, value); } 30 | } 31 | 32 | public static DependencyProperty ItemContainerStyleProperty = 33 | DependencyProperty.Register( 34 | "ItemContainerStyle", 35 | typeof(Style), 36 | typeof(ItemsControl)); 37 | 38 | public Style ItemContainerStyle { 39 | get { return (Style)GetValue(ItemContainerStyleProperty); } 40 | set { SetValue(ItemContainerStyleProperty, value); } 41 | } 42 | 43 | #endregion 44 | 45 | protected virtual void OnItemsCollectionChanged ( 46 | object sender, NotifyCollectionChangedEventArgs e ) { } 47 | } 48 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Markup/INameScope.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2010 Novell Inc. http://novell.com 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining 5 | // a copy of this software and associated documentation files (the 6 | // "Software"), to deal in the Software without restriction, including 7 | // without limitation the rights to use, copy, modify, merge, publish, 8 | // distribute, sublicense, and/or sell copies of the Software, and to 9 | // permit persons to whom the Software is furnished to do so, subject to 10 | // the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be 13 | // included in all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | // 23 | using System; 24 | using System.Collections.Generic; 25 | 26 | namespace System.Windows.Markup 27 | { 28 | #if !NET_2_1 29 | [System.Runtime.CompilerServices.TypeForwardedFrom (Consts.AssemblyWindowsBase)] 30 | #endif 31 | public interface INameScope 32 | { 33 | object FindName (string name); 34 | void RegisterName (string name, object scopedElement); 35 | void UnregisterName (string name); 36 | } 37 | } -------------------------------------------------------------------------------- /WPFLight.XNA/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using System.Resources; 5 | 6 | // Allgemeine Informationen über eine Assembly werden über den folgenden 7 | // Satz von Attributen kontrolliert. Ändern Sie diese Attributwerte, um die mit einer Assembly 8 | // verbundenen Informationen zu ändern. 9 | [assembly: AssemblyTitle("WPFLight.XNA")] 10 | [assembly: AssemblyProduct("WPFLight.XNA")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Bei Einstellung von ComVisible auf falsch sind die Typen in dieser Assembly für 18 | // COM-Komponenten nicht sichtbar. Wenn Sie von COM aus auf einen Typ in dieser Assembly 19 | // zugreifen müssen, stellen Sie das Attribut ComVisible bei diesem Typ auf wahr ein. Nur Windows- 20 | // Assemblys unterstützen COM. 21 | [assembly: ComVisible(false)] 22 | 23 | // Auf Windows gilt die folgende GUID für die ID von typelib, wenn dieses 24 | // COM ausgesetzt ist. Auf anderen Plattformen identifiziert sie den 25 | // Titelspeichercontainer bei Bereitstellung dieser Assembly auf dem Gerät eindeutig. 26 | [assembly: Guid("49db0d4d-acac-4899-bd8f-a8404e1eced7")] 27 | 28 | // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: 29 | // 30 | // Größere Version 31 | // Kleinere Version 32 | // Build-Nummer 33 | // Revision 34 | // 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: NeutralResourcesLanguageAttribute("de-DE")] 37 | -------------------------------------------------------------------------------- /WPFLight/System/Xaml/NamespaceDeclaration.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2010 Novell Inc. http://novell.com 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining 5 | // a copy of this software and associated documentation files (the 6 | // "Software"), to deal in the Software without restriction, including 7 | // without limitation the rights to use, copy, modify, merge, publish, 8 | // distribute, sublicense, and/or sell copies of the Software, and to 9 | // permit persons to whom the Software is furnished to do so, subject to 10 | // the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be 13 | // included in all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | // 23 | using System; 24 | using System.Collections.Generic; 25 | 26 | namespace System.Xaml 27 | { 28 | public class NamespaceDeclaration 29 | { 30 | public NamespaceDeclaration (string ns, string prefix) 31 | { 32 | // null arguments are allowed. 33 | Namespace = ns; 34 | Prefix = prefix; 35 | } 36 | 37 | public string Namespace { get; private set; } 38 | public string Prefix { get; private set; } 39 | } 40 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/RepeatButton.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework.Input.Touch; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | 5 | namespace System.Windows.Controls { 6 | public class RepeatButton : Button { 7 | public RepeatButton () { } 8 | 9 | #region Properties 10 | 11 | public static readonly DependencyProperty IntervalProperty = 12 | DependencyProperty.Register ( 13 | "Interval", typeof ( TimeSpan ), typeof ( RepeatButton ), 14 | new PropertyMetadata ( 15 | TimeSpan.FromMilliseconds ( 80 ) ) ); 16 | 17 | public TimeSpan Interval { 18 | get { return (TimeSpan)GetValue (IntervalProperty); } 19 | set { SetValue (IntervalProperty,value); } 20 | } 21 | 22 | public static readonly DependencyProperty DelayProperty = 23 | DependencyProperty.Register ( 24 | "Delay", typeof ( TimeSpan ), typeof ( RepeatButton ), 25 | new PropertyMetadata ( 26 | TimeSpan.FromMilliseconds ( 130 ) ) ); 27 | 28 | public TimeSpan Delay { 29 | get { return (TimeSpan)GetValue (DelayProperty); } 30 | set { SetValue (DelayProperty,value); } 31 | } 32 | 33 | #endregion 34 | 35 | public override void OnTouchDown (TouchLocation state) { 36 | mouseDown = true; 37 | lastClick = DateTime.UtcNow + this.Delay; 38 | base.OnTouchDown (state); 39 | } 40 | 41 | public override void OnTouchMove (TouchLocation state) { 42 | base.OnTouchMove (state); 43 | if (mouseDown) { 44 | if (DateTime.UtcNow - lastClick >= this.Interval) { 45 | OnClick (); 46 | lastClick = DateTime.UtcNow; 47 | } 48 | } 49 | } 50 | 51 | private bool mouseDown; 52 | private DateTime lastClick; 53 | } 54 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/ListBoxCollection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Audio; 6 | using Microsoft.Xna.Framework.Content; 7 | using Microsoft.Xna.Framework.Graphics; 8 | using Microsoft.Xna.Framework.Input; 9 | using Microsoft.Xna.Framework.Media; 10 | using System.Collections.ObjectModel; 11 | 12 | namespace System.Windows 13 | { 14 | public sealed class ListBoxCollection : Collection 15 | { 16 | protected override void InsertItem ( int index, string item ) 17 | { 18 | base.InsertItem ( index, item ); 19 | OnCollectionChanged ( ); 20 | } 21 | 22 | protected override void ClearItems ( ) 23 | { 24 | var changed = false; 25 | if ( this.Count > 0 ) 26 | changed = true; 27 | 28 | base.ClearItems ( ); 29 | if ( changed ) 30 | OnCollectionChanged ( ); 31 | } 32 | 33 | protected override void RemoveItem ( int index ) 34 | { 35 | base.RemoveItem ( index ); 36 | OnCollectionChanged ( ); 37 | } 38 | 39 | protected override void SetItem ( int index, string item ) 40 | { 41 | base.SetItem ( index, item ); 42 | OnCollectionChanged ( ); 43 | } 44 | 45 | public event EventHandler CollectionChanged; 46 | 47 | void OnCollectionChanged ( ) 48 | { 49 | if ( this.CollectionChanged != null ) 50 | this.CollectionChanged ( this, EventArgs.Empty ); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/FontContainer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.Xna.Framework.Graphics; 3 | namespace System.Windows.Media { 4 | 5 | // the used fonts must be registered in the LoadContent-Method of the Game-class 6 | 7 | public static class FontContainer { 8 | static FontContainer () { 9 | registeredFonts = new Dictionary(); 10 | } 11 | 12 | public static void Register (FontFamily fontFamily, SpriteFont font) { 13 | if (fontFamily == null || font == null) 14 | throw new ArgumentException(); 15 | 16 | registeredFonts[fontFamily] = font; 17 | } 18 | 19 | public static void Register (string fontName, SpriteFont font) { 20 | if (String.IsNullOrEmpty(fontName) || font == null ) 21 | throw new ArgumentException(); 22 | 23 | var fontFamily = new FontFamily (fontName, font.Spacing, font.LineSpacing); 24 | registeredFonts[fontFamily] = font; 25 | } 26 | 27 | public static SpriteFont Resolve (string fontName) { 28 | if (String.IsNullOrEmpty(fontName)) 29 | throw new ArgumentException(); 30 | 31 | foreach ( var ff in registeredFonts ) { 32 | if (ff.Key.Source.ToLower () == fontName.ToLower ()) 33 | return ff.Value; 34 | } 35 | throw new KeyNotFoundException (); 36 | } 37 | 38 | public static SpriteFont Resolve (FontFamily fontFamily) { 39 | if (fontFamily == null) 40 | throw new ArgumentNullException(); 41 | 42 | return registeredFonts[fontFamily]; 43 | } 44 | 45 | private static Dictionary registeredFonts; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/VisualTreeHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Windows.Controls; 3 | using System.Linq; 4 | 5 | namespace System.Windows.Media { 6 | public static class VisualTreeHelper { 7 | public static List GetChildren (UIElement root) where T : UIElement { 8 | var children = new List(); 9 | if (root is Panel) { 10 | foreach (var c in ((Panel)root).Children) { 11 | if (c is T) 12 | children.Add((T)c); 13 | 14 | children.AddRange(GetChildren(c)); 15 | } 16 | } else if (root is ItemsControl) { 17 | foreach (var c in ((ItemsControl)root).Items.OfType ( )) { 18 | if (c is T) 19 | children.Add((T)c); 20 | 21 | children.AddRange(GetChildren(c)); 22 | } 23 | } else if (root is ContentControl) { 24 | var element = ((ContentControl)root).Content as UIElement; 25 | if (element != null) { 26 | if (element is T) 27 | children.Add((T)element); 28 | 29 | children.AddRange( 30 | GetChildren(element)); 31 | } 32 | } 33 | return children; 34 | } 35 | 36 | public static bool IsVisible ( UIElement c ) { 37 | return c.IsVisible 38 | && (c.Parent == null || IsVisible (c.Parent)); 39 | } 40 | 41 | public static UIElement GetRoot (UIElement c) { 42 | if (c.Parent == null) 43 | return c; 44 | else 45 | return GetRoot(c.Parent); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/TabControl.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Windows.Controls.Primitives; 3 | using System.Windows.Media; 4 | 5 | namespace System.Windows.Controls { 6 | public class TabControl : Selector { 7 | public TabControl () { 8 | gridItems = new Grid(); 9 | gridItems.Parent = this; 10 | gridItems.RowDefinitions.Add(RowDefinition.Auto); 11 | gridItems.RowDefinitions.Add(RowDefinition.Star); 12 | gridItems.ColumnDefinitions.Add(ColumnDefinition.Star); 13 | 14 | lbItems = new ListBox(); 15 | lbItems.SelectionChanged += 16 | (s, e) => { this.SelectedIndex = lbItems.SelectedIndex; }; 17 | 18 | Grid.SetRow(lbItems, 0); 19 | } 20 | 21 | public override void Initialize () { 22 | foreach (var item in this.Items.OfType ( ) ) { 23 | gridItems.Children.Add(item); 24 | Grid.SetRow(item, 1); 25 | lbItems.Items.Add(item.Header); 26 | } 27 | base.Initialize(); 28 | } 29 | 30 | protected override void OnSelectionChanged () { 31 | base.OnSelectionChanged(); 32 | foreach (var item in this.Items.OfType ( ) ) 33 | item.Visible = false; 34 | 35 | if (this.SelectedItem != null) 36 | ((TabItem)this.SelectedItem).Visible = true; 37 | 38 | lbItems.SelectedIndex = this.SelectedIndex; 39 | } 40 | 41 | protected internal override void OnRender (DrawingContext dc) { 42 | base.OnRender(dc); 43 | gridItems.OnRender(dc); 44 | } 45 | 46 | private ListBox lbItems; 47 | private Grid gridItems; 48 | } 49 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Size.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Xna.Framework; 3 | 4 | namespace System.Windows { 5 | public struct Size { 6 | public Size (float width, float height) { 7 | this.width = width; 8 | this.height = height; 9 | } 10 | 11 | internal Size (Vector2 vec) : this (vec.X, vec.Y) { 12 | } 13 | 14 | public Size (Point point) : this (point.X, point.Y) { 15 | } 16 | 17 | #region Operators 18 | 19 | public static bool operator == (Size size1, Size size2) { 20 | return size1.Width == size2.Width && 21 | size1.Height == size2.Height; 22 | } 23 | 24 | public static bool operator != (Size size1, Size size2) { 25 | return !(size1 == size2); 26 | } 27 | 28 | #endregion 29 | 30 | #region Properties 31 | 32 | public float Width { get { return width; } set { width = value; } } 33 | 34 | public float Height { get { return height; } set { height = value; } } 35 | 36 | public static Size Empty { 37 | get { return EMPTY; } 38 | } 39 | 40 | public bool IsEmpty { 41 | get { 42 | return width < 0; 43 | } 44 | } 45 | 46 | #endregion 47 | 48 | public static bool Equals (Size size1, Size size2) { 49 | if (size1.IsEmpty) 50 | return size2.IsEmpty; 51 | else 52 | return size1.Width.Equals (size2.Width) 53 | && size1.Height.Equals (size2.Height); 54 | } 55 | 56 | public override bool Equals (object o) { 57 | if ((null == o) || !(o is Size)) 58 | return false; 59 | 60 | Size value = (Size)o; 61 | return Size.Equals (this, value); 62 | } 63 | 64 | public override int GetHashCode () { 65 | if (IsEmpty) 66 | return 0; 67 | else { 68 | // Perform field-by-field XOR of HashCodes 69 | return 70 | this.Width.GetHashCode () ^ 71 | this.Height.GetHashCode (); 72 | } 73 | } 74 | 75 | private float width; 76 | private float height; 77 | 78 | static readonly Size EMPTY = new Size (); 79 | } 80 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/Image.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Graphics; 5 | using WPFLight.Resources; 6 | 7 | namespace System.Windows.Controls { 8 | public class Image : Control { 9 | public Image ( Texture2D texture ) : base ( ) { 10 | if ( texture == null ) 11 | throw new ArgumentNullException ( "texture" ); 12 | 13 | texImage = texture; 14 | this.BorderThickness = new Thickness (); 15 | this.Color = System.Windows.Media.Colors.White; 16 | } 17 | 18 | #region Eigenschaften 19 | 20 | public float Rotation { get; set; } 21 | public System.Windows.Media.Color Color { get; set; } 22 | 23 | #endregion 24 | 25 | public override void Draw ( GameTime gameTime, SpriteBatch batch, float alpha, Matrix transform ) { 26 | base.Draw ( gameTime, batch, alpha, transform ); 27 | 28 | batch.Begin ( 29 | SpriteSortMode.Deferred, 30 | BlendState.AlphaBlend, 31 | null, 32 | DepthStencilState.None, 33 | rasterizerState, 34 | null, 35 | transform ); 36 | 37 | var bounds = this.Bounds; 38 | 39 | batch.Draw ( 40 | texImage, 41 | new Rectangle ( 42 | (int)this.GetAbsoluteLeft ( ), 43 | (int)this.GetAbsoluteTop ( ), 44 | (int)this.ActualWidth, 45 | (int)this.ActualHeight ), 46 | (Rectangle?)null, 47 | System.Windows.Media.ColorHelper.ToXnaColor ( this.Color ) * alpha * this.Opacity, 48 | this.Rotation, 49 | Vector2.Zero, 50 | SpriteEffects.None, 51 | 0); 52 | 53 | batch.End ( ); 54 | } 55 | 56 | private Texture2D texImage; 57 | 58 | static RasterizerState rasterizerState = 59 | new RasterizerState { CullMode = CullMode.None, FillMode = FillMode.Solid, MultiSampleAntiAlias = true }; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Markup/XmlnsPrefixAttribute.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2010 Novell Inc. http://novell.com 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining 5 | // a copy of this software and associated documentation files (the 6 | // "Software"), to deal in the Software without restriction, including 7 | // without limitation the rights to use, copy, modify, merge, publish, 8 | // distribute, sublicense, and/or sell copies of the Software, and to 9 | // permit persons to whom the Software is furnished to do so, subject to 10 | // the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be 13 | // included in all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | // 23 | using System; 24 | using System.Collections; 25 | using System.Collections.Generic; 26 | using System.ComponentModel; 27 | using System.Reflection; 28 | using System.Windows.Markup; 29 | using System.Xaml.Schema; 30 | 31 | namespace System.Windows.Markup 32 | { 33 | [AttributeUsage (AttributeTargets.Assembly, AllowMultiple = true)] 34 | #if !NET_2_1 35 | [System.Runtime.CompilerServices.TypeForwardedFrom (Consts.AssemblyWindowsBase)] 36 | #endif 37 | public sealed class XmlnsPrefixAttribute : Attribute 38 | { 39 | public XmlnsPrefixAttribute (string xmlNamespace, string prefix) 40 | { 41 | XmlNamespace = xmlNamespace; 42 | Prefix = prefix; 43 | } 44 | 45 | public string Prefix { get; private set; } 46 | public string XmlNamespace { get; private set; } 47 | } 48 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/ColorConverter.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Globalization; 3 | //using System.ComponentModel.Design.Serialization; 4 | using System.Reflection; 5 | 6 | namespace System.Windows.Media { 7 | public sealed class ColorConverter : TypeConverter { 8 | public override bool CanConvertFrom (ITypeDescriptorContext td, Type t) { 9 | if (t == typeof(string)) { 10 | return true; 11 | } else { 12 | return false; 13 | } 14 | } 15 | 16 | public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType) { 17 | return base.CanConvertTo (context, destinationType); 18 | } 19 | 20 | public static new object ConvertFromString (string value) { 21 | if (null == value) { 22 | return null; 23 | } 24 | 25 | return ColorHelper.Parse (value, null); 26 | } 27 | 28 | public override object ConvertFrom (ITypeDescriptorContext td, System.Globalization.CultureInfo ci, object value) { 29 | if (value == null) 30 | throw new ArgumentNullException (); 31 | 32 | var s = value as string; 33 | if (s == null) 34 | throw new ArgumentException (); 35 | 36 | return ColorHelper.Parse (s, td); 37 | } 38 | 39 | public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { 40 | /* 41 | if (destinationType != null && value is Color) { 42 | if (destinationType == typeof(InstanceDescriptor)) { 43 | MethodInfo mi = typeof(Color).GetMethod ("FromArgb", new Type[] { 44 | typeof(byte), 45 | typeof(byte), 46 | typeof(byte), 47 | typeof(byte) 48 | }); 49 | Color c = (Color)value; 50 | return new InstanceDescriptor ( 51 | mi, new object[]{ c.A, c.R, c.G, c.B }); 52 | } else if (destinationType == typeof(string)) { 53 | Color c = (Color)value; 54 | return c.ToString (); 55 | } 56 | } 57 | * */ 58 | return base.ConvertTo (context, culture, value, destinationType); 59 | } 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Markup/XmlnsDefinitionAttribute.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2010 Novell Inc. http://novell.com 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining 5 | // a copy of this software and associated documentation files (the 6 | // "Software"), to deal in the Software without restriction, including 7 | // without limitation the rights to use, copy, modify, merge, publish, 8 | // distribute, sublicense, and/or sell copies of the Software, and to 9 | // permit persons to whom the Software is furnished to do so, subject to 10 | // the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be 13 | // included in all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | // 23 | using System; 24 | using System.Collections; 25 | using System.Collections.Generic; 26 | using System.ComponentModel; 27 | using System.Reflection; 28 | using System.Windows.Markup; 29 | using System.Xaml.Schema; 30 | 31 | namespace System.Windows.Markup 32 | { 33 | [AttributeUsage (AttributeTargets.Assembly, AllowMultiple = true)] 34 | #if !NET_2_1 35 | [System.Runtime.CompilerServices.TypeForwardedFrom (Consts.AssemblyWindowsBase)] 36 | #endif 37 | public sealed class XmlnsDefinitionAttribute : Attribute 38 | { 39 | public XmlnsDefinitionAttribute (string xmlNamespace, string clrNamespace) 40 | { 41 | XmlNamespace = xmlNamespace; 42 | ClrNamespace = clrNamespace; 43 | } 44 | 45 | public string AssemblyName { get; set; } 46 | public string ClrNamespace { get; private set; } 47 | public string XmlNamespace { get; private set; } 48 | } 49 | } -------------------------------------------------------------------------------- /WPFLight/System/Xaml/NameScope.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2010 Novell Inc. http://novell.com 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining 5 | // a copy of this software and associated documentation files (the 6 | // "Software"), to deal in the Software without restriction, including 7 | // without limitation the rights to use, copy, modify, merge, publish, 8 | // distribute, sublicense, and/or sell copies of the Software, and to 9 | // permit persons to whom the Software is furnished to do so, subject to 10 | // the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be 13 | // included in all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | // 23 | using System; 24 | using System.Collections; 25 | using System.Collections.Generic; 26 | using System.ComponentModel; 27 | using System.Linq; 28 | using System.Reflection; 29 | using System.Windows.Markup; 30 | using System.Xaml.Schema; 31 | 32 | namespace System.Xaml 33 | { 34 | class NameScope : INameScope 35 | { 36 | Dictionary table = new Dictionary (); 37 | // It is an external read-only namescope. 38 | INameScope external; 39 | 40 | public NameScope (INameScope external) 41 | { 42 | this.external = external; 43 | } 44 | 45 | public object FindName (string name) 46 | { 47 | object obj = external != null ? external.FindName (name) : null; 48 | if (obj != null) 49 | return obj; 50 | return table.TryGetValue (name, out obj) ? obj : null; 51 | } 52 | 53 | public void RegisterName (string name, object scopedElement) 54 | { 55 | table.Add (name, scopedElement); 56 | } 57 | 58 | public void UnregisterName (string name) 59 | { 60 | table.Remove (name); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/UIElementCollection.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls; 2 | using System.Collections.Generic; 3 | using System.Collections; 4 | 5 | public class UIElementCollection : IList { 6 | public UIElementCollection () { 7 | elements = new List(); 8 | } 9 | 10 | public UIElementCollection (UIElement owner) : this( ) { 11 | collectionOwner = owner; 12 | } 13 | 14 | #region Eigenschaften 15 | 16 | public int Count { 17 | get { return elements.Count; } 18 | } 19 | 20 | public bool IsReadOnly { 21 | get { return false; } 22 | } 23 | 24 | #endregion 25 | 26 | public int IndexOf (UIElement item) { 27 | return elements.IndexOf(item); 28 | } 29 | 30 | public void Insert (int index, UIElement item) { 31 | if (collectionOwner != null) 32 | item.Parent = collectionOwner; 33 | 34 | elements.Insert(index, item); 35 | } 36 | 37 | public void RemoveAt (int index) { 38 | elements.RemoveAt(index); 39 | } 40 | 41 | public UIElement this[int index] { 42 | get { 43 | return elements[index]; 44 | } 45 | set { 46 | if (collectionOwner != null) 47 | value.Parent = collectionOwner; 48 | 49 | elements[index] = value; 50 | } 51 | } 52 | 53 | public void Add (UIElement item) { 54 | if (collectionOwner != null) 55 | item.Parent = collectionOwner; 56 | 57 | elements.Add(item); 58 | } 59 | 60 | public void Clear () { 61 | elements.Clear(); 62 | } 63 | 64 | public bool Contains (UIElement item) { 65 | return elements.Contains(item); 66 | } 67 | 68 | public void CopyTo (UIElement[] array, int arrayIndex) { 69 | elements.CopyTo(array, arrayIndex); 70 | } 71 | 72 | public bool Remove (UIElement item) { 73 | return elements.Remove(item); 74 | } 75 | 76 | public IEnumerator GetEnumerator () { 77 | return elements.GetEnumerator(); 78 | } 79 | 80 | IEnumerator IEnumerable.GetEnumerator () { 81 | return elements.GetEnumerator(); 82 | } 83 | 84 | private UIElement collectionOwner; 85 | private List elements; 86 | } -------------------------------------------------------------------------------- /WPFLight.Test/Tests/LayoutTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Controls; 3 | using NUnit.Framework; 4 | 5 | namespace WPFLight.Test { 6 | [TestFixture] 7 | public class LayoutTests { 8 | [SetUp] 9 | public void Setup ( ) { 10 | gridParent = new Grid (); 11 | gridParent.Width = 500; 12 | gridParent.Height = 400; 13 | 14 | button = new Button (); 15 | gridParent.Children.Add (button); 16 | 17 | gridRoot = new Grid (); 18 | gridRoot.Width = 1000; 19 | gridRoot.Height = 1000; 20 | 21 | gridRoot.Children.Add (gridParent); 22 | } 23 | 24 | [Test] 25 | public void TestActualSize ( ) { 26 | button.Width = 100; 27 | button.Height = 150; 28 | Assert.AreEqual (button.Width, button.ActualWidth); 29 | Assert.AreEqual (button.Height, button.ActualHeight); 30 | } 31 | 32 | [Test] 33 | public void TestDerivedSize ( ) { 34 | Assert.AreEqual (gridParent.ActualWidth, button.ActualWidth); 35 | Assert.AreEqual (gridParent.ActualHeight, button.ActualHeight); 36 | } 37 | 38 | [Test] 39 | public void TestParentSize ( ) { 40 | gridParent.HorizontalAlignment = HorizontalAlignment.Left; 41 | gridParent.VerticalAlignment = VerticalAlignment.Top; 42 | 43 | Assert.AreEqual (gridParent.ActualWidth, button.ActualWidth); 44 | Assert.AreEqual (gridParent.ActualHeight, button.ActualHeight); 45 | } 46 | 47 | [Test] 48 | public void TestParentSizeCenter_Unsized ( ) { 49 | gridParent.HorizontalAlignment = HorizontalAlignment.Center; 50 | gridParent.VerticalAlignment = VerticalAlignment.Center; 51 | 52 | Assert.AreEqual (gridParent.ActualWidth, button.ActualWidth); 53 | Assert.AreEqual (gridParent.ActualHeight, button.ActualHeight); 54 | } 55 | 56 | //[Test] 57 | public void TestParentSizeCenter_Sized ( ) { 58 | gridParent.HorizontalAlignment = HorizontalAlignment.Center; 59 | gridParent.VerticalAlignment = VerticalAlignment.Center; 60 | 61 | gridParent.Width = null; 62 | gridParent.Height = null; 63 | 64 | button.Width = 100; 65 | button.Height = 120; 66 | 67 | Assert.AreEqual (gridParent.ActualWidth, button.ActualWidth); 68 | Assert.AreEqual (gridParent.ActualHeight, button.ActualHeight); 69 | } 70 | 71 | private Grid gridRoot; 72 | private Grid gridParent; 73 | private Button button; 74 | } 75 | } 76 | 77 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/RadioButton.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Windows.Media; 3 | using System.Windows.Controls.Primitives; 4 | 5 | namespace System.Windows.Controls { 6 | public class RadioButton : ToggleButton { 7 | public RadioButton () { } 8 | 9 | #region Properties 10 | 11 | public static readonly DependencyProperty GroupNameProperty = 12 | DependencyProperty.Register( 13 | "GroupName", typeof(string), typeof(RadioButton)); 14 | 15 | public string GroupName { 16 | get { return (string)GetValue(GroupNameProperty); } 17 | set { SetValue(GroupNameProperty, value); } 18 | } 19 | 20 | public static readonly DependencyProperty IsUncheckableProperty = 21 | DependencyProperty.Register( 22 | "IsUncheckable", typeof(bool), typeof(RadioButton)); 23 | 24 | public bool IsUncheckable { 25 | get { return (bool)GetValue(IsUncheckableProperty); } 26 | set { SetValue(IsUncheckableProperty, value); } 27 | } 28 | 29 | #endregion 30 | 31 | protected override void OnCheckedChanged (bool chk) { 32 | if (chk) { 33 | // uncheck all RadioButtons with same group-name 34 | var root = VisualTreeHelper.GetRoot (this); 35 | var controls = VisualTreeHelper.GetChildren (root); 36 | foreach (var c in controls) { 37 | if (c != this 38 | && c.IsChecked 39 | && c.GroupName != null 40 | && c.GroupName == this.GroupName 41 | && c.IsChecked ) { 42 | c.IsChecked = false; 43 | } 44 | } 45 | } 46 | base.OnCheckedChanged(chk); 47 | } 48 | 49 | protected override void OnClick () { 50 | RaiseClick (); 51 | if (this.Parent is Panel) { 52 | foreach (var c in ((Panel)this.Parent).Children.OfType()) { 53 | if (c != this && c.IsChecked && c.GroupName == this.GroupName) { 54 | c.IsChecked = false; 55 | } 56 | } 57 | } 58 | if (!this.IsChecked) 59 | this.IsChecked = true; 60 | else { 61 | if (this.IsUncheckable) { 62 | this.IsChecked = false; 63 | } 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/ImageBrush.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using WPFLight.Helpers; 5 | 6 | namespace System.Windows.Media { 7 | public class ImageBrush : Brush { 8 | [Obsolete] 9 | public ImageBrush (GraphicsDevice graphicsDevice, Texture2D texture) 10 | : base (graphicsDevice) { 11 | if (texture == null) 12 | throw new ArgumentNullException (); 13 | 14 | this.Texture = texture; 15 | } 16 | 17 | public ImageBrush (Texture2D texture) 18 | : base () { 19 | if (texture == null) 20 | throw new ArgumentNullException (); 21 | 22 | this.Texture = texture; 23 | } 24 | 25 | 26 | #region Properties 27 | 28 | internal Texture2D Texture { get; private set; } 29 | 30 | #endregion 31 | 32 | public override void Draw (SpriteBatch batch, Rectangle bounds, Matrix transform, float alpha) { 33 | if ( alpha > 0 ) { 34 | GraphicsDevice.ScissorRectangle = ScreenHelper.CheckScissorRect (bounds); 35 | batch.Begin ( 36 | SpriteSortMode.Deferred, 37 | alpha == 1 ? BlendState.AlphaBlend : BlendState.AlphaBlend, 38 | SamplerState.LinearClamp, 39 | DepthStencilState.None, 40 | scissorEnabled, 41 | null, 42 | transform); 43 | 44 | var cx = (int)Math.Ceiling ( 45 | (float)bounds.Width / (float)Texture.Width); 46 | 47 | var cy = (int)Math.Ceiling ( 48 | (float)bounds.Height / (float)Texture.Height); 49 | 50 | for (var y = 0; y < Math.Max (1, cy); y++) { 51 | for (var x = 0; x < Math.Max (1, cx); x++) { 52 | batch.Draw ( 53 | Texture, 54 | new Microsoft.Xna.Framework.Rectangle ( 55 | bounds.X + x * Texture.Width, 56 | bounds.Y + y * Texture.Height, 57 | Texture.Width, 58 | Texture.Height), 59 | null, 60 | Microsoft.Xna.Framework.Color.White * alpha, 61 | 0, 62 | new Vector2 (), 63 | SpriteEffects.None, 64 | 0); 65 | } 66 | } 67 | batch.End (); 68 | } 69 | } 70 | 71 | internal override Color GetPixel (int x, int y, int width, int height) { 72 | throw new NotImplementedException (); 73 | } 74 | 75 | internal override int[] GetTextureData (int width, int height) { 76 | // TODO, test 77 | var data = new int []{}; 78 | Texture.GetData(data); 79 | return data; 80 | } 81 | 82 | static RasterizerState scissorEnabled = 83 | new RasterizerState { 84 | CullMode = CullMode.None, 85 | FillMode = FillMode.Solid, 86 | ScissorTestEnable = true, 87 | MultiSampleAntiAlias = false }; 88 | 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/DependencyProperty.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | namespace System.Windows { 3 | public sealed class DependencyProperty { 4 | static DependencyProperty () { 5 | registeredProperties = new List(); 6 | attachedProperties = new List(); 7 | } 8 | 9 | DependencyProperty ( 10 | string propertyName, Type propertyType, Type ownerType ) { 11 | 12 | this.Name = propertyName; 13 | this.PropertyType = propertyType; 14 | this.OwnerType = ownerType; 15 | } 16 | 17 | DependencyProperty ( 18 | string propertyName, 19 | Type propertyType, 20 | Type ownerType, 21 | PropertyMetadata metadata ) { 22 | 23 | this.Name = propertyName; 24 | this.PropertyType = propertyType; 25 | this.OwnerType = ownerType; 26 | this.DefaultMetadata = metadata; 27 | } 28 | 29 | 30 | #region Eigenschaften 31 | 32 | public string Name { get; private set; } 33 | public Type PropertyType { get; private set; } 34 | public Type OwnerType { get; private set; } 35 | public PropertyMetadata DefaultMetadata { get; private set; } 36 | 37 | #endregion 38 | 39 | public static DependencyProperty Register ( string name, Type propertyType, Type ownerType ) { 40 | return Register (name, propertyType, ownerType, null); 41 | } 42 | 43 | public static DependencyProperty Register ( string name, Type propertyType, Type ownerType, PropertyMetadata metadata ) { 44 | var prop = new DependencyProperty(name, propertyType, ownerType,metadata); 45 | registeredProperties.Add(prop); 46 | return prop; 47 | } 48 | 49 | public static DependencyProperty RegisterAttached ( string name, Type propertyType, Type ownerType ) { 50 | return RegisterAttached (name, propertyType, ownerType, null); 51 | } 52 | 53 | public static DependencyProperty RegisterAttached (string name, Type propertyType, Type ownerType, PropertyMetadata metadata) { 54 | var prop = new DependencyProperty(name, propertyType, ownerType, metadata); 55 | attachedProperties.Add(prop); 56 | return prop; 57 | } 58 | 59 | internal static bool IsRegisteredProperty (string propertyName, Type ownerType) { 60 | foreach (var prop in registeredProperties) 61 | if (prop.OwnerType == ownerType && prop.Name == propertyName) 62 | return true; 63 | 64 | return false; 65 | } 66 | 67 | public static readonly object UnsetValue = new object(); 68 | 69 | private static List registeredProperties; 70 | private static List attachedProperties; 71 | } 72 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/SolidColorBrush.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using Microsoft.Xna.Framework.Graphics; 3 | using WPFLight.Helpers; 4 | using WPFLight.Extensions; 5 | 6 | namespace System.Windows.Media { 7 | public class SolidColorBrush : Brush { 8 | public SolidColorBrush () { } 9 | 10 | public SolidColorBrush (GraphicsDevice device) : base (device) {} 11 | 12 | public SolidColorBrush (GraphicsDevice device, Color color) 13 | : base (device) { 14 | this.Color = color; 15 | } 16 | 17 | public SolidColorBrush (Color color) { 18 | this.Color = color; 19 | } 20 | 21 | public SolidColorBrush (byte r, byte g, byte b) { 22 | this.Color = new Color (r, g, b); 23 | } 24 | 25 | public SolidColorBrush (byte r, byte g, byte b, byte a) { 26 | this.Color = new Color (r, g, b, a); 27 | } 28 | 29 | public SolidColorBrush (float r, float g, float b) { 30 | this.Color = new Color (r, g, b); 31 | } 32 | 33 | public SolidColorBrush (float r, float g, float b, float a) { 34 | this.Color = new Color (r, g, b, a); 35 | } 36 | 37 | #region Properties 38 | 39 | public System.Windows.Media.Color Color { get; set; } 40 | 41 | internal Texture2D Texture { get { return solid; } } 42 | 43 | #endregion 44 | 45 | public override void Draw (SpriteBatch batch, Rectangle bounds, Matrix transform, float alpha) { 46 | if (solid == null) 47 | solid = CreateSolidTexture (); 48 | 49 | batch.Begin ( 50 | SpriteSortMode.Texture, 51 | BlendState.AlphaBlend, 52 | SamplerState.LinearClamp, 53 | DepthStencilState.None, 54 | RasterizerState.CullNone, 55 | null, 56 | transform); 57 | 58 | var color = ColorHelper.ToXnaColor (this.Color); 59 | batch.Draw (solid, bounds, (color * ((float)color.A / 255f) * alpha)); 60 | batch.End (); 61 | } 62 | 63 | Texture2D CreateSolidTexture () { 64 | var width = 10; 65 | var height = 10; 66 | var tex = new Texture2D (ScreenHelper.Device, width, height); 67 | var pixels = GetTextureData(width, height); 68 | tex.SetData (pixels); 69 | return tex; 70 | } 71 | 72 | internal override Color GetPixel (int x, int y, int width, int height) { 73 | return this.Color; 74 | } 75 | 76 | internal override int[] GetTextureData (int width, int height) { 77 | var pixels = new int[width * height]; 78 | pixels.Fill((int)this.Color.PackedValue); 79 | //pixels[y * width + x] 80 | return pixels; 81 | } 82 | 83 | public override int GetHashCode () { 84 | return this.Color.GetHashCode(); 85 | } 86 | 87 | public override bool Equals (object obj) { 88 | return obj is SolidColorBrush 89 | && ((SolidColorBrush)obj).Color == this.Color; 90 | } 91 | 92 | static Texture2D solid; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/Primitives/Selector.cs: -------------------------------------------------------------------------------- 1 | namespace System.Windows.Controls.Primitives { 2 | public class Selector : ItemsControl { 3 | public event EventHandler SelectionChanged; 4 | 5 | #region Eigenschaften 6 | 7 | public static DependencyProperty SelectedIndexProperty = 8 | DependencyProperty.Register( 9 | "SelectedIndex", 10 | typeof(int), 11 | typeof(Selector), 12 | new PropertyMetadata( 13 | -1, new PropertyChangedCallback( 14 | (s, e) => { 15 | ((Selector)s).OnSelectedIndexChanged( e ); 16 | }))); 17 | 18 | public int SelectedIndex { 19 | get{ return ( int ) GetValue(SelectedIndexProperty); } 20 | set{ SetValue(SelectedIndexProperty, value); } 21 | } 22 | 23 | public static DependencyProperty SelectedItemProperty = 24 | DependencyProperty.Register( 25 | "SelectedItem", 26 | typeof(Object), 27 | typeof(Selector), 28 | new PropertyMetadata( 29 | new PropertyChangedCallback( 30 | (s, e) => { 31 | ((Selector)s).OnSelectedItemChanged ( e ); 32 | }))); 33 | 34 | public object SelectedItem { 35 | get{ return ( object ) GetValue(SelectedItemProperty); } 36 | set{ SetValue(SelectedItemProperty, value); } 37 | } 38 | 39 | #endregion 40 | 41 | void OnSelectedItemChanged ( DependencyPropertyChangedEventArgs e) { 42 | this.SelectedIndex = this.GetIndex(this.SelectedItem); 43 | 44 | /* 45 | if (e.OldValue != null) 46 | ((TabItem)e.OldValue).IsSelected = false; 47 | 48 | if (e.NewValue != null) 49 | ((TabItem)e.NewValue).IsSelected = true; 50 | */ 51 | } 52 | 53 | void OnSelectedIndexChanged ( DependencyPropertyChangedEventArgs e ) { 54 | this.SelectedItem = this.GetItem(this.SelectedIndex); 55 | this.OnSelectionChanged(); 56 | } 57 | 58 | protected virtual void OnSelectionChanged ( ) { 59 | if (this.SelectionChanged != null) 60 | this.SelectionChanged(this, EventArgs.Empty); 61 | } 62 | 63 | int GetIndex (object item) { 64 | if (item != null) { 65 | var index = 0; 66 | foreach (var child in Items ) { 67 | if (item == child) 68 | return index; 69 | 70 | index++; 71 | } 72 | } 73 | return -1; 74 | } 75 | 76 | object GetItem (int index) { 77 | if (index != -1 ) { 78 | return this.Items[index]; 79 | } 80 | return null; 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/RadialGradientBrush.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Xna.Framework.Graphics; 3 | using Microsoft.Xna.Framework; 4 | 5 | namespace System.Windows.Media { 6 | public class RadialGradientBrush : GradientBrush { 7 | public RadialGradientBrush ( ) : base ( ) { 8 | this.Radius = 1; 9 | this.Center = new Vector2 (.5f, .5f); 10 | this.GradientOrigin = new Vector2 (0.5f, 1f); 11 | } 12 | 13 | protected override Texture2D CreateTexture () { 14 | var width = 100; 15 | var height = 100; 16 | 17 | var tex = new Texture2D (this.GraphicsDevice, width, height); 18 | var data = new int[width * height]; 19 | 20 | int x, y; 21 | float grad, fx_, fy_, dx, dy, denom, radius2, dx2, dy2; 22 | 23 | fx_ = this.GradientOrigin.X - this.Center.X; 24 | fy_ = this.GradientOrigin.Y - this.Center.Y; 25 | radius2 = this.Radius * this.Radius; 26 | denom = 1.0f / (radius2 - ((fx_ * fx_) + (fy_ * fy_))); 27 | 28 | for (y = 0; y < height; ++y) { 29 | for (x = 0; x < width; ++x) { 30 | dx = x - this.GradientOrigin.X; 31 | dy = y - this.GradientOrigin.Y; 32 | dx2 = dx * dx; 33 | dy2 = dy * dy; 34 | grad = (radius2 * (dx2 + dy2)) - ((dx * fy_ - dy * fx_) * (dx * fy_ - dy * fx_)); 35 | grad = ((dx * fx_ + dy * fy_) + (float)Math.Sqrt (grad)); 36 | grad *= denom; 37 | 38 | data [y * width + x] = 39 | (int)GetGradientColor (grad / 100f).PackedValue; 40 | } 41 | } 42 | tex.SetData (data); 43 | return tex; 44 | } 45 | 46 | internal override Color GetPixel (int x, int y, int width, int height) { 47 | float grad, fx_, fy_, dx, dy, denom, radius2, dx2, dy2; 48 | 49 | fx_ = this.GradientOrigin.X - this.Center.X; 50 | fy_ = this.GradientOrigin.Y - this.Center.Y; 51 | radius2 = this.Radius * this.Radius; 52 | denom = 1.0f / (radius2 - ((fx_ * fx_) + (fy_ * fy_))); 53 | 54 | dx = x - this.GradientOrigin.X; 55 | dy = y - this.GradientOrigin.Y; 56 | dx2 = dx * dx; 57 | dy2 = dy * dy; 58 | grad = (radius2 * (dx2 + dy2)) - ((dx * fy_ - dy * fx_) * (dx * fy_ - dy * fx_)); 59 | grad = ((dx * fx_ + dy * fy_) + (float)Math.Sqrt (grad)); 60 | grad *= denom; 61 | 62 | return this.GetGradientColor (grad / 100f); 63 | } 64 | 65 | internal override int[] GetTextureData (int width, int height) { 66 | throw new NotImplementedException(); 67 | } 68 | 69 | #region Eigenschaften 70 | 71 | /// 72 | /// gets or sets the radius of the radial-gradient 73 | /// 74 | public float Radius { get; set; } 75 | 76 | /// 77 | /// gets or sets the center-point 78 | /// 79 | public Vector2 Center { get; set; } 80 | 81 | /// 82 | /// gets or sets the focus-point 83 | /// 84 | public Vector2 GradientOrigin { get; set; } 85 | 86 | #endregion 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Style.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using System.Windows.Markup; 4 | using WPFLight.Helpers; 5 | 6 | namespace System.Windows { 7 | [ContentProperty("Setters")] 8 | public class Style { 9 | public Style () {} 10 | 11 | public Style (Type targetType) { 12 | this.TargetType = targetType; 13 | } 14 | 15 | public Style (Type targetType, Style basedOn) { 16 | this.TargetType = targetType; 17 | this.BasedOn = basedOn; 18 | 19 | if (basedOn != null) { 20 | foreach (var setter in basedOn.Setters) 21 | this.Setters.Add(setter); 22 | 23 | foreach (var trigger in basedOn.Triggers) 24 | this.Triggers.Add(trigger); 25 | } 26 | } 27 | 28 | #region Eigenschaften 29 | 30 | public Type TargetType { get; set; } 31 | 32 | public SetterCollection Setters { 33 | get { 34 | if (setters == null) 35 | setters = new SetterCollection(); 36 | 37 | return setters; 38 | } 39 | internal set { 40 | setters = value; 41 | } 42 | } 43 | 44 | public TriggerCollection Triggers { 45 | get { 46 | if (triggers == null) 47 | triggers = new TriggerCollection(); 48 | 49 | return triggers; 50 | } 51 | internal set { 52 | triggers = value; 53 | } 54 | } 55 | 56 | public Style BasedOn { 57 | get; 58 | internal set; 59 | } 60 | 61 | #endregion 62 | 63 | /// 64 | /// Wenn true, dann wird der Type, welcher über die Style-Key-Eigenschaft zugewiesen wurde 65 | /// mit diesem Style überschrieben 66 | /// 67 | /// true if overrides default style; otherwise, false. 68 | public bool OverridesDefaultStyle { 69 | get { 70 | var setter = this.Setters 71 | .Where ( s => s.Property.Name == "OverridesDefaultStyle" ) 72 | .FirstOrDefault ( ); 73 | 74 | if (setter != null) 75 | return (bool)setter.Value; 76 | 77 | return false; 78 | } 79 | } 80 | 81 | /// 82 | /// Gibt eine Style-Resource zurück, welcher zuvor über einen Namen oder einen Type zugewiesen wurde 83 | /// 84 | /// The style. 85 | /// Key. 86 | public static Style GetStyleResource ( object resourceKey ) { 87 | return ( Style ) ResourceHelper.GetResource (resourceKey); 88 | } 89 | 90 | public static Style Parse ( string xaml ) { 91 | return ( Style ) XamlReader.Parse (xaml); 92 | } 93 | 94 | private SetterCollection setters; 95 | private TriggerCollection triggers; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/StackPanel.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Microsoft.Xna.Framework; 3 | using System; 4 | using System.Windows; 5 | 6 | namespace System.Windows.Controls { 7 | public class StackPanel : Panel { 8 | public StackPanel () : base () { 9 | Orientation = Orientation.Vertical; 10 | } 11 | 12 | #region Properties 13 | 14 | public static readonly DependencyProperty OrientationProperty = 15 | DependencyProperty.Register ( 16 | "Orientation", 17 | typeof ( Orientation ), 18 | typeof ( StackPanel ), 19 | new FrameworkPropertyMetadata ( 20 | Orientation.Vertical, 21 | FrameworkPropertyMetadataOptions.AffectsMeasure ) ); 22 | 23 | public Orientation Orientation { 24 | get { return (Orientation)GetValue (OrientationProperty); } 25 | set { SetValue (OrientationProperty, value); } 26 | } 27 | 28 | #endregion 29 | 30 | internal override float MeasureHeight (float availableHeight) { 31 | var height = 0f; 32 | var maxHeight = 0f; 33 | foreach (var c in this.Children.OfType ( )) { 34 | var itemHeight = c.ActualHeight + c.Margin.Bottom + c.Margin.Top; 35 | 36 | if (this.Orientation == Orientation.Vertical) 37 | height += itemHeight; 38 | else 39 | maxHeight = Math.Max (itemHeight, maxHeight); 40 | } 41 | return (this.Orientation == Orientation.Vertical) 42 | ? height : maxHeight; 43 | } 44 | 45 | internal override float MeasureWidth (float availableWidth) { 46 | var width = 0f; 47 | var maxWidth = 0f; 48 | foreach (var c in this.Children.OfType ( )) { 49 | var itemWidth = c.ActualWidth + c.Margin.Right + c.Margin.Left; 50 | 51 | if (this.Orientation == Orientation.Horizontal) 52 | width += itemWidth; 53 | else 54 | maxWidth = Math.Max (itemWidth, maxWidth); 55 | } 56 | 57 | return (this.Orientation == Orientation.Horizontal) 58 | ? width : maxWidth; 59 | } 60 | 61 | internal override float GetAbsoluteLeft (UIElement child) { 62 | var left = child.Parent.GetAbsoluteLeft (); 63 | left += this.Padding.Left; 64 | foreach (var c in this.Children.OfType()) { 65 | if (c == child) 66 | return left + c.Margin.Left; 67 | 68 | if (this.Orientation == Orientation.Horizontal) 69 | left += c.ActualWidth + c.Margin.Right + c.Margin.Left; 70 | } 71 | return base.GetAbsoluteLeft (child); 72 | } 73 | 74 | internal override float GetAbsoluteTop (UIElement child) { 75 | var top = child.Parent.GetAbsoluteTop (); 76 | top += this.Padding.Top; 77 | foreach (var c in this.Children.OfType()) { 78 | if (c == child) 79 | return top + c.Margin.Top; 80 | 81 | if (this.Orientation == Orientation.Vertical) 82 | top += c.ActualHeight + c.Margin.Bottom + c.Margin.Top; 83 | } 84 | return base.GetAbsoluteTop (child); 85 | } 86 | } 87 | 88 | public enum Orientation { 89 | Vertical, 90 | Horizontal, 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | 11 | [Dd]ebug/ 12 | [Rr]elease/ 13 | x64/ 14 | build/ 15 | [Oo]bj/ 16 | 17 | # MSTest test Results 18 | [Tt]est[Rr]esult*/ 19 | [Bb]uild[Ll]og.* 20 | 21 | *_i.c 22 | *_p.c 23 | *.ilk 24 | *.meta 25 | *.obj 26 | *.pch 27 | *.pdb 28 | *.pgc 29 | *.pgd 30 | *.rsp 31 | *.sbr 32 | *.tlb 33 | *.tli 34 | *.tlh 35 | *.tmp 36 | *.tmp_proj 37 | *.log 38 | *.vspscc 39 | *.vssscc 40 | .builds 41 | *.pidb 42 | *.log 43 | *.scc 44 | 45 | # Visual C++ cache files 46 | ipch/ 47 | *.aps 48 | *.ncb 49 | *.opensdf 50 | *.sdf 51 | *.cachefile 52 | 53 | # Visual Studio profiler 54 | *.psess 55 | *.vsp 56 | *.vspx 57 | 58 | # Guidance Automation Toolkit 59 | *.gpState 60 | 61 | # ReSharper is a .NET coding add-in 62 | _ReSharper*/ 63 | *.[Rr]e[Ss]harper 64 | 65 | # TeamCity is a build add-in 66 | _TeamCity* 67 | 68 | # DotCover is a Code Coverage Tool 69 | *.dotCover 70 | 71 | # NCrunch 72 | *.ncrunch* 73 | .*crunch*.local.xml 74 | 75 | # Installshield output folder 76 | [Ee]xpress/ 77 | 78 | # DocProject is a documentation generator add-in 79 | DocProject/buildhelp/ 80 | DocProject/Help/*.HxT 81 | DocProject/Help/*.HxC 82 | DocProject/Help/*.hhc 83 | DocProject/Help/*.hhk 84 | DocProject/Help/*.hhp 85 | DocProject/Help/Html2 86 | DocProject/Help/html 87 | 88 | # Click-Once directory 89 | publish/ 90 | 91 | # Publish Web Output 92 | *.Publish.xml 93 | *.pubxml 94 | 95 | # NuGet Packages Directory 96 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 97 | #packages/ 98 | 99 | # Windows Azure Build Output 100 | csx 101 | *.build.csdef 102 | 103 | # Windows Store app package directory 104 | AppPackages/ 105 | 106 | # Others 107 | sql/ 108 | *.Cache 109 | ClientBin/ 110 | [Ss]tyle[Cc]op.* 111 | ~$* 112 | *~ 113 | *.dbmdl 114 | *.[Pp]ublish.xml 115 | *.pfx 116 | *.publishsettings 117 | 118 | # RIA/Silverlight projects 119 | Generated_Code/ 120 | 121 | # Backup & report files from converting an old project file to a newer 122 | # Visual Studio version. Backup files are not needed, because we have git ;-) 123 | _UpgradeReport_Files/ 124 | Backup*/ 125 | UpgradeLog*.XML 126 | UpgradeLog*.htm 127 | 128 | # SQL Server files 129 | App_Data/*.mdf 130 | App_Data/*.ldf 131 | 132 | 133 | #LightSwitch generated files 134 | GeneratedArtifacts/ 135 | _Pvt_Extensions/ 136 | ModelManifest.xml 137 | 138 | # ========================= 139 | # Windows detritus 140 | # ========================= 141 | 142 | # Windows image file caches 143 | Thumbs.db 144 | ehthumbs.db 145 | 146 | # Folder config file 147 | Desktop.ini 148 | 149 | # Recycle Bin used on file shares 150 | $RECYCLE.BIN/ 151 | 152 | # Mac desktop service store files 153 | .DS_Store 154 | -------------------------------------------------------------------------------- /WPFLight/System/Xaml/XamlReader.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2010 Novell Inc. http://novell.com 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining 5 | // a copy of this software and associated documentation files (the 6 | // "Software"), to deal in the Software without restriction, including 7 | // without limitation the rights to use, copy, modify, merge, publish, 8 | // distribute, sublicense, and/or sell copies of the Software, and to 9 | // permit persons to whom the Software is furnished to do so, subject to 10 | // the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be 13 | // included in all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | // 23 | using System; 24 | using System.Collections.Generic; 25 | 26 | namespace System.Xaml 27 | { 28 | public abstract class XamlReader : IDisposable 29 | { 30 | protected bool IsDisposed { get; private set; } 31 | 32 | public abstract bool IsEof { get; } 33 | public abstract XamlMember Member { get; } 34 | public abstract NamespaceDeclaration Namespace { get; } 35 | public abstract XamlNodeType NodeType { get; } 36 | public abstract XamlSchemaContext SchemaContext { get; } 37 | public abstract XamlType Type { get; } 38 | public abstract object Value { get; } 39 | 40 | public void Close () 41 | { 42 | Dispose (true); 43 | } 44 | 45 | protected virtual void Dispose (bool disposing) 46 | { 47 | IsDisposed = true; 48 | } 49 | 50 | void IDisposable.Dispose () 51 | { 52 | Dispose (true); 53 | } 54 | 55 | public abstract bool Read (); 56 | 57 | public virtual XamlReader ReadSubtree () 58 | { 59 | return new XamlSubtreeReader (this); 60 | } 61 | 62 | public virtual void Skip () 63 | { 64 | int count = 0; 65 | switch (NodeType) { 66 | case XamlNodeType.StartMember: 67 | case XamlNodeType.StartObject: 68 | case XamlNodeType.GetObject: 69 | count++; 70 | while (Read ()) { 71 | switch (NodeType) { 72 | case XamlNodeType.StartMember: 73 | case XamlNodeType.GetObject: 74 | case XamlNodeType.StartObject: 75 | count++; 76 | continue; 77 | case XamlNodeType.EndMember: 78 | case XamlNodeType.EndObject: 79 | count--; 80 | if (count == 0) { 81 | Read (); 82 | return; 83 | } 84 | continue; 85 | } 86 | } 87 | return; 88 | 89 | default: 90 | Read (); 91 | return; 92 | } 93 | } 94 | } 95 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/Animation/Clock.cs: -------------------------------------------------------------------------------- 1 | namespace System.Windows.Media.Animation { 2 | public class Clock { 3 | protected internal Clock ( Timeline timeline ) { 4 | Timeline = timeline; 5 | } 6 | 7 | #region Ereignisse 8 | 9 | public event EventHandler CurrentStateInvalidated; 10 | public event EventHandler CurrentTimeInvalidated; 11 | 12 | #endregion 13 | 14 | #region Eigenschaften 15 | 16 | public ClockState CurrentState { get; private set; } 17 | 18 | public double? CurrentProgress { get; set; } 19 | 20 | public Timeline Timeline { get; private set; } 21 | 22 | public TimeSpan? CurrentTime { get; private set; } 23 | 24 | protected TimeSpan CurrentGlobalTime { 25 | get { 26 | return currentGlobalTime; 27 | } 28 | } 29 | 30 | #endregion 31 | 32 | /// 33 | /// Wird nur einmal global innerhalb der GameLoop aufgerufen 34 | /// 35 | /// 36 | internal static void SetCurrentGlobalTime (TimeSpan time) { 37 | currentGlobalTime = time; 38 | } 39 | 40 | static TimeSpan currentGlobalTime; 41 | } 42 | 43 | // Summary: 44 | // Describes the potential states of a timeline's System.Windows.Media.Animation.Clock 45 | // object. 46 | public enum ClockState { 47 | // Summary: 48 | // The current System.Windows.Media.Animation.Clock time changes in direct relation 49 | // to that of its parent. If the timeline is an animation, it is actively affecting 50 | // targeted properties, so their value may change from tick (a sampling point 51 | // in time) to tick. If the timeline has children, they may be System.Windows.Media.Animation.ClockState.Active, 52 | // System.Windows.Media.Animation.ClockState.Filling, or System.Windows.Media.Animation.ClockState.Stopped. 53 | Active = 0, 54 | // 55 | // Summary: 56 | // The System.Windows.Media.Animation.Clock timing continues, but does not change 57 | // in relation to that of its parent. If the timeline is an animation, it is 58 | // actively affecting targeted properties, but its values don't change from 59 | // tick to tick. If the timeline has children, they may be System.Windows.Media.Animation.ClockState.Active, 60 | // System.Windows.Media.Animation.ClockState.Filling, or System.Windows.Media.Animation.ClockState.Stopped. 61 | Filling = 1, 62 | // 63 | // Summary: 64 | // The System.Windows.Media.Animation.Clock timing is halted, making the clock's 65 | // current time and progress values undefined. If this timeline is an animation, 66 | // it no longer affects targeted properties. If this timeline has children, 67 | // they are also System.Windows.Media.Animation.ClockState.Stopped. 68 | Stopped = 2, 69 | } 70 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/Button.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Windows.Media; 4 | 5 | using Microsoft.Xna.Framework; 6 | using Microsoft.Xna.Framework.Graphics; 7 | using Microsoft.Xna.Framework.Input; 8 | using Microsoft.Xna.Framework.Input.Touch; 9 | 10 | namespace System.Windows.Controls { 11 | public class Button : ContentControl { 12 | public Button () { } 13 | 14 | #region Ereignisse 15 | 16 | public event EventHandler Click; 17 | 18 | #endregion 19 | 20 | #region Eigenschaften 21 | 22 | public static readonly DependencyProperty CornerRadiusXProperty = 23 | DependencyProperty.Register( 24 | "CornerRadiusX", 25 | typeof(int), 26 | typeof(Button)); 27 | 28 | public int CornerRadiusX { 29 | get { return (int)GetValue(CornerRadiusXProperty); } 30 | set { SetValue(CornerRadiusXProperty, value); 31 | } 32 | } 33 | 34 | public static readonly DependencyProperty CornerRadiusYProperty = 35 | DependencyProperty.Register( 36 | "CornerRadiusY", 37 | typeof(int), 38 | typeof(Button)); 39 | 40 | public int CornerRadiusY { 41 | get { return (int)GetValue(CornerRadiusYProperty); } 42 | set { SetValue(CornerRadiusYProperty, value); } 43 | } 44 | 45 | #endregion 46 | 47 | public override void Invalidate () { 48 | base.Invalidate (); 49 | if (this.IsInitialized) { 50 | if (rcBackground == null ) { 51 | rcBackground = new System.Windows.Shapes.Rectangle( ); 52 | rcBackground.Parent = this; 53 | rcBackground.Initialize (); 54 | } 55 | rcBackground.Stroke = this.BorderBrush; 56 | rcBackground.Fill = this.Background; 57 | rcBackground.StrokeThickness = this.BorderThickness.Left; 58 | rcBackground.RadiusX = this.CornerRadiusX; 59 | rcBackground.RadiusY = this.CornerRadiusY; 60 | rcBackground.Invalidate (); 61 | } 62 | } 63 | 64 | public override void Initialize () { 65 | base.Initialize(); 66 | } 67 | 68 | protected override void OnBackgroundChanged (Brush color) { 69 | base.OnBackgroundChanged (color); 70 | } 71 | 72 | protected override void DrawBackground (GameTime gameTime, SpriteBatch batch, float alpha, Matrix transform) { 73 | if ( rcBackground != null ) 74 | rcBackground.Draw(gameTime, batch, alpha, transform); 75 | } 76 | 77 | protected virtual void OnClick () { 78 | this.RaiseClick(); 79 | } 80 | 81 | internal protected void RaiseClick ( ) { 82 | if (this.Click != null) 83 | this.Click (this, EventArgs.Empty); 84 | } 85 | 86 | public override void OnTouchDown (TouchLocation state) { 87 | mouseDown = true; 88 | base.OnTouchDown (state); 89 | } 90 | 91 | public override void OnTouchUp (TouchLocation state) { 92 | if (mouseDown) { 93 | OnClick (); 94 | mouseDown = false; 95 | } 96 | base.OnTouchUp (state); 97 | } 98 | 99 | private bool mouseDown; 100 | private Shapes.Rectangle rcBackground; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/WrapPanel.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Microsoft.Xna.Framework; 3 | using System; 4 | 5 | namespace System.Windows.Controls { 6 | public class WrapPanel : Canvas { 7 | public WrapPanel () : base () { 8 | 9 | } 10 | 11 | #region Properties 12 | 13 | public static readonly DependencyProperty OrientationProperty = 14 | DependencyProperty.Register ( 15 | "Orientation", 16 | typeof ( Orientation ), 17 | typeof ( WrapPanel ), 18 | new FrameworkPropertyMetadata ( 19 | Orientation.Vertical, 20 | FrameworkPropertyMetadataOptions.AffectsMeasure ) ); 21 | 22 | public Orientation Orientation { 23 | get { return (Orientation)GetValue (OrientationProperty); } 24 | set { SetValue (OrientationProperty, value); } 25 | } 26 | 27 | #endregion 28 | 29 | internal override float MeasureHeight (float availableHeight) { 30 | var height = 0f; 31 | var maxHeight = 0f; 32 | foreach (var c in this.Children.OfType ( )) { 33 | var itemHeight = c.ActualHeight + c.Margin.Bottom + c.Margin.Top; 34 | if (this.Orientation == Orientation.Vertical) 35 | height += itemHeight; 36 | else 37 | maxHeight = Math.Max (itemHeight, maxHeight); 38 | } 39 | return (this.Orientation == Orientation.Vertical) 40 | ? height : maxHeight; 41 | 42 | } 43 | 44 | internal override float MeasureWidth (float availableWidth) { 45 | var width = 0f; 46 | var maxWidth = 0f; 47 | foreach (var c in this.Children.OfType ( )) { 48 | var itemWidth = c.ActualWidth + c.Margin.Right + c.Margin.Left; 49 | if (this.Orientation == Orientation.Horizontal) 50 | width += itemWidth; 51 | else 52 | maxWidth = Math.Max (itemWidth, maxWidth); 53 | } 54 | return (this.Orientation == Orientation.Horizontal) 55 | ? width : maxWidth; 56 | } 57 | 58 | public override void Invalidate () { 59 | base.Invalidate (); 60 | if (this.IsInitialized) { 61 | this.Refresh (); 62 | } 63 | } 64 | 65 | void Refresh ( ) { 66 | var left = this.Padding.Left; // 0f; 67 | var top = this.Padding.Top; // 0f; 68 | foreach (var c in this.Children.OfType ( )) { 69 | if (this.Orientation == Orientation.Vertical) { 70 | if ((top + c.ActualHeight + c.Margin.Bottom) > this.ActualHeight) { 71 | top = this.Padding.Top; 72 | left += c.ActualWidth + c.Margin.Right; 73 | } 74 | 75 | if (top == this.Padding.Top) 76 | left += c.Margin.Left; 77 | 78 | top += c.Margin.Top; 79 | 80 | SetLeft (c, (int)left); 81 | SetTop (c, (int)top); 82 | 83 | top += c.ActualHeight + c.Margin.Bottom; 84 | } else { 85 | if ((left + c.ActualWidth + c.Margin.Right) > this.ActualWidth) { 86 | left = this.Padding.Left; 87 | top += c.ActualHeight + c.Margin.Bottom; 88 | } 89 | 90 | if (left == this.Padding.Left) 91 | top += c.Margin.Top; 92 | 93 | left += c.Margin.Left; 94 | 95 | SetLeft (c, (int)left); 96 | SetTop (c, (int)top); 97 | 98 | left += c.ActualWidth + c.Margin.Right; 99 | } 100 | } 101 | } 102 | 103 | public override void Initialize () { 104 | this.Refresh (); 105 | base.Initialize (); 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /WPFLight/System/Collections/ObjectModel/ObservableCollection.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Specialized; 2 | using System.ComponentModel; 3 | using System.Collections.Generic; 4 | 5 | namespace System.Collections.ObjectModel { 6 | public class ObservableCollection 7 | : Collection, INotifyCollectionChanged, INotifyPropertyChanged { 8 | public ObservableCollection () 9 | : base() { } 10 | 11 | public ObservableCollection ( IList list ) 12 | : base ( list ) { } 13 | 14 | #region Events 15 | 16 | public event NotifyCollectionChangedEventHandler CollectionChanged; 17 | public event PropertyChangedEventHandler PropertyChanged; 18 | 19 | #endregion 20 | 21 | protected override void InsertItem (int index, T item) { 22 | base.InsertItem(index, item); 23 | 24 | OnCollectionChanged( 25 | new NotifyCollectionChangedEventArgs( 26 | NotifyCollectionChangedAction.Add, item, index)); 27 | 28 | OnPropertyChanged( 29 | new PropertyChangedEventArgs("Count")); 30 | 31 | OnPropertyChanged( 32 | new PropertyChangedEventArgs("Item[]")); 33 | } 34 | 35 | protected virtual void MoveItem (int oldIndex, int newIndex) { 36 | var item = Items[oldIndex]; 37 | base.RemoveItem(oldIndex); 38 | base.InsertItem(newIndex, item); 39 | 40 | OnCollectionChanged( 41 | new NotifyCollectionChangedEventArgs( 42 | NotifyCollectionChangedAction.Move, item, newIndex, oldIndex)); 43 | 44 | OnPropertyChanged( 45 | new PropertyChangedEventArgs("Item[]")); 46 | } 47 | 48 | protected override void SetItem (int index, T item) { 49 | var oldItem = Items [index]; 50 | base.SetItem (index, item); 51 | 52 | OnCollectionChanged ( 53 | new NotifyCollectionChangedEventArgs ( 54 | NotifyCollectionChangedAction.Replace, item, oldItem, index)); 55 | 56 | OnPropertyChanged ( 57 | new PropertyChangedEventArgs ("Item[]")); 58 | } 59 | 60 | protected override void ClearItems () { 61 | base.ClearItems(); 62 | OnCollectionChanged ( 63 | new NotifyCollectionChangedEventArgs ( 64 | NotifyCollectionChangedAction.Reset)); 65 | 66 | OnPropertyChanged ( 67 | new PropertyChangedEventArgs ("Count")); 68 | 69 | OnPropertyChanged ( 70 | new PropertyChangedEventArgs ("Item[]")); 71 | } 72 | 73 | protected override void RemoveItem (int index) { 74 | var item = Items [index]; 75 | base.RemoveItem (index); 76 | 77 | this.OnCollectionChanged ( 78 | new NotifyCollectionChangedEventArgs ( 79 | NotifyCollectionChangedAction.Remove, item, index)); 80 | 81 | this.OnPropertyChanged ( 82 | new PropertyChangedEventArgs ("Count")); 83 | 84 | this.OnPropertyChanged ( 85 | new PropertyChangedEventArgs ("Item[]")); 86 | } 87 | 88 | protected virtual void OnCollectionChanged (NotifyCollectionChangedEventArgs e) { 89 | if ( this.CollectionChanged != null ) 90 | this.CollectionChanged ( this, e ); 91 | } 92 | 93 | protected virtual void OnPropertyChanged (PropertyChangedEventArgs e) { 94 | if (this.PropertyChanged != null) 95 | this.PropertyChanged ( this, e ); 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /WPFLight/System/ComponentModel/TypeDescriptor.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Globalization; 5 | 6 | namespace System.ComponentModel { 7 | public sealed class TypeDescriptor { 8 | public static TypeConverter GetConverter (Type type) { 9 | if (type == null) 10 | throw new ArgumentNullException("type"); 11 | 12 | var attributes = type.GetCustomAttributes( 13 | typeof(TypeConverterAttribute), true); 14 | 15 | if (attributes.Length > 0) { 16 | return ( TypeConverter ) Activator.CreateInstance ( 17 | Type.GetType ( 18 | ((TypeConverterAttribute)attributes[0]).ConverterTypeName, true) 19 | ); 20 | } 21 | 22 | if (DefaultConverters.ContainsKey(type)) { 23 | return ( TypeConverter ) 24 | Activator.CreateInstance(DefaultConverters[type]); 25 | } 26 | return null; 27 | } 28 | 29 | static Dictionary DefaultConverters { 30 | get { 31 | if ( defaultConverters == null ) { 32 | defaultConverters = new Dictionary ( ); 33 | /* 34 | defaultConverters.Add(typeof(bool), typeof(BooleanConverter)); 35 | defaultConverters.Add(typeof(byte), typeof(ByteConverter)); 36 | defaultConverters.Add(typeof(sbyte), typeof(SByteConverter)); 37 | defaultConverters.Add(typeof(string), typeof(StringConverter)); 38 | defaultConverters.Add(typeof(char), typeof(CharConverter)); 39 | defaultConverters.Add(typeof(short), typeof(Int16Converter)); 40 | defaultConverters.Add(typeof(int), typeof(Int32Converter)); 41 | defaultConverters.Add(typeof(long), typeof(Int64Converter)); 42 | defaultConverters.Add(typeof(ushort), typeof(UInt16Converter)); 43 | defaultConverters.Add(typeof(uint), typeof(UInt32Converter)); 44 | defaultConverters.Add(typeof(ulong), typeof(UInt64Converter)); 45 | defaultConverters.Add(typeof(float), typeof(SingleConverter)); 46 | defaultConverters.Add(typeof(double), typeof(DoubleConverter)); 47 | defaultConverters.Add(typeof(decimal), typeof(DecimalConverter)); 48 | defaultConverters.Add(typeof(void), typeof(TypeConverter)); 49 | defaultConverters.Add(typeof(Array), typeof(ArrayConverter)); 50 | defaultConverters.Add(typeof(CultureInfo), typeof(CultureInfoConverter)); 51 | defaultConverters.Add(typeof(DateTime), typeof(DateTimeConverter)); 52 | defaultConverters.Add(typeof(Guid), typeof(GuidConverter)); 53 | defaultConverters.Add(typeof(TimeSpan), typeof(TimeSpanConverter)); 54 | defaultConverters.Add(typeof(ICollection), typeof(CollectionConverter)); 55 | defaultConverters.Add(typeof(Enum), typeof(EnumConverter)); 56 | * */ 57 | } 58 | return defaultConverters; 59 | } 60 | } 61 | 62 | static Dictionary defaultConverters; 63 | } 64 | } -------------------------------------------------------------------------------- /WPFLight/Extensions/EnumExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | using System.Reflection; 5 | namespace WPFLight.Extensions { 6 | public static class EnumHelpers { 7 | private static void CheckIsEnum (bool withFlags) { 8 | if (!typeof(T).IsEnum) 9 | throw new ArgumentException(string.Format("Type '{0}' is not an enum", typeof(T).FullName)); 10 | if (withFlags && !Attribute.IsDefined(typeof(T), typeof(FlagsAttribute))) 11 | throw new ArgumentException(string.Format("Type '{0}' doesn't have the 'Flags' attribute", typeof(T).FullName)); 12 | } 13 | 14 | public static bool IsFlagSet (this T value, T flag) where T : struct { 15 | CheckIsEnum(true); 16 | long lValue = Convert.ToInt64(value); 17 | long lFlag = Convert.ToInt64(flag); 18 | return (lValue & lFlag) != 0; 19 | } 20 | 21 | public static IEnumerable GetFlags (this T value) where T : struct { 22 | CheckIsEnum(true); 23 | 24 | #if WINDOWS_PHONE 25 | foreach (T flag in GetValues ( )) { 26 | #else 27 | foreach (T flag in Enum.GetValues(typeof(T)).Cast()) { 28 | #endif 29 | if (value.IsFlagSet(flag)) 30 | yield return flag; 31 | } 32 | } 33 | 34 | public static T SetFlags (this T value, T flags, bool on) where T : struct { 35 | CheckIsEnum(true); 36 | long lValue = Convert.ToInt64(value); 37 | long lFlag = Convert.ToInt64(flags); 38 | if (on) { 39 | lValue |= lFlag; 40 | } else { 41 | lValue &= (~lFlag); 42 | } 43 | return (T)Enum.ToObject(typeof(T), lValue); 44 | } 45 | 46 | public static T SetFlags (this T value, T flags) where T : struct { 47 | return value.SetFlags(flags, true); 48 | } 49 | 50 | public static T ClearFlags (this T value, T flags) where T : struct { 51 | return value.SetFlags(flags, false); 52 | } 53 | 54 | public static T CombineFlags (this IEnumerable flags) where T : struct { 55 | CheckIsEnum(true); 56 | long lValue = 0; 57 | foreach (T flag in flags) { 58 | long lFlag = Convert.ToInt64(flag); 59 | lValue |= lFlag; 60 | } 61 | return (T)Enum.ToObject(typeof(T), lValue); 62 | } 63 | 64 | #if WINDOWS_PHONE 65 | 66 | /* 67 | * Enum.GetValues doesn't exist in Windows Phone 7, so I need to add the same functionality 68 | * */ 69 | 70 | public static T[] GetValues () { 71 | Type enumType = typeof(T); 72 | if (!enumType.IsEnum) 73 | throw new ArgumentException("Type '" + enumType.Name + "' is not an enum"); 74 | 75 | FieldInfo[] fields = enumType.GetFields(); 76 | int literalCount = 0; 77 | for (int i = 0; i < fields.Length; i++) 78 | if (fields[i].IsLiteral == true) 79 | literalCount++; 80 | 81 | T[] arr = new T[literalCount]; 82 | int pos = 0; 83 | for (int i = 0; i < fields.Length; i++) 84 | if (fields[i].IsLiteral == true) { 85 | arr[pos] = (T)fields[i].GetValue(enumType); 86 | pos++; 87 | } 88 | 89 | return arr; 90 | } 91 | #endif 92 | } 93 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/Panel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Windows.Markup; 5 | 6 | using Microsoft.Xna.Framework; 7 | using Microsoft.Xna.Framework.Graphics; 8 | using Microsoft.Xna.Framework.Input.Touch; 9 | using System.Windows.Media; 10 | 11 | namespace System.Windows.Controls { 12 | [ContentProperty("Children")] 13 | public abstract class Panel : Control { 14 | public Panel ( ) { 15 | this.Children = new UIElementCollection(this); 16 | } 17 | 18 | #region Properties 19 | 20 | public UIElementCollection Children { get; protected set; } 21 | 22 | #endregion 23 | 24 | public override void Initialize () { 25 | if (this.Children.Count > 0) { 26 | foreach (var c in this.Children) { 27 | if (c != null) 28 | c.Initialize(); 29 | } 30 | } 31 | base.Initialize (); 32 | } 33 | 34 | public override void Update (GameTime gameTime) { 35 | if (this.IsEnabled) { 36 | foreach (var c in this.Children.OfType()) 37 | c.Update(gameTime); 38 | } 39 | base.Update (gameTime); 40 | } 41 | 42 | public override void Draw (GameTime gameTime, Microsoft.Xna.Framework.Graphics.SpriteBatch batch, float alpha, Matrix transform) { 43 | base.Draw (gameTime, batch, alpha, transform); 44 | if (this.IsVisible && this.Opacity > 0) { 45 | var drawable = this.Children.OfType () 46 | .OrderBy (d => d.DrawOrder) 47 | .ToArray (); 48 | 49 | if (drawable.Length > 0) { 50 | foreach (var d in drawable.OfType()) 51 | d.Draw (gameTime, batch, alpha * this.Opacity, transform); 52 | } 53 | } 54 | } 55 | 56 | public override void Invalidate () { 57 | base.Invalidate (); 58 | if (this.IsInitialized) { 59 | foreach (var child in this.Children.OfType()) 60 | child.Invalidate (); 61 | } 62 | } 63 | 64 | public override void OnTouchDown (TouchLocation state) { 65 | foreach (var c in this.Children.OfType()) { 66 | if (c.IsEnabled 67 | && c.Opacity > 0 // TODO Should remove, in WPF, transparent Buttons are clickable 68 | && VisualTreeHelper.IsVisible ( c ) 69 | && c.HitTest(state.Position)) { 70 | c.OnTouchDown(state); 71 | } 72 | } 73 | base.OnTouchDown (state); 74 | } 75 | 76 | public override void OnTouchUp (TouchLocation state) { 77 | foreach (var c in this.Children.OfType()) 78 | if (c.IsEnabled 79 | && c.Opacity > 0 80 | && VisualTreeHelper.IsVisible ( c ) 81 | && (c.HitTest(state.Position) || c.IsTouchDown)) 82 | c.OnTouchUp(state); 83 | 84 | base.OnTouchUp (state); 85 | } 86 | 87 | public override void OnTouchMove (TouchLocation state) { 88 | foreach (var c in this.Children.OfType()) 89 | if (c.IsEnabled 90 | && c.Opacity > 0 91 | && VisualTreeHelper.IsVisible ( c ) 92 | && (c.HitTest(state.Position) || c.IsTouchDown)) 93 | c.OnTouchMove(state); 94 | 95 | base.OnTouchMove (state); 96 | } 97 | 98 | public void ResetTouchStates () { 99 | var children = GetAllControls(this); 100 | foreach (var c in children) 101 | c.IsTouchDown = false; 102 | } 103 | 104 | static IEnumerable GetAllControls (Control control) { 105 | var children = new List(); 106 | children.Add(control); 107 | if (control is Panel) { 108 | foreach (var c in ((Panel)control).Children.OfType()) 109 | children.AddRange (GetAllControls (c)); 110 | } 111 | return children; 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/DialogBox.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Media; 2 | using WPFLight.Helpers; 3 | 4 | namespace System.Windows.Controls { 5 | public abstract class DialogBox : Window { 6 | public DialogBox ( ) { 7 | this.Width = 200; 8 | this.Height = 200; 9 | this.Background = new SolidColorBrush (System.Windows.Media.Color.FromArgb (200, 150, 150, 150 )); 10 | this.BorderBrush = new SolidColorBrush (new Color(.9f,.9f,.9f )*.5f); 11 | this.BorderThickness = new Thickness (1); 12 | 13 | gridRoot = new Grid (); 14 | gridRoot.RowDefinitions.Add (new RowDefinition (new GridLength (50, GridUnitType.Pixel))); 15 | gridRoot.RowDefinitions.Add (RowDefinition.Star); 16 | gridRoot.RowDefinitions.Add (new RowDefinition (new GridLength (65, GridUnitType.Pixel))); 17 | gridRoot.Parent = this; 18 | 19 | base.Content = gridRoot; 20 | } 21 | 22 | #region Properties 23 | 24 | public new object Content { 25 | get { 26 | return dialogContent; 27 | } 28 | set { 29 | if (dialogContent != value) { 30 | var oldElement = dialogContent as UIElement; 31 | if (oldElement != null) 32 | gridRoot.Children.Remove(oldElement); 33 | 34 | var newElement = value as UIElement; 35 | if (newElement != null) { 36 | gridRoot.Children.Add(newElement); 37 | Grid.SetRow(newElement, 1); 38 | } 39 | 40 | dialogContent = value; 41 | } 42 | } 43 | } 44 | 45 | #endregion 46 | 47 | 48 | public override void Invalidate () { 49 | base.Invalidate(); 50 | gridRoot.Invalidate(); 51 | } 52 | 53 | public override void Initialize () { 54 | lblTitle = new Label (); 55 | lblTitle.Text = this.Title; 56 | lblTitle.FontScale = .2f; 57 | lblTitle.Margin = new Thickness (12, 4, 0, 0); 58 | 59 | gridRoot.Children.Add (lblTitle); 60 | 61 | cmdCancel = new Button (); 62 | cmdCancel.Content = "CANCEL"; 63 | cmdCancel.IsEnabled = true; 64 | cmdCancel.Margin = new Thickness (15, 5, 15, 10); 65 | cmdCancel.Width = 120; 66 | cmdCancel.FontSize = .18f; 67 | cmdCancel.Foreground = Brushes.White; 68 | cmdCancel.HorizontalAlignment = HorizontalAlignment.Right; 69 | cmdCancel.Click += delegate { 70 | this.DialogResult = false; 71 | this.Close (); 72 | }; 73 | 74 | gridRoot.Children.Add (cmdCancel); 75 | Grid.SetRow ( cmdCancel, 2); 76 | 77 | cmdOkay = new Button (); 78 | cmdOkay.Content = "OK"; 79 | cmdOkay.IsEnabled = true; 80 | cmdOkay.Margin = new Thickness (15, 5, 145, 10); 81 | cmdOkay.Width = 80; 82 | cmdOkay.Foreground = Brushes.White; 83 | cmdOkay.FontSize = .18f; 84 | cmdOkay.HorizontalAlignment = HorizontalAlignment.Right; 85 | cmdOkay.Click += delegate { 86 | this.DialogResult = true; 87 | this.Close (); 88 | }; 89 | 90 | gridRoot.Children.Add (cmdOkay); 91 | Grid.SetRow (cmdOkay, 2); 92 | 93 | if (this.WindowStartUpLocation == WindowStartUpLocation.CenterScreen) { 94 | var left = ((float)ScreenHelper.ORIGINAL_WIDTH / 2f) - this.ActualWidth / 2f; 95 | var top = ((float)ScreenHelper.ORIGINAL_HEIGHT / 2f) - this.ActualHeight / 2f; 96 | 97 | this.Left = left; 98 | this.Top = top; 99 | } 100 | 101 | gridRoot.Initialize(); 102 | base.Initialize (); 103 | } 104 | 105 | #region Eigenschaften 106 | 107 | public string Title { get; set; } 108 | 109 | #endregion 110 | 111 | private Button cmdCancel; 112 | private Button cmdOkay; 113 | private Label lblTitle; 114 | private Grid gridRoot; 115 | 116 | private object dialogContent; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/ListBox.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Windows.Controls.Primitives; 3 | 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Graphics; 6 | using Microsoft.Xna.Framework.Input.Touch; 7 | 8 | namespace System.Windows.Controls { 9 | public class ListBox : Selector { 10 | public ListBox ( ) { 11 | contentPanel = new StackPanel { 12 | Orientation = Orientation.Vertical, 13 | Padding = new Thickness ( ) 14 | }; 15 | 16 | scrollViewer = new ScrollViewer(); 17 | scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden; 18 | scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Visible; 19 | scrollViewer.Content = contentPanel; 20 | scrollViewer.Parent = this; 21 | scrollViewer.ScissorTest = true; 22 | } 23 | 24 | #region Properties 25 | 26 | #endregion 27 | 28 | public override void Initialize () { 29 | base.Initialize(); 30 | scrollViewer.Initialize(); 31 | this.Invalidate(); 32 | } 33 | 34 | public override void Invalidate ( ) { 35 | contentPanel.Children.Clear(); 36 | var list = new List (); 37 | foreach (var item in Items) { 38 | if (!list.Contains (item)) { 39 | list.Add (item); 40 | if (!(item is ListBoxItem)) { 41 | var lbItem = 42 | new ListBoxItem { 43 | FontFamily = this.FontFamily, 44 | Padding = new Thickness ( 10,0,0,0 ), 45 | Parent = contentPanel, 46 | HorizontalContentAlignment = HorizontalAlignment.Left, // TODO REMOVE 47 | Content = item, 48 | }; 49 | 50 | lbItem.CheckedChanged += (s, e) => { 51 | if (((ListBoxItem)s).IsChecked) { 52 | this.SelectedItem = ((ListBoxItem)s).Content; 53 | } 54 | }; 55 | 56 | if (this.ItemContainerStyle != null) { 57 | lbItem.Style = this.ItemContainerStyle; 58 | } 59 | 60 | lbItem.Initialize (); 61 | contentPanel.Children.Add (lbItem); 62 | } else { 63 | contentPanel.Children.Add ( 64 | item as ListBoxItem); 65 | } 66 | } 67 | } 68 | if ( scrollViewer.IsInitialized ) 69 | scrollViewer.Invalidate (); 70 | 71 | base.Invalidate(); 72 | } 73 | 74 | protected override void OnSelectionChanged () { 75 | base.OnSelectionChanged (); 76 | 77 | /* 78 | if (this.SelectedIndex < contentPanel.Children.Count) { 79 | ((ListBoxItem)contentPanel.Children [this.SelectedIndex]).IsChecked = true; 80 | } 81 | */ 82 | } 83 | 84 | public override void OnTouchMove (TouchLocation state) { 85 | base.OnTouchMove (state); 86 | scrollViewer.OnTouchMove (state); 87 | } 88 | 89 | public override void OnTouchDown (TouchLocation state) { 90 | base.OnTouchDown (state); 91 | scrollViewer.OnTouchDown (state); 92 | } 93 | 94 | public override void OnTouchUp (TouchLocation state) { 95 | base.OnTouchUp (state); 96 | scrollViewer.OnTouchUp (state); 97 | } 98 | 99 | public override void Update (GameTime gameTime) { 100 | base.Update(gameTime); 101 | scrollViewer.Update(gameTime); 102 | } 103 | 104 | public override void Draw (GameTime gameTime, SpriteBatch batch, float alpha, Matrix transform) { 105 | base.Draw(gameTime, batch, alpha, transform); 106 | scrollViewer.Draw(gameTime, batch, alpha, transform); 107 | } 108 | 109 | private ScrollViewer scrollViewer; 110 | private StackPanel contentPanel; 111 | 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/ColorHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.Xna.Framework; 3 | using System.ComponentModel; 4 | 5 | namespace System.Windows.Media { 6 | internal static class ColorHelper { 7 | static ColorHelper () { 8 | var props = typeof(Colors).GetProperties ( 9 | System.Reflection.BindingFlags.Public 10 | | System.Reflection.BindingFlags.Static); 11 | 12 | NamedColors = new Dictionary (); 13 | foreach (var p in props) { 14 | if (p.PropertyType == typeof(Color)) { 15 | NamedColors.Add ( 16 | p.Name.ToUpper ( ), 17 | ( Color ) p.GetValue (null,null)); 18 | } 19 | } 20 | } 21 | 22 | public static Color GetNamedColor (string name) { 23 | if (name == null) 24 | throw new ArgumentNullException (); 25 | 26 | return NamedColors [name.ToUpper()]; 27 | } 28 | 29 | static int ParseHexChar(char c ) 30 | { 31 | int intChar = (int) c; 32 | if ((intChar >= s_zeroChar) && (intChar <= (s_zeroChar+9))) 33 | { 34 | return (intChar-s_zeroChar); 35 | } 36 | 37 | if ((intChar >= s_aLower) && (intChar <= (s_aLower+5))) 38 | { 39 | return (intChar-s_aLower + 10); 40 | } 41 | 42 | if ((intChar >= s_aUpper) && (intChar <= (s_aUpper+5))) 43 | { 44 | return (intChar-s_aUpper + 10); 45 | } 46 | throw new ArgumentException (); 47 | } 48 | 49 | static Color ParseHexColor(string trimmedColor) 50 | { 51 | int a,r,g,b; 52 | a = 255; 53 | 54 | if ( trimmedColor.Length > 7 ) 55 | { 56 | a = ParseHexChar(trimmedColor[1]) * 16 + ParseHexChar(trimmedColor[2]); 57 | r = ParseHexChar(trimmedColor[3]) * 16 + ParseHexChar(trimmedColor[4]); 58 | g = ParseHexChar(trimmedColor[5]) * 16 + ParseHexChar(trimmedColor[6]); 59 | b = ParseHexChar(trimmedColor[7]) * 16 + ParseHexChar(trimmedColor[8]); 60 | } 61 | else if ( trimmedColor.Length > 5) 62 | { 63 | r = ParseHexChar(trimmedColor[1]) * 16 + ParseHexChar(trimmedColor[2]); 64 | g = ParseHexChar(trimmedColor[3]) * 16 + ParseHexChar(trimmedColor[4]); 65 | b = ParseHexChar(trimmedColor[5]) * 16 + ParseHexChar(trimmedColor[6]); 66 | } 67 | else if (trimmedColor.Length > 4) 68 | { 69 | a = ParseHexChar(trimmedColor[1]); 70 | a = a + a*16; 71 | r = ParseHexChar(trimmedColor[2]); 72 | r = r + r*16; 73 | g = ParseHexChar(trimmedColor[3]); 74 | g = g + g*16; 75 | b = ParseHexChar(trimmedColor[4]); 76 | b = b + b*16; 77 | } 78 | else 79 | { 80 | r = ParseHexChar(trimmedColor[1]); 81 | r = r + r*16; 82 | g = ParseHexChar(trimmedColor[2]); 83 | g = g + g*16; 84 | b = ParseHexChar(trimmedColor[3]); 85 | b = b + b*16; 86 | } 87 | 88 | return Color.FromArgb ((byte)a, (byte)r, (byte)g, (byte)b); 89 | } 90 | 91 | public static Color ConvertFromHex ( string hexValue ) { 92 | return ParseHexColor (hexValue); 93 | } 94 | 95 | internal static Color Parse (string value, ITypeDescriptorContext context) { 96 | if (value == null) 97 | throw new ArgumentNullException (); 98 | 99 | if (value.StartsWith ("#")) { 100 | return ColorHelper.ConvertFromHex (value); 101 | } else { 102 | return ColorHelper.GetNamedColor (value); 103 | } 104 | } 105 | 106 | public static Microsoft.Xna.Framework.Color ToXnaColor ( System.Windows.Media.Color color ) { 107 | var c = new Microsoft.Xna.Framework.Color (); 108 | c.PackedValue = color.PackedValue; 109 | return c; 110 | } 111 | 112 | static Dictionary NamedColors; 113 | 114 | private const int s_zeroChar = (int) '0'; 115 | private const int s_aLower = (int) 'a'; 116 | private const int s_aUpper = (int) 'A'; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/MessageBox.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Media; 2 | using WPFLight.Helpers; 3 | 4 | namespace System.Windows.Controls { 5 | public class MessageBox : Window { 6 | private MessageBox ( ) { 7 | this.Width = 350; 8 | this.Height = 200; 9 | 10 | this.Background = new SolidColorBrush (System.Windows.Media.Color.FromArgb (230, 150, 150, 150 )); 11 | this.BorderBrush = new SolidColorBrush (new Color(.8f,.8f,.8f )*.4f); 12 | this.BorderThickness = new Thickness (2); 13 | 14 | gridRoot = new Grid (); 15 | gridRoot.RowDefinitions.Add (new RowDefinition (new GridLength (45, GridUnitType.Pixel))); 16 | gridRoot.RowDefinitions.Add (RowDefinition.Star); 17 | gridRoot.RowDefinitions.Add (new RowDefinition (new GridLength (75, GridUnitType.Pixel))); 18 | gridRoot.Parent = this; 19 | 20 | base.Content = gridRoot; 21 | } 22 | 23 | #region Properties 24 | 25 | public new object Content { 26 | get { 27 | return dialogContent; 28 | } 29 | set { 30 | if (dialogContent != value) { 31 | var oldElement = dialogContent as UIElement; 32 | if (oldElement != null) 33 | gridRoot.Children.Remove(oldElement); 34 | 35 | var newElement = value as UIElement; 36 | if (newElement != null) { 37 | gridRoot.Children.Add(newElement); 38 | Grid.SetRow(newElement, 1); 39 | } 40 | 41 | dialogContent = value; 42 | } 43 | } 44 | } 45 | 46 | #endregion 47 | 48 | 49 | public override void Invalidate () { 50 | base.Invalidate(); 51 | lblText.Text = this.Text; 52 | gridRoot.Invalidate(); 53 | } 54 | 55 | public override void Initialize () { 56 | lblTitle = new Label (); 57 | lblTitle.Text = this.Title; 58 | lblTitle.FontScale = .17f; 59 | lblTitle.Margin = new Thickness (8, 4, 0, 0); 60 | 61 | gridRoot.Children.Add (lblTitle); 62 | 63 | lblText = new Label (); 64 | lblText.Text = this.Text; 65 | lblText.Foreground = Brushes.White; 66 | lblText.FontScale = .20f; 67 | lblText.Margin = new Thickness (30, 0, 0, 0); 68 | lblText.HorizontalAlignment = HorizontalAlignment.Left; 69 | lblText.VerticalAlignment = VerticalAlignment.Top; 70 | 71 | this.Content = lblText; 72 | 73 | cmdOkay = new Button (); 74 | cmdOkay.Content = "OK"; 75 | cmdOkay.IsEnabled = true; 76 | cmdOkay.Margin = new Thickness (0, 0, 0, 18); 77 | cmdOkay.Width = 140; 78 | cmdOkay.FontSize = .18f; 79 | cmdOkay.Foreground = Brushes.White; 80 | cmdOkay.HorizontalAlignment = HorizontalAlignment.Center; 81 | cmdOkay.VerticalAlignment = VerticalAlignment.Stretch; 82 | cmdOkay.Click += delegate { 83 | this.DialogResult = true; 84 | this.Close (); 85 | }; 86 | 87 | gridRoot.Children.Add (cmdOkay); 88 | Grid.SetRow (cmdOkay, 2); 89 | 90 | if (this.WindowStartUpLocation == WindowStartUpLocation.CenterScreen) { 91 | var left = ((float)ScreenHelper.ORIGINAL_WIDTH / 2f) - this.ActualWidth / 2f; 92 | var top = ((float)ScreenHelper.ORIGINAL_HEIGHT / 2f) - this.ActualHeight / 2f; 93 | 94 | this.Left = left; 95 | this.Top = top; 96 | } 97 | 98 | gridRoot.Initialize(); 99 | base.Initialize (); 100 | } 101 | 102 | #region Properties 103 | 104 | public string Title { get; set; } 105 | public string Text { get; set; } 106 | 107 | #endregion 108 | 109 | public static void Show ( string text ) { 110 | if (text == null) 111 | throw new ArgumentNullException (); 112 | 113 | var msg = new MessageBox { 114 | Text = text, 115 | }; 116 | msg.Show (true); 117 | } 118 | 119 | private Button cmdOkay; 120 | private Label lblTitle; 121 | private Label lblText; 122 | private Grid gridRoot; 123 | 124 | private object dialogContent; 125 | } 126 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/Plane.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Graphics; 5 | using System; 6 | 7 | namespace System.Windows.Controls 8 | { 9 | public sealed class Plane : UIElement, IDrawable3D 10 | { 11 | public Plane ( Game game, Vector3 x1, Vector3 x2, Vector3 y1, Vector3 y2, Color color ) : base ( ) 12 | { 13 | this.Color = color; 14 | this.Opacity = 1.0f; 15 | this.X1 = x1; 16 | this.X2 = x2; 17 | this.Y1 = y1; 18 | this.Y2 = y2; 19 | } 20 | 21 | #region Eigenschaften 22 | 23 | public Vector3 X1 { get; private set; } 24 | public Vector3 X2 { get; private set; } 25 | public Vector3 Y1 { get; private set; } 26 | public Vector3 Y2 { get; private set; } 27 | 28 | public Color Color { get; private set; } 29 | 30 | #endregion 31 | 32 | public override void Initialize ( ) 33 | { 34 | vertexBuffer = 35 | new VertexBuffer ( 36 | this.Game.GraphicsDevice, 37 | typeof ( VertexPositionColor ), 38 | 6, 39 | BufferUsage.None ); 40 | 41 | vertexBuffer.SetData ( 42 | new VertexPositionColor[]{ 43 | new VertexPositionColor ( X1, this.Color ), 44 | new VertexPositionColor ( X2, this.Color ), 45 | new VertexPositionColor ( Y1, this.Color ), 46 | new VertexPositionColor ( Y1, this.Color ), 47 | new VertexPositionColor ( X2, this.Color ), 48 | new VertexPositionColor ( Y2, this.Color ), 49 | } ); 50 | 51 | basicEffect = new BasicEffect ( this.Game.GraphicsDevice ); 52 | basicEffect.EnableDefaultLighting ( ); 53 | 54 | base.Initialize ( ); 55 | } 56 | 57 | protected override void OnDeviceReset ( ) { 58 | base.OnDeviceReset ( ); 59 | if ( this.IsInitialized ) { 60 | if ( vertexBuffer != null ) 61 | vertexBuffer.Dispose ( ); 62 | 63 | if ( basicEffect != null ) 64 | basicEffect.Dispose ( ); 65 | 66 | Initialize ( ); 67 | } 68 | } 69 | 70 | public void Draw ( GameTime gameTime, Matrix world, Matrix view, Matrix projection, float alpha ) 71 | { 72 | basicEffect.World = world; 73 | basicEffect.View = view; 74 | basicEffect.Projection = projection; 75 | basicEffect.VertexColorEnabled = true; 76 | basicEffect.LightingEnabled = false; 77 | basicEffect.PreferPerPixelLighting = false; 78 | basicEffect.Alpha = this.Opacity * ( this.Color.A / 256f ) * alpha; 79 | 80 | this.Draw ( basicEffect ); 81 | } 82 | 83 | void Draw ( Effect effect ) { 84 | this.Game.GraphicsDevice.RasterizerState = RasterizerState.CullNone; 85 | this.Game.GraphicsDevice.DepthStencilState = DepthStencilState.Default; 86 | this.Game.GraphicsDevice.BlendState = BlendState.AlphaBlend; 87 | this.Game.GraphicsDevice.SetVertexBuffer ( vertexBuffer ); 88 | foreach ( EffectPass effectPass in effect.CurrentTechnique.Passes ) { 89 | effectPass.Apply ( ); 90 | this.Game.GraphicsDevice.DrawPrimitives ( 91 | PrimitiveType.TriangleList, 0, 2 ); 92 | } 93 | } 94 | 95 | public override void Dispose ( ) 96 | { 97 | basicEffect.Dispose ( ); 98 | vertexBuffer.Dispose ( ); 99 | 100 | base.Dispose ( ); 101 | } 102 | 103 | private BasicEffect basicEffect; 104 | private VertexBuffer vertexBuffer; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/ThicknessConverter.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | //using System.ComponentModel.Design.Serialization; 3 | using System.Globalization; 4 | using System.Reflection; 5 | using System.Text; 6 | 7 | namespace System.Windows { 8 | public class ThicknessConverter : TypeConverter { 9 | public override bool CanConvertFrom (ITypeDescriptorContext typeDescriptorContext, Type sourceType) { 10 | // We can only handle strings, integral and floating types 11 | TypeCode tc = Type.GetTypeCode (sourceType); 12 | switch (tc) { 13 | case TypeCode.String: 14 | case TypeCode.Decimal: 15 | case TypeCode.Single: 16 | case TypeCode.Double: 17 | case TypeCode.Int16: 18 | case TypeCode.Int32: 19 | case TypeCode.Int64: 20 | case TypeCode.UInt16: 21 | case TypeCode.UInt32: 22 | case TypeCode.UInt64: 23 | return true; 24 | 25 | default: 26 | return false; 27 | } 28 | } 29 | 30 | public override bool CanConvertTo (ITypeDescriptorContext typeDescriptorContext, Type destinationType) { 31 | return destinationType == typeof(String)/* 32 | || destinationType == typeof(InstanceDescriptor)*/; 33 | } 34 | 35 | public override object ConvertFrom (ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object source) { 36 | if (source != null) { 37 | if (source is string) { 38 | return FromString ((string)source, cultureInfo); 39 | } else if (source is float) { 40 | return new Thickness ((float)source); 41 | } else { 42 | return new Thickness (Convert.ToSingle (source, cultureInfo)); 43 | } 44 | } 45 | throw new Exception ("Cannot convert type"); 46 | } 47 | 48 | public override object ConvertTo (ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value, Type destinationType) { 49 | if (null == value) { 50 | throw new ArgumentNullException ("value"); 51 | } 52 | 53 | if (null == destinationType) { 54 | throw new ArgumentNullException ("destinationType"); 55 | } 56 | 57 | if (!(value is Thickness)) { 58 | throw new ArgumentException (); 59 | } 60 | 61 | Thickness th = (Thickness)value; 62 | if (destinationType == typeof(string)) { 63 | return ToString (th, cultureInfo); 64 | } 65 | /* 66 | if (destinationType == typeof(InstanceDescriptor)) { 67 | ConstructorInfo ci = typeof(Thickness).GetConstructor (new Type[] { 68 | typeof(double), 69 | typeof(double), 70 | typeof(double), 71 | typeof(double) 72 | }); 73 | return new InstanceDescriptor ( 74 | ci, new object[] { th.Left, th.Top, th.Right, th.Bottom }); 75 | } 76 | * */ 77 | throw new Exception ("Cannot convert type"); 78 | } 79 | 80 | static internal string ToString(Thickness th, CultureInfo cultureInfo) 81 | { 82 | char listSeparator = ','; 83 | 84 | // Initial capacity [64] is an estimate based on a sum of: 85 | // 48 = 4x double (twelve digits is generous for the range of values likely) 86 | // 8 = 4x Unit Type string (approx two characters) 87 | // 4 = 4x separator characters 88 | StringBuilder sb = new StringBuilder(64); 89 | 90 | sb.Append(th.Left.ToString ( cultureInfo )); 91 | sb.Append(listSeparator); 92 | sb.Append(th.Top.ToString ( cultureInfo )); 93 | sb.Append(listSeparator); 94 | sb.Append(th.Right.ToString ( cultureInfo )); 95 | sb.Append(listSeparator); 96 | sb.Append (th.Bottom.ToString (cultureInfo)); 97 | 98 | return sb.ToString(); 99 | } 100 | 101 | static internal Thickness FromString (string s, CultureInfo cultureInfo) { 102 | if (String.IsNullOrEmpty (s)) 103 | throw new ArgumentException (); 104 | 105 | if (s.Contains (",")) { 106 | var values = s.Split (','); 107 | return new Thickness ( 108 | float.Parse (values [0]), 109 | float.Parse (values [1]), 110 | float.Parse (values [2]), 111 | float.Parse (values [3])); 112 | } else { 113 | return new Thickness ( 114 | float.Parse (s)); 115 | } 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Vector2Converter.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | //using System.ComponentModel.Design.Serialization; 3 | using System.Globalization; 4 | using System.Reflection; 5 | using System.Text; 6 | 7 | namespace System.Windows { 8 | public class ThicknessConverter : TypeConverter { 9 | public override bool CanConvertFrom (ITypeDescriptorContext typeDescriptorContext, Type sourceType) { 10 | // We can only handle strings, integral and floating types 11 | TypeCode tc = Type.GetTypeCode (sourceType); 12 | switch (tc) { 13 | case TypeCode.String: 14 | case TypeCode.Decimal: 15 | case TypeCode.Single: 16 | case TypeCode.Double: 17 | case TypeCode.Int16: 18 | case TypeCode.Int32: 19 | case TypeCode.Int64: 20 | case TypeCode.UInt16: 21 | case TypeCode.UInt32: 22 | case TypeCode.UInt64: 23 | return true; 24 | 25 | default: 26 | return false; 27 | } 28 | } 29 | 30 | public override bool CanConvertTo (ITypeDescriptorContext typeDescriptorContext, Type destinationType) { 31 | return destinationType == typeof(String)/* 32 | || destinationType == typeof(InstanceDescriptor)*/; 33 | } 34 | 35 | public override object ConvertFrom (ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object source) { 36 | if (source != null) { 37 | if (source is string) { 38 | return FromString ((string)source, cultureInfo); 39 | } else if (source is float) { 40 | return new Thickness ((float)source); 41 | } else { 42 | return new Thickness (Convert.ToSingle (source, cultureInfo)); 43 | } 44 | } 45 | throw new Exception ("Cannot convert type"); 46 | } 47 | 48 | public override object ConvertTo (ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value, Type destinationType) { 49 | if (null == value) { 50 | throw new ArgumentNullException ("value"); 51 | } 52 | 53 | if (null == destinationType) { 54 | throw new ArgumentNullException ("destinationType"); 55 | } 56 | 57 | if (!(value is Thickness)) { 58 | throw new ArgumentException (); 59 | } 60 | 61 | Thickness th = (Thickness)value; 62 | if (destinationType == typeof(string)) { 63 | return ToString (th, cultureInfo); 64 | } 65 | /* 66 | if (destinationType == typeof(InstanceDescriptor)) { 67 | ConstructorInfo ci = typeof(Thickness).GetConstructor (new Type[] { 68 | typeof(double), 69 | typeof(double), 70 | typeof(double), 71 | typeof(double) 72 | }); 73 | return new InstanceDescriptor ( 74 | ci, new object[] { th.Left, th.Top, th.Right, th.Bottom }); 75 | } 76 | * */ 77 | throw new Exception ("Cannot convert type"); 78 | } 79 | 80 | static internal string ToString(Thickness th, CultureInfo cultureInfo) 81 | { 82 | char listSeparator = ','; 83 | 84 | // Initial capacity [64] is an estimate based on a sum of: 85 | // 48 = 4x double (twelve digits is generous for the range of values likely) 86 | // 8 = 4x Unit Type string (approx two characters) 87 | // 4 = 4x separator characters 88 | StringBuilder sb = new StringBuilder(64); 89 | 90 | sb.Append(th.Left.ToString ( cultureInfo )); 91 | sb.Append(listSeparator); 92 | sb.Append(th.Top.ToString ( cultureInfo )); 93 | sb.Append(listSeparator); 94 | sb.Append(th.Right.ToString ( cultureInfo )); 95 | sb.Append(listSeparator); 96 | sb.Append (th.Bottom.ToString (cultureInfo)); 97 | 98 | return sb.ToString(); 99 | } 100 | 101 | static internal Thickness FromString (string s, CultureInfo cultureInfo) { 102 | if (String.IsNullOrEmpty (s)) 103 | throw new ArgumentException (); 104 | 105 | if (s.Contains (",")) { 106 | var values = s.Split (','); 107 | return new Thickness ( 108 | float.Parse (values [0]), 109 | float.Parse (values [1]), 110 | float.Parse (values [2]), 111 | float.Parse (values [3])); 112 | } else { 113 | return new Thickness ( 114 | float.Parse (s)); 115 | } 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Rect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace System.Windows { 4 | public struct Rect { 5 | public Rect (float left, float top, float width, float height) { 6 | this.x = left; 7 | this.y = top; 8 | this.width = width; 9 | this.height = height; 10 | } 11 | 12 | public Rect (Point p1, Point p2) { 13 | var left = Math.Min (p1.X, p2.X); 14 | var top = Math.Min (p1.Y, p2.Y); 15 | var right = Math.Max (p1.X, p2.X); 16 | var bottom = Math.Max (p1.Y, p2.Y); 17 | 18 | this.x = left; 19 | this.y = top; 20 | this.width = right - left; 21 | this.height = bottom - top; 22 | } 23 | 24 | public Rect ( Point location, Size size ) { 25 | this.x = location.X; 26 | this.y = location.Y; 27 | this.width = size.Width; 28 | this.height = size.Height; 29 | } 30 | 31 | public Rect ( Size size ) { 32 | if (size.IsEmpty) 33 | this = empty; 34 | else { 35 | x = y = 0; 36 | width = size.Width; 37 | height = size.Height; 38 | } 39 | } 40 | 41 | #region Operators 42 | 43 | public static bool operator == (Rect rect1, Rect rect2) { 44 | return rect1.X == rect2.X && 45 | rect1.Y == rect2.Y && 46 | rect1.Width == rect2.Width && 47 | rect1.Height == rect2.Height; 48 | } 49 | 50 | public static bool operator != (Rect rect1, Rect rect2) { 51 | return !(rect1 == rect2); 52 | } 53 | 54 | #endregion 55 | 56 | #region Properties 57 | 58 | public float X { get { return x; } set { x = value; } } 59 | 60 | public float Y { get { return y; } set { y = value; } } 61 | 62 | public float Left { get { return x; } } 63 | 64 | public float Top { get { return y; } } 65 | 66 | public float Width { get { return width; } set { width = value; } } 67 | 68 | public float Height { get { return height; } set { height = value; } } 69 | 70 | public float Right { 71 | get { return x + width; } 72 | } 73 | 74 | public float Bottom { 75 | get { return y + height; } 76 | } 77 | 78 | public Size Size { 79 | get { 80 | if (IsEmpty) 81 | return Size.Empty; 82 | 83 | return new Size (width, height); 84 | } 85 | set { 86 | if (value.IsEmpty) 87 | this = empty; 88 | else { 89 | if (IsEmpty) 90 | throw new System.InvalidOperationException ("Rect is not initialized"); 91 | 92 | width = value.Width; 93 | height = value.Height; 94 | } 95 | } 96 | } 97 | 98 | public Point Location { 99 | get { 100 | return new Point (x, y); 101 | } 102 | set { 103 | if (IsEmpty) 104 | throw new InvalidOperationException ("Rect is not initialized"); 105 | 106 | x = value.X; 107 | y = value.Y; 108 | } 109 | } 110 | 111 | public bool IsEmpty { 112 | get { 113 | return width < 0; 114 | } 115 | } 116 | 117 | #endregion 118 | 119 | static Rect CreateEmptyRect () { 120 | Rect rect = new Rect (); 121 | rect.x = Single.PositiveInfinity; 122 | rect.y = Single.PositiveInfinity; 123 | rect.width = Single.NegativeInfinity; 124 | rect.height = Single.NegativeInfinity; 125 | return rect; 126 | } 127 | 128 | public static bool Equals (Rect rect1, Rect rect2) { 129 | if (rect1.IsEmpty) { 130 | return rect2.IsEmpty; 131 | } else { 132 | return rect1.X.Equals (rect2.X) && 133 | rect1.Y.Equals (rect2.Y) && 134 | rect1.Width.Equals (rect2.Width) && 135 | rect1.Height.Equals (rect2.Height); 136 | } 137 | } 138 | 139 | public override bool Equals (object o) { 140 | if ((null == o) || !(o is Rect)) 141 | return false; 142 | 143 | var value = (Rect)o; 144 | return Rect.Equals (this, value); 145 | } 146 | 147 | public override int GetHashCode () { 148 | if (IsEmpty) 149 | return 0; 150 | else { 151 | // Perform field-by-field XOR of HashCodes 152 | return X.GetHashCode () ^ 153 | Y.GetHashCode () ^ 154 | Width.GetHashCode () ^ 155 | Height.GetHashCode (); 156 | } 157 | } 158 | 159 | private float x; 160 | private float y; 161 | private float width; 162 | private float height; 163 | 164 | static readonly Rect empty = CreateEmptyRect (); 165 | } 166 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/ScreenBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Windows; 6 | using System.Windows.Media; 7 | using System.Windows.Media.Animation; 8 | 9 | using Microsoft.Xna.Framework; 10 | using Microsoft.Xna.Framework.Graphics; 11 | 12 | using WPFLight.Helpers; 13 | 14 | namespace System.Windows.Controls { 15 | public abstract class ScreenBase : Panel { 16 | public ScreenBase ( ) : base ( ) { 17 | this.DrawOrder = 1; 18 | this.Visible = false; 19 | this.VerticalAlignment = VerticalAlignment.Stretch; 20 | this.HorizontalAlignment = HorizontalAlignment.Stretch; 21 | this.Width = ScreenHelper.ORIGINAL_WIDTH; 22 | this.Height = ScreenHelper.ORIGINAL_HEIGHT; 23 | this.ScissorTest = false; 24 | this.HitTestEnabled = true; 25 | 26 | fadeAnimation = new SingleAnimation ( 27 | 0, 1, TimeSpan.FromMilliseconds ( 300 ), false ); 28 | 29 | fadeAnimation.Completed += delegate { 30 | if ( hiding ) 31 | { 32 | this.Visible = false; 33 | this.IsEnabled = false; 34 | if ( this.Closed != null ) 35 | this.Closed ( this, EventArgs.Empty ); 36 | } 37 | else 38 | { 39 | this.IsEnabled = true; 40 | if ( this.Open != null ) 41 | this.Open ( this, EventArgs.Empty ); 42 | } 43 | }; 44 | } 45 | 46 | #region Eigenschaften 47 | 48 | public bool IsPressed { get; protected set; } 49 | public new float ActualWidth { get { return ScreenHelper.ORIGINAL_WIDTH; } } 50 | public new float ActualHeight { get { return ScreenHelper.ORIGINAL_HEIGHT; } } 51 | 52 | #endregion 53 | 54 | #region Ereignisse 55 | 56 | public event EventHandler Open; 57 | public event EventHandler Closed; 58 | 59 | #endregion 60 | 61 | public virtual void Show ( ) { 62 | hiding = false; 63 | fadeAnimation.Begin ( ); 64 | this.Visible = true; 65 | this.IsEnabled = true; 66 | } 67 | 68 | public virtual void Hide ( ) { 69 | hiding = true; 70 | fadeAnimation.Begin ( ); 71 | } 72 | 73 | public override void Initialize () { 74 | //fadeAnimation.Initialize(); 75 | base.Initialize(); 76 | } 77 | 78 | public override void Update ( GameTime gameTime ) { 79 | var pressed = false; 80 | foreach ( var c in this.Children.OfType ( ) ) 81 | { 82 | c.Update ( gameTime ); 83 | if ( !pressed ) 84 | { 85 | var cmd = c as Button; 86 | if ( cmd != null ) 87 | { 88 | if ( cmd.IsTouchDown ) 89 | pressed = true; 90 | } 91 | } 92 | } 93 | this.IsPressed = pressed; 94 | base.Update ( gameTime ); 95 | 96 | fadeAnimation.Update(gameTime); 97 | } 98 | 99 | public override void Draw ( GameTime gameTime, SpriteBatch batch, float alpha, Matrix transform ) { 100 | if ( this.Visible && alpha > 0 && this.Opacity > 0 ) { 101 | var currentValue = 0f; 102 | if ( hiding ) 103 | currentValue = fadeAnimation.GetCurrentValue ( ); 104 | else 105 | currentValue = 1- fadeAnimation.GetCurrentValue ( ); 106 | 107 | base.Draw ( gameTime, batch, alpha * ( 1 - currentValue ), transform * Matrix.CreateTranslation ( this.ActualWidth * (hiding?-currentValue:currentValue), 0, 0 ) ); 108 | } 109 | } 110 | 111 | public override float GetAbsoluteLeft () 112 | { 113 | return 0; 114 | } 115 | 116 | public override float GetAbsoluteTop () 117 | { 118 | return 0; 119 | } 120 | 121 | private bool hiding; 122 | private SingleAnimation fadeAnimation; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/TrackBar.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Shapes; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Graphics; 6 | using System.Windows.Media; 7 | 8 | namespace System.Windows.Controls { 9 | public class TrackBar : Panel { 10 | public TrackBar () { 11 | this.Height = 60; 12 | this.MinValue = 0; 13 | this.MaxValue = 100; 14 | this.Value = 0; 15 | } 16 | 17 | #region Ereignisse 18 | 19 | public event EventHandler ValueChanged; 20 | 21 | #endregion 22 | 23 | #region Eigenschaften 24 | 25 | public float MinValue { 26 | get { return minValue; } 27 | set { 28 | if (value != minValue) { 29 | minValue = value; 30 | 31 | if (minValue > maxValue) 32 | maxValue = minValue; 33 | 34 | Refresh (); 35 | } 36 | } 37 | } 38 | 39 | public float MaxValue { 40 | get { return maxValue; } 41 | set { 42 | if (value != maxValue) { 43 | maxValue = value; 44 | Refresh (); 45 | } 46 | } 47 | } 48 | 49 | public float Value { 50 | get { return myValue; } 51 | set { 52 | if (value != myValue) { 53 | var v = MathHelper.Clamp(value, MinValue, MaxValue); 54 | if (v != myValue) { 55 | myValue = v; 56 | this.RaiseValueChanged(); 57 | } 58 | } 59 | } 60 | } 61 | 62 | #endregion 63 | 64 | public override void Initialize () { 65 | rcBackground = new System.Windows.Shapes.Rectangle (); 66 | rcBackground.Fill = Brushes.Gray; 67 | rcBackground.HorizontalAlignment = HorizontalAlignment.Stretch; 68 | rcBackground.Height = 5; 69 | rcBackground.Margin = new Thickness (17,2,17,2); 70 | rcBackground.Top = (int)((this.ActualHeight / 2f) - (rcBackground.Height / 2f)); 71 | rcBackground.StrokeThickness = 1; 72 | rcBackground.RadiusX = 0; 73 | rcBackground.RadiusY = 0; 74 | this.Children.Add (rcBackground); 75 | 76 | cmdTrack = new Button ( ); 77 | cmdTrack.FontFamily = this.FontFamily; 78 | cmdTrack.Content = 79 | new System.Windows.Shapes.Rectangle { 80 | Fill = Brushes.White, 81 | Width = 30, 82 | Height = 30, 83 | }; 84 | 85 | cmdTrack.Background = Brushes.Transparent; 86 | cmdTrack.BorderThickness = new Thickness (0); 87 | cmdTrack.Width = 60; 88 | cmdTrack.Height = 60; 89 | cmdTrack.VerticalAlignment = VerticalAlignment.Center; 90 | 91 | cmdTrack.Left = 0; 92 | cmdTrack.Margin = new Thickness (0, 0, 0, 1); 93 | cmdTrack.CornerRadiusX = 0; 94 | cmdTrack.CornerRadiusY = 0; 95 | 96 | this.Children.Add (cmdTrack); 97 | 98 | base.Initialize (); 99 | this.Refresh (); 100 | } 101 | 102 | public override void Update (GameTime gameTime) { 103 | base.Update (gameTime); 104 | cmdTrack.Left = (int)(this.Value * factor); 105 | cmdTrack.Visible = this.IsEnabled; 106 | } 107 | 108 | public override void OnTouchDown (Microsoft.Xna.Framework.Input.Touch.TouchLocation state) { 109 | base.OnTouchDown (state); 110 | if (cmdTrack.IsTouchDown) { 111 | startPosX = state.Position.X; 112 | startValue = this.Value; 113 | moving = true; 114 | } 115 | } 116 | 117 | public override void OnTouchUp (Microsoft.Xna.Framework.Input.Touch.TouchLocation state) { 118 | base.OnTouchUp (state); 119 | moving = false; 120 | } 121 | 122 | public override void OnTouchMove (Microsoft.Xna.Framework.Input.Touch.TouchLocation state) { 123 | base.OnTouchMove (state); 124 | if (moving) { 125 | var x = state.Position.X - startPosX; 126 | this.Value = (x / factor) + startValue; 127 | } 128 | } 129 | 130 | void Refresh ( ) { 131 | if (this.IsInitialized) { 132 | factor = (this.ActualWidth - this.cmdTrack.ActualWidth) 133 | / MathHelper.Distance (MinValue, MaxValue); 134 | } 135 | } 136 | 137 | void RaiseValueChanged () { 138 | if (this.ValueChanged != null) 139 | this.ValueChanged (this, EventArgs.Empty); 140 | } 141 | 142 | private System.Windows.Shapes.Rectangle rcBackground; 143 | private Button cmdTrack; 144 | private float factor; 145 | private bool moving; 146 | private float startPosX; 147 | private float startValue; 148 | private float myValue; 149 | 150 | private float minValue; 151 | private float maxValue; 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/GradientBrush.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Xna.Framework.Graphics; 3 | using Microsoft.Xna.Framework; 4 | using System.Windows.Markup; 5 | 6 | namespace System.Windows.Media { 7 | [ContentProperty("GradientStops")] 8 | public abstract class GradientBrush : Brush { 9 | public GradientBrush () : base ( ) { 10 | this.GradientStops = new GradientStopCollection (); 11 | this.StartPoint = new Point (0, 0); 12 | this.EndPoint = new Point (1, 1); 13 | } 14 | 15 | 16 | #region Eigenschaften 17 | 18 | public Point StartPoint { get; set; } 19 | 20 | public Point EndPoint { get; set; } 21 | 22 | public GradientStopCollection GradientStops { get; internal set; } 23 | 24 | internal Texture2D Texture { 25 | get { 26 | if (texture == null) 27 | texture = CreateTexture (); 28 | 29 | return texture; 30 | } 31 | } 32 | 33 | #endregion 34 | 35 | public override void Draw (SpriteBatch batch, Rectangle bounds, Matrix transform, float alpha) { 36 | if (blendState == null) 37 | blendState = ContainsAlpha () 38 | ? BlendState.AlphaBlend : BlendState.Opaque; 39 | 40 | var state = blendState; 41 | if (state == BlendState.Opaque && alpha < 1) 42 | state = BlendState.AlphaBlend; 43 | 44 | batch.Begin ( 45 | SpriteSortMode.Deferred, 46 | state, 47 | SamplerState.LinearClamp, 48 | DepthStencilState.None, 49 | RasterizerState.CullNone, 50 | null, 51 | transform); 52 | 53 | batch.Draw ( 54 | this.Texture, 55 | bounds, 56 | null, 57 | Microsoft.Xna.Framework.Color.White * alpha, 58 | 0, 59 | new Vector2 (), 60 | SpriteEffects.None, 61 | 0); 62 | 63 | batch.End (); 64 | } 65 | 66 | /// 67 | /// Gibt true zurück, wenn mindestens ein Wert eine Transparenz enthält 68 | /// 69 | /// 70 | protected bool ContainsAlpha () { 71 | foreach (var s in GradientStops) { 72 | if (s.Color.A < 255) 73 | return true; 74 | } 75 | return false; 76 | } 77 | 78 | protected abstract Texture2D CreateTexture (); 79 | 80 | Color GetPrevColor (float offset) { 81 | GradientStop frame = null; 82 | foreach (var f in this.GradientStops) { 83 | if (f.Offset <= offset && (frame == null || (frame != null && f.Offset > frame.Offset))) 84 | frame = f; 85 | } 86 | if (frame != null) 87 | return frame.Color; 88 | 89 | return Colors.Transparent; 90 | } 91 | 92 | Color GetNextColor (float offset) { 93 | GradientStop frame = null; 94 | foreach (var f in this.GradientStops) { 95 | if (f.Offset > offset && (frame == null || (frame != null && f.Offset < frame.Offset))) 96 | frame = f; 97 | } 98 | if (frame != null) 99 | return frame.Color; 100 | 101 | return Colors.Transparent; 102 | } 103 | 104 | float GetPrevOffset (float offset) { 105 | GradientStop frame = null; 106 | foreach (var f in this.GradientStops) { 107 | if (f.Offset <= offset && (frame == null || (frame != null && f.Offset > frame.Offset))) 108 | frame = f; 109 | } 110 | if (frame != null) 111 | return frame.Offset; 112 | 113 | return float.NaN; 114 | } 115 | 116 | float GetNextOffset (float offset) { 117 | GradientStop frame = null; 118 | foreach (var f in this.GradientStops) { 119 | if (f.Offset > offset && (frame == null || (frame != null && f.Offset < frame.Offset))) 120 | frame = f; 121 | } 122 | if (frame != null) 123 | return frame.Offset; 124 | 125 | return float.NaN; 126 | } 127 | 128 | protected Color GetGradientColor (float offset) { 129 | offset = MathHelper.Clamp(offset, 0, 1); 130 | /* 131 | if (offset > 1) 132 | offset = 1; 133 | * */ 134 | 135 | var prevTimeMillis = GetPrevOffset (offset); 136 | var nextTimeMillis = GetNextOffset (offset); 137 | 138 | var prevValue = GetPrevColor (offset); 139 | var nextValue = GetNextColor (offset); 140 | 141 | if (offset - prevTimeMillis <= 0.0) 142 | return prevValue; 143 | else if ((offset - prevTimeMillis) >= nextTimeMillis) 144 | return nextValue; 145 | else { 146 | float v = (float)(1.0 / ((double)(nextTimeMillis - prevTimeMillis) 147 | / (double)(offset - prevTimeMillis))); 148 | 149 | return Color.Lerp ( 150 | prevValue, nextValue, v); 151 | } 152 | } 153 | 154 | private BlendState blendState; 155 | private Texture2D texture; 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Controls/NumericUpDown.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Graphics; 5 | using WPFLight.Resources; 6 | using System.Windows.Media; 7 | 8 | namespace System.Windows.Controls { 9 | public class NumericUpDown : Panel { 10 | public NumericUpDown () : base ( ) { 11 | this.Value = 0; 12 | this.MinValue = 0; 13 | this.MaxValue = 100; 14 | this.Background = new SolidColorBrush (this.GraphicsDevice, System.Windows.Media.Colors.White * .28f); 15 | } 16 | 17 | #region Ereignisse 18 | 19 | public event EventHandler ValueChanged; 20 | 21 | #endregion 22 | 23 | #region Eigenschaften 24 | 25 | public static readonly DependencyProperty MinValueProperty = 26 | DependencyProperty.Register ( 27 | "MinValue", typeof ( int ), typeof ( NumericUpDown ) ); 28 | 29 | public int MinValue { 30 | get { return ( int ) GetValue (MinValueProperty); } 31 | set { SetValue (MinValueProperty, value); } 32 | } 33 | 34 | public static readonly DependencyProperty MaxValueProperty = 35 | DependencyProperty.Register ( 36 | "MaxValue", typeof ( int ), typeof ( NumericUpDown ) ); 37 | 38 | public int MaxValue { 39 | get { return ( int ) GetValue (MaxValueProperty); } 40 | set { SetValue (MaxValueProperty, value); } 41 | } 42 | 43 | public static readonly DependencyProperty ValueProperty = 44 | DependencyProperty.Register ( 45 | "Value", 46 | typeof ( int ), 47 | typeof ( NumericUpDown ), 48 | new PropertyMetadata ( 49 | 0, OnValueChanged ) ); 50 | 51 | public int Value { 52 | get { return ( int ) GetValue (ValueProperty); } 53 | set { SetValue (ValueProperty, value); } 54 | } 55 | 56 | #endregion 57 | 58 | static void OnValueChanged ( DependencyObject sender, DependencyPropertyChangedEventArgs e ) { 59 | var ctrl = sender as NumericUpDown; 60 | ctrl.UpdateValue (); 61 | if (ctrl.ValueChanged != null) 62 | ctrl.ValueChanged (sender, EventArgs.Empty); 63 | } 64 | 65 | public override void Initialize () { 66 | gridRoot = new Grid(); 67 | gridRoot.RowDefinitions.Add(RowDefinition.Star); 68 | gridRoot.ColumnDefinitions.Add(ColumnDefinition.Star); 69 | gridRoot.ColumnDefinitions.Add(new ColumnDefinition(new GridLength(64, GridUnitType.Pixel))); 70 | gridRoot.ColumnDefinitions.Add(new ColumnDefinition(new GridLength(64, GridUnitType.Pixel))); 71 | 72 | this.Children.Add(this.gridRoot); 73 | 74 | cmdDown = new Button(); 75 | cmdDown.Content = new Image (Textures.ArrowDown){ Margin = new Thickness ( 10,15,10,15 ), Opacity = .6f }; 76 | //cmdDown.FontScale = .3f; 77 | //cmdDown.Foreground = System.Windows.Media.Color.White; 78 | //cmdDown.Background = new SolidColorBrush (this.GraphicsDevice, Color.Black * .45f); 79 | cmdDown.BorderThickness = new Thickness (1); 80 | //cmdDown.BorderColor = Color.White * .45f; 81 | cmdDown.Margin = new Thickness (3); 82 | cmdDown.Click += delegate { 83 | this.Value = ( int ) MathHelper.Clamp ( 84 | this.Value - 1, this.MinValue, this.MaxValue ); 85 | }; 86 | 87 | gridRoot.Children.Add(cmdDown); 88 | 89 | Grid.SetColumn(cmdDown, 1); 90 | 91 | cmdUp = new Button(); 92 | cmdUp.Content = new Image (Textures.ArrowUp){ Margin = new Thickness ( 10,15,10,15 ), Opacity = .6f }; 93 | //cmdUp.Background = new SolidColorBrush (this.GraphicsDevice, Color.Black * .45f); 94 | cmdUp.BorderThickness = new Thickness (1); 95 | //cmdUp.BorderColor = Color.White * .45f; 96 | cmdUp.Margin = new Thickness (3); 97 | cmdUp.Click += delegate { 98 | this.Value = ( int ) MathHelper.Clamp ( 99 | this.Value + 1, this.MinValue, this.MaxValue ); 100 | }; 101 | 102 | gridRoot.Children.Add(cmdUp); 103 | 104 | Grid.SetColumn(cmdUp, 2); 105 | 106 | lblValue = new Label(); 107 | lblValue.VerticalAlignment = VerticalAlignment.Center; 108 | lblValue.FontScale = .23f; 109 | lblValue.Margin = new Thickness (15,3,3,3); 110 | 111 | gridRoot.Children.Add (lblValue); 112 | 113 | base.Initialize(); 114 | UpdateValue (); 115 | } 116 | 117 | void UpdateValue ( ) { 118 | if ( this.IsInitialized ) 119 | lblValue.Text = this.Value.ToString (); 120 | } 121 | 122 | private Label lblValue; 123 | private Button cmdUp; 124 | private Button cmdDown; 125 | private Grid gridRoot; 126 | } 127 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/Animation/SingleKeyFrameAnimation.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.Xna.Framework; 3 | using System; 4 | 5 | namespace System.Windows.Media.Animation 6 | { 7 | public class SingleKeyFrameAnimation : SingleAnimationBase { 8 | public SingleKeyFrameAnimation ( ) { 9 | this.KeyFrames = new List ( ); 10 | } 11 | 12 | #region Eigenschaften 13 | 14 | public List KeyFrames { get; private set; } 15 | 16 | #endregion 17 | 18 | public void Add ( SingleKeyFrame item ) { 19 | this.KeyFrames.Add ( item ); 20 | _lastDuration = TimeSpan.FromSeconds ( -1 ); 21 | } 22 | 23 | public void Add ( TimeSpan time, float value ) { 24 | this.KeyFrames.Add ( new SingleKeyFrame ( time, value ) ); 25 | _lastDuration = TimeSpan.FromSeconds(-1); 26 | } 27 | 28 | public void Clear ( ) { 29 | this.KeyFrames.Clear ( ); 30 | _lastDuration = TimeSpan.FromSeconds ( -1 ); 31 | } 32 | 33 | public void Remove ( SingleKeyFrame item ) { 34 | this.KeyFrames.Remove ( item ); 35 | _lastDuration = TimeSpan.FromSeconds ( -1 ); 36 | } 37 | 38 | float GetPrevValue ( ) { 39 | SingleKeyFrame? frame = null; 40 | foreach ( SingleKeyFrame f in this.KeyFrames ) { 41 | if ( f.Time <= CurrentTime && ( frame==null || ( frame != null && f.Time > frame.Value.Time ) ) ) { 42 | frame = f; 43 | } 44 | } 45 | if ( frame != null ) 46 | return frame.Value.Value; 47 | 48 | return float.NaN; 49 | } 50 | 51 | float GetNextValue ( ) { 52 | SingleKeyFrame? frame = null; 53 | foreach ( SingleKeyFrame f in this.KeyFrames ) { 54 | if ( f.Time > CurrentTime && ( frame==null || ( frame != null && f.Time < frame.Value.Time ) ) ) { 55 | frame = f; 56 | } 57 | } 58 | if ( frame != null ) 59 | return frame.Value.Value; 60 | 61 | return float.NaN; 62 | } 63 | 64 | TimeSpan GetPrevTime ( ) { 65 | SingleKeyFrame? frame = null; 66 | foreach ( SingleKeyFrame f in this.KeyFrames ) { 67 | if ( f.Time <= CurrentTime && ( frame==null || ( frame != null && f.Time > frame.Value.Time ) ) ) { 68 | frame = f; 69 | } 70 | } 71 | if ( frame != null ) 72 | return frame.Value.Time; 73 | 74 | return TimeSpan.FromSeconds(-1); 75 | } 76 | 77 | TimeSpan GetNextTime ( ) { 78 | SingleKeyFrame? frame = null; 79 | foreach ( SingleKeyFrame f in this.KeyFrames ) { 80 | if ( f.Time > CurrentTime && ( frame==null || ( frame != null && f.Time < frame.Value.Time ) ) ) { 81 | frame = f; 82 | } 83 | } 84 | if ( frame != null ) 85 | return frame.Value.Time; 86 | 87 | return TimeSpan.FromSeconds(-1); 88 | } 89 | 90 | public override float GetCurrentValue ( ) { 91 | var prevTimeMillis = TimeSpan.Zero; 92 | var nextTimeMillis = TimeSpan.Zero; 93 | 94 | if ((lastPrevTime==TimeSpan.FromMinutes(-1)) 95 | || this.CurrentTime >= lastNextTime ) 96 | lastPrevTime = GetPrevTime (); 97 | 98 | if ((lastNextTime==TimeSpan.FromMinutes(-1)) 99 | || this.CurrentTime >= lastNextTime ) 100 | lastNextTime = GetNextTime (); 101 | 102 | prevTimeMillis = lastPrevTime; 103 | nextTimeMillis = lastNextTime; 104 | 105 | if (CurrentTime - prevTimeMillis <= TimeSpan.Zero) 106 | return GetPrevValue (); 107 | else if ((CurrentTime - prevTimeMillis) >= nextTimeMillis) 108 | return GetNextValue (); 109 | else { 110 | float v = ( float ) ( 1.0 / ( ( double ) ( nextTimeMillis - prevTimeMillis ).Ticks / ( double ) ( CurrentTime - prevTimeMillis ).Ticks ) ); 111 | if (lastV != v) { 112 | lastV = v; 113 | lastComputedValue = ComputeValue ( 114 | GetPrevValue(), GetNextValue(), v ); 115 | } 116 | return lastComputedValue; 117 | } 118 | } 119 | 120 | private TimeSpan lastNextTime; 121 | private TimeSpan lastPrevTime; 122 | private float lastComputedValue; 123 | private float lastV = float.MinValue; 124 | 125 | public override void Begin (TimeSpan beginTime) 126 | { 127 | lastNextTime = TimeSpan.FromSeconds (-1); 128 | lastPrevTime = TimeSpan.FromSeconds (-1); 129 | base.Begin (beginTime); 130 | } 131 | 132 | public TimeSpan GetDuration() { 133 | if ( _lastDuration > TimeSpan.FromSeconds(-1) ) 134 | return _lastDuration; 135 | 136 | var max = TimeSpan.Zero; 137 | foreach ( SingleKeyFrame f in this.KeyFrames ) { 138 | if ( f.Time > max ) 139 | max = f.Time; 140 | } 141 | _lastDuration = max; 142 | return max; 143 | } 144 | 145 | private TimeSpan _lastDuration; 146 | } 147 | } -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/LinearGradientBrush.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using Microsoft.Xna.Framework; 5 | using WPFLight.Helpers; 6 | using WPFLight.Extensions; 7 | 8 | namespace System.Windows.Media 9 | { 10 | public class LinearGradientBrush : GradientBrush 11 | { 12 | public LinearGradientBrush () : base ( ) { } 13 | 14 | public override bool Equals (object obj) { 15 | var brush = obj as LinearGradientBrush; 16 | if (brush != null 17 | && brush.StartPoint == this.StartPoint 18 | && brush.EndPoint == this.EndPoint 19 | && brush.Opacity == this.Opacity 20 | && brush.GradientStops.Count == this.GradientStops.Count ) { 21 | 22 | var stops = this.GradientStops 23 | .OrderBy(g => g.Offset) 24 | .ToArray(); 25 | 26 | var brushStops = brush.GradientStops 27 | .OrderBy ( g => g.Offset ) 28 | .ToArray ( ); 29 | 30 | for ( var i = 0; i < brushStops.Length; i++ ) { 31 | if (!brushStops[i].Equals(stops[i])) 32 | return false; 33 | } 34 | return true; 35 | } 36 | return false; 37 | } 38 | 39 | public override int GetHashCode () { 40 | var hash = "LGB_" 41 | + this.StartPoint.GetHashCode() + ";" 42 | + this.EndPoint.GetHashCode() + ";" 43 | + this.Opacity.GetHashCode() + ";"; 44 | 45 | foreach (var gs in this.GradientStops.OrderBy(g => g.Offset)) { 46 | hash += gs.GetHashCode() + ";"; 47 | } 48 | return hash.GetHashCode(); 49 | } 50 | 51 | protected override Texture2D CreateTexture() { 52 | var width = 100; 53 | var height = 100; 54 | 55 | var tex = new Texture2D(this.GraphicsDevice, width, height); 56 | tex.SetData(this.GetTextureData(width, height)); 57 | return tex; 58 | } 59 | 60 | internal override Color GetPixel ( int x, int y, int width, int height ) { 61 | var deltaX = EndPoint.X - StartPoint.X; 62 | var deltaY = EndPoint.Y - StartPoint.Y; 63 | var denom = 1.0f / ((deltaX * deltaX) + (deltaY * deltaY)); 64 | var t = (deltaX * (x - StartPoint.X) + deltaY * (y - StartPoint.Y)) * denom; 65 | return this.GetGradientColor (t / 100f); 66 | } 67 | 68 | internal override int[] GetTextureData ( int width, int height ) { 69 | var pixels = new int[width * height]; 70 | var copyHorizontal = false; 71 | var copyVertical = false; 72 | 73 | if (this.StartPoint.X == this.EndPoint.X) { 74 | // 0° / 180° - copy vertical lines 75 | copyVertical = true; 76 | } 77 | 78 | if (this.EndPoint.Y == this.StartPoint.Y) { 79 | // 90° / 270° - copy horizontal lines 80 | copyHorizontal = true; 81 | } 82 | 83 | if (copyVertical) { 84 | var lastValue = 0; 85 | var srcLine = default ( int[] ); 86 | 87 | // copy each line 88 | for (var y = 0; y < height; y++) { 89 | var value = (int) this.GetPixel(0, y, width, height).PackedValue; 90 | if ( srcLine == null || ( lastValue!= value ) ) { 91 | if ( srcLine == null ) 92 | srcLine = new int [ width ]; 93 | 94 | srcLine.Fill ( value ); 95 | lastValue = value; 96 | } 97 | Array.Copy ( 98 | srcLine, 0, pixels, y * width, width); 99 | } 100 | } else if ( copyHorizontal ) { 101 | // Array.Copy can't be used for Horizontal-Copy 102 | for (var x = 0; x < width; x++) { 103 | var value = (int)this.GetPixel(x, 0, width, height).PackedValue; 104 | for (var y = 0; y < height; y++) { 105 | pixels[y * width + x] = value; 106 | } 107 | } 108 | } else { 109 | // copy each pixel 110 | for ( var y = 0; y < height; y++ ) { 111 | for ( var x = 0; x < width; x++) { 112 | pixels[y * width + x] = 113 | ( int ) this.GetPixel(x, y, width, height).PackedValue; 114 | } 115 | } 116 | } 117 | return pixels; 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Shapes/Shape.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Media; 2 | using System.Collections.Generic; 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Graphics; 5 | using WPFLight.Helpers; 6 | using System.Threading.Tasks; 7 | 8 | namespace System.Windows.Shapes { 9 | public abstract class Shape : FrameworkElement { 10 | #region Eigenschaften 11 | 12 | /// 13 | /// Fill property 14 | /// 15 | public static readonly DependencyProperty FillProperty = 16 | DependencyProperty.Register ( 17 | "Fill", 18 | typeof(Brush), 19 | typeof(Shape)); 20 | 21 | /// 22 | /// Fill property 23 | /// 24 | public Brush Fill { 25 | get { return (Brush)GetValue (FillProperty); } 26 | set { SetValue (FillProperty, value); } 27 | } 28 | 29 | /// 30 | /// Stroke property 31 | /// 32 | public static readonly DependencyProperty StrokeProperty = 33 | DependencyProperty.Register ( 34 | "Stroke", 35 | typeof(Brush), 36 | typeof(Shape)); 37 | 38 | /// 39 | /// Stroke property 40 | /// 41 | public Brush Stroke { 42 | get { return (Brush)GetValue (StrokeProperty); } 43 | set { SetValue (StrokeProperty, value); } 44 | } 45 | 46 | /// 47 | /// StrokeThickness property 48 | /// 49 | public static readonly DependencyProperty StrokeThicknessProperty = 50 | DependencyProperty.Register ( 51 | "StrokeThickness", 52 | typeof(double), 53 | typeof(Shape) ); 54 | 55 | /// 56 | /// StrokeThickness property 57 | /// 58 | public double StrokeThickness { 59 | get { return (double)GetValue (StrokeThicknessProperty); } 60 | set { SetValue (StrokeThicknessProperty, value); } 61 | } 62 | 63 | #endregion 64 | 65 | protected internal static Point GetCubicBezier (double t, Point p0, Point p1, Point p2, Point p3) { 66 | double cx = 3 * (p1.X - p0.X); 67 | double cy = 3 * (p1.Y - p0.Y); 68 | 69 | double bx = 3 * (p2.X - p1.X) - cx; 70 | double by = 3 * (p2.Y - p1.Y) - cy; 71 | 72 | double ax = p3.X - p0.X - cx - bx; 73 | double ay = p3.Y - p0.Y - cy - by; 74 | 75 | double Cube = t * t * t; 76 | double Square = t * t; 77 | 78 | double resX = (ax * Cube) + (bx * Square) + (cx * t) + p0.X; 79 | double resY = (ay * Cube) + (by * Square) + (cy * t) + p0.Y; 80 | 81 | return new Point ((float)resX, (float)resY); 82 | } 83 | 84 | public override void Invalidate ( ) { 85 | if ( this.ActualWidth > 0 && this.ActualHeight > 0 ) 86 | texture = CreateTexture(); 87 | 88 | /* 89 | if (this.ActualWidth > 0 && this.ActualHeight > 0) { 90 | CreateTextureAsync().ContinueWith( 91 | (t) => { 92 | //lock ( this ) { 93 | if ( t.IsCompleted && !t.IsFaulted && t.Result != null ) { 94 | //if ( texture != null && !texture.IsDisposed ) 95 | //texture.Dispose ( ); 96 | 97 | texture = t.Result; 98 | } 99 | //} 100 | } ); 101 | } 102 | * */ 103 | 104 | base.Invalidate (); 105 | } 106 | 107 | Task CreateTextureAsync () { 108 | return Task.Factory.StartNew( 109 | () => { return CreateTexture(); }); 110 | } 111 | 112 | public override void Initialize () { 113 | base.Initialize (); 114 | } 115 | 116 | public override void Draw (GameTime gameTime, SpriteBatch batch, float alpha, Matrix transform) { 117 | //base.Draw (gameTime, batch, alpha, transform); 118 | 119 | if (texture != null 120 | && !texture.IsDisposed 121 | && alpha > 0 122 | && (this.Stroke != null || this.Fill != null) 123 | && this.IsVisible 124 | && this.ActualWidth > 0 125 | && this.ActualHeight > 0) { 126 | 127 | batch.Begin ( 128 | SpriteSortMode.Deferred, 129 | BlendState.AlphaBlend, 130 | SamplerState.LinearClamp, 131 | DepthStencilState.None, 132 | SCISSOR_ENABLED, 133 | null, 134 | transform); 135 | 136 | var left = this.GetAbsoluteLeft (); 137 | var top = this.GetAbsoluteTop (); 138 | 139 | batch.Draw ( 140 | texture, 141 | new Microsoft.Xna.Framework.Rectangle ( 142 | (int)(left), 143 | (int)(top), 144 | (int)Math.Ceiling (this.ActualWidth), 145 | (int)Math.Ceiling (this.ActualHeight)), 146 | Microsoft.Xna.Framework.Color.White * alpha 147 | ); 148 | 149 | batch.End (); 150 | } 151 | } 152 | 153 | protected abstract Texture2D CreateTexture (); 154 | 155 | private Texture2D texture; 156 | private bool invalidTexture; 157 | 158 | static readonly RasterizerState SCISSOR_ENABLED = 159 | new RasterizerState { 160 | CullMode = CullMode.None, 161 | ScissorTestEnable = true }; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /WPFLight/System/Windows/Media/Animation/Storyboard.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Windows; 5 | using Microsoft.Xna.Framework; 6 | using System.Windows.Controls; 7 | 8 | namespace System.Windows.Media.Animation { 9 | public class Storyboard : IAnimationBase { 10 | static Storyboard ( ) { 11 | storyboards = new List ( ); 12 | } 13 | 14 | #region Eigenschaften 15 | 16 | public bool IsActive { get; private set; } 17 | 18 | public TimeSpan BeginTime { get; set; } 19 | 20 | public List Children { 21 | get { 22 | if ( children == null ) 23 | children = new List ( ); 24 | 25 | return children; 26 | } 27 | } 28 | 29 | private static Dictionary Targets { 30 | get { 31 | if ( targets == null ) 32 | targets = new Dictionary ( ); 33 | 34 | return targets; 35 | } 36 | } 37 | 38 | private static Dictionary TargetProperties { 39 | get { 40 | if ( targetProperties == null ) 41 | targetProperties = new Dictionary ( ); 42 | 43 | return targetProperties; 44 | } 45 | } 46 | 47 | #endregion 48 | 49 | public void Begin ( ) { 50 | Begin ( TimeSpan.Zero ); 51 | } 52 | 53 | public void Begin ( TimeSpan beginTime ) { 54 | this.BeginTime = beginTime; 55 | this.IsActive = true; 56 | foreach ( var child in this.Children ) { 57 | child.Completed += delegate { CheckState ( ); }; 58 | child.Begin ( this.BeginTime ); 59 | } 60 | if ( !storyboards.Contains ( this ) ) 61 | storyboards.Add ( this ); 62 | } 63 | 64 | public void Pause ( ) { 65 | this.IsActive = false; 66 | foreach ( var child in this.Children ) 67 | child.Pause ( ); 68 | 69 | storyboards.Remove ( this ); 70 | } 71 | 72 | public void Resume ( ) { 73 | this.IsActive = true; 74 | foreach ( var child in this.Children ) 75 | child.Resume ( ); 76 | 77 | if ( !storyboards.Contains ( this ) ) 78 | storyboards.Add ( this ); 79 | } 80 | 81 | public void Stop ( ) { 82 | this.IsActive = false; 83 | foreach ( var child in this.Children ) 84 | child.Stop ( ); 85 | 86 | storyboards.Remove ( this ); 87 | } 88 | 89 | public void Update ( GameTime gameTime ) { 90 | foreach ( var child in this.Children ) { 91 | child.Update ( gameTime ); 92 | } 93 | } 94 | 95 | public static Control GetTarget ( SingleAnimationBase animation ) { 96 | return Storyboard.Targets.ContainsKey ( animation ) 97 | ? Storyboard.Targets[animation] : null; 98 | } 99 | 100 | public static string GetTargetProperty ( SingleAnimationBase animation ) { 101 | return Storyboard.TargetProperties.ContainsKey ( animation ) 102 | ? Storyboard.TargetProperties[animation] : null; 103 | } 104 | 105 | public static void SetTarget ( SingleAnimationBase animation, Control target ) { 106 | Storyboard.Targets[animation] = target; 107 | } 108 | 109 | public static void SetTargetProperty ( SingleAnimationBase animation, string propertyName ) { 110 | Storyboard.TargetProperties[animation] = propertyName; 111 | } 112 | 113 | void CheckState ( ) { 114 | var active = false; 115 | foreach ( var child in this.Children ) { 116 | if ( child.State == AnimationState.Started ) 117 | active = true; 118 | } 119 | this.IsActive = active; 120 | if ( !active ) 121 | storyboards.Remove ( this ); 122 | } 123 | 124 | public static void UpdateActive ( GameTime gameTime ) { 125 | foreach ( var s in storyboards.ToArray ( ) ) { 126 | if ( s.IsActive ) { 127 | s.Update ( gameTime ); 128 | } 129 | } 130 | } 131 | 132 | private List children; 133 | 134 | private static IList storyboards; 135 | private static Dictionary targets; 136 | private static Dictionary targetProperties; 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /WPFLight/System/Collections/Specialized/NotifyCollectionChangedEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace System.Collections.Specialized { 2 | public class NotifyCollectionChangedEventArgs : EventArgs { 3 | public NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction action) { 4 | this.Action = action; 5 | if (action != NotifyCollectionChangedAction.Reset) 6 | throw new ArgumentException("This constructor can only be used with the Reset action.", "action"); 7 | } 8 | 9 | public NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction action, object changedItem, int index) { 10 | IList changedItems = new object[] { changedItem }; 11 | this.Action = action; 12 | 13 | if (action == NotifyCollectionChangedAction.Add) { 14 | this.NewItems = new[] { changedItem }; 15 | this.NewStartingIndex = index; 16 | } else if (action == NotifyCollectionChangedAction.Remove) { 17 | this.OldItems = new[] { changedItem }; 18 | this.OldStartingIndex = index; 19 | } else if (action == NotifyCollectionChangedAction.Reset) { 20 | if (changedItem != null) 21 | throw new ArgumentException("This constructor can only be used with the Reset action if changedItem is null", "changedItem"); 22 | 23 | if (index != -1) 24 | throw new ArgumentException("This constructor can only be used with the Reset action if index is -1", "index"); 25 | } else { 26 | throw new ArgumentException("This constructor can only be used with the Reset, Add, or Remove actions.", "action"); 27 | } 28 | } 29 | 30 | public NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction action, object newItem, object oldItem, int index) { 31 | this.Action = action; 32 | 33 | if (action != NotifyCollectionChangedAction.Replace) 34 | throw new ArgumentException("This constructor can only be used with the Replace action.", "action"); 35 | 36 | this.NewItems = new[] { newItem }; 37 | this.NewStartingIndex = index; 38 | 39 | this.OldItems = new[] { oldItem }; 40 | this.OldStartingIndex = index; 41 | } 42 | 43 | public NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction action, object changedItem, int index, int oldIndex) 44 | : this(action, new object[] { changedItem }, index, oldIndex) { 45 | 46 | } 47 | 48 | public NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction action, IList changedItems, int index, int oldIndex) { 49 | this.Action = action; 50 | 51 | if (action != NotifyCollectionChangedAction.Move) 52 | throw new ArgumentException("This constructor can only be used with the Move action.", "action"); 53 | 54 | if (index < -1) 55 | throw new ArgumentException("The value of index must be -1 or greater.", "index"); 56 | 57 | this.NewItems = changedItems; 58 | this.NewStartingIndex = index; 59 | 60 | this.OldItems = changedItems; 61 | this.OldStartingIndex = oldIndex; 62 | } 63 | 64 | public NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction action, IList changedItems) { 65 | switch (action) { 66 | case NotifyCollectionChangedAction.Add: { 67 | NewItems = changedItems; 68 | break; 69 | } 70 | case NotifyCollectionChangedAction.Remove: { 71 | OldItems = changedItems; 72 | break; 73 | } 74 | case NotifyCollectionChangedAction.Move: { 75 | throw new NotImplementedException(); 76 | } 77 | case NotifyCollectionChangedAction.Replace: { 78 | throw new NotImplementedException(); 79 | } 80 | case NotifyCollectionChangedAction.Reset: { 81 | OldItems = changedItems; 82 | break; 83 | } 84 | } 85 | 86 | this.Action = action; 87 | } 88 | 89 | #region Properties 90 | 91 | public NotifyCollectionChangedAction Action { get; private set; } 92 | public IList NewItems { get; private set; } 93 | public IList OldItems { get; private set; } 94 | public int OldStartingIndex { get; private set; } 95 | public int NewStartingIndex { get; private set; } 96 | 97 | #endregion 98 | } 99 | 100 | public enum NotifyCollectionChangedAction { 101 | Add, 102 | Move, 103 | Remove, 104 | Replace, 105 | Reset, 106 | } 107 | } --------------------------------------------------------------------------------