Ejemplo n.º 1
0
 public static void Load(string path)
 {
     ClearGraphics(GraphicController.rootList);
     GraphicController.Selected = null;
     try
     {
         if (File.Exists(path))
         {
             using (StreamReader sr = new StreamReader(path))
             {
                 GraphicSerializer serializer = new GraphicSerializer();
                 GraphicController.rootList = serializer.Deserialize(sr.ReadToEnd());
                 HideGraphics(GraphicController.rootList);
                 ControllerHelpers.CheckResize();
                 ControllerHelpers.RepositionControls(GraphicController.rootList);
                 CustomMessageBox.Show("Config file read.");
             }
         }
         else
         {
             CustomMessageBox.Show("No config file found.");
         }
     }
     catch { }
 }
        // Clear all controls so they can be freed
        public void Delete()
        {
            if (Graphic != null)
            {
                Graphic.Remove();
            }
            int parentIndex = 0;

            if (ControllerParent == null)
            {
                parentIndex = rootList.IndexOf(this);
            }
            else
            {
                parentIndex = ControllerParent.Children.IndexOf(this);
            }
            foreach (GraphicController child in Children)
            {
                child.ControllerParent = ControllerParent;
                if (child.ControllerParent != null)
                {
                    child.ControllerParent.Children.Insert(parentIndex, child);
                    if (ControllerParent.expanded)
                    {
                        child.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        child.Visibility = Visibility.Collapsed;
                    }
                }
                else
                {
                    rootList.Insert(parentIndex, child);
                }
                parentIndex++;
            }
            Children.Clear();
            grid.Children.Clear();
            Windows.Main.controllerContainer.Children.Remove(this);
            if (ControllerParent == null)
            {
                rootList.Remove(this);
            }
            else
            {
                ControllerParent.Children.Remove(this);
                if (ControllerParent.Children.Count == 0)
                {
                    ControllerParent.childrenHiddenArrow.Visibility  = Visibility.Collapsed;
                    ControllerParent.childrenVisibleArrow.Visibility = Visibility.Collapsed;
                }
            }
            if (copy == this)
            {
                copy = null;
            }
            ControllerHelpers.CheckResize();
            ControllerHelpers.RepositionControls(rootList);
        }
        public void Copy()
        {
            GraphicSerializer serializer = new GraphicSerializer();
            JObject           copy       = serializer.SerializeSingle(this, true);

            serializer.DeserializeSingle(copy);
            ControllerHelpers.CheckResize();
            ControllerHelpers.RepositionControls(rootList);
        }
Ejemplo n.º 4
0
        private void Main_PreviewKeydown(object sender, KeyEventArgs e)
        {
            // Move to previous controller
            if (e.Key == Key.Up && GraphicController.Selected != null && !(Keyboard.FocusedElement is TextBox || Keyboard.FocusedElement is RichTextBox))
            {
                GraphicController previous = ControllerHelpers.FindPreviousVisibleFrom(GraphicController.Selected);
                if (previous != null)
                {
                    MouseButtonEventArgs mouseEvent = new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left);
                    mouseEvent.RoutedEvent = MouseLeftButtonDownEvent;
                    previous.border.RaiseEvent(mouseEvent);
                    // Release event by giving opposite event
                    mouseEvent.RoutedEvent = MouseLeftButtonUpEvent;
                    GraphicController.Selected.border.RaiseEvent(mouseEvent);
                    // Bring selected to view if it is not already
                    if (GraphicController.Selected.Margin.Top < containerscrollviewer.VerticalOffset)
                    {
                        containerscrollviewer.ScrollToVerticalOffset(GraphicController.Selected.Margin.Top - containerscrollviewer.Height);
                    }
                }
            }

            // Move to next controller
            if (e.Key == Key.Down && GraphicController.Selected != null && !(Keyboard.FocusedElement is TextBox || Keyboard.FocusedElement is RichTextBox))
            {
                GraphicController next = ControllerHelpers.FindNextVisibleFrom(GraphicController.Selected);
                if (next != null)
                {
                    MouseButtonEventArgs mouseEvent = new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left);
                    mouseEvent.RoutedEvent = MouseLeftButtonDownEvent;
                    next.border.RaiseEvent(mouseEvent);
                    // Release event by giving opposite event
                    mouseEvent.RoutedEvent = MouseLeftButtonUpEvent;
                    GraphicController.Selected.border.RaiseEvent(mouseEvent);
                    // Bring selected to view if it is not already
                    if (GraphicController.Selected.Margin.Top >= containerscrollviewer.VerticalOffset + containerscrollviewer.Height)
                    {
                        containerscrollviewer.ScrollToVerticalOffset(GraphicController.Selected.Margin.Top + GraphicController.Selected.border.Height - containerscrollviewer.Height);
                    }
                }
            }
        }
        public GraphicController(Graphic graphic)
        {
            InitializeComponent();
            Graphic = graphic;
            int count = ControllerHelpers.GetVisibleControllerCount(rootList);

            Margin = new Thickness(0, count * 46, 0, 0);
            Windows.Main.controllerContainer.Children.Add(this);
            Panel.SetZIndex(this, 0);
            do
            {
                Id = random.Next(1, 10000);
            } while (HasControllerWithId(rootList));

            if (graphic is Media || graphic is Playlist)
            {
                button.ClearValue(BackgroundProperty);
            }

            rootList.Add(this);
            ControllerHelpers.CheckResize();
        }
Ejemplo n.º 6
0
 // Mouse was released, move controllers to proper positions
 private void ControllerContainer_MouseLeftButtonUp(object sender, MouseEventArgs e)
 {
     GraphicController.holdTimer.Stop();
     if (GraphicController.dragging)
     {
         GraphicController.Selected.Opacity = 1;
         Debug.Write("Is hittest visible");
         GraphicController.Selected.IsHitTestVisible = true;
         if ((Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)))
         {
             GraphicController.Selected.SetParent();
         }
         else
         {
             // If returns false, it's the last element
             if (!GraphicController.Selected.CalculatePosition(GraphicController.rootList, null))
             {
                 GraphicController last = ControllerHelpers.FindLastVisible(GraphicController.rootList);
                 if (last != null && last != GraphicController.Selected)
                 {
                     GraphicController.Selected.RemovePreviousParent();
                     if (last.ControllerParent != null)
                     {
                         last.ControllerParent.Children.Add(GraphicController.Selected);
                     }
                     else
                     {
                         GraphicController.rootList.Add(GraphicController.Selected);
                     }
                     GraphicController.Selected.ControllerParent = last.ControllerParent;
                 }
             }
         }
         ControllerHelpers.RepositionControls(GraphicController.rootList);
         ControllerHelpers.CheckResize();
         GraphicController.dragging = false;
     }
 }