Example #1
0
 public void SetupProperties()
 {
     if ((LayerType == LayerType.Keyboard || LayerType == LayerType.KeyboardGif) &&
         !(Properties is KeyboardPropertiesModel))
     {
         Properties = new KeyboardPropertiesModel
         {
             Brush     = new SolidColorBrush(ColorHelpers.GetRandomRainbowMediaColor()),
             Animation = LayerAnimation.None,
             Height    = 1,
             Width     = 1,
             X         = 0,
             Y         = 0,
             Opacity   = 1
         };
     }
     else if (LayerType == LayerType.Mouse && !(Properties is MousePropertiesModel))
     {
         Properties = new MousePropertiesModel
         {
             Brush = new SolidColorBrush(ColorHelpers.GetRandomRainbowMediaColor())
         }
     }
     ;
     else if (LayerType == LayerType.Headset && !(Properties is HeadsetPropertiesModel))
     {
         Properties = new HeadsetPropertiesModel
         {
             Brush = new SolidColorBrush(ColorHelpers.GetRandomRainbowMediaColor())
         }
     }
     ;
 }
Example #2
0
        public static GifImage DrawGif(DrawingContext c, KeyboardPropertiesModel props, AppliedProperties applied,
                                       GifImage gifImage)
        {
            if (string.IsNullOrEmpty(props.GifFile))
            {
                return(null);
            }
            if (!File.Exists(props.GifFile))
            {
                return(null);
            }

            const int scale = 4;

            // Only reconstruct GifImage if the underlying source has changed
            if (gifImage == null)
            {
                gifImage = new GifImage(props.GifFile);
            }
            if (gifImage.Source != props.GifFile)
            {
                gifImage = new GifImage(props.GifFile);
            }

            var gifRect = new Rect(applied.X * scale, applied.Y * scale, applied.Width * scale,
                                   applied.Height * scale);

            lock (gifImage)
            {
                var draw = gifImage.GetNextFrame();
                c.DrawImage(ImageUtilities.BitmapToBitmapImage(new Bitmap(draw)), gifRect);
            }

            return(gifImage);
        }
Example #3
0
        public static void UpdateAnimation(KeyboardPropertiesModel properties, bool updateAnimations)
        {
            const int scale    = 4;
            var       progress = properties.AnimationProgress;

            switch (properties.Animation)
            {
            case LayerAnimation.SlideRight:
            case LayerAnimation.SlideLeft:
                if (progress + properties.AnimationSpeed * 2 >= properties.Width * scale)
                {
                    progress = 0;
                }
                progress = progress + properties.AnimationSpeed * 2;
                break;

            case LayerAnimation.SlideDown:
            case LayerAnimation.SlideUp:
                if (progress + properties.AnimationSpeed * 2 >= properties.Height * scale)
                {
                    progress = 0;
                }
                progress = progress + properties.AnimationSpeed * 2;
                break;

            case LayerAnimation.Pulse:
                if (progress > 2)
                {
                    progress = 0;
                }
                progress = progress + properties.AnimationSpeed / 2;
                break;

            case LayerAnimation.Grow:
                if (progress > 10)
                {
                    progress = 0;
                }
                progress = progress + properties.AnimationSpeed / 2.5;
                break;

            default:
                progress = progress + properties.AnimationSpeed * 2;
                break;
            }

            // If not previewing, store the animation progress in the actual model for the next frame
            if (updateAnimations)
            {
                properties.AnimationProgress = progress;
            }
        }
