Example #1
0
        public void Colour(Color colour)
        {
            if (State != BackgroundState.Coloured)
            {
                Restore();
                try
                {
                    Image image;
                    image = ImageProcessing.ImportImage(Path);
                    Image    blackImage = new Bitmap(image);
                    Graphics graphics   = Graphics.FromImage(blackImage);
                    graphics.Clear(colour);

                    File.Move(Path, Path + "clr");
                    blackImage.Save(Path);
                    State = BackgroundState.Coloured;
                }
                catch (IOException ex)
                {
                    if (File.Exists(Path + "clr") && !File.Exists(Path))
                    {
                        File.Move(Path + "clr", Path);
                    }
                    throw new IOException($"Failed to colour background: {Name}. Restored to normal.", ex);
                }
            }
        }
Example #2
0
 public void Blur(int BlurRadius)
 {
     if (State != BackgroundState.Blurred)
     {
         Restore();
         if (BlurRadius > 0)
         {
             try
             {
                 Image image;
                 image = ImageProcessing.ImportImage(Path);
                 Image blurredImage = ImageProcessing.Blur((Bitmap)image, BlurRadius);
                 File.Move(Path, Path + "blr");
                 blurredImage.Save(Path);
                 State = BackgroundState.Blurred;
             }
             catch (IOException ex)
             {
                 if (File.Exists(Path + "blr") && !File.Exists(Path))
                 {
                     File.Move(Path + "blr", Path);
                 }
                 throw new IOException($"Failed to blur background: {Name}. Restored to normal.", ex);
             }
         }
     }
 }
Example #3
0
 public Background(string path)
 {
     if (File.Exists(path))
     {
         Path  = path;
         State = BackgroundState.Normal;
         if (File.Exists(path + "blr"))
         {
             State = BackgroundState.Blurred;
         }
         else if (File.Exists(path + "clr"))
         {
             State = BackgroundState.Coloured;
         }
     }
     else if (File.Exists(path + "dbl"))
     {
         Path  = path;
         State = BackgroundState.Disabled;
     }
     else
     {
         State = BackgroundState.Missing;
     }
 }
Example #4
0
    public async Task ParseAsync(XmlReader reader, IParsingContext parsingContext, IParentParsingContext parentParsingContext)
    {
        var context = new BackgroundContext();
        await elementParser.ParseAsync(reader, parsingContext, context, Settings);

        if (!string.IsNullOrWhiteSpace(context.ParsedText))
        {
            var state = new BackgroundState(context.ParsedText, BackgroundType.Image, BackgroundPosition.Left);
            var block = parsingContext.BlockFactory.Create(
                new BackgroundNode(state, null),
                new ScrollNode(null)
                );
            parentParsingContext.AddNode(new BlockNode(block, context.When));
            parsingContext.RegisterDismissNode(DismissNode);
            return;
        }

        if (context.Nodes.Count == 0)
        {
            parsingContext.LogError(reader, "Nome de imagem ou elemento filho era esperado.");
            return;
        }

        {
            var block = parsingContext.BlockFactory.Create(context.Nodes);
            parentParsingContext.AddNode(new BlockNode(block, context.When));
            parsingContext.RegisterDismissNode(DismissNode);
        }
    }
Example #5
0
 public Background(float x, float y, float x2, float y2, Color color, BackgroundState state)
 {
     this._x     = x;
     this._y     = y;
     this._x2    = x2;
     this._y2    = y2;
     this._color = color;
     this._state = state;
 }
Example #6
0
 public void Disable()
 {
     if (State != BackgroundState.Disabled)
     {
         Restore();
         try { File.Move(Path, Path + "dbl"); }
         catch (IOException ex) { throw new IOException($"Failed to disable background: {Name}. Restored to normal.", ex); }
         State = BackgroundState.Disabled;
     }
 }
Example #7
0
    public async Task IgnoreOnInvalidState(BackgroundType type, BackgroundPosition position)
    {
        var oldState = new BackgroundState("alpha", type, position);
        var context  = A.Dummy <INavigationContext>();

        context.State.Background = oldState;
        var invoker = new TestInvoker(context);

        var sut = new ScrollNode(null);
        var ret = await sut.EnterAsync(context);

        ret.Should().BeNull();
        context.State.Background.Should().BeSameAs(oldState);
        invoker.Count.Should().Be(0);
    }
Example #8
0
        private static void CreateStateInstancees(IApplicationController applicationController,
                                                  out IBackgroundState backgroundState, out IGridState gridState, out IScaleState scaleState, out IDataDrawState graphState, out IGraphControlFormState graphControlFormState)
        {
            backgroundState = new BackgroundState();
            applicationController.RegisterInstance <IBackgroundState>(backgroundState);

            gridState = new GridState();
            applicationController.RegisterInstance <IGridState>(gridState);

            scaleState = new ScaleState();
            applicationController.RegisterInstance <IScaleState>(scaleState);

            graphState = new DataDrawState();
            applicationController.RegisterInstance <IDataDrawState>(graphState);

            graphControlFormState = new GraphControlFormState();
            applicationController.RegisterInstance <IGraphControlFormState>(graphControlFormState);
        }