Example #4
0
        private static void DrawRectangle(DrawingContext c, KeyboardPropertiesModel props, AppliedProperties applied,
                                          Rect clip, Rect rectangle, Rect slide1, Rect slide2)
        {
            // Apply the pulse animation
            if (props.Animation == LayerAnimation.Pulse)
            {
                applied.Brush.Opacity = (Math.Sin(props.AnimationProgress * Math.PI) + 1) * (props.Opacity / 2);
            }
            else
            {
                applied.Brush.Opacity = props.Opacity;
            }

            if (props.Animation == LayerAnimation.Grow)
            {
                // Take an offset of 4 to allow layers to slightly leave their bounds
                var progress = (6.0 - props.AnimationProgress) * 10.0;
                if (progress < 0)
                {
                    applied.Brush.Opacity = 1 + 0.025 * progress;
                    if (applied.Brush.Opacity < 0)
                    {
                        applied.Brush.Opacity = 0;
                    }
                    if (applied.Brush.Opacity > 1)
                    {
                        applied.Brush.Opacity = 1;
                    }
                }
                rectangle.Inflate(-rectangle.Width / 100.0 * progress, -rectangle.Height / 100.0 * progress);
                clip.Inflate(-clip.Width / 100.0 * progress, -clip.Height / 100.0 * progress);
            }

            c.PushClip(new RectangleGeometry(clip));
            // Most animation types can be drawn regularly
            if (props.Animation == LayerAnimation.None ||
                props.Animation == LayerAnimation.Grow ||
                props.Animation == LayerAnimation.Pulse)
            {
                c.DrawRectangle(applied.Brush, null, rectangle);
            }
            // Sliding animations however, require offsetting two rects
            else
            {
                c.PushClip(new RectangleGeometry(clip));
                c.DrawRectangle(applied.Brush, null, slide1);
                c.DrawRectangle(applied.Brush, null, slide2);
                c.Pop();
            }
            c.Pop();
        }
Example #5
0
        public void Apply(KeyboardPropertiesModel keyboardProperties)
        {
            var original = keyboardProperties.DynamicProperties.FirstOrDefault(lp => lp.LayerProperty == _property);

            if (original != null)
            {
                keyboardProperties.DynamicProperties.Remove(original);
            }

            if (!Proposed.GameProperty.IsNullOrEmpty())
            {
                keyboardProperties.DynamicProperties.Add(Proposed);
            }
        }
Example #6
0
        public static void Draw(DrawingContext c, KeyboardPropertiesModel props, AppliedProperties applied)
        {
            if (applied.Brush == null)
            {
                return;
            }

            const int scale = 4;
            // Set up variables for this frame
            var rect = props.Contain
                ? new Rect(applied.X * scale, applied.Y * scale, applied.Width * scale, applied.Height * scale)
                : new Rect(props.X * scale, props.Y * scale, props.Width * scale, props.Height * scale);

            var s1 = new Rect();
            var s2 = new Rect();

            if (props.Animation == LayerAnimation.SlideRight)
            {
                s1 = new Rect(new Point(rect.X + props.AnimationProgress, rect.Y), new Size(rect.Width, rect.Height));
                s2 = new Rect(new Point(s1.X - rect.Width, rect.Y), new Size(rect.Width + 1, rect.Height));
            }
            if (props.Animation == LayerAnimation.SlideLeft)
            {
                s1 = new Rect(new Point(rect.X - props.AnimationProgress, rect.Y),
                              new Size(rect.Width + 0.05, rect.Height));
                s2 = new Rect(new Point(s1.X + rect.Width, rect.Y), new Size(rect.Width, rect.Height));
            }
            if (props.Animation == LayerAnimation.SlideDown)
            {
                s1 = new Rect(new Point(rect.X, rect.Y + props.AnimationProgress), new Size(rect.Width, rect.Height));
                s2 = new Rect(new Point(s1.X, s1.Y - rect.Height), new Size(rect.Width, rect.Height));
            }
            if (props.Animation == LayerAnimation.SlideUp)
            {
                s1 = new Rect(new Point(rect.X, rect.Y - props.AnimationProgress), new Size(rect.Width, rect.Height));
                s2 = new Rect(new Point(s1.X, s1.Y + rect.Height), new Size(rect.Width, rect.Height));
            }

            var clip = new Rect(applied.X * scale, applied.Y * scale, applied.Width * scale, applied.Height * scale);

            DrawRectangle(c, props, applied, clip, rect, s1, s2);
        }
Example #7
0
        public LayerDynamicPropertiesViewModel(string property,
                                               BindableCollection <GeneralHelpers.PropertyCollection> dataModelProps,
                                               KeyboardPropertiesModel keyboardProperties)
        {
            _property = property;

            // Look for the existing property model
            Proposed = new DynamicPropertiesModel();
            var original = keyboardProperties.DynamicProperties.FirstOrDefault(lp => lp.LayerProperty == _property);

            if (original == null)
            {
                Proposed.LayerProperty     = property;
                Proposed.LayerPropertyType = LayerPropertyType.PercentageOf;
            }
            else
            {
                Proposed = GeneralHelpers.Clone(original);
            }

            PropertyChanged += OnPropertyChanged;
            SetupControls(dataModelProps);
        }