Example #9
0
        public void Restore()
        {
            if (!(State == BackgroundState.Normal || State == BackgroundState.Missing))
            {
                if (State == BackgroundState.Disabled)
                {
                    try { File.Move(Path + "dbl", Path); }
                    catch (IOException ex) { throw new IOException($"Failed to restore background: {Name}", ex); }
                }
                else
                {
                    string ext = "";
                    switch (State)
                    {
                    case BackgroundState.Coloured:
                        ext = "clr";
                        break;

                    case BackgroundState.Blurred:
                        ext = "blr";
                        break;
                    }
                    try
                    {
                        File.Move(Path, Path + "temp");
                        File.Move(Path + ext, Path);
                    }
                    catch (IOException ex)
                    {
                        if (File.Exists(Path + "temp"))
                        {
                            File.Move(Path + "temp", Path);
                        }
                        throw new IOException(ex.Message, ex);
                    }
                    finally { if (File.Exists(Path + "temp"))
                              {
                                  File.Delete(Path + "temp");
                              }
                    }
                }
                State = BackgroundState.Normal;
            }
        }
Example #10
0
    public async Task EnterAsync(BackgroundPosition oldPosition, BackgroundPosition newPosition)
    {
        var oldState = new BackgroundState("alpha", BackgroundType.Image, oldPosition);
        var newState = new BackgroundState("alpha", BackgroundType.Image, newPosition);

        var when = A.Dummy <ICondition>();

        var context = A.Dummy <INavigationContext>();

        context.State.Background = oldState;
        var invoker = new TestInvoker(context);

        var sut = new ScrollNode(when);
        var ret = await sut.EnterAsync(context);

        ret.Should().BeNull();

        invoker.ShouldContainSingle <IBackgroundScrollEvent>(
            i => i.Should().BeEquivalentTo(new { Position = newPosition })
            );

        context.State.Background.Should().Be(newState);
    }
Example #11
0
        public UIManagerImpl(GameTablePanel gameTablePanel)
        {
            myGameTablePanel = gameTablePanel;
              Application.Current.RootVisual.Effect = myBackgroundBlur = new BlurEffect {Radius = 0};
              myCurrentBackgroundState = new BackgroundState(0, 1);

              Application.Current.RootVisual.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e)
                                                              {
                                                                if (myPopupData.Popup.IsOpen)
                                                                {
                                                                  ClosePopup(myPopupData, myPopupData.Element, false);
                                                                  e.Handled = true;
                                                                }
                                                              };
              Application.Current.RootVisual.KeyDown += delegate(object sender, KeyEventArgs e)
                                                  {
                                                    if (e.Key == Key.Escape && myPopupData.Popup.IsOpen)
                                                    {
                                                      ClosePopup(myPopupData, myPopupData.Element, false);
                                                      e.Handled = true;
                                                    }
                                                  };
        }
Example #12
0
        private void AnimatePopup(
            UIElement element,
            double duration,
            double targetElementOpacity,
            double targetBackgroundOpacity,
            double targetBackgroundBlur,
            IEnumerable<AnimationInfo> additionalAnimations = null,
            Action onCompleted = null)
        {
            if (myStoryboard != null)
              {
            myStoryboard.Pause();
            if (myOnAnimationCompleted != null)
            {
              myOnAnimationCompleted();
              myOnAnimationCompleted = null;
            }
              }

              UIElement rootVisual = Application.Current.RootVisual;
              IEnumerable<AnimationInfo> animations = new[]
                                                {
                                                  new AnimationInfo(element, new PropertyPath(UIElement.OpacityProperty), element.Opacity, targetElementOpacity),
                                                  new AnimationInfo(rootVisual, new PropertyPath(UIElement.OpacityProperty), rootVisual.Opacity, targetBackgroundOpacity),
                                                  new AnimationInfo(myBackgroundBlur, new PropertyPath(BlurEffect.RadiusProperty), myBackgroundBlur.Radius, targetBackgroundBlur)
                                                };
              if (additionalAnimations != null)
            animations = animations.Concat(additionalAnimations);

              myCurrentBackgroundState = new BackgroundState(targetBackgroundBlur, targetBackgroundOpacity);
              myStoryboard = UIUtil.StartAnimation(duration, animations);
              if (onCompleted != null)
              {
            myOnAnimationCompleted = onCompleted;
            myStoryboard.Completed += delegate
                                    {
                                      onCompleted();
                                      myOnAnimationCompleted = null;
                                    };
              }
        }
Example #13
0
 public BckSpiral(float x, float y, float x2, float y2, Color color, BackgroundState state) : base(x, y, x2, y2, color, state)
 {
 }
Example #14
0
 string SetBackground(BackgroundState state)
 {
     gameObject.transform.localScale = Vector3.one * state.scale;
     backgroundImage.color           = state.color;
     return(state.status);
 }
Example #15
0
    public void ToStringTest(string name, BackgroundType type, BackgroundPosition position, string expected)
    {
        var sut = new BackgroundState(name, type, position);

        sut.ToString().Should().Be(expected);
    }
Example #16
0
 private void Start()
 {
     State = BackgroundState.Inactive;
 }
Example #17
0
 private void Start()
 {
     State = BackgroundState.Inactive;
 }